Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/test_cbz_drift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down Expand Up @@ -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'),
]


Expand Down
1 change: 1 addition & 0 deletions tools/cbz_drift/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
14 changes: 14 additions & 0 deletions tools/cbz_drift/crawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -63,6 +65,10 @@
import lean_decls # noqa: E402

BLOCK, INFO = 'BLOCK', 'INFO'
# A path segment named `evidence` or ending in `-evidence` (cbz/evidence/<slice>/, 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):
Expand Down Expand Up @@ -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:
Expand All @@ -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()):
Expand Down
Loading