Title: test(cli): foundation for CLI-contract unit-test campaign by mikolalysenko · Pull Request #68 · SocketDev/socket-patch · GitHub
Open Graph Title: test(cli): foundation for CLI-contract unit-test campaign by mikolalysenko · Pull Request #68 · SocketDev/socket-patch
X Title: test(cli): foundation for CLI-contract unit-test campaign by mikolalysenko · Pull Request #68 · SocketDev/socket-patch
Description: Summary
Foundation PR for a comprehensive unit-test campaign on the socket-patch CLI. Stacked on #67 (so it can land alongside the per-package/diff pathways work). No behavior change to the binary. Follow-up PRs will be stacked on this branch and add the actual per-command tests in parallel.
Three changes:
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.
De-duplicate manifest-path resolution. The same 5-line absolute-vs-relative join block was copy-pasted across apply/rollback/list/remove/repair. New helper socket_patch_core::manifest::operations::resolve_manifest_path replaces all 5 copies. 3 unit tests cover the relative/absolute/dotted cases.
New crates/socket-patch-cli/CLI_CONTRACT.md documenting every subcommand, flag, default value, alias, JSON-output shape, and exit code as semver-significant surface. Spells out the bump policy (rename a flag → MAJOR; add an optional flag → MINOR; …) and how to invoke scripts/version-sync.sh afterward. A 4-line comment block above pub enum Commands points readers at it.
Why now
The CLI crate currently has zero unit tests under src/ — only network-dependent tests/e2e_*.rs suites gated behind --ignored. A flag rename, a default change, or a JSON key drift could land green and silently break every shipped wrapper (npm @socketsecurity/socket-patch, pypi socket-patch, cargo, prebuilt binaries). This PR lays the groundwork; the follow-up PRs will lock in every flag and helper.
What lands later (stacked on this branch)
10 parallel test PRs:
tests/cli-parse-main — looks_like_uuid + parse_with_uuid_fallback (the bare-UUID fallback no test guards today)
tests/cli-parse-output — format_severity, color, confirm
tests/cli-parse-ecosystem-dispatch — partition_purls
tests/cli-parse-apply — every ApplyArgs flag + verify_status_str + result_to_json
tests/cli-parse-rollback — every RollbackArgs flag + find_patches_to_rollback
tests/cli-parse-get — every GetArgs flag, download visible alias, hidden --no-apply alias, detect_identifier_type, select_patches
tests/cli-parse-scan — every ScanArgs flag, --batch-size default = 100
tests/cli-parse-list — every ListArgs flag + async run tests (missing/empty/populated manifest)
tests/cli-parse-repair — every RepairArgs flag, gc visible alias, pin --download-mode default = file (the divergent one)
tests/cli-parse-remove-setup — both RemoveArgs/SetupArgs flags + async error-path JSON shape tests
Each will be a sibling PR targeting 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 — 415 unit tests pass (was 412; +3 from resolve_manifest_path tests)
cargo test --workspace --all-features --no-run — all 8 e2e test binaries still compile
Smoke: socket-patch download --help, socket-patch gc --help, socket-patch get --no-apply
Open Graph Description: Summary Foundation PR for a comprehensive unit-test campaign on the socket-patch CLI. Stacked on #67 (so it can land alongside the per-package/diff pathways work). No behavior change to the binary....
X Description: Summary Foundation PR for a comprehensive unit-test campaign on the socket-patch CLI. Stacked on #67 (so it can land alongside the per-package/diff pathways work). No behavior change to the binary....
Opengraph URL: https://github.com/SocketDev/socket-patch/pull/68
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:f0269d80-2278-b5d9-9abb-9008a881a839 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A790:3BD8F2:18631CA:21920CF:6A4F232E |
| html-safe-nonce | 020ca3b921d00a13f4fd4074c8357824b69242dc05f0294ddc96ae0bb554a6b5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzkwOjNCRDhGMjoxODYzMUNBOjIxOTIwQ0Y6NkE0RjIzMkUiLCJ2aXNpdG9yX2lkIjoiNjU4MDIyNTI4MDM2NjgxMzk5OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b2a5913f862758e7e21905aedcb8913a599a1946801aafd23715b33fbcd79e57 |
| hovercard-subject-tag | pull_request:3711872675 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/SocketDev/socket-patch/pull/68/files |
| twitter:image | https://avatars.githubusercontent.com/u/231686?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/231686?s=400&v=4 |
| og:image:alt | Summary Foundation PR for a comprehensive unit-test campaign on the socket-patch CLI. Stacked on #67 (so it can land alongside the per-package/diff pathways work). No behavior change to the binary.... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/SocketDev/socket-patch git https://github.com/SocketDev/socket-patch.git |
| octolytics-dimension-user_id | 69326764 |
| octolytics-dimension-user_login | SocketDev |
| octolytics-dimension-repository_id | 1093661456 |
| octolytics-dimension-repository_nwo | SocketDev/socket-patch |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1093661456 |
| octolytics-dimension-repository_network_root_nwo | SocketDev/socket-patch |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b8f23afb982271f1b22258a94aede67a6b77760 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width