Skip to content

test(cli): pin ListArgs flag surface + run() error/empty/populated paths#77

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

test(cli): pin ListArgs flag surface + run() error/empty/populated paths#77
Mikola Lysenko (mikolalysenko) wants to merge 2 commits into
tests/cli-contract-foundationfrom
tests/cli-parse-list

Conversation

@mikolalysenko
Copy link
Copy Markdown
Contributor

Summary

Adds crates/socket-patch-cli/tests/cli_parse_list.rs to lock in the public
CLI contract for socket-patch list. This is the second branch in the stacked
CLI-contract test campaign on top of #67.

  • Parser tests pin every ListArgs flag (long + short), the defaults from
    CLI_CONTRACT.md (cwd = ".", manifest_path = ".socket/manifest.json",
    json = false), and assert unknown flags surface
    clap::error::ErrorKind::UnknownArgument.
  • Async run() tests cover the no-network branches against tempdirs:
    missing manifest (exit 1, plain + json), empty manifest (exit 0, plain +
    json), populated manifest (exit 0, plain + json), and absolute
    --manifest-path overriding --cwd.
  • Subprocess test invokes the compiled binary against a missing-manifest
    tempdir with --json and parses stdout to lock the missing-manifest JSON
    shape (status = "error", error = "Manifest not found", plus path),
    since run() writes to the real stdout and cannot be captured in-process.

list is the smallest of the manifest-reading commands and exercises all the
no-network JSON paths that remove and repair will reuse, so locking it
down first gives the rest of the campaign a clean reference shape.

Test plan

  • cargo build --workspace --all-features clean
  • cargo test -p socket-patch-cli --test cli_parse_list — 14/14 pass
  • cargo test --workspace --all-features --lib --tests — all green
  • Clippy on the new file produces no warnings (pre-existing warnings in
    tests/e2e_{npm,pypi,gem}.rs are unchanged and out of scope here)

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
Adds tests/cli_parse_list.rs covering the public contract for `socket-patch
list`:
- clap parser tests pin each ListArgs flag (long + short forms), assert the
  defaults from CLI_CONTRACT.md, and verify unknown flags surface
  ErrorKind::UnknownArgument.
- async run() tests exercise the no-network branches against tempdirs:
  missing manifest (exit 1, plain + json), empty manifest (exit 0, plain +
  json), populated manifest (exit 0, plain + json), and an absolute
  --manifest-path overriding --cwd.
- one subprocess test invokes the compiled binary against a missing-manifest
  tempdir with --json and parses stdout to lock the
  { status: "error", error: "Manifest not found", path: ... } shape, since
  run() writes to the real stdout and cannot be captured in-process.

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