File size: 4,192 Bytes
870b85a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""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)