"""Empty-observation end-to-end contracts: exercise every downstream writer/reader.""" from pathlib import Path import json,shutil,hashlib def qualify_numeric_invariants(root, modules, marker, profile, run_container): """Keep identity and partition invariance mandatory for future candidates.""" checked = [] for name, entry in [ ('observed-geometry-identity', 'test_observed_geometry.py'), ('object-evidence-partition', 'test_object_evidence.py'), ]: assert (modules / 'marking_pass' / entry).is_file(), 'Missing numeric contract: ' + entry output = root / name output.mkdir() run_container( marker, 'contract-' + name, profile['mapper_image'], [(modules / 'marking_pass', '/candidate', True), (output, '/out', False)], ['-B', '/candidate/' + entry], output, lambda: None, 60, gpu=False, executable='python3', readonly=True, environment=dict(PYTHONPATH='/candidate', OPENBLAS_NUM_THREADS='3', OMP_NUM_THREADS='3'), ) checked.append(name) print('CONTRACT_OK', name, flush=True) return checked def run(root,definition,modules,original,marker,profile,runtime,release,run_container,write_json): preflight=root/'contracts';preflight.mkdir();primary=preflight/'primary';primary.mkdir() empty=preflight/'empty';empty.mkdir();write_json(empty/'full-map.json',dict(type='FeatureCollection',features=[])) digest=hashlib.sha256((original/'full_plan/fields.npz').read_bytes()).hexdigest() for name,doc in { 'observations.json':dict(paint=[],crossbars=[]), 'search-proposals.json':dict(lines=[],glyphs=[],source_fields_sha256=digest), 'catalog-proposals.json':dict(glyphs=[],source_fields_sha256=digest), 'arrow-gates.json':[], 'crossing-seeds.json':[], 'symbol-patches.json':dict(patches=[]), }.items():write_json(primary/name,doc) write_json(primary/'symbol-semantics.json',dict(records=[],patch_manifest_sha256=hashlib.sha256((primary/'symbol-patches.json').read_bytes()).hexdigest())) previous=empty;results=[];locations={} base=next(g for g in definition['groups']if g['group']=='base') if 'test_initial_views.py'in base['files']: coverage=preflight/'initial-views';coverage.mkdir() run_container(marker,'contract-initial-views',profile['mapper_image'], [(modules/'base','/candidate',True),(coverage,'/out',False)], ['-B','/candidate/test_initial_views.py'],coverage,lambda:None,60,gpu=False,executable='python3', environment=dict(PYTHONPATH='/candidate',OPENBLAS_NUM_THREADS='3',OMP_NUM_THREADS='3'),readonly=True) results.append('initial-view-cover');print('CONTRACT_OK initial-view-cover',flush=True) if 'test_survey_index.py'in base['files']: reader=preflight/'survey-index';reader.mkdir() run_container(marker,'contract-survey-index',profile['mapper_image'], [(modules/'base','/candidate',True),(reader,'/out',False)], ['-B','/candidate/test_survey_index.py'],reader,lambda:None,60,gpu=False,executable='python3', environment=dict(PYTHONPATH='/candidate'),readonly=True) results.append('survey-manifest-identity');print('CONTRACT_OK survey-manifest-identity',flush=True) primary_group=next(g for g in definition['groups']if g['group']=='primary_search') if 'test_connected_ridges.py'in primary_group['files']: branches=preflight/'connected-ridges';branches.mkdir() run_container(marker,'contract-connected-ridges',profile['mapper_image'], [(modules/'primary_search','/candidate',True),(branches,'/out',False)], ['-B','/candidate/test_connected_ridges.py'],branches,lambda:None,60,gpu=False,executable='python3', environment=dict(PYTHONPATH='/candidate',OPENBLAS_NUM_THREADS='3',OMP_NUM_THREADS='3'),readonly=True) results.append('connected-ridges');print('CONTRACT_OK connected-ridges',flush=True) continuation=next(g for g in definition['groups']if g['group']=='continuation_pass') if 'test_shared_surface_edges.py'in continuation['files']: surface=preflight/'surface-structure';surface.mkdir() run_container(marker,'contract-shared-surface-edges',profile['mapper_image'], [(modules/'continuation_pass','/candidate',True),(surface,'/out',False)], ['-B','/candidate/test_shared_surface_edges.py'],surface,lambda:None,60,gpu=False,executable='python3', environment=dict(PYTHONPATH='/candidate',OPENBLAS_NUM_THREADS='3',OMP_NUM_THREADS='3'),readonly=True) results.append('shared-surface-edges');print('CONTRACT_OK shared-surface-edges',flush=True) marking=next(g for g in definition['groups']if g['group']=='marking_pass') if 'test_joint_choice.py'in marking['files']: joint=preflight/'joint-assembly';joint.mkdir() run_container(marker,'contract-joint-assembly',profile['mapper_image'], [(modules/'marking_pass','/candidate',True),(joint,'/out',False)], ['-B','/candidate/test_joint_choice.py'],joint,lambda:None,60,gpu=False,executable='python3', environment=dict(PYTHONPATH='/candidate',OPENBLAS_NUM_THREADS='3',OMP_NUM_THREADS='3'),readonly=True) results.append('joint-assembly');print('CONTRACT_OK joint-assembly',flush=True) results.extend(qualify_numeric_invariants(preflight,modules,marker,profile,run_container)) fixture=Path('C:/NDC_MISSIONCORE_CACHE/urban-mapping/qualifications/topdown-writer-queue-20261016101327/maroseyka/observations') begin=next(i for i,g in enumerate(definition['groups'])if g['group']=='paint_assembly') for group in definition['groups'][begin:]: name=group['group'];out=preflight/name;out.mkdir() if (previous/'crosswalk-standard-check.json').exists():shutil.copyfile(previous/'crosswalk-standard-check.json',out/'crosswalk-standard-check.json') for stage in group['stages']: mounts=[(modules/name,'/candidate',True),(previous,'/fullplan',True),(out,'/out',False), (original/'full_plan','/evidence_plan',True),(original/'ortho/survey','/survey',True), (original/'ortho','/ortho',True),(primary,'/primary',True), (primary,'/symbolplan',True),(primary,'/gateplan',True),(primary,'/uniformplan',True),(primary,'/searchplan',True)] if name=='primary_arrows': mounts=[m for m in mounts if m[1]not in {'/ortho','/survey'}] mounts += [(fixture,'/ortho',True),(fixture/'survey','/survey',True),(fixture/'native-geometry','/native_geometry',True)] if 'primary_arrows'in locations:mounts.append((locations['primary_arrows'],'/primaryarrows',True)) for wheel in (release/'simulation/urban-plan-research/pipeline/vendor').glob('*.whl'):mounts.append((wheel,'/candidate/'+wheel.name,True)) env=dict(PYTHONPATH='/candidate:/candidate/mapping',SCENE='scene',OPENBLAS_NUM_THREADS='3',OMP_NUM_THREADS='3',WINDOW_SOURCE='/candidate/linear_window_support.py') if name=='primary_arrows' and stage==group['stages'][0]: fixture_mounts=[m for m in mounts if m[1]!='/symbolplan']+[(primary,'/symbolplan',False)] code="from pathlib import Path;import json,hashlib;from ground_observations import GroundObservations;p=Path('/symbolplan');d=json.loads((p/'symbol-patches.json').read_text());d['observation_snapshot']=GroundObservations().inventory()['snapshot'];(p/'symbol-patches.json').write_text(json.dumps(d));(p/'symbol-semantics.json').write_text(json.dumps(dict(records=[],patch_manifest_sha256=hashlib.sha256((p/'symbol-patches.json').read_bytes()).hexdigest())))" run_container(marker,'contract-native-fixture',profile['mapper_image'],fixture_mounts,['-B','-c',code],out,lambda:None,180,gpu=False,executable='python3',environment=env,readonly=True) entry='import runpy;' if stage=='final_symbol_admission':entry+="import sys;sys.argv=['final_symbol_admission','/fullplan/full-map.json','/candidate/symbol_rules.py','/out'];" entry+="runpy.run_path('/candidate/"+stage+".py',run_name='__main__')" run_container(marker,'contract-'+stage,profile['mapper_image'],mounts,['-B','-c',entry],out,lambda:None,180 if name=='primary_arrows' else 60,gpu=False,executable='python3',environment=env,readonly=True) results.append(stage);print('CONTRACT_OK',stage,flush=True) if group.get('map_file'):shutil.copyfile(out/group['map_file'],out/'full-map.json') assert json.loads((out/'full-map.json').read_text())['features']==[] previous=out;locations[name]=out write_json(preflight/'contract-fixture.json',dict(native_observations=fixture.as_posix(),read_only=True,scope='empty-observation contracts; not a cold result')) write_json(preflight/'contract-report.json',dict(passed=True,stages=results,empty_input_remains_empty=True)) return results