Skip to content

make check-docs passes with a stale reference fragment for a deleted command: gen-docs writes but never prunes #795

Closed

Description

@scttfrdmn

Found while removing the alerts command for #783.

gen-docs writes one fragment per command into docs-gen/ and make check-docs
then runs git diff --exit-code docs-gen/. That catches a fragment whose
content drifted. It does not catch a fragment whose command no longer
exists
, because nothing deletes it:

$ make check-docs
go run . gen-docs --out docs-gen
wrote 53 reference fragments to docs-gen      # was 54
git diff --exit-code docs-gen/ || { ... }
$ echo $?
0                                             # passed

$ git ls-files docs-gen/ | grep alerts
docs-gen/alerts.md                            # still tracked, still shipped

The count dropped from 54 to 53 and the gate was still happy. docs-gen/alerts.md
was neither rewritten nor removed, so there was no diff to detect — and published
reference docs would have kept describing spawn alerts create|list|delete|history
after the command was deleted.

That is worse than ordinary staleness: a user reading the docs gets a command
that does not exist, and the gate whose job is "docs match the CLI" reports
success.

Why the obvious fix is not quite enough

Making gen-docs empty docs-gen/ before writing would fix this case, but it
should also fail loudly rather than silently delete: a run that produces 0
fragments because the binary failed to enumerate commands would wipe the
directory and the git diff would then correctly fail — noisy, but only after
the damage. Better to assert a plausible floor, the way
scripts/nested-modules.sh refuses to pass on an empty discovery.

Suggested

  1. Have gen-docs remove docs-gen/*.md that it did not just write, and report
    each removal by name so a deletion is visible in CI output rather than only
    in a diff.
  2. Refuse to prune when the generated set is implausibly small — a discovery that
    finds almost nothing is broken, not a repo with almost no commands.
  3. Gate it: a test that the set of docs-gen/*.md matches the command set from
    the cobra tree exactly, in both directions. The current check is one-way
    (every generated file matches its content) and this issue is the other
    direction (every file corresponds to a live command).

Point 3 subsumes 1 and 2 and is the one I would do — a set-equality assertion
cannot pass while the two sides disagree, which is what both halves are really
asking for.

Related: #792 (the Tier 0 harness running a stale binary), the same shape one
layer up — a check that validates an artifact rather than re-deriving it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions