Fix agent-help hidden-flag leak; make check-surface a real drift gate
Closes #539.
TL;DR
#539 asked to reconcile the committed .surface snapshot with scripts/check-cli-surface.sh, on the premise that the file had drifted from its generator and CI didn't catch it. Investigating, the premise doesn't hold: .surface is owned and enforced by a different generator, which it already matches exactly. So instead of regenerating the file, this PR fixes the two things that are actually wrong and turns the misleading check-surface target into a real gate.
What's actually going on
There are two independent surface generators, and they disagree:
scripts/check-cli-surface.sh (shell) | surface.SnapshotString (Go, github.com/basecamp/cli) | |
|---|---|---|
| Walks | --help --agent JSON | the Cobra command tree |
| Globals per subcommand | curated → salient only (post-#499) | full inherited globals |
Hidden flags (--assignee) | emitted | excluded |
--version leak (#368) | had it pre-#499 | never had it (--version is local, not inherited) |
| Output | ~7.6k lines | ~16.6k lines |
| Enforced by | nothing — check-surface just echoed a /tmp line count | TestSurfaceSnapshot (internal/commands/surface_test.go) |
The committed .surface is byte-identical (modulo trailing newline) to the Go generator's output. TestSurfaceSnapshot passes precisely because .surface == surface.SnapshotString(root), and that test is the CI catch #539 thought was missing. Cross-version compatibility is separately handled by check-surface-compat → check-cli-surface-diff.sh, entirely on the script side.
Regenerating .surface to the shell script's curated shape (the literal ask) would have:
- permanently reddened
TestSurfaceSnapshot(the two generators can't both own the file), - churned ~9k lines,
- forced ~9 false-drift baselines into
.surface-skill-driftfor globals (--jq,--agent,--profile) that do work on those subcommands — curation drops true information, and - enshrined an agent-help bug (below) as canonical surface.
What this PR changes instead (4 files, zero .surface churn)
1. Fix the agent-help hidden-flag leak (internal/cli/root.go)
The "2 additions" #539 noticed (FLAG basecamp recordings [list] --assignee) are a leak, not new surface. --assignee is MarkHidden with usage "Not supported — use reports assigned instead". emitAgentHelp surfaced it anyway because pflag's VisitAll visits hidden flags. Skip hidden flags at all three emission sites so agent-help matches text --help and the tree walker. Legitimate visible --assignee/--assignees flags on cards/todos are unaffected. Regression test in help_test.go.
2. Make check-surface a real gate (Makefile)
It regenerated to /tmp and echoed a count — caught nothing but a totally broken binary. Repoint it at TestSurfaceSnapshot (the authority) so it fails on drift and points at a new make update-surface regeneration target. check-surface-compat / the cli-surface CI job are untouched (they diff generated-vs-generated across versions and never read the committed file).
3. Idempotent regeneration (internal/commands/surface_test.go)
-update-surface wrote .surface without a trailing newline (stripping the POSIX one, creating churn). Add one so make update-surface is idempotent.
Verification
make check-surfacepasses, and bites when.surfacedrifts (pointing atmake update-surface).make update-surfaceis idempotent (16,586 lines, no diff).basecamp recordings --help --agentno longer emits--assignee; the shell script's output drops the 2 leak lines while keeping the 8 legit visible ones.TestSurfaceSnapshot,check-skill-drift,check-smoke-coveragegreen;bin/ciexits 0.
Follow-up note for #539
The shell script and .surface still legitimately differ on the curated-vs-full-globals axis, but no consumer cross-checks them, so it's benign. If we later want a single source of truth, the options are: (a) keep the Go generator as authority (status quo after this PR), (b) migrate the snapshot + compat gate onto the shell script and retire TestSurfaceSnapshot/.surface-breaking, or (c) reconcile the two generators in github.com/basecamp/cli. This PR takes (a) as the smallest correct step.
Summary by cubic
Fixes the hidden flag leak in agent help and turns check-surface into a real drift gate bound to TestSurfaceSnapshot. Also hardens drift detection to catch acknowledged-removal-only staleness and keeps update-surface idempotent, addressing #539 without churn.
-
Bug Fixes
- Agent help now skips hidden flags across all emission paths; strengthened
TestAgentHelpOmitsHiddenFlagsto assert success and verify bothflagsandinherited_flags.
- Agent help now skips hidden flags across all emission paths; strengthened
-
Refactors
check-surfacerunsTestSurfaceSnapshotand now fails when.surfacebyte-differs with no additions or unacknowledged removals (baselineNeedsRegen);make helpupdated.update-surfaceonly rewrites.surfacewhen the snapshot differs and no unacknowledged removals remain (shouldWriteBaseline), still writes on removal-only updates, and appends a trailing newline; addedTestShouldWriteBaselineandTestBaselineNeedsRegen.