Skip to content

Sweep core utils http, mod and hatch - #1914

Open
Mikola Lysenko (mikolalysenko) wants to merge 5 commits into
mainfrom
arch-refactor/sweep-core-utils-http-hatch
Open

Mikola Lysenko (mikolalysenko) wants to merge 5 commits into
mainfrom
arch-refactor/sweep-core-utils-http-hatch

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

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

Architecture refactor sweep of core utils/http.rs, utils/line_endings.rs (clean, nothing to do), utils/mod.rs, utils/hatch_workspace.rs and utils/hatch.rs. It follows the audit notes in coverage/files.tsv on arch-audit/ledger (living document: discussion #1830, Part 4 structure and Part 5 tests).

Changes

utils/http.rs

utils/hatch.rs

utils/hatch_workspace.rs

utils/mod.rs

  • The hatch modules are sorted into place, and hatch_workspace is pub(crate): its only users are in core.

/code-review high

I fixed 3 findings:

  • The HatchPermission → HatchEdit merge is reverted. A plan's permission holds whole file texts, while a HatchEdit holds one line.
  • The environments forwarder is deleted.
  • The members_of doc is rewrapped.

I left 5 unfixed:

  • Visibility narrowing on hatch_workspace: the audit asked for it, and prior sweeps narrowed core items the same way.
  • require_pip_installer_documents ignores the hatch.toml envs override: this is pre-existing, and fixing it changes refusals, so it wants an issue.
  • walk's key-stripping merge: it mutates a copy for the rewrite, a different operation from a lookup.
  • respond_raw duplicating other modules' private test servers: sharing them is test_support work across files held by open PRs.
  • #547/#505 references in vendor/pypi_hatch.rs: that file isn't in this sweep.

Totals

git diff --stat: 5 files, +231 / −208.

  • Production: about −19.
  • Tests: about +42, from the two new branch tests.

Behavior

None. The output bytes, error strings and refusal order are unchanged.

Verification

  • CI: all 82 checks green on ece45b6. Bugbot found no issues.
  • cargo clippy --workspace --all-features -- -D warnings is clean.
  • cargo test -p socket-patch-core --lib: 6997 pass and 4 fail. All 4 rely on chmod and fail under the root sandbox, in files this PR doesn't touch:
    • copy_tree::relax_loop_must_not_traverse_symlinked_root
    • vlt_heal::an_unremovable_hidden_lock_keeps_every_store_entry
    • pypi_poetry::wire_write_failure_maps_error_and_leaves_lock_untouched
    • pypi_requirements::wire_failure_rolls_back_already_written_files
  • Mutation check: making merged_key ignore hatch.toml for lock-envs fails hatch_lock_detection_follows_the_config_merge.

Risk

Low. The changes are local to core, and no cfg(windows)/cfg(unix) code changed.

https://claude.ai/code/session_011f9aeNjuH4Ykvk5p4WEcU3


Note

Low Risk
Structural refactors and test harness changes in core utils; PR asserts byte-identical outputs and unchanged refusal order.

Overview
Refactors Hatch TOML handling without changing rewrite or refusal behavior. hatch.rs introduces PYPROJECT / HATCH_TOML, centralizes pyproject [tool.hatch] access via tool_hatch, and replaces ad hoc hatch.toml-vs-pyproject merging with merged_key (replacing the old environments helper). Round::new, Target::root_relative, external_metadata, and shared parse_documents cut duplicated setup; pypi_hatch.rs follows the new path constants.

hatch_workspace.rs uses the same merge helper and document names, inlines member-spec {root}/{home} expansion into members_of, and simplifies checkout-root discovery in roots. mod.rs reorders exports and makes hatch_workspace pub(crate).

http.rs test-only changes: wiremock is replaced with a raw loopback server so cap logic can be exercised on chunked bodies and truncated Content-Length responses; assertions target ReadCappedError variants. Stale issue/history comments are stripped across these files.

Reviewed by Cursor Bugbot for commit e598769. 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 Nov 1, 2026
The cap tests matched "too large" in a String; they now assert the
ReadCappedError variant and message. New tests cover the mid-stream
cap (a chunked body with no Content-Length) and a body cut short of
its Content-Length (Truncated), neither of which had a test. A raw
loopback server replaces wiremock, which always declares a length.

Drop the history note on read_capped and the issue-number banner,
and rename production_builder_builds to what it checks.

Assisted-by: Claude Code:claude-opus-5-5
hatch.rs: name the two documents (PYPROJECT, HATCH_TOML); one
tool_hatch lookup and one merged_key rule (a hatch.toml top-level key
replaces [tool.hatch]'s) replace three hand copies; Round::new builds
the targets and index that plan and rewrite_all built twice;
Target::root_relative replaces three {root:uri} literals; plan's
permission is a HatchEdit, so HatchPermission goes; require_pip_installer
reuses parse_documents; external_metadata replaces collecting every
hatch.toml key to test for one. Bare issue numbers dropped.

hatch_workspace.rs: inline expand into members_of, replace a constant
take_while with an if, use the named documents, drop review/issue
history from test docs.

mod.rs: sort hatch modules into place; hatch_workspace is pub(crate).

Assisted-by: Claude Code:claude-opus-5-5
Review: plan's permission holds whole file texts while a HatchEdit
holds one setting line, so folding one into the other blurred the
type. Restore HatchPermission with a doc saying what it holds.

environments was a one-line forward to merged_key(.., "envs");
its two callers call merged_key instead. Rewrap the members_of doc.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 1, 2026 05:23
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

BugBot review


Generated by Claude Code

Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Nov 1, 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.

Stale Bugbot comment from a previous run.

Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Nov 1, 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

Burn-down agent: labeled Ready for review.

  • Head: ece45b6b47b928f21085641b1b88a5cb85178e78, mergeable.
  • CI: 32/32 ran green (50 skipped by path filters).
  • Bugbot: reviewed this head, no new issues; no open review threads.
  • Reviewer focus: refactor-only sweep of utils/http.rs, utils/hatch.rs, hatch_workspace.rs — check behavior is unchanged.
  • Slack announcement could not be sent this run (send tool unavailable); next run retries.

Generated by Claude Code

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Final review brief (ece45b6)

What it does. This cleans up utils/hatch.rs, hatch_workspace.rs, http.rs and utils/mod.rs without changing production behavior. Two hand-written copies of the hatch.toml-over-pyproject merge rule become one merged_key helper. Round::new replaces two duplicated constructors, expand is inlined, and hatch_workspace is narrowed to pub(crate). The http tests move from wiremock to a raw loopback server so they can reach the mid-stream cap and Truncated branches. In http.rs, the only production change is a doc comment.

Risk: low. I compared each rewrite with the old code and found them equivalent:

  • merged_key vs environments: and_then(get) vs filter(contains_key) plus get. Both skip Item::None.
  • locks_environments: hatch.toml still wins on a top-level key.
  • external_metadata: same check as before.
  • require_pip_installer: it now iterates the documents in BTreeMap order, but it returns one constant refusal on any match, and parse errors keep HATCH_FILES order, so the result is the same.
  • members_of: same order of {root}/{home} substitution and the same guards.
  • read_capped: byte-for-byte unchanged.

Look here

Verified

  • Read the full diff and the description. The description matches the code: 13 issue references removed, 3 sites changed in pypi_hatch.rs, and nothing outside core uses hatch_workspace.
  • Tests:
    • cargo test -p socket-patch-core --lib utils::: 434 passed
    • --lib vendor::pypi_hatch: 15 passed
    • --lib hatch: 74 passed
  • cargo clippy -p socket-patch-core --lib -- -D warnings is clean. The --all-targets lint errors are already on main and are not from this PR.
  • CI on ece45b6: 82 check runs, 32 passed and 50 skipped. ci-ok and clippy are green, and Bugbot passed.
  • No open review threads. CHANGELOG.md is untouched, and I found no debug leftovers.

Changes I made: none.

Open questions (not blocking)

  • hatch_workspace goes from pub to pub(crate) in the published socket-patch-core crate. Nothing in this workspace uses it, and earlier sweeps did the same, but a downstream user of the crate would break.
  • exact_cap_boundary_is_allowed now sends a chunked body. That means no test covers the declared Content-Length len == max boundary any more. A Content-Length variant could be added in a follow-up.

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


Generated by Claude Code

The boundary test moved to a chunked body, leaving no test of a
declared Content-Length equal to the cap. Check both: a declared
length of exactly max is accepted, as is a streamed body of max
bytes. Changing the declared check to >= now fails it.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] Final review follow-up: e598769 adds back the case where the declared Content-Length equals the cap. exact_cap_boundary_is_allowed now checks a declared content-length: 16 and a chunked 16-byte body, both against a cap of 16. Changing the declared check to len >= max fails it.

I'm leaving hatch_workspace as pub(crate). The audit asked for it, nothing in the workspace uses it, and earlier sweeps narrowed core items the same way.


Generated by Claude Code

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

BugBot review


Generated by Claude Code

@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 e598769. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[final reviewer] Disarmed auto-merge: head e598769 adds a test-only commit after the final-review brief on ece45b6, so the brief no longer covers the current head. The push was under 45 minutes ago, so I am leaving it alone this run. The next final-review run will review e598769 (Bugbot was requested on it) and re-arm auto-merge once the brief is current. CI (ci-ok, clippy) is green on e598769.


Generated by Claude Code

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Final review brief (e598769)

This covers the one commit added after the previous brief on ece45b6. Everything in that brief still applies.

What it does. This is a refactor-only sweep of utils/hatch.rs, hatch_workspace.rs, http.rs and utils/mod.rs, with no intended behavior change. The new commit e598769 only changes a test: exact_cap_boundary_is_allowed now checks a declared content-length: 16 body as well as a chunked 16-byte body, both against a cap of 16. That closes the coverage gap the previous brief raised.

Risk: low. The commit doesn't touch production code.

Look here

Verified

  • cargo test -p socket-patch-core --lib utils::http on e598769: 10 passed.
  • Mutation check: changing line 221 to len >= max makes exact_cap_boundary_is_allowed fail. I reverted the change and didn't push it.
  • CI on e598769: ci-ok and clippy are green. Bugbot found no new issues, and there are no review threads. CHANGELOG.md is untouched.

Changes I made: none.

Open question (not blocking): hatch_workspace goes from pub to pub(crate) in the published core crate. Nothing in this workspace uses it.

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


Generated by Claude Code

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Burn-down agent: Ready for review re-confirmed on the new head.

  • Head: e598769eb91891e2120a0cded1a6a6d973367bf0 (test-only commit added after the earlier label on ece45b6), mergeable.
  • CI: 50/50 check runs green on this head.
  • Bugbot: reviewed e598769, no findings; no open review threads.
  • Slack announcement could not be sent this run (send tool unavailable); next run retries.

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