Skip to content

test(cli): pin GetArgs flag surface, download/no-apply aliases, detect_identifier_type#76

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

test(cli): pin GetArgs flag surface, download/no-apply aliases, detect_identifier_type#76
Mikola Lysenko (mikolalysenko) wants to merge 2 commits into
tests/cli-contract-foundationfrom
tests/cli-parse-get

Conversation

@mikolalysenko
Copy link
Copy Markdown
Contributor

Summary

Locks in the get subcommand's public CLI contract with parser snapshot tests, and adds unit tests for the two pure helpers behind it: detect_identifier_type and select_patches. No behavior change to the binary.

Stacked on #67 (tests/cli-contract-foundation).

What's covered

tests/cli_parse_get.rs (27 tests) — every flag in the get table asserts its documented default + binding:

  • Positional identifier (required; missing triggers MissingRequiredArgument).
  • --org, --cwd, --id, --cve, --ghsa, --package/-p, --yes/-y, --api-url, --api-token, --save-only, --global/-g, --global-prefix, --one-off, --json.
  • --download-mode default = "diff" plus "package" and "file" accepted.
  • Hidden alias --no-apply proven equivalent to --save-only (contract-significant; widely used in existing scripts but doesn't appear in --help).
  • Visible alias download proven equivalent to get.
  • Unknown flag triggers UnknownArgument.

#[cfg(test)] mod tests in commands/get.rs (17 tests):

  • detect_identifier_type: UUID/CVE/GHSA/PURL detection, case-insensitivity for UUID + CVE + GHSA (load-bearing), bare package names + malformed CVE + empty string all map to None.
  • select_patches: free user single-free auto-select, paid user prefers most-recent paid over free for same PURL, paid user picks most-recent paid, paid user falls back to most-recent free when no paid is available, free user paid-filtered-out then single-free auto-select, free user multi-free JSON mode returns Err(1), empty input is Ok(vec![]). The interactive TTY path (free user, multi-free, non-JSON) is intentionally not tested — it calls dialoguer which requires a real TTY.

Verification

cargo build --workspace --all-features      # clean
cargo clippy --workspace --all-features -- -D warnings   # clean
cargo test --workspace --all-features --lib --tests      # 459 lib tests + 27 cli_parse_get tests pass

Test plan

  • cargo build --workspace --all-features clean
  • cargo clippy --workspace --all-features -- -D warnings clean
  • cargo test --workspace --all-features --lib --tests passes (17 new commands::get::tests + 27 new cli_parse_get tests, plus existing 415 + others)
  • --no-apply hidden alias exercised
  • download visible alias exercised
  • Required positional enforced via clap error-kind assertion

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
…t_identifier_type

Locks in the `get` subcommand's public CLI contract with parser snapshot
tests and unit-tests the pure helpers behind it. No behavior change.

- New tests/cli_parse_get.rs (27 tests) asserts every flag in the get
  table parses to its documented default and bound field: positional
  identifier, `--org`, `--cwd`, `--id`, `--cve`, `--ghsa`, `--package`/`-p`,
  `--yes`/`-y`, `--api-url`, `--api-token`, `--save-only`, `--global`/`-g`,
  `--global-prefix`, `--one-off`, `--json`, `--download-mode` (default
  `diff`, plus `package` and `file`). Exercises the hidden `--no-apply`
  alias for `--save-only` and the visible `download` alias for `get`.
  Pins the missing-positional and unknown-flag clap error kinds.
- New `#[cfg(test)] mod tests` in commands/get.rs (17 tests) covers
  `detect_identifier_type` (UUID/CVE/GHSA/PURL, case-insensitive for
  UUID+CVE+GHSA, plain package names + malformed CVE + empty string both
  None) and `select_patches` (free/paid x single/multi/empty, paid-wins,
  most-recent-paid, fallback to most-recent-free, JSON-mode rejection
  for multi-free). Interactive TTY path is intentionally skipped.

Verified: cargo build/clippy/test --workspace --all-features all clean
from the worktree (459 unit tests + 27 cli_parse_get tests pass).

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