Skip to content

Commit 2a226f0

Browse files
committed
refactor: sweep remove.rs and repair.rs (#1875)
Assisted-by: Claude Code:claude-opus-5-5
1 parent 3c5edeb commit 2a226f0

3 files changed

Lines changed: 41 additions & 4 deletions

File tree

‎coverage/files.tsv‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ crates/socket-patch-cli/src/commands/list.rs 1102 audit-cli-tests c8e26f6 2026-1
1313
crates/socket-patch-cli/src/commands/lock_cli.rs 596 audit-cli-tests c8e26f6 2026-10-29 PR #1864 acquire_or_emit should take &GlobalArgs (all 5 callers pass the same fields); move report_lock_failure here from agent_download; inline emit, waiting_message, held_hint, held_message; ~30 comment lines (history L30, L161, L313-L315, L543-L547; lifecycle essay L34-L47 belongs in core apply_lock); 3 subset tests, 1 doc overclaim; T09
1414
crates/socket-patch-cli/src/commands/mod.rs 675 audit-cli-tests c8e26f6 2026-10-29 PR #1864 move `mod user_patches` (L675) up; move vendor_state_lenient (1 caller, list text) to list.rs; global_scope_flag (L296-L302) duplicates ui::global_scope_arg and drifted (--global vs --global-prefix when both set); PatchRecord L388-L396 -> ledgers::uuid_only_record; weak tests: one asserts only .contains("--mode"), 2 only is_err(); T14
1515
crates/socket-patch-cli/src/commands/pypi_reinstall.rs 206 audit-cli-tests c8e26f6 2026-10-29 PR #1864 clean (pypi_name L65-L70 hand-splits the purl: A14)
16-
crates/socket-patch-cli/src/commands/remove.rs 2184 audit-cli-tests c8e26f6 2026-10-29 - split 924-line run (L325-L1248); inline emit_not_found, hosted_unwind_error, HostedUnwindError newtype; hosted event built twice (L893, L1679), kept-exit tail twice (L1235, L1822); rename print_hosted_leg_warnings; 6 println!(to_pretty_json); ~90 comment lines (history, bare #refs, stale L1936); fake test dry_run_footer_matches_repair; T16 T17 T19 T20
17-
crates/socket-patch-cli/src/commands/repair.rs 1349 audit-cli-tests c8e26f6 2026-10-29 - drop noun: ArtifactNoun param (always BLOB in prod, 5 fns); inline format_found_missing; type the (String,String,String) vendor refs; socket_dir computed twice (L165, L497); ~45 comment lines (history L31-L36, L202-L211, L500-L505; broken wrap L997); tautological HOSTED_ONLY_REASON assert (L791); 3 duplicate tests (L1115/L1188, L1159/L872); T17 T19 T20
16+
crates/socket-patch-cli/src/commands/remove.rs 2184 audit-cli-tests c8e26f6 2026-10-29 PR #1875 split 924-line run (L325-L1248); inline emit_not_found, hosted_unwind_error, HostedUnwindError newtype; hosted event built twice (L893, L1679), kept-exit tail twice (L1235, L1822); rename print_hosted_leg_warnings; 6 println!(to_pretty_json); ~90 comment lines (history, bare #refs, stale L1936); fake test dry_run_footer_matches_repair; T16 T17 T19 T20
17+
crates/socket-patch-cli/src/commands/repair.rs 1349 audit-cli-tests c8e26f6 2026-10-29 PR #1875 drop noun: ArtifactNoun param (always BLOB in prod, 5 fns); inline format_found_missing; type the (String,String,String) vendor refs; socket_dir computed twice (L165, L497); ~45 comment lines (history L31-L36, L202-L211, L500-L505; broken wrap L997); tautological HOSTED_ONLY_REASON assert (L791); 3 duplicate tests (L1115/L1188, L1159/L872); T17 T19 T20
1818
crates/socket-patch-cli/src/commands/rollback.rs 6525 audit-cli-tests c8e26f6 2026-10-29 - split run (1,214 lines) and rollback_patches_inner (826); 4 open-coded error branches (L1533,L1609,L1758,L2565) -> emit_rollback_error; 7 println!(to_pretty_json); Identifier(None) test-only; inline verify_rollback_status_camel, not_installed_event; move remove's helpers to ui/hosted_unwind; ~120 comment lines; fake test L5475; T08 T13 T22 C24
1919
crates/socket-patch-cli/src/commands/scan/discovery.rs 2571 audit-cli-tests c8e26f6 2026-10-29 - inline candidate_supersedes (L507) and severity_order wrapper (L573); local shell_word -> ui::shell_word (T18); delete 5 severity_order tests (copy core ranking.rs); move candidate_supersedes, unsupported_layout_warnings tests to core; drop 2 pub use shims (L49, L429); ~35 comment lines; nested_project_skips -> scan/hosted.rs (C11)
2020
crates/socket-patch-cli/src/commands/scan/gc.rs 1840 audit-cli-tests - -
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[agent] 2026-10-30: architecture refactor (sweep)
2+
3+
`main` @ `5ca5623`. The previous run was structural, so this run was a sweep. There was no maintainer steering, and no PR of mine merged or closed. The next audited, unswept rows were `cli/src/commands/remove.rs` and `repair.rs`. No open PR touches either file (`rollback.rs`, the next row, is in #1864).
4+
5+
**PR:** [#1875](https://github.com/SocketDev/socket-patch/pull/1875), ready for review. CI and Bugbot are pending.
6+
7+
### Per file
8+
- **`remove.rs`:**
9+
- 2 fns inlined (`emit_not_found`, `hosted_unwind_error`), and 1 newtype deleted (`HostedUnwindError`).
10+
- The `hosted_reverted` event and the kept-exit tail are each built once now, by `hosted_reverted_event` and `kept_exit_code`.
11+
- Renamed `print_hosted_leg_warnings` to `print_run_warnings`.
12+
- 6 envelopes now go through `ui::print_json`, and 2 warning literals use `RunWarning::new`.
13+
- About 15 comment lines removed.
14+
- 1 can't-fail test deleted. 1 test now asserts exact lines instead of `.contains`.
15+
- Net: production −62, tests +4.
16+
- **`repair.rs`:**
17+
- The always-`BLOB` `noun` parameter is dropped from 5 formatters.
18+
- About 35 comment lines removed.
19+
- 1 tautological assert and 2 duplicate multibyte tests deleted.
20+
- 2 offline tests merged into 1 that covers the wet and dry runs, shown red→green by dropping the `!offline` conjunct.
21+
- Net: production −52, tests −108.
22+
- **Total:** +188 / −406.
23+
24+
### Not done
25+
- **The split of remove's 924-line `run`:** too big for a sweep.
26+
- **T16, T17, T19, T20:** structural.
27+
- **The typed vendor-reference tuple:** it lives in `vendored_backend/repair.rs`.
28+
29+
### Merges recorded
30+
None.
31+
32+
### Lessons
33+
- Before deleting a single-caller formatter's test, check that the wording it pins is covered somewhere else. `format_found_missing` stayed for that reason.
34+
- `print_json(&env.to_value())` is byte-identical to `to_pretty_json()` only because the workspace builds `serde_json` with `preserve_order`.

‎register/90-refactor.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
### Refactor routine
2-
_Last updated 2026-10-30T01:50Z · main @ 5ca5623_
2+
_Last updated 2026-10-30T03:30Z · main @ 5ca5623_
33

44
#### In flight
55
| PR | Kind | Scope | State |
@@ -9,6 +9,7 @@ _Last updated 2026-10-30T01:50Z · main @ 5ca5623_
99
| [#1849](https://github.com/SocketDev/socket-patch/pull/1849) | structural | A01 [#1832](https://github.com/SocketDev/socket-patch/issues/1832): `utils/cargo_build_cache.rs` | ready; CI and Bugbot green |
1010
| [#1864](https://github.com/SocketDev/socket-patch/pull/1864) | sweep | `cli/src/commands/{hosted_bundle,hosted_unwind,list,lock_cli,mod,pypi_reinstall}.rs` (+ dead branch in `rollback.rs`) | ready; CI (82 checks) and Bugbot green |
1111
| [#1870](https://github.com/SocketDev/socket-patch/pull/1870) | structural | A27 [#1869](https://github.com/SocketDev/socket-patch/issues/1869): `api/client.rs`, one serve GET and one vendor retry loop | ready; CI (82 checks) and Bugbot green |
12+
| [#1875](https://github.com/SocketDev/socket-patch/pull/1875) | sweep | `cli/src/commands/{remove,repair}.rs` | ready; CI and Bugbot pending |
1213

1314
#### Merged
1415
_None._
@@ -23,7 +24,7 @@ Structural candidates, scored `3·B + 2·U + 2·D + 2·C − risk`:
2324

2425
A02 [#1833](https://github.com/SocketDev/socket-patch/issues/1833) moved to the fixer's #1866. T03 [#1837](https://github.com/SocketDev/socket-patch/issues/1837) stays at 4, A05 [#1844](https://github.com/SocketDev/socket-patch/issues/1844) at ~2.
2526

26-
The next run is a sweep (this one was structural). Next sweep files, in order: `cli/commands/remove.rs`, `repair.rs`, `rollback.rs`, `scan/discovery.rs` (check against #1856), then `core/constants.rs`, `core/lib.rs`, `core/utils/cargo_home.rs`, `core/utils/cargo_workspace.rs` (skip `cargo_build_cache.rs` while #1849 is open, and `api/client.rs` while #1870 is open). Skip `agent_download.rs`, `apply.rs`, `get.rs` and `vendor.rs` while #1698 is open.
27+
The next run is structural if a candidate scores 6 or more and its files are free (T09 is not yet), else a sweep. Next sweep files, in order: `scan/discovery.rs` (`rollback.rs` waits for #1864), then `core/constants.rs`, `core/lib.rs`, `core/utils/cargo_home.rs`, `core/utils/cargo_workspace.rs` (skip `cargo_build_cache.rs` while #1849 is open, and `api/client.rs` while #1870 is open). Skip `agent_download.rs`, `apply.rs`, `get.rs` and `vendor.rs` while #1698 is open.
2728

2829
#### Notes
2930
- The PRs of the first thread (`arch-refactor/<issue>-*`) are listed in `review/2026-10-v1/register/90-refactor.md`.
@@ -34,4 +35,6 @@ The next run is a sweep (this one was structural). Next sweep files, in order: `
3435
- #1698 also touches `vendor.rs`, so the three `bun_vendor_preflight*` entry points (callers in `get.rs`, `agent_download.rs`, `vendor.rs`) and `StageOutcome::Unavailable`'s payload (caller `apply.rs`) wait until it merges. Check every caller file against open PRs, not only the swept file.
3536
- Build with `CARGO_PROFILE_DEV_DEBUG=0 CARGO_INCREMENTAL=0`: a default debug build of the CLI tests exhausts the session disk allowance. CI's clippy is `--workspace --all-features` without `--tests`; the integration tests carry pre-existing lints.
3637
- `ApiClient::with_vendor_retry` is the policy builder; a new private helper with that name collides (E0592). Grep a name before you introduce it.
38+
- `tests/repair` has 2 chmod-based tests that fail under the root sandbox (`repair_cleanup_failure_is_reported_in_json_and_silent_modes`, `repair_exits_zero_and_stays_quiet_when_lock_file_unremovable`); they pass in CI.
39+
- remove's ~900-line `run` split (audit note) is too big for a sweep; it wants an issue alongside T16/T17/T20.
3740
- A shared GET must keep every caller's bounds: folding an uncapped `resp.text()` error read into the capped `PatchApi` path is what /code-review caught on #1870.

0 commit comments

Comments
 (0)