diff --git a/.github/workflows/cbz-federation-drift.yml b/.github/workflows/cbz-federation-drift.yml new file mode 100644 index 000000000..c39db8ae9 --- /dev/null +++ b/.github/workflows/cbz-federation-drift.yml @@ -0,0 +1,80 @@ +name: CBZ federation drift +'on': + pull_request: + paths: + - '**/*.lean' + - '**/lakefile.lean' + - '**/lakefile.toml' + - '**/lake-manifest.json' + - '**/lean-toolchain' + - 'tools/cbz_drift/**' + - 'tests/test_cbz_drift.py' + - '.github/workflows/cbz-federation-drift.yml' + push: + branches: [main] + schedule: + - cron: '41 4 * * *' + workflow_dispatch: +permissions: + contents: read +jobs: + self-test: + name: drift-crawler-self-test + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 + with: + python-version: '3.11' + - name: Behaviour and mutation tests in both interpreter modes + env: + PYTHONDONTWRITEBYTECODE: '1' + run: | + set -euo pipefail + cd tests + for mode in normal optimized; do + flag=""; [ "$mode" = optimized ] && flag="-O" + python -B $flag -m unittest test_cbz_drift -v 2>&1 | tee "$RUNNER_TEMP/drift-$mode.log" + grep -Eq '^Ran [1-9][0-9]* tests? in ' "$RUNNER_TEMP/drift-$mode.log" || { echo "::error::drift $mode run collected 0 tests"; exit 1; } + done + crawl: + name: federation-drift + needs: self-test + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + fetch-depth: 0 + path: fed/main + - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 + with: + python-version: '3.11' + - name: Crawl the federation from its workspace seed + env: + PYTHONDONTWRITEBYTECODE: '1' + run: | + set -euo pipefail + # Only the seed is named here. Every other repository, and its ref, is discovered + # from the seed's pins, submodules, repository list, registry and lake manifests. + git clone -q https://github.com/d6g8k5htny-coder/Universal-Law-Workspace.git fed/Universal-Law-Workspace + head=$(git -C fed/main rev-parse HEAD) + status=0 + for at in pins tips; do + python -B -S fed/main/tools/cbz_drift/crawl.py --seed d6g8k5htny-coder/Universal-Law-Workspace \ + --search fed --clone-into fed --fetch --at "$at" \ + --override "d6g8k5htny-coder/main=$head" \ + --json "$RUNNER_TEMP/drift-$at.json" || status=$? + [ "$status" -le 1 ] || { echo "::error::drift crawler error (exit $status)"; exit "$status"; } + done + exit "$status" + - if: always() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: federation-drift-reports + path: ${{ runner.temp }}/drift-*.json + if-no-files-found: warn diff --git a/cbz/evidence/drift-crawler-017-20261029/README.md b/cbz/evidence/drift-crawler-017-20261029/README.md new file mode 100644 index 000000000..e36207a6e --- /dev/null +++ b/cbz/evidence/drift-crawler-017-20261029/README.md @@ -0,0 +1,66 @@ +# Drift crawler: evidence and proposed registration + +Built by Anthropic Claude, session Claude017 (`session_017Mi3hx…`), under the owner's CBZ-0 +addendum ("Intent-locked reinforcements": a dynamic federation drift crawler). +- Pickup: main#684/6510531192. +- Credit 0. Scientific effect NONE. +- Under B-003, this directory and `tools/cbz_drift/` are the only things written here. + `GOVERNANCE.md`, `TOOLING.md` and the gate matrix belong to Root. The proposed text + for them is below. + +## Observed runs (2026-10-29, CPython 3.11.15) + +The tool bytes and every command are in this directory. Exit status is in `exits.txt`. + +| Run | Seed | Crawled | BLOCK | INFO | Lean files / declarations / names shared across locations | Registry artifacts verified | +|---|---|---|---|---|---|---| +| `crawl-pins.json`, local clones | ULW `a4b01682` | 9 repositories | **0** | `PIN-STALE` 4, `REGISTRY-EVOLVED` 31 | 166 / 3,030 / 479 | 592 of 592 | +| `crawl-tips.json`, default tips | ULW `a4b01682` | 9 | **0** | `PIN-STALE` 4, `REGISTRY-EVOLVED` 32 | 172 / 3,039 / 482 | 592 of 592 | +| `crawl-cold-pins.json`, only the seed cloned, the rest found and cloned by the crawler | ULW `a4b01682` | 9 | **0** | as for pins | as for pins | 592 of 592 | + +- **Cold start.** The cold-start report has the same statistics, refs and findings as the + local run at pins. The crawler needs nothing but the seed. +- **What the 0 means.** No two records that claim the same identity disagree. At the pins + and at the tips, every Lean name declared in two or more places (479 at the pins, 482 at + the tips) has one interface. Almost all of them are statement packages copied between Math- packages + (`frontiers/source_*`, `companions/torus_filtration`, `frontiers/compact_morse_elder_adapter`, + `specifications/lean_statements_20261010` and others). Three are within `main`'s + `cbz/evidence` kernel replays. +- **Pins.** The four stale pins (`governance-`, `main`, `Math-`, `meta-framework`) are + behind their tips and on the default line. This crawler reports staleness as INFO. + Currency is what ULW's own `verify_pins.py --require-current` enforces. +- **Local fetch.** Several local clones were shallow. `--fetch` unshallowed them, which is + additive only. Without it, the crawler reports BLOCK `PIN-OFFLINE … shallow clone` and + does not guess ancestry. + +## Tool verification + +- Two interpreter modes (`python3 -B` and `-B -O`): 43 tests OK, about 42 s each. +- **35 mutants, all killed**, each by its designated test failing by assertion. Every + designated test passes on the unmutated copy (the harness control). +- The 344 tests in `main`'s workflow-reading modules give the same 3 errors with and + without this change: `test_formal_workflow_shell` and two `test_periodic_pilot_custody*` + load errors. All three are environmental in this container. + +## Proposed text for Root (B-003) + +**GOVERNANCE.md, Tool registry.** Add this entry: + +> `tools/cbz_drift/crawl.py`: federation drift crawler (G7). Discovers the federation from +> the workspace seed's records and fails on disagreement between records of one +> identity: pins, registry bytes, and the source interfaces of Lean declarations shared +> across locations. Lexical domain and limits: `tools/cbz_drift/README.md`. It certifies +> agreement of recorded identities and source text only; G2–G4 remain authoritative for +> kernel closure. + +**TOOLING.md.** Add this row: + +| Tool | Gate | Command | Verification | +|---|---|---|---| +| `tools/cbz_drift/crawl.py` | G7 | `crawl.py --seed d6g8k5htny-coder/Universal-Law-Workspace --search fed --clone-into fed --fetch --at pins` (and `--at tips`) | `tests/test_cbz_drift.py`, both modes; 35 designated-assertion mutants (G6) | + +**Gate matrix §10, G7.** Proposed wording: "PASS when `cbz-federation-drift` exits 0 at +`--at pins` in the final run, with every discovered repository resolved. A BLOCK finding +fails G7 and blocks integration of the PR that introduces it." The workflow already runs +on every PR to `main` that touches Lean, lake files or the tool. It overrides `main` +with the candidate head and crawls the rest of the federation at its pins and tips. diff --git a/cbz/evidence/drift-crawler-017-20261029/crawl-cold-pins.json b/cbz/evidence/drift-crawler-017-20261029/crawl-cold-pins.json new file mode 100644 index 000000000..b2cb8a51c --- /dev/null +++ b/cbz/evidence/drift-crawler-017-20261029/crawl-cold-pins.json @@ -0,0 +1,406 @@ +{ + "blocking": 0, + "edges": [ + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/google-drive", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/governance-", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/main", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/math-", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/meta-framework", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/query-", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/sandbox", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/trial", + "via": "gitmodules+pins+listed" + } + ], + "findings": [ + { + "code": "PIN-STALE", + "level": "INFO", + "message": "pin e396002aa191 is 1 commits behind the default tip 1b62ca2f64b3", + "pin": "e396002aa19158f9fcca27eaf33a5da38b1ed313", + "repo": "d6g8k5htny-coder/governance-", + "tip": "1b62ca2f64b3012c2fdbbf7f55ced236c3042891" + }, + { + "code": "PIN-STALE", + "level": "INFO", + "message": "pin 81acc060341e is 31 commits behind the default tip e6f265384105", + "pin": "81acc060341e8a31cc4cd4f9523ef71fb6c06175", + "repo": "d6g8k5htny-coder/main", + "tip": "e6f2653841053004d213b3647a7e14e799f503b2" + }, + { + "code": "PIN-STALE", + "level": "INFO", + "message": "pin 8151f592918a is 17 commits behind the default tip 9f8dbb4d18b9", + "pin": "8151f592918a845bf19eb8eafaf8444540a32734", + "repo": "d6g8k5htny-coder/math-", + "tip": "9f8dbb4d18b9f3ebd9ffac6b0caa42df9f343966" + }, + { + "code": "PIN-STALE", + "level": "INFO", + "message": "pin c70e1984477a is 1 commits behind the default tip 0f5894f81a54", + "pin": "c70e1984477ae1752e93a060fac8bf0486c0ce73", + "repo": "d6g8k5htny-coder/meta-framework", + "tip": "0f5894f81a5462c10ee5ec8f8109f466e712e47e" + }, + { + "artifact": "downstream-hard-gate", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate: frontiers/downstream_gate_20260925/README.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-graph", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-graph: frontiers/downstream_gate_20260925/GRAPH.json differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-code", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-code: frontiers/downstream_gate_20260925/hard_gate.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-tests", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-tests: frontiers/downstream_gate_20260925/test_hard_gate.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-output", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-output: frontiers/downstream_gate_20260925/RESULTS.json differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-replay", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-replay: frontiers/downstream_gate_20260925/run_validation.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "contact-small-gap-kernel", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact contact-small-gap-kernel: reviews/contact_kernel_tail_20260925/KERNEL_TAILS_AND_SMALL_GAP.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "contact-small-gap-source-files", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact contact-small-gap-source-files: reviews/contact_kernel_tail_20260925/SOURCE_FILES.json differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "landing-claims-manifest", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact landing-claims-manifest: claims/LANDING_CLAIMS.json differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "landing-claims-check", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact landing-claims-check: tools/landing_claims_check.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "landing-claims-tests", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact landing-claims-tests: tests/test_landing_claims_check.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "lifetime-parent-verify", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact lifetime-parent-verify: imports/lifetime_parent_20260925/verify.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "review-topology-merged", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact review-topology-merged: REVIEW_TOPOLOGY.md differs at the crawled ref e396002aa191", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "proof-availability-index", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact proof-availability-index: PROOF_INDEX.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "trial-status-guard-snapshot", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact trial-status-guard-snapshot: portable/STATUS_GUARD_SNAPSHOT.json differs at the crawled ref 3738c859d519", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "math-downstream-gate-workflow", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact math-downstream-gate-workflow: .github/workflows/downstream-gate.yml differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "h5-ledger-custody-readme", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact h5-ledger-custody-readme: imports/upper2d_h5_ledgers_20260926/README.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "h5-rim-contract-workflow", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact h5-rim-contract-workflow: .github/workflows/h5-rim-contract.yml differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "bf-six-pin-workflow", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact bf-six-pin-workflow: .github/workflows/bf-six-pin-scalar.yml differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-workflow", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-workflow: .github/workflows/formal-lean.yml differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-manifest", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-manifest: formal/manifest.json differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-gate", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-gate: formal/gate.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-gate-test", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-gate-test: formal/tests/test_gate.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-core-root", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-core-root: formal/ResearchFormalCoreR1.lean differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-scope", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-scope: formal/SCOPE.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "drive-hole-substitutes-ledger", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact drive-hole-substitutes-ledger: reviews/drive_hole_substitutes_20260926/LEDGER.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "public-reading-map", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact public-reading-map: PUBLIC_READING_MAP.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "math-pr96-agents", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact math-pr96-agents: AGENTS.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-required-checks-doc", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-required-checks-doc: docs/FORMAL_REQUIRED_CHECKS.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "required-formal-check-tool", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact required-formal-check-tool: tools/required_formal_check.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "required-formal-check-tests", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact required-formal-check-tests: tests/test_required_formal_check.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + } + ], + "mode": "pins", + "repositories": [ + { + "optional": false, + "pin": "ad08584b3ea9d533af10113e85169f471fa8ec93", + "ref": "ad08584b3ea9d533af10113e85169f471fa8ec93", + "repository": "d6g8k5htny-coder/google-drive", + "resolved": true + }, + { + "optional": false, + "pin": "e396002aa19158f9fcca27eaf33a5da38b1ed313", + "ref": "e396002aa19158f9fcca27eaf33a5da38b1ed313", + "repository": "d6g8k5htny-coder/governance-", + "resolved": true + }, + { + "optional": false, + "pin": "81acc060341e8a31cc4cd4f9523ef71fb6c06175", + "ref": "81acc060341e8a31cc4cd4f9523ef71fb6c06175", + "repository": "d6g8k5htny-coder/main", + "resolved": true + }, + { + "optional": false, + "pin": "8151f592918a845bf19eb8eafaf8444540a32734", + "ref": "8151f592918a845bf19eb8eafaf8444540a32734", + "repository": "d6g8k5htny-coder/math-", + "resolved": true + }, + { + "optional": false, + "pin": "c70e1984477ae1752e93a060fac8bf0486c0ce73", + "ref": "c70e1984477ae1752e93a060fac8bf0486c0ce73", + "repository": "d6g8k5htny-coder/meta-framework", + "resolved": true + }, + { + "optional": false, + "pin": "fb4c457b5861dc49696fd0a8e11c7c405056c05f", + "ref": "fb4c457b5861dc49696fd0a8e11c7c405056c05f", + "repository": "d6g8k5htny-coder/query-", + "resolved": true + }, + { + "optional": true, + "pin": "dce04a4174835107126ab4f36c199a2dc320f964", + "ref": "dce04a4174835107126ab4f36c199a2dc320f964", + "repository": "d6g8k5htny-coder/sandbox", + "resolved": true + }, + { + "optional": false, + "pin": "3738c859d519d2dbf1e388fe48fe0ae60c9487a3", + "ref": "3738c859d519d2dbf1e388fe48fe0ae60c9487a3", + "repository": "d6g8k5htny-coder/trial", + "resolved": true + }, + { + "optional": false, + "pin": null, + "ref": "a4b016820329afc1787d9c191572b05cd88236ac", + "repository": "d6g8k5htny-coder/universal-law-workspace", + "resolved": true + } + ], + "schema": "cbz.drift.v1", + "seed": { + "ref": "a4b016820329afc1787d9c191572b05cd88236ac", + "repository": "d6g8k5htny-coder/universal-law-workspace" + }, + "stats": { + "lean_declarations": 3030, + "lean_files": 166, + "lean_shared_names": 479, + "registry_artifacts": 592, + "registry_artifacts_evolved": 31, + "registry_artifacts_verified": 592 + } +} diff --git a/cbz/evidence/drift-crawler-017-20261029/crawl-cold-pins.stdout b/cbz/evidence/drift-crawler-017-20261029/crawl-cold-pins.stdout new file mode 100644 index 000000000..65411515b --- /dev/null +++ b/cbz/evidence/drift-crawler-017-20261029/crawl-cold-pins.stdout @@ -0,0 +1 @@ +crawled 9 repositories from d6g8k5htny-coder/universal-law-workspace@a4b016820329 (pins): 0 BLOCK, INFO {'PIN-STALE': 4, 'REGISTRY-EVOLVED': 31}; stats {'lean_declarations': 3030, 'lean_files': 166, 'lean_shared_names': 479, 'registry_artifacts': 592, 'registry_artifacts_evolved': 31, 'registry_artifacts_verified': 592} diff --git a/cbz/evidence/drift-crawler-017-20261029/crawl-pins.json b/cbz/evidence/drift-crawler-017-20261029/crawl-pins.json new file mode 100644 index 000000000..b2cb8a51c --- /dev/null +++ b/cbz/evidence/drift-crawler-017-20261029/crawl-pins.json @@ -0,0 +1,406 @@ +{ + "blocking": 0, + "edges": [ + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/google-drive", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/governance-", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/main", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/math-", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/meta-framework", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/query-", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/sandbox", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/trial", + "via": "gitmodules+pins+listed" + } + ], + "findings": [ + { + "code": "PIN-STALE", + "level": "INFO", + "message": "pin e396002aa191 is 1 commits behind the default tip 1b62ca2f64b3", + "pin": "e396002aa19158f9fcca27eaf33a5da38b1ed313", + "repo": "d6g8k5htny-coder/governance-", + "tip": "1b62ca2f64b3012c2fdbbf7f55ced236c3042891" + }, + { + "code": "PIN-STALE", + "level": "INFO", + "message": "pin 81acc060341e is 31 commits behind the default tip e6f265384105", + "pin": "81acc060341e8a31cc4cd4f9523ef71fb6c06175", + "repo": "d6g8k5htny-coder/main", + "tip": "e6f2653841053004d213b3647a7e14e799f503b2" + }, + { + "code": "PIN-STALE", + "level": "INFO", + "message": "pin 8151f592918a is 17 commits behind the default tip 9f8dbb4d18b9", + "pin": "8151f592918a845bf19eb8eafaf8444540a32734", + "repo": "d6g8k5htny-coder/math-", + "tip": "9f8dbb4d18b9f3ebd9ffac6b0caa42df9f343966" + }, + { + "code": "PIN-STALE", + "level": "INFO", + "message": "pin c70e1984477a is 1 commits behind the default tip 0f5894f81a54", + "pin": "c70e1984477ae1752e93a060fac8bf0486c0ce73", + "repo": "d6g8k5htny-coder/meta-framework", + "tip": "0f5894f81a5462c10ee5ec8f8109f466e712e47e" + }, + { + "artifact": "downstream-hard-gate", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate: frontiers/downstream_gate_20260925/README.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-graph", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-graph: frontiers/downstream_gate_20260925/GRAPH.json differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-code", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-code: frontiers/downstream_gate_20260925/hard_gate.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-tests", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-tests: frontiers/downstream_gate_20260925/test_hard_gate.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-output", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-output: frontiers/downstream_gate_20260925/RESULTS.json differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-replay", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-replay: frontiers/downstream_gate_20260925/run_validation.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "contact-small-gap-kernel", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact contact-small-gap-kernel: reviews/contact_kernel_tail_20260925/KERNEL_TAILS_AND_SMALL_GAP.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "contact-small-gap-source-files", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact contact-small-gap-source-files: reviews/contact_kernel_tail_20260925/SOURCE_FILES.json differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "landing-claims-manifest", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact landing-claims-manifest: claims/LANDING_CLAIMS.json differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "landing-claims-check", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact landing-claims-check: tools/landing_claims_check.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "landing-claims-tests", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact landing-claims-tests: tests/test_landing_claims_check.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "lifetime-parent-verify", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact lifetime-parent-verify: imports/lifetime_parent_20260925/verify.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "review-topology-merged", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact review-topology-merged: REVIEW_TOPOLOGY.md differs at the crawled ref e396002aa191", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "proof-availability-index", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact proof-availability-index: PROOF_INDEX.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "trial-status-guard-snapshot", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact trial-status-guard-snapshot: portable/STATUS_GUARD_SNAPSHOT.json differs at the crawled ref 3738c859d519", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "math-downstream-gate-workflow", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact math-downstream-gate-workflow: .github/workflows/downstream-gate.yml differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "h5-ledger-custody-readme", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact h5-ledger-custody-readme: imports/upper2d_h5_ledgers_20260926/README.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "h5-rim-contract-workflow", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact h5-rim-contract-workflow: .github/workflows/h5-rim-contract.yml differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "bf-six-pin-workflow", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact bf-six-pin-workflow: .github/workflows/bf-six-pin-scalar.yml differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-workflow", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-workflow: .github/workflows/formal-lean.yml differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-manifest", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-manifest: formal/manifest.json differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-gate", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-gate: formal/gate.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-gate-test", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-gate-test: formal/tests/test_gate.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-core-root", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-core-root: formal/ResearchFormalCoreR1.lean differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-scope", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-scope: formal/SCOPE.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "drive-hole-substitutes-ledger", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact drive-hole-substitutes-ledger: reviews/drive_hole_substitutes_20260926/LEDGER.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "public-reading-map", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact public-reading-map: PUBLIC_READING_MAP.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "math-pr96-agents", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact math-pr96-agents: AGENTS.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-required-checks-doc", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-required-checks-doc: docs/FORMAL_REQUIRED_CHECKS.md differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "required-formal-check-tool", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact required-formal-check-tool: tools/required_formal_check.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "required-formal-check-tests", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact required-formal-check-tests: tests/test_required_formal_check.py differs at the crawled ref 8151f592918a", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + } + ], + "mode": "pins", + "repositories": [ + { + "optional": false, + "pin": "ad08584b3ea9d533af10113e85169f471fa8ec93", + "ref": "ad08584b3ea9d533af10113e85169f471fa8ec93", + "repository": "d6g8k5htny-coder/google-drive", + "resolved": true + }, + { + "optional": false, + "pin": "e396002aa19158f9fcca27eaf33a5da38b1ed313", + "ref": "e396002aa19158f9fcca27eaf33a5da38b1ed313", + "repository": "d6g8k5htny-coder/governance-", + "resolved": true + }, + { + "optional": false, + "pin": "81acc060341e8a31cc4cd4f9523ef71fb6c06175", + "ref": "81acc060341e8a31cc4cd4f9523ef71fb6c06175", + "repository": "d6g8k5htny-coder/main", + "resolved": true + }, + { + "optional": false, + "pin": "8151f592918a845bf19eb8eafaf8444540a32734", + "ref": "8151f592918a845bf19eb8eafaf8444540a32734", + "repository": "d6g8k5htny-coder/math-", + "resolved": true + }, + { + "optional": false, + "pin": "c70e1984477ae1752e93a060fac8bf0486c0ce73", + "ref": "c70e1984477ae1752e93a060fac8bf0486c0ce73", + "repository": "d6g8k5htny-coder/meta-framework", + "resolved": true + }, + { + "optional": false, + "pin": "fb4c457b5861dc49696fd0a8e11c7c405056c05f", + "ref": "fb4c457b5861dc49696fd0a8e11c7c405056c05f", + "repository": "d6g8k5htny-coder/query-", + "resolved": true + }, + { + "optional": true, + "pin": "dce04a4174835107126ab4f36c199a2dc320f964", + "ref": "dce04a4174835107126ab4f36c199a2dc320f964", + "repository": "d6g8k5htny-coder/sandbox", + "resolved": true + }, + { + "optional": false, + "pin": "3738c859d519d2dbf1e388fe48fe0ae60c9487a3", + "ref": "3738c859d519d2dbf1e388fe48fe0ae60c9487a3", + "repository": "d6g8k5htny-coder/trial", + "resolved": true + }, + { + "optional": false, + "pin": null, + "ref": "a4b016820329afc1787d9c191572b05cd88236ac", + "repository": "d6g8k5htny-coder/universal-law-workspace", + "resolved": true + } + ], + "schema": "cbz.drift.v1", + "seed": { + "ref": "a4b016820329afc1787d9c191572b05cd88236ac", + "repository": "d6g8k5htny-coder/universal-law-workspace" + }, + "stats": { + "lean_declarations": 3030, + "lean_files": 166, + "lean_shared_names": 479, + "registry_artifacts": 592, + "registry_artifacts_evolved": 31, + "registry_artifacts_verified": 592 + } +} diff --git a/cbz/evidence/drift-crawler-017-20261029/crawl-pins.stdout b/cbz/evidence/drift-crawler-017-20261029/crawl-pins.stdout new file mode 100644 index 000000000..65411515b --- /dev/null +++ b/cbz/evidence/drift-crawler-017-20261029/crawl-pins.stdout @@ -0,0 +1 @@ +crawled 9 repositories from d6g8k5htny-coder/universal-law-workspace@a4b016820329 (pins): 0 BLOCK, INFO {'PIN-STALE': 4, 'REGISTRY-EVOLVED': 31}; stats {'lean_declarations': 3030, 'lean_files': 166, 'lean_shared_names': 479, 'registry_artifacts': 592, 'registry_artifacts_evolved': 31, 'registry_artifacts_verified': 592} diff --git a/cbz/evidence/drift-crawler-017-20261029/crawl-tips.json b/cbz/evidence/drift-crawler-017-20261029/crawl-tips.json new file mode 100644 index 000000000..a2048fabb --- /dev/null +++ b/cbz/evidence/drift-crawler-017-20261029/crawl-tips.json @@ -0,0 +1,414 @@ +{ + "blocking": 0, + "edges": [ + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/google-drive", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/governance-", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/main", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/math-", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/meta-framework", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/query-", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/sandbox", + "via": "gitmodules+pins+listed" + }, + { + "from": "d6g8k5htny-coder/universal-law-workspace", + "to": "d6g8k5htny-coder/trial", + "via": "gitmodules+pins+listed" + } + ], + "findings": [ + { + "code": "PIN-STALE", + "level": "INFO", + "message": "pin e396002aa191 is 1 commits behind the default tip 1b62ca2f64b3", + "pin": "e396002aa19158f9fcca27eaf33a5da38b1ed313", + "repo": "d6g8k5htny-coder/governance-", + "tip": "1b62ca2f64b3012c2fdbbf7f55ced236c3042891" + }, + { + "code": "PIN-STALE", + "level": "INFO", + "message": "pin 81acc060341e is 31 commits behind the default tip e6f265384105", + "pin": "81acc060341e8a31cc4cd4f9523ef71fb6c06175", + "repo": "d6g8k5htny-coder/main", + "tip": "e6f2653841053004d213b3647a7e14e799f503b2" + }, + { + "code": "PIN-STALE", + "level": "INFO", + "message": "pin 8151f592918a is 17 commits behind the default tip 9f8dbb4d18b9", + "pin": "8151f592918a845bf19eb8eafaf8444540a32734", + "repo": "d6g8k5htny-coder/math-", + "tip": "9f8dbb4d18b9f3ebd9ffac6b0caa42df9f343966" + }, + { + "code": "PIN-STALE", + "level": "INFO", + "message": "pin c70e1984477a is 1 commits behind the default tip 0f5894f81a54", + "pin": "c70e1984477ae1752e93a060fac8bf0486c0ce73", + "repo": "d6g8k5htny-coder/meta-framework", + "tip": "0f5894f81a5462c10ee5ec8f8109f466e712e47e" + }, + { + "artifact": "downstream-hard-gate", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate: frontiers/downstream_gate_20260925/README.md differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-graph", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-graph: frontiers/downstream_gate_20260925/GRAPH.json differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-code", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-code: frontiers/downstream_gate_20260925/hard_gate.py differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-tests", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-tests: frontiers/downstream_gate_20260925/test_hard_gate.py differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-output", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-output: frontiers/downstream_gate_20260925/RESULTS.json differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-replay", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-replay: frontiers/downstream_gate_20260925/run_validation.py differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "downstream-hard-gate-pr15-replica-source", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact downstream-hard-gate-pr15-replica-source: replicas/downstream-gate-pr15-v1/SOURCE.json differs at the crawled ref 0f5894f81a54", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "contact-small-gap-kernel", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact contact-small-gap-kernel: reviews/contact_kernel_tail_20260925/KERNEL_TAILS_AND_SMALL_GAP.md differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "contact-small-gap-source-files", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact contact-small-gap-source-files: reviews/contact_kernel_tail_20260925/SOURCE_FILES.json differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "landing-claims-manifest", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact landing-claims-manifest: claims/LANDING_CLAIMS.json differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "landing-claims-check", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact landing-claims-check: tools/landing_claims_check.py differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "landing-claims-tests", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact landing-claims-tests: tests/test_landing_claims_check.py differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "lifetime-parent-verify", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact lifetime-parent-verify: imports/lifetime_parent_20260925/verify.py differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "review-topology-merged", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact review-topology-merged: REVIEW_TOPOLOGY.md differs at the crawled ref 1b62ca2f64b3", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "proof-availability-index", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact proof-availability-index: PROOF_INDEX.md differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "trial-status-guard-snapshot", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact trial-status-guard-snapshot: portable/STATUS_GUARD_SNAPSHOT.json differs at the crawled ref 3738c859d519", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "math-downstream-gate-workflow", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact math-downstream-gate-workflow: .github/workflows/downstream-gate.yml differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "h5-ledger-custody-readme", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact h5-ledger-custody-readme: imports/upper2d_h5_ledgers_20260926/README.md differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "h5-rim-contract-workflow", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact h5-rim-contract-workflow: .github/workflows/h5-rim-contract.yml differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "bf-six-pin-workflow", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact bf-six-pin-workflow: .github/workflows/bf-six-pin-scalar.yml differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-workflow", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-workflow: .github/workflows/formal-lean.yml differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-manifest", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-manifest: formal/manifest.json differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-gate", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-gate: formal/gate.py differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-gate-test", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-gate-test: formal/tests/test_gate.py differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-core-root", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-core-root: formal/ResearchFormalCoreR1.lean differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-lean-scope", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-lean-scope: formal/SCOPE.md differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "drive-hole-substitutes-ledger", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact drive-hole-substitutes-ledger: reviews/drive_hole_substitutes_20260926/LEDGER.md differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "public-reading-map", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact public-reading-map: PUBLIC_READING_MAP.md differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "math-pr96-agents", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact math-pr96-agents: AGENTS.md differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "formal-required-checks-doc", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact formal-required-checks-doc: docs/FORMAL_REQUIRED_CHECKS.md differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "required-formal-check-tool", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact required-formal-check-tool: tools/required_formal_check.py differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + }, + { + "artifact": "required-formal-check-tests", + "code": "REGISTRY-EVOLVED", + "level": "INFO", + "message": "artifact required-formal-check-tests: tests/test_required_formal_check.py differs at the crawled ref 9f8dbb4d18b9", + "path": "registry.json", + "repo": "d6g8k5htny-coder/meta-framework" + } + ], + "mode": "tips", + "repositories": [ + { + "optional": false, + "pin": "ad08584b3ea9d533af10113e85169f471fa8ec93", + "ref": "ad08584b3ea9d533af10113e85169f471fa8ec93", + "repository": "d6g8k5htny-coder/google-drive", + "resolved": true + }, + { + "optional": false, + "pin": "e396002aa19158f9fcca27eaf33a5da38b1ed313", + "ref": "1b62ca2f64b3012c2fdbbf7f55ced236c3042891", + "repository": "d6g8k5htny-coder/governance-", + "resolved": true + }, + { + "optional": false, + "pin": "81acc060341e8a31cc4cd4f9523ef71fb6c06175", + "ref": "e6f2653841053004d213b3647a7e14e799f503b2", + "repository": "d6g8k5htny-coder/main", + "resolved": true + }, + { + "optional": false, + "pin": "8151f592918a845bf19eb8eafaf8444540a32734", + "ref": "9f8dbb4d18b9f3ebd9ffac6b0caa42df9f343966", + "repository": "d6g8k5htny-coder/math-", + "resolved": true + }, + { + "optional": false, + "pin": "c70e1984477ae1752e93a060fac8bf0486c0ce73", + "ref": "0f5894f81a5462c10ee5ec8f8109f466e712e47e", + "repository": "d6g8k5htny-coder/meta-framework", + "resolved": true + }, + { + "optional": false, + "pin": "fb4c457b5861dc49696fd0a8e11c7c405056c05f", + "ref": "fb4c457b5861dc49696fd0a8e11c7c405056c05f", + "repository": "d6g8k5htny-coder/query-", + "resolved": true + }, + { + "optional": true, + "pin": "dce04a4174835107126ab4f36c199a2dc320f964", + "ref": "dce04a4174835107126ab4f36c199a2dc320f964", + "repository": "d6g8k5htny-coder/sandbox", + "resolved": true + }, + { + "optional": false, + "pin": "3738c859d519d2dbf1e388fe48fe0ae60c9487a3", + "ref": "3738c859d519d2dbf1e388fe48fe0ae60c9487a3", + "repository": "d6g8k5htny-coder/trial", + "resolved": true + }, + { + "optional": false, + "pin": null, + "ref": "a4b016820329afc1787d9c191572b05cd88236ac", + "repository": "d6g8k5htny-coder/universal-law-workspace", + "resolved": true + } + ], + "schema": "cbz.drift.v1", + "seed": { + "ref": "a4b016820329afc1787d9c191572b05cd88236ac", + "repository": "d6g8k5htny-coder/universal-law-workspace" + }, + "stats": { + "lean_declarations": 3039, + "lean_files": 172, + "lean_shared_names": 482, + "registry_artifacts": 592, + "registry_artifacts_evolved": 32, + "registry_artifacts_verified": 592 + } +} diff --git a/cbz/evidence/drift-crawler-017-20261029/crawl-tips.stdout b/cbz/evidence/drift-crawler-017-20261029/crawl-tips.stdout new file mode 100644 index 000000000..fb999a8eb --- /dev/null +++ b/cbz/evidence/drift-crawler-017-20261029/crawl-tips.stdout @@ -0,0 +1 @@ +crawled 9 repositories from d6g8k5htny-coder/universal-law-workspace@a4b016820329 (tips): 0 BLOCK, INFO {'PIN-STALE': 4, 'REGISTRY-EVOLVED': 32}; stats {'lean_declarations': 3039, 'lean_files': 172, 'lean_shared_names': 482, 'registry_artifacts': 592, 'registry_artifacts_evolved': 32, 'registry_artifacts_verified': 592} diff --git a/cbz/evidence/drift-crawler-017-20261029/exits.txt b/cbz/evidence/drift-crawler-017-20261029/exits.txt new file mode 100644 index 000000000..acbfd33bc --- /dev/null +++ b/cbz/evidence/drift-crawler-017-20261029/exits.txt @@ -0,0 +1,3 @@ +pins exit=0 +tips exit=0 +cold-pins exit=0 diff --git a/tests/test_cbz_drift.py b/tests/test_cbz_drift.py new file mode 100644 index 000000000..e1fca064f --- /dev/null +++ b/tests/test_cbz_drift.py @@ -0,0 +1,589 @@ +"""Tests for tools/cbz_drift: the federation drift crawler and its Lean declaration lexer. + +Every check runs against a synthetic federation of real git repositories built in a +temporary directory, so each finding is produced by the same code path as a live crawl. +`ScannerMutationTests` rewrites the crawler in designated ways and requires a designated +test to fail by assertion (A8); a mutant that only breaks import or syntax does not count. + +CBZ_DRIFT_DIR selects the tool directory under test (default: tools/cbz_drift). +""" +import hashlib +import json +import os +import pathlib +import py_compile +import re +import shutil +import subprocess +import sys +import tempfile +import textwrap +import unittest + +ROOT = pathlib.Path(__file__).resolve().parents[1] +TOOL = pathlib.Path(os.environ.get('CBZ_DRIFT_DIR', ROOT / 'tools' / 'cbz_drift')) +sys.path.insert(0, str(TOOL)) +import crawl # noqa: E402 +import lean_decls # noqa: E402 + +ENV = dict(os.environ, GIT_AUTHOR_NAME='t', GIT_AUTHOR_EMAIL='t@t', GIT_COMMITTER_NAME='t', + GIT_COMMITTER_EMAIL='t@t', GIT_CONFIG_GLOBAL=os.devnull, GIT_CONFIG_NOSYSTEM='1') + +LEAN_A = textwrap.dedent('''\ + import Mathlib + /-- doc -/ + namespace Fed + theorem t (n : Nat) : n + 0 = n := by simp + def f : Nat := 3 + private def p : Nat := 1 + structure S where + x : Nat + y : Nat + end Fed + ''') + + +def sh(cwd, *args, data=None): + r = subprocess.run(['git', '-C', str(cwd), *args], input=data, capture_output=True, env=ENV) + if r.returncode: + raise AssertionError('git %s: %s' % (args, r.stderr.decode())) + return r.stdout.decode().strip() + + +class Fed: + """A synthetic federation: seed `ws`, Lean repos `a` and `b`, registry `reg`.""" + + def __init__(self, base): + self.base = pathlib.Path(base) + self.urls = {} + + def url(self, name): + return self.urls.get(name, 'https://github.com/fed/%s.git' % name) + + def repo(self, name): + d = self.base / name + if not d.exists(): + d.mkdir() + sh(d, 'init', '-q', '-b', 'main') + sh(d, 'remote', 'add', 'origin', 'https://github.com/fed/%s.git' % name) + return d + + def commit(self, name, files, msg='c', remove=()): + d = self.repo(name) + for path, text in files.items(): + p = d / path + p.parent.mkdir(parents=True, exist_ok=True) + p.write_bytes(text if isinstance(text, bytes) else text.encode()) + sh(d, 'add', path) + for path in remove: + sh(d, 'rm', '-q', path) + sh(d, 'commit', '-q', '--allow-empty', '-m', msg) + sha = sh(d, 'rev-parse', 'HEAD') + sh(d, 'update-ref', 'refs/remotes/origin/main', sha) + return sha + + def build(self, a_lean=LEAN_A, b_lean=LEAN_A): + self.pins = {} + self.pins['a'] = self.commit('a', {'lakefile.toml': 'name = "a"\n', 'lean-toolchain': 'v4.0.0\n', + 'Fed/A.lean': a_lean, 'data/x.txt': 'payload\n'}) + self.pins['b'] = self.commit('b', {'lakefile.toml': 'name = "b"\n', 'lean-toolchain': 'v4.0.0\n', + 'Copy/A.lean': b_lean}) + payload = b'payload\n' + self.registry = { + 'repositories': {'A': {'full_name': 'fed/a'}}, + 'artifacts': [{'key': 'x', 'repository': 'A', 'commit': self.pins['a'], 'path': 'data/x.txt', + 'bytes': len(payload), 'sha256': hashlib.sha256(payload).hexdigest()}], + } + self.pins['reg'] = self.commit('reg', {'registry.json': json.dumps(self.registry)}) + self.members = ['a', 'b', 'reg'] + return self.write_seed() + + def write_seed(self, pins=None, gitlinks=None, listed=None, modules=None, extra=None, update=None): + pins = dict(self.pins if pins is None else pins) + gitlinks = dict(pins if gitlinks is None else gitlinks) + names = sorted(self.members) + modules = names if modules is None else modules + listed = names if listed is None else listed + gm = ''.join('[submodule "repos/%s"]\n\tpath = repos/%s\n\turl = %s\n%s' % ( + n, n, self.url(n), '\tupdate = none\n' if update == n else '') for n in modules) + pj = {'schema': 'ulw.pins.v1', 'repos': [ + {'name': n, 'path': 'repos/%s' % n, 'url': self.url(n), + 'pinned_sha': pins[n], 'opt_in': update == n} for n in names if n in pins]} + reg_blob = sh(self.repo('reg'), 'rev-parse', '%s:registry.json' % pins.get('reg', self.pins['reg'])) + wsj = {'repositories': [{'full_name': 'fed/ws'}] + [{'full_name': 'fed/%s' % n} for n in listed], + 'canonical_inputs': {'repository_registry': {'repository': 'fed/reg', 'path': 'registry.json', + 'observed_blob': reg_blob}}} + files = {'.gitmodules': gm, 'pins.json': json.dumps(pj), 'workspace/repositories.json': json.dumps(wsj)} + files.update(extra or {}) + d = self.repo('ws') + for path, text in files.items(): + p = d / path + p.parent.mkdir(parents=True, exist_ok=True) + p.write_text(text) + sh(d, 'add', path) + tracked = sh(d, 'ls-files', '-s', 'repos').splitlines() + for line in tracked: + sh(d, 'rm', '-q', '--cached', line.split('\t')[1]) + for n, sha in gitlinks.items(): + if n in modules: + sh(d, 'update-index', '--add', '--cacheinfo', '160000,%s,repos/%s' % (sha, n)) + sh(d, 'commit', '-q', '--allow-empty', '-m', 'seed') + sha = sh(d, 'rev-parse', 'HEAD') + sh(d, 'update-ref', 'refs/remotes/origin/main', sha) + return sha + + def crawl(self, **kw): + return crawl.run('fed/ws', [str(self.base)], **kw) + + +def codes(rep, level=None): + return sorted(f['code'] for f in rep['findings'] if level is None or f['level'] == level) + + +class FedCase(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.fed = Fed(self.tmp.name) + + def tearDown(self): + self.tmp.cleanup() + + +class CleanFederationTests(FedCase): + def test_clean_federation_has_no_block_and_is_not_vacuous(self): + self.fed.build() + rep = self.fed.crawl() + self.assertEqual(codes(rep, 'BLOCK'), []) + self.assertEqual(rep['blocking'], 0) + self.assertEqual({r['repository'] for r in rep['repositories'] if r['resolved']}, + {'fed/ws', 'fed/a', 'fed/b', 'fed/reg'}) + self.assertEqual(rep['stats']['registry_artifacts_verified'], 1) + self.assertEqual(rep['stats']['lean_shared_names'], 3) # Fed.t, Fed.f, Fed.S (private p excluded) + self.assertEqual(rep['stats']['lean_files'], 2) + + def test_cli_exit_status(self): + self.fed.build() + out = os.path.join(self.tmp.name, 'r.json') + r = subprocess.run([sys.executable, '-B', str(TOOL / 'crawl.py'), '--seed', 'fed/ws', '--search', self.tmp.name, + '--json', out], capture_output=True, env=ENV) + self.assertEqual(r.returncode, 0, r.stdout + r.stderr) + with open(out) as fh: + self.assertEqual(json.load(fh)['blocking'], 0) + self.fed.commit('b', {'Copy/A.lean': LEAN_A.replace('n + 0 = n', '0 + n = n')}) + self.fed.pins['b'] = sh(self.fed.repo('b'), 'rev-parse', 'HEAD') + self.fed.write_seed() + r = subprocess.run([sys.executable, '-B', str(TOOL / 'crawl.py'), '--seed', 'fed/ws', '--search', self.tmp.name], + capture_output=True, env=ENV) + self.assertEqual(r.returncode, 1, r.stdout + r.stderr) + self.assertIn(b'BLOCK LEAN-DRIFT', r.stdout) + r = subprocess.run([sys.executable, '-B', str(TOOL / 'crawl.py'), '--seed', 'fed/nope', '--search', self.tmp.name], + capture_output=True, env=ENV) + self.assertEqual(r.returncode, 2) + + +class LeanDriftTests(FedCase): + def drift(self, b_lean): + self.fed.build(b_lean=b_lean) + return self.fed.crawl() + + def test_changed_theorem_statement_blocks(self): + rep = self.drift(LEAN_A.replace('n + 0 = n', '0 + n = n')) + self.assertEqual(codes(rep, 'BLOCK'), ['LEAN-DRIFT']) + f = [f for f in rep['findings'] if f['code'] == 'LEAN-DRIFT'][0] + self.assertEqual(f['name'], 'Fed.t') + self.assertEqual(len(f['variants']), 2) + + def test_changed_definition_value_blocks(self): + rep = self.drift(LEAN_A.replace('def f : Nat := 3', 'def f : Nat := 4')) + self.assertEqual([f['name'] for f in rep['findings'] if f['code'] == 'LEAN-DRIFT'], ['Fed.f']) + + def test_changed_structure_field_blocks(self): + rep = self.drift(LEAN_A.replace(' y : Nat', ' y : Int')) + self.assertEqual([f['name'] for f in rep['findings'] if f['code'] == 'LEAN-DRIFT'], ['Fed.S']) + + def test_changed_kind_blocks(self): + rep = self.drift(LEAN_A.replace('def f : Nat := 3', 'abbrev f : Nat := 3')) + self.assertEqual([f['name'] for f in rep['findings'] if f['code'] == 'LEAN-DRIFT'], ['Fed.f']) + + def test_proof_comment_and_layout_changes_do_not_block(self): + b = LEAN_A.replace(':= by simp', ':= by\n omega -- different proof').replace( + 'theorem t (n : Nat)', 'theorem t -- the statement\n (n : Nat) /- note -/') + rep = self.drift(b) + self.assertEqual(codes(rep, 'BLOCK'), []) + + def test_private_names_are_not_compared(self): + rep = self.drift(LEAN_A.replace('private def p : Nat := 1', 'private def p : Nat := 2')) + self.assertEqual(codes(rep, 'BLOCK'), []) + self.assertEqual(rep['stats']['lean_shared_names'], 3) + + def test_differently_namespaced_names_are_not_compared(self): + rep = self.drift(LEAN_A.replace('namespace Fed', 'namespace Other').replace('end Fed', 'end Other') + .replace('def f : Nat := 3', 'def f : Nat := 9')) + self.assertEqual(codes(rep, 'BLOCK'), []) + self.assertEqual(rep['stats']['lean_shared_names'], 0) + + def test_lean_syntax_error_blocks(self): + rep = self.drift(LEAN_A + '\n/- never closed\n') + self.assertIn('LEAN-SYNTAX', codes(rep, 'BLOCK')) + + def test_override_tests_a_candidate_head(self): + self.fed.build() + cand = self.fed.commit('b', {'Copy/A.lean': LEAN_A.replace('def f : Nat := 3', 'def f : Nat := 5')}) + sh(self.fed.repo('b'), 'update-ref', 'refs/remotes/origin/main', self.fed.pins['b']) + self.assertEqual(codes(self.fed.crawl(), 'BLOCK'), []) + rep = self.fed.crawl(overrides={'fed/b': cand}) + self.assertEqual(codes(rep, 'BLOCK'), ['LEAN-DRIFT']) + + def test_tips_mode_reads_default_tips(self): + self.fed.build() + self.fed.commit('b', {'Copy/A.lean': LEAN_A.replace('def f : Nat := 3', 'def f : Nat := 5')}) + self.assertEqual(codes(self.fed.crawl(), 'BLOCK'), []) + self.assertEqual(codes(self.fed.crawl(at='tips'), 'BLOCK'), ['LEAN-DRIFT']) + + +class PinTests(FedCase): + def test_gitlink_disagreeing_with_pins_blocks(self): + self.fed.build() + other = self.fed.commit('b', {'z': 'z'}) + self.fed.write_seed(gitlinks=dict(self.fed.pins, b=other)) + self.assertIn('PIN-SOURCES', codes(self.fed.crawl(), 'BLOCK')) + + def test_submodule_without_pin_blocks(self): + self.fed.build() + self.fed.write_seed(pins={k: v for k, v in self.fed.pins.items() if k != 'b'}, gitlinks=self.fed.pins) + self.assertIn('PIN-SOURCES', codes(self.fed.crawl(), 'BLOCK')) + + def test_pinned_but_unlisted_blocks(self): + self.fed.build() + self.fed.write_seed(listed=['a', 'reg']) + self.assertIn('PIN-SOURCES', codes(self.fed.crawl(), 'BLOCK')) + + def test_gitlink_without_gitmodules_entry_blocks(self): + self.fed.build() + d = self.fed.repo('ws') + sh(d, 'update-index', '--add', '--cacheinfo', '160000,%s,vendor/stray' % self.fed.pins['b']) + sh(d, 'commit', '-q', '-m', 'stray') + sh(d, 'update-ref', 'refs/remotes/origin/main', sh(d, 'rev-parse', 'HEAD')) + rep = self.fed.crawl() + self.assertEqual([f['message'] for f in rep['findings'] if f['level'] == 'BLOCK'], + ['gitlink vendor/stray has no .gitmodules entry']) + + def test_missing_pin_blocks(self): + self.fed.build() + self.fed.write_seed(pins=dict(self.fed.pins, b='0' * 39 + '1')) + self.assertIn('PIN-MISSING', codes(self.fed.crawl(), 'BLOCK')) + + def test_pin_off_the_default_line_blocks(self): + self.fed.build() + d = self.fed.repo('b') + sh(d, 'checkout', '-q', '-b', 'side') + side = self.fed.commit('b', {'s': 's'}) + sh(d, 'checkout', '-q', 'main') + sh(d, 'update-ref', 'refs/remotes/origin/main', self.fed.pins['b']) + self.fed.write_seed(pins=dict(self.fed.pins, b=side)) + self.assertIn('PIN-OFFLINE', codes(self.fed.crawl(), 'BLOCK')) + + def test_stale_pin_is_info_only(self): + self.fed.build() + self.fed.commit('b', {'later': 'x'}) + rep = self.fed.crawl() + self.assertEqual(codes(rep, 'BLOCK'), []) + self.assertEqual(codes(rep, 'INFO'), ['PIN-STALE']) + + def test_shallow_clone_cannot_decide_ancestry(self): + self.fed.build() + self.fed.commit('b', {'later': 'x'}) + src = self.fed.repo('b') + shutil.move(str(src), str(self.fed.base / 'b-full')) + subprocess.run(['git', 'clone', '-q', '--depth', '1', '--no-local', 'file://%s' % (self.fed.base / 'b-full'), + str(src)], check=True, env=ENV, capture_output=True) + sh(src, 'remote', 'set-url', 'origin', 'https://github.com/fed/b.git') + sh(src, 'fetch', '-q', '--depth', '1', 'file://%s' % (self.fed.base / 'b-full'), self.fed.pins['b']) + sh(src, 'update-ref', 'refs/remotes/origin/main', sh(src, 'rev-parse', 'HEAD')) + shutil.move(str(self.fed.base / 'b-full'), self.tmp.name + '-unused') + try: + msgs = [f['message'] for f in self.fed.crawl()['findings'] if f['code'] == 'PIN-OFFLINE'] + # a shallow clone cannot show ancestry; saying "not an ancestor" would be untrue (A7) + self.assertEqual(len(msgs), 1) + self.assertIn('shallow clone', msgs[0]) + finally: + shutil.rmtree(self.tmp.name + '-unused') + + def test_unresolved_repository_blocks_unless_opt_in(self): + self.fed.build() + shutil.move(str(self.fed.repo('b')), self.tmp.name + '-moved') + try: + self.assertIn('UNRESOLVED', codes(self.fed.crawl(), 'BLOCK')) + # the seed itself still has b's gitlink; mark b opt-in + shutil.move(self.tmp.name + '-moved', str(self.fed.base / 'b')) + self.fed.write_seed(update='b') + shutil.move(str(self.fed.base / 'b'), self.tmp.name + '-moved') + rep = self.fed.crawl() + self.assertNotIn('UNRESOLVED', codes(rep, 'BLOCK')) + self.assertIn('UNRESOLVED', codes(rep, 'INFO')) + finally: + if os.path.exists(self.tmp.name + '-moved'): + shutil.rmtree(self.tmp.name + '-moved') + + def test_malformed_pins_json_blocks(self): + self.fed.build() + self.fed.write_seed(extra={'pins.json': '{"repos": ['}) + self.assertIn('MALFORMED', codes(self.fed.crawl(), 'BLOCK')) + + +class RegistryTests(FedCase): + def rebuild(self, **change): + self.fed.build() + self.fed.registry['artifacts'][0].update(change) + self.fed.pins['reg'] = self.fed.commit('reg', {'registry.json': json.dumps(self.fed.registry)}) + self.fed.write_seed() + return self.fed.crawl() + + def test_wrong_digest_blocks(self): + self.assertIn('REGISTRY-BYTES', codes(self.rebuild(sha256='0' * 64), 'BLOCK')) + + def test_wrong_size_blocks(self): + self.assertIn('REGISTRY-BYTES', codes(self.rebuild(bytes=9), 'BLOCK')) + + def test_absent_path_blocks(self): + self.assertIn('REGISTRY-BYTES', codes(self.rebuild(path='data/none.txt'), 'BLOCK')) + + def test_missing_commit_blocks(self): + self.assertIn('PIN-MISSING', codes(self.rebuild(commit='1' * 40), 'BLOCK')) + + def test_evolved_artifact_is_info_only(self): + self.fed.build() + self.fed.pins['a'] = self.fed.commit('a', {'data/x.txt': 'payload v2\n'}) + self.fed.write_seed() + rep = self.fed.crawl() + self.assertEqual(codes(rep, 'BLOCK'), []) + self.assertIn('REGISTRY-EVOLVED', codes(rep, 'INFO')) + + def test_observed_input_blob_difference_is_info(self): + self.fed.build() + self.fed.registry['note'] = 'changed' + self.fed.commit('reg', {'registry.json': json.dumps(self.fed.registry)}) + rep = self.fed.crawl(at='tips') + self.assertIn('INPUT-OBSERVED', codes(rep, 'INFO')) + self.assertEqual(codes(rep, 'BLOCK'), []) + + +class TopologyTests(FedCase): + def test_added_repository_is_crawled_without_code_change(self): + self.fed.build() + self.fed.pins['c'] = self.fed.commit('c', {'lakefile.toml': 'name = "c"\n', 'lean-toolchain': 'v4.0.0\n', + 'C.lean': LEAN_A.replace('def f : Nat := 3', 'def f : Nat := 7')}) + self.fed.members.append('c') + self.fed.write_seed() + rep = self.fed.crawl() + self.assertIn('fed/c', {r['repository'] for r in rep['repositories'] if r['resolved']}) + self.assertEqual([f['name'] for f in rep['findings'] if f['code'] == 'LEAN-DRIFT'], ['Fed.f']) + + def test_removed_repository_is_not_crawled(self): + self.fed.build() + self.fed.members.remove('b') + del self.fed.pins['b'] + self.fed.write_seed() + rep = self.fed.crawl() + self.assertNotIn('fed/b', {r['repository'] for r in rep['repositories']}) + self.assertEqual(codes(rep, 'BLOCK'), []) + + def test_registry_artifact_repositories_join_the_crawl(self): + self.fed.build() + self.fed.members.remove('a') + del self.fed.pins['a'] + self.fed.write_seed() + rep = self.fed.crawl() + self.assertIn('fed/a', {r['repository'] for r in rep['repositories'] if r['resolved']}) + self.assertEqual(rep['stats']['registry_artifacts_verified'], 1) + + def test_lake_dependency_on_a_crawled_repository_is_followed(self): + self.fed.build() + manifest = {'packages': [{'type': 'git', 'url': 'https://github.com/fed/a', 'rev': '2' * 40, 'name': 'a'}]} + self.fed.pins['b'] = self.fed.commit('b', {'lake-manifest.json': json.dumps(manifest)}) + self.fed.write_seed() + rep = self.fed.crawl() + self.assertIn('LAKE-DEP', codes(rep, 'INFO')) + self.assertIn({'from': 'fed/b', 'to': 'fed/a', 'via': 'lake'}, rep['edges']) + + def test_unheld_repository_is_cloned_from_its_recorded_url(self): + self.fed.build() + remote = pathlib.Path(self.tmp.name + '-remote') / 'fed' / 'b' + remote.parent.mkdir(parents=True) + shutil.move(str(self.fed.repo('b')), str(remote)) + try: + self.fed.urls['b'] = 'file://%s' % remote + self.fed.write_seed() + self.assertIn('UNRESOLVED', codes(self.fed.crawl(), 'BLOCK')) + clones = pathlib.Path(self.tmp.name + '-remote') / 'clones' + clones.mkdir() + rep = self.fed.crawl(clone_into=str(clones)) + self.assertEqual(codes(rep, 'BLOCK'), []) + self.assertEqual(rep['stats']['lean_shared_names'], 3) + self.assertTrue((clones / 'fed__b').is_dir()) + finally: + shutil.rmtree(self.tmp.name + '-remote') + + def test_identity_normalization(self): + for u in ('https://github.com/Fed/A.git', 'git@github.com:fed/a.git', 'fed/a', + 'http://proxy@127.0.0.1:9/git/fed/a', 'https://github.com/fed/a/'): + self.assertEqual(crawl.repo_key(u), 'fed/a') + + +class LeanDeclTests(unittest.TestCase): + def names(self, text): + return [(d['name'], d['kind']) for d in lean_decls.declarations(text)] + + def test_namespaces_sections_and_root(self): + text = 'namespace A.B\nsection S\ntheorem x : True := trivial\nend S\ndef _root_.y : Nat := 1\nend A.B\ndef z := 2\n' + self.assertEqual(self.names(text), [('A.B.x', 'theorem'), ('y', 'def'), ('z', 'def')]) + + def test_unbalanced_scopes_raise(self): + for text in ('namespace A\nend B\n', 'end A\n', 'section\nend X\n'): + with self.subTest(text=text), self.assertRaises(lean_decls.LeanSyntaxError): + lean_decls.declarations(text) + + def test_header_stops_at_top_level_assign_and_line_leading_bar(self): + ds = lean_decls.declarations('theorem a (h : |x| ≤ 1 := 2) : |x| ≤ 1 := by simp\n' + 'def g : Nat → Nat\n | 0 => 1\n | n+1 => n\n') + self.assertEqual(ds[0]['header'], '( h : | x | ≤ 1 := 2 ) : | x | ≤ 1') + self.assertEqual(ds[1]['header'], ': Nat → Nat') + self.assertIn('| 0 = > 1', ds[1]['interface']) + + def test_theorem_interface_excludes_proof_definition_includes_value(self): + t, d = lean_decls.declarations('theorem t : 1 = 1 := rfl\ndef d : Nat := 7\n') + self.assertEqual(t['interface'], ': 1 = 1') + self.assertEqual(d['interface'], ': Nat := 7') + + def test_comments_and_strings(self): + ds = lean_decls.declarations('-- theorem fake : False\n/- def fake2 := 1 -/\ndef s := "theorem fake3 : False"\n') + self.assertEqual([d['name'] for d in ds], ['s']) + + def test_modifiers_attributes_and_anonymous_instance(self): + ds = lean_decls.declarations('@[simp] protected noncomputable def a := 1\ninstance : Inhabited Nat := ⟨0⟩\n' + 'instance (priority := low) named : Inhabited Int := ⟨0⟩\nprivate theorem p : True := trivial\n') + self.assertEqual([(d['name'], d['private'], d['modifiers']) for d in ds], + [('a', False, ['noncomputable', 'protected']), ('named', False, []), ('p', True, [])]) + + def test_malformed_raise(self): + for text in ('/- open', 'def s := "open', 'def «open := 1', 'theorem : True := trivial', 'namespace\n'): + with self.subTest(text=text), self.assertRaises(lean_decls.LeanSyntaxError): + lean_decls.declarations(text) + + +# Each mutant: (label, exact source substring, replacement, file, designated test). +MUTANTS = [ + ('theorem statement ignored', "'interface': header if dkind in STATEMENT_ONLY else", "'interface': '' if dkind in STATEMENT_ONLY else", + 'lean_decls.py', 'LeanDriftTests.test_changed_theorem_statement_blocks'), + ('definition value ignored', "else ' '.join(hdr + body)", "else header", 'lean_decls.py', + 'LeanDriftTests.test_changed_definition_value_blocks'), + ('kind ignored', "variants.setdefault((l['kind'], l['interface']), [])", "variants.setdefault(('', l['interface']), [])", + 'crawl.py', 'LeanDriftTests.test_changed_kind_blocks'), + ('drift downgraded', "self.add(BLOCK, 'LEAN-DRIFT'", "self.add(INFO, 'LEAN-DRIFT'", 'crawl.py', + 'LeanDriftTests.test_changed_theorem_statement_blocks'), + ('private compared', " if d['private']:\n continue\n", "", 'crawl.py', + 'LeanDriftTests.test_private_names_are_not_compared'), + ('namespace dropped', "'.'.join(current_ns() + [name])", "name", 'lean_decls.py', + 'LeanDriftTests.test_differently_namespaced_names_are_not_compared'), + ('comments kept', " fresh = first\n continue\n if text.startswith('/-', i):", + " yield 'sym', text[i:i + 2], start_line, first\n fresh = first\n continue\n if text.startswith('/-', i):", + 'lean_decls.py', 'LeanDriftTests.test_proof_comment_and_layout_changes_do_not_block'), + ('lean syntax swallowed', "self.add(BLOCK, 'LEAN-SYNTAX', str(exc)", "self.add(INFO, 'LEAN-SYNTAX', str(exc)", 'crawl.py', + 'LeanDriftTests.test_lean_syntax_error_blocks'), + ('unbalanced end accepted', " if sparts != parts:\n", " if False:\n", 'lean_decls.py', + 'LeanDeclTests.test_unbalanced_scopes_raise'), + ('bar ends every header', "(k == 'sym' and t == '|' and fst)", "(k == 'sym' and t == '|')", 'lean_decls.py', + 'LeanDeclTests.test_header_stops_at_top_level_assign_and_line_leading_bar'), + ('depth ignored', " if depth == 0:\n if k == 'ident' and t in COMMANDS and not", + " if True:\n if k == 'ident' and t in COMMANDS and not", 'lean_decls.py', + 'LeanDeclTests.test_header_stops_at_top_level_assign_and_line_leading_bar'), + ('override ignored', " if key in self.overrides:\n", " if False:\n", 'crawl.py', + 'LeanDriftTests.test_override_tests_a_candidate_head'), + ('tips mode ignored', "elif self.at == 'pins' and key in self.pins", "elif key in self.pins", 'crawl.py', + 'LeanDriftTests.test_tips_mode_reads_default_tips'), + ('gitlink unchecked', "if 'gitlink' in rec and 'pins' in rec and rec['gitlink'] != rec['pins']:", + "if False:", 'crawl.py', 'PinTests.test_gitlink_disagreeing_with_pins_blocks'), + ('gitmodules/pins membership unchecked', "if gm is not None and pins is not None and ('gitmodules' in have) != ('pins' in have):", + "if False:", 'crawl.py', 'PinTests.test_submodule_without_pin_blocks'), + ('listing unchecked', "if reg is not None and (have & {'gitmodules', 'pins'}) and 'listed' not in have:", "if False:", + 'crawl.py', 'PinTests.test_pinned_but_unlisted_blocks'), + ('stray gitlink unchecked', " if typ == 'commit' and not any(", " if False and not any(", 'crawl.py', + 'PinTests.test_gitlink_without_gitmodules_entry_blocks'), + ('missing pin passes', "self.add(BLOCK, 'PIN-MISSING', 'pinned commit", "self.add(INFO, 'PIN-MISSING', 'pinned commit", 'crawl.py', + 'PinTests.test_missing_pin_blocks'), + ('ancestry unchecked', " elif not repo.is_ancestor(pin, tip):", " elif False:", 'crawl.py', + 'PinTests.test_pin_off_the_default_line_blocks'), + ('stale pin blocks', "self.add(INFO, 'PIN-STALE'", "self.add(BLOCK, 'PIN-STALE'", 'crawl.py', 'PinTests.test_stale_pin_is_info_only'), + ('shallow trusted', " if repo.shallow:\n", " if False:\n", 'crawl.py', + 'PinTests.test_shallow_clone_cannot_decide_ancestry'), + ('unresolved passes', "self.add(INFO if key in self.optional else BLOCK, 'UNRESOLVED'", "self.add(INFO, 'UNRESOLVED'", 'crawl.py', + 'PinTests.test_unresolved_repository_blocks_unless_opt_in'), + ('opt-in ignored', "self.add(INFO if key in self.optional else BLOCK, 'UNRESOLVED'", "self.add(BLOCK, 'UNRESOLVED'", 'crawl.py', + 'PinTests.test_unresolved_repository_blocks_unless_opt_in'), + ('malformed json passes', "self.add(BLOCK, 'MALFORMED', '%s is not valid JSON", "self.add(INFO, 'MALFORMED', '%s is not valid JSON", 'crawl.py', + 'PinTests.test_malformed_pins_json_blocks'), + ('digest unchecked', "if len(data) != size or hashlib.sha256(data).hexdigest() != digest:", "if len(data) != size:", 'crawl.py', + 'RegistryTests.test_wrong_digest_blocks'), + ('size unchecked', "if len(data) != size or hashlib.sha256(data).hexdigest() != digest:", "if hashlib.sha256(data).hexdigest() != digest:", 'crawl.py', + 'RegistryTests.test_wrong_size_blocks'), + ('absent artifact passes', " if data is None:\n self.add(BLOCK, 'REGISTRY-BYTES'", " if data is None:\n self.add(INFO, 'REGISTRY-BYTES'", 'crawl.py', + 'RegistryTests.test_absent_path_blocks'), + ('artifact commit unchecked', "self.add(BLOCK, 'PIN-MISSING', 'artifact %s", "self.add(INFO, 'PIN-MISSING', 'artifact %s", 'crawl.py', + 'RegistryTests.test_missing_commit_blocks'), + ('evolution blocks', "self.add(INFO, 'REGISTRY-EVOLVED'", "self.add(BLOCK, 'REGISTRY-EVOLVED'", 'crawl.py', + 'RegistryTests.test_evolved_artifact_is_info_only'), + ('observed blob unchecked', "if spec.get('observed_blob') and (ent is None or ent[2] != spec['observed_blob']):", "if False:", 'crawl.py', + 'RegistryTests.test_observed_input_blob_difference_is_info'), + ('registry not followed', " self.check_artifacts(repo, ref, spec['path'], doc)", " pass", 'crawl.py', + 'TopologyTests.test_registry_artifact_repositories_join_the_crawl'), + ('lake deps not followed', " if isinstance(pkg, dict) and pkg.get('type') == 'git'", " if False and isinstance(pkg, dict)", 'crawl.py', + 'TopologyTests.test_lake_dependency_on_a_crawled_repository_is_followed'), + ('clone ignored', " if gitdir is None and self.clone_into:\n", " if False:\n", 'crawl.py', + 'TopologyTests.test_unheld_repository_is_cloned_from_its_recorded_url'), + ('case-sensitive identity', " return ('%s/%s' % (m.group(1), m.group(2))).lower()", " return '%s/%s' % (m.group(1), m.group(2))", 'crawl.py', + 'TopologyTests.test_identity_normalization'), + ('exit ignores blocks', " return 1 if rep['blocking'] else 0", " return 0", 'crawl.py', 'CleanFederationTests.test_cli_exit_status'), +] + + +class ScannerMutationTests(unittest.TestCase): + """A8: each mutant must make its designated test fail by assertion, nothing else.""" + + def run_designated(self, tool_dir, test): + env = dict(ENV, CBZ_DRIFT_DIR=str(tool_dir), PYTHONDONTWRITEBYTECODE='1') + return subprocess.run([sys.executable, '-B', '-m', 'unittest', 'test_cbz_drift.%s' % test], + cwd=str(pathlib.Path(__file__).parent), capture_output=True, env=env, timeout=600) + + def copy_tool(self, base): + dst = pathlib.Path(base) / 'cbz_drift' + shutil.copytree(TOOL, dst, ignore=shutil.ignore_patterns('__pycache__')) + return dst + + def test_harness_control_every_designated_test_passes_unmutated(self): + with tempfile.TemporaryDirectory() as tmp: + dst = self.copy_tool(tmp) + for test in sorted({m[4] for m in MUTANTS}): + r = self.run_designated(dst, test) + self.assertEqual(r.returncode, 0, '%s: %s' % (test, r.stderr.decode()[-2000:])) + self.assertRegex(r.stderr.decode(), r'Ran 1 test') + + def test_every_mutant_is_killed_by_its_designated_assertion(self): + survivors = [] + for label, old, new, fname, test in MUTANTS: + with self.subTest(mutant=label), tempfile.TemporaryDirectory() as tmp: + dst = self.copy_tool(tmp) + src = (dst / fname).read_text() + self.assertEqual(src.count(old), 1, 'mutant %r does not apply exactly once' % label) + (dst / fname).write_text(src.replace(old, new)) + py_compile.compile(str(dst / fname), doraise=True) # a syntax error cannot count as a kill + r = self.run_designated(dst, test) + err = r.stderr.decode() + # failures=1 with no errors: the designated assertion failed; an exception would count as an error + killed = r.returncode != 0 and re.search(r'FAILED \(failures=\d+\)\s*$', err) + if not killed: + survivors.append((label, err[-1500:])) + self.assertEqual(survivors, [], 'mutants survived or failed for the wrong reason: %s' % survivors) + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/cbz_drift/README.md b/tools/cbz_drift/README.md new file mode 100644 index 000000000..b52ba35bb --- /dev/null +++ b/tools/cbz_drift/README.md @@ -0,0 +1,93 @@ +# Federation drift crawler + +CBZ-0 addendum tool: the dynamic federation drift crawler. It uses the standard library +only. Its gate is G7 (pins consistent), extended to interface consistency. + +``` +python3 -B -S tools/cbz_drift/crawl.py --seed d6g8k5htny-coder/Universal-Law-Workspace \ + --search DIR [--search DIR2] [--clone-into DIR] [--fetch] [--at pins|tips] \ + [--override OWNER/NAME=REV] [--seed-ref REV] [--json REPORT] +``` + +Exit status: 0 no BLOCK finding, 1 at least one BLOCK, 2 usage or internal error. + +## What it discovers + +Only the seed is named on the command line. The crawler reads the seed's +`.gitmodules`, gitlinks, `pins.json` and `workspace/repositories.json`, then: + +- each registry named under `canonical_inputs` (today the meta-framework + `registry.json`), resolving artifact `repository` keys through the registry's own map; +- every Lean package (`lakefile.lean` / `lakefile.toml`) in every reached repository; +- every `lake-manifest.json` dependency whose URL is a reachable repository. + +So a rename, addition or removal in those records changes the crawl with no code +change. `--search` directories are scanned for clones by their `origin` URL. With +`--clone-into`, a discovered repository that no search directory holds is cloned, so +a CI job needs only the seed. A repository it still cannot read is a BLOCK finding, +never a skip. The one exception is a repository its own records mark opt-in +(`update = none` / `opt_in`), which is INFO. + +## What it checks + +The rule: **two records that claim the same identity must agree (BLOCK); a record may +lag a moving tip (INFO).** + +| Code | Level | Meaning | +|---|---|---| +| `PIN-SOURCES` | BLOCK | gitlink, `.gitmodules`, `pins.json` and `repositories.json` disagree, or one of them lacks a repository the others list | +| `PIN-MISSING` | BLOCK | a pinned or recorded commit is absent (`--fetch` consults origin) | +| `PIN-OFFLINE` | BLOCK | a pin is not an ancestor of its repository's default tip; on a shallow clone it says ancestry cannot be decided | +| `PIN-STALE` | INFO | a pin is behind the default tip | +| `UNRESOLVED` | BLOCK | a discovered repository cannot be read | +| `REGISTRY-BYTES` | BLOCK | a registry artifact's size or SHA-256 differs at its recorded commit, or the path is absent | +| `REGISTRY-EVOLVED` | INFO | the artifact differs, or is gone, at the crawled ref | +| `INPUT-OBSERVED` | INFO | a canonical input's recorded blob differs at the crawled ref | +| `LEAN-DRIFT` | BLOCK | one fully qualified Lean declaration has different interfaces in two crawled locations | +| `LEAN-SYNTAX` | BLOCK | a Lean file cannot be lexed, or its `namespace`/`section`/`end` do not balance | +| `LAKE-DEP` | INFO | a lake dependency on a crawled repository pins a different rev | +| `TOOLCHAIN` | INFO | Lean packages that share declarations use different `lean-toolchain`s | +| `MALFORMED` | BLOCK | a manifest exists but cannot be parsed | + +`--at pins` (the default) reads each pinned repository at its pin, which is the +federation snapshot. `--at tips` reads default tips. `--override` puts a candidate head +in place of one repository's ref: that is how a PR is tested against the rest of the +federation (see `.github/workflows/cbz-federation-drift.yml`). + +## Domain and limits (B-006) + +`lean_decls.py` extracts declarations written literally in source: +- `theorem`, `lemma`, `def`, `abbrev`, named `instance`, `axiom`, `opaque`, `structure`, + `class` and `inductive`; +- with their modifiers, qualified by `namespace` / `section`. + +The compared **interface** is: +- for a theorem, lemma, axiom or opaque: its statement (proofs are irrelevant, and + opaque values are hidden); +- for anything definition-like: statement plus value, because the value is part of + its meaning. + +Comments are removed and whitespace is normalized. Equal interfaces mean equal source +text, not equal elaborated terms. The extractor does not elaborate, expand notation or +macros, or see generated declarations. `private` names are file-local and are never +compared. Two copies that differ only by an alpha-renamed binder are reported as drift; +that is the safe direction, since named arguments are part of the interface. Kernel +closure and axiom dependencies stay with G2–G4. + +## Verification + +`tests/test_cbz_drift.py` runs every check against a synthetic git federation built in +a temporary directory, covering both positive and negative cases. That includes: +- topology changes (added, removed and registry-only repositories, and lake edges); +- shallow clones; +- clone-on-demand; +- candidate-head overrides. + +`ScannerMutationTests` applies 35 source mutants. Each one must be killed by its own +designated test, failing by assertion (`FAILED (failures=N)` with no errors). Every +mutant must apply exactly once and must compile, and the unmutated copy must pass +every designated test, as the harness control. + +``` +cd tests && python3 -B -m unittest test_cbz_drift && python3 -B -O -m unittest test_cbz_drift +``` diff --git a/tools/cbz_drift/crawl.py b/tools/cbz_drift/crawl.py new file mode 100644 index 000000000..ed6b8f706 --- /dev/null +++ b/tools/cbz_drift/crawl.py @@ -0,0 +1,569 @@ +#!/usr/bin/env python3 +"""Federation drift crawler (CBZ-0 addendum: dynamic federation drift crawler). + +Discovers the federation at run time from a seed repository and blocks on drift between +records that claim the same identity. Nothing about the topology is hardcoded: targets +come from the seed's `.gitmodules`, gitlinks, `pins.json` and +`workspace/repositories.json`, from any repository registry those name under +`canonical_inputs` (artifact `repository` keys are resolved through the registry's own +`repositories` map), and from every `lake-manifest.json` dependency whose URL resolves to +a repository the crawl can reach. A rename, addition or removal in those records changes +the crawl with no code change. + +Findings. BLOCK means two records that claim the same identity disagree, or something the +crawl must read is missing or malformed; the exit status is then 1. INFO means a record +differs from a moving tip (a stale pin, an artifact that has evolved since its recorded +commit, different Lean toolchains); it never fails the run. + + PIN-SOURCES .gitmodules, gitlink, pins.json and repositories.json disagree BLOCK + PIN-MISSING a pinned commit is not present in its repository BLOCK + PIN-OFFLINE a pinned commit is not an ancestor of the repository's default BLOCK + PIN-STALE a pinned commit is behind the default tip INFO + UNRESOLVED a discovered repository cannot be read (opt-in ones are INFO) BLOCK + REGISTRY-BYTES a registry artifact's bytes or SHA-256 differ at its commit BLOCK + REGISTRY-EVOLVED the artifact differs (or is gone) at the crawled ref INFO + INPUT-OBSERVED a canonical input's observed blob differs at the crawled ref INFO + LEAN-DRIFT one fully qualified Lean declaration has different interfaces BLOCK + in two crawled locations (see lean_decls for the exact domain) + LEAN-SYNTAX a Lean file could not be lexed or its scopes do not balance BLOCK + LAKE-DEP a lake dependency on a crawled repository pins another rev INFO + TOOLCHAIN Lean packages that share declarations use different toolchains INFO + MALFORMED a manifest exists but cannot be parsed BLOCK + +Repositories are read from local git object stores only, found by matching each +candidate directory's `origin` URL. `--fetch` additionally runs `git fetch` for missing +commits, and `--clone-into DIR` clones a discovered repository that no search directory +holds (so a CI job needs only the seed). The crawl reads each repository at one ref: the seed at `--seed-ref`, every +pinned repository at its pin (`--at pins`, the default) or at its default tip +(`--at tips`), and `--override NAME=REV` replaces one repository's ref (to test a +candidate head against the rest of the federation). + +Standard library only. Exit: 0 no BLOCK, 1 BLOCK findings, 2 usage or internal error. +""" +from __future__ import annotations + +import argparse +import collections +import hashlib +import json +import os +import pathlib +import re +import subprocess +import sys + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +import lean_decls # noqa: E402 + +BLOCK, INFO = 'BLOCK', 'INFO' + + +class CrawlError(RuntimeError): + pass + + +def repo_key(url_or_name): + """Normalize a GitHub-style URL or owner/name to a lowercase 'owner/name' key.""" + s = url_or_name.strip() + s = re.sub(r'\.git/?$', '', s).rstrip('/') + m = re.search(r'(?:^|[:/])([^/:@\s]+)/([^/:@\s]+)$', s) + if m: + return ('%s/%s' % (m.group(1), m.group(2))).lower() + raise CrawlError('cannot read a repository identity from %r' % url_or_name) + + +def git(gitdir, *args, check=True, data=None): + r = subprocess.run(['git', '-C', str(gitdir), *args], input=data, capture_output=True) + if check and r.returncode: + raise CrawlError('git %s failed in %s: %s' % (' '.join(args), gitdir, r.stderr.decode(errors='replace').strip())) + return r + + +class Repo: + def __init__(self, key, gitdir, fetch=False): + self.key, self.gitdir, self.fetch = key, gitdir, fetch + self._blob_cache = {} + self.shallow = git(gitdir, 'rev-parse', '--is-shallow-repository').stdout.decode().strip() == 'true' + if self.shallow and fetch: + git(gitdir, 'fetch', '-q', '--unshallow', 'origin', check=False) + self.shallow = git(gitdir, 'rev-parse', '--is-shallow-repository').stdout.decode().strip() == 'true' + + def has_commit(self, rev): + if git(self.gitdir, 'cat-file', '-e', rev + '^{commit}', check=False).returncode == 0: + return True + if self.fetch and re.fullmatch(r'[0-9a-f]{40}', rev): + git(self.gitdir, 'fetch', '-q', 'origin', rev, check=False) + return git(self.gitdir, 'cat-file', '-e', rev + '^{commit}', check=False).returncode == 0 + return False + + def resolve(self, rev): + return git(self.gitdir, 'rev-parse', '--verify', '-q', rev + '^{commit}').stdout.decode().strip() + + def default_tip(self): + r = git(self.gitdir, 'symbolic-ref', '-q', 'refs/remotes/origin/HEAD', check=False) + ref = r.stdout.decode().strip() if r.returncode == 0 else '' + for cand in ([ref] if ref else []) + ['refs/remotes/origin/main', 'refs/remotes/origin/master', 'HEAD']: + r = git(self.gitdir, 'rev-parse', '--verify', '-q', cand + '^{commit}', check=False) + if r.returncode == 0: + return r.stdout.decode().strip() + raise CrawlError('no default tip in %s' % self.gitdir) + + def where(self): + if self.fetch: + return ' (also not fetchable from origin)' + return ' (local object store%s; rerun with --fetch to consult origin)' % (', shallow clone' if self.shallow else '') + + def is_ancestor(self, a, b): + return git(self.gitdir, 'merge-base', '--is-ancestor', a, b, check=False).returncode == 0 + + def tree(self, rev): + """{path: (mode, type, sha)} for every entry at rev, recursively.""" + out = git(self.gitdir, 'ls-tree', '-r', '-z', '--full-tree', rev).stdout.decode() + entries = {} + for rec in out.split('\0'): + if rec: + meta, path = rec.split('\t', 1) + mode, typ, sha = meta.split() + entries[path] = (mode, typ, sha) + return entries + + def blob(self, sha): + if sha not in self._blob_cache: + self._blob_cache[sha] = git(self.gitdir, 'cat-file', 'blob', sha).stdout + return self._blob_cache[sha] + + def read(self, rev, path): + r = git(self.gitdir, 'cat-file', 'blob', '%s:%s' % (rev, path), check=False) + return r.stdout if r.returncode == 0 else None + + +def find_local_repos(search_dirs): + """{key: gitdir} for git repositories directly inside each search directory.""" + found = {} + for d in search_dirs: + for child in sorted(pathlib.Path(d).iterdir()): + if not child.is_dir(): + continue + if git(child, 'rev-parse', '--git-dir', check=False).returncode: + continue + if git(child, 'rev-parse', '--show-toplevel', check=False).stdout.decode().strip() != str(child.resolve()): + continue + r = git(child, 'remote', 'get-url', 'origin', check=False) + if r.returncode == 0: + try: + found.setdefault(repo_key(r.stdout.decode()), child) + except CrawlError: + pass + return found + + +def parse_gitmodules(text): + mods, cur = {}, None + for raw in text.splitlines(): + line = raw.strip() + if not line or line[0] in '#;': + continue + m = re.fullmatch(r'\[submodule\s+"([^"]+)"\]', line) + if m: + cur = mods.setdefault(m.group(1), {}) + continue + m = re.fullmatch(r'([A-Za-z]+)\s*=\s*(.*)', line) + if m and cur is not None: + cur[m.group(1).lower()] = m.group(2).strip() + else: + raise CrawlError('unparsed .gitmodules line: %r' % raw) + return mods + + +class Crawl: + def __init__(self, local, at='pins', overrides=None, fetch=False, clone_into=None): + self.local, self.at, self.overrides, self.fetch = local, at, dict(overrides or {}), fetch + self.clone_into, self.urls = clone_into, {} + self.findings, self.repos, self.refs = [], {}, {} + self.pins, self.optional, self.edges = {}, set(), [] + self.stats = collections.Counter() + + def add(self, level, code, msg, **where): + self.findings.append(dict(where, level=level, code=code, message=msg)) + + def open(self, key, why): + if key in self.repos: + return self.repos[key] + gitdir = self.local.get(key) + if gitdir is None and self.clone_into: + gitdir = self.clone(key) + if gitdir is None: + self.repos[key] = None + self.add(INFO if key in self.optional else BLOCK, 'UNRESOLVED', + 'repository %s (%s) is not available locally' % (key, why), repo=key) + return None + self.repos[key] = Repo(key, gitdir, self.fetch) + return self.repos[key] + + def clone(self, key): + """Clone a discovered repository that no search directory holds; None if that fails.""" + url = self.urls.get(key) or 'https://github.com/%s.git' % key + dest = pathlib.Path(self.clone_into) / key.replace('/', '__') + if not dest.exists(): + r = subprocess.run(['git', 'clone', '-q', '--no-checkout', url, str(dest)], capture_output=True) + if r.returncode: + return None + try: + if repo_key(git(dest, 'remote', 'get-url', 'origin').stdout.decode()) != key: + return None + except CrawlError: + return None + self.local[key] = dest + return dest + + def ref_for(self, key, repo): + if key in self.refs: + return self.refs[key] + if key in self.overrides: + rev = self.overrides[key] + if not repo.has_commit(rev): + raise CrawlError('override %s=%s does not name a commit' % (key, rev)) + ref = repo.resolve(rev) + elif self.at == 'pins' and key in self.pins and repo.has_commit(self.pins[key]): + ref = self.pins[key] + else: + ref = repo.default_tip() + self.refs[key] = ref + return ref + + def json_at(self, repo, ref, path): + data = repo.read(ref, path) + if data is None: + return None + try: + return json.loads(data.decode('utf-8')) + except (UnicodeDecodeError, ValueError) as exc: + self.add(BLOCK, 'MALFORMED', '%s is not valid JSON: %s' % (path, exc), repo=repo.key, ref=ref, path=path) + return None + + # ------------------------------------------------------------------ topology + def seed(self, seed_key, seed_ref): + repo = self.open(seed_key, 'seed') + if repo is None: + raise CrawlError('seed repository %s is not available locally' % seed_key) + if seed_ref: + self.overrides.setdefault(seed_key, seed_ref) + ref = self.ref_for(seed_key, repo) + self.seed_key, self.seed_ref = seed_key, ref + tree = repo.tree(ref) + records = collections.defaultdict(dict) # key -> {source: value} + + gm = repo.read(ref, '.gitmodules') + if gm is not None: + try: + mods = parse_gitmodules(gm.decode('utf-8')) + except (CrawlError, UnicodeDecodeError) as exc: + self.add(BLOCK, 'MALFORMED', '.gitmodules: %s' % exc, repo=seed_key, ref=ref, path='.gitmodules') + mods = {} + for name, m in sorted(mods.items()): + if 'url' not in m or 'path' not in m: + self.add(BLOCK, 'MALFORMED', 'submodule %s lacks url or path' % name, repo=seed_key, path='.gitmodules') + continue + key = repo_key(m['url']) + self.urls.setdefault(key, m['url']) + records[key]['gitmodules'] = m['path'] + if m.get('update') == 'none': + self.optional.add(key) + ent = tree.get(m['path']) + if ent is None or ent[1] != 'commit': + self.add(BLOCK, 'PIN-SOURCES', 'submodule %s has no gitlink at %s' % (name, m['path']), + repo=seed_key, ref=ref, path=m['path']) + else: + records[key]['gitlink'] = ent[2] + for path, (mode, typ, sha) in sorted(tree.items()): + if typ == 'commit' and not any(r.get('gitmodules') == path for r in records.values()): + self.add(BLOCK, 'PIN-SOURCES', 'gitlink %s has no .gitmodules entry' % path, repo=seed_key, ref=ref, path=path) + + pins = self.json_at(repo, ref, 'pins.json') + if pins is not None: + if not isinstance(pins, dict) or not isinstance(pins.get('repos'), list): + self.add(BLOCK, 'MALFORMED', 'pins.json has no repos list', repo=seed_key, path='pins.json') + else: + for ent in pins['repos']: + try: + key = repo_key(ent['url']) + sha, path = ent['pinned_sha'], ent['path'] + self.urls.setdefault(key, ent['url']) + except (KeyError, TypeError, CrawlError) as exc: + self.add(BLOCK, 'MALFORMED', 'pins.json entry %r: %s' % (ent, exc), repo=seed_key, path='pins.json') + continue + if 'pins' in records[key]: + self.add(BLOCK, 'PIN-SOURCES', 'pins.json lists %s twice' % key, repo=seed_key, path='pins.json') + records[key]['pins'] = sha + records[key]['pins_path'] = path + if ent.get('opt_in'): + self.optional.add(key) + + reg = self.json_at(repo, ref, 'workspace/repositories.json') + inputs = {} + if reg is not None: + for ent in reg.get('repositories', []) if isinstance(reg, dict) else []: + try: + records[repo_key(ent['full_name'])]['listed'] = True + except (KeyError, TypeError, CrawlError) as exc: + self.add(BLOCK, 'MALFORMED', 'repositories.json entry %r: %s' % (ent, exc), repo=seed_key) + inputs = reg.get('canonical_inputs', {}) if isinstance(reg, dict) else {} + + for key, rec in sorted(records.items()): + if key == seed_key: + continue + srcs = [s for s in ('gitmodules', 'pins', 'listed') if s in rec] + have = set(srcs) + if gm is not None and pins is not None and ('gitmodules' in have) != ('pins' in have): + self.add(BLOCK, 'PIN-SOURCES', '%s is in %s but not in %s' % ( + key, 'gitmodules' if 'gitmodules' in have else 'pins.json', + 'pins.json' if 'gitmodules' in have else '.gitmodules'), repo=seed_key, target=key) + if reg is not None and (have & {'gitmodules', 'pins'}) and 'listed' not in have: + self.add(BLOCK, 'PIN-SOURCES', '%s is pinned but not listed in workspace/repositories.json' % key, + repo=seed_key, target=key) + if 'gitlink' in rec and 'pins' in rec and rec['gitlink'] != rec['pins']: + self.add(BLOCK, 'PIN-SOURCES', '%s: gitlink %s but pins.json %s' % (key, rec['gitlink'][:12], rec['pins'][:12]), + repo=seed_key, target=key) + if 'gitmodules' in rec and 'pins_path' in rec and rec['gitmodules'] != rec['pins_path']: + self.add(BLOCK, 'PIN-SOURCES', '%s: .gitmodules path %s but pins.json path %s' % (key, rec['gitmodules'], rec['pins_path']), + repo=seed_key, target=key) + pin = rec.get('pins') or rec.get('gitlink') + if pin: + self.pins[key] = pin + self.edges.append((seed_key, key, '+'.join(srcs))) + self.discovered = sorted(k for k in records if k != seed_key) + self.canonical_inputs = inputs + + def check_pins(self): + for key in self.discovered: + repo = self.open(key, 'listed by the seed') + if repo is None or key not in self.pins: + continue + pin = self.pins[key] + if not repo.has_commit(pin): + self.add(BLOCK, 'PIN-MISSING', 'pinned commit %s is not in %s%s' % (pin, key, repo.where()), repo=key, pin=pin) + continue + tip = repo.default_tip() + if pin == tip: + continue + if repo.shallow: + self.add(BLOCK, 'PIN-OFFLINE', 'cannot decide whether pin %s is on the default line: %s is a shallow clone ' + '(rerun with --fetch)' % (pin[:12], repo.gitdir), repo=key, pin=pin, tip=tip) + elif not repo.is_ancestor(pin, tip): + self.add(BLOCK, 'PIN-OFFLINE', 'pinned commit %s is not an ancestor of the default tip %s' % (pin[:12], tip[:12]), + repo=key, pin=pin, tip=tip) + else: + n = git(repo.gitdir, 'rev-list', '--count', '%s..%s' % (pin, tip)).stdout.decode().strip() + self.add(INFO, 'PIN-STALE', 'pin %s is %s commits behind the default tip %s' % (pin[:12], n, tip[:12]), + repo=key, pin=pin, tip=tip) + + # ------------------------------------------------------------------ registries + def check_registries(self): + for label, spec in sorted(self.canonical_inputs.items()): + if not isinstance(spec, dict) or 'repository' not in spec or 'path' not in spec: + continue + key = repo_key(spec['repository']) + repo = self.open(key, 'canonical input %s' % label) + if repo is None: + continue + ref = spec.get('ref') + if ref and not repo.has_commit(ref): + self.add(BLOCK, 'PIN-MISSING', 'canonical input %s ref %s is not in %s%s' % (label, ref, key, repo.where()), repo=key) + continue + ref = ref or self.ref_for(key, repo) + ent = repo.tree(ref).get(spec['path']) + if spec.get('observed_blob') and (ent is None or ent[2] != spec['observed_blob']): + self.add(INFO, 'INPUT-OBSERVED', 'canonical input %s: %s at %s is %s, recorded %s' % ( + label, spec['path'], ref[:12], ent[2][:12] if ent else 'absent', spec['observed_blob'][:12]), + repo=key, ref=ref, path=spec['path']) + if ent is None: + continue + doc = self.json_at(repo, ref, spec['path']) + if isinstance(doc, dict) and isinstance(doc.get('artifacts'), list) and isinstance(doc.get('repositories'), dict): + self.check_artifacts(repo, ref, spec['path'], doc) + + def check_artifacts(self, reg_repo, reg_ref, reg_path, doc): + names = {} + for name, ent in doc['repositories'].items(): + try: + names[name] = repo_key(ent['full_name']) + except (KeyError, TypeError, CrawlError) as exc: + self.add(BLOCK, 'MALFORMED', 'registry repository %r: %s' % (name, exc), repo=reg_repo.key, path=reg_path) + trees = {} + for art in doc['artifacts']: + where = dict(repo=reg_repo.key, path=reg_path, artifact=art.get('key')) + try: + key = names[art['repository']] + commit, path, size, digest = art['commit'], art['path'], int(art['bytes']), art['sha256'] + except (KeyError, TypeError, ValueError) as exc: + self.add(BLOCK, 'MALFORMED', 'artifact %r: %s' % (art.get('key'), exc), **where) + continue + repo = self.open(key, 'registry artifact %s' % art.get('key')) + if repo is None: + continue + self.stats['registry_artifacts'] += 1 + if not repo.has_commit(commit): + self.add(BLOCK, 'PIN-MISSING', 'artifact %s: commit %s is not in %s%s' % (art.get('key'), commit, key, repo.where()), **where) + continue + if (key, commit) not in trees: + trees[(key, commit)] = repo.tree(commit) + ent = trees[(key, commit)].get(path) + data = repo.blob(ent[2]) if ent and ent[1] == 'blob' else None + if data is None: + self.add(BLOCK, 'REGISTRY-BYTES', 'artifact %s: %s is absent at %s' % (art.get('key'), path, commit[:12]), **where) + continue + if len(data) != size or hashlib.sha256(data).hexdigest() != digest: + self.add(BLOCK, 'REGISTRY-BYTES', 'artifact %s: %s at %s has %d bytes / sha256 %s, recorded %d / %s' % ( + art.get('key'), path, commit[:12], len(data), hashlib.sha256(data).hexdigest()[:16], size, digest[:16]), **where) + continue + self.stats['registry_artifacts_verified'] += 1 + ref = self.ref_for(key, repo) + if (key, ref) not in trees: + trees[(key, ref)] = repo.tree(ref) + now = trees[(key, ref)].get(path) + if now is None or now[2] != ent[2]: + self.stats['registry_artifacts_evolved'] += 1 + self.add(INFO, 'REGISTRY-EVOLVED', 'artifact %s: %s %s at the crawled ref %s' % ( + art.get('key'), path, 'is absent' if now is None else 'differs', ref[:12]), **where) + + # ------------------------------------------------------------------ Lean + def crawled(self): + for key in sorted(k for k, r in self.repos.items() if r is not None): + yield key, self.repos[key], self.ref_for(key, self.repos[key]) + + def check_lean(self): + decls = collections.defaultdict(list) + packages = {} + lake_deps = [] + for key, repo, ref in list(self.crawled()): + tree = repo.tree(ref) + roots = sorted({p.rsplit('/', 1)[0] if '/' in p else '' for p in tree + if p.rsplit('/', 1)[-1] in ('lakefile.lean', 'lakefile.toml')}) + for root in roots: + tc = repo.read(ref, (root + '/' if root else '') + 'lean-toolchain') + packages[(key, root)] = tc.decode(errors='replace').strip() if tc else None + lm = (root + '/' if root else '') + 'lake-manifest.json' + if lm in tree: + doc = self.json_at(repo, ref, lm) + for pkg in (doc or {}).get('packages', []) if isinstance(doc, dict) else []: + if isinstance(pkg, dict) and pkg.get('type') == 'git' and pkg.get('url') and pkg.get('rev'): + lake_deps.append((key, ref, lm, pkg)) + for path, (mode, typ, sha) in sorted(tree.items()): + if typ != 'blob' or not path.endswith('.lean') or '/.lake/' in '/' + path: + continue + pkg = max((r for r in roots if r == '' or path.startswith(r + '/')), key=len, default=None) + self.stats['lean_files'] += 1 + try: + found = lean_decls.declarations(repo.blob(sha).decode('utf-8'), unit='%s:%s' % (key, path)) + except (lean_decls.LeanSyntaxError, UnicodeDecodeError) as exc: + self.add(BLOCK, 'LEAN-SYNTAX', str(exc), repo=key, ref=ref, path=path) + continue + for d in found: + self.stats['lean_declarations'] += 1 + if d['private']: + continue + decls[d['name']].append({'repo': key, 'ref': ref, 'path': path, 'line': d['line'], + 'package': pkg, 'kind': d['kind'], 'interface': d['interface']}) + shared = 0 + coupled = collections.defaultdict(set) + for name, locs in sorted(decls.items()): + if len(locs) < 2: + continue + shared += 1 + pk = {(l['repo'], l['package']) for l in locs if l['package'] is not None} + for a in pk: + coupled[a] |= pk - {a} + variants = collections.OrderedDict() + for l in locs: + variants.setdefault((l['kind'], l['interface']), []).append(l) + if len(variants) > 1: + self.add(BLOCK, 'LEAN-DRIFT', '%s has %d different interfaces across %d locations' % (name, len(variants), len(locs)), + name=name, variants=[{'kind': k, 'interface': i, 'locations': ['%s@%s:%s:%d' % ( + l['repo'], l['ref'][:12], l['path'], l['line']) for l in ls]} for (k, i), ls in variants.items()]) + self.stats['lean_shared_names'] = shared + for (a, b) in sorted({tuple(sorted((x, y))) for x, ys in coupled.items() for y in ys}): + if packages.get(a) != packages.get(b): + self.add(INFO, 'TOOLCHAIN', 'packages %s:%s and %s:%s share declarations but use %s and %s' % ( + a[0], a[1] or '.', b[0], b[1] or '.', packages.get(a), packages.get(b))) + for key, ref, lm, pkg in lake_deps: + try: + dep = repo_key(pkg['url']) + except CrawlError: + continue + if dep in self.repos or dep in self.local: + self.edges.append((key, dep, 'lake')) + drepo = self.open(dep, 'lake dependency of %s' % key) + if drepo is not None and pkg['rev'] != self.ref_for(dep, drepo): + self.add(INFO, 'LAKE-DEP', '%s:%s pins %s at %s; crawl reads it at %s' % ( + key, lm, dep, pkg['rev'][:12], self.ref_for(dep, drepo)[:12]), repo=key, path=lm) + + def report(self): + return { + 'schema': 'cbz.drift.v1', + 'seed': {'repository': self.seed_key, 'ref': self.seed_ref}, + 'mode': self.at, + 'repositories': [{'repository': k, 'ref': self.refs.get(k), 'resolved': r is not None, + 'optional': k in self.optional, 'pin': self.pins.get(k)} for k, r in sorted(self.repos.items())], + 'edges': [{'from': a, 'to': b, 'via': v} for a, b, v in self.edges], + 'stats': dict(sorted(self.stats.items())), + 'blocking': sum(f['level'] == BLOCK for f in self.findings), + 'findings': self.findings, + } + + +def run(seed, search, at='pins', seed_ref=None, overrides=None, fetch=False, clone_into=None): + local = find_local_repos(search) + c = Crawl(local, at=at, overrides=overrides, fetch=fetch, clone_into=clone_into) + c.seed(repo_key(seed) if '/' in seed else _match_name(seed, local), seed_ref) + c.check_pins() + c.check_registries() + c.check_lean() + return c.report() + + +def _match_name(name, local): + hits = [k for k in local if k.split('/')[1] == name.lower()] + if len(hits) != 1: + raise CrawlError('seed %r matches %d local repositories' % (name, len(hits))) + return hits[0] + + +def main(argv=None): + ap = argparse.ArgumentParser(description=__doc__.split('\n')[0]) + ap.add_argument('--seed', required=True, help='owner/name (or a unique name) of the seed repository') + ap.add_argument('--search', action='append', required=True, help='directory whose subdirectories are local clones') + ap.add_argument('--seed-ref', help='ref of the seed to read (default: its default tip)') + ap.add_argument('--at', choices=('pins', 'tips'), default='pins') + ap.add_argument('--override', action='append', default=[], metavar='OWNER/NAME=REV') + ap.add_argument('--fetch', action='store_true', help='git fetch commits missing locally') + ap.add_argument('--clone-into', metavar='DIR', help='clone discovered repositories that no --search directory holds') + ap.add_argument('--json', metavar='FILE', help='write the full report here') + args = ap.parse_args(argv) + try: + ov = {} + for o in args.override: + k, _, v = o.partition('=') + if not v: + raise CrawlError('override %r is not NAME=REV' % o) + ov[repo_key(k) if '/' in k else k.lower()] = v + if args.clone_into: + pathlib.Path(args.clone_into).mkdir(parents=True, exist_ok=True) + rep = run(args.seed, args.search, at=args.at, seed_ref=args.seed_ref, overrides=ov, fetch=args.fetch, + clone_into=args.clone_into) + except CrawlError as exc: + print('drift crawler error: %s' % exc, file=sys.stderr) + return 2 + if args.json: + pathlib.Path(args.json).write_text(json.dumps(rep, indent=1, sort_keys=True) + '\n') + for f in rep['findings']: + if f['level'] == BLOCK: + print('BLOCK %s %s' % (f['code'], f['message'])) + info = collections.Counter(f['code'] for f in rep['findings'] if f['level'] == INFO) + print('crawled %d repositories from %s@%s (%s): %d BLOCK, INFO %s; stats %s' % ( + sum(r['resolved'] for r in rep['repositories']), rep['seed']['repository'], rep['seed']['ref'][:12], + rep['mode'], rep['blocking'], dict(sorted(info.items())) or '{}', rep['stats'])) + return 1 if rep['blocking'] else 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/cbz_drift/lean_decls.py b/tools/cbz_drift/lean_decls.py new file mode 100644 index 000000000..15c30bcd5 --- /dev/null +++ b/tools/cbz_drift/lean_decls.py @@ -0,0 +1,260 @@ +"""Lexical extraction of Lean 4 declaration headers, for cross-repository drift checks. + +Domain (B-006). This module sees declarations written literally in source: +`theorem`, `lemma`, `def`, `abbrev`, `instance` (named), `axiom`, `opaque`, `structure`, +`class` and `inductive`, with their modifiers, inside `namespace` / `section` blocks. It +does not elaborate, expand macros or notation, or see declarations generated by +commands such as `deriving`, `mutual` auto-names or user syntax. A header is the token +sequence from the keyword to the first top-level `:=`, `where` or line-leading `|` +(for `structure`, `class` and `inductive`, the whole body up to the next command), with +comments removed and whitespace normalized. The compared `interface` is the header for +`theorem`, `lemma`, `axiom` and `opaque` (proofs are irrelevant; opaque values are +hidden), and header plus value for every definition-like declaration, whose value is part +of its meaning. Equal interfaces mean equal source text, not equal elaborated terms; +unequal interfaces mean the source differs. + +Fails closed: an unterminated comment, string or quoted name, an unbalanced `end`, or a +declaration keyword with no name raises LeanSyntaxError. +""" +from __future__ import annotations + +import re + +DECL_KEYWORDS = frozenset({ + 'theorem', 'lemma', 'def', 'abbrev', 'instance', 'axiom', 'opaque', + 'structure', 'class', 'inductive', 'example', +}) +BODY_KEYWORDS = frozenset({'structure', 'class', 'inductive'}) +# proofs are irrelevant to meaning; opaque values are hidden by design +STATEMENT_ONLY = frozenset({'theorem', 'lemma', 'axiom', 'opaque', 'example'}) +MODIFIERS = frozenset({'private', 'protected', 'noncomputable', 'unsafe', 'partial', 'nonrec'}) +COMMANDS = DECL_KEYWORDS | MODIFIERS | frozenset({ + 'namespace', 'section', 'end', 'open', 'variable', 'universe', 'set_option', + 'attribute', 'import', 'mutual', 'macro', 'macro_rules', 'syntax', 'notation', + 'infix', 'infixl', 'infixr', 'prefix', 'postfix', 'elab', 'elab_rules', + 'declare_syntax_cat', 'initialize', 'builtin_initialize', 'export', 'local', 'scoped', + 'omit', 'include', 'deriving', +}) +OPEN = {'(': ')', '[': ']', '{': '}', '⟨': '⟩', '⦃': '⦄', '⟪': '⟫'} +CLOSE = {v: k for k, v in OPEN.items()} +RAW_OPEN = re.compile(r'r(#*)"') + + +class LeanSyntaxError(ValueError): + pass + + +def _ident_start(c): + return c.isalpha() or c == '_' + + +def _ident_char(c): + return c.isalnum() or c in "_'!?" + + +def tokens(text): + """Yield (kind, text, line, first_on_line). Kinds: ident, str, char, num, sym.""" + i, n, line, fresh = 0, len(text), 1, True + while i < n: + c = text[i] + if c == '\n': + line, fresh, i = line + 1, True, i + 1 + continue + if c in ' \t\r': + i += 1 + continue + start_line, first = line, fresh + fresh = False + if text.startswith('--', i): + j = text.find('\n', i) + i = n if j < 0 else j + fresh = first + continue + if text.startswith('/-', i): + depth, i = 1, i + 2 + while depth: + if i >= n: + raise LeanSyntaxError('unterminated comment opened on line %d' % start_line) + if text.startswith('/-', i): + depth, i = depth + 1, i + 2 + elif text.startswith('-/', i): + depth, i = depth - 1, i + 2 + else: + line += text[i] == '\n' + i += 1 + fresh = first + continue + m = RAW_OPEN.match(text, i) if c == 'r' else None + if m and (i == 0 or not _ident_char(text[i - 1])): + close = '"' + m.group(1) + j = text.find(close, m.end()) + if j < 0: + raise LeanSyntaxError('unterminated raw string on line %d' % start_line) + line += text.count('\n', i, j) + yield 'str', text[i:j + len(close)], start_line, first + i = j + len(close) + continue + if c == '"': + j = i + 1 + while True: + if j >= n: + raise LeanSyntaxError('unterminated string on line %d' % start_line) + if text[j] == '\\': + j += 2 + elif text[j] == '"': + break + else: + j += 1 + line += text.count('\n', i, j) + yield 'str', text[i:j + 1], start_line, first + i = j + 1 + continue + if c == "'" and i + 2 < n and (text[i + 2] == "'" or (text[i + 1] == '\\' and "'" in text[i + 3:i + 12])): + j = text.index("'", i + 2 if text[i + 1] != '\\' else i + 3) + yield 'char', text[i:j + 1], start_line, first + i = j + 1 + continue + if c == '«' or _ident_start(c): + j, parts = i, [] + while True: + if j < n and text[j] == '«': + k = text.find('»', j) + if k < 0: + raise LeanSyntaxError('unterminated «name» on line %d' % start_line) + parts.append(text[j:k + 1]) + j = k + 1 + elif j < n and _ident_start(text[j]): + k = j + while k < n and _ident_char(text[k]): + k += 1 + parts.append(text[j:k]) + j = k + else: + break + if j + 1 < n and text[j] == '.' and (text[j + 1] == '«' or _ident_start(text[j + 1])): + j += 1 + else: + break + yield 'ident', '.'.join(parts), start_line, first + i = j + continue + if c.isdigit(): + j = i + while j < n and (text[j].isalnum() or text[j] in '._'): + j += 1 + yield 'num', text[i:j], start_line, first + i = j + continue + if text.startswith(':=', i): + yield 'sym', ':=', start_line, first + i += 2 + continue + yield 'sym', c, start_line, first + i += 1 + + +def declarations(text, unit=''): + """Return a list of dicts: name, kind, header, line, private, modifiers. + + `unit` disambiguates `private` names, which are file-local and never compared. + """ + toks = list(tokens(text)) + out, scopes, i, n = [], [], 0, len(toks) + + def current_ns(): + return [p for kind, parts in scopes if kind == 'namespace' for p in parts] + + while i < n: + kind, tx, line, first = toks[i] + if kind == 'ident' and tx in ('namespace', 'section'): + name = toks[i + 1][1] if i + 1 < n and toks[i + 1][0] == 'ident' and toks[i + 1][2] == line else '' + if tx == 'namespace' and not name: + raise LeanSyntaxError('namespace without a name on line %d' % line) + scopes.append((tx, name.split('.') if name else [])) + i += 2 if name else 1 + continue + if kind == 'ident' and tx == 'end': + name = toks[i + 1][1] if i + 1 < n and toks[i + 1][0] == 'ident' and toks[i + 1][2] == line and toks[i + 1][1] not in COMMANDS else '' + parts = name.split('.') if name else [] + if not scopes: + raise LeanSyntaxError('unbalanced end on line %d' % line) + skind, sparts = scopes[-1] + if sparts != parts: + raise LeanSyntaxError('end %s on line %d closes %s %s' % (name or '(anonymous)', line, skind, '.'.join(sparts) or '(anonymous)')) + scopes.pop() + i += 2 if name else 1 + continue + if kind == 'ident' and (tx in DECL_KEYWORDS or tx in MODIFIERS): + # collect modifiers, attributes already passed as symbols + mods, j = [], i + while j < n and toks[j][0] == 'ident' and toks[j][1] in MODIFIERS: + mods.append(toks[j][1]) + j += 1 + if j >= n or toks[j][0] != 'ident' or toks[j][1] not in DECL_KEYWORDS: + i = max(j, i + 1) + continue + dkind, dline = toks[j][1], toks[j][2] + j += 1 + if dkind == 'instance' and j < n and toks[j][1] == '(': + depth = 0 + while j < n: + depth += toks[j][1] == '(' + depth -= toks[j][1] == ')' + j += 1 + if depth == 0: + break + name = None + if dkind != 'example' and j < n and toks[j][0] == 'ident' and toks[j][1] not in COMMANDS and toks[j][1] != 'where': + name = toks[j][1] + j += 1 + if name is None and dkind not in ('example', 'instance'): + raise LeanSyntaxError('%s without a name on line %d' % (dkind, dline)) + hdr, depth = [], 0 + while j < n: + k, t, ln, fst = toks[j] + if depth == 0: + if k == 'ident' and t in COMMANDS and not (t == 'deriving' and dkind in BODY_KEYWORDS): + break + if k == 'sym' and t == '@' and j + 1 < n and toks[j + 1][1] == '[': + break + if k == 'sym' and t == '#' and fst and j + 1 < n and toks[j + 1][0] == 'ident': + break + if dkind not in BODY_KEYWORDS: + if (k == 'sym' and t == ':=') or (k == 'ident' and t == 'where') or (k == 'sym' and t == '|' and fst): + break + if k == 'sym' and t in OPEN: + depth += 1 + elif k == 'sym' and t in CLOSE: + depth = max(depth - 1, 0) + hdr.append(t) + j += 1 + # the rest of the declaration, up to the next top-level command + body = [] + while j < n: + k, t, ln, fst = toks[j] + if depth == 0 and ( + (k == 'ident' and t in COMMANDS and t != 'deriving') + or (k == 'sym' and t == '@' and j + 1 < n and toks[j + 1][1] == '[') + or (k == 'sym' and t == '#' and fst and j + 1 < n and toks[j + 1][0] == 'ident')): + break + if k == 'sym' and t in OPEN: + depth += 1 + elif k == 'sym' and t in CLOSE: + depth = max(depth - 1, 0) + body.append(t) + j += 1 + if name is not None: + full = name[len('_root_.'):] if name.startswith('_root_.') else '.'.join(current_ns() + [name]) + header = ' '.join(hdr) + out.append({ + 'name': full, 'kind': dkind, 'header': header, 'line': dline, + 'private': 'private' in mods, 'unit': unit, + 'modifiers': sorted(m for m in mods if m != 'private'), + # what must agree across copies: the statement of a proposition, the + # statement and value of a definition (its value is part of its meaning) + 'interface': header if dkind in STATEMENT_ONLY else ' '.join(hdr + body), + }) + i = j + continue + i += 1 + return out