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
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Inventory every public AIR rejection and verify audited source twins.
|
||||
|
||||
Pending, source-error analogues and AIR-only cases remain unmet P6-7 rows.
|
||||
Pending, source-error/early analogues and AIR-only cases remain unmet P6-7 rows.
|
||||
Default: verify declared pairs and report incomplete coverage. --inventory:
|
||||
JSON inventory without running the compiler. --require-complete: also fail
|
||||
unless every AIR rejection has a verified same-code source twin.
|
||||
@@ -89,7 +89,7 @@ def inventory():
|
||||
allowed = {'kind', 'rule', 'spec', 'site', 'lowering', 'analogues',
|
||||
'required_ops', 'exact_ops', 'required_identity_uses',
|
||||
'match_type_declarations', 'early_context', 'audited_context',
|
||||
'feature_header_context'}
|
||||
'feature_header_context', 'air_fields'}
|
||||
if set(review) - allowed:
|
||||
raise ValueError(f'{name}: unknown/reserved review keys: {sorted(set(review) - allowed)}')
|
||||
witnesses = review.get('required_ops', {})
|
||||
@@ -113,7 +113,7 @@ def inventory():
|
||||
if 'feature_header_context' in review and (
|
||||
review['feature_header_context'] is not True or expected != ['E0006']):
|
||||
raise ValueError(f'{name}: feature-header context needs one E0006 rejection')
|
||||
if review['kind'] not in {'same_code', 'source_error', 'air_only'}:
|
||||
if review['kind'] not in {'same_code', 'source_error', 'source_early', 'air_only'}:
|
||||
raise ValueError(f'{name}: invalid classification')
|
||||
if ({'required_ops', 'exact_ops', 'required_identity_uses', 'match_type_declarations',
|
||||
'audited_context', 'feature_header_context'} & review.keys()) and (
|
||||
@@ -129,14 +129,25 @@ def inventory():
|
||||
raise ValueError(f'{name}: missing source/site')
|
||||
elif sources:
|
||||
raise ValueError(f'{name}: analogue/inexpressible case cannot count as a twin')
|
||||
if review['kind'] == 'source_error' and not review.get('analogues'):
|
||||
if review['kind'] in {'source_error', 'source_early'} and not review.get('analogues'):
|
||||
raise ValueError(f'{name}: source-error classification needs an analogue')
|
||||
if review['kind'] == 'source_early':
|
||||
if (expected != ['E5101'] or review.get('site') != 'declaration' or
|
||||
review.get('lowering') != 'rejected' or
|
||||
not isinstance(review.get('air_fields'), dict) or
|
||||
set(review['air_fields']) != {'kind', 'limit', 'max', 'found', 'type'}):
|
||||
raise ValueError(f'{name}: early source analogue needs declaration-budget facts')
|
||||
elif 'air_fields' in review:
|
||||
raise ValueError(f'{name}: early AIR facts require source_early')
|
||||
if review.get('lowering') == 'rejected':
|
||||
context = review.get('early_context')
|
||||
if (review['kind'] != 'same_code' or not isinstance(context, dict) or
|
||||
context_sources = (sources if review['kind'] == 'same_code' else
|
||||
[a['source'] for a in review.get('analogues', [])])
|
||||
if (review['kind'] not in {'same_code', 'source_early'} or
|
||||
not isinstance(context, dict) or
|
||||
set(context) != {'air', 'sources'} or
|
||||
not isinstance(context['sources'], dict) or
|
||||
set(context['sources']) != set(sources) or
|
||||
set(context['sources']) != set(context_sources) or
|
||||
any(not isinstance(x, str) or not re.fullmatch(r'[0-9a-f]{64}', x)
|
||||
for x in [context['air'], *context['sources'].values()])):
|
||||
raise ValueError(f'{name}: early rejection needs audited AIR/source fingerprints')
|
||||
@@ -152,7 +163,13 @@ def inventory():
|
||||
*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']):
|
||||
if review['kind'] == 'source_early':
|
||||
if (analogue.get('codes') != ['E1003'] or
|
||||
not isinstance(analogue.get('fields'), dict) or
|
||||
analogue['fields'].get('kind') != 'type.recursive' or
|
||||
not isinstance(analogue['fields'].get('type'), str)):
|
||||
raise ValueError(f'{name}: early source analogue must identify E1003/type')
|
||||
elif 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')
|
||||
p = corpus_path(analogue['source'], '.aji')
|
||||
if Counter(codes(p) or []) != Counter(analogue['codes']):
|
||||
@@ -562,6 +579,33 @@ def verify_analogue(aji, analogue):
|
||||
for d in ds:
|
||||
if any(d.get(k) != v for k, v in analogue.get('fields', {}).items()):
|
||||
raise ValueError(f"{analogue['source']}: analogue rule facts changed")
|
||||
return ds
|
||||
|
||||
|
||||
def verify_early_analogue(aji, row):
|
||||
air = CORPUS / row['air']
|
||||
context = row['early_context']
|
||||
if hashlib.sha256(air.read_bytes()).hexdigest() != context['air']:
|
||||
raise ValueError('audited early AIR changed; a new context audit is required')
|
||||
for analogue in row['analogues']:
|
||||
source = CORPUS / analogue['source']
|
||||
if hashlib.sha256(source.read_bytes()).hexdigest() != context['sources'][analogue['source']]:
|
||||
raise ValueError('audited early source changed; a new context audit is required')
|
||||
for d in errors(aji, air):
|
||||
site_key(air.read_text(), d, 'declaration')
|
||||
if any(d.get(k) != v for k, v in row['air_fields'].items()):
|
||||
raise ValueError('early AIR rule facts changed')
|
||||
for analogue in row['analogues']:
|
||||
source = CORPUS / analogue['source']
|
||||
ds = verify_analogue(aji, analogue)
|
||||
lowered = [load_json(x) for x in command(aji, 'lower', source, status=1).splitlines()]
|
||||
if lowered != ds:
|
||||
raise ValueError('lower/check early errors differ')
|
||||
for d in ds:
|
||||
line = source.read_text().splitlines()[d['line'] - 1].strip()
|
||||
if (not line.startswith(('struct ', 'enum ')) or d['file'] != str(source) or
|
||||
'air_line' in d or 'air_col' in d):
|
||||
raise ValueError('early source analogue lacks an unmapped declaration position')
|
||||
|
||||
|
||||
def main():
|
||||
@@ -581,12 +625,16 @@ def main():
|
||||
else:
|
||||
with tempfile.TemporaryDirectory(prefix='aji-reject-twins-') as directory:
|
||||
for row in rows:
|
||||
if row['kind'] == 'source_early':
|
||||
verify_early_analogue(args.aji, row)
|
||||
continue
|
||||
for source in row['sources']:
|
||||
verify_pair(args.aji, Path(directory), row, source)
|
||||
for analogue in row.get('analogues', []):
|
||||
verify_analogue(args.aji, analogue)
|
||||
print(f"AIR rejection twins: {counts['same_code']}/{len(rows)} same-code cases verified; "
|
||||
f"{counts['pending']} pending, {counts['source_error']} source-error analogues, "
|
||||
f"{counts['source_early']} source-early analogues, "
|
||||
f"{counts['air_only']} AIR-only. P6-7 complete: {report['complete']}.")
|
||||
if args.require_complete and not report['complete']:
|
||||
return 1
|
||||
|
||||
Reference in new issue
Block a user