test(cli): pin GetArgs flag surface, download/no-apply aliases, detect_identifier_type#76
Closed
Mikola Lysenko (mikolalysenko) wants to merge 2 commits into
Closed
Conversation
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
0bd4f50 to
6cb84b8
Compare
…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
40b2cd6 to
0eb8ac6
Compare
6cb84b8 to
ef0deac
Compare
Contributor
Author
|
Squashed into #68. All tests from this PR are now part of the single combined commit on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Locks in the
getsubcommand's public CLI contract with parser snapshot tests, and adds unit tests for the two pure helpers behind it:detect_identifier_typeandselect_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:identifier(required; missing triggersMissingRequiredArgument).--org,--cwd,--id,--cve,--ghsa,--package/-p,--yes/-y,--api-url,--api-token,--save-only,--global/-g,--global-prefix,--one-off,--json.--download-modedefault ="diff"plus"package"and"file"accepted.--no-applyproven equivalent to--save-only(contract-significant; widely used in existing scripts but doesn't appear in--help).downloadproven equivalent toget.UnknownArgument.#[cfg(test)] mod testsincommands/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 toNone.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 returnsErr(1), empty input isOk(vec![]). The interactive TTY path (free user, multi-free, non-JSON) is intentionally not tested — it callsdialoguerwhich requires a real TTY.Verification
Test plan
cargo build --workspace --all-featurescleancargo clippy --workspace --all-features -- -D warningscleancargo test --workspace --all-features --lib --testspasses (17 newcommands::get::tests+ 27 newcli_parse_gettests, plus existing 415 + others)--no-applyhidden alias exerciseddownloadvisible alias exercised