Skip to content

test(cli): pin ScanArgs flag surface (batch-size=100, download-mode=diff)#74

Closed
Mikola Lysenko (mikolalysenko) wants to merge 2 commits into
tests/cli-contract-foundationfrom
tests/cli-parse-scan
Closed

test(cli): pin ScanArgs flag surface (batch-size=100, download-mode=diff)#74
Mikola Lysenko (mikolalysenko) wants to merge 2 commits into
tests/cli-contract-foundationfrom
tests/cli-parse-scan

Conversation

@mikolalysenko
Copy link
Copy Markdown
Contributor

Summary

Adds clap parser snapshot tests for the scan subcommand to lock in every flag, short form, and default. Two load-bearing defaults are explicitly asserted because they're silent-regression risks:

  • --batch-size default is 100 — downstream API batching depends on this.
  • --download-mode default is "diff" — this diverges from repair's default.

Coverage:

  • Every flag in the scan contract table (--cwd, --org, --json, --yes/-y, --global/-g, --global-prefix, --batch-size, --api-url, --api-token, --ecosystems, --download-mode).
  • Short-form variants for --yes and --global.
  • --ecosystems CSV split for multi-value and single-value inputs.
  • All three --download-mode values: diff, package, file.
  • --batch-size edge cases: 1, 500, 0 (parser-accepted), negative (rejected with ValueValidation/InvalidValue).
  • Unknown-flag failure asserts clap::error::ErrorKind::UnknownArgument.

No changes to scan.rs — it's all async + network-touching helpers, not unit-testable.

Stacked on #67 via tests/cli-contract-foundation.

Test plan

  • cargo build --workspace --all-features clean
  • cargo clippy --workspace --all-features -- -D warnings clean
  • cargo test --workspace --all-features --lib --tests — 21 new tests pass, full suite green
  • --batch-size default 100 explicitly asserted
  • --download-mode default "diff" explicitly asserted
  • --ecosystems CSV split verified
  • Unknown-flag failure asserts correct ErrorKind

Sets up the foundation for a comprehensive unit-test campaign on the
socket-patch CLI. No behavior change to the binary.

Two changes:

1. Expose the clap parser as a library so integration tests can verify
   the public CLI contract without spawning the binary:
   - new crates/socket-patch-cli/src/lib.rs hosting Cli, Commands,
     looks_like_uuid, and parse_with_uuid_fallback (extracted from main.rs)
   - Cargo.toml gains [lib] entry alongside the existing [[bin]]
   - main.rs is now a thin wrapper that delegates to the lib

2. De-duplicate the manifest-path resolution block that was copy-pasted
   into 5 commands (apply, rollback, list, remove, repair). New helper
   socket_patch_core::manifest::operations::resolve_manifest_path
   handles the absolute-vs-relative join in one place, with 3 unit tests.

3. New CLI_CONTRACT.md next to the crate documenting every subcommand,
   flag, default, alias, JSON shape, and exit code as semver-significant
   surface. Adds a comment block above pub enum Commands pointing to it
   so anyone editing the parser sees the contract reminder.

Verified: cargo build/clippy/test --workspace --all-features all clean
(415 unit tests pass, including 3 new resolve_manifest_path tests).

Foundation for follow-up PRs that add the per-command parser snapshot
tests and helper unit tests.

Assisted-by: Claude Code:claude-opus-4-7
…iff)

Adds clap parser snapshot tests for the `scan` subcommand to lock in
every flag, short form, and default. The two load-bearing defaults
(`--batch-size = 100`, `--download-mode = "diff"`) are explicitly
asserted to catch silent regressions. Covers CSV splitting of
`--ecosystems`, all three valid `--download-mode` values, and the
expected clap error kinds for negative batch sizes and unknown flags.

Assisted-by: Claude Code:claude-opus-4-7
@mikolalysenko
Copy link
Copy Markdown
Contributor Author

Squashed into #68. All tests from this PR are now part of the single combined commit on tests/cli-contract-foundation.

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