Repository navigation
Move the Socket origin classifier into one module - #2002
Draft
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
Draft
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
Conversation
Mikola Lysenko (mikolalysenko)
force-pushed
the
lock-model/1-origin
branch
2 times, most recently
from
November 4, 2026 16:34
2133177 to
6c4869b
Compare
Discovery's classifier (the memoized hosted_uuid fast path, vendor_ref and its variants, locate, Wired, the socket-patch-<uuid> name grammar) and the redirect's hosted URL rule (hosted_patch_uuid, hosted_patch_url_uuids, SOCKET_PATCH_SERVER_HOST) now live in crates/socket-patch-core/src/origin.rs, with their tests. The code moves verbatim. DiscoverCtx holds an OriginPolicy (the per-run origin allowlist and its memoized host set) and delegates hosted_uuid and locate to it. vex::discover and patch::redirect re-export the moved items, so no caller changes. origin.rs sits outside formats/ on purpose: format models are guarded to apply no host policy (formats/mod.rs architecture_tests). Budget: lock-readers 30,898 -> 30,976 (49 lines moved in from patch/redirect, ~30 lines of OriginPolicy and re-export glue); lock-writers 88,363 -> 88,314. No behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mikola Lysenko (mikolalysenko)
force-pushed
the
lock-model/1-origin
branch
from
November 4, 2026 17:18
6c4869b to
134d40e
Compare
Resolve the scripts/loc-budget.json conflict: the base fixed the counter's cfg(test) and module bugs, so both budgets are recounted with the fixed counter and lowered to the exact current totals (lock-readers 30259, lock-writers 88313), keeping this PR's 'both groups at their budget' intent. Co-Authored-By: Claude <noreply@anthropic.com>
Brings in the counter's crate-field and const-generic fix and the doc symbol fixes. Also restores crates/socket-patch-core/src/origin.rs to the lock-readers group: the previous merge (4242ebc) resolved the loc-budget.json conflict with the base's path list and dropped it, so the 281 lines this PR moves into origin.rs went uncounted (30259). With origin.rs counted, lock-readers is 30540 and lock-writers 88313. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The extractor guard also bans OriginPolicy and crate::origin:: (not bare origin::, which would catch crate::vendor::npm_origin::), and vex::discover no longer re-exports OriginPolicy; mod.rs imports it from crate::origin. - The lock_inventory model guard bans OriginPolicy, crate::origin:: and hosted_uuid(; the formats guard bans OriginPolicy, hosted_uuid( and SOCKET_PATCH_SERVER_HOST. formats may still use origin's pure path grammar (vendor_ref), which applies no host policy. - socket_identities takes &OriginPolicy. The policy memoizes one lowercased host set, shared by hosted_uuid's fast path and a case-insensitive matcher (host_finder), so a discovery run builds the matcher once instead of on every swept file. hosted_uuids_in_text keeps its signature. Answers are unchanged: reqwest already lowercases http(s) hosts. - origin.rs's module doc states one classifier as the goal and names the readers that still classify on their own; it no longer links pub(crate) items (rustdoc private_intra_doc_links). - socket_patch_name_uuid is pub(crate) again; hosted_patch_url_uuids loses its duplicate is_canonical_uuid import. - patch::redirect stops re-exporting hosted_patch_uuid, hosted_patch_url_uuids and SOCKET_PATCH_SERVER_HOST; vlt_heal, upstream, lock_inventory::pypi and discover use crate::origin directly. Extractors keep importing origin helpers through vex::discover's re-export (now with SOCKET_PATCH_SERVER_HOST for pypi_other), as the guard requires. - New test: DiscoverCtx::with_origins(..).hosted_uuid(..) honours a configured origin and only for that run. Budget raised by hand: lock-readers 30540 -> 30544 (the shared host matcher and the re-export note), lock-writers 88313 -> 88315 (rustfmt wraps the upstream origin path). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mikola Lysenko (mikolalysenko)
added a commit
that referenced
this pull request
Nov 6, 2026
Brings in #2002's review fixes (OriginPolicy imported from crate::origin, the redirect re-export dropped, the shared host matcher, the stricter architecture guards) and #2001's later counter fixes. Restores crates/socket-patch-core/src/origin.rs to the lock-readers group, which the previous merge (1d27a20) inherited the loss of from 1-origin's 4242ebc. Budget at this branch's counts: lock-readers 30767, lock-writers 88315. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mikola Lysenko (mikolalysenko)
added a commit
that referenced
this pull request
Nov 6, 2026
Brings in #2002's review fixes and #2001's later counter fixes through 2a. Restores crates/socket-patch-core/src/origin.rs to the lock-readers group (lost in the earlier 1-origin merge). Budget at this branch's counts: lock-readers 30766, lock-writers 88114, both below 2a's 30767 and 88315. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack: PR 1 of the
lock-model/*stack, based on #2001 (design:docs/design/lock-model-unification.md).What
This PR moves the Socket-origin classifier into one new module,
crates/socket-patch-core/src/origin.rs. The code comes from two places:vex/discover/mod.rs:hosted_uuidwith its cached plain-URL fast path, now on a smallOriginPolicythat holds the run's origin allowlist;vendor_ref,vendor_ref_decorated,vendor_uuid_dir,strip_leaf_suffix,vendored_leaf_purl;locate,Located,LocateOpts,Wired;socket_patch_name_uuid;names_vendor_dir/mentions_vendor_dir/root_anchored_spellinghelpers.patch/redirect/mod.rs:hosted_patch_uuid,hosted_patch_url_uuidsandSOCKET_PATCH_SERVER_HOST.The tests move with the code:
hosted_patch_uuid_testsverbatim, and the six discovery tests that cover the moved functions.Why
This is the first step to one classifier for every reader. Today, discovery checks a Socket host allowlist, while the lock inventory accepts any host whose URL leaf matches. Later PRs point the inventory and the writers at this module. It sits outside
formats/on purpose: theformats/mod.rsarchitecture test keeps format models free of host policy.No behavior change
crate::patch::redirect::X→X);OriginPolicystruct replacingDiscoverCtx'spatch_server_origins/hosted_hostsfields;DiscoverCtx(hosted_uuid,locate);UUID_A→UUIDin the moved tests.vex::discoverre-exports the moved items its extractors use.patch::redirect's re-export is gone (review finding 7): its four callers import fromcrate::origin.socket_identitieschange (finding 3) reuses the policy's host matcher instead of building one per call; the answers are the same (the recognition, memo and golden tests pass unchanged).Size budget
lock-readers(now includesorigin.rs)patch/redirect, plusOriginPolicyand re-export gluelock-writerscrate::origin::path)Counted with #2001's fixed counter. The routine merge 4242ebc resolved the
loc-budget.jsonconflict with the base's path list, which droppedorigin.rsfromlock-readers(it showed 30,259). The next merge (88df7f9) puts it back. #2009 and #2029 had inherited the same drop, and their restack merges fix it too.Review findings
Each finding was checked against the code first. Commit fbe644d ("Address the review of the origin move") applies them, after a merge of #2001's review fixes.
Fixed (confirmed). The extractor guard (
extractors_read_content_only_through_the_recognizing_ctx_helpers) banned onlyhosted_patch_uuid(/hosted_patch_url_uuids(, so an extractor could build its ownOriginPolicyand bypassDiscoverCtx::hosted_uuid. It now also bansOriginPolicyandcrate::origin::. The needle iscrate::origin::, not bareorigin::, because extractors legitimately importcrate::vendor::npm_origin::.vex::discoverno longer re-exportsOriginPolicy;mod.rsimports it fromcrate::origindirectly.Fixed, except one needle. The
lock_inventoryentry-model guard now also bansOriginPolicy,crate::origin::andhosted_uuid(. Theformats/guard bansOriginPolicy,hosted_uuid(andSOCKET_PATCH_SERVER_HOST, but notcrate::origin::. That guard's rule is "no I/O and no host policy", andoriginalso holds the pure, root-anchored path grammar (vendor_ref), which applies no host policy. The pnpm planner core in Plan pnpm rewires with one core for both modes (lock-model 2b) #2029 (formats::pnpm::plan::match_key) uses it on purpose: it is the rule N5 asks every reader to use.Fixed (confirmed).
socket_identitiesrebuilt the host list and its Aho-Corasick matcher on every call. It now takes&OriginPolicy, and the policy memoizes:hosted_uuid's fast path (which used the un-lowercasedhost_str();reqwestalready lowercases http(s) hosts, so no answer changes);OriginPolicy::host_finder).DiscoverCtxpasses its own policy, so a discovery run builds the matcher once.hosted_uuids_in_text, the upstream restore's probe, keeps its&[String]signature and builds a policy per call, as before. The vex::discover golden test passes.Fixed.
origin.rs's module doc now states the one-classifier rule as the goal and names what still classifies on its own:lock_inventory/pypi.rshosted_pypi_reference, with its own url-tail grammar);pypi_other.rs, which compares hosts directly);Fixed.
socket_patch_name_uuidispub(crate)again, as it was invex::discover.Fixed. Removed the duplicate inner
use is_canonical_uuidinhosted_patch_url_uuids.Fixed, with one exception. The
patch::redirectre-export ofhosted_patch_uuid/hosted_patch_url_uuids/SOCKET_PATCH_SERVER_HOSTis gone.redirect::vlt_heal,redirect::upstream,lock_inventory::pypi,vex::discover) usecrate::origin::directly.socket_identities,redirect::generationandvendor::path.vex::discoverkeeps re-exporting the vendored-path and locate helpers, and nowSOCKET_PATCH_SERVER_HOSTforpypi_other.rs:576. Finding 1's guard banscrate::origin::in extractor files, so the extractors import every identity helper throughsuper::. The publicvex::discover::vendor_reffamily stays too, because the CLI'svex_sources.rsimports it.Fixed. The new test
vex::discover::tests::ctx_hosted_uuid_honours_the_runs_configured_originsgoes throughDiscoverCtx::with_origins(..).hosted_uuid(..). It checks a configured-origin URL, a registry URL, and the same URL with no origins configured.Fixed (confirmed). The public module's doc linked
pub(crate)items (OriginPolicy::hosted_uuid,OriginPolicy::locate, and nowsocket_patch_name_uuid). They are plain code spans now.cargo doc -p socket-patch-corewithrustdoc::private_intra_doc_linksreports nothing fororigin.rs.Testing
cargo test -p socket-patch-core --lib -- origin:: vex:: formats:: vendor::lock_inventory:: vendor::pnpm patch::redirect:: hosted::: 2,518 passed, 0 failed. This includes:vex::discover::testing::golden::tests::committed_fixture_corpus_matches_golden;formatsandlock_inventoryarchitecture guards;origin::.cargo clippy --locked --workspace --all-features -- -D warnings: clean.cargo fmt --all -- --check: clean.python3 -B -m unittest discover -s scripts/tests -p 'test_loc_budget.py': 31 tests, OK.scripts/loc-budget.py --check: both groups at their budget.Generated by Claude Code