From 3fb58927a714d25fcd1b4906de91d96310768141 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Fri, 6 Nov 2026 02:54:58 -0600 Subject: [PATCH 1/3] cbz: consolidate auditors and bound ordinary-string hole traversal Reconstruct main#698 plus released P1-P3 review repairs on current Main. Replace recursive ordinary-string hole rescans with an absolute-offset worklist, add adverse controls and mutations, and preserve the known distinct-brace quadratic limit explicitly. --- .../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 | 129 ++++ tests/test_cbz_a3_float_census.py | 282 +++++++ tests/test_cbz_auditor_hardening.py | 353 +++++++++ tests/test_cbz_layer_a_scan.py | 293 ++++++++ tests/test_cbz_layer_a_scan_mutants.py | 224 ++++++ tools/cbz/a3_float_census.py | 307 ++++++++ tools/cbz/layer_a_scan.py | 708 ++++++++++++++++++ 56 files changed, 4039 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..268aad10e --- /dev/null +++ b/docs/cbz/CANONICAL_AUDITORS.md @@ -0,0 +1,129 @@ +# 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 (the original consolidation +was verified with 3.11.16; the non-recursive hole-scan repair was additionally +verified with 3.12.14): + +```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 83 tests, including 74 lexical source mutations and +27 A3 source mutations. Every old/replacement anchor must occur exactly once. +Each mutant is bound to a named test, and only that test is run against it. A +kill is exit status 1, `Ran 1 test`, `FAILED (failures=N)` with no errors or +skips, every `FAIL:` header naming the designated test, and every failure's +traceback passing through the designated method to an `AssertionError`. +Import/launch failures, syntax errors, unrelated failures, test errors, other +exit statuses and zero- or multi-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. Hole +starts are absolute offsets shared by one explicit generator work stack: each +start is lexed at most once, so nested candidate strings cannot recurse through +the Python call stack or multiply the same overlapping suffix exponentially. +Two subprocess regressions and two bound source mutants exercise those exact +properties. This is not a general linear-time claim: an ordinary string with +many distinct unmatched opening braces still starts one suffix scan per brace +and has a quadratic worst case. That finite performance limit does not skip a +source or manufacture a clean result; a global runtime budget, if later added, +must fail closed and receive separate adverse tests. + +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..b7b56615f --- /dev/null +++ b/tests/test_cbz_a3_float_census.py @@ -0,0 +1,282 @@ +"""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 ast +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'}) + + +# ULW#29 review parity (main#698/6545133621) +MUTANTS.extend([ + ('aliases not pre-collected', ' v.collect_aliases(tree)\n', ''), + ('parent-package ia ignored', ' elif any(a.name == "ia" for a in node.names):', ' elif False:'), + ('source decoded as utf-8 text', ' records.append(census_text(data, rel))', " records.append(census_text(data.decode('utf-8', 'replace').lstrip('\\ufeff'), rel))"), + ('git source decoded strictly', ' records.append(census_text(data, p, sha))', " records.append(census_text(data.decode('utf-8'), p, sha))"), +]) +EXPECTED_FAILURE.update({'aliases not pre-collected': 'test_census_alias_imported_after_use', 'parent-package ia ignored': 'test_census_interval_module_from_parent_package', 'source decoded as utf-8 text': 'test_census_declared_encodings', 'git source decoded strictly': 'test_census_declared_encodings'}) + +TEST_MODULES = ('tests.test_cbz_a3_float_census', 'tests.test_cbz_auditor_hardening') + + +def designated_test_ids(modules=TEST_MODULES): + """Map each test method name to its unique module.Class.method id.""" + ids = {} + for module in modules: + with open(os.path.join(WORKSPACE, *module.split(".")) + ".py", encoding="utf-8") as fh: + tree = ast.parse(fh.read()) + for cls in tree.body: + if isinstance(cls, ast.ClassDef): + for node in cls.body: + if isinstance(node, ast.FunctionDef) and node.name.startswith("test_"): + if node.name in ids: + raise ValueError("ambiguous designated test: " + node.name) + ids[node.name] = ".".join((module, cls.name, node.name)) + return ids + + +def run_suite(tool_path, test_id=None): + 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", + *([test_id] if test_id else TEST_MODULES)], + cwd=WORKSPACE, env=env, capture_output=True, text=True, timeout=600) + + +def killed(r, expected_test=None): + """A kill is exit 1 from the designated test run alone, failing only by its own assertions. + + Launch/import/syntax failures, errors, skips, zero or extra tests, foreign + failures and failures raised outside the designated method are not kills. + Nor is an AssertionError raised inside the tool under test: the innermost + traceback frame must be test code, so a crash counts the same whatever its + exception type. + """ + out = r.stdout + r.stderr + if expected_test is None or r.returncode != 1: + return False + runs = re.findall(r"^Ran [^\n]*$", out, re.M) + summary = re.findall(r"^FAILED \(failures=([1-9][0-9]*)\)$", out, re.M) + if (len(runs) != 1 or not re.fullmatch(r"Ran 1 test in [0-9]+(?:\.[0-9]+)?s", runs[0]) + or len(summary) != 1 or re.search(r"^FAILED \((?!failures=[1-9][0-9]*\)$)", out, re.M)): + return False + failures = 0 + for block in re.split(r"(?m)^={70}$", out)[1:]: + header = re.match(r"\n(FAIL|ERROR): (test_[A-Za-z0-9_]+) \(", block) + if header is None: + continue + if (header.group(1) != "FAIL" or header.group(2) != expected_test + or not re.search(r'^ File "[^"\n]+", line [0-9]+, in %s$' % re.escape(expected_test), block, re.M) + or not re.search(r"^AssertionError\b", block, re.M)): + return False + frames = re.findall(r'^ File "([^"\n]+)", line [0-9]+, in ', block, re.M) + if not frames or not re.search(r"[/\\]tests[/\\][^/\\]+\.py$", frames[-1]): + return False + failures += 1 + return failures == int(summary[0]) + + +@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 = [] + ids = designated_test_ids() + 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, ids[EXPECTED_FAILURE[name]]), 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..cdc1bb69f --- /dev/null +++ b/tests/test_cbz_auditor_hardening.py @@ -0,0 +1,353 @@ +"""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_plain_macro_holes_do_not_recurse_on_nested_string_candidates(self): + script = ( + "import importlib.util,sys\n" + f"p={str(SCAN)!r}\n" + "s=importlib.util.spec_from_file_location('bounded_scanner',p)\n" + "m=importlib.util.module_from_spec(s);s.loader.exec_module(m)\n" + "sys.setrecursionlimit(80)\n" + "m.scan_text(('\\\"{ ' * 60) + '\\\"','M.lean')\n" + ) + p = subprocess.run([sys.executable, '-B', '-S', '-c', script], + capture_output=True, text=True, timeout=5) + last_error = p.stderr.rstrip().rsplit('\n', 1)[-1] if p.stderr else '' + self.assertEqual(p.returncode, 0, + f"scanner subprocess exited {p.returncode}: {last_error}") + + def test_plain_macro_holes_do_not_repeat_overlapping_suffix_work(self): + script = ( + "import importlib.util\n" + f"p={str(SCAN)!r}\n" + "s=importlib.util.spec_from_file_location('bounded_scanner',p)\n" + "m=importlib.util.module_from_spec(s);s.loader.exec_module(m)\n" + "m.scan_text(('\\\"{ ' * 30) + '\\\"','M.lean')\n" + ) + try: + p = subprocess.run([sys.executable, '-B', '-S', '-c', script], + capture_output=True, text=True, timeout=2) + except subprocess.TimeoutExpired as exc: + self.fail(f"overlapping ordinary-string hole scans exceeded 2 seconds: {exc}") + self.assertEqual(p.returncode, 0, p.stdout + p.stderr) + + 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_native_field_inside_code_holes_keeps_field_context(self): + for src in ['#check s!"{let _ : 1 = 1 := by decide (config := { native := (true) }); 0}"', + 'def e := m!"{f { a := 1 } { native := (true) }}"', + 'def e := throwError "bad {decide (config := { native := (true) })}"']: + with self.subTest(src=src): self.assertEqual(kinds(src), ['native']) + self.assertEqual(kinds('#check s!"{decide (config := { native := false })}"'), []) + def test_native_false_requires_the_false_token(self): + for expr in ['f alse', 'f /- c -/ alse', 'fa\n lse', 'false x']: + src = 'theorem bad : 1 = 1 := by decide (config := { native := ' + expr + ' })' + with self.subTest(src=src): self.assertEqual(kinds(src), ['native']) + self.assertEqual(kinds('by decide (config := { native := /- c -/ false })'), []) + 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')) + +def fail_block(test): + return ('='*70+'\nFAIL: '+test+' (tests.C.'+test+')\n'+'-'*70+'\nTraceback (most recent call last):\n' + ' File "/w/tests/t.py", line 9, in '+test+'\n self.assertEqual(1, 2)\nAssertionError: 1 != 2\n\n') + +@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=fail_block('test_expected')+'-'*70+'\nRan 1 test in 0.001s\n\nFAILED (failures=1)\n' + self.assertTrue(mod.killed(subprocess.CompletedProcess([],1,stdout='',stderr=good),'test_expected')) + a8=[(2,good), # wrong nonzero exit + (1,fail_block('test_expected')+fail_block('test_other')+'-'*70+'\nRan 1 test in 0.001s\n\nFAILED (failures=2)\n'), + (1,good.replace('Ran 1 test','Ran 3 tests')), # the designated test must run alone + (1,good.replace(', in test_expected',', in setUp')), # raised outside the designated method + (1,good.replace('FAILED (failures=1)','FAILED (failures=2)')), + # an AssertionError raised inside the tool under test is a crash, not the test's assertion + (1,good.replace(' self.assertEqual(1, 2)\n',' self.assertEqual(1, 2)\n' + ' File "/tmp/m/mutant_00.py", line 5, in classify_token\n raise AssertionError\n'))] + for code,out in a8: + with self.subTest(module=mod.__name__,code=code,out=out): + self.assertFalse(mod.killed(subprocess.CompletedProcess([],code,stdout='',stderr=out),'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') + +C = load(CENSUS, 'hardening_census') + + +def census_kinds(src): + r = C.census_text(src, 'x.py') + return r['class'], [k['kind'] for k in r['signals']] + + +def git_init(d): + subprocess.run(['git','init','-q',str(d)],check=True,capture_output=True, + env=dict(os.environ,GIT_CONFIG_GLOBAL=os.devnull,GIT_CONFIG_SYSTEM=os.devnull)) + + +class ReviewParityULW29(unittest.TestCase): + """Findings first raised by automated review on ULW#29, the consolidated source.""" + def test_fail_on_rejects_unknown_contexts(self): + with tempfile.TemporaryDirectory() as d: + (Path(d)/'A.lean').write_text('example : False := by sorry\n') + for bad in ['prodution', '', 'production,', ',control', 'production,nope']: + with self.subTest(fail_on=bad): + p = cli(SCAN, d, '--fail-on', bad) + self.assertEqual(p.returncode, 2, p.stdout+p.stderr) + self.assertEqual(cli(SCAN, d, '--fail-on', 'production,control').returncode, 1) + self.assertEqual(cli(SCAN, d, '--fail-on', 'evidence_copy').returncode, 0) + + def test_context_does_not_depend_on_path_spelling(self): + with tempfile.TemporaryDirectory() as d: + repo = Path(d)/'checkout'; (repo/'raw').mkdir(parents=True); git_init(repo) + (repo/'raw'/'A.lean').write_text('theorem t : True := sorry\n') + for arg in [repo, repo/'raw', repo/'raw'/'A.lean']: + with self.subTest(arg=str(arg)): + out = Path(d)/'o.json' + p = cli(SCAN, arg, '--json', out) + self.assertEqual(p.returncode, 0, p.stdout+p.stderr) + findings = json.loads(out.read_text())['findings'] + self.assertEqual([(f['context'], f['context_path']) for f in findings], + [('evidence_copy', 'raw/A.lean')]) + + def test_unrelated_ancestor_does_not_change_context(self): + with tempfile.TemporaryDirectory() as d: + proj = Path(d)/'archive'/'project'; proj.mkdir(parents=True) + (proj/'P.lean').write_text('theorem t : True := sorry\n') + for arg in [proj/'P.lean', proj]: + with self.subTest(arg=str(arg)): + p = cli(SCAN, arg) + self.assertEqual(p.returncode, 1, p.stdout+p.stderr) + self.assertIn('P.lean:1:21: A1 sorry (production)', p.stdout) + + def test_explicit_context_root(self): + with tempfile.TemporaryDirectory() as d, tempfile.TemporaryDirectory() as other: + proj = Path(d)/'archive'/'project'; proj.mkdir(parents=True) + src = proj/'P.lean'; src.write_text('theorem t : True := sorry\n') + out = Path(d)/'o.json' + p = cli(SCAN, src, '--context-root', d, '--json', out) + self.assertEqual(p.returncode, 0, p.stdout+p.stderr) + f = json.loads(out.read_text())['findings'][0] + self.assertEqual((f['context'], f['context_path']), ('evidence_copy', 'archive/project/P.lean')) + self.assertEqual(cli(SCAN, src, '--context-root', other).returncode, 2) + + def test_census_alias_imported_after_use(self): + self.assertEqual(census_kinds('def f(n):\n return m.sqrt(n)\nimport math as m\n'), + ('FLOAT_SIGNAL', ['math_float'])) + cls, sig = census_kinds('def f():\n return mp.iv\nimport mpmath as mp\n') + self.assertIn('exact_module', sig) + + def test_census_interval_module_from_parent_package(self): + for src in ['from . import ia\nx = ia.up(0.5)\n', 'from pkg import ia\nx = ia.up(0.5)\n', + 'from pkg import ia as I\nx = I.up(0.5)\n', 'from .. import other, ia\nx = 0.5\n']: + with self.subTest(src=src): + cls, sig = census_kinds(src) + self.assertEqual(cls, 'MIXED') + self.assertIn('interval_layer', sig) + self.assertEqual(census_kinds('from pkg import iax\nx = 0.5\n')[0], 'FLOAT_SIGNAL') + + def test_census_declared_encodings(self): + latin = b"# -*- coding: latin-1 -*-\n\xe9t\xe9 = 1\nx = 0.5\n" + self.assertEqual(C.census_text(b'\xef\xbb\xbfx = 0.5\n', 'bom.py')['class'], 'FLOAT_SIGNAL') + self.assertEqual(C.census_text(latin, 'latin.py')['class'], 'FLOAT_SIGNAL') + self.assertEqual(C.census_text(b"x = '\xff\xfe'\n", 'bad.py')['class'], 'UNPARSEABLE') + with tempfile.TemporaryDirectory() as d: + root = Path(d) + (root/'a.py').write_bytes(b'\xef\xbb\xbfx = 0.5\n'); (root/'b.py').write_bytes(latin) + out = root/'o.json' + p = cli(CENSUS, root, '--json', out) + self.assertEqual(p.returncode, 0, p.stdout+p.stderr) + self.assertEqual(sorted((f['path'], f['class']) for f in json.loads(out.read_text())['files']), + [('a.py', 'FLOAT_SIGNAL'), ('b.py', 'FLOAT_SIGNAL')]) + subprocess.run(['git','-c','user.name=t','-c','user.email=t@x','-c','commit.gpgsign=false','init','-q'],cwd=d,check=True,capture_output=True) + subprocess.run(['git','-c','user.name=t','-c','user.email=t@x','-c','commit.gpgsign=false','add','a.py','b.py'],cwd=d,check=True,capture_output=True) + subprocess.run(['git','-c','user.name=t','-c','user.email=t@x','-c','commit.gpgsign=false','commit','-qm','f'],cwd=d,check=True,capture_output=True) + p = cli(CENSUS, '--git', root, '--json', out) + self.assertEqual(p.returncode, 0, p.stdout+p.stderr) + self.assertEqual(sorted((f['path'], f['class']) for f in json.loads(out.read_text())['files']), + [('a.py', 'FLOAT_SIGNAL'), ('b.py', 'FLOAT_SIGNAL')]) + +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..faab4ff7e --- /dev/null +++ b/tests/test_cbz_layer_a_scan_mutants.py @@ -0,0 +1,224 @@ +"""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 ast +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 _HOLE_START, hole_start, hole_line, hole_col', ' continue'), ('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', 'work.append(_lex_tokens(text, [], _until_brace=True,', 'work.append(_lex_tokens(text[:start], [], _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')")]) + +MUTANTS.extend([('code-hole brace field context dropped', ' advance(1)\n last_code_char = "{"\n', ' advance(1)\n'), ('native false token boundary dropped', " if gap and out and _id_rest(out[-1]) and _id_rest(text[i]):\n out.append(' ')\n", '')]) + +MUTANTS.extend([ + ('ordinary hole start revisited', ' if start not in started:', ' if True:'), + ('ordinary hole recursion restored', + ' yield _HOLE_START, hole_start, hole_line, hole_col', + ' for token in lex_tokens(text[hole_start:], _until_brace=True):\n' + ' yield token'), +]) + +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'}) + +EXPECTED_FAILURE.update({'code-hole brace field context dropped': 'test_native_field_inside_code_holes_keeps_field_context', 'native false token boundary dropped': 'test_native_false_requires_the_false_token'}) + +EXPECTED_FAILURE.update({'ordinary hole start revisited': 'test_plain_macro_holes_do_not_repeat_overlapping_suffix_work', 'ordinary hole recursion restored': 'test_plain_macro_holes_do_not_recurse_on_nested_string_candidates'}) + + +# ULW#29 review parity (main#698/6545133621) +MUTANTS.extend([ + ('fail-on not validated', ' if not fail_ctx <= set(CONTEXTS):', ' if False:'), + ('context from spelled path', ' findings += scan_text(text, rel, context_path=cpath)', ' findings += scan_text(text, rel)'), + ('git work tree ignored', ' base = _git_top(os.path.dirname(full)) or os.path.abspath(scan_base)', ' base = os.path.abspath(scan_base)'), + ('context root outside accepted', ' raise OSError(f"{full} is outside --context-root {context_root}")', ' pass'), +]) +EXPECTED_FAILURE.update({'fail-on not validated': 'test_fail_on_rejects_unknown_contexts', 'context from spelled path': 'test_context_does_not_depend_on_path_spelling', 'git work tree ignored': 'test_context_does_not_depend_on_path_spelling', 'context root outside accepted': 'test_explicit_context_root'}) + +TEST_MODULES = ('tests.test_cbz_layer_a_scan', 'tests.test_cbz_auditor_hardening') + + +def designated_test_ids(modules=TEST_MODULES): + """Map each test method name to its unique module.Class.method id.""" + ids = {} + for module in modules: + with open(os.path.join(WORKSPACE, *module.split(".")) + ".py", encoding="utf-8") as fh: + tree = ast.parse(fh.read()) + for cls in tree.body: + if isinstance(cls, ast.ClassDef): + for node in cls.body: + if isinstance(node, ast.FunctionDef) and node.name.startswith("test_"): + if node.name in ids: + raise ValueError("ambiguous designated test: " + node.name) + ids[node.name] = ".".join((module, cls.name, node.name)) + return ids + + +def run_suite(tool_path, test_id=None): + env = dict(os.environ, CBZ_LAYER_A_SCAN=tool_path, PYTHONDONTWRITEBYTECODE="1") + return subprocess.run([sys.executable, *(["-O"] if sys.flags.optimize else []), "-B", "-S", "-m", "unittest", "-v", + *([test_id] if test_id else TEST_MODULES)], + cwd=WORKSPACE, env=env, capture_output=True, text=True, timeout=600) + + +def killed(r, expected_test=None): + """A kill is exit 1 from the designated test run alone, failing only by its own assertions. + + Launch/import/syntax failures, errors, skips, zero or extra tests, foreign + failures and failures raised outside the designated method are not kills. + Nor is an AssertionError raised inside the tool under test: the innermost + traceback frame must be test code, so a crash counts the same whatever its + exception type. + """ + out = r.stdout + r.stderr + if expected_test is None or r.returncode != 1: + return False + runs = re.findall(r"^Ran [^\n]*$", out, re.M) + summary = re.findall(r"^FAILED \(failures=([1-9][0-9]*)\)$", out, re.M) + if (len(runs) != 1 or not re.fullmatch(r"Ran 1 test in [0-9]+(?:\.[0-9]+)?s", runs[0]) + or len(summary) != 1 or re.search(r"^FAILED \((?!failures=[1-9][0-9]*\)$)", out, re.M)): + return False + failures = 0 + for block in re.split(r"(?m)^={70}$", out)[1:]: + header = re.match(r"\n(FAIL|ERROR): (test_[A-Za-z0-9_]+) \(", block) + if header is None: + continue + if (header.group(1) != "FAIL" or header.group(2) != expected_test + or not re.search(r'^ File "[^"\n]+", line [0-9]+, in %s$' % re.escape(expected_test), block, re.M) + or not re.search(r"^AssertionError\b", block, re.M)): + return False + frames = re.findall(r'^ File "([^"\n]+)", line [0-9]+, in ', block, re.M) + if not frames or not re.search(r"[/\\]tests[/\\][^/\\]+\.py$", frames[-1]): + return False + failures += 1 + return failures == int(summary[0]) + + +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 = [] + ids = designated_test_ids() + 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, ids[EXPECTED_FAILURE[name]]) + 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..9b8cbc2a5 --- /dev/null +++ b/tools/cbz/a3_float_census.py @@ -0,0 +1,307 @@ +#!/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. Module aliases (``import math as m``) are collected +from the whole file before classification, so code that precedes the import +still counts; ``from pkg import ia`` is an interval layer; sources are parsed +from bytes, honouring a UTF-8 BOM and PEP 263 encoding declarations. + +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 collect_aliases(self, tree): + # first pass: module aliases are visible to code that precedes the import + for node in ast.walk(tree): + if isinstance(node, ast.Import): + 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) + + 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") + elif any(a.name == "ia" for a in node.names): + self.add(node, "interval_layer", f"from {'.' * node.level}{mod} import ia") + 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 | bytes, path: str, blob: str | None = None) -> dict: + """Census one source; bytes are decoded as Python would (BOM, PEP 263 cookie).""" + rec = {"path": path} + if blob: + rec["blob"] = blob + try: + tree = ast.parse(text, filename=path) + except (SyntaxError, ValueError, LookupError) as exc: + rec.update({"class": "UNPARSEABLE", "error": f"{type(exc).__name__}: {exc}", "signals": [], "counts": {}}) + return rec + v = _Visitor() + v.collect_aliases(tree) + 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): + records.append(census_text(data, p, sha)) + for rel, full in _iter_fs(args.paths): + with open(full, "rb") as fh: + data = fh.read() + records.append(census_text(data, 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..0d53463de --- /dev/null +++ b/tools/cbz/layer_a_scan.py @@ -0,0 +1,708 @@ +#!/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); each entry must be one of + production, evidence_copy, control, or the single word + "all". An unknown or empty entry is a usage error (exit 2). + --context-root DIR classify filesystem paths relative to DIR +Context is decided from a repository-relative path, never from how a path +was spelled: a filesystem file is classified relative to its enclosing git +work tree, else relative to the scan argument (a file's parent directory for +a file argument), unless --context-root is given. Findings record it as +context_path. +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. Layout that + separates two identifier characters stays as one space, so ``f alse`` + never reads as ``false``. + """ + out = [] + i = start + gap = False + 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 + gap = True + 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 '' + gap = True + elif text[i].isspace(): + i += 1 + gap = True + else: + if gap and out and _id_rest(out[-1]) and _id_rest(text[i]): + out.append(' ') + gap = False + 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): + """Yield absolute starts for secondary conservative code-hole scans. + + The caller's explicit work stack runs the same lexer from each possible + hole through nested strings/comments and stops at its matching brace. A + hole 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)) + yield i + 1, base_line, base_col + i += 1 + + +_HOLE_START = object() + + +def _lex_tokens(text: str, errors: list, *, _until_brace: bool = False, + _start: int = 0, _line: int = 1, _col: int = 1): + """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 = _start + n = len(text) + line = _line + col = _col + line_has_token = False + last_code_char = '' + stack: list[list] = [["code", 0 if _until_brace else None]] + 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) + last_code_char = "{" + 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: + for hole_start, hole_line, hole_col in _brace_segments( + text, content_start, i - 1, start[0], start[1] + 1): + yield _HOLE_START, hole_start, hole_line, hole_col + 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 lex_tokens(text: str, errors: list | None = None, *, _until_brace: bool = False): + """Yield lexical tokens while scanning each ordinary-string hole once. + + Secondary ordinary-string interpretations share absolute source offsets. + An explicit generator stack preserves depth-first behavior without Python + recursion, while ``started`` prevents overlapping interpretations from + launching the same suffix more than once. Errors from speculative hole + interpretations remain isolated; only the primary interpretation can add + fail-closed lexer errors, matching the historical contract. + """ + if errors is None: + errors = [] + started = {0} + work = [_lex_tokens(text, errors, _until_brace=_until_brace)] + while work: + try: + item = next(work[-1]) + except StopIteration: + work.pop() + continue + if item[0] is _HOLE_START: + _, start, line, col = item + if start not in started: + started.add(start) + work.append(_lex_tokens(text, [], _until_brace=True, + _start=start, _line=line, _col=col)) + continue + yield item + + +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)") + + +CONTEXTS = ("production", "evidence_copy", "control") + + +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, context_path: str | None = None) -> list[dict]: + out = [] + cpath = context_path if context_path is not None else path + ctx = context_of(cpath) + 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, "context_path": cpath} + if blob: + f["blob"] = blob + out.append(f) + return out + + +def _git_top(directory: str): + """The enclosing git work tree of an absolute directory, or None.""" + d = directory + while True: + if os.path.exists(os.path.join(d, ".git")): + return d + parent = os.path.dirname(d) + if parent == d: + return None + d = parent + + +def _context_path(full: str, scan_base: str, context_root: str | None) -> str: + full = os.path.abspath(full) + if context_root is not None: + rel = os.path.relpath(full, os.path.abspath(context_root)) + if rel == ".." or rel.startswith(".." + os.sep): + raise OSError(f"{full} is outside --context-root {context_root}") + return rel.replace(os.sep, "/") + base = _git_top(os.path.dirname(full)) or os.path.abspath(scan_base) + return os.path.relpath(full, base).replace(os.sep, "/") + + +def iter_fs(paths, context_root: str | None = None): + """Yield (display_path, full_path, context_path) for every .lean input file.""" + 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, _context_path(full, p, context_root) + elif p.endswith(".lean"): + yield p, p, _context_path(p, os.path.dirname(os.path.abspath(p)), context_root) + + +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") + ap.add_argument("--context-root", metavar="DIR") + args = ap.parse_args(argv) + if not args.paths and not args.git: + ap.print_usage(sys.stderr) + return 2 + if args.fail_on == "all": + fail_ctx = None + else: + fail_ctx = set(args.fail_on.split(",")) + if not fail_ctx <= set(CONTEXTS): + print(f"layer_a_scan: error: --fail-on must name contexts from {', '.join(CONTEXTS)} " + f"or be 'all', got {args.fail_on!r}", file=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, cpath in iter_fs(args.paths, args.context_root): + 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, context_path=cpath) + except (OSError, UnicodeDecodeError, subprocess.CalledProcessError) as exc: + print(f"layer_a_scan: error: {exc}", file=sys.stderr) + return 2 + 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()) From 4b5beab79e0a0dfbf1f5da4f71f74e9eaa5bb052 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Fri, 6 Nov 2026 03:03:21 -0600 Subject: [PATCH 2/3] docs(cbz): bind current auditor repair receipt --- cbz/evidence/auditor-consolidation/README.md | 9 +++- .../auditor-consolidation/REGISTRY.json | 10 ++-- .../SHA256SUMS_WORKLIST_20261106 | 11 +++++ .../WORKLIST_REPAIR_20261106.json | 48 +++++++++++++++++++ 4 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 cbz/evidence/auditor-consolidation/SHA256SUMS_WORKLIST_20261106 create mode 100644 cbz/evidence/auditor-consolidation/WORKLIST_REPAIR_20261106.json diff --git a/cbz/evidence/auditor-consolidation/README.md b/cbz/evidence/auditor-consolidation/README.md index e36638c13..c73819900 100644 --- a/cbz/evidence/auditor-consolidation/README.md +++ b/cbz/evidence/auditor-consolidation/README.md @@ -2,14 +2,19 @@ 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. +`VERIFICATION.json`, `SHA256SUMS` and the v4 logs bind the historical original +consolidation source and its observed 72-test runs; they are deliberately not +rebound to later repairs. `WORKLIST_REPAIR_20261106.json` binds the current +candidate tree, 83-test runs, 101 source mutants and exact remaining quadratic +boundary. 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. +current-review-replay.json binds a further replay to its recorded historical +scanner bytes, not to every later candidate head. Native-expression raw outputs show four valid Lean theorem proofs using fresh compiler-trust axioms, all rejected by the repaired source scanner. diff --git a/cbz/evidence/auditor-consolidation/REGISTRY.json b/cbz/evidence/auditor-consolidation/REGISTRY.json index b206ab0f0..f9252dab9 100644 --- a/cbz/evidence/auditor-consolidation/REGISTRY.json +++ b/cbz/evidence/auditor-consolidation/REGISTRY.json @@ -4,7 +4,7 @@ "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", + "verification": "current candidate: two83-test normal/optimized suites;74lexical source mutants all killed via named assertion failures; 1025 old/new parity cases; historical pinnedLean counterexamples retained without rebinding", "owner": "none — self-contained", "cbz_criteria": [ 4, @@ -17,14 +17,15 @@ ], "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." + "Lexical results do not see arbitrary macros/elaboration/imports; G2-G4 remain authoritative.", + "Distinct unmatched ordinary-string opening braces retain a quadratic worst case; no timeout or silent skip is used." ] }, { "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", + "verification": "same83-test normal/optimized suites;27A3 source mutants all killed; syntax/import/launch errors not kills", "owner": "none — self-contained", "cbz_criteria": [ 4, @@ -42,5 +43,6 @@ ], "canonical_registration_owner": "Root per B-003; proposed addenda only", "source_doc": "docs/cbz/CANONICAL_AUDITORS.md", - "verification": "cbz/evidence/auditor-consolidation/VERIFICATION.json" + "verification": "cbz/evidence/auditor-consolidation/WORKLIST_REPAIR_20261106.json", + "historical_verification": "cbz/evidence/auditor-consolidation/VERIFICATION.json" } diff --git a/cbz/evidence/auditor-consolidation/SHA256SUMS_WORKLIST_20261106 b/cbz/evidence/auditor-consolidation/SHA256SUMS_WORKLIST_20261106 new file mode 100644 index 000000000..f7f390125 --- /dev/null +++ b/cbz/evidence/auditor-consolidation/SHA256SUMS_WORKLIST_20261106 @@ -0,0 +1,11 @@ +d798703413a5d90bbd962ea09b2ced765d203010a430f41c5e4a1d1f78816f97 README.md +f19fbc63df39e1ab90ee07bfdd7e7e7f3f0475f0d77cc2a7dd31bef7b1af0597 REGISTRY.json +e0aa01017eb43c98aa70a190f0137454308a566409ec886693b8e1622362e580 WORKLIST_REPAIR_20261106.json +13ea6c994243ad2cd99e22d68915c8f47ab0f8c3ab12a885d680efb5fc14d153 ../../../docs/cbz/CANONICAL_AUDITORS.md +bf797f33d5df7a8e695f62e6a2d70dca05ec99956ac5c33aa0347164eac48410 ../../../tools/cbz/layer_a_scan.py +9faf7275053254e75372cd06d57de290b41124e86162c1c23eb5f4e46b6b2b80 ../../../tools/cbz/a3_float_census.py +3f6f666e0a8cc9d4415d8e87a3cbc4fa879fb34becf3cdf1602137a266d5a0ed ../../../tests/test_cbz_layer_a_scan.py +7df98bb1ada762777a6e3597e37514977d5088c932d1ef67d5f8a1d850970dec ../../../tests/test_cbz_layer_a_scan_mutants.py +458a2c1d1b56034acdb24b5444eb024b0c0ff425c018aa9d9353e25762be88c4 ../../../tests/test_cbz_a3_float_census.py +503a842afbcc466cabc3d1a01236bca7ff0ff2c8f60da0324faeac562d329877 ../../../tests/test_cbz_auditor_hardening.py + diff --git a/cbz/evidence/auditor-consolidation/WORKLIST_REPAIR_20261106.json b/cbz/evidence/auditor-consolidation/WORKLIST_REPAIR_20261106.json new file mode 100644 index 000000000..838bc51fa --- /dev/null +++ b/cbz/evidence/auditor-consolidation/WORKLIST_REPAIR_20261106.json @@ -0,0 +1,48 @@ +{ + "observed_utc": "2026-11-06T08:57:30Z", + "scope": "finite lexical source and AST-signal auditors only; no kernel, semantic, scientific or global CBZ qualification", + "python": "CPython 3.12.14", + "base_commit": "c933b81f59929af85a7f2de5123df1ccfadd7f80", + "candidate_commit": "3fb58927a714d25fcd1b4906de91d96310768141", + "candidate_tree_before_this_receipt": "cd7afcfafa9a02f1e19b27babeedff8b89ed370c", + "sources": { + "tools/cbz/layer_a_scan.py": "bf797f33d5df7a8e695f62e6a2d70dca05ec99956ac5c33aa0347164eac48410", + "tools/cbz/a3_float_census.py": "9faf7275053254e75372cd06d57de290b41124e86162c1c23eb5f4e46b6b2b80", + "tests/test_cbz_layer_a_scan.py": "3f6f666e0a8cc9d4415d8e87a3cbc4fa879fb34becf3cdf1602137a266d5a0ed", + "tests/test_cbz_layer_a_scan_mutants.py": "7df98bb1ada762777a6e3597e37514977d5088c932d1ef67d5f8a1d850970dec", + "tests/test_cbz_a3_float_census.py": "458a2c1d1b56034acdb24b5444eb024b0c0ff425c018aa9d9353e25762be88c4", + "tests/test_cbz_auditor_hardening.py": "503a842afbcc466cabc3d1a01236bca7ff0ff2c8f60da0324faeac562d329877" + }, + "normal": {"tests": 83, "exit": 0, "duration_seconds_decimal": "28.062"}, + "optimized": {"tests": 83, "exit": 0, "duration_seconds_decimal": "111.764"}, + "source_mutations": { + "lexical": 74, + "a3": 27, + "threshold_percent": 100, + "killed": 101, + "survivors": 0, + "stale_anchors": 0, + "kill_requires": "designated named test-body assertion failure; errors, import/launch/syntax failures, tool-origin traceback frames and unrelated failures cannot kill" + }, + "semantic_parity": { + "total": 1025, + "main_lean_files": 18, + "targeted_nested_hole_cases": 7, + "deterministic_fuzz_cases": 1000, + "mismatches": 0 + }, + "performance_seconds": { + "nested_candidate_30": "0.000786", + "json_like_nested_24": "0.000858", + "distinct_unmatched_1600": "0.391233", + "distinct_unmatched_3200": "1.685002" + }, + "remaining_boundaries": [ + "Distinct unmatched ordinary-string opening braces still start distinct suffix scans; quadratic worst case remains.", + "No runtime budget or skip is present. A future budget must fail closed and receive separate adverse tests.", + "Lexical results do not see arbitrary macros, elaboration or imports; G2-G4 remain authoritative.", + "A3 census does not certify mathematical bounds or exactness.", + "No final federation G0-G11 or CBZ-0 result is claimed." + ] +} + From cdf07c920b91ccdfec313949f9755ead21989f81 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Fri, 6 Nov 2026 03:11:14 -0600 Subject: [PATCH 3/3] docs(cbz): state full quadratic hole boundary --- cbz/evidence/auditor-consolidation/REGISTRY.json | 2 +- .../SHA256SUMS_WORKLIST_20261106 | 6 +++--- .../WORKLIST_REPAIR_20261106.json | 2 +- docs/cbz/CANONICAL_AUDITORS.md | 11 ++++++----- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cbz/evidence/auditor-consolidation/REGISTRY.json b/cbz/evidence/auditor-consolidation/REGISTRY.json index f9252dab9..a576fd8e9 100644 --- a/cbz/evidence/auditor-consolidation/REGISTRY.json +++ b/cbz/evidence/auditor-consolidation/REGISTRY.json @@ -18,7 +18,7 @@ "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.", - "Distinct unmatched ordinary-string opening braces retain a quadratic worst case; no timeout or silent skip is used." + "Each distinct ordinary-string hole start is lexed once to its own end, so many unmatched openings and deeply nested matched holes retain a quadratic worst case; no timeout or silent skip is used." ] }, { diff --git a/cbz/evidence/auditor-consolidation/SHA256SUMS_WORKLIST_20261106 b/cbz/evidence/auditor-consolidation/SHA256SUMS_WORKLIST_20261106 index f7f390125..d4711b2dc 100644 --- a/cbz/evidence/auditor-consolidation/SHA256SUMS_WORKLIST_20261106 +++ b/cbz/evidence/auditor-consolidation/SHA256SUMS_WORKLIST_20261106 @@ -1,7 +1,7 @@ d798703413a5d90bbd962ea09b2ced765d203010a430f41c5e4a1d1f78816f97 README.md -f19fbc63df39e1ab90ee07bfdd7e7e7f3f0475f0d77cc2a7dd31bef7b1af0597 REGISTRY.json -e0aa01017eb43c98aa70a190f0137454308a566409ec886693b8e1622362e580 WORKLIST_REPAIR_20261106.json -13ea6c994243ad2cd99e22d68915c8f47ab0f8c3ab12a885d680efb5fc14d153 ../../../docs/cbz/CANONICAL_AUDITORS.md +fa884ddc6b0bd83d21ca637c208d3c61f64adb39414cc86316442521609059c3 REGISTRY.json +fd6b7837fe2a4a2e481d9c575292ac27971d504d5c507d477cb0e4ecc2a0a503 WORKLIST_REPAIR_20261106.json +22ac2d0915625dae88fb769fb1344876c5504e42471f8ad7a92a27acf3d33fa3 ../../../docs/cbz/CANONICAL_AUDITORS.md bf797f33d5df7a8e695f62e6a2d70dca05ec99956ac5c33aa0347164eac48410 ../../../tools/cbz/layer_a_scan.py 9faf7275053254e75372cd06d57de290b41124e86162c1c23eb5f4e46b6b2b80 ../../../tools/cbz/a3_float_census.py 3f6f666e0a8cc9d4415d8e87a3cbc4fa879fb34becf3cdf1602137a266d5a0ed ../../../tests/test_cbz_layer_a_scan.py diff --git a/cbz/evidence/auditor-consolidation/WORKLIST_REPAIR_20261106.json b/cbz/evidence/auditor-consolidation/WORKLIST_REPAIR_20261106.json index 838bc51fa..da212b3c0 100644 --- a/cbz/evidence/auditor-consolidation/WORKLIST_REPAIR_20261106.json +++ b/cbz/evidence/auditor-consolidation/WORKLIST_REPAIR_20261106.json @@ -38,7 +38,7 @@ "distinct_unmatched_3200": "1.685002" }, "remaining_boundaries": [ - "Distinct unmatched ordinary-string opening braces still start distinct suffix scans; quadratic worst case remains.", + "Each distinct ordinary-string hole start is lexed once to its own end, so total work is the sum of hole lengths; many unmatched openings and deeply nested matched holes both retain a quadratic worst case.", "No runtime budget or skip is present. A future budget must fail closed and receive separate adverse tests.", "Lexical results do not see arbitrary macros, elaboration or imports; G2-G4 remain authoritative.", "A3 census does not certify mathematical bounds or exactness.", diff --git a/docs/cbz/CANONICAL_AUDITORS.md b/docs/cbz/CANONICAL_AUDITORS.md index 268aad10e..7cd14b92d 100644 --- a/docs/cbz/CANONICAL_AUDITORS.md +++ b/docs/cbz/CANONICAL_AUDITORS.md @@ -115,11 +115,12 @@ starts are absolute offsets shared by one explicit generator work stack: each start is lexed at most once, so nested candidate strings cannot recurse through the Python call stack or multiply the same overlapping suffix exponentially. Two subprocess regressions and two bound source mutants exercise those exact -properties. This is not a general linear-time claim: an ordinary string with -many distinct unmatched opening braces still starts one suffix scan per brace -and has a quadratic worst case. That finite performance limit does not skip a -source or manufacture a clean result; a global runtime budget, if later added, -must fail closed and receive separate adverse tests. +properties. This is not a general linear-time claim: each distinct ordinary- +string hole start is lexed once to its own end, so total work is the sum of +hole lengths. Many unmatched opening braces and deeply nested matched holes +therefore both retain a quadratic worst case. That finite performance limit +does not skip a source or manufacture a clean result; a global runtime budget, +if later added, must fail closed and receive separate adverse tests. Native configuration fields are fail-closed for arbitrary expressions: only complete literal `false` followed by a field delimiter is exempt. Parenthesized