"""Structured asset exhaustion survives the actual default controller layers.""" import hashlib import json from pathlib import Path import sys import tempfile import unittest ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT.parent)) from engine.run_chain import run_chain from engine.repair_execution import execute_repairs from engine.wholehouse_pipeline import run_wholehouse STUB = '''import hashlib,json,pathlib,sys attempt=pathlib.Path(sys.argv[1]);request=pathlib.Path(sys.argv[2]);out=attempt/'generated';out.mkdir() eid=json.loads(request.read_text())['furniture'][0]['entity_id'] report=dict(schema='rhg.eligible_candidate_request.v1',passed=False,input_request=str(request), input_request_sha256=hashlib.sha256(request.read_bytes()).hexdigest(),prepared_pools=[], empty_roles_after_full_prepared_pool=[eid],all_entity_domains_evaluated=True,unchecked_entity_ids=[], entities=[dict(entity_id=eid,eligible_asset_ids=[],eligible_record_ids=[], rejections=[dict(asset_id='fixture-invalid',reason='collision_representation_unqualified:open_boundary_edges')])]) (out/'candidate_eligibility_report.json').write_text(json.dumps(report)) raise SystemExit(1) ''' class CandidateExhaustionTests(unittest.TestCase): def setUp(self): self.folder = tempfile.TemporaryDirectory() self.addCleanup(self.folder.cleanup) self.root = Path(self.folder.name) entity = dict(entity_id='sofa', role='sofa', room_id='living', asset_id='fixture-invalid', center_xy_m=[2, 2], dimensions_m=[2, 1, 1], yaw_deg=0, base_z_m=0) self.write('manifest.json', dict(scene_id='fixture', floor_plan=dict( rooms=[dict(room_id='living', room_type='living', bounds_m=[0, 0, 5, 5])], doors=[]), entities=[entity])) self.write('request.json', dict(schema='rhg.scene_request.v1', mode='pool', task_kind='scene_generation', task_text='Synthetic exhaustion fixture.', entities=[entity], furniture=[dict(entity_id='sofa', candidate_asset_ids=['fixture-invalid'])])) self.config = dict(schema='rhg.frontier-chain-config.v1', manifest=str(self.root/'manifest.json'), request=str(self.root/'request.json'), max_attempts=2, geometry_validation=dict(enabled=False), generation=dict(command=[sys.executable, '-c', STUB, '{attempt_dir}', '{request}'], manifest_output='generated/manifest.json', timeout_s=20)) def write(self, name, data): path = self.root / name path.write_text(json.dumps(data)) return path def assert_exhausted(self, result): self.assertEqual(result['status'], 'candidate_domain_exhausted', result) self.assertFalse(result['output_contract_passed']) self.assertFalse(result['whole_task_acceptance']) self.assertFalse(result['physical_qualified']) failure = result['candidate_admission_failure'] self.assertEqual(failure['entity_ids'], ['sofa']) self.assertFalse(failure['placement_retry_applicable']) path = Path(failure['report_path']) self.assertEqual(hashlib.sha256(path.read_bytes()).hexdigest(), failure['report_sha256']) self.assertFalse(any(self.root.rglob('*.blend'))) def test_native_failure_preserves_asset_exhaustion(self): self.assert_exhausted(run_chain(self.write('config.json', self.config), self.root/'native', execute=True)) def test_repair_controller_does_not_retry_asset_exhaustion_as_placement(self): self.config['repair_execution'] = dict(enabled=True, max_attempts=2, total_timeout_s=60) result = execute_repairs(self.write('config.json', self.config), self.root/'repair', execute=True) self.assert_exhausted(result) self.assertEqual(result['count'], 1) self.assertFalse(result['automatic_retry']) def test_wholehouse_preserves_asset_exhaustion(self): self.config['repair_execution'] = dict(enabled=True, max_attempts=2, total_timeout_s=60) self.assert_exhausted(run_wholehouse(self.write('config.json', self.config), self.root/'house', execute=True)) if __name__ == '__main__': unittest.main(verbosity=2)