tests: preserve audited CFG loan handoff contexts

This commit is contained in:
dev committed 2026-10-08 21:57:27 +03:00
1 parent 50d1bb2c4b
commit fe63ae9586
12 files changed
+377 -8

No files matched your search

+75
View File
@@ -167,6 +167,81 @@ class CoverageFailures(unittest.TestCase):
with self.assertRaisesRegex(ValueError, 'missing diagnostic-identity use witness'):
self.verify_fake(row)
def audited_cfg_pair(self, source='cfg_provenance_loan_br', air='cfg_provenance_loan_br'):
row = self.fake_pair(source_path=f'source/reject_twins/{source}.aji',
air_path=f'phase3/reject/{air}.air')
p = self.corpus / 's.aji'
canonical = twins.command(AJI, 'lower', p, status=0)
row['audited_context'] = {
'air': hashlib.sha256((self.corpus / 'a.air').read_bytes()).hexdigest(),
'sources': {'s.aji': hashlib.sha256(p.read_bytes()).hexdigest()},
'lowered': {'s.aji': hashlib.sha256(canonical.encode('utf-8')).hexdigest()},
}
return row
def test_straight_line_loan_cannot_replace_audited_handoff(self):
row = self.audited_cfg_pair()
self.verify_fake(row)
text = (REAL_CORPUS / 'source/cfg_provenance/tasks_end_lent_borrow.aji').read_text()
text = re.sub(r'^// AIR twin: .+$', '// AIR twin: a.air', text, flags=re.MULTILINE)
(self.corpus / 's.aji').write_text(text)
with self.assertRaisesRegex(ValueError, 'audited source changed'):
self.verify_fake(row)
def test_single_handoff_cannot_replace_audited_loop_or_merge(self):
for air in ('cfg_provenance_loan_backedge', 'cfg_provenance_loan_join'):
with self.subTest(air=air):
row = self.audited_cfg_pair(source=air, air=air)
self.verify_fake(row)
text = (REAL_CORPUS / 'source/reject_twins/cfg_provenance_loan_br.aji').read_text()
text = re.sub(r'^// AIR twin: .+$', '// AIR twin: a.air', text, flags=re.MULTILINE)
(self.corpus / 's.aji').write_text(text)
with self.assertRaisesRegex(ValueError, 'audited source changed'):
self.verify_fake(row)
def test_changed_audited_air_requires_a_fresh_review(self):
row = self.audited_cfg_pair()
self.verify_fake(row)
(self.corpus / 'a.air').write_text(
(REAL_CORPUS / 'phase3/reject/tasks_end_lent_borrow.air').read_text())
with self.assertRaisesRegex(ValueError, 'audited AIR changed'):
self.verify_fake(row)
def test_deterministic_lowering_drift_requires_a_fresh_review(self):
row = self.audited_cfg_pair()
self.verify_fake(row)
real_command = twins.command
def changed(aji, *args, status):
result = real_command(aji, *args, status=status)
if args[0] == 'lower' and '--annotate' not in args:
return result.replace('module test.cfg', 'module changed.cfg')
return result
with patch.object(twins, 'command', changed):
with self.assertRaisesRegex(ValueError, 'audited lowering changed'):
self.verify_fake(row)
def test_lowered_context_cannot_omit_one_artifact(self):
row = self.audited_cfg_pair()
del row['audited_context']['lowered']['s.aji']
self.manifest.write_text(json.dumps({'version': 1, 'cases': {'a.air': row}}))
# Manifest rows contain review facts, not computed inventory columns.
data = json.loads(self.manifest.read_text())
for field in ('air', 'sources', 'codes'):
del data['cases']['a.air'][field]
self.manifest.write_text(json.dumps(data))
with patch.object(twins, 'CORPUS', self.corpus), patch.object(twins, 'MANIFEST', self.manifest):
with self.assertRaisesRegex(ValueError, 'lowered context needs audited'):
twins.inventory()
def test_guard_parent_end_cannot_replace_guard_unlock(self):
row = self.fake_pair(source_path='source/borrow_returns/lock_escape.aji',
air_path='phase3/reject/sync_unlock_live_borrow.air')
self.verify_fake(row)
(self.corpus / 'a.air').write_text(
(REAL_CORPUS / 'phase3/reject/cfg_provenance_guard_parent.air').read_text())
with self.assertRaisesRegex(ValueError, 'different offending operation/rule facts'):
self.verify_fake(row)
def test_same_code_different_atomic_operation_is_not_a_twin(self):
row = self.fake_pair(air_name='load_release')
with self.assertRaisesRegex(ValueError, 'different offending operation/rule facts'):