From 03a2eeb71412f92deb20db6852d83fc285bbf5c6 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 31 Oct 2026 23:02:50 +0000 Subject: [PATCH] cbz_drift: count Lean files under evidence directories, do not compare them Evidence directories hold frozen copies on purpose: sealed checker inputs, snapshots of earlier commits and mutation controls. The crawler compared them as live declarations, so the G1 stack under #733 (which adds 367 .lean evidence copies) failed federation-drift with 16 LEAN-DRIFT blocks, each with at most one live variant (formal/ and tools/) and every other variant under cbz/evidence/ or a *-evidence segment. A path segment named evidence or ending in -evidence now marks a frozen copy: it is counted (stats.lean_evidence_files) and reported once per repository as INFO LEAN-EVIDENCE, never compared. A live copy with the same change still blocks. Two tests and two designated mutants cover it; the four drift modules run 80 tests OK in normal and -O mode. At #733's head 0513bb12 the crawl goes from 16 BLOCK to 0 (372 evidence copies, 167 live Lean files); current main stays at 0 BLOCK. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DKKe26v3CSgdYch8kiJLt9 --- tests/test_cbz_drift.py | 25 +++++++++++++++++++++++++ tools/cbz_drift/README.md | 1 + tools/cbz_drift/crawl.py | 14 ++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/tests/test_cbz_drift.py b/tests/test_cbz_drift.py index 0a222e29d..b54825d67 100644 --- a/tests/test_cbz_drift.py +++ b/tests/test_cbz_drift.py @@ -193,6 +193,27 @@ def test_changed_theorem_statement_blocks(self): self.assertEqual(f['name'], 'Fed.t') self.assertEqual(len(f['variants']), 2) + def test_evidence_copies_are_counted_not_compared(self): + self.fed.build() + stale = LEAN_A.replace('n + 0 = n', '0 + n = n') + self.fed.pins['b'] = self.fed.commit('b', {'cbz/evidence/run/Copy/A.lean': stale, + 'kernel/cbz-evidence/A.lean': stale}) + self.fed.write_seed() + rep = self.fed.crawl() + self.assertEqual(codes(rep, 'BLOCK'), []) + self.assertIn('LEAN-EVIDENCE', codes(rep, 'INFO')) + self.assertEqual(rep['stats']['lean_evidence_files'], 2) + # a live copy with the same change still blocks + self.fed.pins['b'] = self.fed.commit('b', {'Copy/A.lean': stale}) + self.fed.write_seed() + self.assertEqual(codes(self.fed.crawl(), 'BLOCK'), ['LEAN-DRIFT']) + + def test_evidence_paths_are_matched_by_segment(self): + for path in ('cbz/evidence/x/A.lean', 'a/kernel/cbz-evidence/A.lean', 'formal-evidence/A.lean', 'evidence/A.lean'): + self.assertTrue(crawl.EVIDENCE_SEGMENT.search(path), path) + for path in ('formal/Evidenced.lean', 'tools/evidence_check.lean', 'formal/UniversalLaw/A.lean'): + self.assertFalse(crawl.EVIDENCE_SEGMENT.search(path), path) + 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']) @@ -838,6 +859,10 @@ def test_malformed_raise(self): ('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'), + ('evidence copies compared', " if EVIDENCE_SEGMENT.search(path):", " if False:", 'crawl.py', + 'LeanDriftTests.test_evidence_copies_are_counted_not_compared'), + ('every evidence-like name skipped', "EVIDENCE_SEGMENT = re.compile(r'(^|/)([^/]*-)?evidence(/|$)')", + "EVIDENCE_SEGMENT = re.compile(r'evidence')", 'crawl.py', 'LeanDriftTests.test_evidence_paths_are_matched_by_segment'), ] diff --git a/tools/cbz_drift/README.md b/tools/cbz_drift/README.md index fafc251a8..b36cdae28 100644 --- a/tools/cbz_drift/README.md +++ b/tools/cbz_drift/README.md @@ -54,6 +54,7 @@ lag a moving tip (INFO).** | `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 | +| `LEAN-EVIDENCE` | INFO | Lean files under an evidence directory (a path segment `evidence` or `*-evidence`) are frozen copies — sealed checker inputs, snapshots of earlier commits, mutation controls — and are counted but not compared | | `LAKE-DEP` | INFO | a lake dependency on a crawled repository pins a present, different full commit id (any other rev, such as an absent, empty, short or floating one like a branch or tag, is `PIN-MISSING`; a git package with no repository URL, a package that is neither git nor path, and a `packages` value that is not a list are `MALFORMED`) | | `PIN-DIVERGENT` | INFO | two reached repositories pin one repository differently; the first in breadth-first order is read | | `FETCH-FAILED` | BLOCK | `--fetch` could not refresh a repository, so its tips are not current | diff --git a/tools/cbz_drift/crawl.py b/tools/cbz_drift/crawl.py index 4d1865d5d..cf47050a9 100644 --- a/tools/cbz_drift/crawl.py +++ b/tools/cbz_drift/crawl.py @@ -30,6 +30,8 @@ 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 + LEAN-EVIDENCE Lean files under an evidence directory are frozen copies, not INFO + compared (sealed checker inputs, snapshots, mutation controls) LAKE-DEP a lake dependency on a crawled repository pins another rev INFO PIN-DIVERGENT two reached repositories pin one repository differently INFO FETCH-FAILED --fetch could not refresh a repository, so its tips are not current BLOCK @@ -63,6 +65,10 @@ import lean_decls # noqa: E402 BLOCK, INFO = 'BLOCK', 'INFO' +# A path segment named `evidence` or ending in `-evidence` (cbz/evidence//, kernel/cbz-evidence/, +# formal-evidence/) holds frozen copies: sealed checker inputs, snapshots of earlier commits and mutation +# controls. They are deliberately different from the live sources, so they are not compared. +EVIDENCE_SEGMENT = re.compile(r'(^|/)([^/]*-)?evidence(/|$)') class CrawlError(RuntimeError): @@ -585,9 +591,13 @@ def check_lean(self): 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 + evidence = 0 for path, (mode, typ, sha) in sorted(tree.items()): if typ != 'blob' or not path.endswith('.lean') or '/.lake/' in '/' + path: continue + if EVIDENCE_SEGMENT.search(path): + evidence += 1 + continue pkg = max((r for r in roots if r == '' or path.startswith(r + '/')), key=len, default=None) self.stats['lean_files'] += 1 try: @@ -601,6 +611,10 @@ def check_lean(self): continue decls[d['name']].append({'repo': key, 'ref': ref, 'path': path, 'line': d['line'], 'package': pkg, 'kind': d['kind'], 'interface': d['interface']}) + if evidence: + self.stats['lean_evidence_files'] += evidence + self.add(INFO, 'LEAN-EVIDENCE', '%d Lean files under evidence directories are frozen copies and ' + 'are not compared' % evidence, repo=key, ref=ref) shared = 0 coupled = collections.defaultdict(set) for name, locs in sorted(decls.items()):