tests: audit source rejections before AIR lowering
This commit is contained in:
1 parent
a491eba193
commit
ba99ad6727
7 files changed
+192
-9
No files matched your search
@@ -2,6 +2,7 @@
|
||||
"""Independent failure probes for the rejection-twin coverage check."""
|
||||
import importlib.util
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
@@ -643,6 +644,102 @@ class CoverageFailures(unittest.TestCase):
|
||||
self.assertEqual(row['site'], 'function')
|
||||
twins.verify_pair(AJI, self.root, row, row['sources'][0])
|
||||
|
||||
def early_analogue(self):
|
||||
air = self.corpus / 'a.air'
|
||||
source = self.corpus / 's.aji'
|
||||
air.write_text((REAL_CORPUS / 'phase1/reject/nested_size_cycle_overflow.air').read_text())
|
||||
text = (REAL_CORPUS / 'source/size_limits/nested_size_cycle.aji').read_text()
|
||||
text = re.sub(r' // diagnostic here.*$', '', text, flags=re.MULTILINE)
|
||||
source.write_text(text.replace('struct A { n: u8, x: [A; 4294967296] }',
|
||||
'struct A { n: u8, x: [A; 4294967296] } // diagnostic here: struct A'))
|
||||
rule = {
|
||||
'kind': 'source_early', 'site': 'declaration', 'lowering': 'rejected',
|
||||
'spec': 'docs/spec/15-source-language.md §10',
|
||||
'rule': 'The same cyclic array shape reaches different validation stages.',
|
||||
'air_fields': {'kind': 'verifier.resource_limit', 'limit': 'value size bytes',
|
||||
'max': 1048576, 'found': 4294967297, 'type': '@A'},
|
||||
'analogues': [{'source': 's.aji', 'codes': ['E1003'],
|
||||
'fields': {'kind': 'type.recursive', 'type': 'A'}}],
|
||||
'early_context': {'air': hashlib.sha256(air.read_bytes()).hexdigest(),
|
||||
'sources': {'s.aji': hashlib.sha256(source.read_bytes()).hexdigest()}},
|
||||
}
|
||||
self.manifest.write_text(json.dumps({'version': 1, 'cases': {'a.air': rule}}))
|
||||
return {'air': 'a.air', 'sources': [], 'codes': ['E5101'], **rule}
|
||||
|
||||
def verify_early(self, row):
|
||||
with patch.object(twins, 'CORPUS', self.corpus):
|
||||
twins.verify_early_analogue(AJI, row)
|
||||
|
||||
def test_early_source_analogue_retains_different_codes_without_becoming_a_twin(self):
|
||||
row = self.early_analogue()
|
||||
with patch.object(twins, 'CORPUS', self.corpus), patch.object(twins, 'MANIFEST', self.manifest):
|
||||
found = twins.inventory()[0]
|
||||
self.assertEqual(found['kind'], 'source_early')
|
||||
self.assertEqual(found['sources'], [])
|
||||
self.assertEqual(found['codes'], ['E5101'])
|
||||
self.verify_early(row)
|
||||
|
||||
def test_early_source_analogue_cannot_complete_same_code_coverage(self):
|
||||
row = self.early_analogue()
|
||||
with patch.object(twins, 'inventory', return_value=[row]), \
|
||||
patch.object(twins, 'verify_early_analogue'), \
|
||||
patch.object(twins.sys, 'argv', ['twins', '--require-complete']), \
|
||||
patch.object(twins.sys, 'stdout', io.StringIO()) as out:
|
||||
self.assertEqual(twins.main(), 1)
|
||||
self.assertIn('0/1 same-code', out.getvalue())
|
||||
self.assertIn('1 source-early', out.getvalue())
|
||||
|
||||
def test_early_source_analogue_needs_reviewed_artifacts(self):
|
||||
self.early_analogue()
|
||||
manifest = json.loads(self.manifest.read_text())
|
||||
del manifest['cases']['a.air']['early_context']
|
||||
self.manifest.write_text(json.dumps(manifest))
|
||||
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_direct_cycle_cannot_replace_early_size_analogue(self):
|
||||
row = self.early_analogue()
|
||||
p = self.corpus / 's.aji'
|
||||
p.write_text(p.read_text().replace('[A; 4294967296]', 'A'))
|
||||
with self.assertRaisesRegex(ValueError, 'audited early source changed'):
|
||||
self.verify_early(row)
|
||||
|
||||
def test_different_size_cannot_replace_early_air_analogue(self):
|
||||
row = self.early_analogue()
|
||||
p = self.corpus / 'a.air'
|
||||
p.write_text(p.read_text().replace('4294967296', '4294967295'))
|
||||
with self.assertRaisesRegex(ValueError, 'audited early AIR changed'):
|
||||
self.verify_early(row)
|
||||
|
||||
def test_wrong_air_budget_fact_cannot_hide_behind_source_cycle_code(self):
|
||||
row = self.early_analogue()
|
||||
row['air_fields']['found'] = 1048577
|
||||
with self.assertRaisesRegex(ValueError, 'early AIR rule facts changed'):
|
||||
self.verify_early(row)
|
||||
|
||||
def test_early_source_marker_must_point_to_rejected_declaration(self):
|
||||
row = self.early_analogue()
|
||||
p = self.corpus / 's.aji'
|
||||
p.write_text(p.read_text().replace('diagnostic here: struct A', 'diagnostic here: x:'))
|
||||
row['early_context']['sources']['s.aji'] = hashlib.sha256(p.read_bytes()).hexdigest()
|
||||
with self.assertRaisesRegex(ValueError, 'analogue position changed'):
|
||||
self.verify_early(row)
|
||||
|
||||
def test_early_source_check_and_lower_cannot_disagree(self):
|
||||
row = self.early_analogue()
|
||||
real_command = twins.command
|
||||
def changed(aji, *args, status):
|
||||
result = real_command(aji, *args, status=status)
|
||||
if args[0] == 'lower':
|
||||
ds = [json.loads(line) for line in result.splitlines()]
|
||||
ds[0]['type'] = 'Wrong'
|
||||
return '\n'.join(json.dumps(d) for d in ds) + '\n'
|
||||
return result
|
||||
with patch.object(twins, 'command', changed):
|
||||
with self.assertRaisesRegex(ValueError, 'lower/check early errors differ'):
|
||||
self.verify_early(row)
|
||||
|
||||
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')
|
||||
|
||||
Reference in new issue
Block a user