cli: golden corpus recorded from the base binary
TestCLIGolden derives its cases from the command tree, records them from the fork point 7f4bdf3a (-record -base, every case run twice) and replays them against this tree's binary. 155 cases, 9 skipped; agent and adopt are Golden.Skip because they act before reading -h.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
clireg_golden_test.go+767 −0commands.go+9 −2testdata/clireg-golden.jsonl+155 −0
Intent
<task-notification> <task-id>a4abb02b71cd5d717</task-id> <tool-use-id>toolu_01WVGY93yrnWcR4faGWSNMff</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/27979b8d-cc90-4f50-88f6-87ba41433627/tasks/a4abb02b71cd5d717.output</output-file> <status>completed</status> <summary>Agent "Implement Task 2 main from tree" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Task 2 is done and committed as one commit, `e7c1c945ee4adeb74eac421373b62c1d7b9ef9ac` (`cli: main dispatches from the command tree`). It printed the packed-refs.lock error, but `git log -1` and the branch both point at it and the tree is clean. All the tests you listed pass. The census tests in `internal/provision` now fail, as the plan expects until Task 9 (details at the end). **What changed** (worktree `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/cli-registry-words`) - **`commands.go` (new):** `commandRoot()` builds the tree once, on first use. Every top-level word that has subcommands is one leaf calling today's dispatcher unchanged. - The root's `Fallback` prints usage to stderr and exits 2. - `help` is one leaf with aliases `-h` and `--help`. - `version` is a branch: child `target`, plus an unnamed default leaf that prints the build id on absent, flag or word. - The `__` bodies moved over verbatim. - The two shim words are built from `cgroup.Shims`, sorted, and panic if run. - **`main.go`:** the switch and the `__` checks are gone; `main()` now calls `clireg.Dispatch` and then the update hint. - **`update.go`:** `noHintVerbs` is deleted. `maybeUpdateHint(ran []*clireg.Node)` returns early if any node on the path has `NoUpdateHint`; the rest of the function is unchanged. - **`internal/cgroup/shim.go`:** new `Shims` map, and `RunShimIfRequested` dispatches from it. `TestShimsMapIsTheSwitch` added. - **Tests:** `commands_test.go` covers tree validity, the top-level word list and the hint per path. `canary_test.go` and `update_test.go` now use the path form. - **Projection:** `cli_projection_test.go` holds `TestCLIProjection` with `-update`, which writes `parity/cli.tsv`. `make parity-doc` now runs it first. - **Docsite and parity:** `internal/docsite/cliscan.go` is deleted and `internal/docsite/clinames.go` adds `TopLevelNames`. The docsite tests and `internal/parity/repo_test.go` read `../../parity/cli.tsv`. **How the channels/releases hint is kept:** `runChannelsTop` and `runReleasesTop` return true when they ran `resign`, `digests`, `retention` or `authorize`. The leaf stores that in `subVerbSkipsHint` (`commands.go:40`, `:139`, `:149`), and `main.go:41` skips `maybeUpdateHint` when it is set. Before, those four sub-verbs returned from `main()` before reaching the hint, so the result is the same. Task 5 deletes the variable once they are nodes with `NoUpdateHint`. **Tests run** - `go build ./...`: pass. - `go vet` on `.`, `internal/cgroup`, `internal/docsite`, `internal/parity` and `internal/clireg`: clean. `gofmt -l`: nothing. - `go test . -run 'TestCommandTree|TestTopLevelWords|TestUpdateHint|TestCanary|TestUpdate|TestCLIProjection'`: pass. - `go test ./internal/cgroup/ ./internal/docsite/ ./internal/parity/ ./internal/clireg/`: pass. - `TestMovesCopy*`, `TestMovesApproved*` and `TestPendingCopy*` also pass; that gate scans string literals in main.go. **Spot check:** base is the fork point `7f4bdf3a`, both binaries built with `-buildvcs=false`, run under `env -i`, with an empty HOME and an empty working directory. Every case matched. | args | stdout | stderr | exit | exit; bytes out, err | |---|---|---|---|---| | (bare) | same | same | same | 2; 0, 7460 | | help / -h / --help | same | same | same | 0; 7460, 0 | | version / version foo | same | same | same | 0; 11, 0 | | zz | same | same | same | 2; 0, 7460 | | channels -h / releases -h | same | same | same | 0; 0, 722 | | apps / apps zz | same | same | same | 1; 0, 6816 | | system | same | same | same | 2; 0, 4735 | The base worktree was removed and the scratch directory deleted. **Top-level lists:** `docsite.TopLevelCommands("main.go")` at base and `TopLevelNames` on the new `parity/cli.tsv` give the same list (checked with `diff`): `accounts add adopt agent analytics apps assets auth availability billing bootstrap canary channels config console db deploy devbox domains economics edge email env errors explain features fleets gate geo help instance-control instance-exec instance-exit instance-probe instance-stop instances ledger logs move ops pipeline promote proof protection ratelimit relay release-keygen releases remove restart rollback route routes run schedule secrets services ship sidecars skills status steering store system update version vet` **Decisions the plan did not settle** 1. **Audience where the parity rows are mixed:** I went by the most customer-facing status present. - `ops`, `status` and `system` have only operator and box-local rows, so I made them Operator (`commands.go:166,167,169`). - `devbox` (box-local and cli-only), `relay` (box-local, gap, operator), `move` (gap, operator) and `instances` are Customer, because each has at least one customer-status row (`:103,:126,:168`). - `proof` and `remove`/`route`/`add` are BoxLocal; `billing` and `economics` are Operator. - Words with no parity row (`agent`, `adopt`, `instance-*`, `remove`, `route`) are BoxLocal; `__drain-call` is Internal. 2. **The hint test can't call `Dispatch` without running handlers**, so `commands_test.go:59` copies the tree with every `Run` and `Fallback` made inert and dispatches that copy. 3. **`parity/cli.tsv` format:** two `#` comment lines, then a header line `id audience effect scope tool flags enums` (`cli_projection_test.go:31-33`). `TopLevelNames` skips `#` lines and requires the header first (`internal/docsite/clinames.go:40`). 4. **`Makefile parity-doc`** runs the test and the generator as two recipe lines rather than joined with `&&`. Make stops at the first failure, so the effect is the same. 5. **Golden skips:** - The shim words: "the cgroup shim, dispatched before main" (`commands.go:205`). - The `__` words: "plumbing". - The bare forms of edge, agent, adopt, bootstrap and instance-*: "starts a daemon or touches the box". 6. **`TestCanaryIsDispatchedNotStubbed`** now only checks that `canary` is in the tree and that something runs for it. It can no longer check for "not implemented". Task 5 tightens it. 7. **Test message wording:** the failure messages in `internal/parity/repo_test.go` now say "the binary dispatches" instead of "main.go dispatches". **Left for later** - `docs/parity.md:9` and `internal/parity/page.go:30` still say "checked against main.go". That is generated page copy, so I left it for Task 8. - The census tests in `internal/provision` fail, as the plan expects (the census is Task 9): - The record-write census: `main.go:main` is now stale, and `commands.go:buildCommandRoot [lit:instances,lit:sidecars]` is an unlisted write site. - `TestPlan14RootReadCensus`: `update.go:maybeUpdateHint` changed, and so did the root envelopes for `.`, `internal/cgroup` and `internal/clireg`. Task 9's CLAIMS file needs to cover them.</result> <usage><subagent_tokens>131945</subagent_tokens><tool_uses>53</tool_uses><duration_ms>722568</duration_ms></usage> </task-notification>
clireg_golden_test.goLoading diff…
commands.goLoading diff…
testdata/clireg-golden.jsonlLoading diff…