Files
FabledScribe/tests/test_mcp_list_family.py
T
bvandeusenandClaude Fable 5 a8f35e465e
CI & Build / Python lint (push) Successful in 4s
CI & Build / Plugin hooks (push) Successful in 27s
CI & Build / TypeScript typecheck (push) Successful in 36s
CI & Build / integration (push) Successful in 1m34s
CI & Build / Python tests (push) Successful in 2m21s
CI & Build / Build & push image (push) Successful in 25s
refactor(plugin+tests): the last two parallel-family gaps — pageable list tools, one config preamble (#2278)
DRY pass 3's remainder. Both halves start from enumeration, because the task's
candidate list was hypotheses and the process requires counting before
proposing — and counting changed the answer twice.

## The list_* family: a limit with no offset

Enumerated all 19 `list_*` MCP tools first. They are genuinely heterogeneous —
8 take `project_id`, 6 take `limit`, six take no arguments at all — so a
common-parameter guard would invent a convention the API does not have, which
is the over-DRY trap (§5). One contract IS real: a `limit` without an `offset`
is a truncation with no continuation. The caller is told there are 250 results,
handed 50, and given no way to ask for the rest.

Two tools had it, and both were capped over a service that already accepted an
offset: `snippets_svc.list_snippets(offset=0)` was simply not exposed, and
`list_processes` passed a hardcoded `offset=0` into `query_knowledge`. The
capability existed one layer down in both; only the door was missing — the
missing-sibling shape exactly. Both now expose it.

`tests/test_mcp_list_family.py` guards it, with `list_tags` exempted for a
stated reason (a ranked top-N over a bounded vocabulary has no "rest" to page
into). Candidates derived, decision explicit, same design as test_mcp_auth —
plus the reverse checks: a stale exemption, and an offset with no limit, which
would page through an unbounded result set. Verified non-vacuous by running the
sweep against the pre-fix tree, where it fails naming both tools.

## The verb pairs: no finding, which is the finding

`preview`/`apply` and `dry_run`/`commit` do not exist anywhere in the 102
tools — those were guesses about a shape Scribe never adopted. `count_*` does
not exist either. Of the create/delete stems only `project_rule` lacks a
`delete_X`, and deliberately: a project rule IS a rule, `delete_rule` removes
it, and the docstring says so. `force` sits on 6 of 7 duplicate-gated creates;
the exception is `create_system`, whose gate is an exact normalized-NAME match
rather than a semantic near-match — forcing it would split one area's records
across two piles, which its own message explains. No guard added: it would
need a seven-entry exemption list to defend against a hypothetical. Recorded
on the leave-alone list instead, which the process asks for by name.

## The hook config preamble

Not 3 of 6 hooks as recorded — all FIVE carried their own copy, and of four
lines rather than two. The extra two are a guard treating an unexpanded
`${...}` placeholder as unset, so it is never sent as a garbage Bearer token:
precisely the correctness detail a sixth hook would omit with nothing failing
loudly. Now `scribe_config` in scribe_defs.sh, which also declares the two
names it owns. It sets globals rather than echoing, so a token never passes
through a subshell's output where xtrace or a log could catch it, and returns
a status so a caller can bail (`|| exit 0`) or continue degraded — the
session-context hook still owes its static floor when Scribe is unconfigured.

`check_plugin.py` now runs shellcheck with `-x`. Without it the shared helpers
were invisible: every variable they set read as unassigned and every bug inside
them went unlinted at the call site, which is the opposite of what sharing them
was for. All twelve fail-open scenarios still pass, and all five hooks were
probed live against the instance — prior_art and after_write both still name
canon, autoinject returns context, session_context serves 11k chars of rules,
sync_processes stays silent. Plugin 0.1.46 (#2209).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-24 01:28:07 -04:00

115 lines
5.0 KiB
Python

"""Cross-family contracts for the `list_*` MCP tools (#2278, shape 4).
Per-tool tests cover what each list tool does. Nothing covered what the FAMILY
owes its callers, which is where the missing-sibling shape hides: a capability
added to one member and not its neighbour changes no return value, so no
behavioural test can see it. Source inspection can.
WHAT THIS DELIBERATELY DOES NOT ASSERT. The 19 `list_*` tools are genuinely
heterogeneous — 8 take `project_id`, 6 take `limit`, and six take no arguments
at all (`list_projects`, `list_trash`, `list_rulebooks`, `list_design_systems`,
`list_repo_bindings`, `list_starter_role_groups`). Requiring a common parameter
across them would be inventing a convention the API does not have, which the
DRY process's over-DRY guard (§5) warns against by name: a wrong abstraction is
worse than the duplication. So this file asserts ONE contract, the one that is
a real promise rather than a shape coincidence.
THE CONTRACT: a `limit` without an `offset` is a truncation with no
continuation. The caller is told there are 250 results and handed 50, with no
way to ask for the rest. Both tools that had this were capped over a service
that already accepted an offset — `snippets_svc.list_snippets(offset=0)` was
simply not exposed, and `list_processes` passed a hardcoded `offset=0` into
`query_knowledge`. The capability existed one layer down in both cases; only
the door was missing.
As in `test_mcp_auth`, the CANDIDATES are derived and the DECISION is explicit.
Deriving the exemption too would make the contract follow a naming convention,
so any future `list_*` could opt itself out by accident.
"""
import ast
import pathlib
TOOLS_DIR = pathlib.Path(__file__).resolve().parents[1] / "src" / "scribe" / "mcp" / "tools"
# `limit` here caps a RANKED top-N, not a page into a corpus, so there is no
# "rest" to ask for — the 51st most-used tag is not what the caller wanted and
# an offset into that ordering answers no question. Anything added here needs a
# reason of that kind, not "it isn't paged yet".
_DELIBERATELY_UNPAGED = {
"list_tags", # most-used tags by count, over a bounded vocabulary
}
def _list_tools() -> dict[str, set[str]]:
"""{tool name: parameter names} for every `list_*` in the tools package."""
out: dict[str, set[str]] = {}
for path in sorted(TOOLS_DIR.glob("*.py")):
if path.name == "__init__.py":
continue
for node in ast.parse(path.read_text()).body:
if (
isinstance(node, (ast.AsyncFunctionDef, ast.FunctionDef))
and node.name.startswith("list_")
):
out[node.name] = {
a.arg for a in node.args.args
} | {a.arg for a in node.args.kwonlyargs}
return out
def test_the_tools_package_is_where_we_think_it_is():
"""If this fails the sweep below is silently checking nothing."""
tools = _list_tools()
assert len(tools) >= 15, f"found only {len(tools)} list tools — did the package move?"
def test_every_capped_list_tool_can_be_paged():
"""A `limit` promises a cap; without an `offset` it also imposes a ceiling."""
tools = _list_tools()
capped = {name for name, args in tools.items() if "limit" in args}
assert capped, "no list tool takes a limit — the sweep is not finding signatures"
unpageable = sorted(
name for name in capped
if "offset" not in tools[name] and name not in _DELIBERATELY_UNPAGED
)
assert not unpageable, (
f"these list tools cap their results with no way to page past the cap: "
f"{unpageable}. Each hands the caller a `total` it cannot reach. Add an "
f"`offset` (check the service first — it usually already takes one), or "
f"add the tool to _DELIBERATELY_UNPAGED with a reason saying why there "
f"is no 'rest' to ask for."
)
def test_the_unpaged_exemptions_still_exist():
"""A stale exemption is an exemption for nothing, and it hides the next
tool that inherits the name. Same reverse check `test_mcp_auth` runs on
its allow-lists."""
tools = _list_tools()
missing = sorted(_DELIBERATELY_UNPAGED - set(tools))
assert not missing, (
f"_DELIBERATELY_UNPAGED names tools that no longer exist: {missing}. "
f"Renamed or deleted — drop them from the set."
)
still_capped = sorted(
name for name in _DELIBERATELY_UNPAGED
if name in tools and "limit" not in tools[name]
)
assert not still_capped, (
f"these are exempted from paging but no longer take a `limit` at all, "
f"so the exemption is moot: {still_capped}."
)
def test_offset_never_appears_without_limit():
"""The inverse, and it is a real bug rather than a style point: an offset
with no cap pages through an unbounded result set, so page 2 of an
ever-growing list silently returns everything after the skip."""
tools = _list_tools()
bad = sorted(
name for name, args in tools.items()
if "offset" in args and "limit" not in args
)
assert not bad, f"these take an offset but no limit: {bad}"