diag: add stable source reasons and diagnostic incidence reporting
This commit is contained in:
1 parent
911982dd1c
commit
dbd9763713
21 files changed
+571
-156
No files matched your search
@@ -0,0 +1,87 @@
|
||||
"""Structured reason counts: historical uncertainty and per-run incidence."""
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from ajieval import report
|
||||
|
||||
|
||||
class DiagnosticReasons(unittest.TestCase):
|
||||
def events(self, directory, outputs):
|
||||
with open(os.path.join(directory, 'events.jsonl'), 'w') as f:
|
||||
for output in outputs:
|
||||
f.write(json.dumps({'event': 'command', 'output': output}) + '\n')
|
||||
|
||||
def test_unknown_historical_records_and_code_totals(self):
|
||||
r = {'language': {'name': 'aji_source'}}
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
self.events(d, [
|
||||
'{"code":"E7006","reason":"move_copy","message":"any prose"}\n'
|
||||
'{"reason":"zero_not_zeroable","code":"E7006"}\n'
|
||||
'{"code":"E7006","message":"move applies to Copy"}\n'
|
||||
'prefix {"code":"E7006","reason":"move_copy"} truncated\n'
|
||||
'{"code":"E7006","reason":12}\n'
|
||||
'{"code":"E0006","reason":"future_reason"}\n'
|
||||
'{"code":"E3101"}\n'])
|
||||
pairs = report._diagnostic_reasons(r, d)
|
||||
self.assertEqual(pairs, [
|
||||
{'code': 'E0006', 'reason': 'future_reason', 'count': 1},
|
||||
{'code': 'E3101', 'reason': None, 'count': 1},
|
||||
{'code': 'E7006', 'reason': None, 'count': 3},
|
||||
{'code': 'E7006', 'reason': 'move_copy', 'count': 1},
|
||||
{'code': 'E7006', 'reason': 'zero_not_zeroable', 'count': 1}])
|
||||
totals = {}
|
||||
for row in pairs:
|
||||
totals[row['code']] = totals.get(row['code'], 0) + row['count']
|
||||
self.assertEqual(totals, report._diagnostic_codes(r, d))
|
||||
|
||||
def test_native_outputs_and_unavailable_logs(self):
|
||||
r = {'track': 'B', 'agent': {'name': 'claude'}, 'language': {'name': 'aji_source'}}
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
self.assertIsNone(report._diagnostic_reasons(r, d))
|
||||
open(os.path.join(d, 'transcript.jsonl'), 'w').close()
|
||||
outputs = [(None, None, '{"code":"E7006","reason":"move_borrow"}\n')]
|
||||
with patch('ajieval.native.command_events', return_value=outputs):
|
||||
self.assertEqual(report._diagnostic_reasons(r, d), [
|
||||
{'code': 'E7006', 'reason': 'move_borrow', 'count': 1}])
|
||||
self.assertIsNone(report._diagnostic_reasons({'language': {'name': 'rust'}}, d))
|
||||
|
||||
def test_spaced_records_do_not_change_legacy_code_counts(self):
|
||||
r = {'language': {'name': 'aji_source'}}
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
self.events(d, ['{"code": "E7006", "reason": "move_copy"}\n'
|
||||
'{"code":"E7006"}\n'])
|
||||
# The historical code-count extractor deliberately remains intact.
|
||||
# A spaced record it did not count cannot consume another record's
|
||||
# unknown bucket and manufacture known Copy evidence.
|
||||
self.assertEqual(report._diagnostic_reasons(r, d), [
|
||||
{'code': 'E7006', 'reason': None, 'count': 1}])
|
||||
|
||||
def test_summary_counts_runs_once_and_reports_log_coverage(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
runs = []
|
||||
for i in range(3):
|
||||
d = os.path.join(root, str(i)); os.makedirs(d)
|
||||
r = {'task': {'id': 'synthetic'}, 'language': {'name': 'aji_source'},
|
||||
'model': {'id': 'test', 'class': 'test'}, 'accepted': False,
|
||||
'metrics': {'context': {}}, '_dir': d}
|
||||
runs.append(r)
|
||||
with open(os.path.join(d, 'run.json'), 'w') as f:
|
||||
json.dump(r, f)
|
||||
if i != 2:
|
||||
output = ('{"code":"E7006","reason":"move_copy"}\n' * 2
|
||||
if i == 0 else '{"code":"E7006"}\n')
|
||||
self.events(d, [output])
|
||||
text = report.summary([root])
|
||||
self.assertIn('| aji_source | E7006 | move_copy | 2 | 1 | 2/3 |', text)
|
||||
self.assertIn('| aji_source | E7006 | unknown | 1 | 1 | 2/3 |', text)
|
||||
self.assertIn('observed command outputs', text)
|
||||
rows = report.checkpoint_rows([os.path.join(root, '0'), os.path.join(root, '1')])
|
||||
pairs = [p for row in rows for p in (row['diagnostic_reasons'] or [])]
|
||||
self.assertIn({'code': 'E7006', 'reason': 'move_copy', 'count': 2}, pairs)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user