From 38312e16f7ae22aeb433823c4a00a2cc80e23d0b Mon Sep 17 00:00:00 2001 From: OpenAI Codex Date: Thu, 29 Oct 2026 18:33:54 +0000 Subject: [PATCH] cbz: consolidate verified source auditors and close lexer gaps --- .../DECISION_ADDENDUM.md | 6 + cbz/evidence/auditor-consolidation/README.md | 22 + .../auditor-consolidation/REGISTRY.json | 46 ++ cbz/evidence/auditor-consolidation/SHA256SUMS | 48 ++ .../auditor-consolidation/VERIFICATION.json | 50 ++ .../current-review-replay.json | 94 +++ .../auditor-consolidation/hardening-red.log | 282 ++++++++ .../identifier-escape-red.log | 69 ++ .../independent-p1-red.log | 47 ++ .../independent-review/REVIEW.md | 12 + .../final-five-fixture-results.json | 70 ++ .../macro-string-final-lean.log | 2 + .../macro-string-final-scan.json | 22 + .../independent-review/macro-string-lean.log | 2 + .../independent-review/macro-string-scan.json | 11 + .../independent-review/macro-string-scan.log | 1 + .../independent-review/macro-string.lean.txt | 5 + .../numeral-adjacency-lean.log | 8 + .../numeral-adjacency-scan.json | 11 + .../numeral-adjacency.lean.txt | 3 + .../numeral-command-final-lean.log | 1 + .../numeral-command-final-scan.json | 22 + .../numeral-command-lean.log | 1 + .../numeral-command-scan.json | 11 + .../numeral-command.lean.txt | 3 + .../radix-command-final-lean.log | 3 + .../radix-command-final-scan.json | 42 ++ .../independent-review/radix-command-lean.log | 3 + .../radix-command-scan.json | 22 + .../independent-review/radix-command.lean.txt | 6 + .../scientific-command-final-lean.log | 1 + .../scientific-command-final-scan.json | 22 + .../scientific-command-lean.log | 1 + .../scientific-command-scan.json | 11 + .../scientific-command.lean.txt | 3 + .../successor-two-fixture-scan.json | 32 + .../unicode-char-final-lean.log | 1 + .../unicode-char-final-scan.json | 11 + .../independent-review/unicode-char-lean.log | 1 + .../independent-review/unicode-char-scan.json | 22 + .../independent-review/unicode-char.lean.txt | 2 + .../interpolation-layout-red.log | 53 ++ .../native-expression-red.log | 341 ++++++++++ .../native-expressions-lean.log | 4 + .../native-expressions-scan.json | 42 ++ .../native-expressions.lean.txt | 8 + .../numeral-prime-red.log | 253 +++++++ .../auditor-consolidation/v4-final-normal.log | 5 + .../v4-final-optimized.log | 5 + docs/cbz/CANONICAL_AUDITORS.md | 114 ++++ tests/test_cbz_a3_float_census.py | 228 +++++++ tests/test_cbz_auditor_hardening.py | 202 ++++++ tests/test_cbz_layer_a_scan.py | 293 +++++++++ tests/test_cbz_layer_a_scan_mutants.py | 157 +++++ tools/cbz/a3_float_census.py | 299 +++++++++ tools/cbz/layer_a_scan.py | 621 ++++++++++++++++++ 56 files changed, 3657 insertions(+) create mode 100644 cbz/evidence/auditor-consolidation/DECISION_ADDENDUM.md create mode 100644 cbz/evidence/auditor-consolidation/README.md create mode 100644 cbz/evidence/auditor-consolidation/REGISTRY.json create mode 100644 cbz/evidence/auditor-consolidation/SHA256SUMS create mode 100644 cbz/evidence/auditor-consolidation/VERIFICATION.json create mode 100644 cbz/evidence/auditor-consolidation/current-review-replay.json create mode 100644 cbz/evidence/auditor-consolidation/hardening-red.log create mode 100644 cbz/evidence/auditor-consolidation/identifier-escape-red.log create mode 100644 cbz/evidence/auditor-consolidation/independent-p1-red.log create mode 100644 cbz/evidence/auditor-consolidation/independent-review/REVIEW.md create mode 100644 cbz/evidence/auditor-consolidation/independent-review/final-five-fixture-results.json create mode 100644 cbz/evidence/auditor-consolidation/independent-review/macro-string-final-lean.log create mode 100644 cbz/evidence/auditor-consolidation/independent-review/macro-string-final-scan.json create mode 100644 cbz/evidence/auditor-consolidation/independent-review/macro-string-lean.log create mode 100644 cbz/evidence/auditor-consolidation/independent-review/macro-string-scan.json create mode 100644 cbz/evidence/auditor-consolidation/independent-review/macro-string-scan.log create mode 100644 cbz/evidence/auditor-consolidation/independent-review/macro-string.lean.txt create mode 100644 cbz/evidence/auditor-consolidation/independent-review/numeral-adjacency-lean.log create mode 100644 cbz/evidence/auditor-consolidation/independent-review/numeral-adjacency-scan.json create mode 100644 cbz/evidence/auditor-consolidation/independent-review/numeral-adjacency.lean.txt create mode 100644 cbz/evidence/auditor-consolidation/independent-review/numeral-command-final-lean.log create mode 100644 cbz/evidence/auditor-consolidation/independent-review/numeral-command-final-scan.json create mode 100644 cbz/evidence/auditor-consolidation/independent-review/numeral-command-lean.log create mode 100644 cbz/evidence/auditor-consolidation/independent-review/numeral-command-scan.json create mode 100644 cbz/evidence/auditor-consolidation/independent-review/numeral-command.lean.txt create mode 100644 cbz/evidence/auditor-consolidation/independent-review/radix-command-final-lean.log create mode 100644 cbz/evidence/auditor-consolidation/independent-review/radix-command-final-scan.json create mode 100644 cbz/evidence/auditor-consolidation/independent-review/radix-command-lean.log create mode 100644 cbz/evidence/auditor-consolidation/independent-review/radix-command-scan.json create mode 100644 cbz/evidence/auditor-consolidation/independent-review/radix-command.lean.txt create mode 100644 cbz/evidence/auditor-consolidation/independent-review/scientific-command-final-lean.log create mode 100644 cbz/evidence/auditor-consolidation/independent-review/scientific-command-final-scan.json create mode 100644 cbz/evidence/auditor-consolidation/independent-review/scientific-command-lean.log create mode 100644 cbz/evidence/auditor-consolidation/independent-review/scientific-command-scan.json create mode 100644 cbz/evidence/auditor-consolidation/independent-review/scientific-command.lean.txt create mode 100644 cbz/evidence/auditor-consolidation/independent-review/successor-two-fixture-scan.json create mode 100644 cbz/evidence/auditor-consolidation/independent-review/unicode-char-final-lean.log create mode 100644 cbz/evidence/auditor-consolidation/independent-review/unicode-char-final-scan.json create mode 100644 cbz/evidence/auditor-consolidation/independent-review/unicode-char-lean.log create mode 100644 cbz/evidence/auditor-consolidation/independent-review/unicode-char-scan.json create mode 100644 cbz/evidence/auditor-consolidation/independent-review/unicode-char.lean.txt create mode 100644 cbz/evidence/auditor-consolidation/interpolation-layout-red.log create mode 100644 cbz/evidence/auditor-consolidation/native-expression-red.log create mode 100644 cbz/evidence/auditor-consolidation/native-expressions-lean.log create mode 100644 cbz/evidence/auditor-consolidation/native-expressions-scan.json create mode 100644 cbz/evidence/auditor-consolidation/native-expressions.lean.txt create mode 100644 cbz/evidence/auditor-consolidation/numeral-prime-red.log create mode 100644 cbz/evidence/auditor-consolidation/v4-final-normal.log create mode 100644 cbz/evidence/auditor-consolidation/v4-final-optimized.log create mode 100644 docs/cbz/CANONICAL_AUDITORS.md create mode 100644 tests/test_cbz_a3_float_census.py create mode 100644 tests/test_cbz_auditor_hardening.py create mode 100644 tests/test_cbz_layer_a_scan.py create mode 100644 tests/test_cbz_layer_a_scan_mutants.py create mode 100644 tools/cbz/a3_float_census.py create mode 100644 tools/cbz/layer_a_scan.py diff --git a/cbz/evidence/auditor-consolidation/DECISION_ADDENDUM.md b/cbz/evidence/auditor-consolidation/DECISION_ADDENDUM.md new file mode 100644 index 000000000..1d93534bc --- /dev/null +++ b/cbz/evidence/auditor-consolidation/DECISION_ADDENDUM.md @@ -0,0 +1,6 @@ +# Proposed append-only ledger entry + +[2026-10-29T18:33:13Z] [phase2] [layer B/C] [consolidate overlapping finite source auditors] [ULW29ef5b924 provides the strongest portable basis; retain compatible main687/014K regression requirements and preserve all old declared controls. Repair actual pinned-Lean counterexamples before admission. Use one canonical Main tool pair; do not replace Root's existing census, certify semantic bounds from A3 classes, or infer kernel closure from lexical results.] [reversible: yes — ordinary Git additions] [cbz/evidence/auditor-consolidation/VERIFICATION.json; docs/cbz/CANONICAL_AUDITORS.md] + +Canonical Root owns GOVERNANCE/TOOLING/STATUS/DECISIONS integration under B-003. +This file is proposed addenda and does not silently amend those surfaces. diff --git a/cbz/evidence/auditor-consolidation/README.md b/cbz/evidence/auditor-consolidation/README.md new file mode 100644 index 000000000..e36638c13 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/README.md @@ -0,0 +1,22 @@ +# Auditor consolidation evidence + +Canonical implementation candidate based on ULW29ef5b924, preserving its controls +and integrating compatible peer regressions. Read docs/cbz/CANONICAL_AUDITORS.md. +VERIFICATION.json binds the final working source bytes and observed72-test runs. +REGISTRY.json is proposed addenda for Root, not a claim canonical registry is +already updated. No full federation G0-G11 or CBZ-0 result is claimed. + +The independent-review directory preserves a historical frozen-source AMEND +review, exact actual Lean counterexamples and successor replays. Review states +are bound to their written source hashes, not silently transferred to new heads. +current-review-replay.json binds a further replay to the current scanner bytes. +Native-expression raw outputs show four valid Lean theorem proofs using fresh +compiler-trust axioms, all rejected by the repaired source scanner. + +Every .lean.txt is deliberately adversarial test data, never a production Lean +module, closed mathematical obligation, or import of closed code. The original +bytes are retained exactly. Tests generate actual standalone source in temporary +areas; the compiler observations establish counterexamples to an earlier scanner, +not accepted proofs. Red logs remain evidence of defects repaired in this unit. +The repository-wide semantic closure and submodule-pin admission are outside +this contribution. diff --git a/cbz/evidence/auditor-consolidation/REGISTRY.json b/cbz/evidence/auditor-consolidation/REGISTRY.json new file mode 100644 index 000000000..b206ab0f0 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/REGISTRY.json @@ -0,0 +1,46 @@ +{ + "tools": [ + { + "path": "tools/cbz/layer_a_scan.py", + "purpose": "finite Lean source-token scanner, tracked-Git or explicit filesystem source", + "usage": "python3.11 -B -S tools/cbz/layer_a_scan.py --git REPO --rev EXACT_COMMIT --fail-on all --json OUTSIDE_SOURCE.json", + "verification": "two72-test normal/optimized suites;66source mutants all killed via named assertion failures; actual pinnedLean counterexamples replayed", + "owner": "none — self-contained", + "cbz_criteria": [ + 4, + 9, + 11 + ], + "gates": [ + "G0", + "finite necessary source portion of G1" + ], + "limitations": [ + "Gitlinks require separately pinned admission; ULW45a80ab0 is rejected with exit2 until resolved.", + "Lexical results do not see arbitrary macros/elaboration/imports; G2-G4 remain authoritative." + ] + }, + { + "path": "tools/cbz/a3_float_census.py", + "purpose": "finite Python AST floating/exact/interval signal inventory, never semantic bound certification", + "usage": "python3.11 -B -S tools/cbz/a3_float_census.py --git REPO --rev EXACT_COMMIT --json OUTSIDE_SOURCE.json", + "verification": "same normal/optimized suites;23source mutants all killed; syntax/import/launch errors not kills", + "owner": "none — self-contained", + "cbz_criteria": [ + 4, + 9, + 11 + ], + "gates": [ + "G0", + "A3source triage only" + ], + "limitations": [ + "A3census does not certify mathematical bounds or exactness; no semantic A3 closure inferred." + ] + } + ], + "canonical_registration_owner": "Root per B-003; proposed addenda only", + "source_doc": "docs/cbz/CANONICAL_AUDITORS.md", + "verification": "cbz/evidence/auditor-consolidation/VERIFICATION.json" +} diff --git a/cbz/evidence/auditor-consolidation/SHA256SUMS b/cbz/evidence/auditor-consolidation/SHA256SUMS new file mode 100644 index 000000000..f61b10650 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/SHA256SUMS @@ -0,0 +1,48 @@ +cd29a57928b77c374c5dbaa22c4c73b1d1f75aea3a3fe0ad2058fe345b9475f9 DECISION_ADDENDUM.md +811ac6978a8a0f04631666a45c2f9976c9fb3cc22f8e5ffd368d227ba299d3ea README.md +fd4de11664c7a676f1cbdd6f734c223869e42e53a5946fe6770a353dd510182a REGISTRY.json +43f4428c2ea5667478698e5d821eb7985fa2b7a20876981c0d14a185ea395e74 VERIFICATION.json +b95a14ac932c86bf37232aae5152028996872d8447c4c12adeda5709b8f79fa4 current-review-replay.json +f3eb644fa1c9d38ef42aca1e076f1e300e506a548f778b78e26b02573db2bf6e hardening-red.log +51a910cd883039a99f86d161c0e76bf334184c3efb7105a2c8be27b92262de23 identifier-escape-red.log +640898b95489bc92c7c346db9d31dcd6d53efb5fe88e72a6c60131c85206d5dc independent-p1-red.log +12075d7a3d7515ecf59fd315560101b41ae71cbd99ad7a74ca203ed3ae91fe60 independent-review/REVIEW.md +dd3170a10c561c128a8bb9bebbcf85f343721add9485adff1288b3e6c5a917c8 independent-review/final-five-fixture-results.json +bc79166e4825380ce31cc69aa72534ec05eb55b46ac2f4106e791aedee3c0e7c independent-review/macro-string-final-lean.log +348a7bd4fc30dc9369e62a7fab33a880f0f813c4c6c91e5ee7fcd1838c7d0cf8 independent-review/macro-string-final-scan.json +bc79166e4825380ce31cc69aa72534ec05eb55b46ac2f4106e791aedee3c0e7c independent-review/macro-string-lean.log +10a0dc3b9599fa7e6f5c48bb416aa85b3b19d5deb4cb0a30abb34496b898e707 independent-review/macro-string-scan.json +85f9108ea955174df354f516be46b543d9a597a802338bf99ff73f0fa6f59617 independent-review/macro-string-scan.log +8ac3a070483d0a0b1679db84ea243e2c3465fe700d227c5405c4ab6f23fb2555 independent-review/macro-string.lean.txt +59d3f582434d877f348cfc248ece736a3f667b343135c6e126c04ec065fed3ea independent-review/numeral-adjacency-lean.log +10a0dc3b9599fa7e6f5c48bb416aa85b3b19d5deb4cb0a30abb34496b898e707 independent-review/numeral-adjacency-scan.json +e1aed17d06a9de4d69f17d1cf8426e789224b5a3b152d7aad2cf8661e9539731 independent-review/numeral-adjacency.lean.txt +27f7d7a80eba4fe355322ffbc04a612ffe2726eabdd64d4043165fefcc39d688 independent-review/numeral-command-final-lean.log +21e72992af5a12ea565606d1bb2078595fc939304f3f5128357ff95660d7c1a9 independent-review/numeral-command-final-scan.json +27f7d7a80eba4fe355322ffbc04a612ffe2726eabdd64d4043165fefcc39d688 independent-review/numeral-command-lean.log +10a0dc3b9599fa7e6f5c48bb416aa85b3b19d5deb4cb0a30abb34496b898e707 independent-review/numeral-command-scan.json +f9f3bbbffd6c7e03732f8305473e3ed657089b2a23ad84ddf3511c0687a35075 independent-review/numeral-command.lean.txt +04fd6a3d411d51cf7763e7b1d750bd99ae6612c443e54ddafa5748c56e2ba2bc independent-review/radix-command-final-lean.log +db2f11bb8ae835f5edb53ce3e423231d6716c7703ef1ba6cbab4d954680df0ac independent-review/radix-command-final-scan.json +04fd6a3d411d51cf7763e7b1d750bd99ae6612c443e54ddafa5748c56e2ba2bc independent-review/radix-command-lean.log +19c301bdbc912dd3d456402c058a5b4572e0f9b530ddce08b815ba35cbfdd282 independent-review/radix-command-scan.json +3124a713cafa4bb2cc3664e32d7bf2cceb533c0d2b860299655294d317641d1c independent-review/radix-command.lean.txt +27f7d7a80eba4fe355322ffbc04a612ffe2726eabdd64d4043165fefcc39d688 independent-review/scientific-command-final-lean.log +b357b2f48cca2bc93cacd4339b66515d88f06242850cdea067262fed549bde69 independent-review/scientific-command-final-scan.json +27f7d7a80eba4fe355322ffbc04a612ffe2726eabdd64d4043165fefcc39d688 independent-review/scientific-command-lean.log +10a0dc3b9599fa7e6f5c48bb416aa85b3b19d5deb4cb0a30abb34496b898e707 independent-review/scientific-command-scan.json +c584f4815e38be6b082ce997f7ac4d7adc41a8b4ab0ee5875649cd9d9faeef36 independent-review/scientific-command.lean.txt +3828cd28ef8212aa292d8b4c161ac72552b4e79b1159a2df39c2bcc71f47b5d4 independent-review/successor-two-fixture-scan.json +173e4207cd2442ce88b6b733f0ab8f8df3a89243d133af82dc33b99714e12c61 independent-review/unicode-char-final-lean.log +10a0dc3b9599fa7e6f5c48bb416aa85b3b19d5deb4cb0a30abb34496b898e707 independent-review/unicode-char-final-scan.json +173e4207cd2442ce88b6b733f0ab8f8df3a89243d133af82dc33b99714e12c61 independent-review/unicode-char-lean.log +27e8b66440bac78c28022a0a83cf4ae56faf7b976fca90fe62924a6e2f661dbd independent-review/unicode-char-scan.json +62a75ca0fa51ad8bd00b48b23e3738792b8d3af7eb0a7e810148c798206f65d3 independent-review/unicode-char.lean.txt +2ef3cf7af4aa31bdd418946cb9444dd3a13abcf6f1191896c4c1c54cbd7bbb15 interpolation-layout-red.log +2589f0a942f862e728a10c06ce2097ef8bbdcd8a518fd9d948e36bca2baf47de native-expression-red.log +29044f47ad2d3f821bbe23b6dc9369fadffdb777d731ef1ffa099fb0cec9a56b native-expressions-lean.log +d1bf2e8e1bf03dba99f425685fffdfe93410950842c43494ca877a5b7c62c6b4 native-expressions-scan.json +bd9ec74a033cc04f5b24e83292476b421c2311e79204a7c5bbf6e9df7837f2d6 native-expressions.lean.txt +4cebfae9e19607f16608284826d87c38ea7cf359366f9e69c6a890134a6d22a1 numeral-prime-red.log +2dea1bc8d01355db8a1f9704ef453f6ef23f283d610fea833725796d129f8c89 v4-final-normal.log +9b5fac2a2cd784f6f89e6d60ebd199d7af3b1e97439f4736c57ee61a96ca9c8d v4-final-optimized.log diff --git a/cbz/evidence/auditor-consolidation/VERIFICATION.json b/cbz/evidence/auditor-consolidation/VERIFICATION.json new file mode 100644 index 000000000..435bb9c9c --- /dev/null +++ b/cbz/evidence/auditor-consolidation/VERIFICATION.json @@ -0,0 +1,50 @@ +{ + "observed_utc": "2026-10-29T18:33:13.800535+00:00", + "scope": "finite lexical source and AST-signal auditors only; no kernel/semantic/global CBZ qualification", + "python": "CPython3.11.16", + "base_commit": "27c89b05bd2503c580b692f57146d608a7f0f668", + "sources": { + "tools/cbz/layer_a_scan.py": "9ed661b1490f73c4dc3664a33ed688e937c1c7d8fecfb4d48c5349fa41823818", + "tools/cbz/a3_float_census.py": "882b6f611aaf14e30c314ab25ef17a787eed579dbc2591b0720341174df10d90", + "tests/test_cbz_layer_a_scan.py": "3f6f666e0a8cc9d4415d8e87a3cbc4fa879fb34becf3cdf1602137a266d5a0ed", + "tests/test_cbz_layer_a_scan_mutants.py": "170d158de2f3d1a8c1d7d96dc5d8d2893333eea30786eef769ad021d6c31d121", + "tests/test_cbz_a3_float_census.py": "da19b8436089be8300236cd3f363a82e7db1dd3aab10751a75ee9255a45700a9", + "tests/test_cbz_auditor_hardening.py": "f31d43830b807f4c3f593181e2ccbdae8bf08393456b8d464d30d4277f222fdb" + }, + "normal": { + "tests": 72, + "exit": 0, + "duration_seconds_decimal": "110.936", + "log": "v4-final-normal.log" + }, + "optimized": { + "tests": 72, + "exit": 0, + "duration_seconds_decimal": "118.016", + "log": "v4-final-optimized.log" + }, + "source_mutations": { + "lexical": 66, + "a3": 23, + "threshold_percent": 100, + "killed": 89, + "survivors": 0, + "stale_anchors": 0, + "kill_requires": "designated named assertion failure; errors/import/launch/syntax/unrelated failures cannot kill" + }, + "scoped_source_probe": { + "repo": "Math-", + "commit": "8151f592918a845bf19eb8eafaf8444540a32734", + "lean_blobs": 162, + "violations": 0, + "lex_errors": 0, + "exit": 0, + "not_final_federation_gate": true + }, + "remaining_boundaries": [ + "Gitlinks require separately pinned admission; ULW45a80ab0 is rejected with exit2 until resolved.", + "Lexical results do not see arbitrary macros/elaboration/imports; G2-G4 remain authoritative.", + "A3census does not certify mathematical bounds or exactness; no semantic A3 closure inferred.", + "Full preexisting regression/hosted/federation final gates not run by this contribution." + ] +} diff --git a/cbz/evidence/auditor-consolidation/current-review-replay.json b/cbz/evidence/auditor-consolidation/current-review-replay.json new file mode 100644 index 000000000..b5876ded5 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/current-review-replay.json @@ -0,0 +1,94 @@ +{ + "scanner_sha256": "9ed661b1490f73c4dc3664a33ed688e937c1c7d8fecfb4d48c5349fa41823818", + "fixtures": [ + { + "fixture": "macro-string", + "source_sha256": "8ac3a070483d0a0b1679db84ea243e2c3465fe700d227c5405c4ab6f23fb2555", + "findings": [ + { + "path": "macro-string.lean", + "line": 4, + "col": 58, + "token": "sorry", + "kind": "sorry", + "layer": "A1", + "severity": "violation", + "context": "production" + } + ] + }, + { + "fixture": "numeral-command", + "source_sha256": "f9f3bbbffd6c7e03732f8305473e3ed657089b2a23ad84ddf3511c0687a35075", + "findings": [ + { + "path": "numeral-command.lean", + "line": 1, + "col": 18, + "token": "axiom", + "kind": "axiom", + "layer": "A2", + "severity": "violation", + "context": "production" + } + ] + }, + { + "fixture": "scientific-command", + "source_sha256": "c584f4815e38be6b082ce997f7ac4d7adc41a8b4ab0ee5875649cd9d9faeef36", + "findings": [ + { + "path": "scientific-command.lean", + "line": 1, + "col": 20, + "token": "axiom", + "kind": "axiom", + "layer": "A2", + "severity": "violation", + "context": "production" + } + ] + }, + { + "fixture": "radix-command", + "source_sha256": "3124a713cafa4bb2cc3664e32d7bf2cceb533c0d2b860299655294d317641d1c", + "findings": [ + { + "path": "radix-command.lean", + "line": 1, + "col": 18, + "token": "axiom", + "kind": "axiom", + "layer": "A2", + "severity": "violation", + "context": "production" + }, + { + "path": "radix-command.lean", + "line": 2, + "col": 17, + "token": "axiom", + "kind": "axiom", + "layer": "A2", + "severity": "violation", + "context": "production" + }, + { + "path": "radix-command.lean", + "line": 3, + "col": 23, + "token": "axiom", + "kind": "axiom", + "layer": "A2", + "severity": "violation", + "context": "production" + } + ] + }, + { + "fixture": "unicode-char", + "source_sha256": "62a75ca0fa51ad8bd00b48b23e3738792b8d3af7eb0a7e810148c798206f65d3", + "findings": [] + } + ] +} diff --git a/cbz/evidence/auditor-consolidation/hardening-red.log b/cbz/evidence/auditor-consolidation/hardening-red.log new file mode 100644 index 000000000..aed00d71b --- /dev/null +++ b/cbz/evidence/auditor-consolidation/hardening-red.log @@ -0,0 +1,282 @@ +FFFFFFFFFFFFFFFFFFFF.FFFF +====================================================================== +FAIL: test_git_source_symlink_fails_for_both_tools (tests.test_cbz_auditor_hardening.InputCoverage.test_git_source_symlink_fails_for_both_tools) (tool=PosixPath('/workspace/cbz/auditor-review/tools/cbz/layer_a_scan.py')) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 87, in test_git_source_symlink_fails_for_both_tools + with self.subTest(tool=tool): self.assertEqual(cli(tool,'--git',root).returncode,2) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: 0 != 2 + +====================================================================== +FAIL: test_git_source_symlink_fails_for_both_tools (tests.test_cbz_auditor_hardening.InputCoverage.test_git_source_symlink_fails_for_both_tools) (tool=PosixPath('/workspace/cbz/auditor-review/tools/cbz/a3_float_census.py')) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 87, in test_git_source_symlink_fails_for_both_tools + with self.subTest(tool=tool): self.assertEqual(cli(tool,'--git',root).returncode,2) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: 0 != 2 + +====================================================================== +FAIL: test_gitlink_is_explicitly_rejected_by_both_tools (tests.test_cbz_auditor_hardening.InputCoverage.test_gitlink_is_explicitly_rejected_by_both_tools) (tool=PosixPath('/workspace/cbz/auditor-review/tools/cbz/layer_a_scan.py')) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 95, in test_gitlink_is_explicitly_rejected_by_both_tools + with self.subTest(tool=tool): self.assertEqual(cli(tool,'--git',root).returncode,2) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: 0 != 2 + +====================================================================== +FAIL: test_gitlink_is_explicitly_rejected_by_both_tools (tests.test_cbz_auditor_hardening.InputCoverage.test_gitlink_is_explicitly_rejected_by_both_tools) (tool=PosixPath('/workspace/cbz/auditor-review/tools/cbz/a3_float_census.py')) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 95, in test_gitlink_is_explicitly_rejected_by_both_tools + with self.subTest(tool=tool): self.assertEqual(cli(tool,'--git',root).returncode,2) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: 0 != 2 + +====================================================================== +FAIL: test_missing_root_fails_for_both_tools (tests.test_cbz_auditor_hardening.InputCoverage.test_missing_root_fails_for_both_tools) (tool=PosixPath('/workspace/cbz/auditor-review/tools/cbz/layer_a_scan.py')) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 64, in test_missing_root_fails_for_both_tools + self.assertEqual(p.returncode,2,p.stdout+p.stderr) +AssertionError: 0 != 2 : {"files": 0, "findings": 0, "violations": 0, "errors": 0, "failing": 0, "undecodable": []} + + +====================================================================== +FAIL: test_missing_root_fails_for_both_tools (tests.test_cbz_auditor_hardening.InputCoverage.test_missing_root_fails_for_both_tools) (tool=PosixPath('/workspace/cbz/auditor-review/tools/cbz/a3_float_census.py')) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 64, in test_missing_root_fails_for_both_tools + self.assertEqual(p.returncode,2,p.stdout+p.stderr) +AssertionError: 0 != 2 : {"files": 0, "by_class": {}} + + +====================================================================== +FAIL: test_source_symlink_fails_for_both_tools (tests.test_cbz_auditor_hardening.InputCoverage.test_source_symlink_fails_for_both_tools) (tool=PosixPath('/workspace/cbz/auditor-review/tools/cbz/layer_a_scan.py')) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 73, in test_source_symlink_fails_for_both_tools + self.assertEqual(p.returncode,2,p.stdout+p.stderr) +AssertionError: 0 != 2 : {"files": 1, "findings": 0, "violations": 0, "errors": 0, "failing": 0, "undecodable": []} + + +====================================================================== +FAIL: test_source_symlink_fails_for_both_tools (tests.test_cbz_auditor_hardening.InputCoverage.test_source_symlink_fails_for_both_tools) (tool=PosixPath('/workspace/cbz/auditor-review/tools/cbz/a3_float_census.py')) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 73, in test_source_symlink_fails_for_both_tools + self.assertEqual(p.returncode,2,p.stdout+p.stderr) +AssertionError: 0 != 2 : {"files": 1, "by_class": {"NO_FLOAT_SIGNAL": 1}} + + +====================================================================== +FAIL: test_symlink_directory_is_not_silently_skipped (tests.test_cbz_auditor_hardening.InputCoverage.test_symlink_directory_is_not_silently_skipped) (tool=PosixPath('/workspace/cbz/auditor-review/tools/cbz/layer_a_scan.py')) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 78, in test_symlink_directory_is_not_silently_skipped + with self.subTest(tool=tool): self.assertEqual(cli(tool,root).returncode,2) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: 0 != 2 + +====================================================================== +FAIL: test_symlink_directory_is_not_silently_skipped (tests.test_cbz_auditor_hardening.InputCoverage.test_symlink_directory_is_not_silently_skipped) (tool=PosixPath('/workspace/cbz/auditor-review/tools/cbz/a3_float_census.py')) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 78, in test_symlink_directory_is_not_silently_skipped + with self.subTest(tool=tool): self.assertEqual(cli(tool,root).returncode,2) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: 0 != 2 + +====================================================================== +FAIL: test_native_configuration_layout_is_not_a_bypass (tests.test_cbz_auditor_hardening.LexicalUnion.test_native_configuration_layout_is_not_a_bypass) (src='by decide (config := { native /- a /- b -/ c -/ := true })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 37, in test_native_configuration_layout_is_not_a_bypass + self.assertEqual(kinds(src), ['native']) +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_native_configuration_layout_is_not_a_bypass (tests.test_cbz_auditor_hardening.LexicalUnion.test_native_configuration_layout_is_not_a_bypass) (src='by decide (config := { native := /- x -/ true })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 37, in test_native_configuration_layout_is_not_a_bypass + self.assertEqual(kinds(src), ['native']) +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_native_configuration_layout_is_not_a_bypass (tests.test_cbz_auditor_hardening.LexicalUnion.test_native_configuration_layout_is_not_a_bypass) (src='by decide (config := { native -- comment\n := -- c\n true })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 37, in test_native_configuration_layout_is_not_a_bypass + self.assertEqual(kinds(src), ['native']) +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_native_configuration_layout_is_not_a_bypass (tests.test_cbz_auditor_hardening.LexicalUnion.test_native_configuration_layout_is_not_a_bypass) (src='by decide (config := { native :=true })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 37, in test_native_configuration_layout_is_not_a_bypass + self.assertEqual(kinds(src), ['native']) +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_native_false_and_longer_identifiers_are_not_true (tests.test_cbz_auditor_hardening.LexicalUnion.test_native_false_and_longer_identifiers_are_not_true) (src='native := true₁') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 43, in test_native_false_and_longer_identifiers_are_not_true + with self.subTest(src=src): self.assertEqual(kinds(src), []) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: ['native'] != [] + +First list contains 1 additional elements. +First extra element 0: +'native' + +- ['native'] ++ [] + +====================================================================== +FAIL: test_native_false_and_longer_identifiers_are_not_true (tests.test_cbz_auditor_hardening.LexicalUnion.test_native_false_and_longer_identifiers_are_not_true) (src='native := trueα') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 43, in test_native_false_and_longer_identifiers_are_not_true + with self.subTest(src=src): self.assertEqual(kinds(src), []) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: ['native'] != [] + +First list contains 1 additional elements. +First extra element 0: +'native' + +- ['native'] ++ [] + +====================================================================== +FAIL: test_plain_macro_braces_are_conservatively_scanned (tests.test_cbz_auditor_hardening.LexicalUnion.test_plain_macro_braces_are_conservatively_scanned) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 45, in test_plain_macro_braces_are_conservatively_scanned + self.assertEqual(kinds('def e := throwError "bad {sorry}"'), ['sorry']) +AssertionError: Lists differ: [] != ['sorry'] + +Second list contains 1 additional elements. +First extra element 0: +'sorry' + +- [] ++ ['sorry'] + +====================================================================== +FAIL: test_plus_native_layout_is_not_a_bypass (tests.test_cbz_auditor_hardening.LexicalUnion.test_plus_native_layout_is_not_a_bypass) (src='by decide +\nnative') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 40, in test_plus_native_layout_is_not_a_bypass + with self.subTest(src=src): self.assertEqual(kinds(src), ['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_plus_native_layout_is_not_a_bypass (tests.test_cbz_auditor_hardening.LexicalUnion.test_plus_native_layout_is_not_a_bypass) (src='by decide + /- c -/ native') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 40, in test_plus_native_layout_is_not_a_bypass + with self.subTest(src=src): self.assertEqual(kinds(src), ['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_plus_native_layout_is_not_a_bypass (tests.test_cbz_auditor_hardening.LexicalUnion.test_plus_native_layout_is_not_a_bypass) (src='by decide + --c\n native') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 40, in test_plus_native_layout_is_not_a_bypass + with self.subTest(src=src): self.assertEqual(kinds(src), ['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unterminated_character_literal_is_error (tests.test_cbz_auditor_hardening.LexicalUnion.test_unterminated_character_literal_is_error) (src="def c := '") +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 53, in test_unterminated_character_literal_is_error + self.assertIn('unterminated_char', [f['kind'] for f in S.scan_text(src,'M.lean')]) +AssertionError: 'unterminated_char' not found in [] + +====================================================================== +FAIL: test_unterminated_character_literal_is_error (tests.test_cbz_auditor_hardening.LexicalUnion.test_unterminated_character_literal_is_error) (src="def c := '\\") +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 53, in test_unterminated_character_literal_is_error + self.assertIn('unterminated_char', [f['kind'] for f in S.scan_text(src,'M.lean')]) +AssertionError: 'unterminated_char' not found in [] + +====================================================================== +FAIL: test_unterminated_character_literal_is_error (tests.test_cbz_auditor_hardening.LexicalUnion.test_unterminated_character_literal_is_error) (src="def c := '\\n") +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 53, in test_unterminated_character_literal_is_error + self.assertIn('unterminated_char', [f['kind'] for f in S.scan_text(src,'M.lean')]) +AssertionError: 'unterminated_char' not found in [] + +====================================================================== +FAIL: test_unterminated_character_literal_is_error (tests.test_cbz_auditor_hardening.LexicalUnion.test_unterminated_character_literal_is_error) (src='def c := \'"\n') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 53, in test_unterminated_character_literal_is_error + self.assertIn('unterminated_char', [f['kind'] for f in S.scan_text(src,'M.lean')]) +AssertionError: 'unterminated_char' not found in ['unterminated_string'] + +---------------------------------------------------------------------- +Ran 11 tests in 0.334s + +FAILED (failures=24) diff --git a/cbz/evidence/auditor-consolidation/identifier-escape-red.log b/cbz/evidence/auditor-consolidation/identifier-escape-red.log new file mode 100644 index 000000000..b4da6a40c --- /dev/null +++ b/cbz/evidence/auditor-consolidation/identifier-escape-red.log @@ -0,0 +1,69 @@ +FFFFF +====================================================================== +FAIL: test_pinned_lean_identifier_character_domain (tests.test_cbz_auditor_hardening.LexicalUnion.test_pinned_lean_identifier_character_domain) (prefix='Ж') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 96, in test_pinned_lean_identifier_character_domain + with self.subTest(prefix=prefix): self.assertEqual(kinds(prefix+'sorry'),['sorry']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['sorry'] + +Second list contains 1 additional elements. +First extra element 0: +'sorry' + +- [] ++ ['sorry'] + +====================================================================== +FAIL: test_pinned_lean_identifier_character_domain (tests.test_cbz_auditor_hardening.LexicalUnion.test_pinned_lean_identifier_character_domain) (prefix='ᵀ') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 96, in test_pinned_lean_identifier_character_domain + with self.subTest(prefix=prefix): self.assertEqual(kinds(prefix+'sorry'),['sorry']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['sorry'] + +Second list contains 1 additional elements. +First extra element 0: +'sorry' + +- [] ++ ['sorry'] + +====================================================================== +FAIL: test_pinned_lean_identifier_character_domain (tests.test_cbz_auditor_hardening.LexicalUnion.test_pinned_lean_identifier_character_domain) (prefix='𝛂') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 96, in test_pinned_lean_identifier_character_domain + with self.subTest(prefix=prefix): self.assertEqual(kinds(prefix+'sorry'),['sorry']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['sorry'] + +Second list contains 1 additional elements. +First extra element 0: +'sorry' + +- [] ++ ['sorry'] + +====================================================================== +FAIL: test_unsupported_character_escape_is_error (tests.test_cbz_auditor_hardening.LexicalUnion.test_unsupported_character_escape_is_error) (src="def c := '\\q'") +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 103, in test_unsupported_character_escape_is_error + self.assertTrue([f for f in S.scan_text(src,'M.lean') if f['severity']=='error']) +AssertionError: [] is not true + +====================================================================== +FAIL: test_unsupported_character_escape_is_error (tests.test_cbz_auditor_hardening.LexicalUnion.test_unsupported_character_escape_is_error) (src="def c := '\\u{41}'") +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 103, in test_unsupported_character_escape_is_error + self.assertTrue([f for f in S.scan_text(src,'M.lean') if f['severity']=='error']) +AssertionError: [] is not true + +---------------------------------------------------------------------- +Ran 2 tests in 0.002s + +FAILED (failures=5) diff --git a/cbz/evidence/auditor-consolidation/independent-p1-red.log b/cbz/evidence/auditor-consolidation/independent-p1-red.log new file mode 100644 index 000000000..d8f17ee22 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-p1-red.log @@ -0,0 +1,47 @@ +FFFF +====================================================================== +FAIL: test_plain_macro_holes_with_nested_literals (tests.test_cbz_auditor_hardening.LexicalUnion.test_plain_macro_holes_with_nested_literals) (src='def f := throwError "bad {let x := "safe"; (sorry : Nat)}"') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 55, in test_plain_macro_holes_with_nested_literals + with self.subTest(src=src): self.assertIn('sorry',kinds(src)) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: 'sorry' not found in [] + +====================================================================== +FAIL: test_plain_macro_holes_with_nested_literals (tests.test_cbz_auditor_hardening.LexicalUnion.test_plain_macro_holes_with_nested_literals) (src='def f := throwError "bad {let x := "safe"; /- } -/ (sorry : Nat)}"') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 55, in test_plain_macro_holes_with_nested_literals + with self.subTest(src=src): self.assertIn('sorry',kinds(src)) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: 'sorry' not found in [] + +====================================================================== +FAIL: test_plain_macro_holes_with_nested_literals (tests.test_cbz_auditor_hardening.LexicalUnion.test_plain_macro_holes_with_nested_literals) (src='def f := throwError "bad {let «odd}name» := "safe"; (sorry : Nat)}"') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 55, in test_plain_macro_holes_with_nested_literals + with self.subTest(src=src): self.assertIn('sorry',kinds(src)) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: 'sorry' not found in [] + +====================================================================== +FAIL: test_adjacent_numeral_never_swallows_code_keyword (tests.test_cbz_auditor_hardening.LexicalUnion.test_adjacent_numeral_never_swallows_code_keyword) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 57, in test_adjacent_numeral_never_swallows_code_keyword + self.assertEqual(kinds('def harmless := 0axiom hiddenPremise : False\ntheorem bad : False := hiddenPremise'),['axiom']) +AssertionError: Lists differ: [] != ['axiom'] + +Second list contains 1 additional elements. +First extra element 0: +'axiom' + +- [] ++ ['axiom'] + +---------------------------------------------------------------------- +Ran 2 tests in 0.001s + +FAILED (failures=4) diff --git a/cbz/evidence/auditor-consolidation/independent-review/REVIEW.md b/cbz/evidence/auditor-consolidation/independent-review/REVIEW.md new file mode 100644 index 000000000..b0a38496d --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/REVIEW.md @@ -0,0 +1,12 @@ +# Independent scanner review + +Reviewed frozen scanner working bytes at SHA256 `679988ace9817638867f84ada19d7171fc0b5749f313f5fb5b2a45a26e6d2fde`, on repository base `27c89b05bd2503c580b692f57146d608a7f0f668`. Candidate paths were untracked. The author confirmed this freeze before findings were delivered. Author repairs subsequently changed working bytes; this review is not a verdict on those successor bytes. + +Two P1 false negatives were observed using official Lean 4.34.1 and CPython 3.11.16. Both valid source fixtures compile with exit0 and expose a forbidden axiom through `#print axioms`, while the scanner CLI with `--fail-on all` exits0 with zero findings and lexical errors. + +1. `macro-string.lean`: builtin `throwError` interpolation containing a nested ordinary quoted string hides an explicit `sorry` term. `def f : CoreM Unit := throwError "bad {let x := "safe"; (sorry : Nat)}"`. Actual axiom set includes `sorryAx`. The primary ordinary-string scan stops at the nested quote before the interpolation hole closes; its later string then hides the placeholder. Balanced-hole postprocessing does not see the complete region. +2. `numeral-command.lean`: `def harmless := 0axiom hiddenPremise : False` followed by `theorem bad : False := hiddenPremise` is valid Lean. Actual axiom set for bad is `[hiddenPremise]`. The numeric scan consumes arbitrary alphanumeric suffixes and therefore swallows the axiom keyword in `0axiom`. Numeric token boundaries must follow Lean rather than generic isalnum. + +Exact source fixtures, compiler output, scanner JSON and scanner output are adjacent. The preliminary `numeral-adjacency.lean` attempt failed Lean elaboration/parsing; it is retained as a failed probe and is not the valid counterexample. No production source, tests, scanner working bytes, refs or remote metadata were edited by this reviewer. + +Both concrete findings were sent directly to the auditor author, root and receipt reviewer. The author confirmed the first and began source repairs; no final successor-source PASS is claimed. Kernel and semantic coverage remain separate from this finite lexical review. diff --git a/cbz/evidence/auditor-consolidation/independent-review/final-five-fixture-results.json b/cbz/evidence/auditor-consolidation/independent-review/final-five-fixture-results.json new file mode 100644 index 000000000..0c6af794b --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/final-five-fixture-results.json @@ -0,0 +1,70 @@ +{ + "scanner_sha256": "ffe9f9a384b77ac8e858e02085b459861cf8f758362db43ac101c059cb898488", + "results": [ + { + "fixture": "macro-string", + "source_sha256": "8ac3a070483d0a0b1679db84ea243e2c3465fe700d227c5405c4ab6f23fb2555", + "lean_exit": 0, + "scanner_exit": 1, + "expected_kinds": [ + "sorry" + ], + "observed_kinds": [ + "sorry" + ], + "qualifies": true + }, + { + "fixture": "numeral-command", + "source_sha256": "f9f3bbbffd6c7e03732f8305473e3ed657089b2a23ad84ddf3511c0687a35075", + "lean_exit": 0, + "scanner_exit": 1, + "expected_kinds": [ + "axiom" + ], + "observed_kinds": [ + "axiom" + ], + "qualifies": true + }, + { + "fixture": "scientific-command", + "source_sha256": "c584f4815e38be6b082ce997f7ac4d7adc41a8b4ab0ee5875649cd9d9faeef36", + "lean_exit": 0, + "scanner_exit": 1, + "expected_kinds": [ + "axiom" + ], + "observed_kinds": [ + "axiom" + ], + "qualifies": true + }, + { + "fixture": "radix-command", + "source_sha256": "3124a713cafa4bb2cc3664e32d7bf2cceb533c0d2b860299655294d317641d1c", + "lean_exit": 0, + "scanner_exit": 1, + "expected_kinds": [ + "axiom", + "axiom", + "axiom" + ], + "observed_kinds": [ + "axiom", + "axiom", + "axiom" + ], + "qualifies": true + }, + { + "fixture": "unicode-char", + "source_sha256": "62a75ca0fa51ad8bd00b48b23e3738792b8d3af7eb0a7e810148c798206f65d3", + "lean_exit": 0, + "scanner_exit": 0, + "expected_kinds": [], + "observed_kinds": [], + "qualifies": true + } + ] +} diff --git a/cbz/evidence/auditor-consolidation/independent-review/macro-string-final-lean.log b/cbz/evidence/auditor-consolidation/independent-review/macro-string-final-lean.log new file mode 100644 index 000000000..b5dd24a93 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/macro-string-final-lean.log @@ -0,0 +1,2 @@ +/workspace/cbz/discovery/scanner-independent-review/macro-string.lean:4:4: warning: declaration uses `sorry` +'f' depends on axioms: [propext, sorryAx, Classical.choice, Quot.sound] diff --git a/cbz/evidence/auditor-consolidation/independent-review/macro-string-final-scan.json b/cbz/evidence/auditor-consolidation/independent-review/macro-string-final-scan.json new file mode 100644 index 000000000..7528f64f8 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/macro-string-final-scan.json @@ -0,0 +1,22 @@ +{ + "summary": { + "files": 1, + "findings": 1, + "violations": 1, + "errors": 0, + "failing": 1, + "undecodable": [] + }, + "findings": [ + { + "path": "/workspace/cbz/discovery/scanner-independent-review/macro-string.lean", + "line": 4, + "col": 58, + "token": "sorry", + "kind": "sorry", + "layer": "A1", + "severity": "violation", + "context": "production" + } + ] +} \ No newline at end of file diff --git a/cbz/evidence/auditor-consolidation/independent-review/macro-string-lean.log b/cbz/evidence/auditor-consolidation/independent-review/macro-string-lean.log new file mode 100644 index 000000000..b5dd24a93 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/macro-string-lean.log @@ -0,0 +1,2 @@ +/workspace/cbz/discovery/scanner-independent-review/macro-string.lean:4:4: warning: declaration uses `sorry` +'f' depends on axioms: [propext, sorryAx, Classical.choice, Quot.sound] diff --git a/cbz/evidence/auditor-consolidation/independent-review/macro-string-scan.json b/cbz/evidence/auditor-consolidation/independent-review/macro-string-scan.json new file mode 100644 index 000000000..a230eeb5c --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/macro-string-scan.json @@ -0,0 +1,11 @@ +{ + "summary": { + "files": 1, + "findings": 0, + "violations": 0, + "errors": 0, + "failing": 0, + "undecodable": [] + }, + "findings": [] +} \ No newline at end of file diff --git a/cbz/evidence/auditor-consolidation/independent-review/macro-string-scan.log b/cbz/evidence/auditor-consolidation/independent-review/macro-string-scan.log new file mode 100644 index 000000000..2949cfb63 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/macro-string-scan.log @@ -0,0 +1 @@ +{"files": 1, "findings": 0, "violations": 0, "errors": 0, "failing": 0, "undecodable": []} diff --git a/cbz/evidence/auditor-consolidation/independent-review/macro-string.lean.txt b/cbz/evidence/auditor-consolidation/independent-review/macro-string.lean.txt new file mode 100644 index 000000000..3d94783f5 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/macro-string.lean.txt @@ -0,0 +1,5 @@ +import Lean +open Lean + +def f : CoreM Unit := throwError "bad {let x := "safe"; (sorry : Nat)}" +#print axioms f diff --git a/cbz/evidence/auditor-consolidation/independent-review/numeral-adjacency-lean.log b/cbz/evidence/auditor-consolidation/independent-review/numeral-adjacency-lean.log new file mode 100644 index 000000000..faed2e198 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/numeral-adjacency-lean.log @@ -0,0 +1,8 @@ +/workspace/cbz/discovery/scanner-independent-review/numeral-adjacency.lean:2:15: error: Type mismatch + z 0 +has type + Nat → Nat +but is expected to have type + Nat +/workspace/cbz/discovery/scanner-independent-review/numeral-adjacency.lean:2:18: error: unexpected token 'sorry'; expected command +'f' depends on axioms: [sorryAx] diff --git a/cbz/evidence/auditor-consolidation/independent-review/numeral-adjacency-scan.json b/cbz/evidence/auditor-consolidation/independent-review/numeral-adjacency-scan.json new file mode 100644 index 000000000..a230eeb5c --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/numeral-adjacency-scan.json @@ -0,0 +1,11 @@ +{ + "summary": { + "files": 1, + "findings": 0, + "violations": 0, + "errors": 0, + "failing": 0, + "undecodable": [] + }, + "findings": [] +} \ No newline at end of file diff --git a/cbz/evidence/auditor-consolidation/independent-review/numeral-adjacency.lean.txt b/cbz/evidence/auditor-consolidation/independent-review/numeral-adjacency.lean.txt new file mode 100644 index 000000000..54b16c2e0 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/numeral-adjacency.lean.txt @@ -0,0 +1,3 @@ +def z (a b : Nat) : Nat := a+b +def f : Nat := z 0sorry +#print axioms f diff --git a/cbz/evidence/auditor-consolidation/independent-review/numeral-command-final-lean.log b/cbz/evidence/auditor-consolidation/independent-review/numeral-command-final-lean.log new file mode 100644 index 000000000..dd8796143 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/numeral-command-final-lean.log @@ -0,0 +1 @@ +'bad' depends on axioms: [hiddenPremise] diff --git a/cbz/evidence/auditor-consolidation/independent-review/numeral-command-final-scan.json b/cbz/evidence/auditor-consolidation/independent-review/numeral-command-final-scan.json new file mode 100644 index 000000000..afae305cc --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/numeral-command-final-scan.json @@ -0,0 +1,22 @@ +{ + "summary": { + "files": 1, + "findings": 1, + "violations": 1, + "errors": 0, + "failing": 1, + "undecodable": [] + }, + "findings": [ + { + "path": "/workspace/cbz/discovery/scanner-independent-review/numeral-command.lean", + "line": 1, + "col": 18, + "token": "axiom", + "kind": "axiom", + "layer": "A2", + "severity": "violation", + "context": "production" + } + ] +} \ No newline at end of file diff --git a/cbz/evidence/auditor-consolidation/independent-review/numeral-command-lean.log b/cbz/evidence/auditor-consolidation/independent-review/numeral-command-lean.log new file mode 100644 index 000000000..dd8796143 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/numeral-command-lean.log @@ -0,0 +1 @@ +'bad' depends on axioms: [hiddenPremise] diff --git a/cbz/evidence/auditor-consolidation/independent-review/numeral-command-scan.json b/cbz/evidence/auditor-consolidation/independent-review/numeral-command-scan.json new file mode 100644 index 000000000..a230eeb5c --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/numeral-command-scan.json @@ -0,0 +1,11 @@ +{ + "summary": { + "files": 1, + "findings": 0, + "violations": 0, + "errors": 0, + "failing": 0, + "undecodable": [] + }, + "findings": [] +} \ No newline at end of file diff --git a/cbz/evidence/auditor-consolidation/independent-review/numeral-command.lean.txt b/cbz/evidence/auditor-consolidation/independent-review/numeral-command.lean.txt new file mode 100644 index 000000000..46435e50a --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/numeral-command.lean.txt @@ -0,0 +1,3 @@ +def harmless := 0axiom hiddenPremise : False +theorem bad : False := hiddenPremise +#print axioms bad diff --git a/cbz/evidence/auditor-consolidation/independent-review/radix-command-final-lean.log b/cbz/evidence/auditor-consolidation/independent-review/radix-command-final-lean.log new file mode 100644 index 000000000..297ca2c4d --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/radix-command-final-lean.log @@ -0,0 +1,3 @@ +'binaryPremise' depends on axioms: [binaryPremise] +'octalPremise' depends on axioms: [octalPremise] +'exponentPremise' depends on axioms: [exponentPremise] diff --git a/cbz/evidence/auditor-consolidation/independent-review/radix-command-final-scan.json b/cbz/evidence/auditor-consolidation/independent-review/radix-command-final-scan.json new file mode 100644 index 000000000..5f0536c01 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/radix-command-final-scan.json @@ -0,0 +1,42 @@ +{ + "summary": { + "files": 1, + "findings": 3, + "violations": 3, + "errors": 0, + "failing": 3, + "undecodable": [] + }, + "findings": [ + { + "path": "/workspace/cbz/discovery/scanner-independent-review/radix-command.lean", + "line": 1, + "col": 18, + "token": "axiom", + "kind": "axiom", + "layer": "A2", + "severity": "violation", + "context": "production" + }, + { + "path": "/workspace/cbz/discovery/scanner-independent-review/radix-command.lean", + "line": 2, + "col": 17, + "token": "axiom", + "kind": "axiom", + "layer": "A2", + "severity": "violation", + "context": "production" + }, + { + "path": "/workspace/cbz/discovery/scanner-independent-review/radix-command.lean", + "line": 3, + "col": 23, + "token": "axiom", + "kind": "axiom", + "layer": "A2", + "severity": "violation", + "context": "production" + } + ] +} \ No newline at end of file diff --git a/cbz/evidence/auditor-consolidation/independent-review/radix-command-lean.log b/cbz/evidence/auditor-consolidation/independent-review/radix-command-lean.log new file mode 100644 index 000000000..297ca2c4d --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/radix-command-lean.log @@ -0,0 +1,3 @@ +'binaryPremise' depends on axioms: [binaryPremise] +'octalPremise' depends on axioms: [octalPremise] +'exponentPremise' depends on axioms: [exponentPremise] diff --git a/cbz/evidence/auditor-consolidation/independent-review/radix-command-scan.json b/cbz/evidence/auditor-consolidation/independent-review/radix-command-scan.json new file mode 100644 index 000000000..0a9ba9245 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/radix-command-scan.json @@ -0,0 +1,22 @@ +{ + "summary": { + "files": 1, + "findings": 1, + "violations": 1, + "errors": 0, + "failing": 1, + "undecodable": [] + }, + "findings": [ + { + "path": "/workspace/cbz/discovery/scanner-independent-review/radix-command.lean", + "line": 3, + "col": 23, + "token": "axiom", + "kind": "axiom", + "layer": "A2", + "severity": "violation", + "context": "production" + } + ] +} \ No newline at end of file diff --git a/cbz/evidence/auditor-consolidation/independent-review/radix-command.lean.txt b/cbz/evidence/auditor-consolidation/independent-review/radix-command.lean.txt new file mode 100644 index 000000000..209c70ee5 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/radix-command.lean.txt @@ -0,0 +1,6 @@ +def binary := 0b0axiom binaryPremise : False +def octal := 0o0axiom octalPremise : False +def exponent := 1.0E+1axiom exponentPremise : False +#print axioms binaryPremise +#print axioms octalPremise +#print axioms exponentPremise diff --git a/cbz/evidence/auditor-consolidation/independent-review/scientific-command-final-lean.log b/cbz/evidence/auditor-consolidation/independent-review/scientific-command-final-lean.log new file mode 100644 index 000000000..dd8796143 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/scientific-command-final-lean.log @@ -0,0 +1 @@ +'bad' depends on axioms: [hiddenPremise] diff --git a/cbz/evidence/auditor-consolidation/independent-review/scientific-command-final-scan.json b/cbz/evidence/auditor-consolidation/independent-review/scientific-command-final-scan.json new file mode 100644 index 000000000..b6e73ed30 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/scientific-command-final-scan.json @@ -0,0 +1,22 @@ +{ + "summary": { + "files": 1, + "findings": 1, + "violations": 1, + "errors": 0, + "failing": 1, + "undecodable": [] + }, + "findings": [ + { + "path": "/workspace/cbz/discovery/scanner-independent-review/scientific-command.lean", + "line": 1, + "col": 20, + "token": "axiom", + "kind": "axiom", + "layer": "A2", + "severity": "violation", + "context": "production" + } + ] +} \ No newline at end of file diff --git a/cbz/evidence/auditor-consolidation/independent-review/scientific-command-lean.log b/cbz/evidence/auditor-consolidation/independent-review/scientific-command-lean.log new file mode 100644 index 000000000..dd8796143 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/scientific-command-lean.log @@ -0,0 +1 @@ +'bad' depends on axioms: [hiddenPremise] diff --git a/cbz/evidence/auditor-consolidation/independent-review/scientific-command-scan.json b/cbz/evidence/auditor-consolidation/independent-review/scientific-command-scan.json new file mode 100644 index 000000000..a230eeb5c --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/scientific-command-scan.json @@ -0,0 +1,11 @@ +{ + "summary": { + "files": 1, + "findings": 0, + "violations": 0, + "errors": 0, + "failing": 0, + "undecodable": [] + }, + "findings": [] +} \ No newline at end of file diff --git a/cbz/evidence/auditor-consolidation/independent-review/scientific-command.lean.txt b/cbz/evidence/auditor-consolidation/independent-review/scientific-command.lean.txt new file mode 100644 index 000000000..09bfcdfdf --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/scientific-command.lean.txt @@ -0,0 +1,3 @@ +def harmless := 1e1axiom hiddenPremise : False +theorem bad : False := hiddenPremise +#print axioms bad diff --git a/cbz/evidence/auditor-consolidation/independent-review/successor-two-fixture-scan.json b/cbz/evidence/auditor-consolidation/independent-review/successor-two-fixture-scan.json new file mode 100644 index 000000000..3c72c3a24 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/successor-two-fixture-scan.json @@ -0,0 +1,32 @@ +{ + "summary": { + "files": 2, + "findings": 2, + "violations": 2, + "errors": 0, + "failing": 2, + "undecodable": [] + }, + "findings": [ + { + "path": "/workspace/cbz/discovery/scanner-independent-review/macro-string.lean", + "line": 4, + "col": 58, + "token": "sorry", + "kind": "sorry", + "layer": "A1", + "severity": "violation", + "context": "production" + }, + { + "path": "/workspace/cbz/discovery/scanner-independent-review/numeral-command.lean", + "line": 1, + "col": 18, + "token": "axiom", + "kind": "axiom", + "layer": "A2", + "severity": "violation", + "context": "production" + } + ] +} \ No newline at end of file diff --git a/cbz/evidence/auditor-consolidation/independent-review/unicode-char-final-lean.log b/cbz/evidence/auditor-consolidation/independent-review/unicode-char-final-lean.log new file mode 100644 index 000000000..30dfe4aef --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/unicode-char-final-lean.log @@ -0,0 +1 @@ +'A' diff --git a/cbz/evidence/auditor-consolidation/independent-review/unicode-char-final-scan.json b/cbz/evidence/auditor-consolidation/independent-review/unicode-char-final-scan.json new file mode 100644 index 000000000..a230eeb5c --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/unicode-char-final-scan.json @@ -0,0 +1,11 @@ +{ + "summary": { + "files": 1, + "findings": 0, + "violations": 0, + "errors": 0, + "failing": 0, + "undecodable": [] + }, + "findings": [] +} \ No newline at end of file diff --git a/cbz/evidence/auditor-consolidation/independent-review/unicode-char-lean.log b/cbz/evidence/auditor-consolidation/independent-review/unicode-char-lean.log new file mode 100644 index 000000000..30dfe4aef --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/unicode-char-lean.log @@ -0,0 +1 @@ +'A' diff --git a/cbz/evidence/auditor-consolidation/independent-review/unicode-char-scan.json b/cbz/evidence/auditor-consolidation/independent-review/unicode-char-scan.json new file mode 100644 index 000000000..9e431ddf2 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/unicode-char-scan.json @@ -0,0 +1,22 @@ +{ + "summary": { + "files": 1, + "findings": 1, + "violations": 0, + "errors": 1, + "failing": 1, + "undecodable": [] + }, + "findings": [ + { + "path": "/workspace/cbz/discovery/scanner-independent-review/unicode-char.lean", + "line": 1, + "col": 17, + "token": "", + "kind": "unterminated_char", + "layer": "A", + "severity": "error", + "context": "production" + } + ] +} \ No newline at end of file diff --git a/cbz/evidence/auditor-consolidation/independent-review/unicode-char.lean.txt b/cbz/evidence/auditor-consolidation/independent-review/unicode-char.lean.txt new file mode 100644 index 000000000..b6517ffb2 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/independent-review/unicode-char.lean.txt @@ -0,0 +1,2 @@ +def c : Char := '\u0041' +#eval c diff --git a/cbz/evidence/auditor-consolidation/interpolation-layout-red.log b/cbz/evidence/auditor-consolidation/interpolation-layout-red.log new file mode 100644 index 000000000..b93c02998 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/interpolation-layout-red.log @@ -0,0 +1,53 @@ +FFF +====================================================================== +FAIL: test_interpolation_prefix_accepts_lean_layout (tests.test_cbz_auditor_hardening.LexicalUnion.test_interpolation_prefix_accepts_lean_layout) (src='#check s! "{("x", (sorry : Nat))}"') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 55, in test_interpolation_prefix_accepts_lean_layout + with self.subTest(src=src): self.assertEqual(kinds(src), ['sorry']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['sorry'] + +Second list contains 1 additional elements. +First extra element 0: +'sorry' + +- [] ++ ['sorry'] + +====================================================================== +FAIL: test_interpolation_prefix_accepts_lean_layout (tests.test_cbz_auditor_hardening.LexicalUnion.test_interpolation_prefix_accepts_lean_layout) (src='#check s! /- layout -/ "{("x", (sorry : Nat))}"') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 55, in test_interpolation_prefix_accepts_lean_layout + with self.subTest(src=src): self.assertEqual(kinds(src), ['sorry']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['sorry'] + +Second list contains 1 additional elements. +First extra element 0: +'sorry' + +- [] ++ ['sorry'] + +====================================================================== +FAIL: test_interpolation_prefix_accepts_lean_layout (tests.test_cbz_auditor_hardening.LexicalUnion.test_interpolation_prefix_accepts_lean_layout) (src='#check m! -- layout\n "{("x", (sorry : Nat))}"') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 55, in test_interpolation_prefix_accepts_lean_layout + with self.subTest(src=src): self.assertEqual(kinds(src), ['sorry']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['sorry'] + +Second list contains 1 additional elements. +First extra element 0: +'sorry' + +- [] ++ ['sorry'] + +---------------------------------------------------------------------- +Ran 1 test in 0.002s + +FAILED (failures=3) diff --git a/cbz/evidence/auditor-consolidation/native-expression-red.log b/cbz/evidence/auditor-consolidation/native-expression-red.log new file mode 100644 index 000000000..9db25d06f --- /dev/null +++ b/cbz/evidence/auditor-consolidation/native-expression-red.log @@ -0,0 +1,341 @@ +FFFFFFFFFFFFFFFFFFFFF +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { native := (true) })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { kernel := false, native := (true) })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { cfg with native := (true) })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { native := false || true })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { kernel := false, native := false || true })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { cfg with native := false || true })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { native := if true then true else false })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { kernel := false, native := if true then true else false })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { cfg with native := if true then true else false })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { native := (false) })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { kernel := false, native := (false) })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { cfg with native := (false) })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { native := Bool.not false })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { kernel := false, native := Bool.not false })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { cfg with native := Bool.not false })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { native := flag })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { kernel := false, native := flag })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { cfg with native := flag })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { native := false /- comment -/ || true })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { kernel := false, native := false /- comment -/ || true })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +====================================================================== +FAIL: test_unknown_native_field_expression_fails_closed (tests.test_cbz_auditor_hardening.LexicalUnion.test_unknown_native_field_expression_fails_closed) (src='by decide (config := { cfg with native := false /- comment -/ || true })') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 50, in test_unknown_native_field_expression_fails_closed + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['native'] + +Second list contains 1 additional elements. +First extra element 0: +'native' + +- [] ++ ['native'] + +---------------------------------------------------------------------- +Ran 1 test in 0.004s + +FAILED (failures=21) diff --git a/cbz/evidence/auditor-consolidation/native-expressions-lean.log b/cbz/evidence/auditor-consolidation/native-expressions-lean.log new file mode 100644 index 000000000..3f27cdba9 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/native-expressions-lean.log @@ -0,0 +1,4 @@ +'wrapped' depends on axioms: [wrapped._native.decide.ax_1_1] +'disj' depends on axioms: [disj._native.decide.ax_1_1] +'choose' depends on axioms: [choose._native.decide.ax_1_1] +'negate' depends on axioms: [negate._native.decide.ax_1_1] diff --git a/cbz/evidence/auditor-consolidation/native-expressions-scan.json b/cbz/evidence/auditor-consolidation/native-expressions-scan.json new file mode 100644 index 000000000..142f4213e --- /dev/null +++ b/cbz/evidence/auditor-consolidation/native-expressions-scan.json @@ -0,0 +1,42 @@ +[ + { + "path": "native-expressions.lean", + "line": 1, + "col": 51, + "token": "native", + "kind": "native", + "layer": "A2", + "severity": "violation", + "context": "production" + }, + { + "path": "native-expressions.lean", + "line": 2, + "col": 48, + "token": "native", + "kind": "native", + "layer": "A2", + "severity": "violation", + "context": "production" + }, + { + "path": "native-expressions.lean", + "line": 3, + "col": 50, + "token": "native", + "kind": "native", + "layer": "A2", + "severity": "violation", + "context": "production" + }, + { + "path": "native-expressions.lean", + "line": 4, + "col": 50, + "token": "native", + "kind": "native", + "layer": "A2", + "severity": "violation", + "context": "production" + } +] diff --git a/cbz/evidence/auditor-consolidation/native-expressions.lean.txt b/cbz/evidence/auditor-consolidation/native-expressions.lean.txt new file mode 100644 index 000000000..7b5ed8020 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/native-expressions.lean.txt @@ -0,0 +1,8 @@ +theorem wrapped : 1 = 1 := by decide (config := { native := (true) }) +theorem disj : 1 = 1 := by decide (config := { native := false || true }) +theorem choose : 1 = 1 := by decide (config := { native := if true then true else false }) +theorem negate : 1 = 1 := by decide (config := { native := Bool.not false }) +#print axioms wrapped +#print axioms disj +#print axioms choose +#print axioms negate diff --git a/cbz/evidence/auditor-consolidation/numeral-prime-red.log b/cbz/evidence/auditor-consolidation/numeral-prime-red.log new file mode 100644 index 000000000..2e303e412 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/numeral-prime-red.log @@ -0,0 +1,253 @@ +FFFFFFFFFFFFFF +====================================================================== +FAIL: test_scientific_and_radix_numerals_preserve_keyword_boundary (tests.test_cbz_auditor_hardening.LexicalUnion.test_scientific_and_radix_numerals_preserve_keyword_boundary) (src='def harmless := 1e1axiom hiddenPremise : False') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 65, in test_scientific_and_radix_numerals_preserve_keyword_boundary + with self.subTest(src=src): self.assertEqual(kinds(src),['axiom']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['axiom'] + +Second list contains 1 additional elements. +First extra element 0: +'axiom' + +- [] ++ ['axiom'] + +====================================================================== +FAIL: test_scientific_and_radix_numerals_preserve_keyword_boundary (tests.test_cbz_auditor_hardening.LexicalUnion.test_scientific_and_radix_numerals_preserve_keyword_boundary) (src='def harmless := 1E1axiom hiddenPremise : False') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 65, in test_scientific_and_radix_numerals_preserve_keyword_boundary + with self.subTest(src=src): self.assertEqual(kinds(src),['axiom']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['axiom'] + +Second list contains 1 additional elements. +First extra element 0: +'axiom' + +- [] ++ ['axiom'] + +====================================================================== +FAIL: test_scientific_and_radix_numerals_preserve_keyword_boundary (tests.test_cbz_auditor_hardening.LexicalUnion.test_scientific_and_radix_numerals_preserve_keyword_boundary) (src='def harmless := 1.0e1axiom hiddenPremise : False') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 65, in test_scientific_and_radix_numerals_preserve_keyword_boundary + with self.subTest(src=src): self.assertEqual(kinds(src),['axiom']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['axiom'] + +Second list contains 1 additional elements. +First extra element 0: +'axiom' + +- [] ++ ['axiom'] + +====================================================================== +FAIL: test_scientific_and_radix_numerals_preserve_keyword_boundary (tests.test_cbz_auditor_hardening.LexicalUnion.test_scientific_and_radix_numerals_preserve_keyword_boundary) (src='def harmless := 1.0E1axiom hiddenPremise : False') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 65, in test_scientific_and_radix_numerals_preserve_keyword_boundary + with self.subTest(src=src): self.assertEqual(kinds(src),['axiom']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['axiom'] + +Second list contains 1 additional elements. +First extra element 0: +'axiom' + +- [] ++ ['axiom'] + +====================================================================== +FAIL: test_scientific_and_radix_numerals_preserve_keyword_boundary (tests.test_cbz_auditor_hardening.LexicalUnion.test_scientific_and_radix_numerals_preserve_keyword_boundary) (src='def harmless := 1_0e1_0axiom hiddenPremise : False') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 65, in test_scientific_and_radix_numerals_preserve_keyword_boundary + with self.subTest(src=src): self.assertEqual(kinds(src),['axiom']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['axiom'] + +Second list contains 1 additional elements. +First extra element 0: +'axiom' + +- [] ++ ['axiom'] + +====================================================================== +FAIL: test_scientific_and_radix_numerals_preserve_keyword_boundary (tests.test_cbz_auditor_hardening.LexicalUnion.test_scientific_and_radix_numerals_preserve_keyword_boundary) (src='def harmless := 0b0axiom hiddenPremise : False') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 65, in test_scientific_and_radix_numerals_preserve_keyword_boundary + with self.subTest(src=src): self.assertEqual(kinds(src),['axiom']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['axiom'] + +Second list contains 1 additional elements. +First extra element 0: +'axiom' + +- [] ++ ['axiom'] + +====================================================================== +FAIL: test_scientific_and_radix_numerals_preserve_keyword_boundary (tests.test_cbz_auditor_hardening.LexicalUnion.test_scientific_and_radix_numerals_preserve_keyword_boundary) (src='def harmless := 0B1_0axiom hiddenPremise : False') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 65, in test_scientific_and_radix_numerals_preserve_keyword_boundary + with self.subTest(src=src): self.assertEqual(kinds(src),['axiom']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['axiom'] + +Second list contains 1 additional elements. +First extra element 0: +'axiom' + +- [] ++ ['axiom'] + +====================================================================== +FAIL: test_scientific_and_radix_numerals_preserve_keyword_boundary (tests.test_cbz_auditor_hardening.LexicalUnion.test_scientific_and_radix_numerals_preserve_keyword_boundary) (src='def harmless := 0o0axiom hiddenPremise : False') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 65, in test_scientific_and_radix_numerals_preserve_keyword_boundary + with self.subTest(src=src): self.assertEqual(kinds(src),['axiom']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['axiom'] + +Second list contains 1 additional elements. +First extra element 0: +'axiom' + +- [] ++ ['axiom'] + +====================================================================== +FAIL: test_scientific_and_radix_numerals_preserve_keyword_boundary (tests.test_cbz_auditor_hardening.LexicalUnion.test_scientific_and_radix_numerals_preserve_keyword_boundary) (src='def harmless := 0O1_0axiom hiddenPremise : False') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 65, in test_scientific_and_radix_numerals_preserve_keyword_boundary + with self.subTest(src=src): self.assertEqual(kinds(src),['axiom']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: Lists differ: [] != ['axiom'] + +Second list contains 1 additional elements. +First extra element 0: +'axiom' + +- [] ++ ['axiom'] + +====================================================================== +FAIL: test_scientific_and_radix_numerals_preserve_keyword_boundary (tests.test_cbz_auditor_hardening.LexicalUnion.test_scientific_and_radix_numerals_preserve_keyword_boundary) (number='0x0') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 68, in test_scientific_and_radix_numerals_preserve_keyword_boundary + self.assertEqual(kinds(f'def x := {number}sorry'),['sorry']) +AssertionError: Lists differ: [] != ['sorry'] + +Second list contains 1 additional elements. +First extra element 0: +'sorry' + +- [] ++ ['sorry'] + +====================================================================== +FAIL: test_scientific_and_radix_numerals_preserve_keyword_boundary (tests.test_cbz_auditor_hardening.LexicalUnion.test_scientific_and_radix_numerals_preserve_keyword_boundary) (number='0Xf_F') +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 68, in test_scientific_and_radix_numerals_preserve_keyword_boundary + self.assertEqual(kinds(f'def x := {number}sorry'),['sorry']) +AssertionError: Lists differ: [] != ['sorry'] + +Second list contains 1 additional elements. +First extra element 0: +'sorry' + +- [] ++ ['sorry'] + +====================================================================== +FAIL: test_mathlib_prime_notations_are_not_unfinished_characters (tests.test_cbz_auditor_hardening.LexicalUnion.test_mathlib_prime_notations_are_not_unfinished_characters) (src="def x := f '' S") +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 73, in test_mathlib_prime_notations_are_not_unfinished_characters + self.assertEqual([f for f in S.scan_text(src,'M.lean') if f['severity']=='error'],[]) +AssertionError: Lists differ: [{'path': 'M.lean', 'line': 1, 'col': 12, [241 chars]on'}] != [] + +First list contains 2 additional elements. +First extra element 0: +{'path': 'M.lean', 'line': 1, 'col': 12, 'token': '', 'kind': 'unterminated_char', 'layer': 'A', 'severity': 'error', 'context': 'production'} + ++ [] +- [{'col': 12, +- 'context': 'production', +- 'kind': 'unterminated_char', +- 'layer': 'A', +- 'line': 1, +- 'path': 'M.lean', +- 'severity': 'error', +- 'token': ''}, +- {'col': 13, +- 'context': 'production', +- 'kind': 'unterminated_char', +- 'layer': 'A', +- 'line': 1, +- 'path': 'M.lean', +- 'severity': 'error', +- 'token': ''}] + +====================================================================== +FAIL: test_mathlib_prime_notations_are_not_unfinished_characters (tests.test_cbz_auditor_hardening.LexicalUnion.test_mathlib_prime_notations_are_not_unfinished_characters) (src="def x := f ⁻¹' S") +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 73, in test_mathlib_prime_notations_are_not_unfinished_characters + self.assertEqual([f for f in S.scan_text(src,'M.lean') if f['severity']=='error'],[]) +AssertionError: Lists differ: [{'path': 'M.lean', 'line': 1, 'col': 14, [97 chars]on'}] != [] + +First list contains 1 additional elements. +First extra element 0: +{'path': 'M.lean', 'line': 1, 'col': 14, 'token': '', 'kind': 'unterminated_char', 'layer': 'A', 'severity': 'error', 'context': 'production'} + ++ [] +- [{'col': 14, +- 'context': 'production', +- 'kind': 'unterminated_char', +- 'layer': 'A', +- 'line': 1, +- 'path': 'M.lean', +- 'severity': 'error', +- 'token': ''}] + +====================================================================== +FAIL: test_mathlib_prime_notations_are_not_unfinished_characters (tests.test_cbz_auditor_hardening.LexicalUnion.test_mathlib_prime_notations_are_not_unfinished_characters) (src="def x := ∑' n, f n") +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz/auditor-review/tests/test_cbz_auditor_hardening.py", line 73, in test_mathlib_prime_notations_are_not_unfinished_characters + self.assertEqual([f for f in S.scan_text(src,'M.lean') if f['severity']=='error'],[]) +AssertionError: Lists differ: [{'path': 'M.lean', 'line': 1, 'col': 11, [97 chars]on'}] != [] + +First list contains 1 additional elements. +First extra element 0: +{'path': 'M.lean', 'line': 1, 'col': 11, 'token': '', 'kind': 'unterminated_char', 'layer': 'A', 'severity': 'error', 'context': 'production'} + ++ [] +- [{'col': 11, +- 'context': 'production', +- 'kind': 'unterminated_char', +- 'layer': 'A', +- 'line': 1, +- 'path': 'M.lean', +- 'severity': 'error', +- 'token': ''}] + +---------------------------------------------------------------------- +Ran 2 tests in 0.003s + +FAILED (failures=14) diff --git a/cbz/evidence/auditor-consolidation/v4-final-normal.log b/cbz/evidence/auditor-consolidation/v4-final-normal.log new file mode 100644 index 000000000..57f0f0b79 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/v4-final-normal.log @@ -0,0 +1,5 @@ +........................................................................ +---------------------------------------------------------------------- +Ran 72 tests in 110.936s + +OK diff --git a/cbz/evidence/auditor-consolidation/v4-final-optimized.log b/cbz/evidence/auditor-consolidation/v4-final-optimized.log new file mode 100644 index 000000000..c4419d0e8 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/v4-final-optimized.log @@ -0,0 +1,5 @@ +........................................................................ +---------------------------------------------------------------------- +Ran 72 tests in 118.016s + +OK diff --git a/docs/cbz/CANONICAL_AUDITORS.md b/docs/cbz/CANONICAL_AUDITORS.md new file mode 100644 index 000000000..e225d5973 --- /dev/null +++ b/docs/cbz/CANONICAL_AUDITORS.md @@ -0,0 +1,114 @@ +# Canonical source auditors + +These standard-library tools implement finite source inventories. Neither a +lexical zero nor an AST category establishes mathematical closure. Kernel +replay and complete axiom/dependency audits remain separate obligations. + +## Source and consolidation + +The implementation basis is Universal-Law-Workspace PR29 at +`ef5b924016c0f85ced7eb1dfb8f5eb9bd776f169`. Its 28 lexical behavioral tests, +39 source mutants, 18 A3 behavioral tests and 15 A3 source mutants are retained. +The compatible regression requirements from main PR687 at +`95e9dd43d70b8d650c07fdfc458199eec507a919` and main issue684 comment6503596060 +are included: balanced ordinary-looking macro-string holes, native settings +with intervening layout, token boundaries, comments, literals, quotations, +escaped constant names, compiled-trust hazards and fail-closed input handling. +The existing root `tools/cbz_inventory.py` is not replaced. + +Policy choices are explicit: Name quotations are conservatively reported; +escaped keywords such as `«sorry»` and qualified ordinary identifiers such as +`Foo.sorry` are not Lean placeholder syntax. Names of actual trust-hole +constants, including escaped components, are reported. `unsafe`, `extern`, +`implemented_by`, `stop`, `Float`, and `Float32` are review findings: their +presence alone is not a proof defect. Context names are metadata. The federation +command uses `--fail-on all`, so evidence/control paths cannot hide violations. + +## Commands + +Use the repository's documented CPython runtime (verified here with 3.11.16): + +```sh +python3.11 -B -S -m unittest tests.test_cbz_layer_a_scan tests.test_cbz_auditor_hardening tests.test_cbz_layer_a_scan_mutants tests.test_cbz_a3_float_census +python3.11 -O -B -S -m unittest tests.test_cbz_layer_a_scan tests.test_cbz_auditor_hardening tests.test_cbz_layer_a_scan_mutants tests.test_cbz_a3_float_census +python3.11 -B -S tools/cbz/layer_a_scan.py --git /path/to/repository --rev EXACT_COMMIT --fail-on all --json /outside/source/lexical.json +python3.11 -B -S tools/cbz/a3_float_census.py --git /path/to/repository --rev EXACT_COMMIT --json /outside/source/float-census.json +``` + +Repeat the source commands for every repository at its recorded cut. Git mode +reads the specified immutable tree, never current worktree contents. Filesystem +mode is also available for explicit source files/directories and scans all +subdirectories except `.git`, including `.lake`; prefer Git mode for owned +repository sources. Missing roots, unreadable/undecodable sources, source +symlinks and directory symlinks fail closed. Git batch reads check requested +object identity/type, exact byte count/trailer and subprocess success; replace +objects, lazy fetch and ambient Git environment/global/system config are disabled. +Gitlinks fail closed: a separate pin-aware admission must resolve and scan them, +so a repository with unadmitted submodules cannot produce a global clean result. + +## Self-verification + +The final suite contains 72 tests, including 66 lexical source mutations and +23 A3 source mutations. Every old/replacement anchor must occur exactly once. +Each mutant is bound to a named assertion that must fail; import/launch failures, +syntax errors, unrelated failures, test errors and zero-test runs are not kills. +The unchanged source must pass through the same copied-source path. Both +mutation runners propagate optimized Python into their children. Actual +syntax-broken-source negative controls and synthetic error/foreign-failure +controls exercise the kill classifier. Two harness-control methods are skipped +only inside mutation subprocesses to prevent recursion; A3's two preexisting +self-mutation methods also do not recurse inside its subprocess. They run at +normal top level. This is not a skipped production/source admission. + +Changes were first exercised as red regressions: 24 failed assertions across +11 hardening tests, followed by three failures in the whitespace/comment +interpolation-prefix test. The latter inputs were accepted by the actual pinned +Lean4.34.1 parser, demonstrating a genuine source-lexer omission. Independent +review then demonstrated actual `sorryAx` from nested `throwError` string holes +and actual unapproved axioms from keywords adjoining numerals (including +scientific/binary/octal forms). Both defects have direct regressions and source +mutants. A later 14-assertion red run covers numeral spelling and valid Mathlib +prime notation; five more red assertions cover the pinned identifier domain and +unsupported character escapes. Prior passing development cuts are historical, +not qualification of the repaired source. + +## Limits + +The lexer sees its documented source-token vocabulary and interpolation forms; +it cannot certify arbitrary custom syntax, generated declarations, imported +code, macro expansion or elaboration recovery. A3 uses the documented Python AST +signal vocabulary; arbitrary aliases, `getattr`, dynamic imports/`exec`, external +input types and semantic intent are outside it. `NO_FLOAT_SIGNAL` does not prove +exact arithmetic. `MIXED` does not prove enclosure of every floating operation. +An interval import is evidence to review, not a certificate. Per-file bound +claims still require exact rational or justified interval reasoning. + +Maintenance owner: none — self-contained. Source changes require rerunning both +modes, all source mutants and the repository inventories. These tools serve G0, +the finite source portion of G1, A3 triage, and CBZ criteria4/9; they cannot alone +establish those global criteria. + +## Pinned lexical oracle + +The finite identifier, numeral and character-escape rules follow Lean4.34.1 +release commit `5045d0056413266e57c625dcd7c365b10e377c52`: + +- `Init/Meta/Defs.lean` (identifier ranges, lines101–143), SHA256 + `01154a5f32560e2e971728ccb90a0cba6faa2f5c4764c9bab4bbcf7cb60b20b6`. +- `Lean/Parser/Basic.lean` (character escapes, lines657–674; numerals, + lines831–918), SHA256 + `9fc3df26147bb4c8dca560507426474f975628ad8598bbb4f5e392cea24ae8d7`. + +Numeral recognition operates only on source spelling. It neither evaluates +numbers nor trusts compiled arithmetic for a mathematical bound. Explicit +regressions cover command keywords adjoining decimal/scientific/radix literals. +Secondary ordinary-string hole scans reuse the full lexer through nested +quoted terms, comments and escaped names; they never move the primary cursor. +Thus ambiguous brace data may add findings but cannot hide primary code. + +Native configuration fields are fail-closed for arbitrary expressions: only +complete literal `false` followed by a field delimiter is exempt. Parenthesized +values, conditionals, operators after false, variables and applications are +reported without evaluation. Ordinary `def native := 1` stays an identifier +definition. Actual Lean accepted `native := (true)` and emitted a fresh native +decision axiom; the regression first failed on all21 expression/context cases. diff --git a/tests/test_cbz_a3_float_census.py b/tests/test_cbz_a3_float_census.py new file mode 100644 index 000000000..ea328b989 --- /dev/null +++ b/tests/test_cbz_a3_float_census.py @@ -0,0 +1,228 @@ +"""Behavioural and mutation self-tests for tools/cbz/a3_float_census.py. + +The census under test is loaded from $CBZ_A3_CENSUS when set (the mutation +test below points it at mutated copies), else from tools/cbz/. +""" +import importlib.util +import json +import os +import re +import shutil +import subprocess +import sys +import tempfile +import unittest + +HERE = os.path.dirname(os.path.abspath(__file__)) +WORKSPACE = os.path.dirname(HERE) +REAL = os.path.join(WORKSPACE, "tools", "cbz", "a3_float_census.py") +TOOL = os.environ.get("CBZ_A3_CENSUS") or REAL + + +def _load(): + spec = importlib.util.spec_from_file_location("a3_census_under_test", TOOL) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod + + +M = _load() + + +def kinds(src): + r = M.census_text(src, "x.py") + return r["class"], [(s["line"], s["kind"], s["detail"]) for s in r["signals"]] + + +class Signals(unittest.TestCase): + def test_float_literals(self): + self.assertEqual(kinds("x = 0.5\ny = 1e-9\nz = 2j\n"), + ("FLOAT_SIGNAL", [(1, "float_literal", "0.5"), (2, "float_literal", "1e-09"), + (3, "float_literal", "2j")])) + + def test_int_and_bool_literals_are_not_float(self): + self.assertEqual(kinds("x = 1\ny = True\nz = 10**9\n"), ("NO_FLOAT_SIGNAL", [])) + + def test_float_and_complex_calls(self): + self.assertEqual(kinds("a = float(x)\nb = complex(1, 2)\n"), + ("FLOAT_SIGNAL", [(1, "float_call", "float"), (2, "float_call", "complex")])) + + def test_true_division_and_augmented(self): + self.assertEqual(kinds("a = p / q\nb //= 2\nc /= 3\n"), + ("FLOAT_SIGNAL", [(1, "true_division", "/"), (3, "true_division", "/=")])) + + def test_floor_division_is_exact(self): + self.assertEqual(kinds("a = p // q\nb = p % q\n"), ("NO_FLOAT_SIGNAL", [])) + + def test_math_float_and_exact_math(self): + self.assertEqual(kinds("import math\nr = math.sqrt(2)\nk = math.isqrt(9)\nc = math.comb(5, 2)\n"), + ("FLOAT_SIGNAL", [(2, "math_float", "math.sqrt")])) + + def test_math_alias_and_from_import(self): + self.assertEqual(kinds("import math as m\nr = m.pi\n"), ("FLOAT_SIGNAL", [(2, "math_float", "math.pi")])) + self.assertEqual(kinds("from math import exp, gcd\n"), + ("FLOAT_SIGNAL", [(1, "math_float", "from math import exp")])) + + def test_unrelated_attribute_named_like_math(self): + self.assertEqual(kinds("obj.sqrt(2)\nmathish.sqrt(2)\n"), ("NO_FLOAT_SIGNAL", [])) + + def test_float_modules(self): + self.assertEqual(kinds("import numpy as np\n"), ("FLOAT_SIGNAL", [(1, "float_module", "numpy")])) + self.assertEqual(kinds("from decimal import Decimal\n"), ("FLOAT_SIGNAL", [(1, "float_module", "decimal")])) + self.assertEqual(kinds("import scipy.special\n"), ("FLOAT_SIGNAL", [(1, "float_module", "scipy")])) + + def test_exact_modules_and_mixed(self): + self.assertEqual(kinds("from fractions import Fraction\nx = Fraction(1, 3)\n"), + ("NO_FLOAT_SIGNAL", [(1, "exact_module", "fractions")])) + self.assertEqual(kinds("from fractions import Fraction\nx = Fraction(1, 3) / 2\n"), + ("MIXED", [(1, "exact_module", "fractions"), (2, "true_division", "/")])) + self.assertEqual(kinds("import sympy\n"), ("NO_FLOAT_SIGNAL", [(1, "exact_module", "sympy")])) + + def test_mpmath_interval(self): + cls, sig = kinds("import mpmath\nx = mpmath.iv.mpf(1)\n") + self.assertEqual(cls, "MIXED") + self.assertIn((1, "float_module", "mpmath"), sig) + self.assertIn((2, "exact_module", "mpmath.iv"), sig) + self.assertIn((1, "exact_module", "mpmath.iv"), kinds("from mpmath import iv\n")[1]) + + def test_interval_layer(self): + cls, sig = kinds("import math\n_na = math.nextafter\nx = 0.5\n") + self.assertEqual(cls, "MIXED") + self.assertIn((2, "interval_layer", "math.nextafter"), sig) + cls, sig = kinds("from ia import dn, up\nx = 0.5\n") + self.assertEqual((cls, sig[0]), ("MIXED", (1, "interval_layer", "from ia import"))) + cls, sig = kinds("import ia\nx = 1 / 3\n") + self.assertEqual((cls, sig[0]), ("MIXED", (1, "interval_layer", "import ia"))) + cls, sig = kinds("from math import ulp\n") + self.assertIn((1, "interval_layer", "math.ulp"), sig) + self.assertEqual(kinds("import iax\nx = 0.5\n")[0], "FLOAT_SIGNAL") + + def test_strings_and_comments_are_not_code(self): + self.assertEqual(kinds("s = '0.5 / 2 float(x)'\n# x = 0.5\n"), ("NO_FLOAT_SIGNAL", [])) + + def test_unparseable_fails_closed(self): + r = M.census_text("def f(:\n", "bad.py") + self.assertEqual(r["class"], "UNPARSEABLE") + + +class CommandLine(unittest.TestCase): + def run_cli(self, args): + return subprocess.run([sys.executable, "-I", TOOL] + list(args), capture_output=True, text=True) + + def test_directory_census_and_json(self): + with tempfile.TemporaryDirectory() as d: + with open(os.path.join(d, "a.py"), "w") as fh: + fh.write("x = 1 / 3\n") + with open(os.path.join(d, "b.py"), "w") as fh: + fh.write("x = 1\n") + out = os.path.join(d, "o.json") + r = self.run_cli([d, "--json", out]) + self.assertEqual(r.returncode, 0, r.stdout + r.stderr) + with open(out) as fh: + data = json.load(fh) + self.assertEqual(data["summary"], {"files": 2, "by_class": {"FLOAT_SIGNAL": 1, "NO_FLOAT_SIGNAL": 1}}) + + def test_unparseable_exit_one(self): + with tempfile.TemporaryDirectory() as d: + with open(os.path.join(d, "a.py"), "w") as fh: + fh.write("def f(:\n") + self.assertEqual(self.run_cli([d]).returncode, 1) + + def test_git_mode(self): + with tempfile.TemporaryDirectory() as d: + env = dict(os.environ, GIT_CONFIG_GLOBAL=os.devnull, GIT_CONFIG_SYSTEM=os.devnull) + git = lambda *a: subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@x", + "-c", "commit.gpgsign=false"] + list(a), cwd=d, + check=True, capture_output=True, env=env) + git("init", "-q") + with open(os.path.join(d, "a.py"), "w") as fh: + fh.write("x = 0.25\n") + git("add", "-A") + git("commit", "-q", "-m", "c") + out = os.path.join(d, "o.json") + r = self.run_cli(["--git", d, "--rev", "HEAD", "--json", out]) + self.assertEqual(r.returncode, 0, r.stdout + r.stderr) + with open(out) as fh: + data = json.load(fh) + self.assertEqual(data["summary"]["files"], 1) + self.assertEqual(data["files"][0]["class"], "FLOAT_SIGNAL") + self.assertEqual(len(data["files"][0]["blob"]), 40) + + def test_usage(self): + self.assertEqual(self.run_cli([]).returncode, 2) + + +MUTANTS = [ + ("float literals ignored", "if isinstance(node.value, (float, complex)) and not isinstance(node.value, bool):", + "if False:"), + ("float() calls ignored", 'node.func.id in ("float", "complex")', 'node.func.id in ()'), + ("true division ignored", " if isinstance(node.op, ast.Div):\n self.add(node, \"true_division\", \"/\")", + " if False:\n self.add(node, \"true_division\", \"/\")"), + ("augmented division ignored", 'self.add(node, "true_division", "/=")', "pass"), + ("math attributes ignored", "if base in self.math_aliases and node.attr not in EXACT_MATH:", "if False:"), + ("from-math imports ignored", 'self.add(node, "math_float", f"from {mod} import {a.name}")', "pass"), + ("sqrt treated as exact", '"comb", "factorial",', '"comb", "factorial", "sqrt",'), + ("float modules ignored", 'FLOAT_MODULES = {"numpy", "scipy", "mpmath", "decimal", "cmath"}', + 'FLOAT_MODULES = set()'), + ("exact modules ignored", 'EXACT_MODULES = {"fractions", "sympy", "flint", "gmpy2"}', "EXACT_MODULES = set()"), + ("interval layer ignored", 'counts.get("exact_module") or counts.get("interval_layer")', + 'counts.get("exact_module")'), + ("nextafter attribute ignored", "if base in self.math_aliases and node.attr in INTERVAL_MATH:", "if False:"), + ("ia import ignored", 'self.add(node, "interval_layer", f"from {mod} import")', "pass"), + ("mixed collapsed", '("MIXED" if has_exact else "FLOAT_SIGNAL")', '"FLOAT_SIGNAL"'), + ("unparseable passes", 'return 1 if by_class.get("UNPARSEABLE") else 0', "return 0"), + ("git mode lists nothing", 'if typ == b"blob" and p.endswith(".py"):', "if False:"), +] + + +# Additional source mutations for the canonical input/lexer repairs. +MUTANTS.extend([('missing root ignored', 'raise OSError(f"source path does not exist: {p}")', 'pass'), ('source symlink accepted', 'raise OSError(f"source symlink requires explicit target admission: {p}")', 'pass'), ('directory symlink skipped', 'raise OSError(f"source directory symlink requires explicit target admission: {d}")', 'pass'), ('gitlink skipped', 'raise OSError(f"gitlink requires a separately pinned scan: {p}")', 'pass'), ('git source symlink accepted', 'if mode not in (b"100644", b"100755"):', 'if False:'), ('git batch header unchecked', 'if len(header) != 3 or header[0] != sha.encode() or header[1] != b"blob" or not header[2].isdigit():', 'if False:'), ('git batch body unchecked', 'if len(data) != size or trailer != b"\\n":', 'if False:'), ('git batch exit unchecked', 'if code != 0:', 'if False:')]) + +EXPECTED_FAILURE = {'float literals ignored': 'test_float_literals', 'float() calls ignored': 'test_float_and_complex_calls', 'true division ignored': 'test_true_division_and_augmented', 'augmented division ignored': 'test_true_division_and_augmented', 'math attributes ignored': 'test_math_float_and_exact_math', 'from-math imports ignored': 'test_math_alias_and_from_import', 'sqrt treated as exact': 'test_math_float_and_exact_math', 'float modules ignored': 'test_float_modules', 'exact modules ignored': 'test_exact_modules_and_mixed', 'interval layer ignored': 'test_interval_layer', 'nextafter attribute ignored': 'test_interval_layer', 'ia import ignored': 'test_interval_layer', 'mixed collapsed': 'test_exact_modules_and_mixed', 'unparseable passes': 'test_unparseable_exit_one', 'git mode lists nothing': 'test_git_mode'} + +EXPECTED_FAILURE.update({'missing root ignored': 'test_missing_root_fails_for_both_tools', 'source symlink accepted': 'test_source_symlink_fails_for_both_tools', 'directory symlink skipped': 'test_symlink_directory_is_not_silently_skipped', 'gitlink skipped': 'test_gitlink_is_explicitly_rejected_by_both_tools', 'git source symlink accepted': 'test_git_source_symlink_fails_for_both_tools', 'git batch header unchecked': 'test_malformed_blob_transport_fails_closed', 'git batch body unchecked': 'test_malformed_blob_transport_fails_closed', 'git batch exit unchecked': 'test_malformed_blob_transport_fails_closed'}) + +def run_suite(tool_path): + env = dict(os.environ, CBZ_A3_CENSUS=tool_path, PYTHONDONTWRITEBYTECODE="1") + return subprocess.run([sys.executable, *(["-O"] if sys.flags.optimize else []), "-B", "-S", "-m", "unittest", "-v", "tests.test_cbz_a3_float_census", "tests.test_cbz_auditor_hardening"], + cwd=WORKSPACE, env=env, capture_output=True, text=True, timeout=600) + + +def killed(r, expected_test=None): + out = r.stdout + r.stderr + summary = re.search(r"^FAILED \(([^)]*)\)$", out, re.M) + if r.returncode == 0 or not summary or "errors=" in summary.group(1): + return False + if not re.search(r"^Ran [1-9][0-9]* tests?", out, re.M): + return False + failures = re.findall(r"^FAIL: (test_[A-Za-z0-9_]+) \(", out, re.M) + return bool(failures) and (expected_test is None or expected_test in failures) + + +@unittest.skipIf(os.environ.get("CBZ_A3_CENSUS"), "mutant run: do not recurse") +class SelfMutation(unittest.TestCase): + def test_harness_control_unmutated_copy_passes(self): + # without this control, a harness that cannot load the tool would "kill" every mutant + with tempfile.TemporaryDirectory() as d: + path = os.path.join(d, "control.py") + shutil.copyfile(REAL, path) + r = run_suite(path) + self.assertEqual(r.returncode, 0, r.stdout + r.stderr) + + def test_every_mutant_is_killed(self): + with open(REAL, encoding="utf-8") as fh: + src = fh.read() + survivors = [] + with tempfile.TemporaryDirectory() as d: + for i, (name, old, new) in enumerate(MUTANTS): + self.assertEqual(src.count(old), 1, f"mutation point drifted: {name}") + path = os.path.join(d, f"m{i:02d}.py") + with open(path, "w", encoding="utf-8") as fh: + fh.write(src.replace(old, new)) + if not killed(run_suite(path), EXPECTED_FAILURE[name]): + survivors.append(name) + self.assertEqual(survivors, []) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_cbz_auditor_hardening.py b/tests/test_cbz_auditor_hardening.py new file mode 100644 index 000000000..7d89d2809 --- /dev/null +++ b/tests/test_cbz_auditor_hardening.py @@ -0,0 +1,202 @@ +"""Regression union for canonical lexical/census auditors (CBZ §2.3). + +These assert source-level behavior only; kernel and semantic closure are separate. +""" +import importlib.util +import json +import os +from pathlib import Path +import subprocess +import sys +import tempfile +import unittest + +ROOT = Path(__file__).resolve().parents[1] +SCAN = Path(os.environ.get('CBZ_LAYER_A_SCAN', ROOT/'tools/cbz/layer_a_scan.py')) +CENSUS = Path(os.environ.get('CBZ_A3_CENSUS', ROOT/'tools/cbz/a3_float_census.py')) +def load(path, name): + spec = importlib.util.spec_from_file_location(name, path) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod +S = load(SCAN, 'hardening_scanner') + +def kinds(src): + return [f['kind'] for f in S.scan_text(src, 'Pkg/M.lean') if f['severity']=='violation'] +def cli(tool, *args): + return subprocess.run([sys.executable,'-B','-S',str(tool),*map(str,args)],capture_output=True,text=True) + +class LexicalUnion(unittest.TestCase): + def test_native_configuration_layout_is_not_a_bypass(self): + for src in ['by decide (config := { native\n := true })', + 'by decide (config := { native /- a /- b -/ c -/ := true })', + 'by decide (config := { native := /- x -/ true })', + 'by decide (config := { native -- comment\n := -- c\n true })', + 'by decide (config := { native' + ' '*100 + ':=true })']: + with self.subTest(src=src): + self.assertEqual(kinds(src), ['native']) + def test_plus_native_layout_is_not_a_bypass(self): + for src in ['by decide +\nnative', 'by decide + /- c -/ native', 'by decide + --c\n native']: + with self.subTest(src=src): self.assertEqual(kinds(src), ['native']) + def test_native_false_and_longer_identifiers_are_not_true(self): + for src in ['native := false', 'native := trueX', 'native := true₁', 'native := trueα']: + with self.subTest(src=src): self.assertEqual(kinds(src), []) + def test_unknown_native_field_expression_fails_closed(self): + for expr in ['(true)','false || true','if true then true else false', + '(false)','Bool.not false','flag', + 'false /- comment -/ || true']: + for prefix in ['{ ', '{ kernel := false, ', '{ cfg with ']: + src='by decide (config := '+prefix+'native := '+expr+' })' + with self.subTest(src=src): self.assertEqual(kinds(src),['native']) + self.assertEqual(kinds('by decide (config := { native := false })'),[]) + self.assertEqual(kinds('by decide (config := { native := false, kernel := true })'),[]) + self.assertEqual(kinds('def native := 1'),[]) + def test_plain_macro_braces_are_conservatively_scanned(self): + self.assertEqual(kinds('def e := throwError "bad {sorry}"'), ['sorry']) + self.assertEqual(kinds('def e := throwError "bad {f {x := admit}}"'), ['admit']) + self.assertEqual(kinds('def e := throwError "axiom {ax} in {name}"'), []) + self.assertEqual(kinds('def s := "a lone { brace"'), []) + self.assertEqual(kinds(r'def s := "escaped \{sorry}"'), []) + def test_plain_macro_holes_with_nested_literals(self): + for src in ['def f := throwError "bad {let x := "safe"; (sorry : Nat)}"', + 'def f := throwError "bad {let x := "safe"; /- } -/ (sorry : Nat)}"', + 'def f := throwError "bad {let «odd}name» := "safe"; (sorry : Nat)}"', + 'def f := throwError "bad {s!"{("x", (sorry : Nat))}"}"']: + with self.subTest(src=src): self.assertIn('sorry',kinds(src)) + def test_adjacent_numeral_never_swallows_code_keyword(self): + self.assertEqual(kinds('def harmless := 0axiom hiddenPremise : False\ntheorem bad : False := hiddenPremise'),['axiom']) + for src in ['def x := 1sorry', 'def x := 0native_decide', 'def x := 123admit']: + with self.subTest(src=src): + self.assertTrue(kinds(src)) + def test_scientific_and_radix_numerals_preserve_keyword_boundary(self): + for number in ['1e1','1E1','1.0e1','1.0E1','1e+1','1E-1', + '1_0e1_0','0b0','0B1_0','0o0','0O1_0']: + src=f'def harmless := {number}axiom hiddenPremise : False' + with self.subTest(src=src): self.assertEqual(kinds(src),['axiom']) + for number in ['0x0','0Xf_F','1.5e-2']: + with self.subTest(number=number): + self.assertEqual(kinds(f'def x := {number}sorry'),['sorry']) + def test_mathlib_prime_notations_are_not_unfinished_characters(self): + for src in ["def x := f '' S", "def x := f ⁻¹' S", "def x := ∑' n, f n", + "theorem t := hb.1.integrable_norm_pow'", "def x := f'' y"]: + with self.subTest(src=src): + self.assertEqual([f for f in S.scan_text(src,'M.lean') if f['severity']=='error'],[]) + for src in [r"def c : Char := '\u0041'", r"def c : Char := '\x41'"]: + with self.subTest(src=src): + self.assertEqual([f for f in S.scan_text(src,'M.lean') if f['severity']=='error'],[]) + def test_interpolation_prefix_accepts_lean_layout(self): + # Both were accepted by the actual pinned Lean4.34.1 parser. + for src in ['#check s! "{("x", (sorry : Nat))}"', + '#check s! /- layout -/ "{("x", (sorry : Nat))}"', + '#check m! -- layout\n "{("x", (sorry : Nat))}"']: + with self.subTest(src=src): self.assertEqual(kinds(src), ['sorry']) + for src in ['def s := s! "{x"', 'def s := s! /- layout -/ "{x"']: + with self.subTest(src=src): + self.assertTrue([f for f in S.scan_text(src,'M.lean') if f['severity']=='error']) + def test_unterminated_character_literal_is_error(self): + for src in ["def c := '", "def c := '\\", "def c := '\\n", "def c := '\"\n"]: + with self.subTest(src=src): + self.assertIn('unterminated_char', [f['kind'] for f in S.scan_text(src,'M.lean')]) + def test_unicode_identifier_prefix_does_not_hide_keyword(self): + # Greek lambda is a binder token, not an identifier letter in Lean. + self.assertEqual(kinds('def f := λsorry => sorry'), ['sorry','sorry']) + def test_pinned_lean_identifier_character_domain(self): + # Lean4.34.1 Init/Meta/Defs.lean:101-143, not Unicode category L. + for prefix in ['λ','Π','Σ','Ж','ᵀ','𝛂']: + with self.subTest(prefix=prefix): self.assertEqual(kinds(prefix+'sorry'),['sorry']) + for prefix in ['α','é','Ā','ℵ','𝔸']: + with self.subTest(prefix=prefix): self.assertEqual(kinds(prefix+'sorry'),[]) + self.assertEqual(kinds('native_decideⱼ'),[]) + def test_unsupported_character_escape_is_error(self): + for src in [r"def c := '\q'",r"def c := '\u{41}'"]: + with self.subTest(src=src): + self.assertTrue([f for f in S.scan_text(src,'M.lean') if f['severity']=='error']) + +class InputCoverage(unittest.TestCase): + def test_missing_root_fails_for_both_tools(self): + with tempfile.TemporaryDirectory() as d: + for tool in [SCAN,CENSUS]: + with self.subTest(tool=tool): + p=cli(tool,Path(d)/'does-not-exist') + self.assertEqual(p.returncode,2,p.stdout+p.stderr) + def test_source_symlink_fails_for_both_tools(self): + with tempfile.TemporaryDirectory() as d: + root=Path(d) + for tool,suffix in [(SCAN,'.lean'),(CENSUS,'.py')]: + target=root/('target'+suffix);target.write_text('') + link=root/('link'+suffix);link.symlink_to(target) + with self.subTest(tool=tool): + p=cli(tool,link) + self.assertEqual(p.returncode,2,p.stdout+p.stderr) + def test_symlink_directory_is_not_silently_skipped(self): + with tempfile.TemporaryDirectory() as d: + root=Path(d);actual=root/'actual';actual.mkdir();(root/'alias').symlink_to(actual,target_is_directory=True) + for tool in [SCAN,CENSUS]: + with self.subTest(tool=tool): self.assertEqual(cli(tool,root).returncode,2) + def test_git_source_symlink_fails_for_both_tools(self): + with tempfile.TemporaryDirectory() as d: + root=Path(d) + def git(*a): + return subprocess.run(['git','-c','user.name=t','-c','user.email=t@x','-c','commit.gpgsign=false',*a],cwd=d,check=True,capture_output=True) + git('init','-q');(root/'A.lean').symlink_to('other');(root/'a.py').symlink_to('other') + git('add','-A');git('commit','-qm','fixture') + for tool in [SCAN,CENSUS]: + with self.subTest(tool=tool): self.assertEqual(cli(tool,'--git',root).returncode,2) + def test_gitlink_is_explicitly_rejected_by_both_tools(self): + with tempfile.TemporaryDirectory() as d: + root=Path(d) + def git(*a): return subprocess.run(['git','-c','user.name=t','-c','user.email=t@x','-c','commit.gpgsign=false',*a],cwd=d,check=True,capture_output=True) + git('init','-q');(root/'README').write_text('x');git('add','-A');git('commit','-qm','fixture') + sha=git('rev-parse','HEAD').stdout.decode().strip();git('update-index','--add','--cacheinfo',f'160000,{sha},sub');git('commit','-qm','gitlink') + for tool in [SCAN,CENSUS]: + with self.subTest(tool=tool): self.assertEqual(cli(tool,'--git',root).returncode,2) + + +class GitObjectTransport(unittest.TestCase): + def test_malformed_blob_transport_fails_closed(self): + import io + from unittest.mock import patch + sha='a'*40 + class Proc: + def __init__(self, payload, code): + self.stdin=io.BytesIO();self.stdout=io.BytesIO(payload);self.stderr=io.BytesIO();self.code=code + def poll(self): return self.code + def wait(self): return self.code + def terminate(self): self.code=-15 + for tool,fn,suffix in [(SCAN,'git_lean_blobs','.lean'),(CENSUS,'_git_blobs','.py')]: + mod=load(tool,'transport_test') + tree=subprocess.CompletedProcess([],0,stdout=f'100644 blob {sha}\tA{suffix}\0'.encode()) + bad=[(f'{sha} tree 1\nx\n'.encode(),0), + (f'{"b"*40} blob 1\nx\n'.encode(),0), + (f'{sha} blob 8\nx\n'.encode(),0), + (f'{sha} blob 1\nxX'.encode(),0), + (f'{sha} blob 1\nx\n'.encode(),7)] + for payload,code in bad: + with self.subTest(tool=tool,payload=payload,code=code): + with patch.object(mod.subprocess,'run',return_value=tree),patch.object(mod.subprocess,'Popen',return_value=Proc(payload,code)): + with self.assertRaises(OSError): list(getattr(mod,fn)('repo','HEAD')) + +@unittest.skipIf(os.environ.get("CBZ_LAYER_A_SCAN") or os.environ.get("CBZ_A3_CENSUS"), "mutation subprocess: harness controls run only at top level") +class MutationKillClassification(unittest.TestCase): + def test_nonbehavioral_failures_do_not_count_as_kills(self): + modules=[load(ROOT/'tests/test_cbz_layer_a_scan_mutants.py','scan_mutants'),load(ROOT/'tests/test_cbz_a3_float_census.py','a3_mutants')] + samples=['SyntaxError: invalid syntax', + 'Ran 1 test in 0.0s\nFAILED (errors=1)\nERROR: test_expected (tests.C)\n', + 'Ran 3 tests in 0.0s\nFAILED (failures=1, errors=1)\nFAIL: test_expected (tests.C)\n', + 'Ran 3 tests in 0.0s\nFAILED (failures=1)\nFAIL: test_other (tests.C)\n'] + for mod in modules: + for out in samples: + with self.subTest(module=mod.__name__,out=out): + self.assertFalse(mod.killed(subprocess.CompletedProcess([],1,stdout='',stderr=out),'test_expected')) + good='Ran 3 tests in 0.0s\nFAILED (failures=1)\nFAIL: test_expected (tests.C)\n' + self.assertTrue(mod.killed(subprocess.CompletedProcess([],1,stdout='',stderr=good),'test_expected')) + def test_actual_syntax_broken_tool_is_not_a_kill(self): + with tempfile.TemporaryDirectory() as d: + broken=Path(d)/'broken.py';broken.write_text('def broken(:\n') + for testfile in ['test_cbz_layer_a_scan_mutants.py','test_cbz_a3_float_census.py']: + mod=load(ROOT/'tests'/testfile,'broken_harness') + proc=mod.run_suite(str(broken)) + self.assertNotEqual(proc.returncode,0) + self.assertFalse(mod.killed(proc),'syntax-broken source must remain an invalid mutant') + +if __name__=='__main__': unittest.main() diff --git a/tests/test_cbz_layer_a_scan.py b/tests/test_cbz_layer_a_scan.py new file mode 100644 index 000000000..8d7fa5261 --- /dev/null +++ b/tests/test_cbz_layer_a_scan.py @@ -0,0 +1,293 @@ +"""Unit and negative controls for tools/cbz/layer_a_scan.py (CBZ-0 gate G0/G1). + +The scanner under test is loaded from $CBZ_LAYER_A_SCAN when set (the mutation +harness in test_cbz_layer_a_scan_mutants.py points it at mutated copies), else +from tools/cbz/layer_a_scan.py. Every case asserts the exact finding list, so a +scanner that over- or under-reports fails. +""" +import importlib.util +import json +import os +import subprocess +import sys +import tempfile +import unittest + +HERE = os.path.dirname(os.path.abspath(__file__)) +WORKSPACE = os.path.dirname(HERE) +SCANNER = os.environ.get("CBZ_LAYER_A_SCAN") or os.path.join(WORKSPACE, "tools", "cbz", "layer_a_scan.py") + + +def _load(): + spec = importlib.util.spec_from_file_location("layer_a_scan_under_test", SCANNER) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod + + +M = _load() + + +def hits(text, path="Pkg/Mod.lean"): + return [(f["line"], f["col"], f["kind"], f["severity"]) for f in M.scan_text(text, path)] + + +def cli(args, cwd=None): + return subprocess.run([sys.executable, "-I", SCANNER] + list(args), cwd=cwd, + capture_output=True, text=True) + + +class ViolationTokens(unittest.TestCase): + def test_each_violation_token_detected(self): + cases = { + "theorem t : True := by sorry": [(1, 24, "sorry", "violation")], + "theorem t : True := sorry": [(1, 21, "sorry", "violation")], + "example : True := by\n admit": [(2, 3, "admit", "violation")], + "axiom bad : False": [(1, 1, "axiom", "violation")], + "private axiom bad : False": [(1, 9, "axiom", "violation")], + "theorem t : 2 = 2 := by native_decide": [(1, 25, "native_decide", "violation")], + "def x := Lean.ofReduceBool": [(1, 10, "ofReduceBool", "violation")], + "def x := Lean.ofReduceNat": [(1, 10, "ofReduceNat", "violation")], + "def x := Lean.trustCompiler": [(1, 10, "trustCompiler", "violation")], + "set_option debug.skipKernelTC true": [(1, 12, "skipKernelTC", "violation")], + "def x := mkConst ``sorryAx": [(1, 20, "sorryAx", "violation")], + "def x := Lean.Elab.admitGoal": [(1, 10, "admitGoal", "violation")], + "def x := Lean.Meta.mkSorry": [(1, 10, "mkSorry", "violation")], + "def x := Environment.addDeclWithoutChecking": [(1, 10, "addDeclWithoutChecking", "violation")], + } + for src, want in cases.items(): + with self.subTest(src=src): + self.assertEqual(hits(src), want) + + def test_native_decide_options(self): + # `decide +native` and `native := true` evaluate by the compiler (ofReduceBool) + self.assertEqual(hits("example : 2 = 2 := by decide +native"), [(1, 31, "native", "violation")]) + self.assertEqual(hits("example : 2 = 2 := by decide + native"), [(1, 32, "native", "violation")]) + self.assertEqual(hits("example : P := by decide (config := { native := true })"), + [(1, 39, "native", "violation")]) + self.assertEqual(hits("example : P := by decide (config := {native:=true})"), + [(1, 38, "native", "violation")]) + self.assertEqual(hits("example : 2 = 2 := by decide +kernel"), []) + self.assertEqual(hits("example : P := by decide (config := { native := false })"), []) + self.assertEqual(hits("def native := 1 ; def y := native + 1"), []) + self.assertEqual(hits("def y := native"), []) + # safe direction: arithmetic on an identifier named native is also flagged + self.assertEqual(hits("def y := x + native"), [(1, 14, "native", "violation")]) + + def test_review_tokens(self): + self.assertEqual(hits("def f (x : Float) := x"), [(1, 12, "Float", "review")]) + self.assertEqual(hits("def f (x : Float32) := x"), [(1, 12, "Float32", "review")]) + self.assertEqual(hits("unsafe def f := 1"), [(1, 1, "unsafe", "review")]) + self.assertEqual(hits("@[implemented_by g] def f := 1"), [(1, 3, "implemented_by", "review")]) + self.assertEqual(hits("@[extern \"c\"] def f := 1"), [(1, 3, "extern", "review")]) + self.assertEqual(hits("example : True := by\n stop\n trivial"), [(2, 3, "stop", "review")]) + + def test_stop_only_at_line_start(self): + self.assertEqual(hits("def stop := 1"), []) + self.assertEqual(hits("example := f stop"), []) + + def test_multiple_and_positions(self): + src = "theorem a : True := sorry\n\ntheorem b : True := by\n admit\naxiom c : False\n" + self.assertEqual(hits(src), [(1, 21, "sorry", "violation"), (4, 5, "admit", "violation"), + (5, 1, "axiom", "violation")]) + + def test_eof_without_newline(self): + self.assertEqual(hits("example : True := sorry"), [(1, 19, "sorry", "violation")]) + + def test_unicode_before_token_counts_characters(self): + self.assertEqual(hits("theorem α₁ : True := sorry"), [(1, 22, "sorry", "violation")]) + + +class NotCode(unittest.TestCase): + def test_line_comment(self): + self.assertEqual(hits("-- sorry admit axiom native_decide\ntheorem t : True := trivial"), []) + self.assertEqual(hits("theorem t : True := trivial -- sorry"), []) + + def test_block_comments_nested_and_doc(self): + self.assertEqual(hits("/- sorry /- nested sorry -/ still sorry -/ def x := 1"), []) + self.assertEqual(hits("/-- doc: uses sorry -/ def x := 1"), []) + self.assertEqual(hits("/-! module doc axiom -/"), []) + # a single close of a two-deep nest must not end the comment + self.assertEqual(hits("/- a /- b -/ sorry -/ def y := sorry"), [(1, 32, "sorry", "violation")]) + + def test_strings(self): + self.assertEqual(hits('def s := "sorry axiom"'), []) + self.assertEqual(hits('def s := "escaped \\" sorry"'), []) + self.assertEqual(hits('def s := "a\\\\" ; theorem t : True := sorry'), + [(1, 38, "sorry", "violation")]) + self.assertEqual(hits('def s := "-- not a comment" ; def t := sorry'), + [(1, 40, "sorry", "violation")]) + self.assertEqual(hits('def s := "/- not a comment" ; def t := sorry'), + [(1, 40, "sorry", "violation")]) + + def test_raw_strings(self): + self.assertEqual(hits('def s := r"sorry"'), []) + self.assertEqual(hits('def s := r#"a " sorry "#'), []) + self.assertEqual(hits('def s := r#"a " x "# ; def t := sorry'), [(1, 33, "sorry", "violation")]) + + def test_char_literals_do_not_open_strings(self): + self.assertEqual(hits("def q := '\"' ; theorem t : True := sorry"), + [(1, 36, "sorry", "violation")]) + self.assertEqual(hits("def q := '\\'' ; theorem t : True := sorry"), + [(1, 37, "sorry", "violation")]) + self.assertEqual(hits("def f' := 1 ; def g'' := f' ; def h := sorry"), + [(1, 40, "sorry", "violation")]) + + def test_interpolated_strings(self): + self.assertEqual(hits('def s := s!"{1} sorry"'), []) + self.assertEqual(hits('def s := s!"x {sorry} y"'), [(1, 16, "sorry", "violation")]) + self.assertEqual(hits('def s := s!"x {f "sorry" sorry} y"'), [(1, 26, "sorry", "violation")]) + self.assertEqual(hits('def s := m!"{ {a := 1} } sorry" ; def t := sorry'), + [(1, 44, "sorry", "violation")]) + + def test_identifiers_containing_keywords(self): + self.assertEqual(hits("def sorryFree := mysorry ; def admitted := axiomatic"), []) + self.assertEqual(hits("def native_decide_ok := 1 ; def Floaty := 2"), []) + self.assertEqual(hits("#print axioms foo"), []) + self.assertEqual(hits("def x := Foo.sorry ; def y := Bar.axiom"), []) + + def test_escaped_keyword_names_are_identifiers(self): + # «sorry» is an identifier named sorry, never the sorry term or tactic + self.assertEqual(hits("def «sorry» := 1 ; def x := «axiom»"), []) + self.assertEqual(hits("def «Float» := 1"), []) + + def test_escaped_constant_names_are_the_same_constants(self): + # «x» and x are the same name component, so these are real uses + self.assertEqual(hits("def x := Lean.«ofReduceBool»"), [(1, 10, "ofReduceBool", "violation")]) + self.assertEqual(hits("def x : False := «sorryAx» False"), [(1, 18, "sorryAx", "violation")]) + self.assertEqual(hits("def x := Lean.«trustCompiler».foo"), []) + self.assertEqual(hits("@[«implemented_by» g] def f := 1"), [(1, 3, "implemented_by", "review")]) + # a dot inside «» is part of one component, not a namespace separator + self.assertEqual(hits("def x := «Lean.ofReduceBool»"), []) + + +class FailClosed(unittest.TestCase): + def errors(self, text): + return [(f["line"], f["col"], f["kind"], f["severity"]) for f in M.scan_text(text, "P/M.lean") + if f["severity"] == "error"] + + def test_unterminated_constructs_are_errors(self): + cases = { + 'def s := "open\ntheorem t : False := sorry': (1, 10, "unterminated_string"), + "/- open\ntheorem t : False := sorry": (1, 1, "unterminated_comment"), + "/- a /- b -/ still open\n": (1, 1, "unterminated_comment"), + 'def s := r#"open\nsorry': (1, 10, "unterminated_raw_string"), + 'def s := s!"{': (1, 10, "unterminated_interpolated_string"), + 'def s := s!"abc': (1, 10, "unterminated_interpolated_string"), + "def x := «open\nsorry": (1, 10, "unterminated_escaped_name"), + "def x := Foo.«open": (1, 14, "unterminated_escaped_name"), + } + for src, (ln, cl, kind) in cases.items(): + with self.subTest(src=src): + self.assertEqual(self.errors(src), [(ln, cl, kind, "error")]) + + def test_terminated_constructs_are_not_errors(self): + for src in ['def s := "a"', "/- a /- b -/ c -/", 'def s := r#"a"#', 'def s := s!"{x} {y}"', + "def x := «a b»", "-- unterminated \" in a comment", "def c := '\"'"]: + with self.subTest(src=src): + self.assertEqual(self.errors(src), []) + + def test_lex_error_fails_the_run(self): + with tempfile.TemporaryDirectory() as d: + with open(os.path.join(d, "A.lean"), "w", encoding="utf-8") as fh: + fh.write('def s := "never closed\n') + r = cli([d]) + self.assertEqual(r.returncode, 1) + self.assertIn("A.lean:1:10: A unterminated_string (production)", r.stdout) + self.assertEqual(json.loads(r.stdout.strip().splitlines()[-1])["errors"], 1) + + +class Context(unittest.TestCase): + def test_context_classification(self): + self.assertEqual(M.context_of("frontiers/x/Mod.lean"), "production") + self.assertEqual(M.context_of("frontiers/x/foo-evidence/raw/producer/runs/a/Mod.lean"), "evidence_copy") + self.assertEqual(M.context_of("a/raw/Mod.lean"), "evidence_copy") + self.assertEqual(M.context_of("frontiers/x/ModControls.lean"), "control") + self.assertEqual(M.context_of("frontiers/x/NegativeSorry.lean"), "control") + findings = M.scan_text("def t := sorry", "a/raw/M.lean") + self.assertEqual(len(findings), 1) + self.assertEqual(findings[0]["context"], "evidence_copy") + + +class CommandLine(unittest.TestCase): + def write(self, d, rel, text, raw=None): + p = os.path.join(d, rel) + os.makedirs(os.path.dirname(p), exist_ok=True) + with open(p, "wb") as fh: + fh.write(raw if raw is not None else text.encode("utf-8")) + return p + + def test_clean_tree_exits_zero(self): + with tempfile.TemporaryDirectory() as d: + self.write(d, "A.lean", "theorem t : True := trivial -- sorry\n") + r = cli([d]) + self.assertEqual(r.returncode, 0, r.stdout + r.stderr) + self.assertEqual(json.loads(r.stdout.strip().splitlines()[-1])["violations"], 0) + + def test_production_violation_fails(self): + with tempfile.TemporaryDirectory() as d: + self.write(d, "A.lean", "theorem t : True := sorry\n") + r = cli([d]) + self.assertEqual(r.returncode, 1) + self.assertIn("A.lean:1:21: A1 sorry (production)", r.stdout) + + def test_evidence_violation_reported_not_failing_by_default(self): + with tempfile.TemporaryDirectory() as d: + self.write(d, "x-evidence/raw/A.lean", "theorem t : True := sorry\n") + out = os.path.join(d, "out.json") + r = cli([d, "--json", out]) + self.assertEqual(r.returncode, 0, r.stdout) + with open(out, encoding="utf-8") as fh: + data = json.load(fh) + self.assertEqual(data["summary"]["violations"], 1) + self.assertEqual(data["findings"][0]["context"], "evidence_copy") + r2 = cli([d, "--fail-on", "all"]) + self.assertEqual(r2.returncode, 1) + + def test_review_only_does_not_fail(self): + with tempfile.TemporaryDirectory() as d: + self.write(d, "A.lean", "def f (x : Float) := x\n") + self.assertEqual(cli([d]).returncode, 0) + + def test_undecodable_fails_closed(self): + with tempfile.TemporaryDirectory() as d: + self.write(d, "A.lean", None, raw=b"theorem t : True := \xff\xfe\n") + r = cli([d]) + self.assertEqual(r.returncode, 1) + self.assertIn("undecodable", r.stdout) + + def test_non_lean_files_ignored(self): + with tempfile.TemporaryDirectory() as d: + self.write(d, "A.md", "sorry\n") + r = cli([d]) + self.assertEqual(r.returncode, 0) + self.assertEqual(json.loads(r.stdout.strip().splitlines()[-1])["files"], 0) + + def test_usage_error(self): + self.assertEqual(cli([]).returncode, 2) + + def test_git_tree_mode(self): + with tempfile.TemporaryDirectory() as d: + env = dict(os.environ, GIT_CONFIG_GLOBAL=os.devnull, GIT_CONFIG_SYSTEM=os.devnull) + run = lambda *a: subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@x", + "-c", "commit.gpgsign=false"] + list(a), cwd=d, + check=True, capture_output=True, env=env) + run("init", "-q") + self.write(d, "src/A.lean", "theorem t : True := sorry\n") + self.write(d, "src/B.lean", "theorem u : True := trivial\n") + run("add", "-A") + run("commit", "-q", "-m", "c") + # the working tree is changed afterwards; git mode must read the commit + self.write(d, "src/A.lean", "theorem t : True := trivial\n") + out = os.path.join(d, "o.json") + r = cli(["--git", d, "--rev", "HEAD", "--json", out]) + self.assertEqual(r.returncode, 1, r.stdout + r.stderr) + with open(out, encoding="utf-8") as fh: + data = json.load(fh) + self.assertEqual(data["summary"]["files"], 2) + self.assertEqual([(f["path"], f["kind"]) for f in data["findings"]], [("src/A.lean", "sorry")]) + self.assertEqual(len(data["findings"][0]["blob"]), 40) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_cbz_layer_a_scan_mutants.py b/tests/test_cbz_layer_a_scan_mutants.py new file mode 100644 index 000000000..dd354a738 --- /dev/null +++ b/tests/test_cbz_layer_a_scan_mutants.py @@ -0,0 +1,157 @@ +"""Mutation self-test of the Layer A scanner (CBZ-0 gate G0, directive §2.3/A8). + +Each mutant is a copy of tools/cbz/layer_a_scan.py with one deliberate defect: +a hazard token dropped, a lexer rule broken, or a fail-closed exit weakened. +The scanner's own suite (tests/test_cbz_layer_a_scan.py) is run against every +mutant through $CBZ_LAYER_A_SCAN and must FAIL. A surviving mutant means the +suite cannot tell a broken auditor from a sound one, so this test fails. + +Every replacement must match the scanner source exactly once, so the harness +cannot silently drift out of sync with the code it mutates. A mutant counts as +killed only when the suite loaded and ran, and at least one test failed or +errored; a suite that could not even be imported proves nothing. +""" +import os +import re +import subprocess +import sys +import tempfile +import unittest + +HERE = os.path.dirname(os.path.abspath(__file__)) +WORKSPACE = os.path.dirname(HERE) +SCANNER = os.path.join(WORKSPACE, "tools", "cbz", "layer_a_scan.py") + +MUTANTS = [ + ("drop sorry", ' "sorry": "A1",\n', ""), + ("drop admit", ' "admit": "A1",\n', ""), + ("drop axiom", ' "axiom": "A2",\n', ""), + ("drop native_decide", ' "native_decide": "A2",\n', ""), + ("drop sorryAx", ' "sorryAx": "A1",\n', ""), + ("drop admitGoal", ' "admitGoal": "A1",\n', ""), + ("drop mkSorry", ' "mkSorry": "A1",\n', ""), + ("drop ofReduceBool", ' "ofReduceBool": "A2",\n', ""), + ("drop ofReduceNat", ' "ofReduceNat": "A2",\n', ""), + ("drop trustCompiler", ' "trustCompiler": "A2",\n', ""), + ("drop skipKernelTC", ' "skipKernelTC": "A2",\n', ""), + ("drop Float review", ' "Float": "A3",\n', ""), + ("violation demoted to review", 'return name, VIOLATION_EXACT[name], "violation"', + 'return name, VIOLATION_EXACT[name], "review"'), + ("no line comments", 'if c == "-" and text.startswith("--", i):', 'if False:'), + ("flat block comments", 'if text.startswith("/-", i):\n depth += 1\n', 'if text.startswith("/-", i):\n depth = 1\n'), + ("plain strings not skipped", " if c == '\"':\n", " if False:\n"), + ("interpolation regions not lexed", 'stack.append(["code", 0])', "pass"), + ("char literals not recognised", "m = _CHAR_LIT.match(text, i)", "m = None"), + ("raw strings not recognised", 'if word == "r" and i < n', 'if False and i < n'), + ("dotted names not split", 'last = name.split(".")[-1]', "last = name"), + ("stop flagged anywhere", "if line_start and name in LINE_START_REVIEW:", + "if name in LINE_START_REVIEW:"), + ("evidence treated as production", 'return "evidence_copy"', 'return "production"'), + ("git mode lists no blobs", 'if typ == b"blob" and p.endswith(".lean"):', "if False:"), + ("violations never fail", "return 1 if failing else 0", "return 0"), + ("undecodable files pass", " if undecodable:\n return 1\n", + " if False:\n return 1\n"), + ("fail on every context by default", 'ap.add_argument("--fail-on", default="production")', + 'ap.add_argument("--fail-on", default="all")'), + # added after 014K's specification (main#684/6503596060) + ("drop addDeclWithoutChecking", ' "addDeclWithoutChecking": "A2",\n', ""), + ("+native ignored", 'if name == "native" and (plus_before or _NATIVE_TRUE.match(follow) or (field_before and _native_assignment(follow))):', + 'if name == "native" and (_NATIVE_TRUE.match(follow) or (field_before and _native_assignment(follow))):'), + ("native := true ignored", 'if name == "native" and (plus_before or _NATIVE_TRUE.match(follow) or (field_before and _native_assignment(follow))):', + 'if name == "native" and plus_before:'), + ("escaped constants never match", " # escaped component: the same constant name, never a keyword\n last = last[1:]", + " return None"), + ("escaped keywords flagged", + ' if last in REVIEW_COMPONENT:\n return last, REVIEW_COMPONENT[last], "review"\n return None', + ' if last in REVIEW_COMPONENT:\n return last, REVIEW_COMPONENT[last], "review"\n' + ' return (last, VIOLATION_EXACT[last], "violation") if last in VIOLATION_EXACT else None'), + ("dots inside escaped names split", 'parts = ["\\x00" + inner.replace(".", "\\x01")]', 'parts = ["\\x00" + inner]'), + ("unterminated string passes", 'errors.append(start + ("unterminated_string",))', "pass"), + ("unterminated comment passes", 'errors.append(start + ("unterminated_comment",))', "pass"), + ("unterminated raw string passes", 'errors.append((start_line, start_col, "unterminated_raw_string"))', "pass"), + ("unterminated interpolation passes", + 'errors.append((frame[1], frame[2], "unterminated_interpolated_string"))', "pass"), + ("unterminated escaped name passes", + ' errors.append((line, col, "unterminated_escaped_name"))\n advance(n - i)\n break', + ' advance(n - i)\n break'), + ("unterminated dotted escaped name passes", + ' errors.append((line, col, "unterminated_escaped_name"))\n advance(n - i)\n' + ' return', + ' advance(n - i)\n return'), + ("lex errors never fail", 'f["severity"] in ("violation", "error")', 'f["severity"] == "violation"'), +] + + +# Additional source mutations for the canonical input/lexer repairs. +MUTANTS.extend([('native comment layout ignored', " elif text.startswith('/-', i):", ' elif False:'), ('native suffix truncated', 'while i < len(text) and len(out) < 8:', 'while i < len(text) and len(out) < 8 and i - start < 40:'), ('plain macro braces ignored', 'yield from _brace_segments(text, content_start, i - 1, start[0], start[1] + 1)', 'pass'), ('unfinished char ignored', "errors.append((line, col, 'unterminated_char'))", 'pass'), ('missing root ignored', 'raise OSError(f"source path does not exist: {p}")', 'pass'), ('source symlink accepted', 'raise OSError(f"source symlink requires explicit target admission: {p}")', 'pass'), ('directory symlink skipped', 'raise OSError(f"source directory symlink requires explicit target admission: {d}")', 'pass'), ('gitlink skipped', 'raise OSError(f"gitlink requires a separately pinned scan: {p}")', 'pass'), ('git source symlink accepted', 'if mode not in (b"100644", b"100755"):', 'if False:'), ('git batch header unchecked', 'if len(header) != 3 or header[0] != sha.encode() or header[1] != b"blob" or not header[2].isdigit():', 'if False:'), ('git batch body unchecked', 'if len(data) != size or trailer != b"\\n":', 'if False:'), ('git batch exit unchecked', 'if code != 0:', 'if False:')]) + +MUTANTS.extend([('interpolation prefix layout ignored', 'if last_code_char in INTERP_PREFIXES:', 'if False:'), ('drop Float32 review', ' "Float32": "A3",\n', ''), ('drop unsafe review', ' "unsafe": "A2",\n', ''), ('drop implemented_by review', ' "implemented_by": "A2",\n', ''), ('drop extern review', ' "extern": "A2",\n', '')]) + +MUTANTS.extend([('macro hole truncated at primary quote', 'lex_tokens(text[i + 1:], _until_brace=True)', 'lex_tokens(text[i + 1:end], _until_brace=True)'), ('numeral swallows adjacent keyword', 'match = _NUMERAL.match(text, i)', 'match = re.compile(r"[A-Za-z0-9_]+").match(text, i)')]) + +MUTANTS.extend([('scientific numeric tail ignored', 'match = _NUMERAL.match(text, i)', 'match = re.compile(r"[0-9_]+").match(text, i)'), ('prime notation called invalid char', 'if m is None and not prime_notation:', 'if m is None:'), ('unicode char escape ignored', 'u[0-9a-fA-F]{4}|', '')]) + +MUTANTS.extend([('identifier domain broadened to Unicode letters', ' o = ord(ch)\n # Letter-like symbols', ' if ch.isalpha():\n return True\n o = ord(ch)\n # Letter-like symbols'), ('U2C7C identifier suffix omitted', ' or o == 0x2C7C', ''), ('unsupported char escape accepted', '_CHAR_LIT = re.compile(r"\'(?:\\\\(?:u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2}|[\\\\\\"\'rnt])|[^\\\\\'\\n])\'")', '_CHAR_LIT = re.compile(r"\'(?:\\\\(?:u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2}|.)|[^\\\\\'\\n])\'")')]) + +MUTANTS.extend([('unknown native field expression admitted', '(field_before and _native_assignment(follow))', 'False'), ('false expression mistaken for literal false', "not (len(follow) >= 8 and follow[2:7] == 'false' and follow[7] in '},')", "not follow.startswith(':=false')")]) + +EXPECTED_FAILURE = {'drop sorry': 'test_each_violation_token_detected', 'drop admit': 'test_each_violation_token_detected', 'drop axiom': 'test_each_violation_token_detected', 'drop native_decide': 'test_each_violation_token_detected', 'drop sorryAx': 'test_each_violation_token_detected', 'drop admitGoal': 'test_each_violation_token_detected', 'drop mkSorry': 'test_each_violation_token_detected', 'drop ofReduceBool': 'test_each_violation_token_detected', 'drop ofReduceNat': 'test_each_violation_token_detected', 'drop trustCompiler': 'test_each_violation_token_detected', 'drop skipKernelTC': 'test_each_violation_token_detected', 'drop Float review': 'test_review_tokens', 'violation demoted to review': 'test_each_violation_token_detected', 'no line comments': 'test_line_comment', 'flat block comments': 'test_block_comments_nested_and_doc', 'plain strings not skipped': 'test_strings', 'interpolation regions not lexed': 'test_interpolated_strings', 'char literals not recognised': 'test_char_literals_do_not_open_strings', 'raw strings not recognised': 'test_raw_strings', 'dotted names not split': 'test_each_violation_token_detected', 'stop flagged anywhere': 'test_stop_only_at_line_start', 'evidence treated as production': 'test_context_classification', 'git mode lists no blobs': 'test_git_tree_mode', 'violations never fail': 'test_production_violation_fails', 'undecodable files pass': 'test_undecodable_fails_closed', 'fail on every context by default': 'test_evidence_violation_reported_not_failing_by_default', 'drop addDeclWithoutChecking': 'test_each_violation_token_detected', '+native ignored': 'test_native_decide_options', 'native := true ignored': 'test_native_decide_options', 'escaped constants never match': 'test_escaped_constant_names_are_the_same_constants', 'escaped keywords flagged': 'test_escaped_keyword_names_are_identifiers', 'dots inside escaped names split': 'test_escaped_constant_names_are_the_same_constants', 'unterminated string passes': 'test_unterminated_constructs_are_errors', 'unterminated comment passes': 'test_unterminated_constructs_are_errors', 'unterminated raw string passes': 'test_unterminated_constructs_are_errors', 'unterminated interpolation passes': 'test_unterminated_constructs_are_errors', 'unterminated escaped name passes': 'test_unterminated_constructs_are_errors', 'unterminated dotted escaped name passes': 'test_unterminated_constructs_are_errors', 'lex errors never fail': 'test_lex_error_fails_the_run'} + +EXPECTED_FAILURE.update({'native comment layout ignored': 'test_native_configuration_layout_is_not_a_bypass', 'native suffix truncated': 'test_native_configuration_layout_is_not_a_bypass', 'plain macro braces ignored': 'test_plain_macro_braces_are_conservatively_scanned', 'unfinished char ignored': 'test_unterminated_character_literal_is_error', 'missing root ignored': 'test_missing_root_fails_for_both_tools', 'source symlink accepted': 'test_source_symlink_fails_for_both_tools', 'directory symlink skipped': 'test_symlink_directory_is_not_silently_skipped', 'gitlink skipped': 'test_gitlink_is_explicitly_rejected_by_both_tools', 'git source symlink accepted': 'test_git_source_symlink_fails_for_both_tools', 'git batch header unchecked': 'test_malformed_blob_transport_fails_closed', 'git batch body unchecked': 'test_malformed_blob_transport_fails_closed', 'git batch exit unchecked': 'test_malformed_blob_transport_fails_closed'}) + +EXPECTED_FAILURE.update({'interpolation prefix layout ignored': 'test_interpolation_prefix_accepts_lean_layout', 'drop Float32 review': 'test_review_tokens', 'drop unsafe review': 'test_review_tokens', 'drop implemented_by review': 'test_review_tokens', 'drop extern review': 'test_review_tokens'}) + +EXPECTED_FAILURE.update({'macro hole truncated at primary quote': 'test_plain_macro_holes_with_nested_literals', 'numeral swallows adjacent keyword': 'test_adjacent_numeral_never_swallows_code_keyword'}) + +EXPECTED_FAILURE.update({'scientific numeric tail ignored': 'test_scientific_and_radix_numerals_preserve_keyword_boundary', 'prime notation called invalid char': 'test_mathlib_prime_notations_are_not_unfinished_characters', 'unicode char escape ignored': 'test_mathlib_prime_notations_are_not_unfinished_characters'}) + +EXPECTED_FAILURE.update({'identifier domain broadened to Unicode letters': 'test_pinned_lean_identifier_character_domain', 'U2C7C identifier suffix omitted': 'test_pinned_lean_identifier_character_domain', 'unsupported char escape accepted': 'test_unsupported_character_escape_is_error'}) + +EXPECTED_FAILURE.update({'unknown native field expression admitted': 'test_unknown_native_field_expression_fails_closed', 'false expression mistaken for literal false': 'test_unknown_native_field_expression_fails_closed'}) + +def run_suite(scanner_path): + env = dict(os.environ, CBZ_LAYER_A_SCAN=scanner_path, PYTHONDONTWRITEBYTECODE="1") + return subprocess.run([sys.executable, *(["-O"] if sys.flags.optimize else []), "-B", "-S", "-m", "unittest", "-v", "tests.test_cbz_layer_a_scan", "tests.test_cbz_auditor_hardening"], + cwd=WORKSPACE, env=env, capture_output=True, text=True, timeout=600) + + +def killed(r, expected_test=None): + """Only a named assertion failure kills; launch/import/errors do not.""" + out = r.stdout + r.stderr + summary = re.search(r"^FAILED \(([^)]*)\)$", out, re.M) + if r.returncode == 0 or not summary or "errors=" in summary.group(1): + return False + if not re.search(r"^Ran [1-9][0-9]* tests?", out, re.M): + return False + failures = re.findall(r"^FAIL: (test_[A-Za-z0-9_]+) \(", out, re.M) + return bool(failures) and (expected_test is None or expected_test in failures) + + +class ScannerMutants(unittest.TestCase): + @classmethod + def setUpClass(cls): + with open(SCANNER, encoding="utf-8") as fh: + cls.source = fh.read() + + def test_unmutated_scanner_passes_its_suite(self): + r = run_suite(SCANNER) + self.assertEqual(r.returncode, 0, r.stdout + r.stderr) + + def test_every_mutant_is_killed(self): + survivors = [] + with tempfile.TemporaryDirectory() as d: + for i, (name, old, new) in enumerate(MUTANTS): + with self.subTest(mutant=name): + self.assertEqual(self.source.count(old), 1, f"mutation point drifted: {name}") + path = os.path.join(d, f"mutant_{i:02d}.py") + with open(path, "w", encoding="utf-8") as fh: + fh.write(self.source.replace(old, new)) + r = run_suite(path) + if not killed(r, EXPECTED_FAILURE[name]): + survivors.append(name) + self.assertEqual(survivors, [], f"surviving mutants: {survivors}") + self.assertGreaterEqual(len(MUTANTS), 39) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/cbz/a3_float_census.py b/tools/cbz/a3_float_census.py new file mode 100644 index 000000000..50a902c4c --- /dev/null +++ b/tools/cbz/a3_float_census.py @@ -0,0 +1,299 @@ +#!/usr/bin/env python3 +"""Layer A3 float-use census for Python sources (CBZ-0 Phase 1 discovery). + +Layer A3 forbids floating-point certification of mathematical bounds. Whether a +given float is *used to certify* a bound is a question about intent that no +static tool can settle, so this tool is a census, not a certifier: it records, +for every Python file, exactly where floating-point arithmetic can enter, plus +the exact-arithmetic machinery the file uses, so each file can be triaged. + +Signals (each reported with line and column): + float_literal a float or complex literal (``0.5``, ``1e-9``, ``2j``) + float_call a call ``float(...)`` or ``complex(...)`` + true_division the ``/`` or ``/=`` operator (int / int yields a float) + math_float ``math.X`` / ``cmath.X`` for any X not in EXACT_MATH + (attribute access or ``from math import X``) + float_module import of numpy, scipy, mpmath, decimal or cmath + exact_module import of fractions, sympy, flint (python-flint) or + gmpy2, or use of ``mpmath.iv`` (interval arithmetic) + interval_layer an outward-rounding interval layer: ``math.nextafter`` / + ``math.ulp`` (attribute or import), or an import of a + module named ``ia`` (the project's outward-rounded + interval modules) + +Classification per file (derived only from the signals above): + NO_FLOAT_SIGNAL no float_literal / float_call / true_division / + math_float / float_module + FLOAT_SIGNAL at least one of those, and no exact_module + MIXED float signals and exact or interval machinery both present + UNPARSEABLE the file is not valid Python 3 (fails closed) + +Dynamic imports, arbitrary aliases/getattr/exec and the numeric types of +external inputs are outside this finite AST-signal vocabulary. In particular, +NO_FLOAT_SIGNAL is never a semantic proof of exact arithmetic, and MIXED never +proves that floating operations are enclosed. Git mode rejects source symlinks +and gitlinks pending a separate pin-aware admission; filesystem mode rejects +missing roots and symlinks. + +Standard library only; no floating-point values are compared for certification. The exit +status is 0 when every file parsed and 1 when any file is UNPARSEABLE; signal +counts never change the exit status, because they are inventory, not verdicts. + +Usage: + a3_float_census.py PATH... directories and/or .py files + a3_float_census.py --git REPO --rev REV every .py blob in a git tree + --json FILE write the full census +""" +from __future__ import annotations + +import argparse +import ast +import json +import os +import subprocess +import sys + +# math functions that return ints (or bools) exactly for int arguments. +# fabs, copysign, sqrt, exp, log, pi, e, ... return floats and are NOT here. +EXACT_MATH = { + "comb", "factorial", "gcd", "isqrt", "lcm", "perm", "prod", + "floor", "ceil", "trunc", "isfinite", "isinf", "isnan", +} +FLOAT_MODULES = {"numpy", "scipy", "mpmath", "decimal", "cmath"} +EXACT_MODULES = {"fractions", "sympy", "flint", "gmpy2"} +FLOAT_KINDS = ("float_literal", "float_call", "true_division", "math_float", "float_module") +INTERVAL_MATH = {"nextafter", "ulp"} + + +class _Visitor(ast.NodeVisitor): + def __init__(self): + self.signals: list[tuple[int, int, str, str]] = [] + self.math_aliases = {"math": "math", "cmath": "cmath"} + self.mpmath_aliases = {"mpmath"} + self.local_math_names: dict[str, str] = {} + + def add(self, node, kind, detail): + self.signals.append((getattr(node, "lineno", 0), getattr(node, "col_offset", -1) + 1, kind, detail)) + + # -- imports + def visit_Import(self, node): + for a in node.names: + top = a.name.split(".")[0] + bound = (a.asname or a.name).split(".")[0] + if top in ("math", "cmath"): + self.math_aliases[bound] = top + if top == "mpmath": + self.mpmath_aliases.add(bound) + if a.name == "ia" or a.name.endswith(".ia"): + self.add(node, "interval_layer", f"import {a.name}") + self._module(node, a.name) + self.generic_visit(node) + + def visit_ImportFrom(self, node): + mod = node.module or "" + top = mod.split(".")[0] + self._module(node, mod) + if mod == "ia" or mod.endswith(".ia"): + self.add(node, "interval_layer", f"from {mod} import") + if top in ("math", "cmath"): + for a in node.names: + if a.name not in EXACT_MATH: + self.add(node, "math_float", f"from {mod} import {a.name}") + if a.name in INTERVAL_MATH: + self.add(node, "interval_layer", f"{top}.{a.name}") + self.local_math_names[a.asname or a.name] = top + if top == "mpmath": + for a in node.names: + if a.name == "iv": + self.add(node, "exact_module", "mpmath.iv") + self.generic_visit(node) + + def _module(self, node, name): + top = name.split(".")[0] + if name == "mpmath.iv": + self.add(node, "exact_module", "mpmath.iv") + if top in FLOAT_MODULES: + self.add(node, "float_module", top) + if top in EXACT_MODULES: + self.add(node, "exact_module", top) + + # -- expressions + def visit_Constant(self, node): + if isinstance(node.value, (float, complex)) and not isinstance(node.value, bool): + self.add(node, "float_literal", repr(node.value)) + + def visit_Call(self, node): + if isinstance(node.func, ast.Name) and node.func.id in ("float", "complex"): + self.add(node, "float_call", node.func.id) + self.generic_visit(node) + + def visit_BinOp(self, node): + if isinstance(node.op, ast.Div): + self.add(node, "true_division", "/") + self.generic_visit(node) + + def visit_AugAssign(self, node): + if isinstance(node.op, ast.Div): + self.add(node, "true_division", "/=") + self.generic_visit(node) + + def visit_Attribute(self, node): + if isinstance(node.value, ast.Name): + base = node.value.id + if base in self.math_aliases and node.attr not in EXACT_MATH: + self.add(node, "math_float", f"{self.math_aliases[base]}.{node.attr}") + if base in self.math_aliases and node.attr in INTERVAL_MATH: + self.add(node, "interval_layer", f"{self.math_aliases[base]}.{node.attr}") + if base in self.mpmath_aliases and node.attr == "iv": + self.add(node, "exact_module", "mpmath.iv") + self.generic_visit(node) + + +def census_text(text: str, path: str, blob: str | None = None) -> dict: + rec = {"path": path} + if blob: + rec["blob"] = blob + try: + tree = ast.parse(text, filename=path) + except (SyntaxError, ValueError) as exc: + rec.update({"class": "UNPARSEABLE", "error": f"{type(exc).__name__}: {exc}", "signals": [], "counts": {}}) + return rec + v = _Visitor() + v.visit(tree) + sig = sorted(v.signals) + counts: dict[str, int] = {} + for _, _, kind, _ in sig: + counts[kind] = counts.get(kind, 0) + 1 + has_float = any(counts.get(k) for k in FLOAT_KINDS) + has_exact = bool(counts.get("exact_module") or counts.get("interval_layer")) + cls = "NO_FLOAT_SIGNAL" if not has_float else ("MIXED" if has_exact else "FLOAT_SIGNAL") + rec.update({"class": cls, "counts": counts, + "signals": [{"line": l, "col": c, "kind": k, "detail": d} for l, c, k, d in sig]}) + return rec + + +def _iter_fs(paths): + def walk_error(exc): + raise exc + for p in paths: + if not os.path.exists(p): + raise OSError(f"source path does not exist: {p}") + if os.path.islink(p): + raise OSError(f"source symlink requires explicit target admission: {p}") + if os.path.isdir(p): + for root, dirs, files in os.walk(p, onerror=walk_error): + dirs[:] = sorted(d for d in dirs if d != ".git") + for d in dirs: + if os.path.islink(os.path.join(root, d)): + raise OSError(f"source directory symlink requires explicit target admission: {d}") + for fn in sorted(files): + if fn.endswith(".py"): + full = os.path.join(root, fn) + if os.path.islink(full): + raise OSError(f"source symlink requires explicit target admission: {full}") + yield os.path.relpath(full, p), full + elif p.endswith(".py"): + yield p, p + + +def _git_blobs(repo: str, rev: str): + env = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")} + env.update(GIT_CONFIG_GLOBAL=os.devnull, GIT_CONFIG_SYSTEM=os.devnull, + GIT_NO_REPLACE_OBJECTS="1", GIT_NO_LAZY_FETCH="1", + GIT_TERMINAL_PROMPT="0") + cmd = ["git", "--no-replace-objects", "-C", repo] + ls = subprocess.run(cmd + ["ls-tree", "-r", "-z", rev], + check=True, capture_output=True, env=env).stdout + entries = [] + for rec in ls.split(b"\0"): + if not rec: + continue + meta, path = rec.split(b"\t", 1) + mode, typ, sha = meta.split() + p = path.decode("utf-8", "strict") + if typ == b"commit": + raise OSError(f"gitlink requires a separately pinned scan: {p}") + if typ == b"blob" and p.endswith(".py"): + if mode not in (b"100644", b"100755"): + raise OSError(f"nonregular source blob requires explicit admission: {p}") + entries.append((p, sha.decode())) + if not entries: + return + proc = subprocess.Popen(cmd + ["cat-file", "--batch"], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) + try: + for p, sha in entries: + proc.stdin.write(sha.encode() + b"\n") + proc.stdin.flush() + header = proc.stdout.readline().split() + if len(header) != 3 or header[0] != sha.encode() or header[1] != b"blob" or not header[2].isdigit(): + raise OSError(f"invalid git blob header: {p}") + size = int(header[2]) + data = proc.stdout.read(size) + trailer = proc.stdout.read(1) + if len(data) != size or trailer != b"\n": + raise OSError(f"truncated git blob: {p}") + yield p, sha, data + proc.stdin.close() + code = proc.wait() + if code != 0: + raise OSError(f"git cat-file failed with exit {code}") + finally: + if proc.poll() is None: + proc.terminate() + if not proc.stdin.closed: + proc.stdin.close() + proc.stdout.close() + proc.stderr.close() + proc.wait() + + +def main(argv=None) -> int: + ap = argparse.ArgumentParser(description=__doc__.split("\n")[0]) + ap.add_argument("paths", nargs="*") + ap.add_argument("--git", metavar="REPO") + ap.add_argument("--rev", default="HEAD") + ap.add_argument("--json", metavar="FILE") + args = ap.parse_args(argv) + if not args.paths and not args.git: + ap.print_usage(sys.stderr) + return 2 + records = [] + try: + if args.git: + for p, sha, data in _git_blobs(args.git, args.rev): + try: + text = data.decode("utf-8") + except UnicodeDecodeError as exc: + records.append({"path": p, "blob": sha, "class": "UNPARSEABLE", + "error": f"UnicodeDecodeError: {exc}", "signals": [], "counts": {}}) + continue + records.append(census_text(text, p, sha)) + for rel, full in _iter_fs(args.paths): + try: + with open(full, encoding="utf-8") as fh: + text = fh.read() + except UnicodeDecodeError as exc: + records.append({"path": rel, "class": "UNPARSEABLE", "error": f"UnicodeDecodeError: {exc}", + "signals": [], "counts": {}}) + continue + records.append(census_text(text, rel)) + except (OSError, UnicodeDecodeError, subprocess.CalledProcessError) as exc: + print(f"a3_float_census: error: {exc}", file=sys.stderr) + return 2 + by_class: dict[str, int] = {} + for r in records: + by_class[r["class"]] = by_class.get(r["class"], 0) + 1 + summary = {"files": len(records), "by_class": dict(sorted(by_class.items()))} + if args.json: + with open(args.json, "w", encoding="utf-8") as fh: + json.dump({"summary": summary, "files": records}, fh, indent=1, ensure_ascii=False) + for r in records: + if r["class"] == "UNPARSEABLE": + print(f"{r['path']}: UNPARSEABLE {r['error']}") + print(json.dumps(summary, ensure_ascii=False)) + return 1 if by_class.get("UNPARSEABLE") else 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/cbz/layer_a_scan.py b/tools/cbz/layer_a_scan.py new file mode 100644 index 000000000..2eee3a220 --- /dev/null +++ b/tools/cbz/layer_a_scan.py @@ -0,0 +1,621 @@ +#!/usr/bin/env python3 +"""Layer A textual scanner for Lean 4 sources (CBZ-0 gate G1). + +What it certifies, exactly: + For every scanned ``.lean`` file it reports each *code* token (outside + comments, string literals and char literals) that names a Layer A hazard: + + violation tokens (gate-failing in production context) + A1 placeholders : sorry, admit, sorryAx, admitGoal, mkSorry + A2 trust holes : axiom (declaration keyword), native_decide, + ofReduceBool, ofReduceNat, trustCompiler, + skipKernelTC (kernel-check bypass option), + addDeclWithoutChecking, and the ``decide`` options + ``+native`` / ``native := true`` + review tokens (reported, never gate-failing on their own) + A3 float : Float, Float32 + A2 compiled code: unsafe, implemented_by, extern + A1 tactic stop : ``stop`` as the first token on its line + + ``sorry``/``admit``/``axiom``/``native_decide``/``Float``/``Float32``/ + ``unsafe``/``stop`` match only as a whole undotted identifier; the other + violation tokens also match as the last component of a dotted name + (``Lean.ofReduceBool``, ``debug.skipKernelTC``), including an escaped + component (``Lean.«ofReduceBool»`` and ``«sorryAx»`` name the same + constants). An escaped keyword such as ``«sorry»`` is an ordinary + identifier, not the keyword, and is not flagged. + +Fail-closed: a string, block comment, raw string, interpolated string or +``«`` name or character literal left unterminated is reported as an ``error`` +finding, which fails the run like a violation, because the rest of the +file cannot be lexed reliably. + +What it does NOT certify: + * That a file compiles, or that no placeholder arises through + metaprogramming that never spells a listed token. Gates G2-G4 + (``#print axioms`` / kernel re-check) close that gap; this scanner is a + necessary, not sufficient, condition. + * Anything about non-Lean files (Python bounds are a separate gate). + +Lexing follows Lean 4: ``--`` line comments; nested ``/- -/`` block comments +(including ``/--`` and ``/-!``); ``"..."`` strings with backslash escapes; +interpolated strings (``s!"..{code}.."``, ``m!``, ``f!``) whose ``{}`` +regions are lexed as code, including layout after the prefix; balanced brace +regions in ordinary-looking strings are conservatively scanned too (macros +may interpolate them); raw strings ``r"..."`` / ``r#"..."#``; char +literals; and ``«...»`` escaped identifiers. + +Standard library only. No floating point is used in any decision. + +Usage: + layer_a_scan.py PATH... scan files/directories + layer_a_scan.py --git REPO --rev REV scan every .lean blob in a git tree +Options: + --json FILE write all findings as JSON + --fail-on CTX comma list of contexts whose violations fail the run + (default: production). Use "all" for every context. +Git mode scans regular owned blobs only: symlinks/gitlinks are rejected +until explicitly resolved and scanned by a separate pin-aware admission. +Filesystem mode rejects symlinks/missing roots, scans all directories except +.git (including .lake); prefer Git mode for repository-source inventories. +Use --fail-on all for the federation Layer A gate: context names are reporting +labels, not authorization to hide historical/control violations. +Exit status: 0 = no failing violation, 1 = failing violation, 2 = usage/IO. +""" +from __future__ import annotations + +import argparse +import json +import os +import re +import subprocess +import sys + +VIOLATION_EXACT = { + "sorry": "A1", + "admit": "A1", + "axiom": "A2", + "native_decide": "A2", +} +VIOLATION_COMPONENT = { + "sorryAx": "A1", + "admitGoal": "A1", + "mkSorry": "A1", + "ofReduceBool": "A2", + "ofReduceNat": "A2", + "trustCompiler": "A2", + "skipKernelTC": "A2", + "addDeclWithoutChecking": "A2", +} +REVIEW_EXACT = { + "Float": "A3", + "Float32": "A3", + "unsafe": "A2", +} +REVIEW_COMPONENT = { + "implemented_by": "A2", + "extern": "A2", +} +LINE_START_REVIEW = {"stop": "A1"} + +INTERP_PREFIXES = {"s!", "m!", "f!"} +# ``decide +native`` and ``native := true`` select compiler evaluation, i.e. +# ofReduceBool. ``native`` after a ``+`` is flagged even with a space between +# (safe direction: ``x + native`` is a false positive, never a miss). +_NATIVE_TRUE = re.compile(r"\s*:=\s*true(?![\w'!?])") +_EXCLUDED_LETTERS = {"λ", "Π", "Σ"} +_CHAR_LIT = re.compile(r"'(?:\\(?:u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2}|[\\\"'rnt])|[^\\'\n])'") +# Pinned Lean4.34.1 Parser/Basic.lean:831-918. This recognizes spelling, +# never evaluates a numeral or makes a floating-point decision. +_NUMERAL = re.compile(r"(?:0[bB][01_]+|0[oO][0-7_]+|0[xX][0-9a-fA-F_]+|[0-9][0-9_]*(?:\.(?!\.)[0-9_]*)?(?:[eE][+-]?[0-9][0-9_]*)?)") + + +def _is_letter(ch: str) -> bool: + if ch in _EXCLUDED_LETTERS: + return False + if ch.isascii(): + return ch.isalpha() + o = ord(ch) + # Letter-like symbols and Greek/Coptic, as Lean's isLetterLike. + return (0x3B1 <= o <= 0x3C9 and o != 0x3BB) or (0x391 <= o <= 0x3A9 and o not in (0x3A0, 0x3A3)) \ + or 0x3CA <= o <= 0x3FB or 0x1F00 <= o <= 0x1FFE or 0x2100 <= o <= 0x214F \ + or 0x1D49C <= o <= 0x1D59F \ + or (0x00C0 <= o <= 0x00FF and o not in (0x00D7, 0x00F7)) \ + or 0x0100 <= o <= 0x017F + + +def _is_subscript(ch: str) -> bool: + o = ord(ch) + return 0x2080 <= o <= 0x2089 or 0x2090 <= o <= 0x209C or 0x1D62 <= o <= 0x1D6A or o == 0x2C7C + + +def _id_start(ch: str) -> bool: + return ch == "_" or _is_letter(ch) + + +def _id_rest(ch: str) -> bool: + return ch == "_" or ch == "'" or ch == "!" or ch == "?" or '0' <= ch <= '9' \ + or _is_letter(ch) or _is_subscript(ch) + + +def _code_follow(text: str, start: int) -> str: + """Remove layout from a native-option suffix, without a lookahead limit. + + Only the first assignment value is needed. Nested comments are layout; + an unfinished comment cannot manufacture a successful match. + """ + out = [] + i = start + while i < len(text) and len(out) < 8: + if text.startswith('--', i): + end = text.find('\n', i) + i = len(text) if end < 0 else end + elif text.startswith('/-', i): + depth = 1 + i += 2 + while i < len(text) and depth: + if text.startswith('/-', i): + depth += 1 + i += 2 + elif text.startswith('-/', i): + depth -= 1 + i += 2 + else: + i += 1 + if depth: + return '' + elif text[i].isspace(): + i += 1 + else: + out.append(text[i]) + i += 1 + return ''.join(out) + + +def _native_assignment(follow: str) -> bool: + """A native config field is unsafe unless its complete value is false. + + Eight non-layout characters cover ':=false' and its following delimiter. + Merely starting with false is insufficient (false || true is unsafe). + Other expressions are deliberately conservative findings, never evaluated. + """ + return (follow.startswith(':=') and + not (len(follow) >= 8 and follow[2:7] == 'false' and follow[7] in '},')) + + +def _brace_segments(text: str, start: int, end: int, line: int, col: int): + """Secondary conservative code-hole interpretation; primary cursor stays put. + + The same lexer reads a possible hole through nested strings/comments and + stops at its matching brace. It may extend past the first quote of the + primary ordinary-string interpretation: Lean macros can interpolate that + string and permit quoted terms inside its hole. Ambiguous ordinary brace + data can add findings, but cannot suppress primary-code findings. + """ + i = start + while i < end: + if text[i] == '\\': + i += 2 + continue + if text[i] == '{': + prefix = text[start:i + 1] + base_line = line + prefix.count('\n') + base_col = (len(prefix.rsplit('\n', 1)[-1]) + 1 if '\n' in prefix + else col + len(prefix)) + for name, ln, cl, first, plus, follow, field in lex_tokens(text[i + 1:], _until_brace=True): + yield name, base_line + ln - 1, (base_col + cl - 1 if ln == 1 else cl), first, plus, follow, field + i += 1 + + +def lex_tokens(text: str, errors: list | None = None, *, _until_brace: bool = False): + """Yield (name, line, col, line_start, plus_before, follow, field_before). + + ``name`` is the full dotted identifier text; an escaped ``«...»`` + component becomes ``\x00`` plus its text (inner dots as ``\x01``), so it + matches constant names but never a keyword. ``plus_before`` says the + identifier follows a ``+`` across layout; ``follow`` is a normalized + assignment-value prefix after it. + Unterminated constructs are appended to ``errors`` as (line, col, kind). + + Modes are kept on an explicit stack: a ``code`` frame (with a brace + depth when it is an interpolation region) or an ``istr`` frame (the body + of an interpolated string, where ``{`` opens a nested code region). + """ + i = 0 + n = len(text) + line = 1 + col = 1 + line_has_token = False + last_code_char = '' + stack: list[list] = [["code", 0 if _until_brace else None]] + if errors is None: + errors = [] + + def advance(k: int): + nonlocal i, line, col, line_has_token + for _ in range(k): + if i >= n: + return + if text[i] == "\n": + line += 1 + col = 1 + line_has_token = False + else: + col += 1 + i += 1 + + def read_ident_tail(parts: list[str]): + # dotted continuation: .ident or .«escaped» + while i < n and text[i] == "." and i + 1 < n and (_id_start(text[i + 1]) or text[i + 1] == "«"): + advance(1) + if text[i] == "«": + j = text.find("»", i + 1) + if j < 0: + errors.append((line, col, "unterminated_escaped_name")) + advance(n - i) + return + inner = text[i + 1:j] + advance(j + 1 - i) + parts.append("\x00" + inner.replace(".", "\x01")) + else: + s2 = i + while i < n and _id_rest(text[i]): + advance(1) + parts.append(text[s2:i]) + + while i < n: + frame = stack[-1] + c = text[i] + if frame[0] == "istr": + if c == "\\": + advance(2) + elif c == '"': + advance(1) + stack.pop() + elif c == "{": + advance(1) + stack.append(["code", 0]) + else: + advance(1) + continue + # ---- code mode + if c == "-" and text.startswith("--", i): + while i < n and text[i] != "\n": + advance(1) + continue + if c == "/" and text.startswith("/-", i): + start = (line, col) + depth = 0 + while i < n: + if text.startswith("/-", i): + depth += 1 + advance(2) + elif text.startswith("-/", i): + depth -= 1 + advance(2) + if depth == 0: + break + else: + advance(1) + if depth: + errors.append(start + ("unterminated_comment",)) + continue + if frame[1] is not None and c == "{": + frame[1] += 1 + advance(1) + continue + if frame[1] is not None and c == "}": + advance(1) + if frame[1] == 0: + if len(stack) == 1: + return + stack.pop() # back to the interpolated string body + else: + frame[1] -= 1 + continue + if c == '"': + if last_code_char in INTERP_PREFIXES: + start = (line, col) + advance(1) + stack.append(["istr", start[0], start[1]]) + line_has_token = True + last_code_char = '"' + continue + start = (line, col) + advance(1) + content_start = i + closed = False + while i < n: + cc = text[i] + if cc == "\\": + advance(2) + continue + advance(1) + if cc == '"': + closed = True + break + if not closed: + errors.append(start + ("unterminated_string",)) + else: + yield from _brace_segments(text, content_start, i - 1, start[0], start[1] + 1) + line_has_token = True + last_code_char = '"' + continue + if c == "'": + m = _CHAR_LIT.match(text, i) + # Apostrophes also occur in Mathlib image/tSum/preimage notation. + prime_notation = (text.startswith("''", i) or + (i > 0 and not text[i - 1].isspace() + and text[i - 1] not in '=([{,;:')) + if m is None and not prime_notation: + errors.append((line, col, 'unterminated_char')) + advance(m.end() - i if m else (2 if text.startswith("''", i) else 1)) + line_has_token = True + last_code_char = "'" + continue + if c == "«": + start_line, start_col, start_first = line, col, not line_has_token + j = text.find("»", i + 1) + if j < 0: + errors.append((line, col, "unterminated_escaped_name")) + advance(n - i) + break + inner = text[i + 1:j] + advance(j + 1 - i) + parts = ["\x00" + inner.replace(".", "\x01")] + read_ident_tail(parts) + line_has_token = True + plus = last_code_char == '+' + field = last_code_char in ('{', ',', 'with') + last_code_char = 'identifier' + yield ".".join(parts), start_line, start_col, start_first, plus, _code_follow(text, i), field + continue + if _id_start(c): + start_line, start_col, start_first = line, col, not line_has_token + s = i + while i < n and _id_rest(text[i]): + advance(1) + word = text[s:i] + if word == "r" and i < n and text[i] in '"#': + k = i + while k < n and text[k] == "#": + k += 1 + if k < n and text[k] == '"': + close = '"' + "#" * (k - i) + end = text.find(close, k + 1) + if end < 0: + errors.append((start_line, start_col, "unterminated_raw_string")) + end = n if end < 0 else end + len(close) + advance(end - i) + line_has_token = True + last_code_char = '"' + continue + if word in INTERP_PREFIXES and i < n and text[i] == '"': + advance(1) + stack.append(["istr", start_line, start_col]) + line_has_token = True + last_code_char = '"' + continue + parts = [word] + read_ident_tail(parts) + line_has_token = True + plus = last_code_char == '+' + field = last_code_char in ('{', ',', 'with') + last_code_char = word + yield ".".join(parts), start_line, start_col, start_first, plus, _code_follow(text, i), field + continue + if c.isdigit(): + # A numeral can abut a command keyword in valid Lean (0axiom). + # Never swallow alphabetic code as part of a numeric token. + match = _NUMERAL.match(text, i) + advance(match.end() - i if match else 1) + line_has_token = True + last_code_char = 'number' + continue + if not c.isspace(): + line_has_token = True + last_code_char = c + advance(1) + for frame in stack: + if frame[0] == "istr": + errors.append((frame[1], frame[2], "unterminated_interpolated_string")) + break + + +def classify_token(name: str, line_start: bool, plus_before: bool = False, follow: str = "", field_before: bool = False): + """Return (kind, layer, severity) or None.""" + if name == '\x00native': + name = 'native' + last = name.split(".")[-1] + if last.startswith("\x00"): + # escaped component: the same constant name, never a keyword + last = last[1:] + if last in VIOLATION_COMPONENT: + return last, VIOLATION_COMPONENT[last], "violation" + if last in REVIEW_COMPONENT: + return last, REVIEW_COMPONENT[last], "review" + return None + if name == "native" and (plus_before or _NATIVE_TRUE.match(follow) or (field_before and _native_assignment(follow))): + return "native", "A2", "violation" + if "." not in name: + if name in VIOLATION_EXACT: + return name, VIOLATION_EXACT[name], "violation" + if name in REVIEW_EXACT: + return name, REVIEW_EXACT[name], "review" + if line_start and name in LINE_START_REVIEW: + return name, LINE_START_REVIEW[name], "review" + if last in VIOLATION_COMPONENT: + return last, VIOLATION_COMPONENT[last], "violation" + if last in REVIEW_COMPONENT: + return last, REVIEW_COMPONENT[last], "review" + return None + + +_EVIDENCE_SEG = re.compile(r"(^|/)(raw|runs|archive|attempts)(/|$)|-evidence(/|$)") +_CONTROL_NAME = re.compile(r"(?i)(control|negative|mutation|mutant|counterproof|falsifier)") + + +def context_of(path: str) -> str: + p = path.replace("\\", "/") + if _EVIDENCE_SEG.search(p): + return "evidence_copy" + if _CONTROL_NAME.search(os.path.basename(p)): + return "control" + return "production" + + +def scan_text(text: str, path: str, blob: str | None = None) -> list[dict]: + out = [] + ctx = context_of(path) + errors: list = [] + found = [] + seen = set() + for name, ln, cl, first, plus, follow, field in lex_tokens(text, errors): + r = classify_token(name, first, plus, follow, field) + if r is not None and (ln, cl, name, r) not in seen: + seen.add((ln, cl, name, r)) + found.append((ln, cl, name.replace("\x00", "«").replace("\x01", "."), r)) + for ln, cl, kind in errors: + found.append((ln, cl, "", (kind, "A", "error"))) + for ln, cl, token, (kind, layer, sev) in sorted(found, key=lambda x: (x[0], x[1])): + f = {"path": path, "line": ln, "col": cl, "token": token, "kind": kind, + "layer": layer, "severity": sev, "context": ctx} + if blob: + f["blob"] = blob + out.append(f) + return out + + +def iter_fs(paths): + def walk_error(exc): + raise exc + for p in paths: + if not os.path.exists(p): + raise OSError(f"source path does not exist: {p}") + if os.path.islink(p): + raise OSError(f"source symlink requires explicit target admission: {p}") + if os.path.isdir(p): + for root, dirs, files in os.walk(p, onerror=walk_error): + dirs[:] = sorted(d for d in dirs if d != ".git") + for d in dirs: + if os.path.islink(os.path.join(root, d)): + raise OSError(f"source directory symlink requires explicit target admission: {d}") + for fn in sorted(files): + if fn.endswith(".lean"): + full = os.path.join(root, fn) + if os.path.islink(full): + raise OSError(f"source symlink requires explicit target admission: {full}") + yield os.path.relpath(full, p), full + elif p.endswith(".lean"): + yield p, p + + +def git_lean_blobs(repo: str, rev: str): + env = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")} + env.update(GIT_CONFIG_GLOBAL=os.devnull, GIT_CONFIG_SYSTEM=os.devnull, + GIT_NO_REPLACE_OBJECTS="1", GIT_NO_LAZY_FETCH="1", + GIT_TERMINAL_PROMPT="0") + cmd = ["git", "--no-replace-objects", "-C", repo] + ls = subprocess.run(cmd + ["ls-tree", "-r", "-z", rev], + check=True, capture_output=True, env=env).stdout + entries = [] + for rec in ls.split(b"\0"): + if not rec: + continue + meta, path = rec.split(b"\t", 1) + mode, typ, sha = meta.split() + p = path.decode("utf-8", "strict") + if typ == b"commit": + raise OSError(f"gitlink requires a separately pinned scan: {p}") + if typ == b"blob" and p.endswith(".lean"): + if mode not in (b"100644", b"100755"): + raise OSError(f"nonregular source blob requires explicit admission: {p}") + entries.append((p, sha.decode())) + if not entries: + return + proc = subprocess.Popen(cmd + ["cat-file", "--batch"], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) + try: + for p, sha in entries: + proc.stdin.write(sha.encode() + b"\n") + proc.stdin.flush() + header = proc.stdout.readline().split() + if len(header) != 3 or header[0] != sha.encode() or header[1] != b"blob" or not header[2].isdigit(): + raise OSError(f"invalid git blob header: {p}") + size = int(header[2]) + data = proc.stdout.read(size) + trailer = proc.stdout.read(1) + if len(data) != size or trailer != b"\n": + raise OSError(f"truncated git blob: {p}") + yield p, sha, data + proc.stdin.close() + code = proc.wait() + if code != 0: + raise OSError(f"git cat-file failed with exit {code}") + finally: + if proc.poll() is None: + proc.terminate() + if not proc.stdin.closed: + proc.stdin.close() + proc.stdout.close() + proc.stderr.close() + proc.wait() + + +def main(argv=None) -> int: + ap = argparse.ArgumentParser(description=__doc__.split("\n")[0]) + ap.add_argument("paths", nargs="*") + ap.add_argument("--git", metavar="REPO") + ap.add_argument("--rev", default="HEAD") + ap.add_argument("--json", metavar="FILE") + ap.add_argument("--fail-on", default="production") + args = ap.parse_args(argv) + if not args.paths and not args.git: + ap.print_usage(sys.stderr) + return 2 + findings: list[dict] = [] + files = 0 + undecodable = [] + try: + if args.git: + for p, sha, data in git_lean_blobs(args.git, args.rev): + files += 1 + try: + text = data.decode("utf-8") + except UnicodeDecodeError: + undecodable.append(p) + continue + findings += scan_text(text, p, sha) + for rel, full in iter_fs(args.paths): + files += 1 + try: + with open(full, encoding="utf-8") as fh: + text = fh.read() + except UnicodeDecodeError: + undecodable.append(rel) + continue + findings += scan_text(text, rel) + except (OSError, UnicodeDecodeError, subprocess.CalledProcessError) as exc: + print(f"layer_a_scan: error: {exc}", file=sys.stderr) + return 2 + fail_ctx = None if args.fail_on == "all" else set(args.fail_on.split(",")) + failing = [f for f in findings if f["severity"] in ("violation", "error") + and (fail_ctx is None or f["context"] in fail_ctx)] + summary = {"files": files, "findings": len(findings), + "violations": sum(f["severity"] == "violation" for f in findings), + "errors": sum(f["severity"] == "error" for f in findings), + "failing": len(failing), "undecodable": undecodable} + if args.json: + with open(args.json, "w", encoding="utf-8") as fh: + json.dump({"summary": summary, "findings": findings}, fh, indent=1, ensure_ascii=False) + for f in failing: + print(f"{f['path']}:{f['line']}:{f['col']}: {f['layer']} {f['kind']} ({f['context']})") + print(json.dumps(summary, ensure_ascii=False)) + # Undecodable files cannot be certified clean: fail closed. + if undecodable: + return 1 + return 1 if failing else 0 + + +if __name__ == "__main__": + sys.exit(main())