Skip to content

Sweep scan/hosted.rs (helpers and tests region) - #1897

Open
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
mainfrom
arch-refactor/sweep-scan-hosted
Open

Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
mainfrom
arch-refactor/sweep-scan-hosted

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-opus-5-5

Sweep of crates/socket-patch-cli/src/commands/scan/hosted.rs, from its coverage row in the architecture ledger (discussion #1830). It covers everything except the 1,233-line run_redirect_selected_untracked, which is T24's structural work (part of #894), so the row is recorded as partial.

Changes

  • Tests moved to the module they test. 13 tests of core hosted::guidance sat in the CLI behind a #[cfg(test)] pub(crate) use re-export of 17 core items. They now live in hosted/guidance.rs, and the re-export is deleted. The two pnpm lock-sniff tests went beside their functions in formats/pnpm/mod.rs and were renamed for those functions.
  • Inlined emit_json_error into run_redirect, its only caller. scan calls run_redirect only inside if args.common.json, so run_redirect now takes the Envelope itself. The unreachable human "No changes made." arm is deleted.
  • Deleted the test-only wrapper installed_stale_positive_evidence. Its test calls core judge_installed_record(..).stale_evidence through a local helper. Renamed to stale_evidence_requires_readable_mismatched_bytes.
  • Flattened the gem probe's vendor/cache fold (pass 2): one if … else None, and cache_covered is keyed on the judged purl instead of looked up again in candidates.
    • Red→green: dropping the insert fails gem_stale_probe_folds_committed_vendor_cache_into_the_remedy and gem_stale_probe_follows_the_configured_bundle_cache_path.
  • Deleted the duplicate test gem_stale_probe_record_lookup_is_uuid_keyed. It had the same fixture and assertion as gem_stale_probe_matches_records_by_uuid_not_purl_key.
  • Fixed one test that claimed more than it checked. pnpm_lock_carries_hosted_redirect_detects_prior_run_splices now asserts the \/-escaped spelling its doc names.
    • Red→green: making artifact_url_spellings return the raw URL twice fails it.
  • About 120 comment lines removed: the human-output banner, 2 test banners, oversized private docs (run_redirect_selected, gem_stale_install_warnings, acquire_hosted_lock, run_redirect's parameters) and bare issue references. The why comments stay.
  • Moved the SBT_OWNED_FILE_UNREADABLE import to the top of the file.

Size

git diff --stat: 4 files, +696 / −847.

  • Production: scan/hosted.rs +84 / −231, scan/mod.rs ±1.
  • Tests: scan/hosted.rs +20 / −615, core guidance.rs +543, core formats/pnpm/mod.rs +48. Most of that is the move.

Behavior change

None. The deleted arm could not run.

Risk

Low. The production edits are an inline, a dead branch and a loop flattening covered by the gem probe tests. No cfg(windows) or cfg(unix) code changed.

Verification

  • cargo clippy --workspace --all-features -- -D warnings: clean.
  • cargo test -p socket-patch-core --lib (guidance, formats::pnpm): pass. cargo test -p socket-patch-cli --lib scan::hosted: 48 pass.
  • cargo test -p socket-patch-cli --test scan --test in_process_redirect: 149 pass, 3 fail. The 3 failures are chmod-based and fail only because the sandbox runs as root; they pass in CI: partial_lockfile_write_failure_exits_1_and_writes_no_ledger, redirect_json_mode_write_failures_emit_error_envelope, vlt::scan_redirect_vlt_heal_invalidation_failure_warns.
  • /code-review high found no bugs in the diff.

Review findings not fixed here

All of these predate this PR or are outside a sweep.

  • Gem probe pass 3 matches by purl string. Two spellings of one gem sharing an installed dir can warn about the same vendor/cache archive twice.
  • Pass 3 builds the cache name without the platform suffix. It uses {name}-{version}.gem, so a committed stale platform-gem archive with no installed dir is missed. Both gem probe findings change behavior, so they want an issue.
  • Path::is_file is a blocking stat inside the async probe. It predates this PR.
  • The npm_override test fixture now has three copies (the CLI, guidance.rs, redirect/mod.rs). A shared core test builder belongs with A37/Share one scoped env-var test guard: EnvGuard is copy-pasted 11 times across core unit and integration tests #1889-style test-support work.
  • run_redirect_selected still takes Option<Envelope> keyed on common.json. Changing it touches get.rs (held by Fix Go patch delivery, audits, and reinstalls #1698) and the T24 body.

🤖 Generated with Claude Code

https://claude.ai/code/session_011f9aeR2NHGsMnustoUpVWS


Note

Low Risk
Production edits are refactors and comment removal in hosted scan/redirect paths; behavior is unchanged aside from removing unreachable human-output branches, with existing gem probe tests covering the loop change.

Overview
This PR cleans up scan/hosted.rs without changing hosted redirect behavior: large comment/doc trims, removal of the emit_json_error helper (inlined into JSON-only run_redirect, which now takes an Envelope directly), and a small flatten of the gem stale-install probe’s vendor/cache fold (cache_covered keyed by judged purl).

Tests move next to the code they exercise: pnpm/npm trust and heal-on-rerun coverage leaves the CLI re-export shim and lands in socket-patch-core (hosted/guidance.rs, formats/pnpm/mod.rs); the CLI keeps integration-style hosted tests. Duplicates drop (installed_stale_positive_evidence wrapper, redundant uuid lookup test), and pnpm_lock_carries_hosted_redirect now asserts \/-escaped URLs as documented.

Reviewed by Cursor Bugbot for commit 8a0af7a. Configure here.


Generated by Claude Code

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko Mikola Lysenko (mikolalysenko) added refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code arch-refactor PR opened by the scheduled architecture refactor routine labels Oct 30, 2026
The pnpm trust, npm allow-remote and pnpm lock-sniff tests checked
core functions through a cfg(test) re-export in the CLI. They now sit
beside the functions they test, in hosted/guidance.rs and
formats/pnpm/mod.rs, and the re-export is gone.

Assisted-by: Claude Code:claude-opus-5-5
- Inline emit_json_error into run_redirect, its only caller. scan
  calls run_redirect only under --json, so it now takes the Envelope
  itself, and the human 'No changes made.' arm (unreachable) is gone.
- Delete the test-only installed_stale_positive_evidence wrapper; its
  test calls core judge_installed_record directly.
- Flatten the gem probe's vendor/cache fold and key cache_covered on
  the judged purl instead of looking it up again in the candidates.
- Move the SBT_OWNED_FILE_UNREADABLE import to the top.
- Delete the duplicate uuid-keyed gem probe test, two test banners
  and the human-output banner, and trim oversized private docs and
  bare issue references.

Assisted-by: Claude Code:claude-opus-5-5
The test's doc says a \/-escaped hosted URL counts as a prior splice,
but it only checked the raw and percent-encoded spellings. It now
checks the escaped one too, and fails if artifact_url_spellings
drops it.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review October 30, 2026 09:31
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

BugBot review


Generated by Claude Code

Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Oct 30, 2026
Assisted-by: Claude Code:claude-opus-5-5

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 8a0af7a. Configure here.

Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Oct 30, 2026
Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 1, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Ready for review (burn-down agent) at 8a0af7a.

  • CI: 32/32 run checks green (50 skipped). Mergeable, no conflicts.
  • Bugbot: reviewed 8a0af7a, no findings; no unresolved threads.
  • Reviewer note: refactor sweep of scan/hosted.rs helpers and tests; it also touches formats/pnpm/mod.rs and hosted/guidance.rs.

Generated by Claude Code

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Final review brief

What it does: This is a behavior-preserving sweep of scan/hosted.rs. It moves 15 tests of core hosted::guidance and the pnpm lock-sniff helpers into core and drops the CLI's #[cfg(test)] re-export block. It also inlines emit_json_error into the JSON-only run_redirect, which now takes an Envelope instead of an Option. Finally, it flattens the gem vendor/cache fold, removes a duplicate test and trims about 120 comment lines.

Risk: low.

  • The removed human-output arm of run_redirect was unreachable: it is only called under if args.common.json, with a value that was always Some.
  • The flattened gem fold gives the same contains results.
  • Every moved test keeps all its assertions; I compared the removed and added test lines as sorted sets.
  • The deleted gem test was a duplicate of gem_stale_probe_matches_records_by_uuid_not_purl_key.

Look here

Verified: I read the full diff and checked the moved tests one by one. There is no unrelated edit, and CHANGELOG.md is untouched. CI is 82/82 green, and Bugbot passed.

Changes I made: none.

Open questions (non-blocking): a few trimmed doc comments carried useful detail and could each get one line back:

  • the acquire_hosted_lock guard unlinks the lock and prunes an empty .socket/, and maps failures to the lock_held/lock_io codes;
  • the candidate filter is skipped on --dry-run;
  • a --json caller of run_redirect_selected that passes None gets a bare envelope.

Auto-merge is armed, so approving sends this straight to the merge queue.


Generated by Claude Code

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] On the three non-blocking doc questions in the final review: I'm leaving them as they are, to avoid a push that would rerun CI and reset the review.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-refactor PR opened by the scheduled architecture refactor routine Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants