test(retrieval): initialize temporary repositories
CI / Capabilities and shell quality (push) Successful in 13s
CI / Python tests and compilation (push) Successful in 48s
CI / CI configuration security checks (push) Successful in 3s
CI / Build and inspect generated packages (push) Successful in 13s
CI / PowerShell tests on Ubuntu (push) Failing after 55s
CI / Bash integration and installation guards (push) Failing after 17s
CI / Installed client configuration smoke tests (push) Successful in 35s
CI / Qwen retrieval integration (push) Canceled after 6m44s

This commit is contained in:
Julian lechner committed 2026-09-30 10:26:37 +02:00
1 parent a67c34f78d
commit 1b13bed418
1 file changed
+13
+13
View File
@@ -5,6 +5,7 @@ import os
from pathlib import Path from pathlib import Path
import re import re
import socket import socket
import subprocess
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
from types import SimpleNamespace from types import SimpleNamespace
import time import time
@@ -66,6 +67,10 @@ def fake_usearch():
return SimpleNamespace(index=module), module return SimpleNamespace(index=module), module
def initialize_repository(root):
subprocess.run(['git', '-C', str(root), 'init', '--quiet'], check=True)
def huggingface_available(): def huggingface_available():
try: try:
request = urllib.request.Request('https://huggingface.co', method='HEAD') request = urllib.request.Request('https://huggingface.co', method='HEAD')
@@ -144,6 +149,7 @@ class RetrievalServerTests(unittest.TestCase):
os.environ['HF_HOME'] = os.environ['QWEN_TEST_MODEL_CACHE'] os.environ['HF_HOME'] = os.environ['QWEN_TEST_MODEL_CACHE']
with TemporaryDirectory() as temporary: with TemporaryDirectory() as temporary:
root = Path(temporary) root = Path(temporary)
initialize_repository(root)
(root / 'authentication.md').write_text('Password reset tokens are created by create_reset_token. The reset_password endpoint sends the user a password reset email.', encoding='utf-8') (root / 'authentication.md').write_text('Password reset tokens are created by create_reset_token. The reset_password endpoint sends the user a password reset email.', encoding='utf-8')
(root / 'weather.md').write_text('The weather service fetches temperature and rainfall forecasts for a city.', encoding='utf-8') (root / 'weather.md').write_text('The weather service fetches temperature and rainfall forecasts for a city.', encoding='utf-8')
index = MODULE.Index(root, root / 'data') index = MODULE.Index(root, root / 'data')
@@ -175,6 +181,8 @@ class RetrievalServerTests(unittest.TestCase):
first, second = root / 'first', root / 'second' first, second = root / 'first', root / 'second'
first.mkdir() first.mkdir()
second.mkdir() second.mkdir()
initialize_repository(first)
initialize_repository(second)
file = first / 'a.md' file = first / 'a.md'
file.write_text('alpha', encoding='utf-8') file.write_text('alpha', encoding='utf-8')
(second / 'a.md').write_text('other', encoding='utf-8') (second / 'a.md').write_text('other', encoding='utf-8')
@@ -218,6 +226,7 @@ class RetrievalServerTests(unittest.TestCase):
def test_failed_refresh_preserves_previous_index(self): def test_failed_refresh_preserves_previous_index(self):
with TemporaryDirectory() as temporary: with TemporaryDirectory() as temporary:
root = Path(temporary) root = Path(temporary)
initialize_repository(root)
(root / 'a.md').write_text('before', encoding='utf-8') (root / 'a.md').write_text('before', encoding='utf-8')
index = MODULE.Index(root, root / 'data') index = MODULE.Index(root, root / 'data')
index.encoder = lambda: SimpleNamespace(encode=lambda values, **kwargs: [embedding() for _ in values], tokenizer=tokenize) index.encoder = lambda: SimpleNamespace(encode=lambda values, **kwargs: [embedding() for _ in values], tokenizer=tokenize)
@@ -243,6 +252,7 @@ class RetrievalServerTests(unittest.TestCase):
def test_refresh_batches_embeddings_for_changed_files(self): def test_refresh_batches_embeddings_for_changed_files(self):
with TemporaryDirectory() as temporary: with TemporaryDirectory() as temporary:
root = Path(temporary) root = Path(temporary)
initialize_repository(root)
(root / 'first.md').write_text('first', encoding='utf-8') (root / 'first.md').write_text('first', encoding='utf-8')
(root / 'second.md').write_text('second', encoding='utf-8') (root / 'second.md').write_text('second', encoding='utf-8')
index = MODULE.Index(root, root / 'data') index = MODULE.Index(root, root / 'data')
@@ -263,6 +273,7 @@ class RetrievalServerTests(unittest.TestCase):
def test_scan_prunes_ignored_directories_and_warns_at_limit(self): def test_scan_prunes_ignored_directories_and_warns_at_limit(self):
with TemporaryDirectory() as temporary: with TemporaryDirectory() as temporary:
root = Path(temporary) root = Path(temporary)
initialize_repository(root)
index = MODULE.Index(root, root / 'data') index = MODULE.Index(root, root / 'data')
(root / 'visible.md').write_text('visible', encoding='utf-8') (root / 'visible.md').write_text('visible', encoding='utf-8')
(root / '.gitignore').write_text('secrets.json\n**/private/\n', encoding='utf-8') (root / '.gitignore').write_text('secrets.json\n**/private/\n', encoding='utf-8')
@@ -287,6 +298,7 @@ class RetrievalServerTests(unittest.TestCase):
def test_max_files_is_configurable_via_environment(self): def test_max_files_is_configurable_via_environment(self):
with TemporaryDirectory() as temporary: with TemporaryDirectory() as temporary:
root = Path(temporary) root = Path(temporary)
initialize_repository(root)
index = MODULE.Index(root, root / 'data') index = MODULE.Index(root, root / 'data')
try: try:
with patch.dict(os.environ, {MODULE.MAX_FILES_ENV: '3'}): with patch.dict(os.environ, {MODULE.MAX_FILES_ENV: '3'}):
@@ -394,6 +406,7 @@ class RetrievalServerTests(unittest.TestCase):
def test_hybrid_candidates_and_document_metadata(self): def test_hybrid_candidates_and_document_metadata(self):
with TemporaryDirectory() as temporary: with TemporaryDirectory() as temporary:
root = Path(temporary) root = Path(temporary)
initialize_repository(root)
for number in range(110): for number in range(110):
(root / f'{number:03}.md').write_text(f'# Symbol{number}\ncontent {number}', encoding='utf-8', newline='\n') (root / f'{number:03}.md').write_text(f'# Symbol{number}\ncontent {number}', encoding='utf-8', newline='\n')
index = MODULE.Index(root, root / 'data') index = MODULE.Index(root, root / 'data')