tests: preserve rejection contexts and normalize callee effects

This commit is contained in:
dev committed 2026-10-08 19:41:01 +03:00
1 parent 06d8a1a76a
commit fd92604f36
11 files changed
+344 -35

No files matched your search

+108
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
"""Independent failure probes for the rejection-twin coverage check."""
import importlib.util
import hashlib
import json
import re
from pathlib import Path
@@ -188,6 +189,53 @@ class CoverageFailures(unittest.TestCase):
self.assertEqual(row['lowering'], 'rejected')
twins.verify_pair(AJI, self.root, row, row['sources'][0])
def test_self_loop_cannot_replace_audited_long_cycle(self):
row = self.fake_pair(source_path='source/nominal_queries/cycle.aji',
air_path='nominal_queries/cycle.air')
source = self.corpus / 's.aji'
row.update(site='declaration', lowering='rejected', early_context={
'air': hashlib.sha256((self.corpus / 'a.air').read_bytes()).hexdigest(),
'sources': {'s.aji': hashlib.sha256(source.read_bytes()).hexdigest()}})
source.write_text(source.read_text().replace('struct N0 { a: N1, b: N1 }',
'struct N0 { a: N0, b: N0 }'))
with self.assertRaisesRegex(ValueError, 'audited early source changed'):
self.verify_fake(row)
def test_direct_cycle_cannot_replace_audited_array_cycle(self):
row = self.fake_pair(source_path='source/generics/monomorphic_layout_cycle.aji',
air_path='generics/recursive_array.air')
source = self.corpus / 's.aji'
row.update(site='declaration', lowering='rejected', early_context={
'air': hashlib.sha256((self.corpus / 'a.air').read_bytes()).hexdigest(),
'sources': {'s.aji': hashlib.sha256(source.read_bytes()).hexdigest()}})
source.write_text(source.read_text().replace('[Node; 1]', 'Node'))
with self.assertRaisesRegex(ValueError, 'audited early source changed'):
self.verify_fake(row)
def test_changed_early_air_cannot_reuse_the_old_source_audit(self):
row = self.fake_pair(source_path='source/generics/monomorphic_layout_cycle.aji',
air_path='generics/recursive_array.air')
air, source = self.corpus / 'a.air', self.corpus / 's.aji'
row.update(site='declaration', lowering='rejected', early_context={
'air': hashlib.sha256(air.read_bytes()).hexdigest(),
'sources': {'s.aji': hashlib.sha256(source.read_bytes()).hexdigest()}})
original = air.read_text()
changed = original.replace('array<@Node, 1>', '@Node')
self.assertNotEqual(changed, original)
air.write_text(changed)
with self.assertRaisesRegex(ValueError, 'audited early AIR changed'):
self.verify_fake(row)
def test_early_mode_cannot_omit_its_context_audit(self):
row = self.fake_pair(source_path='source/generics/monomorphic_layout_cycle.aji',
air_path='generics/recursive_array.air')
review = {k: v for k, v in row.items() if k not in {'air', 'sources', 'codes'}}
review.update(site='declaration', lowering='rejected')
self.manifest.write_text(json.dumps({'version': 1, 'cases': {'a.air': review}}))
with patch.object(twins, 'CORPUS', self.corpus), patch.object(twins, 'MANIFEST', self.manifest):
with self.assertRaisesRegex(ValueError, 'early rejection needs audited'):
twins.inventory()
def test_one_source_array_borrow_keeps_first_raw_error_per_location(self):
rows = twins.inventory()
row = next(r for r in rows if r['air'] == 'phase1/reject/mut_and_shared.air')
@@ -199,6 +247,66 @@ class CoverageFailures(unittest.TestCase):
self.assertEqual(row['site'], 'function')
twins.verify_pair(AJI, self.root, row, row['sources'][0])
def test_four_type_budget_headers_use_exact_marked_declarations(self):
rows = twins.inventory()
row = next(r for r in rows if r['air'] == 'nominal_queries/diamond_21_u64.air')
self.assertEqual(row['site'], 'declaration')
self.assertNotIn('lowering', row)
twins.verify_pair(AJI, self.root, row, row['sources'][0])
def test_consistent_but_wrong_type_header_projection_is_rejected(self):
row = self.fake_pair(source_path='source/nominal_queries/diamond_21_u64.aji',
air_path='nominal_queries/diamond_21_u64.air')
row['site'] = 'declaration'
p = self.corpus / 's.aji'
lines = p.read_text().splitlines()
marked = [i for i, line in enumerate(lines) if '// diagnostic here' in line]
for i in marked:
lines[i] = lines[i].replace(' // diagnostic here', '')
lines[i + 4] += ' // diagnostic here'
p.write_text('\n'.join(lines) + '\n')
real_command = twins.command
def changed(aji, *args, status):
result = real_command(aji, *args, status=status)
if args[0] == 'check' and Path(args[1]) == p:
ds = [json.loads(line) for line in result.splitlines()]
for d in ds:
d['line'] += 4
return '\n'.join(json.dumps(d) for d in ds) + '\n'
return result
with patch.object(twins, 'command', changed):
with self.assertRaisesRegex(ValueError, 'incorrect source position'):
self.verify_fake(row)
def test_flat_array_sizes_cannot_replace_nominal_diamond_context(self):
row = self.fake_pair(source_path='source/nominal_queries/diamond_21_u64.aji',
air_path='nominal_queries/diamond_21_u64.air')
row.update(site='declaration', match_type_declarations=True)
p = self.corpus / 's.aji'
lines = [line for line in p.read_text().splitlines() if not line.startswith('struct ')]
index = next(i for i, line in enumerate(lines) if line.startswith('module ')) + 1
lines[index:index] = [f'struct N{i} {{ a: [u64; {2097152 >> i}] }} // diagnostic here'
for i in range(4)]
p.write_text('\n'.join(lines) + '\n')
with self.assertRaisesRegex(ValueError, 'different type-declaration context'):
self.verify_fake(row)
def test_effect_pair_survives_a_renamed_callee(self):
self.verify_fake(self.fake_pair(source_path='source/reject_twins/undeclared_effect.aji',
air_path='phase2/reject/undeclared_effect.air'))
def test_same_missing_effect_does_not_hide_different_callee_effect_sets(self):
row = self.fake_pair(source_path='source/reject_twins/undeclared_effect.aji',
air_path='phase2/reject/undeclared_effect.air')
air = self.corpus / 'a.air'
air.write_text(air.read_text().replace('effects []', 'effects [atomic]', 1)
.replace('effects [io.write]', 'effects [atomic, io.write]'))
source = self.corpus / 's.aji'
source.write_text(source.read_text().replace('fn f() -> void effects []',
'fn f() -> void effects [atomic]'))
with self.assertRaisesRegex(ValueError, 'different offending operation/rule facts'):
self.verify_fake(row)
if __name__ == '__main__':
unittest.main()