From ce4cb1d200d0ebc53c98aee4bbf28dd6bdd61f64 Mon Sep 17 00:00:00 2001 From: AleFlyX <1449466458@qq.com> Date: Thu, 26 Nov 2026 21:26:23 +0800 Subject: [PATCH] docs: say what the invocation scan actually matches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The regex is named FENCED_COMMAND and its comment claims it covers fenced examples, but it runs over the whole page, so a prose line or a table row that starts an invocation matches too. That is the behaviour worth keeping — a table row is as copyable as a code block — so fix the name and the comment instead of narrowing the scan. Also record the one thing matches_api_path cannot do: a single-parameter route absorbs any literal in that slot, so `/api/books/nonexistent` matches `/api/books/{book_id}`. The surface carries route shapes, not value constraints. --- docs/tests/doc_facts.py | 6 ++++++ docs/tests/test_doc_contracts.py | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/tests/doc_facts.py b/docs/tests/doc_facts.py index 8b4ff7ead..c5ef7ea5a 100644 --- a/docs/tests/doc_facts.py +++ b/docs/tests/doc_facts.py @@ -139,6 +139,12 @@ def matches_api_path(documented: str, known: set[str]) -> bool: A documented path that is a strict segment prefix of a known path also matches, because docs legitimately name a mounted prefix as the surface root ("the ``/api/reading`` surface"). + + Known limit: a single-parameter route absorbs any literal in that slot, so a + documented ``/api/books/nonexistent`` matches the served + ``/api/books/{book_id}``. Distinguishing a wrong concrete id from a real one + would need the route's value constraints, which the surface does not carry; + this check answers "is there a route of this shape", not "is this id valid". """ documented_segments = [segment for segment in documented.split("/") if segment] for candidate in known: diff --git a/docs/tests/test_doc_contracts.py b/docs/tests/test_doc_contracts.py index ccd039771..6efbb4bca 100644 --- a/docs/tests/test_doc_contracts.py +++ b/docs/tests/test_doc_contracts.py @@ -32,9 +32,11 @@ COMMAND = re.compile( r"\bdeeptutor[ \t]+([a-z][a-z0-9_-]*)(?:[ \t]+([a-z][a-z0-9_-]*))?(?![a-z0-9_-])" ) -# Commands inside fenced examples are checked too — that is where readers copy -# them from, and it is most of the mentions on the site. Only lines that -# actually *invoke* the CLI count, so a path or a container name does not: +# A command mention counts when its line actually *invokes* the CLI. That +# covers fenced examples — where readers copy from, and where most mentions on +# the site live — and also prose lines and table rows that start an invocation +# the same way. Matching only the invocation position keeps a path or a +# container name out: # # deeptutor kb list → invocation (line start) # $ deeptutor kb list → invocation (shell prompt) @@ -44,7 +46,7 @@ COMMAND = re.compile( # the container name, `python` the # command, so this would otherwise # look like `deeptutor python`. -FENCED_COMMAND = re.compile( +COMMAND_INVOCATION = re.compile( r""" (?: ^[ \t]*(?:\$[ \t]+)? # line start, optional prompt @@ -104,7 +106,7 @@ def _documented_commands() -> list[tuple[str, str, str]]: continue found.append((relative, match.group(1), match.group(2) or "")) fenced = page.read_text(encoding="utf-8") - for match in FENCED_COMMAND.finditer(fenced): + for match in COMMAND_INVOCATION.finditer(fenced): if _describes_retired_mention(fenced, match.start()): continue if _is_schematic_mention(fenced, match.end()):