Skip to content

test(cli): unit-test looks_like_uuid + parse_with_uuid_fallback#72

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

test(cli): unit-test looks_like_uuid + parse_with_uuid_fallback#72
Mikola Lysenko (mikolalysenko) wants to merge 2 commits into
tests/cli-contract-foundationfrom
tests/cli-parse-main

Conversation

@mikolalysenko
Copy link
Copy Markdown
Contributor

Summary

Locks in two of the most fragile undocumented surfaces in the
socket-patch CLI: the bare-UUID rewrite shortcut
(socket-patch <UUID>socket-patch get <UUID>) and the
top-level Cli parser. Until now nothing guarded either —
a flag rename or a subcommand-alias drop could land green and
break every shipped wrapper silently.

This PR is part of the CLI-contract unit-test campaign on top of
PR #67 (tests/cli-contract-foundation).

Coverage

src/lib.rs::tests (inline) — 13 tests

looks_like_uuid:

  • canonical lowercase, all-uppercase, mixed-case UUIDs all return true
  • 4-group and 6-group inputs return false
  • 8-4-4-4-13 and 7-4-4-4-12 group-length variants return false
  • non-hex characters in any group return false
  • empty string returns false
  • 32-hex-char string with no dashes returns false
  • bare dashes (----, five empty groups) return false

parse_with_uuid_fallback:

  • socket-patch <UUID> rewrites to Commands::Get { identifier }
  • socket-patch <UUID> --json forwards the flag to the synthesized get
  • socket-patch not-a-uuid returns the ORIGINAL clap error
    (InvalidSubcommand), no rewrite attempted
  • socket-patch list parses normally — fallback never runs
  • socket-patch get <UUID> already parses — no double-rewrite
  • socket-patch <UUID> --invalid-flag surfaces the original
    InvalidSubcommand error (not the rewrite's UnknownArgument)

tests/cli_parse_main.rs (integration) — 14 tests

Top-level error kinds:

  • no subcommand → DisplayHelpOnMissingArgumentOrSubcommand
  • --versionDisplayVersion
  • --helpDisplayHelp
  • unknown subcommand → InvalidSubcommand

Every subcommand name in the contract parses (Apply, Rollback,
Get, Scan, List, Remove, Setup, Repair) with the right
positional-arg requirements (Get/Remove need <identifier>;
Rollback's identifier is optional; the rest take none).

Visible aliases prove out:

  • socket-patch download <id> parses as Commands::Get
  • socket-patch gc parses as Commands::Repair

Contract sections locked in

  • CLI_CONTRACT.md — "Subcommands" table (all 8 names + the
    download / gc visible aliases)
  • CLI_CONTRACT.md — "Bare-UUID fallback" paragraph (the
    8-4-4-4-12 case-insensitive predicate and the rewrite shortcut)

Test plan

  • cargo build --workspace --all-features clean
  • cargo clippy --workspace --all-features -- -D warnings clean
  • cargo test --workspace --all-features --lib --tests — all pass
    (415 core + 17 cli lib + 14 cli_parse_main + e2e suites)

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)] coverage for the bare-UUID fallback in
src/lib.rs — case-insensitive shape predicate, the get-rewrite
shortcut, no-double-rewrite invariant, and original-error
preservation when the rewrite parse also fails. Add a new
tests/cli_parse_main.rs integration suite that locks down the
top-level Cli parser: --help / --version / no-subcommand /
unknown-subcommand error kinds, every subcommand name, and the
download/gc visible aliases.

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