Files
baji-vc/gateway/scripts/check-archive.py
T

56 lines
2.9 KiB
Python

#!/usr/bin/env python3
"""Portable model-free archive regression: isolated temp root + synthetic persona manifests."""
import argparse
import json
import os
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
root = Path(__file__).resolve().parents[1]
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument('--vad-model', type=Path, help='Existing authorized Silero artifact; read only, never downloaded')
args=parser.parse_args()
with tempfile.TemporaryDirectory(prefix='lan-voice-archive-check-') as folder:
stage = Path(folder)
for source in root.glob('*.py'): shutil.copy2(source, stage/source.name)
registry=root/'reviewed_action_packs.json'
if registry.exists():shutil.copy2(registry,stage/registry.name)
for name in ('tests','personas','web'):
shutil.copytree(root/name, stage/name, ignore=shutil.ignore_patterns('__pycache__'))
if args.vad_model:
import hashlib
model=args.vad_model.resolve(strict=True)
sys.path.insert(0,str(root))
from importlib.util import spec_from_file_location, module_from_spec
spec=spec_from_file_location('vad_app',root/'app.py');module=module_from_spec(spec);spec.loader.exec_module(module)
assert hashlib.sha256(model.read_bytes()).hexdigest()==module.EXPECTED_HASH, 'Silero artifact checksum'
(stage/'models').mkdir();(stage/'models/silero_vad.onnx').symlink_to(model)
target=stage/'.runtime/personas'; target.mkdir(parents=True)
for name in ('lvbu','yangmi_fiction'):
# Public dummy IDs only; no production profile/reference audio/runtime copied.
(target/(name+'.json')).write_text(json.dumps({'voice_id':'synthetic-'+name}))
runner=r'''
import sys,unittest
sys.path[:0]=['.','tests']
from pathlib import Path
ordered=['test_gateway','test_continuity','test_history','test_v08','test_debug','test_segmentation','test_guests','test_personas','test_face_context','test_gateway_reply_face']
ordered += sorted(p.stem for p in Path('tests').glob('test_*.py') if p.stem not in ordered)
suite=unittest.TestSuite(unittest.defaultTestLoader.loadTestsFromName(name) for name in ordered)
def safe(suite):
result=unittest.TestSuite()
for item in suite:
if isinstance(item,unittest.TestSuite): result.addTest(safe(item))
elif item.id().endswith('.test_silero_silence_and_state') and not Path('models/silero_vad.onnx').exists():
# Model artifacts are intentionally absent; never download/load a model in archive checks.
item.setUp=lambda: (_ for _ in ()).throw(unittest.SkipTest('Silero artifact excluded from source archive'))
result.addTest(item)
else: result.addTest(item)
return result
out=unittest.TextTestRunner(verbosity=2).run(safe(suite))
raise SystemExit(not out.wasSuccessful())
'''
raise SystemExit(subprocess.run([sys.executable,'-c',runner],cwd=stage,env={**os.environ,'PYTHONDONTWRITEBYTECODE':'1'}).returncode)