tests: audit feature-header context and rejection boundaries
This commit is contained in:
1 parent
fe63ae9586
commit
03305f0957
13 files changed
+326
-10
No files matched your search
@@ -167,6 +167,95 @@ class CoverageFailures(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, 'missing diagnostic-identity use witness'):
|
||||
self.verify_fake(row)
|
||||
|
||||
def task_parameter_pair(self):
|
||||
row = self.fake_pair(source_path='source/reject_twins/task_handle_parameter.aji',
|
||||
air_path='phase3/reject/tasks_handle_as_parameter.air')
|
||||
row.update(site='function', feature_header_context=True)
|
||||
return row
|
||||
|
||||
def test_feature_pair_keeps_rule_with_different_unrelated_features(self):
|
||||
row = self.task_parameter_pair()
|
||||
air = self.corpus / 'a.air'
|
||||
original = air.read_text()
|
||||
for header in ('features [ownership, tasks]',
|
||||
'features [arrays, effects, ownership, tasks] ; inline context'):
|
||||
with self.subTest(header=header):
|
||||
air.write_text(original.replace('features [arrays, ownership, tasks]', header))
|
||||
self.verify_fake(row)
|
||||
|
||||
def test_task_result_cannot_replace_task_parameter_feature_rule(self):
|
||||
row = self.task_parameter_pair()
|
||||
source = self.corpus / 's.aji'
|
||||
source.write_text(source.read_text().replace('fn f(t: task<u8>) -> void',
|
||||
'fn f() -> task<u8>'))
|
||||
with self.assertRaisesRegex(ValueError, 'different offending operation/rule facts'):
|
||||
self.verify_fake(row)
|
||||
|
||||
def test_additional_missing_feature_cannot_reuse_single_error_pair(self):
|
||||
row = self.task_parameter_pair()
|
||||
air = self.corpus / 'a.air'
|
||||
air.write_text(air.read_text().replace('features [arrays, ownership, tasks]',
|
||||
'features [arrays, ownership]'))
|
||||
with self.assertRaisesRegex(ValueError, 'diagnostics do not match rejection header'):
|
||||
self.verify_fake(row)
|
||||
|
||||
def test_same_feature_error_cannot_hide_a_larger_missing_closure(self):
|
||||
row = self.task_parameter_pair()
|
||||
air = self.corpus / 'a.air'
|
||||
air.write_text(air.read_text().replace('features [arrays, ownership, tasks]',
|
||||
'features [arrays, ownership]'))
|
||||
real_command = twins.command
|
||||
def changed(aji, *args, status):
|
||||
result = real_command(aji, *args, status=status)
|
||||
if args[0] == 'check' and Path(args[1]) == air:
|
||||
ds = [json.loads(line) for line in result.splitlines()]
|
||||
# Isolate task_transfer so diagnostic count cannot mask the closure check.
|
||||
return '\n'.join(json.dumps(d) for d in ds if d.get('feature') == 'task_transfer') + '\n'
|
||||
return result
|
||||
with patch.object(twins, 'command', changed):
|
||||
with self.assertRaisesRegex(ValueError, 'different offending operation/rule facts'):
|
||||
self.verify_fake(row)
|
||||
|
||||
def test_invalid_feature_repair_facts_fail_closed(self):
|
||||
row = self.task_parameter_pair()
|
||||
real_command = twins.command
|
||||
changes = [
|
||||
{'canonical_header': 'features [arrays, task_transfer, tasks]'},
|
||||
{'canonical_header': 'features [arrays, heap, ownership, task_transfer, tasks]'},
|
||||
{'canonical_header': 'features [tasks, task_transfer, ownership, arrays]'},
|
||||
{'closure': 'ownership, task_transfer, task_transfer, tasks'},
|
||||
{'closure': 'ownership, , task_transfer, tasks'},
|
||||
{'closure': 'ownership, tasks'},
|
||||
{'closure': None}, {'canonical_header': None},
|
||||
{'reason': 'missing_dependency'},
|
||||
]
|
||||
for fields in changes:
|
||||
with self.subTest(fields=fields):
|
||||
def changed(aji, *args, status):
|
||||
result = real_command(aji, *args, status=status)
|
||||
if args[0] == 'check' and Path(args[1]) == self.corpus / 'a.air':
|
||||
ds = [json.loads(line) for line in result.splitlines()]
|
||||
ds[0].update(fields)
|
||||
return '\n'.join(json.dumps(d) for d in ds) + '\n'
|
||||
return result
|
||||
with patch.object(twins, 'command', changed):
|
||||
with self.assertRaisesRegex(ValueError, 'feature.*(context|header|rule)'):
|
||||
self.verify_fake(row)
|
||||
|
||||
def test_feature_context_does_not_relax_source_raw_payload_mapping(self):
|
||||
row = self.task_parameter_pair()
|
||||
real_command = twins.command
|
||||
def changed(aji, *args, status):
|
||||
result = real_command(aji, *args, status=status)
|
||||
if args[0] == 'check' and Path(args[1]) == self.corpus / 's.aji':
|
||||
ds = [json.loads(line) for line in result.splitlines()]
|
||||
ds[0]['canonical_header'] = 'features [ownership, task_transfer, tasks]'
|
||||
return '\n'.join(json.dumps(d) for d in ds) + '\n'
|
||||
return result
|
||||
with patch.object(twins, 'command', changed):
|
||||
with self.assertRaisesRegex(ValueError, 'mapping changed rule facts'):
|
||||
self.verify_fake(row)
|
||||
|
||||
def audited_cfg_pair(self, source='cfg_provenance_loan_br', air='cfg_provenance_loan_br'):
|
||||
row = self.fake_pair(source_path=f'source/reject_twins/{source}.aji',
|
||||
air_path=f'phase3/reject/{air}.air')
|
||||
|
||||
Reference in new issue
Block a user