Skip to content

cmd: add CLI tests - #823

Open
nisedo wants to merge 1 commit into
dev/baseline-test-fixesfrom
dev/cmd-cli-tests
Open

cmd: add CLI tests#823
nisedo wants to merge 1 commit into
dev/baseline-test-fixesfrom
dev/cmd-cli-tests

Conversation

@nisedo

@nisedo nisedo commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

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

  • add cmd/cli_test.go covering fuzz, init, and corpus clean command behavior
  • refactor flag registration into helper functions so tests can build fresh Cobra commands without mutating the global command instances

Coverage

  • fuzz positional-arg validation and completion suggestions
  • fuzz flag-to-config overrides and invalid log-level handling
  • fuzz early behavior for missing explicit config and default-config path
  • init platform validation, completion suggestions, config generation, and overwrite-decline path
  • corpus clean early validation for missing corpus configuration and missing corpus directory

Verification

  • go test ./cmd/...
  • go test -count=1 ./...

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review.

@nisedo

nisedo commented Mar 19, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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