Datasets:
Download code/robohome/src/engine/tests/test_fusion_semantics.py from RoboParty/RoboHome: direct link, hf CLI and curl.
- Browser
- Download file 15 kB
-
https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/engine/tests/test_fusion_semantics.py
- Command line
-
hf download hf://datasets/RoboParty/RoboHome/code/robohome/src/engine/tests/test_fusion_semantics.py
-
curl -L -o test_fusion_semantics.py https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/engine/tests/test_fusion_semantics.py
15 kB
| """Native binder transitions preserve authored semantics and hard constraints.""" | |
| import copy | |
| import json | |
| from pathlib import Path | |
| import subprocess | |
| import sys | |
| import unittest | |
| BASE = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(BASE)) | |
| from room_program import compile_room_program, evaluate_room_program | |
| def codes(report, field='issues'): | |
| return {issue['code'] for issue in report[field]} | |
| def transition_scene(): | |
| slot = dict(entity_id='decor', room_id='kitchen', role='vase', | |
| asset_id='procedural:small_bowl', procedural_kind='small_bowl', | |
| category='vase', asset_pool_key='vase', dimensions_m=[1, 1, 1], | |
| base_z_m=0) | |
| baseline = dict(floor_plan=dict(rooms=[dict(room_id='kitchen', | |
| room_type='kitchen', bounds_m=[0, 0, 4, 4])]), entities=[slot]) | |
| definition = {key: copy.deepcopy(value) for key, value in slot.items() | |
| if key not in ('asset_id', 'dimensions_m', 'base_z_m')} | |
| request = dict(mode='pool', entities=[definition], furniture=[dict( | |
| entity_id='decor', candidate_asset_ids=['imported:bowl'], | |
| candidate_record_ids=['bowl-record'], source_sha256='a' * 64)]) | |
| output = copy.deepcopy(baseline) | |
| output['fixed_layout_real_asset_binding'] = dict(binding_phase='final', | |
| final_binding_passed=True, uniform_scale_only=True, preserve_source_materials=True) | |
| bound = output['entities'][0] | |
| bound.pop('procedural_kind') | |
| bound.update(asset_id='imported:bowl', category='bowl', binding_semantic_key='bowl', | |
| layout_slot_id='vase', layout_authority='explicit_scene_request_functional_entity', | |
| canonical_path='/assets/bowl.glb', runtime_path='/assets/bowl.glb', | |
| asset_sha256='a' * 64, runtime_sha256='a' * 64, | |
| pool_candidate_key='bowl-record', source_dimensions_m=[1, .5, .25], | |
| dimensions_m=[1, .5, .25], uniform_scale=1, | |
| footprint_polygon_xy_m=[[1, 1], [2, 1], [2, 1.5], [1, 1.5]]) | |
| return baseline, request, output | |
| class FusionSemanticsTests(unittest.TestCase): | |
| def test_package_import_uses_local_support_helper_without_module_directory(self): | |
| paths = [path for path in sys.path if Path(path or '.').resolve() != BASE] | |
| paths.insert(0, str(BASE.parent)) | |
| script = """import importlib, json, sys | |
| sys.path[:0] = json.loads(sys.argv[1]) | |
| module = importlib.import_module(sys.argv[2]) | |
| assert module.authored_support_parent.__module__ == module.__package__ + '.support_contract' | |
| assert 'support_contract' not in sys.modules | |
| assert callable(module.compile_room_program) and callable(module.evaluate_room_program) | |
| """ | |
| result = subprocess.run([sys.executable, '-I', '-c', script, json.dumps(paths), | |
| BASE.name + '.room_program'], cwd=BASE.parent, | |
| capture_output=True, text=True, timeout=30) | |
| self.assertEqual(result.returncode, 0, result.stderr) | |
| def test_compile_bound_output_with_original_pool_request_without_mutation(self): | |
| _, request, output = transition_scene() | |
| before = copy.deepcopy((request, output)) | |
| program = compile_room_program(output, request) | |
| self.assertEqual(program['request'], request) | |
| self.assertEqual(program['request']['mode'], 'pool') | |
| self.assertEqual(program['asset_domains']['decor'], ['imported:bowl']) | |
| self.assertEqual(program['baseline_manifest'], output) | |
| self.assertEqual((request, output), before) | |
| self.assertTrue(evaluate_room_program(output, program)['passed']) | |
| def test_audit_transition_against_original_baseline_keeps_native_unknown(self): | |
| baseline, request, output = transition_scene() | |
| program = compile_room_program(baseline, request) | |
| before = copy.deepcopy(program) | |
| report = evaluate_room_program(output, program) | |
| self.assertNotIn('entity_semantics_changed', codes(report)) | |
| self.assertIn('native_candidate_evidence_unknown', codes(report, 'unknowns')) | |
| self.assertFalse(report['passed']) | |
| self.assertFalse(report['physical_qualified']) | |
| self.assertEqual(program, before) | |
| self.assertEqual(program['baseline_manifest'], baseline) | |
| def test_transition_requires_final_binding_and_consistent_identity(self): | |
| mutations = [ | |
| lambda o: o.pop('fixed_layout_real_asset_binding'), | |
| lambda o: o['fixed_layout_real_asset_binding'].update(binding_phase='propose'), | |
| lambda o: o['fixed_layout_real_asset_binding'].update(final_binding_passed=False), | |
| lambda o: o['entities'][0].pop('binding_semantic_key'), | |
| lambda o: o['entities'][0].update(binding_semantic_key='plate'), | |
| lambda o: o['entities'][0].update(category='chair'), | |
| lambda o: o['entities'][0].update(procedural_kind='dining_plate'), | |
| lambda o: o['entities'][0].pop('asset_sha256'), | |
| lambda o: o['entities'][0].update(runtime_sha256='not-a-hash'), | |
| lambda o: o['entities'][0].update(asset_id='procedural:bowl'), | |
| ] | |
| for mutation in mutations: | |
| with self.subTest(mutation=mutation): | |
| baseline, request, output = transition_scene() | |
| program = compile_room_program(baseline, request) | |
| mutation(output) | |
| self.assertIn('entity_semantics_changed', | |
| codes(evaluate_room_program(output, program))) | |
| with self.assertRaises(ValueError): | |
| compile_room_program(output, request) | |
| def test_request_cannot_change_procedural_intent_or_authored_assignments(self): | |
| for changes in (dict(procedural_kind='dining_plate'), dict(role='cup'), | |
| dict(room_id='other'), dict(asset_pool_key='plate'), | |
| dict(layout_slot_id='plate'), dict(dimensions_m=[.1, .1, .1])): | |
| with self.subTest(changes=changes): | |
| _, request, output = transition_scene() | |
| request['entities'][0].update(changes) | |
| with self.assertRaises(ValueError): | |
| compile_room_program(output, request) | |
| def test_only_projected_default_slot_label_can_be_added(self): | |
| baseline, request, output = transition_scene() | |
| program = compile_room_program(baseline, request) | |
| for changes in (dict(layout_slot_id='plate'), dict(layout_authority='invented')): | |
| with self.subTest(changes=changes): | |
| altered = copy.deepcopy(output) | |
| altered['entities'][0].update(changes) | |
| self.assertIn('entity_semantics_changed', | |
| codes(evaluate_room_program(altered, program))) | |
| baseline['entities'][0]['layout_slot_id'] = 'authored-slot' | |
| program = compile_room_program(baseline, request) | |
| self.assertIn('entity_semantics_changed', codes(evaluate_room_program(output, program))) | |
| def test_asset_domains_and_record_source_pins_still_apply(self): | |
| baseline, request, output = transition_scene() | |
| program = compile_room_program(baseline, request) | |
| for changes, expected in ( | |
| (dict(asset_id='unlisted:bowl'), 'asset_outside_domain'), | |
| (dict(pool_candidate_key='other-record'), 'asset_pin_mismatch'), | |
| (dict(asset_sha256='b' * 64), 'asset_pin_mismatch')): | |
| with self.subTest(changes=changes): | |
| altered = copy.deepcopy(output) | |
| altered['entities'][0].update(changes) | |
| self.assertIn(expected, codes(evaluate_room_program(altered, program))) | |
| request['mode'] = 'locked' | |
| request['furniture'][0]['asset_id'] = 'procedural:small_bowl' | |
| with self.assertRaisesRegex(ValueError, 'Locked request changed asset'): | |
| compile_room_program(output, request) | |
| def test_imported_size_source_and_semantics_cannot_be_rewritten(self): | |
| _, request, output = transition_scene() | |
| program = compile_room_program(output, request) | |
| for changes, expected in ( | |
| (dict(dimensions_m=[.1, .1, .1]), 'native_asset_changed'), | |
| (dict(source_dimensions_m=[.1, .1, .1]), 'native_asset_changed'), | |
| (dict(uniform_scale=.1), 'native_asset_changed'), | |
| (dict(asset_sha256='b' * 64), 'native_asset_changed'), | |
| (dict(role='cup'), 'entity_semantics_changed'), | |
| (dict(category='plate'), 'entity_semantics_changed'), | |
| (dict(procedural_kind='small_bowl'), 'entity_semantics_changed'), | |
| (dict(binding_semantic_key='plate'), 'entity_semantics_changed')): | |
| with self.subTest(changes=changes): | |
| altered = copy.deepcopy(output) | |
| altered['entities'][0].update(changes) | |
| self.assertIn(expected, codes(evaluate_room_program(altered, program))) | |
| def test_plain_procedural_or_imported_edits_get_no_transition_exception(self): | |
| baseline, request, output = transition_scene() | |
| altered = copy.deepcopy(baseline) | |
| altered['entities'][0]['procedural_kind'] = 'dining_plate' | |
| program = compile_room_program(baseline, request) | |
| self.assertIn('entity_semantics_changed', codes(evaluate_room_program(altered, program))) | |
| plain = copy.deepcopy(output) | |
| plain['entities'][0].pop('binding_semantic_key') | |
| plain_request = dict(mode='locked', furniture=[dict(entity_id='decor', asset_id='imported:bowl')]) | |
| program = compile_room_program(plain, plain_request) | |
| plain['entities'][0]['category'] = 'plate' | |
| self.assertIn('entity_semantics_changed', codes(evaluate_room_program(plain, program))) | |
| def test_verified_floor_cover_is_authored_floor_but_retains_actual_support(self): | |
| baseline, _, _ = transition_scene() | |
| baseline['entities'] = [dict(entity_id='rug', room_id='kitchen', role='rug', | |
| asset_id='rug', dimensions_m=[2, 2, .02], base_z_m=0, | |
| asset_sha256='c' * 64, runtime_sha256='c' * 64, | |
| footprint_polygon_xy_m=[[0, 0], [2, 0], [2, 2], [0, 2]]), | |
| dict(entity_id='chair', room_id='kitchen', role='dining_chair', | |
| asset_id='chair', dimensions_m=[1, 1, 1], base_z_m=0, | |
| footprint_polygon_xy_m=[[0, 0], [1, 0], [1, 1], [0, 1]])] | |
| request = dict(mode='locked', entities=copy.deepcopy(baseline['entities']), | |
| furniture=[dict(entity_id=e['entity_id'], asset_id=e['asset_id']) | |
| for e in baseline['entities']]) | |
| output = copy.deepcopy(baseline) | |
| chair = output['entities'][1] | |
| chair.update(base_z_m=.02, support_entity_id='rug', derived_support_relation=dict( | |
| source='actual_floor_cover_mesh_and_furniture_bottom_contacts', | |
| authored_support_parent_entity_id=None, added_support_parent_entity_id='rug', | |
| original_floor_height_m=0, vertical_translation_m=.02, | |
| original_task_relations_retained=True, stage='joint_search_before_freeze')) | |
| chair['selected_support_surface'] = dict(status='measured', source_region_modified=False, | |
| parent_entity_id='rug', parent_asset_id='rug', evidence_sha256='d' * 64, | |
| surface_z_world_m=.02, parent_source_identity=dict(asset_id='rug', | |
| asset_sha256='c' * 64, runtime_sha256='c' * 64)) | |
| program = compile_room_program(baseline, request) | |
| report = evaluate_room_program(output, program) | |
| self.assertNotIn('support_assignment_changed', codes(report)) | |
| self.assertIn('support_contact_unknown', codes(report, 'unknowns')) | |
| compiled_output = compile_room_program(output, request) | |
| self.assertEqual(compiled_output['support_parents']['chair'], 'rug') | |
| self.assertLess(compiled_output['support_order'].index('rug'), | |
| compiled_output['support_order'].index('chair')) | |
| for changes in (dict(source='invented'), dict(original_task_relations_retained=False), | |
| dict(added_support_parent_entity_id='missing'), | |
| dict(vertical_translation_m=.5), dict(stage='after_freeze')): | |
| with self.subTest(changes=changes): | |
| altered = copy.deepcopy(output) | |
| altered['entities'][1]['derived_support_relation'].update(changes) | |
| self.assertIn('support_assignment_changed', | |
| codes(evaluate_room_program(altered, program))) | |
| altered = copy.deepcopy(output) | |
| altered['entities'][1].pop('derived_support_relation') | |
| self.assertIn('support_assignment_changed', codes(evaluate_room_program(altered, program))) | |
| class RecordedABSemanticsTests(unittest.TestCase): | |
| def test_real_eligible_requests_compile_and_audit_against_original(self): | |
| root = BASE.parent / 'pipeline_ab_20261023_02' | |
| baseline_path = root / 'inputs/layout/fullhome_asset_v16_000/composition_manifest.runtime.json' | |
| self.assertTrue(baseline_path.is_file(), 'Recorded source baseline is required') | |
| baseline = json.loads(baseline_path.read_text()) | |
| for relative in ('runs/wqz/generated/fullhome_asset_v16_000', | |
| 'runs/opt2/wholehouse_result/chain/attempt_01/generated/fullhome_asset_v16_000'): | |
| with self.subTest(run=relative): | |
| run = root / relative | |
| output = json.loads((run / 'composition_manifest.runtime.json').read_text()) | |
| request = json.loads((run / 'eligible_scene_request.json').read_text()) | |
| before = copy.deepcopy((baseline, request, output)) | |
| compiled_output = compile_room_program(output, request) | |
| self.assertEqual(compiled_output['request'], request) | |
| self.assertEqual(compiled_output['request']['mode'], 'pool') | |
| for field, value in (('dimensions_m', [.1, .1, .1]), | |
| ('source_dimensions_m', [.1, .1, .1]), | |
| ('uniform_scale', .1)): | |
| with self.subTest(field=field): | |
| altered = copy.deepcopy(output) | |
| altered['entities'][0][field] = value | |
| self.assertIn('native_asset_changed', | |
| codes(evaluate_room_program(altered, compiled_output))) | |
| original_program = compile_room_program(baseline, request) | |
| report = evaluate_room_program(output, original_program) | |
| self.assertNotIn('entity_semantics_changed', codes(report)) | |
| self.assertNotIn('support_assignment_changed', codes(report)) | |
| self.assertIn('native_candidate_evidence_unknown', codes(report, 'unknowns')) | |
| self.assertIn('task_changed', codes(report)) | |
| self.assertFalse(report['passed']) | |
| self.assertEqual((baseline, request, output), before) | |
| if __name__ == '__main__': | |
| unittest.main() | |