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

+23 -3
View File
@@ -88,7 +88,7 @@ def inventory():
else:
allowed = {'kind', 'rule', 'spec', 'site', 'lowering', 'analogues',
'required_ops', 'exact_ops', 'required_identity_uses',
'match_type_declarations', 'early_context'}
'match_type_declarations', 'early_context', 'audited_context'}
if set(review) - allowed:
raise ValueError(f'{name}: unknown/reserved review keys: {sorted(set(review) - allowed)}')
witnesses = review.get('required_ops', {})
@@ -111,7 +111,8 @@ def inventory():
raise ValueError(f'{name}: type-declaration witness must be true')
if review['kind'] not in {'same_code', 'source_error', 'air_only'}:
raise ValueError(f'{name}: invalid classification')
if ({'required_ops', 'exact_ops', 'required_identity_uses', 'match_type_declarations'} & review.keys()) and (
if ({'required_ops', 'exact_ops', 'required_identity_uses', 'match_type_declarations',
'audited_context'} & review.keys()) and (
review['kind'] != 'same_code' or review.get('lowering') == 'rejected'):
raise ValueError(f'{name}: AIR witnesses require a lowered same-code pair')
if not review.get('rule') or not review.get('spec'):
@@ -137,6 +138,15 @@ def inventory():
raise ValueError(f'{name}: early rejection needs audited AIR/source fingerprints')
elif 'early_context' in review:
raise ValueError(f'{name}: early context requires rejected lowering')
if 'audited_context' in review:
context = review['audited_context']
if (not isinstance(context, dict) or set(context) != {'air', 'sources', 'lowered'} or
any(not isinstance(context[key], dict) or set(context[key]) != set(sources)
for key in ('sources', 'lowered')) or
any(not isinstance(x, str) or not re.fullmatch(r'[0-9a-f]{64}', x)
for x in [context['air'], *context['sources'].values(),
*context['lowered'].values()])):
raise ValueError(f'{name}: lowered context needs audited AIR/source/lowered fingerprints')
for analogue in review.get('analogues', []):
if not analogue.get('codes') or any(not re.fullmatch(r'E7[0-9]{3}', c) for c in analogue['codes']):
raise ValueError(f'{name}: source-error analogue must use E7xxx')
@@ -209,6 +219,7 @@ def identity_class(air, d, value):
whole-resource/loan rule:
own<u8>/own<u64> are owners, and ref/slice forms are borrows. Resource
families (region/frozen/own/file<read>/...) must remain distinct.
island.borrow and mutex.borrow are explicit borrow producers.
Unsupported producers fail closed and need a reviewed extension.
"""
function = re.search(r'^fn @' + re.escape(d['function']) + r'\(.*?(?=^fn @|\Z)', air, re.MULTILINE | re.DOTALL)
@@ -233,7 +244,7 @@ def identity_class(air, d, value):
if definition and value in [x.strip() for x in definition[1].split(',')]:
op = definition[2]
if op.startswith('borrow.') or op in {'slice.make', 'slice.sub', 'slice.split',
'buffer.view', 'island.borrow'}:
'buffer.view', 'island.borrow', 'mutex.borrow'}:
return 'borrow'
if op in producers:
return producers[op]
@@ -370,6 +381,13 @@ def type_declarations(air):
def verify_pair(aji, root, row, source):
air_path = CORPUS / row['air']
src_path = CORPUS / source
context = row.get('audited_context')
if context:
# Preserve a manually reviewed CFG artifact, not inferred loan facts.
if hashlib.sha256(air_path.read_bytes()).hexdigest() != context['air']:
raise ValueError('audited AIR changed; a new context audit is required')
if hashlib.sha256(src_path.read_bytes()).hexdigest() != context['sources'][source]:
raise ValueError('audited source changed; a new context audit is required')
original = air_path.read_text()
air_ds = errors(aji, air_path)
ds = errors(aji, src_path)
@@ -403,6 +421,8 @@ def verify_pair(aji, root, row, source):
raise ValueError(f'{source}: early type error has different rule facts')
return
canonical = command(aji, 'lower', src_path, status=0)
if context and hashlib.sha256(canonical.encode('utf-8')).hexdigest() != context['lowered'][source]:
raise ValueError('audited lowering changed; a new context audit is required')
if row.get('match_type_declarations') and type_declarations(original) != type_declarations(canonical):
raise ValueError(f'{source}: different type-declaration context')
if command(aji, 'lower', src_path, status=0) != canonical: