Skip to content

Commit 3ef8f20

Browse files
Cargo VEX: read member manifests, match liveness by origin, withhold mixed and vendored bypasses (#2012)
* Match ledger liveness uuids by origin, not substring Redirect-ledger liveness step 1 kept a record alive when any lock inventory entry's resolved url merely CONTAINED the patch uuid, so a url on any host spelling the uuid (or a Socket url for another patch whose grant token is that uuid) kept a dead hosted record alive. Step 1 now classifies the url with the one origin classifier, `patch::redirect::hosted_patch_uuid`, over Socket's host and the run's patch-server origins, and requires the classified uuid to equal the record's. Discovery records the origins it was run with (`Discovery::patch_server_origins`, set in `discover_with_ctx`), so liveness classifies with exactly the origins discovery did; every `LedgerLiveness` caller already holds a discovery built from the run's `DiscoverOptions`. Socket-host and configured-origin urls for the record's uuid stay live; anything else falls to step 2 (resolves elsewhere: dead). The uv script-lock regression test relied on the substring match for an unconfigured internal host; it now shows that host dead without the origin and live with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Read Cargo workspace members in VEX discovery Hosted mode pins a patched crate in the root Cargo.toml AND every workspace-member manifest that declares it, and vendored mode's live-redirect refusal reads member manifests too. Discovery read only the root manifest, so a crate the root does not declare was "the lock is the only word": a member whose declaration was reverted to crates.io (no `registry = "socket-patch-<uuid>"`) left a ref attested although cargo re-resolves that dependency from crates.io. Discovery now enumerates the members the way the hosted rewriter does (`cargo_workspace::member_manifests_in`, filtered by the rewriter's own `is_cargo_member_manifest_key`, so nothing under `.socket/` or `target/`) and applies its manifest-declaration check across root + members. Each declaration carries its file: diagnostics, the conflict-pair Cargo.toml ref and lockless `UnlockedPin`s name the member manifest that holds the pin. `[patch]` stays root-only (cargo ignores a member's). The member walk over a `DiskSnapshot` now notes every manifest it reads and directory it probes or lists with the snapshot instead of asking for its raw root, so a discovery run under a read-set recording (the re-scan cache) keeps the recording usable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Address review: view-mediated member walk, lockless pins, undecided liveness Cargo member walk (review 4, 6, 7): - `cargo_workspace::member_manifests_in` is now async over the ProjectView: manifests are read with `read_text` (concurrently, bounded, ordered), globs list with `list_dir`, and directory probes use the view's own mediated `is_dir` / `is_symlink`. A snapshot's overlays and content cache apply and its recording notes the walk, so fresh manifests (a `.socket/` copy followed through `[patch]` included) no longer leave a racy read set. `DiskSnapshot::touch` / `touch_listing` are private again; `SnapshotTree` is gone. The in-memory engine keeps the sync walk (`member_manifests_in_memory`); disk-only callers keep `member_manifests`. A test pins the view walk to the disk walk over globs, `**`, excludes, path dependencies, `[patch]` copies, dot / `target` dirs and a symlinked member. Discovery (review 5, 8): - Members are walked only when they can matter: a lock with a Socket-sourced package, or no lock (then parsed only when some manifest carries a `socket-patch-` pin). The walk's texts are adopted into the ctx's read log and rule-11 recognition instead of being read again. - The root `DocumentMut` is moved into the manifest list, not cloned. Lockless pins (review 1, 3): - `UnlockedPin` gains `excluded_reqs`: the requirements of the crate's unpinned declarations. The rewriter leaves a declaration alone only when its requirement excludes the patched version, so a member's `serde = "0.9"` beside a pinned `serde = "1"` no longer suppresses the pin; a ledger version must satisfy every pinned requirement and no excluded one. An unpinned declaration with no requirement still blocks. - One pin and one diagnostic per (crate, patch): the union of the pinning declarations' requirements, every pinning manifest listed once. Liveness (review 2): - A lock entry whose url has the hosted shape for the record's uuid on an origin this run was not given is `RecordLiveness::Undecided`: never attested (`redirect_record_live` / `LedgerLiveness::redirect_record` stay attestation-grade) and never judged dead. `scan`'s takeover classifier and hosted-wiring-retained advisory use the new `LedgerLiveness::redirect_record_retained`, so a record written against a patch server a later run is not pointed at keeps its wiring. A url that merely contains the uuid (file name, query) is still dead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Name the view walk's read-manifest pair (clippy type_complexity) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Stop attesting a Cargo pin a workspace member resolves from crates.io Cargo resolves each source on its own. When one declaration of a crate pins it to `socket-patch-<uuid>` but another (the root's or a workspace member's) names no Socket registry (crates.io, another registry, a path or git) with a requirement the locked patched version satisfies, that declaration builds a separate, unpatched copy, possibly of the very version the pin covers. Discovery still attested the Cargo.lock ref because "some declaration pins the patch" was enough. The hosted rewriter pins every declaration, so this mixed state is a partial revert or a hand edit. The ref now stays (rollback, remove and the ledgers' liveness still see the pin) but is marked unattested with the new `UnattestedKind::CargoUnpinnedDeclaration`, naming the unpinned declaration's manifest. When Cargo.lock already locks a same-version copy from another source beside the Socket entry, the detail names that lock entry as direct evidence. A declaration whose requirement excludes the patched version, and a `[patch]` registry entry (which redirects declarations rather than adding one), do not withhold the statement. The CLI omits the ref as `vex_cargo_unpinned_declaration`; documented in CLI_CONTRACT.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Classify each Cargo declaration before judging a hosted pin Review fixes for the unpinned-declaration mark. Each declaration of a Socket-locked crate is now classified once (`route`): routed to a Socket patch (its own `socket-patch-<uuid>` registry, or a Socket `[patch.<source>]` registry entry that redirects it), unpinned (cargo builds its own copy), or saying nothing about the locked version. - A crates.io (or registry) declaration that a Socket `[patch.<source>]` registry entry in the root manifest or project config redirects is no longer counted as unpinned. - A declaration naming `registry = "socket-patch-<uuid>"` beside `path`, `git` or `registry-index` is not a pin (the hosted rewriter's own pinned check): cargo builds that other source, so it now marks the ref. - Requirements go through `patch::redirect::cargo_req_selects` with the lock's other versions of the crate, and the detail says whether a re-scan can pin the declaration: only a crates.io declaration whose requirement matches no other locked version; otherwise the rewriter refuses (`redirect_cargo_toml_dep_unrewritable`), so the remedy is to change the declaration or roll back. The CLI note's remedy is now generic and the per-case remedy lives in the detail. - `registry-index` declarations are reported as such, not as crates.io. - A `[workspace.dependencies]` template counts only when some manifest inherits it (`workspace = true`). - When the lock already holds a same-version copy from another source, no mark is added: the twin rule (#679) withholds the ref and names it. - Root pinned to patch A with a member pinned to patch B (for the locked version, and B not resolved by the lock) now emits B's Cargo.toml ref beside A's, so the CLI's wiring-conflict gate runs. - `Decl` carries a `DeclSource` enum and a `live` flag; the origin text is formatted only for messages, and `[patch]` pins are built with `Decl::patch` (no dead version parameter). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Withhold a vendored Cargo copy a member's other source bypasses `vendor` wires a crate through the root's `[patch.crates-io]`, which cargo applies only to declarations from crates.io. A workspace member (or the root) that declares the crate from another registry, a `registry-index` or git, at a requirement that may select the patched version, resolves its own unpatched copy. The vendored ref stayed attested beside it because the lock copy claim only reads sourceless entries. The ref now stays (rollback, remove and the ledgers still see the wiring) but is marked unattested with the new `UnattestedKind::CargoPatchBypassed`, naming the declaration. A same-version Cargo.lock entry from any registry or git source beside the copy is marked the same way, naming the lock entry. The check reads the declarations through #2019's classification: live declarations only, a registry dependency counts as covered when a `[patch.<registry>]` table pointing at the same copy redirects it (`Decl::patched_by`), a path declaration (the user's own fork) keeps the existing "ignored" rule, and a `socket-patch-*` registry dependency is hosted wiring. The CLI omits the ref as `vex_cargo_patch_bypassed`; documented in CLI_CONTRACT.md. The workspace member walk ran only when the lock held a Socket-sourced package (or, with no lock, a manifest named a `socket-patch-` registry). A vendored copy's lock entry has no source and it has no such pin, so the walk now also runs whenever the root manifest or the project config wires a Socket copy through `[patch]`, whatever the lock's state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Classify Cargo lockless pins, git patch tables and conflict pins Three Cargo follow-ups to the declaration classification: Lockless pins read declarations like locked ones. A `socket-patch-<uuid>` registry beside `path`, `git` or `registry-index` is no pin (cargo builds that source, and the rewriter's own pinned check agrees), so it no longer adds its requirement to an `UnlockedPin` or makes one on its own. It counts as an unpinned declaration instead, excluding the versions it accepts (every version, without a requirement). A `[workspace.dependencies]` template no manifest inherits is no declaration: a Socket-pinned one makes no lockless pin, and an unpinned one excludes nothing from the root's pin. A non-Socket `[patch]` registry entry no longer counts as an unpinned declaration either (it redirects declarations, it adds none). `DeclSource::Git` keeps its URL, and `Decl::patched_by` matches a `[patch."<repository URL>"]` table against it (a trailing `/` or `.git` ignored). So a git declaration whose repository table points at the same vendored copy no longer withholds that copy, while one from another repository still does. Hosted routing gains the same match for a Socket registry pin in such a table. When no declaration pins the lock's patch, a pin to another patch now makes the conflict pair only when it is live and its requirement may select the locked version (`cargo_req_selects`). One that excludes it is about another version; the stale lock entry is then diagnosed and dropped like any unrouted one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Normalize foreign hosted urls before reading their origin foreign_hosted_uuid parsed the raw lock url, while hosted_patch_uuid first unescapes \/, percent-decodes and strips a Cargo sparse+ / registry+ prefix. A hosted url on an unconfigured origin that only parses after that normalization was never Undecided and could be marked Dead, dropping live wiring. Share the normalization. Addresses one of the two Bugbot findings on this PR. Co-Authored-By: Claude <noreply@anthropic.com> * Fix review findings on Cargo vendored bypass and pin diagnostics False attestation: the vendored bypass check counted a declaration as redirected by any root or config `[patch]` entry pointing at the copy, including a manifest entry cargo ignores (the project config redefines its crates.io key, or a crates.io URL table replaces `[patch.crates-io]`). Cargo then builds whatever replaced it for those declarations, while the copy's other, honored entry was attested. Only honored entries count now: the root's `[patch]` entries are collected once with their shadow reason (a `Shadow` built from the root manifest and the config), and the bypass check sees only the unshadowed ones. `vendored` (the member gate) is derived from the same list instead of re-reading every `[patch]` table. One classifier: the bypass check runs each declaration through `route` with the copy's honored `[patch]` tables as the pins, as hosted pins do, passing the lock's other versions of the crate. A path declaration (the user's own fork) is still left alone. `patched_by` now covers a `registry-index` declaration with a `[patch."<index URL>"]` table for the same index (a `registry+` prefix, host case and a trailing `/` ignored; `sparse+` is another source), and treats a `registry-index` naming the crates.io git index as crates.io. The sparse crates.io index stays a separate source. Git URLs compare as cargo's `CanonicalUrl` spells them (one trailing `/` and a `.git` suffix dropped, a GitHub URL lowercased whole, any host lowercased). The bypass detail ends with the remedy for its evidence: a declaration (re-running `vendor` does not help), a crates.io lock entry beside a `[patch.crates-io]` copy (stale: re-lock), or another lock entry (`cargo tree -i` names its declarer). The CLI note no longer claims re-vendoring never helps. Diagnostics: a Socket pin to another patch that the lock does not reflect (its requirement excludes every locked version) used to vanish once any Socket entry of the crate was locked; it is now diagnosed `patched_ref_unattributable`. A well-formed `socket-patch-<uuid>` registry that pins nothing (beside `path` / `git` / `registry-index`, or on a `[workspace.dependencies]` entry no manifest inherits) is diagnosed `patched_ref_invalid`. The committed `workspace-member` redirect golden gains that diagnostic: its `expected/` tree omits the unchanged inheriting member, so the pinned template reads as uninherited there. `Decl::describe` and `same_version_foreign_entry` are shared by the hosted and vendored checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Read Cargo members whenever a Socket pin could need them Second review round on Cargo member liveness and origin matching. - `read_members` returned nothing for a parsed lock with no Socket-sourced package or an unparseable one, so a member's `socket-patch-` pin beside a stale lock lost its "stale lock, or a server outside the allowlist" diagnostic and its uuid was no longer recognized (rule 11). Members are now parsed whenever the lock is Socket-sourced or a `socket-patch-` name appears in a member's text, the root's or the config's, whatever the lock says; a root or config `[patch]` pin now counts too (it governs members' declarations). - `foreign_hosted_uuid` read any url on any host ending in the record's uuid as a foreign patch server's, so an artifact store's `/blobs/<uuid>/` url kept a dead hosted record retained (and raised a takeover note). It now needs a patch server's path shape (a `patch`, `patch-registry` or `gopatch` segment). - Two inserted functions split their neighbours' doc comments (`hosted_patch_url_uuids`, `log_read`); restored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Count registry = "crates-io" as re-pinnable in the Cargo remedy Second review round. The unpinned-declaration remedy sent every declaration with an explicit `registry` key to "it names another registry ... roll the patch back", including `registry = "crates-io"`, which the hosted rewriter re-pins (#386); it now says a re-scan pins it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Let a shadowed [patch] Socket pin pin no hosted declaration FALSE ATTESTATION (found reviewing #2019; fixed here, where `Shadow` lives): a root `[patch.crates-io]` Socket registry pin cargo ignores (a `[patch."<crates.io URL>"]` table replaces it, or the config redefines the key) still counted as pinning every crates.io declaration of the crate, so a member's plain declaration was taken as routed to the patch and the hosted ref attested while cargo builds crates.io. Such an entry stays a declaration (Socket's wiring is present, the ref stays) but is not live, and `route` only weighs live `[patch]` pins, as the vendored bypass check already weighs only honored entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Shadow a manifest [patch] item by any config item for its source and key Cargo replaces a manifest [patch] item with a project-config item of the same source and key, whatever the source table and whether either wires a path. Shadow only looked at crates.io tables and treated two path-less items (a registry pin and a git fork) as the same wiring, so a config fork left the manifest's Socket pin live and its stale lock row could be attested. Only an identical path is now the same wiring, and named and URL tables are compared too (URLs as an index key). The ineffective-registry diagnostic also called a shadowed [patch] pin an uninherited [workspace.dependencies] template; it now says cargo ignores the [patch] entry. Addresses Bugbot 4501098254, 4501098256 and 4501098258. Co-Authored-By: Claude <noreply@anthropic.com> * Compare [patch] URL tables the way cargo canonicalizes them Shadow compared a config's [patch."<url>"] table with the manifest's through index_key, which keeps a trailing .git and a GitHub path's case. Cargo canonicalizes both, so a config item under a canonical-equivalent git URL replaced the manifest's Socket copy while discovery still counted it. Non-sparse URL tables now compare through git_key; sparse+ ones stay index keys (another source). Addresses Bugbot 4501313607. Co-Authored-By: Claude <noreply@anthropic.com> * Treat registry = "crates-io" as crates.io for URL-form [patch] tables Cargo reads an explicit `registry = "crates-io"` the same as no registry, so a Socket pin under `[patch."https://github.com/rust-lang/ crates.io-index"]` redirects such a declaration. `patched_by` only compared the key to the table name, so it missed that case and marked the lock ref CargoUnpinnedDeclaration. Route the explicit spelling through `is_crates_io_source` like a bare declaration (Bugbot on #2019). Co-Authored-By: Claude <noreply@anthropic.com> * Withhold a vendored Cargo copy a stale pin to another patch bypasses patch_bypassed only withheld the vendored ref for declarations route() finds Unpinned. A member declaring the crate from another socket-patch registry routes to Pin(other) and was skipped. When the lock resolves the crate from that patch, its hosted ref sits beside the vendored one and the CLI's wiring_conflict gate refuses both. When the lock is stale and holds no entry from that patch, only a patched_ref_unattributable diagnostic was left, and patch A was attested even though the member re-resolves to patch B. Mark the vendored copy CargoPatchBypassed in that case instead. Co-Authored-By: Claude <noreply@anthropic.com> * Pair the stale-pin bypass with an emitted ref, not any lock line The exemption for a member pinned to another Socket patch trusted any lock line from that patch. hosted_from_lock drops a line whose project registry definition disagrees, and a line at another version is no ref for this package, so wiring_conflicts never fired and the vendored copy stayed attested. Exempt only when the hosted pass emitted a ref for that patch at this very purl that is not itself withheld. Co-Authored-By: Claude <noreply@anthropic.com> * Fail closed on hosted wiring from an unconfigured patch server Owner decision on #2012: a pre-v5 redirect-ledger record whose wiring resolves the package from a hosted-shaped url on an origin this run was not given (a staging server used without --patch-server-url, or a look-alike host) is never attested. vex reports it as redirect_unwired, whatever is installed and even under --no-verify. Step 1 of redirect_record_verdict already returned Undecided for a lock inventory entry carrying such a url. The formats whose inventory has no url (yarn berry __archiveUrl bindings, Cargo.lock registry sources, pom repositories, Gemfile source blocks, go.mod replace module paths) fell through to the recorded-wiring step 3 (or the gem step 0) and attested. Those steps now return Undecided when any recorded file spells a hosted-shaped url for the uuid on an unconfigured origin. A Socket-host spelling elsewhere in the files does not clear it. foreign_hosted_uuid drops userinfo before reading the origin, so a https://patch.socket.dev@evil.example/... look-alike is Undecided in every step rather than Dead in step 1 and Live in step 3. vex adds a vex_claim_unwired note for such a record naming the cause and --patch-server-url. CLI_CONTRACT.md "Patch hosts (manifest-less VEX)" and the vex_sources module docs state the new rule. The yarn, cargo and maven e2e cells that asserted the old staging fallback now expect redirect_unwired. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Ask the hosted rewriter whether a re-scan can pin a Cargo declaration Review on #2019 (/code-review high): - The vex_cargo_unpinned_declaration remedy said "re-run socket-patch scan" whenever every unpinned declaration was a crates.io one the rewriter would pin. The rewriter skips the whole dependency on its first refusal, including one over a declaration discovery doesn't count as unpinned (the pin's own requirement matching another locked version, a path template nobody inherits). Discovery now runs the rewriter's own Cargo.toml planner dry over the same manifests (plan_cargo_tomls, extracted from rewrite_cargo_with) before it promises a re-scan. - A declaration naming registry = "socket-patch-<uuid>" beside a path, git or registry-index read as if the registry were missing. The detail now says the source overrides it, and says "those declarations" when there are several. - manifest_declarations looks up inherited template keys in a set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Fix review findings on Cargo [patch] shadowing and bypass details Review on #2024 (/code-review high), round 4: - The "resolves it only from other Socket patches" diagnostic fired beside a same-version crates.io twin; it now needs a lock with no non-Socket entry of the crate. - Shadow resolves a [patch.<registry>] table through the config's [registries] index, so a config [patch."<index>"] item shadows it. - An identical path-less Socket registry [patch] pin in the manifest and the config is the same wiring, not a shadow. - patched_by (registry-index) and same_patch_source share patch_source_key, with CanonicalUrl rules on both. - patch_bypassed's conflict-gate check matches the CLI's bypassed_ref (file-scoped marks only); it routes each declaration once; its detail also names other-patch declarations; a git lock entry a git [patch] table redirects gets the stale/re-lock remedy. - Reuse patch::redirect::is_crates_io_source for lock sources. - Move the manifests comment back above its vector. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Simplify the folded Cargo VEX stack Behavior-preserving cleanup of #2012 after #2019 and #2024 were folded in: - One `distinct<T>` replaces four hand-written order-preserving dedups; `describe_all` and one `other_declared` replace repeated describe/join chains. - `DeclSource::patched_by` is the one redirect rule; the bypass check's stale-entry test maps the lock source to a `DeclSource` instead of re-deriving crates.io and git matching. `index_key` is folded into `patch_source_key`. - `beside_the_pin` collects the lock's Socket uuids once; the manifests are serialized for the rewriter's dry planner once per discovery (`ManifestTexts`), not per crate. `vendored_from_patches` takes the lock from `Bypass`; the two `decls` passes in `extract` are one. - `foreign_hosted_uuid` moves to `origin::hosted_shape_uuid`, so `normalized_hosted_url` is private again; the cheap accepted-origin check runs first in `foreign_hosted_url_in_files`. - Comments and docs no longer narrate review history; the cargo module doc points at `beside_the_pin` / `patch_bypassed` instead of restating them; CLI_CONTRACT.md states the registry-index rule once and the `apply` sentence parses. - Tests share `workspace_root`, `member`, `one_mark` and `shadow` instead of respelling manifests and config parsing; the e2e fail-closed comments point at CLI_CONTRACT.md. Review of the simplify diff (/code-review high): the stale-lock remedy named `[patch.crates-io]` and `socket-patch vendor` for a git entry too; it now names the table that redirects the entry and offers `vendor` only for crates.io. CLI_CONTRACT.md keeps the member-walk and uninherited- template rules the trim had dropped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6d17873 commit 3ef8f20

16 files changed

Lines changed: 4144 additions & 507 deletions

File tree

‎crates/socket-patch-cli/CLI_CONTRACT.md‎

Lines changed: 5 additions & 3 deletions
Large diffs are not rendered by default.

‎crates/socket-patch-cli/src/commands/scan/mod.rs‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -981,8 +981,10 @@ fn overlap_from_states(
981981
/// them to right now — the truth source for takeover direction.
982982
///
983983
/// Both directions are proved by lockfile discovery with the same liveness
984-
/// rules `vex` gates attestations on (core `Discovery::redirect_record_live`
985-
/// / `Discovery::vendor_entry_live`). `redirect` holds the overlap PURLs the
984+
/// rules `vex` gates attestations on (core `Discovery::redirect_record_verdict`
985+
/// / `Discovery::vendor_entry_live`); a hosted record on a patch server this
986+
/// run was not given (`RecordLiveness::Undecided`) counts as wired, since the
987+
/// wiring is still there. `redirect` holds the overlap PURLs the
986988
/// lock routes to the hosted patch server (the vendored ledger entry is
987989
/// stale); `vendored` holds those it routes to a committed
988990
/// `.socket/vendor/<eco>/<uuid>` artifact.
@@ -1067,7 +1069,7 @@ pub(super) async fn classify_overlap_takeover_with(
10671069
let mut liveness = LedgerLiveness::new(cwd, discovery, None);
10681070
for purl in overlap {
10691071
let hosted_live = match redirect_uuid_by_purl.get(&PurlKey::new(&purl)) {
1070-
Some(uuid) => liveness.redirect_record(&purl, uuid).await,
1072+
Some(uuid) => liveness.redirect_record_retained(&purl, uuid).await,
10711073
None => discovery.wires_package(&purl, WiringMode::Hosted),
10721074
};
10731075
// `None`: undecided (a JVM pom that cannot be read, or a tree still
@@ -1394,8 +1396,9 @@ async fn gradle_scan(
13941396
/// pin names the purl (`redirect_state`, the lockfiles' hosted state — see
13951397
/// [`crate::commands::hosted_state_from_pins`]) AND lockfile discovery
13961398
/// proves the current lockfile still routes it to that hosted patch — core
1397-
/// `Discovery::redirect_record_live`, the same liveness rule `vex` gates
1398-
/// hosted attestations on.
1399+
/// `Discovery::redirect_record_verdict`, the same liveness rule `vex` gates
1400+
/// hosted attestations on, keeping a record on a patch server this run was
1401+
/// not given (`RecordLiveness::Undecided`): its wiring is still retained.
13991402
///
14001403
/// Deliberately NOT routed through [`classify_overlap_takeover`]: that
14011404
/// classifier keys on purls present in BOTH ledgers, so hosted-only wiring
@@ -1438,7 +1441,7 @@ pub(super) async fn hosted_wiring_retained_purls(
14381441
let mut liveness = LedgerLiveness::new(cwd, &discovery, None);
14391442
let mut out = Vec::new();
14401443
for (purl, uuid) in candidates {
1441-
if liveness.redirect_record(&purl, uuid).await {
1444+
if liveness.redirect_record_retained(&purl, uuid).await {
14421445
out.push(purl);
14431446
}
14441447
}

‎crates/socket-patch-cli/src/commands/vex_sources.rs‎

Lines changed: 147 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
//! whatever raw text survives. Only for a uuid no read file mentions
4545
//! (formats no extractor reads, patch servers outside the host allowlist)
4646
//! does the ledger's own recorded wiring decide — only files that PIN the
47-
//! resolution, never a leftover registry definition; a vendor entry
47+
//! resolution, never a leftover registry definition — and a hosted
48+
//! record whose lock entry or recorded wiring routes the uuid through a
49+
//! hosted-shaped url on an origin this run was not given is never
50+
//! attested (core `RecordLiveness::Undecided`, fail closed); a vendor entry
4851
//! recording no wiring (repair's reconstruction) probes its ecosystem's
4952
//! root locks; a lock inventory entry resolving the purl elsewhere is
5053
//! dead. A reverted lockfile plus a leftover ledger or artifact must not
@@ -82,7 +85,7 @@ use socket_patch_core::utils::purl::strip_purl_qualifiers;
8285
use socket_patch_core::utils::purl_key::{canonical_base_purl, PurlKey};
8386
use socket_patch_core::vendor::state::{VendorArtifact, VendorEntry, VendorState};
8487
use socket_patch_core::vex::discover::{
85-
vendor_ref, Discovery, LedgerLiveness, PatchedRef, WiringMode,
88+
vendor_ref, Discovery, LedgerLiveness, PatchedRef, RecordLiveness, WiringMode,
8689
};
8790
use socket_patch_core::vex::{FailedPatch, Unattested, UnattestedKind};
8891

@@ -232,6 +235,14 @@ const NOTE_MAVEN_REACTOR_ROOT: &str = "vex_maven_reactor_root";
232235
/// classifier copy at another version, which the pin does not reach
233236
/// (`vex::Unattested`).
234237
const NOTE_MAVEN_CLASSIFIER_UNPATCHED: &str = "vex_maven_classifier_unpatched";
238+
/// Omission tag and note: a hosted Cargo pin beside another declaration of
239+
/// the crate that names no Socket registry, which cargo resolves as a
240+
/// separate, unpatched package (`vex::Unattested`).
241+
const NOTE_CARGO_UNPINNED_DECLARATION: &str = "vex_cargo_unpinned_declaration";
242+
/// Omission tag and note: a vendored Cargo copy beside a copy of the crate
243+
/// from a source its `[patch]` entry does not redirect (another registry,
244+
/// git), which cargo builds unpatched (`vex::Unattested`).
245+
const NOTE_CARGO_PATCH_BYPASSED: &str = "vex_cargo_patch_bypassed";
235246
/// Omission tag and note: a pnpm lock pins the patch, but a
236247
/// `pnpm-lock.<branch>.yaml` exists, which pnpm installs from instead when
237248
/// `gitBranchLockfile` is on; its presence withholds (`vex::Unattested`).
@@ -300,6 +311,15 @@ fn unattested_note(kind: UnattestedKind) -> (&'static str, &'static str) {
300311
"not attested while that classifier copy resolves an unpatched version; the \
301312
wiring itself is intact, so re-running `scan` does not change this",
302313
),
314+
UnattestedKind::CargoUnpinnedDeclaration => (
315+
NOTE_CARGO_UNPINNED_DECLARATION,
316+
"not attested while that declaration stands",
317+
),
318+
UnattestedKind::CargoPatchBypassed => (
319+
NOTE_CARGO_PATCH_BYPASSED,
320+
"not attested while that copy can build beside the vendored one; the vendored \
321+
wiring itself is intact (the warning above says how to clear it)",
322+
),
303323
UnattestedKind::PnpmGitBranchLock => (
304324
NOTE_PNPM_GIT_BRANCH_LOCKFILE,
305325
"not attested while any branch lock exists (or the members that could hold one \
@@ -660,9 +680,14 @@ pub(crate) async fn plan(
660680
continue;
661681
}
662682
} else if cand.redirected {
663-
let live = assumed.contains(strip_purl_qualifiers(&cand.key))
664-
|| liveness.redirect_record(&cand.key, &cand.uuid).await;
665-
if live {
683+
let verdict = if assumed.contains(strip_purl_qualifiers(&cand.key)) {
684+
RecordLiveness::Live
685+
} else {
686+
liveness
687+
.redirect_record_verdict(&cand.key, &cand.uuid)
688+
.await
689+
};
690+
if verdict.attests() {
666691
Basis::Hosted {
667692
lockfile_basis: false,
668693
}
@@ -671,6 +696,9 @@ pub(crate) async fn plan(
671696
// purl: verify it as the agent-mode patch it now is.
672697
Basis::Installed
673698
} else {
699+
if verdict == RecordLiveness::Undecided {
700+
notes.push(foreign_origin_note(&cand.key, &cand.uuid));
701+
}
674702
notes.extend(dead_claim_notes(
675703
&discovery,
676704
&cand.key,
@@ -1096,6 +1124,20 @@ fn dead_claim_notes(
10961124
notes
10971125
}
10981126

1127+
/// Why a hosted-ledger record whose wiring resolves from a patch server
1128+
/// this run was not given ([`RecordLiveness::Undecided`]) is not attested:
1129+
/// fail closed, and say how a staging server is admitted.
1130+
fn foreign_origin_note(key: &str, uuid: &str) -> PlanNote {
1131+
PlanNote {
1132+
code: NOTE_CLAIM_UNWIRED,
1133+
detail: format!(
1134+
"{key}: the hosted ledger records patch {uuid}, but its wiring resolves it from a \
1135+
patch server this run was not given; pass --patch-server-url for a non-production \
1136+
patch server; not attested"
1137+
),
1138+
}
1139+
}
1140+
10991141
/// A local record for `uuid` (manifest, then redirect ledger, then vendor
11001142
/// entries) with the key it is filed under.
11011143
fn local_record_by_uuid(
@@ -2090,6 +2132,106 @@ mod tests {
20902132
);
20912133
}
20922134

2135+
/// A hosted Cargo pin beside an unpinned declaration of the crate is
2136+
/// omitted as `vex_cargo_unpinned_declaration`, the note naming the
2137+
/// declaration and the remedy.
2138+
#[tokio::test]
2139+
async fn a_cargo_pin_beside_an_unpinned_declaration_is_gated() {
2140+
const PURL: &str = "pkg:cargo/serde@1.0.1";
2141+
let tmp = tempfile::tempdir().unwrap();
2142+
let mut redirect = RedirectState::new();
2143+
redirect.records.insert(PURL.into(), record(U1));
2144+
let mut found = discovery(vec![hosted_ref(PURL, U1, true)]);
2145+
found.unattested.push(socket_patch_core::vex::Unattested {
2146+
purl: PURL.into(),
2147+
uuid: U1.into(),
2148+
file: "crates/a/Cargo.toml".into(),
2149+
detail: "crates/a/Cargo.toml declares serde \"1\" from crates.io, not registry \
2150+
\"socket-patch-…\"; re-run `socket-patch scan` to pin it too"
2151+
.into(),
2152+
kind: UnattestedKind::CargoUnpinnedDeclaration,
2153+
});
2154+
let gated = plan(
2155+
&common(tmp.path()),
2156+
Sources {
2157+
manifest: PatchManifest::new(),
2158+
vendor: VendorState::new(),
2159+
redirect: Some(redirect),
2160+
discovery: found,
2161+
},
2162+
&[],
2163+
&RunApiClient::new(),
2164+
)
2165+
.await;
2166+
assert!(gated.view.patches.is_empty() && gated.hosted.is_empty());
2167+
assert_eq!(
2168+
gated.gated,
2169+
vec![failed(PURL, NOTE_CARGO_UNPINNED_DECLARATION)]
2170+
);
2171+
assert!(
2172+
gated
2173+
.notes
2174+
.iter()
2175+
.any(|n| n.code == NOTE_CARGO_UNPINNED_DECLARATION
2176+
&& n.detail.contains("crates/a/Cargo.toml declares serde")
2177+
&& n.detail.ends_with(
2178+
"re-run `socket-patch scan` to pin it too; not attested while that \
2179+
declaration stands"
2180+
)),
2181+
"{:?}",
2182+
gated.notes
2183+
);
2184+
}
2185+
2186+
/// A vendored Cargo copy beside a copy of the crate its `[patch]`
2187+
/// entry does not redirect is omitted as `vex_cargo_patch_bypassed`,
2188+
/// the note naming that copy and the remedy.
2189+
#[tokio::test]
2190+
async fn a_vendored_cargo_copy_beside_a_bypassing_source_is_gated() {
2191+
const PURL: &str = "pkg:cargo/serde@1.0.1";
2192+
let tmp = tempfile::tempdir().unwrap();
2193+
let mut manifest = PatchManifest::new();
2194+
manifest.patches.insert(PURL.into(), record(U1));
2195+
let vref = vendor_ref(&format!(".socket/vendor/cargo/{U1}/serde-1.0.1")).unwrap();
2196+
let mut found = discovery(vec![PatchedRef::vendored(
2197+
PURL.into(),
2198+
&vref,
2199+
"Cargo.toml",
2200+
None,
2201+
)]);
2202+
found.unattested.push(socket_patch_core::vex::Unattested {
2203+
purl: PURL.into(),
2204+
uuid: U1.into(),
2205+
file: "crates/a/Cargo.toml".into(),
2206+
detail: "crates/a/Cargo.toml declares serde \"1\" from registry `my-corp`".into(),
2207+
kind: UnattestedKind::CargoPatchBypassed,
2208+
});
2209+
let gated = plan(
2210+
&common(tmp.path()),
2211+
Sources {
2212+
manifest,
2213+
vendor: VendorState::new(),
2214+
redirect: None,
2215+
discovery: found,
2216+
},
2217+
&[],
2218+
&RunApiClient::new(),
2219+
)
2220+
.await;
2221+
assert!(gated.view.patches.is_empty() && gated.hosted.is_empty());
2222+
assert_eq!(gated.gated, vec![failed(PURL, NOTE_CARGO_PATCH_BYPASSED)]);
2223+
assert!(
2224+
gated
2225+
.notes
2226+
.iter()
2227+
.any(|n| n.code == NOTE_CARGO_PATCH_BYPASSED
2228+
&& n.detail.contains("from registry `my-corp`")
2229+
&& n.detail.contains("says how to clear it")),
2230+
"{:?}",
2231+
gated.notes
2232+
);
2233+
}
2234+
20932235
/// Ledger-only records with no wiring anywhere are gated, except the
20942236
/// manifest-owned one, which falls back to agent-mode verification; an
20952237
/// in-run confirmed purl is live by construction.

‎crates/socket-patch-cli/tests/e2e_vex_lockfile/cargo.rs‎

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -913,48 +913,31 @@ fn cargo_hosted_f_spoofed_references_never_attest() {
913913
let run = fx.vex(&["--proxy-url", &api.uri()]);
914914
assert_nothing_discovered(&run, "foreign host");
915915
assert_eq!(api.hits(), 0, "a foreign-host uuid is never even fetched");
916-
// DELIBERATE (the staging fallback): a uuid on a host outside the
917-
// allowlist is not a lockfile reference, but it is not "recognized"
918-
// either, so a redirect-ledger record for it falls back to the ledger's
919-
// own recorded wiring files — which still name it — so that a staging
920-
// `scan --mode hosted` run without `--patch-server-url` keeps
921-
// attesting. Hash verification still judges the copy the build
922-
// consumes (the foreign registry's): nothing is installed here, so the
923-
// default run omits it; only `--no-verify`, which trusts the ledger's
924-
// record by definition, attests.
916+
// Fail closed: a ledger record wired through a hosted-shaped url on an
917+
// unconfigured origin is `redirect_unwired` whatever is installed, even
918+
// under `--no-verify` (CLI_CONTRACT.md, "Patch hosts (manifest-less VEX)").
925919
write_redirect_ledger(&fx, CARGO_PURL, cargo_record(U), CARGO_HOSTED_EDITS);
926-
let run = fx.vex(&["--offline"]);
927-
assert_omitted(
928-
&run,
929-
CARGO_PURL,
930-
"package_not_found",
931-
"foreign host + ledger",
932-
);
933-
fx.install_crate(SOCKET_CARGO_SRC, PATCHED_RS);
934-
let run = fx.vex(&["--offline"]);
935-
assert_omitted(
936-
&run,
937-
CARGO_PURL,
938-
"package_not_found",
939-
"foreign host + ledger: Socket's copy is not what this lock builds",
940-
);
941-
fx.install_crate("evil.example-0123456789abcdef", PRISTINE_RS);
942-
let run = fx.vex(&["--offline"]);
943-
assert_eq!(
944-
run.code,
945-
Some(1),
946-
"foreign registry's pristine copy: {}",
947-
run.env
948-
);
949-
let run = fx.vex(&["--offline", "--no-verify"]);
950-
assert_attested(
951-
&fx,
952-
&run,
953-
CARGO_PURL,
954-
U,
955-
"redirected",
956-
"staging fallback, --no-verify",
957-
);
920+
for (state, install) in [
921+
("not installed", None),
922+
("Socket's patched copy", Some(SOCKET_CARGO_SRC)),
923+
(
924+
"the foreign registry's patched copy",
925+
Some("evil.example-0123456789abcdef"),
926+
),
927+
] {
928+
if let Some(src) = install {
929+
fx.install_crate(src, PATCHED_RS);
930+
}
931+
for extra in [&["--offline"][..], &["--offline", "--no-verify"][..]] {
932+
let run = fx.vex(extra);
933+
assert_omitted(
934+
&run,
935+
CARGO_PURL,
936+
"redirect_unwired",
937+
&format!("foreign host + ledger, {state} {extra:?}"),
938+
);
939+
}
940+
}
958941

959942
// The same foreign origin configured as the operator's patch server.
960943
let fx = Fx::new();

0 commit comments

Comments
 (0)