"""Offline container smoke check: seed cache, filename normalization and DWG decode. Run with a read-only existing DWG mounted at /test-input.dwg. No AI calls. """ import hashlib import json from pathlib import Path import re import sys import tempfile sys.path.insert(0, '/app/src/backend') from shared_cache_seed import install_bundle from model_snapshot_lookup import job_drawings, lookup from dwg_conversion import convert_dwg def main(): source = Path('/test-input.dwg') raw_hash = hashlib.sha256(source.read_bytes()).hexdigest() with tempfile.TemporaryDirectory(prefix='packaged-dwg-test-') as tmp: data = Path(tmp) install_bundle(Path('/app/shared-cache/selected-models.zip'), data) jobs = data / '8097-jobs' matches = [] for file in jobs.glob('*.json'): job = json.loads(file.read_text()) drawings = job_drawings(job, data / 'uploads') hit = lookup(jobs, drawings, data / 'uploads') assert hit and hit['jobId'] == file.stem renamed = [dict(row, name=re.sub(r'_(\d\d)_', r'(\1)', row['name'])) for row in drawings] assert lookup(jobs, renamed, data / 'uploads')['jobId'] == file.stem if len(drawings) > 1: assert lookup(jobs, renamed[:-1], data / 'uploads') is None changed = [dict(row) for row in drawings] changed[0]['sha256'] = 'f' * 64 assert lookup(jobs, changed, data / 'uploads') is None matches.extend(row for row in drawings if row['sha256'] == raw_hash) assert matches, 'Input DWG does not correspond to a retained model' audit = convert_dwg(source, data / 'decoded.dxf') expected = matches[0]['conversionAudit'] assert audit['source_sha256'] == raw_hash assert audit['entity_count'] == expected['entity_count'], (audit['entity_count'], expected['entity_count']) print(json.dumps({'cached_models_checked': len(list(jobs.glob('*.json'))), 'dwg_entity_count': audit['entity_count'], 'dxf_bytes_equal_to_saved_conversion': audit['output_sha256'] == expected['output_sha256'], 'ai_calls': 0})) if __name__ == '__main__': main()