Skip to content

test(cli): pin RollbackArgs flag surface + find_patches_to_rollback#71

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

test(cli): pin RollbackArgs flag surface + find_patches_to_rollback#71
Mikola Lysenko (mikolalysenko) wants to merge 2 commits into
tests/cli-contract-foundationfrom
tests/cli-parse-rollback

Conversation

@mikolalysenko
Copy link
Copy Markdown
Contributor

Summary

Locks in the rollback subcommand's public CLI contract and adds unit-test coverage for its pure helper.

  • New tests/cli_parse_rollback.rs — clap parser snapshot tests for RollbackArgs. Covers every long and short form, every default, the optional positional identifier (absent / UUID / PURL), --ecosystems CSV split, and a clap::error::ErrorKind::UnknownArgument failure path.
  • Inline #[cfg(test)] mod tests in src/commands/rollback.rs — five cases for find_patches_to_rollback (no identifier returns all, PURL match, PURL miss, UUID match, UUID miss).

Tests reach into the library surface via socket_patch_cli::Cli::try_parse_from(...); no binary spawn.

Stacked on #67 (foundation). Base is 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 — all 415 core + 5 cli lib + 24 new parser tests pass

Assisted-by: Claude Code:claude-opus-4-7

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
Add inline #[cfg(test)] mod tests for the pure helper
find_patches_to_rollback in commands/rollback.rs covering all five
identifier paths (None, matching PURL, missing PURL, matching UUID,
missing UUID).

Add tests/cli_parse_rollback.rs locking in the public clap surface of
RollbackArgs — every long and short form, every default, optional
positional identifier (absent / UUID / PURL), --ecosystems CSV split,
and the UnknownArgument failure path. These tests parse argv through
socket_patch_cli::Cli::try_parse_from so any breaking change to the
flag contract trips them in lock-step with CLI_CONTRACT.md.

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.

@mikolalysenko Mikola Lysenko (mikolalysenko) deleted the tests/cli-parse-rollback branch May 20, 2026 19:05
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