Skip to content

test(cli): pin RepairArgs flag surface (download-mode=file, gc alias)#75

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

test(cli): pin RepairArgs flag surface (download-mode=file, gc alias)#75
Mikola Lysenko (mikolalysenko) wants to merge 2 commits into
tests/cli-contract-foundationfrom
tests/cli-parse-repair

Conversation

@mikolalysenko
Copy link
Copy Markdown
Contributor

Summary

Adds parser-level integration tests for the repair subcommand to lock in its public clap contract. The key invariant guarded here is that --download-mode defaults to "file" for repair — diverging from every other command's "diff" default. repair restores legacy per-file blobs needed to apply any patch, so a silent flip to "diff" would break that path with no parser-level signal.

The gc visible alias is also exercised (both bare and with a flag) so a refactor that drops it is caught immediately. Every flag in the repair row of CLI_CONTRACT.md is now covered.

This PR is stacked on tests/cli-contract-foundation (#67).

Coverage

  • Defaults: cwd, manifest-path, dry-run, offline, download-only, json, and the divergent download-mode = "file".
  • Long and short flag forms for --dry-run / -d and --manifest-path / -m.
  • All three valid --download-mode values: file, diff, package.
  • gc alias defaults match repair defaults exactly.
  • gc alias accepts flags (--dry-run).
  • Unknown flag fails with clap::error::ErrorKind::UnknownArgument.

Test plan

  • cargo build --workspace --all-features
  • cargo test --workspace --all-features --lib --tests — 15 new tests pass, no regressions
  • cargo clippy --all-features --test cli_parse_repair -- -D warnings clean on the new file

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 a parser-level integration test that locks in the public clap contract
for the `repair` subcommand. The key assertion is that `--download-mode`
defaults to `"file"` — diverging from every other command's `"diff"`
default. `repair` restores legacy per-file blobs needed to apply any
patch, so a silent flip to `"diff"` would break that path with no
parser-level signal. The `gc` visible alias is also exercised (both bare
and with a flag) so a refactor that drops it is caught immediately.
Covers every flag in the repair row of CLI_CONTRACT.md plus an
unknown-flag failure case that pins the clap error kind.

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