Skip to content

Pin what a program prints with golden files - #75

Merged
aoreshkov merged 2 commits into
mainfrom
cli-kit-golden-program-surface
Nov 6, 2026
Merged

aoreshkov merged 2 commits into
mainfrom
cli-kit-golden-program-surface

Conversation

@aoreshkov

@aoreshkov aoreshkov commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Summary

GoldenFiles.assertSurface(root) renders a command tree, so it can't show what a Program adds: the argument-file line in help, the @* case in completion scripts, or the configuration it reads without passing settings again. A program with argument files on had no public way to pin what it really prints.

GoldenFiles.assertSurface(program) runs the program instead, with --help at each command and completion <shell>, and compares what it printed. Program.root becomes public so the testing module can walk the commands.

  • assertSurface(root) stays, for a test with no program to run. With argument files off, both forms read the same files.
  • A program whose tree lacks StandardOptions.completion gets no script files, because it never prints any. The tree form still writes them.
  • A page the program won't print fails and names its command line, and the other pages are still compared and attached as suppressed failures.

The ABI dumps change by additions only.

Testing

  • ./gradlew check is green on Windows. The bash completion and SIGTERM tests are skipped there, so they need this PR's Linux job.
  • New GoldenFilesTest cases: the two forms read the same files; argument files show in a program's files and fail the tree form; settings show with nothing more to pass; no completion command means no scripts, and a leftover one is an orphan; a page the program won't print fails by name.
  • Trial, not part of this diff: delva-cli's surface test switched to assertSurface(DelvaProgram.program) and built with -Pdelva.cliKitFromSource=true passed against its existing golden files unchanged. delva-cli can move to the new call once its pin reaches 0.5.0.

🤖 Generated with Claude Code

aoreshkov and others added 2 commits November 6, 2026 08:24
assertSurface(root) renders a command tree, so it can't show what a Program
adds: the argument-file line in help, the @* case in completion scripts, or
the configuration it reads. assertSurface(program) runs the program and
compares what it printed. Program.root becomes public so the testing module
can walk the commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aoreshkov
aoreshkov merged commit ec5e61a into main Nov 6, 2026
7 checks passed
@aoreshkov
aoreshkov deleted the cli-kit-golden-program-surface branch November 6, 2026 06:41
aoreshkov added a commit that referenced this pull request Nov 6, 2026
## Summary

`completion <shell>` uses no option's value, but three things from the
commands above it could stop it:

- a required option: `demo completion bash` exits 2 with `missing
required option --store`
- an invalid value in an inherited option's variable
- a constraint on a parent command, such as `ExactlyOne`

The parser already skipped settings for this command, so a broken
configuration file couldn't stop it. It now returns right after reading
the command's own command line, which covers all three and the settings
with one check. `Program` was already answering `completion` without a
handler.

`completion` is still held to its own command line: a missing or unknown
shell is a usage error, and so is an invalid value typed on it. Other
commands are held to everything as before.

There's no public API change.

## Testing

- `ProgramTest`: the new test covers all three cases and failed before
the fix with `missing required option --store`. It also checks that `go`
on the same programs still exits with a usage error. A second test
covers `completion`'s own command line.
- `./gradlew check` is green on Windows. The bash completion and SIGTERM
tests are skipped there, so they need this PR's Linux job.
- This PR and #75 touch nearby lines. A trial merge of the two has no
conflicts and passes `:cli-kit:check` and `:cli-kit-testing:check`,
again on Windows only.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant