Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(doc-drift): treat a reader-project path as uncheckable (#2802)
Amanac208ce04c26
diff --git a/docs/layers/DOC_DRIFT.md b/docs/layers/DOC_DRIFT.mdindex 681de97c2..16dc143b0 100644--- a/docs/layers/DOC_DRIFT.md+++ b/docs/layers/DOC_DRIFT.md@@ -103,6 +103,9 @@ finding's confidence, and Repowise never rewrites your documents.A path that exists on disk but sits outside the index (a test fixture, anexcluded directory) counts as uncheckable, not missing, so it is not reported.+A path the surrounding prose places in the reader's own project ("add this to+your project's `src/setupTests.ts`") is uncheckable the same way, since it was+never a claim about this repository.## Silencing a finding you mean to keepdiff --git a/packages/core/src/repowise/core/analysis/doc_drift/resolver.py b/packages/core/src/repowise/core/analysis/doc_drift/resolver.pyindex 4cad295c9..870545b15 100644--- a/packages/core/src/repowise/core/analysis/doc_drift/resolver.py+++ b/packages/core/src/repowise/core/analysis/doc_drift/resolver.py@@ -20,6 +20,16 @@ from .renderer import RendererMap, github_slug_HEADING_RE = re.compile(r"^#{1,6}\s+(.+?)\s*$")+# A narrow, explicit phrase set, not a fuzzy heuristic: "you can find it in+# `src/index.ts`" must still be checked, so a bare "your" is not enough on its+# own. Each phrase names the reader's own project, never this one.+_READER_PROJECT_RE = re.compile(+ r"\byour\s+(?:project|app|repo|own|codebase)\b"+ r"|\b(?:in|to)\s+your\b"+ r"|\byour\b[^.!?]{0,40}'s\b",+ re.I,+)+# Setext headings. ``Title`` over ``=====`` or ``-----`` is a heading, and# GitHub gives it an anchor exactly as it does an ATX one; recognising only# ``#`` reports every inbound link to a setext heading as broken.@@ -249,6 +259,26 @@ def _under_opaque(idx: RepoIndex, path: str) -> bool:return any(path == d or path.startswith(f"{d}/") for d in idx.opaque_dirs)+def _is_reader_project_reference(ref: DocReference) -> bool:+ """Whether *ref*'s own sentence places the path in the reader's project, not this one.++ ``s = ref.context.find(ref.raw)`` rather than ``ref.column``: ``context``+ is the source line stripped of leading whitespace, while ``column`` indexes+ the unstripped one, so slicing ``context`` by ``column`` directly would be+ off by exactly the amount of indentation a list item or a blockquote adds.+ A plain substring search sidesteps the mismatch, since ``context`` already+ strips consistently from both.++ Scoped to the current sentence (back to the nearest ``.``/``!``/``?``) so+ "This mirrors your project's layout. See ``src/gone.ts`` for details."+ still reports the real miss in its own, unrelated sentence.+ """+ idx = ref.context.find(ref.raw)+ preceding = ref.context[:idx] if idx != -1 else ref.context+ sentence_start = max(preceding.rfind("."), preceding.rfind("!"), preceding.rfind("?")) + 1+ return bool(_READER_PROJECT_RE.search(preceding[sentence_start:]))++def _resolve_path(idx: RepoIndex, ref: DocReference, is_guide: bool) -> Resolution:target = ref.targetif _exists(idx, target):@@ -261,6 +291,14 @@ def _resolve_path(idx: RepoIndex, ref: DocReference, is_guide: bool) -> Resolutiif _under_opaque(idx, target) or _under_opaque(idx, relative):return Resolution(ref, DriftVerdict.UNCHECKABLE, "inside-submodule")+ # A path the prose itself places in the reader's own project ("add this to+ # your project's `src/setupTests.ts`") is not a claim about this repository+ # at all, and must not even reach the anchoring rule below: `src`, `config`,+ # `app` and the like are exactly the top-level directories most repos have,+ # so such a path passes anchoring and falls through to a false MISSING.+ if _is_reader_project_reference(ref):+ return Resolution(ref, DriftVerdict.UNCHECKABLE, "reader-project")+# Anchoring. A reference is evidence about THIS repository only when it# carries a separator and its first segment names a directory the# repository actually has. Everything else is a file Repowise writes intodiff --git a/tests/unit/doc_drift/test_resolver.py b/tests/unit/doc_drift/test_resolver.pyindex b337751ee..fd1184a2f 100644--- a/tests/unit/doc_drift/test_resolver.py+++ b/tests/unit/doc_drift/test_resolver.py@@ -79,6 +79,64 @@ def test_foreign_first_segment_is_uncheckable(target: str):assert res.detail == "unanchored"+# ---------------------------------------------------------------------------+# Rule: a path the prose places in the reader's own project is uncheckable,+# before anchoring even runs (#2743)+# ---------------------------------------------------------------------------+++def _sentence_ref(context: str, raw: str, target: str | None = None) -> DocReference:+ """A reference whose ``context`` is a full sentence, not a bare marker.++ ``_ref`` above sets ``context="ctx"``, which carries no prose for the+ reader-project check to read, so these tests build the real shape.+ """+ return DocReference(+ DriftKind.PATH, raw, target or raw, "docs/architecture/ARCHITECTURE.md", 1, context+ )+++ "context,raw",+ [+ (+ "Add this to your project's `src/setupTests.ts`:",+ "src/setupTests.ts",+ ),+ (+ "Then add the plugin to your project's `config/app.config.ts`.",+ "config/app.config.ts",+ ),+ ],+)+def test_a_path_in_the_readers_own_project_is_uncheckable(context: str, raw: str):+ """Even though ``src``/``config`` are real top-level dirs here, these are not."""+ res = resolve(_index(), _sentence_ref(context, raw))+ assert res.verdict is DriftVerdict.UNCHECKABLE+ assert res.detail == "reader-project"+++def test_a_missing_path_on_a_neutral_line_still_reports():+ context = "See `src/index.ts` for the entry point, and `src/gone.py` which was removed."+ res = resolve(_index(), _sentence_ref(context, "src/gone.py"))+ assert res.verdict is DriftVerdict.MISSING+ assert res.detail == "no-candidate"+++def test_an_earlier_sentences_reader_project_phrase_does_not_leak_forward():+ """The check is scoped to the current sentence, not the whole line."""+ context = "This mirrors your project's layout. See `src/gone.py` for details."+ res = resolve(_index(), _sentence_ref(context, "src/gone.py"))+ assert res.verdict is DriftVerdict.MISSING+++def test_a_bare_your_with_no_recognised_phrase_is_still_checked():+ """'you can find it in ...' must not be swallowed by a bare 'your'."""+ context = "You can find it in `src/gone.py`."+ res = resolve(_index(), _sentence_ref(context, "src/gone.py"))+ assert res.verdict is DriftVerdict.MISSING++# ---------------------------------------------------------------------------# Rule 6: ambiguous is never reported as missing# ---------------------------------------------------------------------------