docs/evaluation/b1-heldout-plan.md: Rust, Zig, Aji/source x 3 native agents x 6 tasks (families A/B/C, capability descriptions only) x 3 runs = 162; metrics, analysis plan, decision rules; owner decisions D1-D5 requested. Phases 7 and 8 on hold. ajieval: statically prevented safety diagnostics, unsafe usage, atomic error kind in classify, vsr table with Wilson intervals.
46 lines
2.2 KiB
Python
46 lines
2.2 KiB
Python
"""B1 metrics (docs/evaluation/b1-heldout-plan.md §5–§6)."""
|
|
|
|
import os
|
|
import tempfile
|
|
import unittest
|
|
|
|
from ajieval import report
|
|
|
|
|
|
class B1Metrics(unittest.TestCase):
|
|
def test_wilson(self):
|
|
lo, hi = report.wilson(9, 18)
|
|
self.assertAlmostEqual((lo + hi) / 2, 0.5, places=6)
|
|
self.assertTrue(0.28 < lo < 0.30 and 0.70 < hi < 0.72)
|
|
self.assertEqual(report.wilson(0, 0), (0.0, 0.0))
|
|
lo, hi = report.wilson(18, 18)
|
|
self.assertAlmostEqual(hi, 1.0)
|
|
self.assertTrue(lo > 0.8)
|
|
|
|
def test_statically_prevented(self):
|
|
rust = {"language": {"name": "rust"}}
|
|
aji = {"language": {"name": "aji_source"}}
|
|
zig = {"language": {"name": "zig"}}
|
|
# E0382 (use after move) and E0499 (two mutable borrows) count; E0308 (types) does not.
|
|
with tempfile.TemporaryDirectory() as d:
|
|
open(os.path.join(d, "events.jsonl"), "w").close()
|
|
self.assertEqual(report.statically_prevented(rust, d, {"E0382": 2, "E0499": 1, "E0308": 5}), 3)
|
|
# E2001 (ownership), E4202 (atomic) count; E7005 (source type) and E1001 do not.
|
|
self.assertEqual(report.statically_prevented(aji, d, {"E2001": 1, "E4202": 2, "E7005": 3, "E1001": 1}), 3)
|
|
self.assertEqual(report.statically_prevented(zig, d, {"error": 4}), 0)
|
|
|
|
def test_unsafe_usage(self):
|
|
with tempfile.TemporaryDirectory() as d:
|
|
ws = os.path.join(d, "workspace")
|
|
os.makedirs(os.path.join(ws, "src"))
|
|
open(os.path.join(ws, "src", "main.rs"), "w").write("// unsafe in a comment\nfn f() { unsafe { g() } }\nunsafe fn g() {}\n")
|
|
self.assertEqual(report.unsafe_usage({"language": {"name": "rust"}}, d), 2)
|
|
open(os.path.join(ws, "main.aji"), "w").write("fn f(s: slice<u8>) -> u8\neffects [unsafe]\n{\n ref unchecked x = s[0];\n *x\n}\n")
|
|
self.assertEqual(report.unsafe_usage({"language": {"name": "aji_source"}}, d), 2)
|
|
open(os.path.join(ws, "main.zig"), "w").write("const p: *u8 = @ptrCast(q); // @ptrCast\n")
|
|
self.assertEqual(report.unsafe_usage({"language": {"name": "zig"}}, d), 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|