docs: say what the invocation scan actually matches

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.
This commit is contained in:
AleFlyX
2026-11-26 21:26:23 +08:00
parent 5958c62bcf
commit ce4cb1d200
2 changed files with 13 additions and 5 deletions

View File

@@ -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:

View File

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