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
@@ -58,7 +58,9 @@ For lowered CFG cases whose diagnostic facts omit the handoff shape, `audited_co
|
||||
|
||||
Early rejection produces no canonical AIR. Its mandatory `early_context` records SHA-256 fingerprints of both manually audited AIR/source files, alongside the rule audit; compiled code/kind/type and independent source positions still have to match. The fingerprints preserve the reviewed cycle shape, including long nominal chains and recursive arrays. They attest unchanged bytes, not the correctness of the audit. Any edit, including comments or line endings, requires a fresh context review before updating these fingerprints; do not regenerate them just to make a failed check pass.
|
||||
|
||||
`--inventory` emits every current AIR rejection as JSON, including newly added unreviewed tests. Its `verification: metadata_only` output does not claim compiled verification. Rows are `same_code`, `source_error` (an audited E7xxx analogue), `air_only` (not authorable in the implemented source) or `pending`. The latter three remain unmet same-code rows. A successful ordinary check verifies the audited pairs against these checks; it does not prove P6-7 complete. `--require-complete` additionally fails until every AIR rejection has a verified same-code twin. Classification is a documented manual audit, not an automatic proof that a rule is inexpressible in source; the phase's literal exit criterion remains unchanged pending Q-053.
|
||||
`--inventory` emits every current AIR rejection as JSON, including newly added unreviewed tests. Its `verification: metadata_only` output does not claim compiled verification. Rows are `same_code`, `source_error` (an audited E7xxx analogue), `source_early` (a different verifier code from source validation before lowering), `air_only` (not authorable in the implemented source) or `pending`. Only same-code pairs meet the criterion. A successful ordinary check verifies the audited pairs and analogues against these checks; it does not prove P6-7 complete. `--require-complete` additionally fails until every AIR rejection has a verified same-code twin. Classification is a documented manual audit, not an automatic proof that a rule is inexpressible in source; the phase's literal exit criterion remains unchanged pending Q-053.
|
||||
|
||||
The currently supported `source_early` case is E5101 at an AIR type declaration versus E1003 at the corresponding source declaration. It requires `site: declaration`, `lowering: rejected`, one AIR budget diagnostic and analogue E1003/type facts. `air_fields` pins exactly kind/limit/max/found/type, while `early_context` pins the manually reviewed AIR and every source analogue. The checker executes both files, checks independent source markers and declaration positions, and requires lower to reproduce check's rejection without AIR coordinates. It does not compare unlike codes as though they were twins or infer the type-cycle shape. A new early-code category needs its own explicit support/audit; E7xxx analogue handling is unchanged. The cyclic-array size case retains E5101 in AIR and E1003 in source, counts zero same-code pairs, and keeps the completion gate failing.
|
||||
|
||||
`python3 tests/hosted/source_reject_twins.py` exercises false-pair detection, independent source markers, raw diagnostic projection, early declarations and automatic discovery of pending cases.
|
||||
|
||||
|
||||
@@ -1763,6 +1763,38 @@
|
||||
"site": "function",
|
||||
"spec": "docs/spec/08-verifier.md \u00a77.1",
|
||||
"rule": "A parameter of array<array<u8,1024>,1025> accounts 1049600 bytes in both artifacts, preserving the complete value-size budget facts."
|
||||
},
|
||||
"phase1/reject/nested_size_cycle_overflow.air": {
|
||||
"kind": "source_early",
|
||||
"site": "declaration",
|
||||
"lowering": "rejected",
|
||||
"spec": "docs/spec/15-source-language.md \u00a71/\u00a710; docs/spec/08-verifier.md \u00a77.1",
|
||||
"rule": "Both declarations have u8 n and an array of 4294967296 A values by value. Source finite-layout validation rejects E1003 at A before emitting AIR; the AIR input budget reports E5101 with bounded size 4294967297 first. This is an earlier-stage analogue, not same-code coverage or an AIR-only source shape.",
|
||||
"air_fields": {
|
||||
"kind": "verifier.resource_limit",
|
||||
"limit": "value size bytes",
|
||||
"max": 1048576,
|
||||
"found": 4294967297,
|
||||
"type": "@A"
|
||||
},
|
||||
"analogues": [
|
||||
{
|
||||
"source": "source/size_limits/nested_size_cycle.aji",
|
||||
"codes": [
|
||||
"E1003"
|
||||
],
|
||||
"fields": {
|
||||
"kind": "type.recursive",
|
||||
"type": "A"
|
||||
}
|
||||
}
|
||||
],
|
||||
"early_context": {
|
||||
"air": "c3eff4c2941ee59e32f9ae4a6aa5e68ef0986f5140301a88a81b86447dab4957",
|
||||
"sources": {
|
||||
"source/size_limits/nested_size_cycle.aji": "b549c862021856f209331a024ba419bf49cf3deb48989bb24c9147ae38e5fc6f"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,5 @@
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §1
|
||||
module test.nested_size_cycle
|
||||
struct A { n: u8, x: [A; 4294967296] }
|
||||
struct A { n: u8, x: [A; 4294967296] } // diagnostic here: struct A
|
||||
fn main() -> void effects [] {}
|
||||
@@ -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