fix(retrieval): accept generated Python bytecode cache
CI / Capabilities and shell quality (push) Successful in 12s
CI / Python tests and compilation (push) Successful in 25s
CI / CI configuration security checks (push) Successful in 5s
CI / Build and inspect generated packages (push) Successful in 14s
CI / PowerShell tests on Ubuntu (push) Successful in 1m14s
CI / Bash integration and installation guards (push) Successful in 1m38s
CI / Installed client configuration smoke tests (push) Successful in 14s
CI / Qwen retrieval integration (push) Successful in 14m18s

This commit is contained in:
Julian lechner committed 2026-09-30 11:41:45 +02:00
1 parent 280292d72e
commit 756b8fe59e
2 files changed
+27 -1

No files matched your search

+7 -1
View File
@@ -3,6 +3,7 @@ import hashlib
import json
import os
from pathlib import Path
import re
import shutil
import subprocess
import sys
@@ -89,10 +90,15 @@ def check_runtime(target, state):
path = target / name
if path.is_symlink() or not path.is_file() or digest(path) != expected:
raise ValueError(f'Owned semantic retrieval file changed: {name}')
allowed = set(state['files']) | {'.venv', 'model-cache'}
allowed = set(state['files']) | {'.venv', 'model-cache', '__pycache__'}
for path in target.iterdir():
if path.is_symlink() or path.name not in allowed:
raise ValueError(f'Foreign or linked semantic retrieval path: {path.name}')
if path.name == '__pycache__' and (not path.is_dir() or any(
child.is_symlink() or not child.is_file() or not re.fullmatch(
r'(?:server|benchmark)\.[A-Za-z0-9_-]+(?:\.opt-\d+)?\.pyc', child.name)
for child in path.iterdir())):
raise ValueError('Foreign or linked semantic retrieval path: __pycache__')
def sync(root, home, clients, enabled, dry_run, update, summary=False):
+20
View File
@@ -4,6 +4,7 @@ import io
import json
from contextlib import redirect_stdout
from pathlib import Path
import py_compile
import tempfile
import unittest
from unittest.mock import patch
@@ -85,6 +86,25 @@ class SemanticRetrievalTests(unittest.TestCase):
self.assertFalse(target.exists())
self.assertFalse(state_path.exists())
def test_update_accepts_python_cache_but_rejects_foreign_cache_content(self):
with tempfile.TemporaryDirectory() as directory:
home = Path(directory) / 'home'
target = home / '.my-ai-configuration/semantic-retrieval'
target.mkdir(parents=True)
files = {}
for name in MODULE.FILES:
content = (ROOT / 'shared/retrieval' / name).read_bytes()
(target / name).write_bytes(content)
files[name] = hashlib.sha256(content).hexdigest()
MODULE.save_state(target.parent / 'semantic-retrieval.json', {'version': 1, 'clients': ['codex'], 'files': files}, False)
py_compile.compile(str(target / 'server.py'), doraise=True)
cache = target / '__pycache__'
with patch.object(MODULE, 'ensure_runtime', return_value=Path('python')), patch.object(MODULE, 'ensure_models'):
MODULE.sync(ROOT, home, ['codex'], True, False, True)
(cache / 'foreign.txt').write_text('keep')
with self.assertRaisesRegex(ValueError, '__pycache__'):
MODULE.sync(ROOT, home, ['codex'], True, False, True)
def test_negative_benchmark_keeps_active_runtime(self):
with tempfile.TemporaryDirectory() as directory:
home = Path(directory) / 'home'