Complete Workstream F: extend check-docs to cover CLI commands, wire into CI
All checks were successful
dev release / build (push) Successful in 1m6s

Two remaining pieces from the original report, both explicitly signed
off on:

1. Wire cargo run -p xtask -- check-docs into dev-release.yml as a
   fail-fast step ahead of the release build/test, so drift between
   api-schema.toml and the real API surface now fails CI instead of
   relying on local discipline.

2. Extend api-schema.toml and check-docs to cover the bread CLI's
   command surface (bread-cli/src/main.rs's Commands/ModulesCommand/
   HooksCommand enums) against README.md's "CLI reference" section,
   not just Lua bindings/IPC methods against Documentation.md. This
   was the specific blind spot that let modules audit, hooks
   install-shell/install-git, and events --tree drift out of README
   in the first place -- check-docs would not have caught that fix
   without this extension, since its prior scope never touched the
   CLI-vs-README relationship at all.

Extraction reuses the same deliberate-textual-scanning approach as
the existing Lua/IPC extractors: depth-tracked enum variant scanning,
clap's PascalCase->kebab-case rename convention, and a hardcoded
(TABLE_VARS-style) map of which top-level Commands variants delegate
to a nested subcommand enum (Modules->ModulesCommand,
Hooks->HooksCommand), producing dotted names like modules.audit.
CLI commands are versioned against the package version (Cargo.toml),
not API_VERSION, since the CLI was never part of that versioned
contract -- documented in api-schema.toml's header.

Verified check-docs actually catches CLI/README drift, not just
passes: temporarily deleted the "bread modules audit" line from
README.md, confirmed check-docs failed with the exact right message,
restored it. 4 new unit tests cover the extraction and cross-check
logic (11 total in xtask, up from 7).
This commit is contained in:
Breadway 2026-08-05 13:49:57 +08:00
parent da889d6f6a
commit a6973360bd
4 changed files with 459 additions and 64 deletions

View file

@ -69,37 +69,27 @@ cargo test --release --workspace
### Keeping the API docs honest
`Documentation.md`'s Lua API and IPC protocol sections are hand-written and
have drifted from the actual code before — there's a checked-in registry,
`api-schema.toml`, plus an `xtask` checker that catches it happening again.
`Documentation.md`'s Lua API/IPC protocol sections and README's CLI
reference are hand-written and have drifted from the actual code before —
there's a checked-in registry, `api-schema.toml`, plus an `xtask` checker
(`cargo run -p xtask -- check-docs`) that catches it happening again, and
it's enforced in CI (`dev-release.yml` fails the build on any drift).
Whenever you add, rename, or remove a `bread.*` Lua binding
(`breadd/src/lua/mod.rs`) or an IPC method (`breadd/src/ipc/mod.rs`):
(`breadd/src/lua/mod.rs`), an IPC method (`breadd/src/ipc/mod.rs`), or a
`bread` CLI command (`bread-cli/src/main.rs`):
1. Add/update/remove its entry in `api-schema.toml` to match.
2. Add/update the corresponding section in `Documentation.md` (a
`#### bread.<name>` heading for a Lua binding, or a row in the IPC
Methods table for an IPC method).
2. Add/update the corresponding section — a `#### bread.<name>` heading in
`Documentation.md` for a Lua binding, a row in `Documentation.md`'s IPC
Methods table for an IPC method, or a `bread <name>` line in `README.md`'s
"CLI reference" section for a CLI command.
3. Run `cargo run -p xtask -- check-docs` before committing. It fails with
a non-zero exit and a list of exactly what's out of sync — added but
undocumented, stale in the schema, or missing a doc heading/row — if
`api-schema.toml`, the code, and `Documentation.md` don't all agree.
`check-docs` is **not yet wired into CI** — it's a local, manually-run
check today, not an enforced gate. That's a deliberate, still-open gap
(not an oversight): CI pipeline changes get a separate review pass before
landing, same as any other workflow-file edit. Wiring `cargo run -p xtask
-- check-docs` into `dev-release.yml` (fail the build on drift) is the
natural next step whenever that review happens — until then, discipline
running it before committing is what keeps `api-schema.toml`, the code,
and `Documentation.md` in sync, not anything automatic.
Also note `check-docs`'s scope: it covers `bread.*` Lua bindings and IPC
methods against `Documentation.md` only. It does not cover the `bread`
CLI's subcommands against `README.md`'s hand-written CLI reference —
that's a separate, currently-unguarded copy of information (see
`README.md`'s "CLI reference" section) and has drifted before for exactly
the same reason `Documentation.md` used to.
undocumented, stale in the schema, or missing a doc line — if
`api-schema.toml`, the code, `Documentation.md`, and `README.md` don't
all agree. CI runs this too, so anything that slips past a local run
still fails the build rather than landing on `main`.
## CI