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()):