fix(build): narrow independent-evidence test to genuine provenance (#4896)

#4927's _has_independent_semantic_evidence counted metadata and captured_at
as evidence, but extract.py attaches both to ordinary INFERRED mention
ghosts, so those ghosts would stop folding into their AST file-self twin and
proliferate as duplicates on real graphs. Keep only rationale, source_url,
author and contributor. Add a regression test that a metadata-only ghost
still folds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
safishamsiandClaude Opus 4.8 committed 2026-11-02 19:04:58 +00:00
1 parent 18813bbb41
commit cfd9846667
2 files changed
+24 -2

No files matched your search

+6 -2
View File
@@ -902,11 +902,15 @@ def _has_independent_semantic_evidence(node: dict) -> bool:
but such a fold discards the semantic record's independent explanation
and attribution. Keep these records distinct unless the same-source
(source_file, label) twin rule already matched them.
Only genuine provenance counts. `metadata` and `captured_at` are attached
to ordinary INFERRED mention ghosts by extract.py, so treating them as
evidence would stop those ghosts folding and let duplicates proliferate
on real graphs (#4896).
"""
return any(
node.get(field) not in (None, "", [], {})
for field in ("rationale", "source_url", "author", "contributor",
"captured_at", "metadata")
for field in ("rationale", "source_url", "author", "contributor")
)
+18
View File
@@ -314,3 +314,21 @@ def test_evidence_free_same_source_file_mention_still_folds():
assert _lost_saved_semantic_nodes(saved, [
{"id": n, **dict(g.nodes[n])} for n in g.nodes
]) == []
def test_metadata_only_mention_is_not_independent_evidence():
"""#4896: `metadata` and `captured_at` ride along on ordinary INFERRED
mention ghosts, so they must not count as independent provenance. A ghost
carrying only those still folds into its AST file-self twin instead of
surviving as a duplicate."""
meta_only = {**_mention("meta_ghost", "config.yaml", "config/config.yaml"),
"metadata": {"confidence": "INFERRED"}, "captured_at": "2026-11-02"}
saved = [meta_only]
ast = _ast_file("config_ast", "config/config.yaml")
g = build_from_json({"nodes": [ast, *saved], "edges": []})
assert "config_ast" in g and "meta_ghost" not in g
folded: dict[str, str] = {}
assert _lost_saved_semantic_nodes(saved, [
{"id": n, **dict(g.nodes[n])} for n in g.nodes
], folded=folded) == []
assert folded == {"meta_ghost": "config_ast"}