cmd: add CLI tests - #823
Conversation
|
@claude review |
There was a problem hiding this comment.
No bugs found — this is a clean, mechanical refactor plus new test coverage. However, all files are covered by CODEOWNERS so a maintainer should sign off.
Extended reasoning...
Overview
This PR adds a new test file (cmd/cli_test.go) with comprehensive CLI-layer tests for the fuzz, init, and corpus clean commands. To enable isolated testing without mutating global command instances, the flag registration in fuzz_flags.go, init_flags.go, and corpus_flags.go is refactored: each original addXxxFlags() function now delegates to a new addXxxFlagsToCommand(cmd) helper that accepts an arbitrary *cobra.Command. The original functions remain unchanged in behavior.
Security risks
None. The production code changes are purely mechanical (parameter extraction). The test file uses t.TempDir() for isolation, restores os.Stdin and working directory via t.Cleanup, and does not touch authentication, cryptography, or permissions.
Level of scrutiny
This is a low-risk change — test additions plus a straightforward refactor. The refactored functions are called in the same way from the same call sites, and the new test helpers are only used in _test.go. A quick human glance should suffice.
Other factors
All files in the repository are covered by the CODEOWNERS file (owned by @Xenomega, @anishnaik, @samalws-tob), so a maintainer should formally approve. The tests are well-structured, use require/assert appropriately, and cover edge cases like missing configs, invalid log levels, and user-decline of overwrite prompts.
Summary
Add focused Cobra command-layer tests for the cmd package.
Why
The command layer in cmd has real flag parsing, arg validation, completion, and early-run behavior, but it previously had no tests.
Changes
Coverage
Verification