RoboHome / code /robohome /src /engine /test_validator_default_v25.py
RoboParty Release
Unify robohome source, assets and scenes delivery
3f15e9f
Raw History Blame
12.8 kB
"""Default root validator, narrow sink scope, and real worker identity."""
import copy
import gzip
import hashlib
import json
from pathlib import Path
import tempfile
import unittest
from unittest.mock import patch
import geometry_validation as geometry
from engine.tests.test_geometry_validation import box, entity
class ValidatorDefaultV25Tests(unittest.TestCase):
def fixture(self, *, role='sink', kind='inset', open_child=True,
open_parent=False, parent=True, collision=False, rest=False):
low = [.5, .5, .9 if collision else 1. if rest else 1.2]
child = box('fixture', low, [1.5, 1.5, 1.8], 'fixture')
counter = box('counter', [0, 0, 0], [2, 2, 1], 'counter')
if open_child:
child['triangles'].pop()
if open_parent:
counter['triangles'].pop()
row = entity('fixture', low, [1.5, 1.5, 1.8], 'counter' if parent else None)
row.update(role=role, support_type=kind)
return ({'entities': [entity('counter', [0, 0, 0], [2, 2, 1]), row]},
{'world_vertices': True, 'meshes': [
box('floor', [-5, -5, -.2], [5, 5, 0]), counter, child]})
def audit(self, **kwargs):
manifest, payload = self.fixture(**kwargs)
result = geometry.audit_meshes(manifest, payload, {})
contact = next(c for c in result['contact_checks'] if c['entity_id'] == 'fixture')
return result, contact
def audit_without_proxies(self, **kwargs):
# The skip scope applies only when an open part has no collision proxy.
with patch.object(geometry, '_proxy_solid', return_value=(None, None)):
return self.audit(**kwargs)
def test_open_inset_sink_is_measured_through_its_proxy(self):
result, contact = self.audit()
self.assertEqual(contact['status'], 'measured')
self.assertIs(contact['passed'], False) # the fixture floats 0.2 m above the counter
self.assertTrue(any(d['code'] == 'support_contact_invalid' for d in result['diagnostics']))
result, contact = self.audit(rest=True)
self.assertEqual(contact['status'], 'measured')
self.assertIs(contact['passed'], True)
self.assertTrue(result['geometry_passed'], result)
self.assertEqual(result['entity_readbacks']['fixture']['collision_proxies'],
[dict(mesh='fixture', proxy='repaired_boundary_caps')])
def test_identity_matches_root_module_bytes(self):
self.assertEqual(getattr(geometry, 'VALIDATOR_REVISION', None), 'xyz-seam-floor-cover-proof-v2.6')
identity = geometry.implementation_identity()
path = Path(geometry.__file__).resolve()
self.assertEqual(identity, dict(module_path=str(path),
sha256=hashlib.sha256(path.read_bytes()).hexdigest(), revision='xyz-seam-floor-cover-proof-v2.6',
helper_sha256={name:hashlib.sha256((path.parent/name).read_bytes()).hexdigest()
for name in ('floor_cover_contacts.py','support_contract.py','saved_mesh_seams.py','triangle_contacts.py')}))
def test_open_inset_sink_without_proxy_is_explicitly_skipped(self):
result, contact = self.audit_without_proxies()
self.assertEqual(contact['status'], 'skipped')
self.assertIsNone(contact['passed'])
self.assertFalse(contact['complete'])
self.assertEqual(contact['reason'], 'asset_installation_evidence_incomplete')
self.assertIn(contact, result['skipped_checks'])
self.assertIn('acceptance_scope', result)
self.assertTrue(contact['pending_fields'])
self.assertTrue(result['pending_fields'])
self.assertFalse(result['complete'])
self.assertFalse(result['geometry_passed'])
self.assertIs(result['physical_qualified'], False)
self.assertIs(result['whole_task_acceptance'], False)
self.assertFalse(result['entity_checks']['fixture']['geometry_passed'])
# AABB separation may already prove these particular pairs safe.
control, _ = self.audit_without_proxies(role='cooktop')
self.assertEqual(result['pair_checks'], control['pair_checks'])
def test_non_sink_inset_without_proxy_stays_pending(self):
result, contact = self.audit_without_proxies(role='cooktop')
self.assertEqual(contact['status'], 'pending')
self.assertIsNone(contact['passed'])
self.assertEqual(result.get('skipped_checks', []), [])
def test_sink_surface_is_not_skipped(self):
result, contact = self.audit(kind='surface', open_parent=True)
self.assertNotEqual(contact['status'], 'skipped')
self.assertEqual(result.get('skipped_checks', []), [])
def test_closed_measurably_unsupported_sink_still_fails(self):
result, contact = self.audit(open_child=False)
self.assertEqual(contact['status'], 'measured')
self.assertIs(contact['passed'], False)
self.assertTrue(any(d['code'] == 'support_contact_invalid'
and d['entity_ids'] == ['fixture'] for d in result['diagnostics']))
self.assertEqual(result.get('skipped_checks', []), [])
def test_invalid_installation_metadata_does_not_skip_measurable_closed_sink(self):
manifest, payload = self.fixture(open_child=False)
manifest['entities'][-1]['installation_gap'] = {}
result = geometry.audit_meshes(manifest, payload, {})
contact = result['contact_checks'][-1]
self.assertNotEqual(contact['status'], 'skipped')
self.assertEqual(result.get('skipped_checks', []), [])
def test_missing_parent_evidence_is_skipped_only_for_inset_sink(self):
result, contact = self.audit(open_child=False, parent=False)
self.assertEqual(contact['status'], 'skipped')
self.assertNotIn('support_parent:fixture', result['pending_fields'])
self.assertIn('support_parent:fixture', result['full_pending_fields'])
self.assertIn('support_parent:fixture', result['skipped_pending_fields'])
self.assertIsNone(contact['passed'])
self.assertFalse(contact['complete'])
self.assertTrue(result['complete'])
self.assertTrue(result['geometry_passed'])
self.assertFalse(result['full_geometry_complete'])
self.assertFalse(result['full_geometry_passed'])
self.assertFalse(result['full_scope_qualified'])
check = result['entity_checks']['fixture']
self.assertTrue(check['geometry_complete'])
self.assertTrue(check['geometry_passed'])
self.assertFalse(check['contact_complete'])
self.assertIsNone(check['contact_passed'])
self.assertTrue(check['contact_skipped'])
self.assertFalse(check['full_geometry_complete'])
self.assertEqual(check['pending_fields'], [])
self.assertEqual(result['pending_fields'], [])
self.assertFalse(result['physical_qualified'])
self.assertFalse(result['whole_task_acceptance'])
def test_skipped_sink_does_not_exclude_other_entities_pending_support(self):
manifest, payload = self.fixture(open_child=False, parent=False)
other = box('other', [3, 0, 1], [4, 1, 2], 'other')
row = entity('other', [3, 0, 1], [4, 1, 2])
row.update(role='cooktop', support_type='inset')
manifest['entities'].append(row)
payload['meshes'].append(other)
result = geometry.audit_meshes(manifest, payload, {})
self.assertEqual(result['pending_fields'], ['support_parent:other'])
self.assertEqual(result['skipped_pending_fields'], ['support_parent:fixture'])
self.assertFalse(result['complete'])
self.assertFalse(result['geometry_passed'])
self.assertFalse(result['full_geometry_complete'])
self.assertEqual(result['contact_checks'][-1]['status'], 'pending')
def test_open_skipped_sink_keeps_solid_and_collision_unknowns_blocking(self):
result, contact = self.audit_without_proxies(open_parent=True, collision=True)
self.assertEqual(contact['status'], 'skipped')
self.assertIsNone(contact['passed'])
self.assertNotIn('support_entity_geometry:fixture', result['pending_fields'])
self.assertIn('support_entity_geometry:fixture', result['skipped_pending_fields'])
self.assertTrue(any(p['passed'] is None for p in result['pair_checks']))
self.assertTrue(any(f.startswith('non_solid_mesh:') for f in result['pending_fields']))
self.assertFalse(result['complete'])
self.assertFalse(result['geometry_passed'])
self.assertFalse(result['full_geometry_complete'])
def test_closed_sink_with_open_support_target_is_skipped(self):
result, contact = self.audit_without_proxies(open_child=False, open_parent=True)
self.assertEqual(contact['status'], 'skipped')
self.assertTrue(result['pending_fields'])
def test_supported_closed_sink_is_measured(self):
manifest, payload = self.fixture(open_child=False)
for point in payload['meshes'][-1]['vertices']:
point[2] -= .2
manifest['entities'][-1] = entity('fixture', [.5, .5, 1.], [1.5, 1.5, 1.6], 'counter')
manifest['entities'][-1].update(role='sink', support_type='inset')
result = geometry.audit_meshes(manifest, payload, {})
contact = result['contact_checks'][-1]
self.assertEqual(contact['status'], 'measured')
self.assertIs(contact['passed'], True)
self.assertEqual(result.get('skipped_checks', []), [])
def test_actual_sink_collision_is_not_skipped(self):
result, contact = self.audit(open_child=False, collision=True)
self.assertFalse(result['geometry_passed'])
self.assertTrue(any(d['code'] == 'collision' for d in result['diagnostics']))
self.assertNotEqual(contact['status'], 'skipped')
self.assertEqual(result.get('skipped_checks', []), [])
def test_known_sink_collision_survives_missing_installation_evidence(self):
result, contact = self.audit(open_child=False, collision=True, parent=False)
self.assertTrue(any(d['code'] == 'collision' for d in result['diagnostics']))
self.assertNotEqual(contact['status'], 'skipped')
def test_unknown_support_mechanism_never_becomes_sink_skip(self):
result, contact = self.audit(kind='suspended')
self.assertEqual(contact['status'], 'pending')
self.assertEqual(result.get('skipped_checks', []), [])
def test_real_worker_returns_verified_identity_in_result_and_receipt(self):
manifest, payload = self.fixture()
with tempfile.TemporaryDirectory() as temporary:
output = Path(temporary)
manifest_path, mesh_path = output / 'manifest.json', output / 'meshes.json.gz'
manifest_path.write_text(json.dumps(manifest))
with gzip.open(mesh_path, 'wt') as stream:
json.dump(payload, stream)
result = geometry._audit_in_worker(manifest_path, mesh_path, {}, output, 60.)
identity = geometry.implementation_identity()
self.assertEqual(result.get('worker_identity'), identity)
receipt = json.loads((output / 'solid_audit_receipt.json').read_text())
self.assertEqual(receipt.get('worker_identity'), identity)
self.assertIs(receipt.get('worker_identity_verified'), True)
self.assertEqual(result['contact_checks'][-1]['status'], 'measured')
def test_mismatched_or_missing_worker_identity_fails_closed_and_is_retained(self):
import process_control
for worker in (None, {'module_path': '/old/geometry_validation.py',
'revision': 'old', 'sha256': '0' * 64}):
with self.subTest(worker=worker), tempfile.TemporaryDirectory() as temporary:
output = Path(temporary)
result = dict(complete=True, geometry_passed=True)
if worker is not None:
result['worker_identity'] = worker
(output / 'solid_audit.json').write_text(json.dumps(result))
receipt = dict(exit_code=0, timed_out=False, cleanup_passed=True)
with patch.object(process_control, 'execute_command', return_value=copy.deepcopy(receipt)):
with self.assertRaisesRegex(ValueError, 'identity'):
geometry._audit_in_worker('manifest.json', 'meshes.json.gz', {}, output, 60.)
saved = json.loads((output / 'solid_audit_receipt.json').read_text())
self.assertIs(saved.get('worker_identity_verified'), False)
self.assertEqual(saved.get('worker_identity'), worker)
if __name__ == '__main__':
unittest.main(verbosity=2)