Datasets:
Download code/robohome/src/engine/tests/test_geometry_chain.py from RoboParty/RoboHome: direct link, hf CLI and curl.
- Browser
- Download file 6.16 kB
-
https://huggingface.co/datasets/RoboParty/RoboHome/resolve/86ffa4ecc1047bb404fdc283987bd22cbc259a96/code/robohome/src/engine/tests/test_geometry_chain.py
- Command line
-
hf download hf://datasets/RoboParty/RoboHome@86ffa4ecc1047bb404fdc283987bd22cbc259a96/code/robohome/src/engine/tests/test_geometry_chain.py
-
curl -L -o test_geometry_chain.py https://huggingface.co/datasets/RoboParty/RoboHome/resolve/86ffa4ecc1047bb404fdc283987bd22cbc259a96/code/robohome/src/engine/tests/test_geometry_chain.py
6.16 kB
| """Real saved Blender fixtures through the bounded generation controller.""" | |
| import copy | |
| import json | |
| from pathlib import Path | |
| import subprocess | |
| import sys | |
| import tempfile | |
| import unittest | |
| from engine.repair_execution import execute_repairs | |
| BASE = Path(__file__).resolve().parents[1] | |
| BLENDER = Path('/Applications/Blender.app/Contents/MacOS/Blender') | |
| class SavedGeometryChainTests(unittest.TestCase): | |
| def setUpClass(cls): | |
| cls.temp = tempfile.TemporaryDirectory() | |
| cls.root = Path(cls.temp.name) | |
| cls.initial = cls.root / 'initial' | |
| command = [str(BLENDER), '--background', '--python-exit-code', '1', '--python', | |
| str(BASE / 'real_test/generate_geometry_fixture.py'), '--', | |
| '--output', str(cls.initial), '--initial'] | |
| result = subprocess.run(command, capture_output=True, text=True, timeout=60) | |
| if result.returncode: | |
| raise AssertionError(result.stdout + result.stderr) | |
| cls.manifest = json.loads((cls.initial / 'generated.json').read_text()) | |
| cls.request = dict(schema='rhg.scene_request.v1', mode='locked', | |
| task_kind='scene_generation', task_text='Procedural saved-geometry fixture only', | |
| entities=copy.deepcopy(cls.manifest['entities']), | |
| furniture=[dict(entity_id=e['entity_id'], asset_id=e['asset_id']) | |
| for e in cls.manifest['entities']]) | |
| cls.request_path = cls.root / 'request.json' | |
| cls.request_path.write_text(json.dumps(cls.request)) | |
| def tearDownClass(cls): | |
| cls.temp.cleanup() | |
| def run_case(self, *, always_collide=False): | |
| name = 'exhausted' if always_collide else 'repaired' | |
| command = [str(BLENDER), '--background', '--python-exit-code', '1', '--python', | |
| str(BASE / 'real_test/generate_geometry_fixture.py'), '--', | |
| '--manifest', '{manifest}', '--request', '{request}', '--output', '{attempt_dir}'] | |
| if always_collide: | |
| command.append('--always-collide') | |
| config = dict(schema='rhg.frontier-chain-config.v1', | |
| manifest=str(self.initial / 'generated.json'), request=str(self.request_path), | |
| repair_execution=dict(enabled=True, max_attempts=2, total_timeout_s=90), | |
| geometry_validation=dict(enabled=True, blender=str(BLENDER), timeout_s=30), | |
| generation=dict(command=command, manifest_output='generated.json', timeout_s=30, | |
| native_search_required=False)) | |
| config_path = self.root / (name + '.config.json') | |
| config_path.write_text(json.dumps(config)) | |
| output = self.root / name | |
| return execute_repairs(config_path, output, execute=True), output | |
| def test_rotation_and_fresh_contact_close_the_saved_scene_repair_loop(self): | |
| result, output = self.run_case() | |
| self.assertEqual(result['count'], 2, result) | |
| self.assertTrue(result['geometry_current'], result) | |
| self.assertTrue(result['geometry_passed'], result) | |
| self.assertTrue(result['preservation_verified'], result) | |
| first = json.loads((output/'round_01/attempt_01/geometry/result.json').read_text()) | |
| second = json.loads((output/'round_02/attempt_01/geometry/result.json').read_text()) | |
| self.assertFalse(first['geometry_passed']) | |
| self.assertTrue(second['geometry_passed'], second) | |
| self.assertNotEqual(first['scene_sha256'], second['scene_sha256']) | |
| self.assertFalse(result['physical_qualified']) | |
| a = json.loads((output/'round_01/attempt_01/generated.json').read_text()) | |
| b = json.loads((output/'round_02/attempt_01/generated.json').read_text()) | |
| self.assertEqual(a['entities'][2], b['entities'][2]) | |
| self.assertNotEqual(a['entities'][0]['yaw_deg'], b['entities'][0]['yaw_deg']) | |
| def test_invalid_geometry_exhausts_budget_without_acceptance(self): | |
| result, _ = self.run_case(always_collide=True) | |
| self.assertEqual(result['count'], 2, result) | |
| self.assertEqual(result['status'], 'budget_exhausted', result) | |
| self.assertFalse(result['geometry_passed'], result) | |
| self.assertFalse(result['whole_task_acceptance']) | |
| def test_generation_entry_enables_geometry_without_mutating_original_config(self): | |
| config = dict(schema='rhg.frontier-chain-config.v1', | |
| manifest=str(self.initial/'generated.json'), request=str(self.request_path)) | |
| path = self.root/'entry.config.json' | |
| original = json.dumps(config).encode() | |
| path.write_bytes(original) | |
| output = self.root/'entry' | |
| result = subprocess.run([sys.executable, '-B', str(BASE/'real_test/run_geometry_chain.py'), | |
| '--config', str(path), '--output', str(output)], capture_output=True, | |
| text=True, timeout=15) | |
| self.assertEqual(result.returncode, 0, result.stdout+result.stderr) | |
| self.assertEqual(path.read_bytes(), original) | |
| effective = json.loads((output/'effective_config.json').read_text()) | |
| self.assertIs(effective['geometry_validation']['enabled'], True) | |
| def test_missing_saved_scene_cannot_pass_the_geometry_gate(self): | |
| from engine.run_chain import run_chain | |
| path = self.root/'missing-scene.config.json' | |
| command = [sys.executable, '-c', | |
| 'import shutil,sys; from pathlib import Path; shutil.copyfile(sys.argv[1],Path(sys.argv[2])/"generated.json")', | |
| '{manifest}', '{attempt_dir}'] | |
| config = dict(schema='rhg.frontier-chain-config.v1', | |
| manifest=str(self.initial/'generated.json'), request=str(self.request_path), | |
| geometry_validation={}, generation=dict(command=command, | |
| manifest_output='generated.json', timeout_s=5)) | |
| path.write_text(json.dumps(config)) | |
| result = run_chain(path, self.root/'missing-scene', execute=True) | |
| self.assertFalse(result['output_contract_passed'], result) | |
| self.assertFalse(result['geometry_current'], result) | |
| if __name__ == '__main__': | |
| unittest.main() | |