test_external_provenance.py¶
tests/test_external_provenance.py
Per-file EXTERNAL provenance (gh#335) — the tag, and what must NOT move because of it.
test_a_nested_tree_with_no_indexed_file_is_not_reported
None test_external_provenance.test_a_nested_tree_with_no_indexed_file_is_not_reported(Path tmp_path)
A nested tree that owns no indexed row is never named in the stamp.
tests/test_external_provenance.py:368
Called by none
Calls _indexed, _ours, external_roots, measure_index_coverage, stamp_external_provenance
Checks
assert external_roots(root) == ["excluded_area/someone_elses"], "detection still sees it"assert tagged == 0assert reported == [], "a root that owns no row must not reach build_meta"assert measure_index_coverage(db_path, root).external_roots == ()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_a_nested_tree_with_no_indexed_file_is_not_reported → external_roots → dependency_roots |
| REQ-DDB-INDEX-002 | measured | test_a_nested_tree_with_no_indexed_file_is_not_reported → measure_index_coverage → _file_yields → memoized |
| REQ-DDB-INDEX-003 | measured | test_a_nested_tree_with_no_indexed_file_is_not_reported → measure_index_coverage |
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-INDEX-005 | measured | test_a_nested_tree_with_no_indexed_file_is_not_reported → stamp_external_provenance |
| REQ-DDB-PIPE-014 | catalog |
Source · 31 lines
def test_a_nested_tree_with_no_indexed_file_is_not_reported(tmp_path: Path) -> None:
"""TWO REASONS, EITHER SUFFICIENT, and the second is the one that made this
urgent. A nested tree some other rule already excluded contributes no row, so:
- naming it is misleading — "0 files belong to 1 nested tree" reads like a broken
detector, and that exact line cost a real measurement here before it was traced
to an unrelated cause;
- ANYTHING STAMPED IS PUBLISHED OVER MCP. The walk sees every directory on disk,
including trees the index deliberately does not cover, and emitting one of those
names into `build_meta` discloses a path this build was configured to leave out.
Caught on this repo's own self-index, which holds an excluded target directory.
@brief A detected-but-empty external root is counted, not named.
@version 1
"""
## A DECLARED dependency with NO indexed file — the shape an exclusion leaves behind. It has
## to be a real gitlink, not just a directory holding `.git`: since gh#352 the latter is a
## stray developer clone, which is first party and would make this test pass for the wrong
## reason (`external_roots` empty because nothing was DETECTED, rather than because the
## detected root owns no row).
db_path, root = _indexed(tmp_path, _ours(), nested=("excluded_area/someone_elses",))
assert external_roots(root) == ["excluded_area/someone_elses"], "detection still sees it"
tagged, reported = stamp_external_provenance(db_path, root)
assert tagged == 0
assert reported == [], "a root that owns no row must not reach build_meta"
assert measure_index_coverage(db_path, root).external_roots == ()
Activity · 6 steps
test_a_stray_developer_clone_the_parent_tracks_is_first_party
None test_external_provenance.test_a_stray_developer_clone_the_parent_tracks_is_first_party(Path tmp_path)
A stray clone inside a directory the parent TRACKS is first party.
tests/test_external_provenance.py:170
Called by none
Calls _indexed, _ours, _theirs, external_roots, git_run, stamp_external_provenance
Checks
assert (make_gitlink_free_clone / ".git").is_dir(), "the fixture must hold a REAL git tree"assert external_roots(root) == ["vendor/theirs"], ("a stray clone in a tracked directory is NOT a declared dependency — reporting it " "makes the tag depend on who built the index rather than on what the repo committed" )assert rows["evidence/checkout/probe.c"] is None, "the repo's own tracked file stays ours"assert rows["vendor/theirs/lib_0.c"] == "vendor/theirs"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_a_stray_developer_clone_the_parent_tracks_is_first_party → external_roots → dependency_roots |
| REQ-DDB-INDEX-005 | measured | test_a_stray_developer_clone_the_parent_tracks_is_first_party → stamp_external_provenance |
| REQ-DDB-PIPE-014 | catalog |
Source · 46 lines
def test_a_stray_developer_clone_the_parent_tracks_is_first_party(tmp_path: Path) -> None:
"""THE NEGATIVE HALF OF gh#352, and the case that forced the predicate split. Both
directories here hold a real `.git`; only one is a gitlink in the parent's index. The other
is a repository somebody CLONED into a directory whose files this repo tracks and owns.
WHY THAT MUST BE FIRST PARTY. The external tag would otherwise be a property of the WORKING
COPY rather than of the repository: the same commit indexes differently depending on who
built it, and one of those indexes reports the repo's own code as somebody else's. Measured
on [tvanfossen/entropic](https://github.com/tvanfossen/entropic): three roots tagged
external against the ONE `.gitmodules` declares, because two of them held entropic's own
committed blobs — `git ls-files -s` returns mode 100644 there, not 160000.
A `.git`-only detector cannot express this test at all: it answers "somebody has a
repository here", and the question is "did this repository declare it as a dependency".
@brief A `.git` with no gitlink in the parent is first party.
@version 1
"""
db_path, root = _indexed(
tmp_path,
[*_ours(), *_theirs(), ("evidence/checkout/probe.c", 4)],
nested=("vendor/theirs",),
)
## A real repository, and the parent TRACKS its file rather than recording a gitlink — the
## shape `git clone` leaves behind inside a tracked directory.
make_gitlink_free_clone = root / "evidence" / "checkout"
git_run(make_gitlink_free_clone, "init", "-q", ".")
git_run(root, "add", "-f", "evidence/checkout/probe.c")
assert (make_gitlink_free_clone / ".git").is_dir(), "the fixture must hold a REAL git tree"
assert external_roots(root) == ["vendor/theirs"], (
"a stray clone in a tracked directory is NOT a declared dependency — reporting it "
"makes the tag depend on who built the index rather than on what the repo committed"
)
stamp_external_provenance(db_path, root)
conn = sqlite3.connect(str(db_path))
try:
rows = dict(conn.execute(f"SELECT name, {EXTERNAL_ROOT_COLUMN} FROM path").fetchall())
finally:
conn.close()
assert rows["evidence/checkout/probe.c"] is None, "the repo's own tracked file stays ours"
assert rows["vendor/theirs/lib_0.c"] == "vendor/theirs"
Activity · 12 steps
test_a_submodule_whose_git_is_a_file_is_detected
None test_external_provenance.test_a_submodule_whose_git_is_a_file_is_detected(Path tmp_path)
A SUBMODULE, whose .git is a FILE, is detected like a clone.
tests/test_external_provenance.py:401
Checks
assert not (root / "extern" / "theirs" / ".git").is_dir(), ("the fixture's whole point is that this `.git` is a FILE — if some helper turned it " "back into a directory the test would pass while covering the case that already worked" )assert external_roots(root) == ["extern/theirs"], ("a submodule's .git is a FILE; a detector that only looks for a directory " "is blind to every submodule while still reporting a plausible count" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_a_submodule_whose_git_is_a_file_is_detected → external_roots → dependency_roots |
| REQ-DDB-INDEX-005 | measured | test_a_submodule_whose_git_is_a_file_is_detected → external_roots |
| REQ-DDB-PIPE-014 | catalog |
Source · 28 lines
def test_a_submodule_whose_git_is_a_file_is_detected(tmp_path: Path) -> None:
"""THE CASE THE WHOLE FEATURE WAS BUILT FOR, and the one every other fixture in
this file gets wrong. A `git submodule` checkout writes a 44-byte
`gitdir: ../../.git/modules/<name>` POINTER FILE where a standalone clone has a
`.git` DIRECTORY, and the detector tested `".git" in dirnames`.
Found on [tvanfossen/entropic](https://github.com/tvanfossen/entropic), which
wraps llama.cpp as a submodule: the build reported 28 nested trees — a number
that made the detector look like it was working — and `extern/llama.cpp` was not
one of them. No unit fixture could have caught it, because every fixture built a
`.git` directory. This one does not.
@brief A `.git` file marks a nested tree just as a `.git` directory does.
@version 1
"""
root = repo_with_submodules(tmp_path / "repo")
make_gitlink(root, "extern/theirs", git_as_file=True)
assert not (root / "extern" / "theirs" / ".git").is_dir(), (
"the fixture's whole point is that this `.git` is a FILE — if some helper turned it "
"back into a directory the test would pass while covering the case that already worked"
)
assert external_roots(root) == ["extern/theirs"], (
"a submodule's .git is a FILE; a detector that only looks for a directory "
"is blind to every submodule while still reporting a plausible count"
)
Activity · 4 steps
test_a_symlinked_doc_outside_the_repository_is_not_ingested
None test_external_provenance.test_a_symlinked_doc_outside_the_repository_is_not_ingested(Path tmp_path)
A committed symlink pointing outside the repo is not ingested as repo prose.
tests/test_external_provenance.py:521
Checks
assert not any("SENTINEL-PROSE-LEAK" in content for _, content in rows), (f"a file outside the repository was ingested as repo prose: {rows}" )assert any(path == "docs/real.md" for path, _ in rows), ("the containment check must not cost the ordinary in-repo document" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_a_symlinked_doc_outside_the_repository_is_not_ingested → ingest_supplementary_docs → _ingest_one_doc_file → memoized |
| REQ-DDB-PIPE-001 | measured | test_a_symlinked_doc_outside_the_repository_is_not_ingested → ingest_supplementary_docs |
| REQ-DDB-PIPE-014 | measured | test_a_symlinked_doc_outside_the_repository_is_not_ingested → ingest_supplementary_docs → within_repo |
Source · 41 lines
def test_a_symlinked_doc_outside_the_repository_is_not_ingested(tmp_path: Path) -> None:
"""H2, 1.1.0 SECURITY AUDIT. `glob` FOLLOWS SYMLINKS, and git tracks symlinks, so a
repository could commit `README.md -> /etc/passwd` (or `/proc/self/environ`, which carries
the indexing user's `ANTHROPIC_API_KEY`) and clew would read it, chunk it into
`supplementary_docs`, and serve it to a model labelled with an in-repo path — the worst
combination: exfiltration plus a false provenance an agent has no way to doubt.
`clew/query/source.py:_read_body` already resolves-then-refuses on the read side; the
INGEST side did not. A missing or escaping file is skipped exactly as an unreadable one is.
@brief An escaping symlink contributes no prose row.
@return None.
@version 1
"""
from clew.prose import ingest_supplementary_docs
secret = tmp_path / "outside" / "secret.md"
secret.parent.mkdir(parents=True)
secret.write_text("# Secret\n\nSENTINEL-PROSE-LEAK\n", encoding="utf-8")
repo = tmp_path / "repo"
(repo / "docs").mkdir(parents=True)
(repo / "README.md").symlink_to(secret)
(repo / "docs" / "guide.md").symlink_to(secret)
(repo / "docs" / "real.md").write_text("# Real\n\nin-repo content\n", encoding="utf-8")
db = tmp_path / "clew.db"
ingest_supplementary_docs(db, repo)
conn = sqlite3.connect(str(db))
rows = conn.execute("SELECT file_path, content FROM supplementary_docs").fetchall()
conn.close()
assert not any("SENTINEL-PROSE-LEAK" in content for _, content in rows), (
f"a file outside the repository was ingested as repo prose: {rows}"
)
assert any(path == "docs/real.md" for path, _ in rows), (
"the containment check must not cost the ordinary in-repo document"
)
Activity · 16 steps
test_a_symlinked_source_file_contributes_no_file_doc
None test_external_provenance.test_a_symlinked_source_file_contributes_no_file_doc(Path tmp_path)
A symlinked source file does not leak an outside file as its file-level doc.
tests/test_external_provenance.py:566
Checks
assert not any("SENTINEL-FILEDOC-LEAK" in doc for _, doc in docs), (f"an outside file was read as an in-repo file's documentation: {docs}" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | inferred | test_a_symlinked_source_file_contributes_no_file_doc → ingest_file_docs → _collect_file_docs → memoized |
| REQ-DDB-PIPE-008 | measured | test_a_symlinked_source_file_contributes_no_file_doc → ingest_file_docs |
| REQ-DDB-PIPE-014 | measured | test_a_symlinked_source_file_contributes_no_file_doc → ingest_file_docs → _collect_file_docs → within_repo |
| REQ-DDB-SCHEMA-014 | measured | test_a_symlinked_source_file_contributes_no_file_doc → ingest_file_docs → ensure_file_docs_table |
Source · 36 lines
def test_a_symlinked_source_file_contributes_no_file_doc(tmp_path: Path) -> None:
"""The second half of H2. `filedocs` reads `repo_root / rel` for every INDEXED file, so a
symlinked `.c` whose target lives outside the tree has its docblock extracted and served
as that path's file documentation. The path list comes from the index, so this one is
reachable even where the prose globs are not.
@brief An escaping path is not read for file-level documentation.
@return None.
@version 1
"""
from clew.filedocs import ingest_file_docs
outside = tmp_path / "outside" / "leak.c"
outside.parent.mkdir(parents=True)
outside.write_text("/** @file\n * SENTINEL-FILEDOC-LEAK\n */\n", encoding="utf-8")
repo = tmp_path / "repo"
repo.mkdir()
(repo / "leaked.c").symlink_to(outside)
db = tmp_path / "clew.db"
conn = sqlite3.connect(str(db))
conn.execute("CREATE TABLE path (name TEXT PRIMARY KEY, type INTEGER NOT NULL)")
conn.execute("INSERT INTO path (name, type) VALUES ('leaked.c', 1)")
conn.commit()
conn.close()
ingest_file_docs(db, repo)
conn = sqlite3.connect(str(db))
docs = conn.execute("SELECT file_path, doc FROM file_docs").fetchall()
conn.close()
assert not any("SENTINEL-FILEDOC-LEAK" in doc for _, doc in docs), (
f"an outside file was read as an in-repo file's documentation: {docs}"
)1 more lines, not shown
Activity · 18 steps
test_admitting_a_submodule_leaves_first_party_coverage_identical
None test_external_provenance.test_admitting_a_submodule_leaves_first_party_coverage_identical(Path tmp_path)
Admitting a submodule must not move a single first-party coverage figure.
tests/test_external_provenance.py:218
Called by none
Calls _indexed, _ours, _theirs, measure_index_coverage, stamp_external_provenance
Checks
assert both.indexed_files == alone.indexed_filesassert both.substantive_files == alone.substantive_filesassert both.barren_files == alone.barren_filesassert both.barren_ratio == alone.barren_ratioassert both.undocumented_files == alone.undocumented_filesassert both.external_files == 12assert both.external_roots == ("vendor/theirs",)assert alone.external_files == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_admitting_a_submodule_leaves_first_party_coverage_identical → stamp_external_provenance → external_roots → dependency_roots |
| REQ-DDB-INDEX-002 | measured | test_admitting_a_submodule_leaves_first_party_coverage_identical → measure_index_coverage → _file_yields → memoized |
| REQ-DDB-INDEX-003 | measured | test_admitting_a_submodule_leaves_first_party_coverage_identical → measure_index_coverage |
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-INDEX-005 | measured | test_admitting_a_submodule_leaves_first_party_coverage_identical → stamp_external_provenance |
| REQ-DDB-PIPE-014 | catalog |
Source · 36 lines
def test_admitting_a_submodule_leaves_first_party_coverage_identical(tmp_path: Path) -> None:
"""THE LOAD-BEARING CONTROL, and the reason it is phrased as a comparison of two
builds rather than as an expected number: it holds whatever the matcher does. If
a first-party figure moves when a nested tree is admitted, the tagging is wrong,
and no assertion about the matcher's internals would have caught it.
The external files are barren, so an untagged build would drag `barren_ratio`
from 0.0 to 12/37 — a visible, wrong measurement rather than a marginal one.
@brief First-party coverage is invariant under admitting an external tree.
@version 1
"""
alone_db, alone_root = _indexed(tmp_path / "alone", _ours())
stamp_external_provenance(alone_db, alone_root)
alone = measure_index_coverage(alone_db, alone_root)
both_db, both_root = _indexed(
tmp_path / "both", [*_ours(), *_theirs()], nested=("vendor/theirs",)
)
stamp_external_provenance(both_db, both_root)
both = measure_index_coverage(both_db, both_root)
assert both.indexed_files == alone.indexed_files
assert both.substantive_files == alone.substantive_files
assert both.barren_files == alone.barren_files
assert both.barren_ratio == alone.barren_ratio
assert both.undocumented_files == alone.undocumented_files
## And the TOTAL really did rise — without this the test above would pass just as
## well against a build that never indexed the submodule at all, which is the
## behaviour gh#333 removed.
assert both.external_files == 12
assert both.external_roots == ("vendor/theirs",)
assert alone.external_files == 0
Activity · 14 steps
test_an_unresolved_include_is_neither_first_party_nor_external
None test_external_provenance.test_an_unresolved_include_is_neither_first_party_nor_external(Path tmp_path)
An unresolved #include row must not be counted as this repo's.
tests/test_external_provenance.py:328
Called by none
Calls _indexed, _ours, graph_stats, measure_index_coverage, stamp_external_provenance
Checks
assert coverage.indexed_files == 25, "an unresolvable include is not one of this repo's files"assert coverage.external_files == 0, "nor is it attributable to a named foreign tree"assert coverage.unresolved_files == 1, "and the exclusion is reported, not silent"assert stats.files.indexed_files == 25assert stats.files.unresolved_files == 1
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_an_unresolved_include_is_neither_first_party_nor_external → stamp_external_provenance → external_roots → dependency_roots |
| REQ-DDB-INDEX-002 | measured | test_an_unresolved_include_is_neither_first_party_nor_external → measure_index_coverage → _file_yields → memoized |
| REQ-DDB-INDEX-003 | measured | test_an_unresolved_include_is_neither_first_party_nor_external → measure_index_coverage |
| REQ-DDB-INDEX-004 | measured | test_an_unresolved_include_is_neither_first_party_nor_external → graph_stats → _symbol_provenance → records_provenance |
| REQ-DDB-INDEX-005 | measured | test_an_unresolved_include_is_neither_first_party_nor_external → stamp_external_provenance |
| REQ-DDB-MCP-001 | measured | test_an_unresolved_include_is_neither_first_party_nor_external → graph_stats → file_counts → meta_section |
| REQ-DDB-PIPE-005 | measured | test_an_unresolved_include_is_neither_first_party_nor_external → graph_stats → read_build_signature |
| REQ-DDB-PIPE-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_an_unresolved_include_is_neither_first_party_nor_external → graph_stats → connect |
| REQ-DDB-QUERY-003 | measured | test_an_unresolved_include_is_neither_first_party_nor_external → graph_stats → call_edge_counts → table_exists |
| REQ-DDB-QUERY-008 | measured | test_an_unresolved_include_is_neither_first_party_nor_external → graph_stats |
Source · 38 lines
def test_an_unresolved_include_is_neither_first_party_nor_external(tmp_path: Path) -> None:
"""THE DEFECT THAT MADE THE INVARIANCE ABOVE FALSE, and it was found on the real
target rather than here. Doxygen registers a `path` row for every `#include` it
cannot resolve, spelled as a BARE FILENAME with no directory. A bare filename
matches no external root, so every one of them counted as first party.
Measured on [entropic](https://github.com/tvanfossen/entropic): admitting the
llama.cpp submodule added 324 such rows from its Ascend and Hexagon backends and
moved `indexed_files` from 488 to 804 — on a change whose entire contract is that
no first-party figure moves. The RATIOS held throughout, because those files do
not exist on disk and the line count had already dropped them from the
substantive set. An invariant preserved by an accident one layer down is not
preserved, and the accident is exactly why no ratio assertion caught it.
@brief A bare-filename row is counted apart from both populations.
@version 1
"""
db_path, root = _indexed(tmp_path, _ours())
conn = sqlite3.connect(str(db_path))
try:
## Exactly what doxygen writes for an unresolvable include: a name with no
## directory and no file behind it.
conn.execute("INSERT INTO path (type, name) VALUES (1, 'aclnn_add.h')")
conn.commit()
finally:
conn.close()
stamp_external_provenance(db_path, root)
coverage = measure_index_coverage(db_path, root)
assert coverage.indexed_files == 25, "an unresolvable include is not one of this repo's files"
assert coverage.external_files == 0, "nor is it attributable to a named foreign tree"
assert coverage.unresolved_files == 1, "and the exclusion is reported, not silent"
stats = q.graph_stats(db_path)
assert stats.files.indexed_files == 25
assert stats.files.unresolved_files == 1
Activity · 13 steps
test_an_untagged_index_reports_no_external_recording
None test_external_provenance.test_an_untagged_index_reports_no_external_recording(Path tmp_path)
An index predating the tag reports every file as first party, and says so.
tests/test_external_provenance.py:280
Checks
assert stats.files.indexed_files == 25assert stats.files.external_files == 0assert stats.files.external_recorded is False
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_an_untagged_index_reports_no_external_recording → graph_stats → _symbol_provenance → records_provenance |
| REQ-DDB-MCP-001 | measured | test_an_untagged_index_reports_no_external_recording → graph_stats → file_counts → meta_section |
| REQ-DDB-PIPE-005 | measured | test_an_untagged_index_reports_no_external_recording → graph_stats → read_build_signature |
| REQ-DDB-PIPE-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_an_untagged_index_reports_no_external_recording → graph_stats → connect |
| REQ-DDB-QUERY-003 | measured | test_an_untagged_index_reports_no_external_recording → graph_stats → call_edge_counts → table_exists |
| REQ-DDB-QUERY-008 | measured | test_an_untagged_index_reports_no_external_recording → graph_stats |
Source · 22 lines
def test_an_untagged_index_reports_no_external_recording(tmp_path: Path) -> None:
"""`external_files == 0` is TRUE both for a repo that vendors nothing and for an
index built before gh#335 — `external_recorded` is what separates them, for the
same reason `coverage_recorded` exists. An unmeasured zero that reads as a
measured one is how a reader concludes "checked and fine" from "not checked".
Counting everything as first party on such an index is correct rather than a
fallback: a build below build version 32 EXCLUDED nested git trees outright, so
everything it holds really is first party.
@brief An index with no external column reports first-party counts and not-recorded.
@version 1
"""
db_path, _ = _indexed(tmp_path, _ours())
stats = q.graph_stats(db_path)
assert stats.files.indexed_files == 25
assert stats.files.external_files == 0
assert stats.files.external_recorded is False
Activity · 5 steps
test_directory_rollup_says_what_it_counts_and_lists_external_files
None test_external_provenance.test_directory_rollup_says_what_it_counts_and_lists_external_files(Path tmp_path)
The directory rollup lists what is INDEXED and never claims to be a tree census.
tests/test_external_provenance.py:456
Called by none
Calls _indexed, _ours, _theirs, directory_rollup, rollup_meaning, stamp_external_provenance
Checks
assert by_dir, "the rollup must produce rows for an index that holds files"assert roll.indexed_files == sum(e.indexed_files for e in roll.directories)assert counts == sorted(counts, reverse=True)assert sum(e.external_files for e in roll.directories) > 0, ("an external file must be COUNTED and annotated, never filtered out of the inventory" )assert "INDEXED" in note and "not a census of the tree" in noteassert "largest directory in the repository" in note, ("the reply must separate 'largest here' from 'largest in the repository'" )assert "not one subtraction" in note, ("it must NOT claim the coverage difference is a single arithmetic — two attempts at that " "sum both failed to reconcile" )assert rollup_meaning(0, 0, 0) == ""assert "not shown" in rollup_meaning(100, 5, 9)assert "not shown" not in rollup_meaning(100, 9, 9)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_directory_rollup_says_what_it_counts_and_lists_external_files → stamp_external_provenance → external_roots → dependency_roots |
| REQ-DDB-INDEX-005 | measured | test_directory_rollup_says_what_it_counts_and_lists_external_files → stamp_external_provenance |
| REQ-DDB-PIPE-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_directory_rollup_says_what_it_counts_and_lists_external_files → directory_rollup → connect |
| REQ-DDB-QUERY-002 | measured | test_directory_rollup_says_what_it_counts_and_lists_external_files → rollup_meaning |
| REQ-DDB-QUERY-003 | measured | test_directory_rollup_says_what_it_counts_and_lists_external_files → directory_rollup → has_columns |
Source · 61 lines
def test_directory_rollup_says_what_it_counts_and_lists_external_files(tmp_path: Path) -> None:
"""SIX SHELL CALLS TO REPLACE A DELETED TOOL. `list_files` has always inventoried the indexed
files, and the `list_files` TOOL was removed in the four-tool consolidation — so on mbedtls
2026-08-14 Q4 ran six `find … | wc -l` commands, 6 of that cell's 11 fallbacks, and still
missed the four marks it was computing them for.
THE ROLLUP MUST NOT READ AS A TREE CENSUS, and on this target that distinction inverts the
answer: mbedtls `tests/` holds 310 tracked files and 44 indexed ones, because most are
`.function` / `.data` fixtures no grammar handles. So the largest directory in the INDEX is
`library` and in the REPOSITORY is `tests`, and a reply offering the first as the second would
argue for a wrong answer — the same class as the two false-count rosters and the config
payload.
IT ALSO MUST NOT ASSERT AN ARITHMETIC IT DOES NOT HAVE. `coverage.indexed_files` is 443 where
the rollup is 527; I wrote the reconciliation as 527-41 and then as 527-41-259 and NEITHER
added up, because coverage also drops prose and documentation and those categories overlap. So
the note states the two DEFINITIONS instead. A stated sum that does not add up is worse than
none, and this test pins the definitions rather than the numbers for the same reason.
NON-FILTERING HOLDS HERE TOO: an external file is counted and annotated, never omitted, or the
rollup would report a smaller repository than the index holds.
"""
from clew.query import directory_rollup
from clew.query.corpus import rollup_meaning
db_path, root = _indexed(tmp_path, [*_ours(), *_theirs()], nested=("vendor/theirs",))
stamp_external_provenance(db_path, root)
roll = directory_rollup(db_path)
by_dir = {e.directory: e for e in roll.directories}
assert by_dir, "the rollup must produce rows for an index that holds files"
assert roll.indexed_files == sum(e.indexed_files for e in roll.directories)
## Largest first, so "which directory is biggest HERE" is the first row rather than a scan.
counts = [e.indexed_files for e in roll.directories]
assert counts == sorted(counts, reverse=True)
## THE EXTERNAL FILES ARE PRESENT AND ANNOTATED. The fixture indexes a vendored git tree, so
## some directory must carry a non-zero external count — omitting them would be the
## filtered-answer failure applied to the inventory.
assert sum(e.external_files for e in roll.directories) > 0, (
"an external file must be COUNTED and annotated, never filtered out of the inventory"
)
## THE SENTENCE IS THE LOAD-BEARING PART, and it must make both misreadings impossible.
note = roll.rollup_meaning
assert "INDEXED" in note and "not a census of the tree" in note
assert "largest directory in the repository" in note, (
"the reply must separate 'largest here' from 'largest in the repository'"
)
assert "not one subtraction" in note, (
"it must NOT claim the coverage difference is a single arithmetic — two attempts at that "
"sum both failed to reconcile"
)
## AND IT STAYS SILENT ON AN EMPTY INDEX rather than describing an absent file set.
assert rollup_meaning(0, 0, 0) == ""
## The cap is reported when it applies, never silently.
assert "not shown" in rollup_meaning(100, 5, 9)
assert "not shown" not in rollup_meaning(100, 9, 9)
Activity · 18 steps
test_graph_stats_counts_first_party_and_reports_external_beside_it
None test_external_provenance.test_graph_stats_counts_first_party_and_reports_external_beside_it(Path tmp_path)
graph_stats reports first party by default and names the external population.
tests/test_external_provenance.py:256
Called by none
Calls _indexed, _ours, _theirs, graph_stats, stamp_external_provenance
Checks
assert stats.files.indexed_files == 25, "the 12 vendored files are not this repo's"assert stats.files.files_with_symbols == 25assert stats.files.files_with_bodies == 25assert stats.files.external_files == 12assert stats.files.external_roots == ("vendor/theirs",)assert stats.files.external_recorded is True
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_graph_stats_counts_first_party_and_reports_external_beside_it → stamp_external_provenance → external_roots → dependency_roots |
| REQ-DDB-INDEX-004 | measured | test_graph_stats_counts_first_party_and_reports_external_beside_it → graph_stats → _symbol_provenance → records_provenance |
| REQ-DDB-INDEX-005 | measured | test_graph_stats_counts_first_party_and_reports_external_beside_it → stamp_external_provenance |
| REQ-DDB-MCP-001 | measured | test_graph_stats_counts_first_party_and_reports_external_beside_it → graph_stats → file_counts → meta_section |
| REQ-DDB-PIPE-005 | measured | test_graph_stats_counts_first_party_and_reports_external_beside_it → graph_stats → read_build_signature |
| REQ-DDB-PIPE-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_graph_stats_counts_first_party_and_reports_external_beside_it → graph_stats → connect |
| REQ-DDB-QUERY-003 | measured | test_graph_stats_counts_first_party_and_reports_external_beside_it → graph_stats → call_edge_counts → table_exists |
| REQ-DDB-QUERY-008 | measured | test_graph_stats_counts_first_party_and_reports_external_beside_it → graph_stats |
Source · 22 lines
def test_graph_stats_counts_first_party_and_reports_external_beside_it(tmp_path: Path) -> None:
"""The same invariance one layer up, where a consumer actually reads it. Asserted
against the file counts `graph_stats` COMPUTES rather than the coverage figures it
merely reads back, because those are two different mechanisms and only one of them
is exercised by the coverage test above.
@brief graph_stats file counts exclude external files and count them separately.
@version 1
"""
db_path, root = _indexed(tmp_path, [*_ours(), *_theirs()], nested=("vendor/theirs",))
stamp_external_provenance(db_path, root)
stats = q.graph_stats(db_path)
assert stats.files.indexed_files == 25, "the 12 vendored files are not this repo's"
assert stats.files.files_with_symbols == 25
assert stats.files.files_with_bodies == 25
assert stats.files.external_files == 12
assert stats.files.external_roots == ("vendor/theirs",)
assert stats.files.external_recorded is True
Activity · 9 steps
test_list_files_returns_external_files_annotated_not_filtered
None test_external_provenance.test_list_files_returns_external_files_annotated_not_filtered(Path tmp_path)
list_files must LIST external files, annotated, never filtered out.
tests/test_external_provenance.py:304
Called by none
Calls _indexed, _ours, _theirs, list_files, stamp_external_provenance
Checks
assert len(listed) == 37, "an external file is annotated, never withheld"assert owners["vendor/theirs/lib_0.c"] == "vendor/theirs"assert owners["src/mod_0.c"] == ""assert q.list_files(db_path, "vendor/*"), "a glob over the submodule still answers"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_list_files_returns_external_files_annotated_not_filtered → stamp_external_provenance → external_roots → dependency_roots |
| REQ-DDB-INDEX-005 | measured | test_list_files_returns_external_files_annotated_not_filtered → stamp_external_provenance |
| REQ-DDB-PIPE-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_list_files_returns_external_files_annotated_not_filtered → list_files |
| REQ-DDB-QUERY-003 | measured | test_list_files_returns_external_files_annotated_not_filtered → list_files → table_exists |
Source · 22 lines
def test_list_files_returns_external_files_annotated_not_filtered(tmp_path: Path) -> None:
"""THE NON-FILTERING GUARANTEE. Every aggregate in this file reports first party
by default; a query must not. An inventory that said "this repo contains 25 files"
while the index holds 37 is precisely the failure the emptiness notes exist to
prevent, and it is worse here than elsewhere because `list_files` is the tool a
reader uses to find out what the index covers.
@brief list_files includes external files and tags them.
@version 1
"""
db_path, root = _indexed(tmp_path, [*_ours(), *_theirs()], nested=("vendor/theirs",))
stamp_external_provenance(db_path, root)
listed = q.list_files(db_path)
owners = {entry.path: entry.external_root for entry in listed}
assert len(listed) == 37, "an external file is annotated, never withheld"
assert owners["vendor/theirs/lib_0.c"] == "vendor/theirs"
assert owners["src/mod_0.c"] == ""
assert q.list_files(db_path, "vendor/*"), "a glob over the submodule still answers"
Activity · 8 steps
test_only_a_directory_with_its_own_git_tree_is_external
None test_external_provenance.test_only_a_directory_with_its_own_git_tree_is_external(Path tmp_path)
A directory the repo declares as a submodule is detected; a copied-in one is not.
tests/test_external_provenance.py:139
Called by none
Calls _indexed, _ours, _theirs, external_roots, stamp_external_provenance
Checks
assert external_roots(root) == ["vendor/theirs"]assert rows["vendor/theirs/lib_0.c"] == "vendor/theirs"assert rows["vendor/copied/header_only.h"] is None, ("a copied-in third-party file with no git tree of its own IS first party — " "this repo committed it and owns it, and no name matching may say otherwise" )assert rows["src/mod_0.c"] is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_only_a_directory_with_its_own_git_tree_is_external → external_roots → dependency_roots |
| REQ-DDB-INDEX-005 | measured | test_only_a_directory_with_its_own_git_tree_is_external → stamp_external_provenance |
| REQ-DDB-PIPE-014 | catalog |
Source · 29 lines
def test_only_a_directory_with_its_own_git_tree_is_external(tmp_path: Path) -> None:
"""THE RULE, stated as a discrimination rather than as a match. Both directories
below are named `vendor/...`; only one is a declared dependency.
@brief External detection keys on the parent's gitlink, never on a directory name.
@version 2
"""
db_path, root = _indexed(
tmp_path,
[*_ours(), *_theirs(), ("vendor/copied/header_only.h", 4)],
nested=("vendor/theirs",),
)
assert external_roots(root) == ["vendor/theirs"]
stamp_external_provenance(db_path, root)
conn = sqlite3.connect(str(db_path))
try:
rows = dict(conn.execute(f"SELECT name, {EXTERNAL_ROOT_COLUMN} FROM path").fetchall())
finally:
conn.close()
assert rows["vendor/theirs/lib_0.c"] == "vendor/theirs"
assert rows["vendor/copied/header_only.h"] is None, (
"a copied-in third-party file with no git tree of its own IS first party — "
"this repo committed it and owns it, and no name matching may say otherwise"
)
assert rows["src/mod_0.c"] is None