diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index 1235ca0db..1339b4076 100644 --- a/crates/socket-patch-cli/CLI_CONTRACT.md +++ b/crates/socket-patch-cli/CLI_CONTRACT.md @@ -547,9 +547,9 @@ Recognition rules that hold for every ecosystem: * **Patch hosts.** A hosted reference counts only on `https://patch.socket.dev` or the `--patch-server-url` / `SOCKET_PATCH_SERVER_URL` origin, with no userinfo. The uuid is the URL's LAST canonical-uuid path segment, because grant tokens may themselves be uuid-shaped. The Go module prefix is fixed. `socket-patch-` registry / repository / source names count only through a pin. For a URL on any other host, see **Patch hosts** above. * **Pins, not definitions.** A registry, index or source *definition* alone (cargo `[registries]`, nuget ``, pom ``, uv index tables, `.npmrc`) never makes a reference, because it survives a reverted pin. Sections the package manager ignores are not read: npm's v2 `dependencies` mirror, a `.cargo/config.toml` shadowed by `.cargo/config`. A Socket pin inside a maven `` is diagnosed, never a reference. * **Contested locks.** When one lock wires a package to a patch and another lock resolves the same `name@version` from a non-Socket source, the build's bytes depend on which package manager runs. The reference is then dropped with a `patched_ref_unattributable` diagnostic naming both files. This applies across npm / pnpm / yarn / bun and across uv / pylock / poetry / pdm / Pipfile.lock / requirements. PEP 723 script locks neither contest nor are contested. The root `requirements.txt` and its in-root `-r` includes count as one lock here: pip reads them as one requirement set, where a direct reference wins over a compatible `==` pin of the same version in another file of the set (#1086). A PyPI version matches under PEP 440 equality, so a requirements line pinned in any spelling that can only install the wired release (`==1.2.3.0`, `==v1.2.3`, `===1.2.3`) contests it like `==1.2.3` does; a range or wildcard (`~=1.2.3`, `==1.2.*`) does not (#1602). A **bundled** npm copy (`inBundle: true`, or v1 `bundled: true`, beneath a dependency that bundles it; the root project's own bundles install from the lock, #1618) of the same `name@version` contests the reference too, in the same lock, in the other npm lock of a shrinkwrap/package-lock pair, or in any other lock. npm unpacks it from the parent package's tarball, so no rewire reaches it and it stays unpatched. Bun and vlt unpack bundled copies the same way (#469, #471). pnpm unpacks bundled copies too, but its lock cannot tie one to a reference (see **Unattested references** below). For Bun, that is a `bun.lock` entry whose meta is `{ "bundled": true }`, or a `bun.lockb` record that a dependency edge with the `bundled` behavior bit reaches, including one Bun shares with a regular install. Such an entry is never a reference, and it contests the reference the same way. For vlt, the lock records no node for a bundled copy, so the copy is found in the installed store: a real package directory inside a store package's own `node_modules`. yarn classic's `yarn.lock` records nothing about bundled copies either (#758), so for a lock with a Socket wiring they are found in the installed `node_modules`: each package a parent's `bundleDependencies` / `bundledDependencies` names inside the parent's own `node_modules`, the dependencies of those beside them, and everything nested under them. Such a copy contests the reference in `yarn.lock` (the diagnostic names the parent's lock entry and the copy's directory); a lock-only `vex` with no `node_modules` can't see it. Hosted and vendored scans skip these copies with `redirect_bun_bundled_instance_skipped` / `redirect_vlt_bundled_instance_skipped` / `vendor_bundled_instance_skipped`, and a yarn classic hosted scan names one with `redirect_copy_unpatched`. When a bundled copy is the only instance, vendoring refuses with `vendor_lock_entry_not_rewritable`. A reference withheld only because such an unreachable copy installs beside it (a bundled npm / Bun / vlt copy, an npm copy beneath a `hasShrinkwrap` package (#753) or one npm installs from a git / url / `file:` spec, or a yarn classic git or `file:` directory block of the same `name@version`) is still the rewriter's own wiring of exactly one package version: it is never attested, but `rollback`, `remove`, `list` and the hosted → vendored takeover treat it as an ordinary hosted pin and restore its upstream registry entry (#828), rather than refusing it with `hosted_wiring_contested`. Another entry of the **same** npm, Bun or yarn lock that resolves the wired `name@version` from a non-Socket source (for example a workspace member added after the rewire, then `npm install` / `bun install` / `yarn install`; for yarn berry, a registry locator such as `left-pad@npm:1.3.0` beside the hosted `…::__archiveUrl=` one) contests the reference too (#588). The package manager installs both entries, and that copy stays unpatched. Re-running `scan` / `vendor` rewires every copy. -* **Unattested references.** Some evidence shows a build may run a copy no wiring reaches, but cannot be tied to the reference's exact `name@version` or cannot say the build runs it. The reference then stays a reference: `list`, `rollback` and `remove` find it, and the ledgers' liveness gates (`vendor --check`, `scan`) keep treating the wiring as live, because re-running `scan` / `vendor` could never clear the evidence. Only `vex` omits it, as a run warning and as the `failed[].reason`. Nine cases besides Gradle's (`vex_gradle_lock_above_base`) and NuGet's (`vex_nuget_lock_other_version`, see the table above); one of them, **hosted sbt pins a build bypasses** (`vex_sbt_pin_bypassed`), is under **Hosted sbt** above: **pnpm bundled copies** (`vex_pnpm_bundled_copy`): a `packages:` entry's `bundledDependencies:` names the copies pnpm unpacks from that package's own tarball, but pnpm never locks them, so the bundled version is not in the lock. A pnpm reference whose package name a `bundledDependencies` list in the same lock names is omitted whatever its version (a missed attestation when the bundled copy is another version, never a false one), and `bundledDependencies: true` (or a value that cannot be read) omits every reference of that lock. It reaches no other lock. **deno.lock** (`vex_deno_lock_copy`): `deno install` installs a `package.json` project's npm dependencies from `deno.lock` and never reads `package-lock.json` / `pnpm-lock.yaml` / `yarn.lock`, so an npm-family reference whose `name@version` the `deno.lock` npm section also locks is omitted (#406). Whether Deno or another package manager populates `node_modules` (`nodeModulesDir: "manual"` allows either) is not in the files, so this holds whatever `nodeModulesDir` says. **Maven reactor roots** (`vex_maven_reactor_root`): a hosted pin in a root `pom.xml` that declares `` / ``, or whose subprojects Maven 4 discovers (see the hosted Maven rewriter), is omitted, because a module's own literal `` overrides a root pin and module poms are not read (#261); hosted scan refuses such roots (`redirect_maven_multimodule_unsupported`), so this only covers pins an older release wrote. **Maven classifier copies** (`vex_maven_classifier_unpatched`): a `` dependency of a hosted-pinned GA is its own coordinate; the classifier-less pin does not retarget it and the grant serves only the main jar, so Maven fetches it from the next repository. When a live, non-profile classifier copy other than `sources` / `javadoc` (`tests`, a native or JDK-specific build) resolves any version other than the suffixed pin — its own literal ``, a `` entry with the same classifier, or no version in the root pom — the pin is omitted. `sources` / `javadoc` copies never run on a classpath and do not withhold the statement; hosted scan only warns about them (`redirect_maven_classifier_unsupported`) and skips the dep when an executable copy names the patched release. **pnpm branch locks** (`vex_pnpm_git_branch_lockfile`): with `gitBranchLockfile` on, pnpm installs a git branch from its own `pnpm-lock..yaml` (the **pnpm per-branch locks** state above), which no wiring reaches. `vex` does not decide whether the setting is on: the presence of any branch lock (at the root, or in a workspace member that installs from its own lock under `sharedWorkspaceLockfile: false`, read from the project's files and never from the environment) omits every reference of the root pnpm lock (`pnpm-lock.yaml`, or `shrinkwrap.yaml` without it) and of each member's own lock, hosted and vendored alike, whatever `gitBranchLockfile` or pnpm's `lockfile` setting says (#556; deterministic and fail-closed). This is checked only when a root or member pnpm lock wires a patch. Hosted mode refuses every pnpm pin when the setting is on and vendored mode refuses the project, so this also covers wiring written before the branch lock appeared. The run warning names the branch lock in the marked lock's own directory. Rush locks are not affected. **Self-patched npm and Bun packages** (`vex_npm_patched_dependency`): a reference in `package-lock.json` / `npm-shrinkwrap.json` / `bun.lock` / `bun.lockb` to a package the project patches itself is omitted, by the hosted rewriters' own per-dependency rule (`redirect_npm_patched_dependency_skipped`, #711; `redirect_bun_patched_dependency_skipped`, #367): a root `package.json` `patchedDependencies` key for its `name@version`, its bare name, or `name@` of a tarball other than the one the reference pins (npm and Bun alike, as both hosted gates read it); for npm also a non-null `patched` record on any present npm lock's entry for that `name@version`; for `bun.lock` also the keys it mirrors (the run warning then names `bun.lock` as the key's source). npm applies the user's diff on top of whatever tarball the lock names and Bun applies it only to the resolution it is keyed on, so both modes leave such a package unwired; this covers pins an earlier release wrote, and an npm one fails `npm ci` with `EPATCHFAILED` until `socket-patch rollback ` restores the registry entry (the remedy says so). A key naming the pinned tarball itself is no conflict; a reference with neither a hosted url nor a vendored tarball is matched by its `name@version` and counts every tarball key. Only a reference that survives the lock contests carries this reason. **Go workspaces** (`go_workspace_override`): a hosted or vendored Go `replace` that the workspace go resolves (an ancestor's `go.work`, one `GOWORK` names, members outside the project included) overrides, ignores or rejects, by the same check hosted and vendored modes run before writing one (`redirect_golang_workspace_conflict`, `vendor_go_workspace_conflict`), is omitted under the reason `vex`'s own go.mod gate reports. So is a replace in the root `go.work` while go builds another one. **Unpinned Cargo declarations** (`vex_cargo_unpinned_declaration`): cargo resolves each source on its own, so when one declaration of a crate pins it to `socket-patch-` but another — the root `Cargo.toml`'s or a workspace member's, read as hosted scan reads them — is not pinned, with a version requirement that may select the locked patched version, that declaration builds a separate, unpatched copy, possibly of the very version the pin covers. Not pinned means crates.io or another registry that no Socket `[patch.]` registry entry redirects, a `registry-index`, a path or git — the last three even beside `registry = "socket-patch-"`, which they override (hosted scan's own pinned check). The `Cargo.lock` reference is omitted, naming the unpinned declaration's manifest. Hosted scan pins every declaration, so this is a partial revert or a hand edit; the warning says whether re-running `scan` pins it again (a crates.io declaration whose requirement matches no other locked version of the crate) or cannot (`redirect_cargo_toml_dep_unrewritable`: roll the patch back or change the declaration). A declaration whose requirement excludes the patched version (cargo resolves it to another version), and a `[workspace.dependencies]` entry no manifest inherits, do not withhold the statement. When the lock already holds a same-version copy from another source, the reference is withheld as an unpatched lock copy instead. A declaration pinned to ANOTHER Socket patch, which the lock does not resolve the crate from, adds that patch's `Cargo.toml` reference, so the package is gated as `wiring_conflict`. +* **Unattested references.** Some evidence shows a build may run a copy no wiring reaches, but cannot be tied to the reference's exact `name@version` or cannot say the build runs it. The reference then stays a reference: `list`, `rollback` and `remove` find it, and the ledgers' liveness gates (`vendor --check`, `scan`) keep treating the wiring as live, because re-running `scan` / `vendor` could never clear the evidence. Only `vex` omits it, as a run warning and as the `failed[].reason`. Ten cases besides Gradle's (`vex_gradle_lock_above_base`) and NuGet's (`vex_nuget_lock_other_version`, see the table above); one of them, **hosted sbt pins a build bypasses** (`vex_sbt_pin_bypassed`), is under **Hosted sbt** above: **pnpm bundled copies** (`vex_pnpm_bundled_copy`): a `packages:` entry's `bundledDependencies:` names the copies pnpm unpacks from that package's own tarball, but pnpm never locks them, so the bundled version is not in the lock. A pnpm reference whose package name a `bundledDependencies` list in the same lock names is omitted whatever its version (a missed attestation when the bundled copy is another version, never a false one), and `bundledDependencies: true` (or a value that cannot be read) omits every reference of that lock. It reaches no other lock. **deno.lock** (`vex_deno_lock_copy`): `deno install` installs a `package.json` project's npm dependencies from `deno.lock` and never reads `package-lock.json` / `pnpm-lock.yaml` / `yarn.lock`, so an npm-family reference whose `name@version` the `deno.lock` npm section also locks is omitted (#406). Whether Deno or another package manager populates `node_modules` (`nodeModulesDir: "manual"` allows either) is not in the files, so this holds whatever `nodeModulesDir` says. **Maven reactor roots** (`vex_maven_reactor_root`): a hosted pin in a root `pom.xml` that declares `` / ``, or whose subprojects Maven 4 discovers (see the hosted Maven rewriter), is omitted, because a module's own literal `` overrides a root pin and module poms are not read (#261); hosted scan refuses such roots (`redirect_maven_multimodule_unsupported`), so this only covers pins an older release wrote. **Maven classifier copies** (`vex_maven_classifier_unpatched`): a `` dependency of a hosted-pinned GA is its own coordinate; the classifier-less pin does not retarget it and the grant serves only the main jar, so Maven fetches it from the next repository. When a live, non-profile classifier copy other than `sources` / `javadoc` (`tests`, a native or JDK-specific build) resolves any version other than the suffixed pin — its own literal ``, a `` entry with the same classifier, or no version in the root pom — the pin is omitted. `sources` / `javadoc` copies never run on a classpath and do not withhold the statement; hosted scan only warns about them (`redirect_maven_classifier_unsupported`) and skips the dep when an executable copy names the patched release. **pnpm branch locks** (`vex_pnpm_git_branch_lockfile`): with `gitBranchLockfile` on, pnpm installs a git branch from its own `pnpm-lock..yaml` (the **pnpm per-branch locks** state above), which no wiring reaches. `vex` does not decide whether the setting is on: the presence of any branch lock (at the root, or in a workspace member that installs from its own lock under `sharedWorkspaceLockfile: false`, read from the project's files and never from the environment) omits every reference of the root pnpm lock (`pnpm-lock.yaml`, or `shrinkwrap.yaml` without it) and of each member's own lock, hosted and vendored alike, whatever `gitBranchLockfile` or pnpm's `lockfile` setting says (#556; deterministic and fail-closed). This is checked only when a root or member pnpm lock wires a patch. Hosted mode refuses every pnpm pin when the setting is on and vendored mode refuses the project, so this also covers wiring written before the branch lock appeared. The run warning names the branch lock in the marked lock's own directory. Rush locks are not affected. **Self-patched npm and Bun packages** (`vex_npm_patched_dependency`): a reference in `package-lock.json` / `npm-shrinkwrap.json` / `bun.lock` / `bun.lockb` to a package the project patches itself is omitted, by the hosted rewriters' own per-dependency rule (`redirect_npm_patched_dependency_skipped`, #711; `redirect_bun_patched_dependency_skipped`, #367): a root `package.json` `patchedDependencies` key for its `name@version`, its bare name, or `name@` of a tarball other than the one the reference pins (npm and Bun alike, as both hosted gates read it); for npm also a non-null `patched` record on any present npm lock's entry for that `name@version`; for `bun.lock` also the keys it mirrors (the run warning then names `bun.lock` as the key's source). npm applies the user's diff on top of whatever tarball the lock names and Bun applies it only to the resolution it is keyed on, so both modes leave such a package unwired; this covers pins an earlier release wrote, and an npm one fails `npm ci` with `EPATCHFAILED` until `socket-patch rollback ` restores the registry entry (the remedy says so). A key naming the pinned tarball itself is no conflict; a reference with neither a hosted url nor a vendored tarball is matched by its `name@version` and counts every tarball key. Only a reference that survives the lock contests carries this reason. **Go workspaces** (`go_workspace_override`): a hosted or vendored Go `replace` that the workspace go resolves (an ancestor's `go.work`, one `GOWORK` names, members outside the project included) overrides, ignores or rejects, by the same check hosted and vendored modes run before writing one (`redirect_golang_workspace_conflict`, `vendor_go_workspace_conflict`), is omitted under the reason `vex`'s own go.mod gate reports. So is a replace in the root `go.work` while go builds another one. **Unpinned Cargo declarations** (`vex_cargo_unpinned_declaration`): cargo resolves each source on its own, so when one declaration of a crate pins it to `socket-patch-` but another — the root `Cargo.toml`'s or a workspace member's, read as hosted scan reads them — is not pinned, with a version requirement that may select the locked patched version, that declaration builds a separate, unpatched copy, possibly of the very version the pin covers. Not pinned means crates.io or another registry that no Socket `[patch.]` registry entry redirects, a `registry-index`, a path or git — the last three even beside `registry = "socket-patch-"`, which they override (hosted scan's own pinned check). The `Cargo.lock` reference is omitted, naming the unpinned declaration's manifest. Hosted scan pins every declaration, so this is a partial revert or a hand edit; the warning says whether re-running `scan` pins it again (a crates.io declaration whose requirement matches no other locked version of the crate) or cannot (`redirect_cargo_toml_dep_unrewritable`: roll the patch back or change the declaration). A declaration whose requirement excludes the patched version (cargo resolves it to another version), and a `[workspace.dependencies]` entry no manifest inherits, do not withhold the statement. When the lock already holds a same-version copy from another source, the reference is withheld as an unpatched lock copy instead. A declaration pinned to ANOTHER Socket patch, which the lock does not resolve the crate from, adds that patch's `Cargo.toml` reference, so the package is gated as `wiring_conflict`. **Vendored Cargo copies a `[patch]` does not reach** (`vex_cargo_patch_bypassed`): a `[patch.]` entry replaces the crate only in declarations from ``, and `vendor` writes `[patch.crates-io]`. So a vendored reference is omitted when a live declaration of the crate (the root `Cargo.toml`'s or a workspace member's) names another registry, a `registry-index` or a git repository, with a version requirement that may select the patched version, unless a `[patch]` table for its source points at the same copy (`[patch.]` for a registry dependency, `[patch.""]` for a git one, compared as cargo canonicalizes it: one trailing `/` and a `.git` suffix ignored, a GitHub URL case-insensitive); cargo builds that declaration's own, unpatched copy. Workspace members are read for this whenever the root manifest or the project cargo config wires a Socket copy through `[patch]`, whatever the lock says. It is also omitted when `Cargo.lock` locks the crate at exactly the patched version from any source (a registry, crates.io included, or git) beside the vendored copy; the warning names that lock entry. A path declaration (the user's own fork) does not withhold the statement. A `registry-index` declaration is covered by a `[patch.""]` table for the same index (a `registry+` prefix, the host's case and a trailing `/` ignored; a `sparse+` index is another source than the git one), and one naming the crates.io git index is crates.io. Only `[patch]` entries cargo honors count: a manifest entry the project config or a crates.io URL table replaces covers nothing. The warning ends with the remedy for its evidence: for a declaration, re-running `vendor` does not help (declare the crate from crates.io there, point a `[patch]` table for its source at the copy, or roll the patch back); for a stale crates.io lock entry beside a `[patch.crates-io]` copy, re-lock (re-run `vendor`, or `cargo update -p `); for another lock entry, `cargo tree -i @` names the dependency that declares it. * **Shrinkwrap without a twin (#899).** npm >= 12 never reads `npm-shrinkwrap.json`: on a project whose only npm lock is the shrinkwrap it resolves the tree from the registry and writes a fresh `package-lock.json`, so a Socket reference there reaches npm <= 11 only. The reference is still discovered, so `list`, `rollback` and `remove` manage it, but `vex` omits the patch (`vex_npm_shrinkwrap_only`, as a run warning and as the `failed[].reason`). A `package-lock.json` beside it (wired the same way) makes it attestable again. Hosted and vendored runs still rewire the shrinkwrap and warn `redirect_npm_shrinkwrap_only` / `vendor_npm_shrinkwrap_only`. -* **Lockless pins.** With no lock to name a version, a `Cargo.toml` pin (every declaration on `socket-patch-`, that registry defined on the patch host for the same uuid) or an exclusive nuget exact-id mapping is never a reference on its own, so v5.0 does not attest it (nor does `list` show it, or `rollback` / `remove` restore it — restore those files from version control). Only a pre-v5 redirect-ledger record naming a version the pin admits keeps it live. The same holds for a gem wired only in the `Gemfile` (the pre-bundler-2.6 mixed state, lock not converged). +* **Lockless pins.** With no lock to name a version, a `Cargo.toml` pin (every declaration on `socket-patch-`, that registry defined on the patch host for the same uuid) or an exclusive nuget exact-id mapping is never a reference on its own, so v5.0 does not attest it (nor does `list` show it, or `rollback` / `remove` restore it — restore those files from version control). Only a pre-v5 redirect-ledger record naming a version the pin admits keeps it live. For Cargo, declarations are read as for a locked pin: a `socket-patch-` registry beside `path`, `git` or `registry-index` is no pin (cargo builds that source), so it admits nothing and its requirement (any version, without one) is excluded from the pin; a `[workspace.dependencies]` template no manifest inherits is no declaration at all. The same holds for a gem wired only in the `Gemfile` (the pre-bundler-2.6 mixed state, lock not converged). **Record resolution.** A candidate's record must carry the patch uuid the lockfile actually **wires**. It is taken from the first source that has one: the manifest (matched qualifier-insensitively), the hosted records above (this run's, then a pre-v5 ledger's), then the vendor ledger's embedded records. If none has it and the run is online, `vex` fetches the patch view by uuid from the patch API — for a v5 hosted checkout this is the normal path. The fetch uses `get`'s API client: the public proxy when no token is configured, and a one-shot 401/403 fallback to the proxy (free patches only). At most 10 fetches run concurrently. Fetched records stay in memory: `vex` never writes the manifest. A candidate still has no record under `--offline`, after a transport error or a 404, or when the patch is refused (paid without an entitled token); it is then omitted as `record_unavailable`, and the run is not aborted. A record whose uuid or package disagrees with the wiring is omitted as `record_mismatch`. The informational `socket-patch.vendor.json` marker is never a record source. When the lockfile wires a package to patch U, a manifest or ledger record for that package under another uuid is superseded, and a human-mode `Note:` says so. @@ -2705,6 +2705,7 @@ match it, withholds the statement: | `go_workspace_override` | run warning and `failed[].reason` | A hosted or vendored Go `replace` is wired, but the workspace go resolves (an ancestor's `go.work`, one `GOWORK` names, members outside the project included) overrides, ignores or rejects it, or go builds another `go.work` than the root's that holds it; no statement while it does. `list`, `rollback` and `remove` still find the replace. | | `vex_maven_classifier_unpatched` | run warning and `failed[].reason` | A hosted Maven pin's GA also has a live executable `` copy (not `sources` / `javadoc`) at a version other than the pin, which the classifier-less pin does not retarget and the grant does not serve; no statement while it does. `list`, `rollback` and `remove` still find the pin. | | `vex_cargo_unpinned_declaration` | run warning and `failed[].reason` | A hosted Cargo pin is wired, but another declaration of the crate (the root's or a workspace member's) is not pinned (crates.io or another registry no Socket `[patch]` entry redirects, a `registry-index`, a path or git) and may select the patched version, so cargo builds a separate unpatched copy for it; no statement while it does. The warning says whether re-running `scan` can pin it. `list`, `rollback` and `remove` still find the pin. | +| `vex_cargo_patch_bypassed` | run warning and `failed[].reason` | A vendored Cargo copy is wired, but a declaration of the crate from another registry or git accepts the patched version, or `Cargo.lock` locks that version from a registry or git, and the copy's `[patch]` entry does not redirect it; no statement while it does. `list`, `rollback` and `remove` still find the wiring. | | `vex_pnpm_git_branch_lockfile` | run warning and `failed[].reason` | An npm pin is wired in a pnpm lock, but a `pnpm-lock..yaml` exists, which pnpm installs the branch from instead when `gitBranchLockfile` is on (#556); the branch lock's presence withholds the statement whatever the setting says, until the branch locks are folded in and deleted. `list`, `rollback` and `remove` still find the pin, and `vendor --check` and `scan` still treat the wiring as live. | | `vex_npm_patched_dependency` | run warning and `failed[].reason` | An npm or Bun pin is wired, but the project patches that package itself (`patchedDependencies`, or npm's lock-entry `patched` record; #711, #367), which hosted and vendored mode never wire; no statement while it does. `list`, `rollback` and `remove` still find the pin. | | `vex_sbt_resolution_unverified` | run warning and `failed[].reason` | A vendored sbt pin (`socket-patch-vendor.sbt`) whose resolution the build's local evidence does not verify, by the same check and build-wide blockers as a hosted sbt pin (no evidence or evidence older than a build source, a declared project with none, a `dependencyOverrides` / `resolvers` reassignment, a `build.sbt.lock`, project definitions that cannot be read statically, another version or other bytes resolved); no statement while it holds. The note names the cause and its remedy: `sbt update` clears stale or missing evidence, keeping the setting's existing entries (appending with `+=` / `++=` in place of a `:=`, `~=` or `--=`) clears a reassignment, removing what forces another version clears a version conflict, and a build whose projects cannot be read statically (a computed `Project(...)`, `projectMatrix`, `crossProject`) is never attested. `vendor --check` and `scan` still treat the wiring as live. | diff --git a/crates/socket-patch-cli/src/commands/vex_sources.rs b/crates/socket-patch-cli/src/commands/vex_sources.rs index b55ae65a3..312a35b18 100644 --- a/crates/socket-patch-cli/src/commands/vex_sources.rs +++ b/crates/socket-patch-cli/src/commands/vex_sources.rs @@ -239,6 +239,10 @@ const NOTE_MAVEN_CLASSIFIER_UNPATCHED: &str = "vex_maven_classifier_unpatched"; /// the crate that names no Socket registry, which cargo resolves as a /// separate, unpatched package (`vex::Unattested`). const NOTE_CARGO_UNPINNED_DECLARATION: &str = "vex_cargo_unpinned_declaration"; +/// Omission tag and note: a vendored Cargo copy beside a copy of the crate +/// from a source its `[patch]` entry does not redirect (another registry, +/// git), which cargo builds unpatched (`vex::Unattested`). +const NOTE_CARGO_PATCH_BYPASSED: &str = "vex_cargo_patch_bypassed"; /// Omission tag and note: a pnpm lock pins the patch, but a /// `pnpm-lock..yaml` exists, which pnpm installs from instead when /// `gitBranchLockfile` is on; its presence withholds (`vex::Unattested`). @@ -310,6 +314,11 @@ fn unattested_note(kind: UnattestedKind) -> (&'static str, &'static str) { NOTE_CARGO_UNPINNED_DECLARATION, "not attested while that declaration stands", ), + UnattestedKind::CargoPatchBypassed => ( + NOTE_CARGO_PATCH_BYPASSED, + "not attested while that copy can build beside the vendored one; the vendored \ + wiring itself is intact (the warning above says how to clear it)", + ), UnattestedKind::PnpmGitBranchLock => ( NOTE_PNPM_GIT_BRANCH_LOCKFILE, "not attested while any branch lock exists (or the members that could hold one \ @@ -2171,6 +2180,55 @@ mod tests { ); } + /// A vendored Cargo copy beside a copy of the crate its `[patch]` + /// entry does not redirect is omitted as `vex_cargo_patch_bypassed`, + /// the note naming that copy and the remedy. + #[tokio::test] + async fn a_vendored_cargo_copy_beside_a_bypassing_source_is_gated() { + const PURL: &str = "pkg:cargo/serde@1.0.1"; + let tmp = tempfile::tempdir().unwrap(); + let mut manifest = PatchManifest::new(); + manifest.patches.insert(PURL.into(), record(U1)); + let vref = vendor_ref(&format!(".socket/vendor/cargo/{U1}/serde-1.0.1")).unwrap(); + let mut found = discovery(vec![PatchedRef::vendored( + PURL.into(), + &vref, + "Cargo.toml", + None, + )]); + found.unattested.push(socket_patch_core::vex::Unattested { + purl: PURL.into(), + uuid: U1.into(), + file: "crates/a/Cargo.toml".into(), + detail: "crates/a/Cargo.toml declares serde \"1\" from registry `my-corp`".into(), + kind: UnattestedKind::CargoPatchBypassed, + }); + let gated = plan( + &common(tmp.path()), + Sources { + manifest, + vendor: VendorState::new(), + redirect: None, + discovery: found, + }, + &[], + &RunApiClient::new(), + ) + .await; + assert!(gated.view.patches.is_empty() && gated.hosted.is_empty()); + assert_eq!(gated.gated, vec![failed(PURL, NOTE_CARGO_PATCH_BYPASSED)]); + assert!( + gated + .notes + .iter() + .any(|n| n.code == NOTE_CARGO_PATCH_BYPASSED + && n.detail.contains("from registry `my-corp`") + && n.detail.contains("says how to clear it")), + "{:?}", + gated.notes + ); + } + /// Ledger-only records with no wiring anywhere are gated, except the /// manifest-owned one, which falls back to agent-mode verification; an /// in-run confirmed purl is live by construction. diff --git a/crates/socket-patch-core/src/patch/redirect/mod.rs b/crates/socket-patch-core/src/patch/redirect/mod.rs index 92ed9d4c4..d2f21c1af 100644 --- a/crates/socket-patch-core/src/patch/redirect/mod.rs +++ b/crates/socket-patch-core/src/patch/redirect/mod.rs @@ -2538,7 +2538,7 @@ fn cargo_manifest_package_id( /// in either the git-index or the sparse spelling. Compared the way cargo's /// `CanonicalUrl` does: host casing, a trailing `/` and a `.git` suffix do /// not make a different source (and github paths are case-insensitive). -fn is_crates_io_source(source: &str) -> bool { +pub(crate) fn is_crates_io_source(source: &str) -> bool { let url = source.trim(); let url = url .strip_prefix("registry+") diff --git a/crates/socket-patch-core/src/vex/discover/cargo.rs b/crates/socket-patch-core/src/vex/discover/cargo.rs index 46af02c95..564be0ec4 100644 --- a/crates/socket-patch-core/src/vex/discover/cargo.rs +++ b/crates/socket-patch-core/src/vex/discover/cargo.rs @@ -126,6 +126,14 @@ //! config), and a `[patch.""]` table in the manifest //! replaces `[patch.crates-io]` wholesale — both leave the lock looking //! exactly like live Socket wiring. +//! A `[patch.]` entry replaces the crate only in declarations from +//! ``, so a ref whose build may also compile a copy of the version +//! the wiring does not reach — a live declaration (root or member) from +//! another registry, a `registry-index` or git that may select the version +//! and that no `[patch]` table pointing at this copy redirects, or a +//! same-version lock entry from any source — stays a ref but is marked +//! [`super::UnattestedKind::CargoPatchBypassed`] ([`patch_bypassed`]); the +//! members are read for this whenever a `[patch]` wires a Socket copy. //! A `.socket/cargo-patches/` path (the retired redirect backend) carries no //! uuid and is not a ref. Socket-shaped entries in a `.cargo/config.toml` //! that cargo ignores (because `.cargo/config` exists) are diagnosed, never @@ -145,10 +153,11 @@ use crate::patch::redirect::generation::{hosted_pin_name, PIN_NAME_PREFIX}; use crate::patch::redirect::{cargo_req_selects, CargoReqMatch}; use crate::utils::digest::is_hex64_lower; use crate::vendor::cargo_config::{ - effective_config_rel_in, patch_entries, registry_definitions, CargoPatchEntry, CONFIG_LEGACY, - CONFIG_TOML, + effective_config_rel_in, patch_entries, registry_definitions, CONFIG_LEGACY, CONFIG_TOML, +}; +use crate::vendor::cargo_manifest::{ + crates_io_url_alias_tables, is_crates_io_source, is_crates_io_url_alias, }; -use crate::vendor::cargo_manifest::{crates_io_url_alias_tables, is_crates_io_source}; use crate::vendor::cargo_tag; use crate::vendor::lock_inventory::LockIntegrity; @@ -169,6 +178,21 @@ pub(crate) async fn extract(ctx: &DiscoverCtx<'_>, out: &mut Discovery) { let lock = load_lock(ctx, out).await; let root = read_toml(ctx, CARGO_TOML, out).await; let config = read_config(ctx, out).await; + // Every `[patch]` entry pointing at a Socket copy, the root manifest's + // (with why cargo ignores it, if it does) and then the config's. + let mut wired_all: Vec<(WiredCopy, Option)> = Vec::new(); + let mut shadow: Option = None; + if let Some(doc) = &root { + let s = Shadow::new(doc, config.as_ref()); + wired_all.extend(socket_copies(doc).into_iter().map(|w| { + let why = s.why(&w.table, &w.key, Some(&w.path), None); + (w, why) + })); + shadow = Some(s); + } + if let Some((_, doc)) = &config { + wired_all.extend(socket_copies(doc).into_iter().map(|w| (w, None))); + } // The root manifest, then every workspace member's — the manifests the // hosted rewriter pins a crate in (each that declares it). let mut manifests: Vec<(String, DocumentMut)> = Vec::new(); @@ -179,8 +203,11 @@ pub(crate) async fn extract(ctx: &DiscoverCtx<'_>, out: &mut Discovery) { || config .as_ref() .is_some_and(|c| c.1.to_string().contains(PIN_NAME_PREFIX)); + // A vendored copy wired in the root or the config is weighed against + // every member's declarations ([`patch_bypassed`]). + let vendored = !wired_all.is_empty(); manifests.push((CARGO_TOML.to_string(), doc)); - manifests.extend(read_members(ctx, &lock, root_pins, out).await); + manifests.extend(read_members(ctx, &lock, root_pins, vendored, out).await); } let manifest: Option<&DocumentMut> = manifests.first().map(|(_, doc)| doc); @@ -194,10 +221,14 @@ pub(crate) async fn extract(ctx: &DiscoverCtx<'_>, out: &mut Discovery) { for patch in patch_entries(doc) { if let Some(reg) = patch.registry { let name = patch.name.to_string(); - decls - .entry(name) - .or_default() - .push(Decl::patch(CARGO_TOML, patch.source, reg)); + // An entry cargo ignores (a crates.io URL table replaces + // `[patch.crates-io]`; the config redefines the key) is + // Socket's wiring still (the ref stays) but pins nothing. + let mut decl = Decl::patch(CARGO_TOML, patch.source, reg); + decl.live = shadow + .as_ref() + .is_none_or(|s| s.why(patch.source, patch.key, None, Some(reg)).is_none()); + decls.entry(name).or_default().push(decl); } } decls @@ -224,60 +255,27 @@ pub(crate) async fn extract(ctx: &DiscoverCtx<'_>, out: &mut Discovery) { if let Some(decls) = &decls { unresolved_manifest_pins(ctx, &lock, decls, &definitions, out); } + // Only the entries cargo honors redirect declarations to a copy: a + // shadowed manifest entry covers nothing (cargo builds whatever replaced + // it). + let wired: Vec = wired_all + .iter() + .filter(|(_, why)| why.is_none()) + .map(|(w, _)| w.clone()) + .collect(); + let bypass = Bypass { + lock: &lock, + decls: decls.as_ref(), + wired: &wired, + }; if let Some(doc) = manifest { - // Cargo drops a manifest crates.io `[patch]` item that the project - // config redefines under the same key (any version), and a - // `[patch.""]` table replaces `[patch.crates-io]` - // wholesale — a Socket entry there is dead wiring, never attested. - let config_keys: Vec<(&str, String, Option)> = config - .iter() - .flat_map(|(file, doc)| { - patch_entries(doc) - .into_iter() - .filter(|e| is_crates_io_source(e.source)) - .map(move |e| (*file, e.key.to_string(), e.path.map(same_path_key))) - }) - .collect(); - let aliases = crates_io_url_alias_tables(doc); - let shadowed = |entry: &CargoPatchEntry<'_>| -> Option { - if !is_crates_io_source(entry.source) { - return None; - } - if let (true, Some(alias)) = (entry.source == "crates-io", aliases.first()) { - return Some(format!( - "the `[patch.\"{alias}\"]` table replaces `[patch.crates-io]` in cargo" - )); - } - // The same key wiring the same copy (a half-migrated project) - // is not a shadow: the config's own ref carries it. - let own = entry.path.map(same_path_key); - config_keys - .iter() - .find(|(_, key, path)| key == entry.key && *path != own) - .map(|(file, key, _)| { - format!("{file} redefines `[patch]` key `{key}`, which replaces it in cargo") - }) - }; - vendored_from_patches(ctx, CARGO_TOML, doc, &lock, &shadowed, out).await; + vendored_from_patches(ctx, CARGO_TOML, doc, &lock, shadow.as_ref(), &bypass, out).await; } if let Some((file, doc)) = &config { - vendored_from_patches(ctx, file, doc, &lock, &|_| None, out).await; + vendored_from_patches(ctx, file, doc, &lock, None, &bypass, out).await; } - let wired: Vec = manifest - .into_iter() - .chain(config.iter().map(|(_, doc)| doc)) - .flat_map(socket_copies) - .collect(); - unattributed_tags(&lock, &wired, out); -} - -/// Every Socket copy a file's `[patch]` tables point at. -fn socket_copies(doc: &DocumentMut) -> Vec { - patch_entries(doc) - .into_iter() - .filter_map(|e| e.path.and_then(vendor_ref)) - .filter(|v| v.eco == "cargo") - .collect() + let copies: Vec = wired_all.into_iter().map(|(w, _)| w.vref).collect(); + unattributed_tags(&lock, &copies, out); } /// Diagnose Socket-tagged sourceless lock entries that no visible @@ -364,14 +362,20 @@ async fn read_toml(ctx: &DiscoverCtx<'_>, file: &str, out: &mut Discovery) -> Op /// Socket-sourced package, or a `socket-patch-` name in a member's own /// text, the root's or the config's (a pin to diagnose or recognize, a /// `[patch]` entry members declare, a lockless pin, [`UnlockedPin`]), -/// whatever the lock says (stale, unparseable or absent). +/// whatever the lock says (stale, unparseable or absent). `vendored` (the +/// root manifest or the config wires a Socket copy through `[patch]`, +/// whose lock entries are sourceless) always reads them: a member's +/// declaration from a source the `[patch]` does not redirect bypasses the +/// copy ([`patch_bypassed`]). async fn read_members( ctx: &DiscoverCtx<'_>, lock: &Lock, root_pins: bool, + vendored: bool, out: &mut Discovery, ) -> Vec<(String, DocumentMut)> { - let socket_sourced = matches!(lock, Lock::Parsed(_)) && has_socket_sourced(ctx, lock); + let socket_sourced = + vendored || (matches!(lock, Lock::Parsed(_)) && has_socket_sourced(ctx, lock)); let texts: Vec<(String, String)> = crate::utils::cargo_workspace::member_manifest_texts_in(&ctx.view) .await @@ -457,8 +461,8 @@ enum DeclSource { RegistryIndex(String), /// `path = "…"` (cargo builds it locally, whatever `registry` says). Path, - /// `git = "…"`. - Git, + /// `git = ""` (empty when the value is not a string). + Git(String), } /// One declaration of a crate: the root-relative file holding it, its @@ -515,21 +519,62 @@ impl Decl { } /// Whether the `[patch.]` table redirects this declaration: - /// a registry dependency of that registry (`crates-io`, or a crates.io - /// URL alias, for one with no `registry` or `registry = "crates-io"`, - /// which cargo reads as crates.io too). + /// + /// * a registry dependency of that registry (`crates-io`, or a + /// crates.io URL alias, for one with no `registry` or + /// `registry = "crates-io"`, which cargo reads as crates.io too); + /// * a `registry-index` dependency of that index URL + /// ([`patch_source_key`], the spelling `[patch]` tables compare in); + /// one naming the crates.io git index is crates.io itself (the same + /// cargo source), so `[patch.crates-io]` redirects it too; + /// * a git dependency of that repository ([`git_key`], cargo's + /// canonical spelling). + /// + /// Any other difference reads as another source: at worst a missed + /// redirect, so a withheld statement, never a false one. fn patched_by(&self, table: &str) -> bool { - self.source == DeclSource::Registry - && match self.registry.as_deref().map(str::trim) { + match &self.source { + DeclSource::Registry => match self.registry.as_deref().map(str::trim) { None | Some("crates-io") => is_crates_io_source(table), Some(reg) => reg == table, + }, + DeclSource::RegistryIndex(url) => { + (is_crates_io_url_alias(url) && is_crates_io_source(table)) + || patch_source_key(url) == patch_source_key(table) + } + DeclSource::Git(url) => git_key(url).is_some_and(|k| git_key(table) == Some(k)), + DeclSource::Path | DeclSource::Patch(_) => false, + } + } + + /// "`` declares `` `` from ``", for + /// messages. A `path` / `git` / `registry-index` overrides a Socket + /// registry named beside it: that is said too, or the message reads as + /// if the registry were missing (review on #2019). + fn describe(&self, name: &str) -> String { + let req = self + .version + .as_deref() + .map_or_else(|| "with no version".to_string(), |v| format!("{v:?}")); + let beside = match self.registry.as_deref() { + Some(reg) + if reg.starts_with(PIN_NAME_PREFIX) && self.source != DeclSource::Registry => + { + format!(", which overrides its registry = \"{reg}\"") } + _ => String::new(), + }; + format!( + "{} declares {name} {req} from {}{beside}", + self.file, + self.origin() + ) } /// Where cargo takes this dependency from, for messages. fn origin(&self) -> String { match (&self.source, self.registry.as_deref()) { - (DeclSource::Git, _) => "a git repository".to_string(), + (DeclSource::Git(_), _) => "a git repository".to_string(), (DeclSource::Path, _) => "a local path".to_string(), (DeclSource::RegistryIndex(url), _) => format!("the registry index {url}"), (_, Some(reg)) => format!("registry `{reg}`"), @@ -538,6 +583,77 @@ impl Decl { } } +/// `url` with its scheme and host lowercased (both are case-insensitive), +/// trimmed, or `None` when empty. +fn lower_host(url: &str) -> Option { + let url = url.trim(); + if url.is_empty() { + return None; + } + let host_end = url.find("://").map(|s| s + 3).map_or(0, |start| { + start + url[start..].find('/').unwrap_or(url.len() - start) + }); + Some(format!( + "{}{}", + url[..host_end].to_ascii_lowercase(), + &url[host_end..] + )) +} + +/// A git repository URL as cargo's `CanonicalUrl` spells it: one trailing +/// `/` dropped, a GitHub URL lowercased whole (GitHub paths are +/// case-insensitive), a trailing `.git` dropped. `None` when empty. +fn git_key(url: &str) -> Option { + let mut url = lower_host(url)?; + if url.ends_with('/') { + url.pop(); + } + let github = url + .split_once("://") + .is_some_and(|(_, rest)| rest.split('/').next() == Some("github.com")); + if github { + url = url.to_ascii_lowercase(); + } + if let Some(stripped) = url.strip_suffix(".git") { + url = stripped.to_string(); + } + Some(url) +} + +/// A registry index URL for comparison: a `registry+` prefix (the lock's +/// spelling of a git index) dropped, a `sparse+` one kept (a sparse index +/// is another cargo source than the git index at the same URL), the host +/// lowercased and a trailing `/` dropped. `None` when empty. +fn index_key(url: &str) -> Option { + let url = url.trim(); + let url = url.strip_prefix("registry+").unwrap_or(url); + let (sparse, url) = match url.strip_prefix("sparse+") { + Some(rest) => ("sparse+", rest), + None => ("", url), + }; + let url = lower_host(url)?; + Some(format!("{sparse}{}", url.trim_end_matches('/'))) +} + +/// The source of a lock entry of `name` at exactly `version` that is not a +/// Socket patch server's: a copy cargo builds from crates.io, another +/// registry or git beside the patched one. +fn same_version_foreign_entry<'l>( + ctx: &DiscoverCtx<'_>, + lock: &'l Lock, + name: &str, + version: &str, +) -> Option<&'l str> { + lock.packages() + .iter() + .filter(|p| p.name == name && p.version == version) + .find_map(|p| { + p.source + .as_deref() + .filter(|s| source_uuid(ctx, s).is_none()) + }) +} + /// Crate name → its declarations ([`Decl`]). type Decls = BTreeMap>; @@ -660,7 +776,7 @@ fn dependency_entries(doc: &DocumentMut) -> Vec { } else if let Some(entry) = item.as_table_like() { let field = |k: &str| entry.get(k).and_then(Item::as_str).map(str::to_string); let source = if entry.contains_key("git") { - DeclSource::Git + DeclSource::Git(field("git").unwrap_or_default()) } else if entry.contains_key("path") { DeclSource::Path } else if let Some(url) = field("registry-index") { @@ -770,8 +886,17 @@ fn hosted_from_lock( beside_the_pin(ctx, lock, manifests, pkg, &purl, &uuid, regs, out); continue; } + // Pins to another Socket patch that may select this version; one + // whose requirement excludes it (or a template nobody inherits) is + // about another version, so it neither conflicts nor keeps the + // stale entry. let others: Vec<(&str, String)> = regs .iter() + .filter(|d| { + d.live + && cargo_req_selects(d.version.as_deref(), &pkg.version, &[]) + != CargoReqMatch::NotOurs + }) .filter_map(|d| Some((d.file.as_str(), d.pin()?))) .collect(); if others.is_empty() { @@ -882,13 +1007,7 @@ fn beside_the_pin( out: &mut Discovery, ) { let same_name = || lock.packages().iter().filter(|p| p.name == pkg.name); - let twin = same_name().any(|p| { - p.version == pkg.version - && p.source - .as_deref() - .is_some_and(|s| source_uuid(ctx, s).is_none()) - }); - if twin { + if same_version_foreign_entry(ctx, lock, &pkg.name, &pkg.version).is_some() { return; } let others = distinct( @@ -899,7 +1018,7 @@ fn beside_the_pin( let patch_pins: Vec<(&str, String)> = regs .iter() .filter_map(|d| match &d.source { - DeclSource::Patch(table) => Some((table.as_str(), d.socket_uuid()?)), + DeclSource::Patch(table) if d.live => Some((table.as_str(), d.socket_uuid()?)), _ => None, }) .collect(); @@ -936,29 +1055,7 @@ fn beside_the_pin( }; let declared = unpinned .iter() - .map(|(d, _)| { - let req = d - .version - .as_deref() - .map_or_else(|| "with no version".to_string(), |v| format!("{v:?}")); - // A `path` / `git` / `registry-index` overrides a Socket - // registry named beside it: say so, or the note reads as if the - // registry were missing (review on #2019). - let beside = match d.registry.as_deref() { - Some(reg) - if reg.starts_with(PIN_NAME_PREFIX) && d.source != DeclSource::Registry => - { - format!(", which overrides its registry = \"{reg}\"") - } - _ => String::new(), - }; - format!( - "{} declares {} {req} from {}{beside}", - d.file, - pkg.name, - d.origin() - ) - }) + .map(|(d, _)| d.describe(&pkg.name)) .collect::>() .join(", and "); let (that, each) = if unpinned.len() == 1 { @@ -1131,13 +1228,20 @@ fn unresolved_manifest_pins( let mut uuids: Vec = Vec::new(); for decl in regs.iter().filter(|d| d.socket_shaped()) { let reg = decl.registry.as_deref().unwrap_or_default(); - match decl.socket_uuid() { - Some(uuid) if !uuids.contains(&uuid) => uuids.push(uuid), - Some(_) => {} - None if !malformed.contains(&(decl.file.as_str(), reg)) => { - malformed.push((decl.file.as_str(), reg)); - } - None => {} + if decl.socket_uuid().is_none() && !malformed.contains(&(decl.file.as_str(), reg)) { + malformed.push((decl.file.as_str(), reg)); + } + } + // Classified like a locked pin ([`route`]): only a live registry + // dependency or `[patch]` entry naming `socket-patch-` pins + // (beside `path` / `git` / `registry-index` the registry key does + // not decide, as in the rewriter's own pinned check), and a + // `[workspace.dependencies]` template nobody inherits declares + // nothing. + let live: Vec<&Decl> = regs.iter().filter(|d| d.live).collect(); + for uuid in live.iter().filter_map(|d| d.pin()) { + if !uuids.contains(&uuid) { + uuids.push(uuid); } } for (file, reg) in malformed { @@ -1150,23 +1254,69 @@ fn unresolved_manifest_pins( ), ); } + // A well-formed Socket registry that pins nothing: say so, since the + // file reads like wiring. + let mut ineffective: Vec<(&str, String)> = Vec::new(); + for d in regs + .iter() + .filter(|d| d.socket_uuid().is_some() && (d.pin().is_none() || !d.live)) + { + let why = if d.live { + format!( + "cargo builds it from {}, whatever `registry` says", + d.origin() + ) + } else if matches!(d.source, DeclSource::Patch(_)) { + "cargo ignores that `[patch]` entry (a crates.io URL table or the project config replaces it)" + .to_string() + } else { + "no manifest inherits that `[workspace.dependencies]` entry".to_string() + }; + if !ineffective.contains(&(d.file.as_str(), why.clone())) { + ineffective.push((d.file.as_str(), why)); + } + } + for (file, why) in ineffective { + out.diag( + DIAG_REF_INVALID, + file, + format!("{file}: {name}'s Socket patch registry pins nothing there: {why}"), + ); + } if uuids.is_empty() { continue; } - let socket_sourced = lock.packages().iter().any(|p| { + // Patches the lock resolves the crate from, and those a ref + // already carries (the lock's, or a conflict pair beside it). + let locked_from: Vec = lock + .packages() + .iter() + .filter(|p| p.name == *name) + .filter_map(|p| p.source.as_deref().and_then(|s| source_uuid(ctx, s))) + .collect(); + // Whether the lock also resolves the crate from a non-Socket source + // (or a path): then "only from other Socket patches" is not what it + // says (review on #2024). + let locked_elsewhere = lock.packages().iter().any(|p| { p.name == *name && p.source .as_deref() - .and_then(|s| source_uuid(ctx, s)) - .is_some() + .is_none_or(|s| source_uuid(ctx, s).is_none()) }); - if socket_sourced { - continue; // a ref (or the conflict pair) came from the lock - } + let carried = |uuid: &str| { + locked_from.iter().any(|u| u == uuid) + || out.refs.iter().any(|r| { + r.uuid == uuid + && crate::utils::purl::purl_parts(&r.purl) + .is_some_and(|(ty, n, _)| ty == "cargo" && n == *name) + }) + }; + let uuids: Vec = uuids.into_iter().filter(|u| !carried(u)).collect(); for uuid in &uuids { - let pinning: Vec<&Decl> = regs + let pinning: Vec<&Decl> = live .iter() - .filter(|d| d.socket_uuid().as_deref() == Some(uuid.as_str())) + .copied() + .filter(|d| d.pin().as_deref() == Some(uuid.as_str())) .collect(); let reg = pinning[0].registry.as_deref().unwrap_or_default(); let file = pinning[0].file.as_str(); @@ -1175,20 +1325,26 @@ fn unresolved_manifest_pins( Lock::Absent => { // Another Socket registry (or a malformed one) for the // same crate is a conflict, never a pin. - let only_this_patch = regs + let only_this_patch = live .iter() - .filter(|d| d.socket_shaped()) - .all(|d| d.socket_uuid().as_deref() == Some(uuid.as_str())); + .filter(|d| { + d.socket_shaped() + && matches!(d.source, DeclSource::Registry | DeclSource::Patch(_)) + }) + .all(|d| d.pin().as_deref() == Some(uuid.as_str())); let defined_here = definitions .get(reg) .and_then(|index| source_uuid(ctx, index)) .is_some_and(|u| u == *uuid); let version_reqs = distinct(pinning.iter().map(|d| d.version.clone())); - // `None` when some unpinned declaration carries no - // requirement (git, path): it may resolve any version. - let excluded_reqs: Option> = regs + // Every live dependency declaration this patch does + // not pin (a `path` / `git` / `registry-index` one + // beside a `socket-patch-` registry included); `None` + // when one carries no requirement: it may resolve any + // version. + let excluded_reqs: Option> = live .iter() - .filter(|d| !d.socket_shaped()) + .filter(|d| !matches!(d.source, DeclSource::Patch(_)) && d.pin().is_none()) .map(|d| d.version.clone()) .collect(); if let (true, true, false, Some(excluded_reqs)) = ( @@ -1210,6 +1366,11 @@ fn unresolved_manifest_pins( } format!("there is no {CARGO_LOCK} to fix its version") } + Lock::Parsed { .. } if !locked_from.is_empty() && !locked_elsewhere => format!( + "{CARGO_LOCK} resolves it only from other Socket patches, at versions \ + this pin's requirement excludes (a stale lock: the next build \ + re-resolves this declaration)" + ), Lock::Parsed { .. } => format!( "{CARGO_LOCK} does not resolve it from a Socket patch server (a stale \ lock, or a patch server outside the allowlist — see \ @@ -1267,14 +1428,366 @@ async fn copy_tag(ctx: &DiscoverCtx<'_>, artifact_rel: &str, out: &mut Discovery } } -/// Vendored refs from one file's `[patch]` tables. `shadowed` names why -/// cargo ignores an entry (a higher-precedence item replaces it), if so. +/// One `[patch.
]` entry that points at a Socket copy. +#[derive(Debug, Clone)] +struct WiredCopy { + table: String, + key: String, + path: String, + vref: VendorRef, +} + +/// Every Socket copy a file's `[patch]` tables point at. +fn socket_copies(doc: &DocumentMut) -> Vec { + patch_entries(doc) + .into_iter() + .filter_map(|e| { + let path = e.path?; + let vref = vendor_ref(path).filter(|v| v.eco == "cargo")?; + Some(WiredCopy { + table: e.source.to_string(), + key: e.key.to_string(), + path: path.to_string(), + vref, + }) + }) + .collect() +} + +/// Why cargo ignores a root-manifest `[patch]` entry, if it does: a +/// `[patch.""]` table replaces `[patch.crates-io]` +/// wholesale, and a project-config `[patch]` item for the same source and +/// key replaces the manifest's (unless both wire the same path, the +/// half-migrated shape attested through the config). Config entries are +/// never shadowed. +struct Shadow { + /// The manifest's `[patch.""]` table keys. + aliases: Vec, + /// The config's `[patch]` items. + config_keys: Vec, + /// The config's `[registries.] index` values: a `[patch.]` + /// table patches the same source as `[patch.""]`. + registries: BTreeMap, +} + +/// One config `[patch]` item as [`Shadow`] compares it: (file, source +/// table, key, path, registry). +type ConfigPatchItem = (&'static str, String, String, Option, Option); + +/// A `[patch.]` table name, a `registry-index` or a lock `source` +/// as cargo's `CanonicalUrl` spells it, for comparison: a URL's host case, +/// a trailing `/` or `.git` and a GitHub path's case ignored, a lock's +/// `registry+` prefix dropped, `sparse+` kept (another source); a registry +/// name verbatim. +fn patch_source_key(source: &str) -> String { + let t = source.trim(); + let key = if t.starts_with("sparse+") { + index_key(t) + } else if t.contains("://") { + git_key(t.strip_prefix("registry+").unwrap_or(t)) + } else { + None + }; + key.unwrap_or_else(|| t.to_string()) +} + +/// Whether two `[patch.]` table names patch the same source: +/// crates.io under any spelling, else the same name or URL +/// ([`patch_source_key`]). +fn same_patch_source(a: &str, b: &str) -> bool { + if is_crates_io_source(a) || is_crates_io_source(b) { + return is_crates_io_source(a) && is_crates_io_source(b); + } + patch_source_key(a) == patch_source_key(b) +} + +impl Shadow { + fn new(manifest: &DocumentMut, config: Option<&(&'static str, DocumentMut)>) -> Self { + let config_keys = config + .into_iter() + .flat_map(|(file, doc)| { + patch_entries(doc).into_iter().map(move |e| { + ( + *file, + e.source.to_string(), + e.key.to_string(), + e.path.map(same_path_key), + e.registry.map(|r| r.trim().to_string()), + ) + }) + }) + .collect(); + let registries = config + .and_then(|(_, doc)| doc.get("registries")) + .and_then(toml_edit::Item::as_table_like) + .into_iter() + .flat_map(|t| t.iter()) + .filter_map(|(name, item)| { + let index = item.as_table_like()?.get("index")?.as_str()?; + Some((name.to_string(), index.to_string())) + }) + .collect(); + Shadow { + aliases: crates_io_url_alias_tables(manifest), + config_keys, + registries, + } + } + + /// `table`, a registry name resolved to its configured index URL. + fn resolved<'s>(&'s self, table: &'s str) -> &'s str { + self.registries + .get(table.trim()) + .map_or(table, String::as_str) + } + + /// Why cargo ignores the manifest's `[patch.
]` item `key` + /// (wiring `path`, or Socket registry `registry`), if it does. + fn why( + &self, + table: &str, + key: &str, + path: Option<&str>, + registry: Option<&str>, + ) -> Option { + if let (true, Some(alias)) = (table == "crates-io", self.aliases.first()) { + return Some(format!( + "the `[patch.\"{alias}\"]` table replaces `[patch.crates-io]` in cargo" + )); + } + // Only identical wiring is the same: the same path, or the same + // registry for path-less items (review on #2024). Two path-less + // items otherwise (a registry pin and a git fork, say) are not. + let own = path.map(same_path_key); + let own_reg = registry.map(str::trim); + let same_wiring = |p: &Option, r: &Option| match (&own, own_reg) { + (Some(_), _) => *p == own, + (None, Some(reg)) => p.is_none() && r.as_deref() == Some(reg), + (None, None) => false, + }; + self.config_keys + .iter() + .find(|(_, src, k, p, r)| { + k == key + && same_patch_source(self.resolved(src), self.resolved(table)) + && !same_wiring(p, r) + }) + .map(|(file, _, k, _, _)| { + format!("{file} redefines `[patch]` key `{k}`, which replaces it in cargo") + }) + } +} + +/// What a vendored copy is weighed against for copies its `[patch]` wiring +/// does not redirect ([`patch_bypassed`]). +struct Bypass<'a> { + lock: &'a Lock, + /// Every declaration in the root and member manifests (`None`: no + /// usable root manifest). + decls: Option<&'a Decls>, + /// The `[patch]` entries pointing at a Socket copy that cargo honors + /// (a shadowed manifest entry redirects nothing). + wired: &'a [WiredCopy], +} + +/// Mark the vendored ref `purl` (the copy `vref` of `name`@`version`) +/// [`UnattestedKind::CargoPatchBypassed`] when the build may also compile +/// a copy of that version its wiring does not reach. A `[patch.
]` +/// entry replaces the crate only in declarations from `
` (v5 +/// `vendor` writes `[patch.crates-io]`), so either of these builds +/// unpatched bytes: +/// +/// * a declaration (the root's or a workspace member's) that [`route`] +/// finds [`Route::Unpinned`] against the honored entries pointing at +/// this copy — the classifier hosted pins use, with this copy's tables +/// as the pins: a live dependency that may select `version` from a +/// source no such table redirects (another registry, a +/// `registry-index`, git, or crates.io when the copy is wired for +/// another source only). A path declaration (the user's own fork) is +/// left alone, as the lock's copy claim leaves its sourceless entry +/// alone; a `socket-patch-*` registry dependency is hosted wiring; +/// * a `Cargo.lock` entry of `name` at exactly `version` with a non-Socket +/// source: that copy is already locked beside the vendored one. +/// +/// The detail ends with the remedy for its evidence. The ref stays +/// (rollback, remove and the ledgers still see the wiring), but nothing +/// attests it. +fn patch_bypassed( + ctx: &DiscoverCtx<'_>, + bypass: &Bypass<'_>, + vref: &VendorRef, + name: &str, + version: &str, + purl: &str, + out: &mut Discovery, +) { + let pins: Vec<(&str, String)> = bypass + .wired + .iter() + .filter(|w| w.vref.uuid == vref.uuid && w.vref.leaf == vref.leaf) + .map(|w| (w.table.as_str(), vref.uuid.clone())) + .collect(); + let others = distinct( + bypass + .lock + .packages() + .iter() + .filter(|p| p.name == name && cargo_tag::strip_tag(&p.version) != version) + .map(|p| Some(cargo_tag::strip_tag(&p.version).to_string())), + ); + let mut declared: Vec<&Decl> = Vec::new(); + let mut pinned_elsewhere: Vec<(&Decl, String)> = Vec::new(); + for d in bypass.decls.and_then(|d| d.get(name)).into_iter().flatten() { + match route(d, &pins, version, &others) { + Route::Unpinned(_) if d.source != DeclSource::Path => declared.push(d), + Route::Pin(uuid) if uuid != vref.uuid => pinned_elsewhere.push((d, uuid)), + _ => {} + } + } + // A declaration pinned to ANOTHER Socket patch builds that patch's + // copy, not this one. Only a ref for that patch at this very package, + // emitted by the hosted pass (from the lock, or a conflict pair beside + // a lock pin) and not itself withheld, puts the pair before the CLI's + // conflict gate; otherwise (a stale lock, a lock line whose config + // index disagrees, another locked version) nothing else says so. + // "Withheld" here is exactly the CLI's `bypassed_ref`: a file-scoped + // mark on the ref's own file (review on #2024); any other mark leaves + // the ref in the conflict gate. + let gated = |uuid: &str| { + out.refs.iter().any(|r| { + r.uuid == uuid + && r.purl == purl + && !out.unattested.iter().any(|u| { + u.kind.file_scoped() + && u.uuid == uuid + && u.purl == purl + && u.file == r.source_file + }) + }) + }; + let other_patch: Vec<(&Decl, String)> = pinned_elsewhere + .into_iter() + .filter(|(_, uuid)| !gated(uuid)) + .collect(); + // Named in every detail, so one `vex` run shows each cause (review on + // #2024). + let also_other = if other_patch.is_empty() { + String::new() + } else { + format!( + ". Also: {}, which no wiring of that patch pairs with this copy", + other_patch + .iter() + .map(|(d, uuid)| format!("{} (Socket patch {uuid})", d.describe(name))) + .collect::>() + .join(", and ") + ) + }; + let locked = same_version_foreign_entry(ctx, bypass.lock, name, version); + let redirects = format!( + "which no [patch] entry pointing at {} redirects", + vref.artifact_rel + ); + let (file, detail) = match (declared.first(), locked) { + (Some(first), _) => { + let evidence = locked.map_or_else(String::new, |source| { + format!("; {CARGO_LOCK} also locks {name} {version} from {source}") + }); + let declared = declared + .iter() + .map(|d| d.describe(name)) + .collect::>() + .join(", and "); + ( + first.file.as_str(), + format!( + "{declared}, {redirects}: cargo resolves that declaration as a separate \ + package, so the crate declaring it builds an unpatched {name} that the \ + requirement allows to be {version}{evidence}. Re-running `vendor` does \ + not change this: declare {name} from crates.io there (or point a \ + [patch] table for its source at the copy), or roll the patch \ + back{also_other}" + ), + ) + } + (None, Some(source)) => { + // A crates.io entry beside a copy `[patch.crates-io]` wires is + // stale (cargo would redirect it); any other is declared by + // some dependency, or left over from one that was removed. + // Likewise a git entry a `[patch.""]` table + // pointing at the copy redirects (review on #2024). + let stale = (crate::patch::redirect::is_crates_io_source(source) + && pins.iter().any(|(table, _)| is_crates_io_source(table))) + || source.trim().strip_prefix("git+").is_some_and(|repo| { + let repo = repo.split(['?', '#']).next().unwrap_or(repo); + pins.iter().any(|(table, _)| { + git_key(table).is_some() && git_key(table) == git_key(repo) + }) + }); + let remedy = if stale { + format!( + "the entry is stale (`[patch.crates-io]` redirects crates.io), so \ + re-lock: re-run `socket-patch vendor`, or `cargo update -p {name}`" + ) + } else { + format!( + "`cargo tree -i {name}@{version}` names the dependency that declares it \ + (change that declaration or roll the patch back); if none does any \ + more, re-lock with `cargo update -p {name}`" + ) + }; + ( + CARGO_LOCK, + format!( + "{CARGO_LOCK} also locks {name} {version} from {source}, {redirects}: \ + cargo builds that copy unpatched beside the vendored one; \ + {remedy}{also_other}" + ), + ) + } + (None, None) => { + let Some((first, _)) = other_patch.first() else { + return; + }; + let declared = other_patch + .iter() + .map(|(d, uuid)| format!("{} (Socket patch {uuid})", d.describe(name))) + .collect::>() + .join(", and "); + ( + first.file.as_str(), + format!( + "{declared}, which no wiring of that patch for {name} {version} pairs \ + with this copy (a stale {CARGO_LOCK}, or a registry definition that \ + disagrees): cargo resolves that declaration from that patch's registry, \ + so the crate declaring it builds {name} with another patch than the copy \ + at {}, and the requirement allows it to be {version}. Keep one patch for \ + {name}: pin that declaration to this patch (or drop it), or roll this \ + patch back", + vref.artifact_rel + ), + ) + } + }; + out.unattested( + purl, + &vref.uuid, + file, + detail, + UnattestedKind::CargoPatchBypassed, + ); +} + +/// Vendored refs from one file's `[patch]` tables. `shadow` (the root +/// manifest's) names why cargo ignores an entry (a higher-precedence item +/// replaces it), if so. async fn vendored_from_patches( ctx: &DiscoverCtx<'_>, file: &str, doc: &DocumentMut, lock: &Lock, - shadowed: &(dyn Fn(&CargoPatchEntry<'_>) -> Option + Sync), + shadow: Option<&Shadow>, + bypass: &Bypass<'_>, out: &mut Discovery, ) { for entry in patch_entries(doc) { @@ -1285,7 +1798,7 @@ async fn vendored_from_patches( continue; // a user path, or the uuid-less `.socket/cargo-patches/` } let name = entry.name; - if let Some(why) = shadowed(&entry) { + if let Some(why) = shadow.and_then(|s| s.why(entry.source, entry.key, entry.path, None)) { out.diag( DIAG_REF_INVALID, file, @@ -1387,6 +1900,7 @@ async fn vendored_from_patches( continue; } } + patch_bypassed(ctx, bypass, &vref, name, version, &purl, out); out.push(PatchedRef::vendored(purl, &vref, file, None)); } } @@ -1892,6 +2406,81 @@ mod tests { assert!(!toml_ref.lockfile_basis_ok()); } + /// No declaration pins the lock's patch A, and the one pinning B + /// cannot select the locked version: B's pin is about another version, + /// so there is no conflict pair, and nothing routes the crate to A, so + /// the stale lock entry is no ref. (B's pin that may select it is the + /// conflict pair, see `manifest_and_lock_disagreeing_on_the_patch_emit_both`.) + #[tokio::test] + async fn another_patch_pin_excluding_the_locked_version_is_no_conflict() { + let p = Project::new(); + p.write("Cargo.toml", manifest(&pinned("serde", "=1.0.2", UUID_B))); + p.write( + "Cargo.lock", + lock(&[("serde", "1.0.1", Some(&index(UUID_A)), Some(CKSUM))]), + ); + let out = run(&p).await; + assert_refs(&out, &[]); + assert!( + diag_codes(&out).contains(&DIAG_REF_INVALID), + "{:#?}", + out.diagnostics + ); + // REVIEW: B's pin, which the lock does not reflect, is still + // diagnosed (it used to vanish once any Socket entry was locked). + assert!( + out.diagnostics + .iter() + .any(|d| d.code == DIAG_REF_UNATTRIBUTABLE + && d.file == std::path::Path::new("Cargo.toml") + && d.detail.contains(UUID_B) + && d.detail.contains("only from other Socket patches")), + "{:#?}", + out.diagnostics + ); + } + + /// REVIEW: a well-formed Socket registry that pins nothing — beside + /// `path` / `git` / `registry-index`, or on a `[workspace.dependencies]` + /// entry no manifest inherits — is diagnosed, since the file reads like + /// wiring. + #[tokio::test] + async fn an_ineffective_socket_registry_is_diagnosed() { + let reg = format!("registry = \"socket-patch-{UUID_A}\""); + let p = mixed_workspace( + &pinned("serde", "1", UUID_A), + &format!("serde = {{ path = \"../serde\", version = \"1\", {reg} }}"), + &[], + ); + let out = run(&p).await; + assert!( + out.diagnostics.iter().any(|d| d.code == DIAG_REF_INVALID + && d.file == std::path::Path::new("crates/a/Cargo.toml") + && d.detail.contains("pins nothing there") + && d.detail.contains("a local path")), + "{:#?}", + out.diagnostics + ); + + let p = Project::new(); + p.write( + "Cargo.toml", + format!( + "[workspace]\nmembers = [\"crates/*\"]\n\n[workspace.dependencies]\n{}\n", + pinned("serde", "1", UUID_A) + ), + ); + member(&p, "a", "other = \"1\""); + let out = run(&p).await; + assert!( + out.diagnostics.iter().any(|d| d.code == DIAG_REF_INVALID + && d.file == std::path::Path::new("Cargo.toml") + && d.detail.contains("no manifest inherits")), + "{:#?}", + out.diagnostics + ); + } + /// A project-config definition of the pinned registry that indexes a /// different patch (or a non-Socket host) is what cargo resolves /// against: the lock entry is stale. @@ -2061,6 +2650,36 @@ mod tests { p } + /// Review on #2019 (round 2, fixed here where `Shadow` lives): a + /// `[patch.crates-io]` Socket pin that cargo ignores (a crates.io URL + /// table replaces it) pins no declaration: the member's crates.io + /// declaration is unpinned, so the ref is not attested. + #[tokio::test] + async fn a_shadowed_patch_pin_pins_no_declaration() { + let patch = format!( + "serde = \"1\"\n\n[patch.crates-io]\nserde = {{ registry = \"socket-patch-{UUID_A}\" }}\n" + ); + let p = mixed_workspace(&patch, "serde = \"1\"", &[]); + let out = run(&p).await; + assert!(out.unattested.is_empty(), "{:#?}", out.unattested); + let shadowed = format!( + "{patch}\n[patch.\"https://github.com/rust-lang/crates.io-index\"]\nother = {{ path = \"other\" }}\n" + ); + let p = mixed_workspace(&shadowed, "serde = \"1\"", &[]); + let out = run(&p).await; + assert_refs( + &out, + &[("pkg:cargo/serde@1.0.1", UUID_A, WiringMode::Hosted)], + ); + assert!( + out.unattested + .iter() + .any(|u| u.kind == UnattestedKind::CargoUnpinnedDeclaration), + "{:#?}", + out.unattested + ); + } + /// The one unattested mark of `out`, asserted to be the hosted serde /// ref's [`UnattestedKind::CargoUnpinnedDeclaration`] naming `file`. fn unpinned_mark<'a>(out: &'a Discovery, file: &str) -> &'a Unattested { @@ -2548,13 +3167,102 @@ mod tests { ); } - /// REVIEW (one pin per crate and patch): the root and two members pin the - /// same patch — one lockless pin carrying every requirement, one - /// diagnostic listing each manifest once. + /// A `socket-patch-` registry beside `path`, `git` or + /// `registry-index` is no pin (cargo builds the path / git / index + /// source; the rewriter's own pinned check agrees): lockless, such a + /// member declaration is an unpinned one, so it excludes the versions it + /// accepts (all of them with no requirement), and alone it makes no + /// lockless pin at all. #[tokio::test] - async fn one_lockless_pin_and_diagnostic_per_crate_and_patch() { - let p = Project::new(); - pinned_root_workspace(&p); + async fn lockless_path_or_git_beside_a_socket_registry_is_no_pin() { + let record = "pkg:cargo/serde@1.0.1"; + let reg = format!("registry = \"socket-patch-{UUID_A}\""); + for member_decl in [ + format!("serde = {{ path = \"../serde\", version = \"1\", {reg} }}"), + format!("serde = {{ git = \"https://example.com/serde\", {reg} }}"), + format!( + "serde = {{ version = \"1\", registry-index = \"sparse+https://x.example/\", {reg} }}" + ), + ] { + let p = Project::new(); + pinned_root_workspace(&p); + member(&p, "a", &member_decl); + p.write(".cargo/config.toml", registry_block(UUID_A)); + let out = run(&p).await; + assert_refs(&out, &[]); + assert_eq!( + out.hosted_claim(record, UUID_A), + Some(false), + "{member_decl}: {:#?}", + out.unlocked_pins + ); + } + // The member's overridden registry alone: no pin anywhere. + let p = Project::new(); + workspace_with_member( + &p, + &format!("serde = {{ path = \"../serde\", version = \"1\", {reg} }}"), + ); + p.write(".cargo/config.toml", registry_block(UUID_A)); + let out = run(&p).await; + assert!(out.unlocked_pins.is_empty(), "{:#?}", out.unlocked_pins); + } + + /// A `[workspace.dependencies]` template no manifest inherits declares + /// nothing cargo resolves: lockless, a Socket-pinned one makes no pin, + /// and an unpinned one excludes no version from the root's pin. Once a + /// member inherits the pinned template, it is the pin. + #[tokio::test] + async fn lockless_uninherited_template_is_not_a_declaration() { + let template = |dep: &str| { + format!("[workspace]\nmembers = [\"crates/*\"]\n\n[workspace.dependencies]\n{dep}\n") + }; + let p = Project::new(); + p.write("Cargo.toml", template(&pinned("serde", "1", UUID_A))); + member(&p, "a", "other = \"1\""); + p.write(".cargo/config.toml", registry_block(UUID_A)); + let out = run(&p).await; + assert!(out.unlocked_pins.is_empty(), "{:#?}", out.unlocked_pins); + + let p = Project::new(); + p.write("Cargo.toml", template(&pinned("serde", "1", UUID_A))); + member(&p, "a", "serde = { workspace = true }"); + p.write(".cargo/config.toml", registry_block(UUID_A)); + let out = run(&p).await; + assert_eq!(out.unlocked_pins.len(), 1, "{:#?}", out.unlocked_pins); + assert_eq!( + out.hosted_claim("pkg:cargo/serde@1.0.1", UUID_A), + Some(true) + ); + + let p = Project::new(); + p.write( + "Cargo.toml", + format!( + "[workspace]\nmembers = [\"crates/*\"]\n\n[workspace.dependencies]\n\ + serde = \"1\"\n\n[package]\nname = \"app\"\nversion = \"0.1.0\"\n\n\ + [dependencies]\n{}\n", + pinned("serde", "1", UUID_A) + ), + ); + member(&p, "a", "other = \"1\""); + p.write(".cargo/config.toml", registry_block(UUID_A)); + let out = run(&p).await; + assert_eq!(out.unlocked_pins.len(), 1, "{:#?}", out.unlocked_pins); + assert!(out.unlocked_pins[0].excluded_reqs.is_empty()); + assert_eq!( + out.hosted_claim("pkg:cargo/serde@1.0.1", UUID_A), + Some(true) + ); + } + + /// REVIEW (one pin per crate and patch): the root and two members pin the + /// same patch — one lockless pin carrying every requirement, one + /// diagnostic listing each manifest once. + #[tokio::test] + async fn one_lockless_pin_and_diagnostic_per_crate_and_patch() { + let p = Project::new(); + pinned_root_workspace(&p); member(&p, "a", &pinned("serde", "1.0", UUID_A)); member( &p, @@ -3537,4 +4245,635 @@ mod tests { } } } + + // ── vendored: copies the [patch] does not redirect ─────────────── + + const MY_CORP: &str = "registry+https://my-corp.example/index"; + + /// A v5-vendored workspace: the root wires cfg-if 1.0.4 to the tagged + /// copy for patch A through `[patch.crates-io]` (plus `root_extra` + /// appended to the root manifest) and declares it from crates.io; the + /// member `crates/a` declares it with `member_dep`. The lock holds the + /// tagged copy plus `extra` entries `(version, source)`. + fn vendored_workspace(member_dep: &str, root_extra: &str, extra: &[(&str, &str)]) -> Project { + let rel = vendor_path(UUID_A, "cfg-if-1.0.4"); + let p = Project::new(); + p.write( + "Cargo.toml", + format!( + "[workspace]\nmembers = [\"crates/*\"]\n\n{}\n[patch.crates-io]\n\ + cfg-if-socket-aaaaaaaa = {{ package = \"cfg-if\", path = \"{rel}\" }}\n\ + {root_extra}\n", + manifest("cfg-if = \"1\"") + ), + ); + p.write( + "crates/a/Cargo.toml", + format!( + "[package]\nname = \"a\"\nversion = \"0.1.0\"\n\n[dependencies]\n{member_dep}\n" + ), + ); + let tagged = crate::vendor::cargo_tag::tag_version("1.0.4", UUID_A); + let mut pkgs = vec![("cfg-if", tagged.as_str(), None, None)]; + pkgs.extend( + extra + .iter() + .map(|(v, s)| ("cfg-if", *v, Some(*s), Some(CKSUM))), + ); + p.write("Cargo.lock", lock(&pkgs)); + p + } + + /// The one unattested mark of `out`, asserted to be the vendored + /// cfg-if ref's [`UnattestedKind::CargoPatchBypassed`] naming `file`. + fn bypassed_mark<'a>(out: &'a Discovery, file: &str) -> &'a Unattested { + assert_eq!(out.unattested.len(), 1, "{:#?}", out.unattested); + let u = &out.unattested[0]; + assert_eq!(u.kind, UnattestedKind::CargoPatchBypassed); + assert_eq!( + (u.purl.as_str(), u.uuid.as_str()), + ("pkg:cargo/cfg-if@1.0.4", UUID_A) + ); + assert_eq!(u.file, std::path::PathBuf::from(file)); + u + } + + /// REGRESSION: `[patch.crates-io]` redirects only crates.io + /// declarations. A member that declares cfg-if from another registry or + /// from git, at a requirement the patched 1.0.4 satisfies, resolves its + /// own unpatched copy, which may be that very version. The vendored ref + /// stays (rollback / remove find it, the ledger claim lives) but is not + /// attested, naming the member. + #[tokio::test] + async fn a_member_from_another_source_bypasses_the_vendored_copy() { + for (member, origin) in [ + ( + "cfg-if = { version = \"1\", registry = \"my-corp\" }", + "from registry `my-corp`", + ), + ( + "fork = { package = \"cfg-if\", version = \"=1.0.4\", registry = \"my-corp\" }", + "from registry `my-corp`", + ), + ( + "cfg-if = { git = \"https://example.com/cfg-if\" }", + "from a git repository", + ), + ( + "cfg-if = { version = \"1\", registry-index = \"sparse+https://my-corp.example/index/\" }", + "from the registry index sparse+https://my-corp.example/index/", + ), + ] { + let p = vendored_workspace(member, "", &[]); + let out = run(&p).await; + assert_refs( + &out, + &[("pkg:cargo/cfg-if@1.0.4", UUID_A, WiringMode::Vendored)], + ); + assert!( + out.diagnostics.is_empty(), + "{member}: {:#?}", + out.diagnostics + ); + assert_eq!( + out.vendored_claim( + "pkg:cargo/cfg-if@1.0.4", + UUID_A, + &vendor_path(UUID_A, "cfg-if-1.0.4") + ), + Some(true), + "{member}" + ); + let u = bypassed_mark(&out, "crates/a/Cargo.toml"); + assert!( + u.detail.contains("crates/a/Cargo.toml declares cfg-if") + && u.detail.contains(origin) + && !u.detail.contains("also locks"), + "{member}: {}", + u.detail + ); + } + } + + /// The lock already holds a same-version cfg-if from another source + /// (another registry, git, even crates.io) beside the vendored copy: + /// cargo builds that copy unpatched whoever declares it, so the mark + /// names the lock entry. A copy at another version is no such evidence. + #[tokio::test] + async fn a_same_version_lock_entry_from_any_source_bypasses_the_vendored_copy() { + for source in [MY_CORP, "git+https://example.com/cfg-if#abc123", CRATES_IO] { + let p = vendored_workspace("cfg-if = \"1\"", "", &[("1.0.4", source)]); + let out = run(&p).await; + assert_refs( + &out, + &[("pkg:cargo/cfg-if@1.0.4", UUID_A, WiringMode::Vendored)], + ); + let u = bypassed_mark(&out, "Cargo.lock"); + assert!( + u.detail + .contains(&format!("Cargo.lock also locks cfg-if 1.0.4 from {source}")), + "{source}: {}", + u.detail + ); + } + let p = vendored_workspace("cfg-if = \"1\"", "", &[("0.1.10", MY_CORP)]); + let out = run(&p).await; + assert_refs( + &out, + &[("pkg:cargo/cfg-if@1.0.4", UUID_A, WiringMode::Vendored)], + ); + assert!(out.unattested.is_empty(), "{:#?}", out.unattested); + } + + /// What the `[patch]` wiring redirects stays attested: a member + /// declaring cfg-if from crates.io, under any spelling, and a + /// declaration from elsewhere whose requirement excludes the patched + /// version, or a registry dependency whose `[patch.]` table + /// also points at the same copy; and a `[workspace.dependencies]` + /// template from another registry that no manifest inherits. A user's + /// own path fork is the documented exception (see + /// `a_same_version_fork_beside_the_tagged_copy_is_ignored`). + #[tokio::test] + async fn declarations_the_patch_redirects_keep_the_vendored_copy_attested() { + let rel = vendor_path(UUID_A, "cfg-if-1.0.4"); + let covered = format!("\n[patch.my-corp]\ncfg-if = {{ path = \"{rel}\" }}\n"); + let template = "\n[workspace.dependencies]\n\ + cfg-if = { version = \"1\", registry = \"my-corp\" }\n"; + for (member, root_extra) in [ + ("cfg-if = \"1\"", ""), + ("cfg-if = \"=1.0.4\"", ""), + ("cfg-if = { version = \"1\", registry = \"crates-io\" }", ""), + ("alias = { package = \"cfg-if\", version = \"1.0\" }", ""), + ("cfg-if = { version = \"0.1\", registry = \"my-corp\" }", ""), + ( + "cfg-if = { version = \"1\", registry = \"my-corp\" }", + covered.as_str(), + ), + ("cfg-if = { path = \"../fork\" }", ""), + ("cfg-if = \"1\"", template), + ] { + let p = vendored_workspace(member, root_extra, &[]); + let out = run(&p).await; + assert!( + out.refs.iter().any(|r| r.purl == "pkg:cargo/cfg-if@1.0.4" + && r.uuid == UUID_A + && r.mode == WiringMode::Vendored), + "{member}: {:#?}", + out.refs + ); + assert!(out.unattested.is_empty(), "{member}: {:#?}", out.unattested); + } + } + + /// A `[patch.""]` table pointing at the same copy redirects a + /// declaration from that repository (a trailing `/` or `.git` aside), + /// so the copy stays attested; one from another repository still + /// bypasses it. + #[tokio::test] + async fn a_git_patch_table_for_the_copy_covers_that_repository_only() { + let rel = vendor_path(UUID_A, "cfg-if-1.0.4"); + let table = + format!("\n[patch.\"https://example.com/cfg-if\"]\ncfg-if = {{ path = \"{rel}\" }}\n"); + for member in [ + "cfg-if = { git = \"https://example.com/cfg-if\" }", + "cfg-if = { git = \"https://example.com/cfg-if.git/\", branch = \"main\" }", + ] { + let out = run(&vendored_workspace(member, &table, &[])).await; + assert_refs( + &out, + &[("pkg:cargo/cfg-if@1.0.4", UUID_A, WiringMode::Vendored)], + ); + assert!(out.unattested.is_empty(), "{member}: {:#?}", out.unattested); + } + let out = run(&vendored_workspace( + "cfg-if = { git = \"https://example.com/fork/cfg-if\" }", + &table, + &[], + )) + .await; + bypassed_mark(&out, "crates/a/Cargo.toml"); + } + + /// The pre-v5 wiring in the project config redirects only crates.io + /// too: a member's git declaration bypasses it the same way. + #[tokio::test] + async fn a_member_from_git_bypasses_the_config_wired_copy() { + let p = Project::new(); + p.write( + ".cargo/config.toml", + patch_config(&[("cfg-if", &vendor_path(UUID_A, "cfg-if-1.0.4"))]), + ); + workspace_with_member(&p, "cfg-if = { git = \"https://example.com/cfg-if\" }"); + p.write("Cargo.lock", lock(&[("cfg-if", "1.0.4", None, None)])); + let out = run(&p).await; + assert_refs( + &out, + &[("pkg:cargo/cfg-if@1.0.4", UUID_A, WiringMode::Vendored)], + ); + bypassed_mark(&out, "crates/a/Cargo.toml"); + } + + /// REGRESSION (member gate): a vendored project's lock has no + /// Socket-sourced package (the copy's entry is sourceless), and a + /// lockless one has no `socket-patch-` pin, so the member walk must + /// not hinge on either: the members are read whenever a `[patch]` + /// wires a Socket copy, lock or no lock. + #[tokio::test] + async fn members_are_read_for_a_vendored_copy_without_a_socket_lock_entry() { + for with_lock in [true, false] { + let p = vendored_workspace( + "cfg-if = { version = \"1\", registry = \"my-corp\" }", + "", + &[], + ); + if !with_lock { + std::fs::remove_file(p.root().join("Cargo.lock")).unwrap(); + } + let out = run(&p).await; + assert_refs( + &out, + &[("pkg:cargo/cfg-if@1.0.4", UUID_A, WiringMode::Vendored)], + ); + bypassed_mark(&out, "crates/a/Cargo.toml"); + } + } + + // ── review findings ────────────────────────────────────────────── + + /// The one vendored cfg-if ref of `out`: attested (no mark) or not. + fn assert_vendored_attested(out: &Discovery, attested: bool, what: &str) { + assert_refs( + out, + &[("pkg:cargo/cfg-if@1.0.4", UUID_A, WiringMode::Vendored)], + ); + assert_eq!( + out.unattested.is_empty(), + attested, + "{what}: {:#?}", + out.unattested + ); + } + + /// REVIEW (false attestation): the project config redefines the + /// manifest's crates.io `[patch]` key with a git fork, so cargo ignores + /// the manifest's entry for the copy and builds the fork for crates.io + /// declarations. That shadowed entry used to count as redirecting them, + /// so the copy's other (honored) `[patch.my-corp]` entry was attested + /// beside the fork. + #[tokio::test] + async fn a_shadowed_manifest_entry_covers_no_declaration() { + let rel = vendor_path(UUID_A, "cfg-if-1.0.4"); + let p = vendored_workspace( + "cfg-if = \"1\"", + &format!("\n[patch.my-corp]\ncfg-if = {{ path = \"{rel}\" }}\n"), + &[], + ); + p.write( + ".cargo/config.toml", + "[patch.crates-io]\ncfg-if-socket-aaaaaaaa = { package = \"cfg-if\", git = \ + \"https://example.com/fork/cfg-if\" }\n", + ); + let out = run(&p).await; + assert_vendored_attested(&out, false, "shadowed"); + let u = bypassed_mark(&out, "Cargo.toml"); + assert!( + u.detail + .contains("Cargo.toml declares cfg-if \"1\" from crates.io"), + "{}", + u.detail + ); + assert!( + diag_codes(&out).contains(&DIAG_REF_INVALID), + "{:#?}", + out.diagnostics + ); + } + + /// Review on #2024 (round 3): a pin to another patch beside a lock that + /// also resolves the crate from crates.io is not described as "only + /// from other Socket patches". + #[tokio::test] + async fn another_patch_pin_beside_a_foreign_twin_is_not_called_socket_only() { + let p = mixed_workspace( + &pinned("serde", "1", UUID_A), + &pinned("serde", "1", UUID_B), + &[("1.0.1", CRATES_IO)], + ); + let out = run(&p).await; + let diag = out + .diagnostics + .iter() + .find(|d| d.code == DIAG_REF_UNATTRIBUTABLE && d.detail.contains(UUID_B)) + .unwrap_or_else(|| panic!("{:#?}", out.diagnostics)); + assert!( + !diag.detail.contains("only from other Socket patches"), + "{}", + diag.detail + ); + } + + /// REVIEW (Bugbot on #2024): a config item for the same key replaces + /// the manifest's `[patch]` item in cargo whatever the source table and + /// whether or not either wires a path: a path-less config git fork + /// shadows a path-less manifest registry pin, and a `[patch.my-corp]` + /// config item shadows the manifest's `[patch.my-corp]` copy. + #[test] + fn config_items_shadow_pathless_and_named_source_entries() { + let manifest: toml_edit::DocumentMut = "[package]\nname = \"x\"\n".parse().unwrap(); + let config: toml_edit::DocumentMut = "[patch.crates-io]\n\ + cfg-if-socket-aaaaaaaa = { package = \"cfg-if\", git = \"https://example.com/f\" }\n\ + [patch.my-corp]\n\ + cfg-if = { git = \"https://example.com/f\" }\n\ + [patch.\"https://My-Corp.example/index/\"]\n\ + cfg-if = { path = \"../fork\" }\n" + .parse() + .unwrap(); + let cfg = (".cargo/config.toml", config); + let s = super::Shadow::new(&manifest, Some(&cfg)); + // A path-less registry pin under the same key: shadowed. + assert!(s + .why( + "crates-io", + "cfg-if-socket-aaaaaaaa", + None, + Some("socket-patch-aaaaaaaa") + ) + .is_some()); + // The same key under another source: not. + assert!(s + .why( + "other", + "cfg-if-socket-aaaaaaaa", + None, + Some("socket-patch-aaaaaaaa") + ) + .is_none()); + // A named non-crates.io table: shadowed. + assert!(s.why("my-corp", "cfg-if", Some("vendor/x"), None).is_some()); + // A URL table, compared as an index. + assert!(s + .why( + "https://my-corp.example/index", + "cfg-if", + Some("vendor/x"), + None + ) + .is_some()); + // A canonical-equivalent git table (Bugbot on a7611ef). + let config: toml_edit::DocumentMut = + "[patch.\"https://GitHub.com/Corp/Fork.git/\"]\ncfg-if = { git = \"https://example.com/f\" }\n" + .parse() + .unwrap(); + let cfg2 = (".cargo/config.toml", config); + let s2 = super::Shadow::new(&manifest, Some(&cfg2)); + assert!(s2 + .why( + "https://github.com/corp/fork", + "cfg-if", + Some("vendor/x"), + None + ) + .is_some()); + assert!(s2 + .why( + "sparse+https://github.com/corp/fork", + "cfg-if", + Some("vendor/x"), + None + ) + .is_none()); + // The half-migrated shape: the same path is the same wiring. + assert!(s + .why( + "https://my-corp.example/index", + "cfg-if", + Some("../fork"), + None + ) + .is_none()); + // Review on #2024: the identical path-less Socket registry pin in + // both files is the same wiring, not a shadow. + let config: toml_edit::DocumentMut = + "[patch.crates-io]\nserde = { registry = \"socket-patch-aaaaaaaa\" }\n" + .parse() + .unwrap(); + let cfg3 = (".cargo/config.toml", config); + let s3 = super::Shadow::new(&manifest, Some(&cfg3)); + assert!(s3 + .why("crates-io", "serde", None, Some("socket-patch-aaaaaaaa")) + .is_none()); + assert!(s3 + .why("crates-io", "serde", None, Some("socket-patch-bbbbbbbb")) + .is_some()); + // Review on #2024: a `[patch.""]` config table patches the + // same source as the manifest's `[patch.]` for a registry + // defined on that index. + let config: toml_edit::DocumentMut = "[registries.my-corp]\n\ + index = \"https://my-corp.example/index\"\n\ + [patch.\"https://my-corp.example/index\"]\n\ + cfg-if = { git = \"https://example.com/fork\" }\n" + .parse() + .unwrap(); + let cfg4 = (".cargo/config.toml", config); + let s4 = super::Shadow::new(&manifest, Some(&cfg4)); + assert!(s4 + .why("my-corp", "cfg-if", Some("vendor/x"), None) + .is_some()); + assert!(s4 + .why("other-corp", "cfg-if", Some("vendor/x"), None) + .is_none()); + } + + /// REVIEW: a `registry-index` declaration is redirected by a + /// `[patch.""]` table for the same index (host case, a + /// trailing `/` and the lock's `registry+` spelling aside; `sparse+` is + /// another source), and one naming the crates.io git index is + /// crates.io. The sparse crates.io index stays another source: whether + /// `[patch.crates-io]` reaches it is not what the files show, so it is + /// withheld rather than risked. + #[tokio::test] + async fn a_registry_index_patch_table_covers_that_index() { + let rel = vendor_path(UUID_A, "cfg-if-1.0.4"); + let table = |key: &str| format!("\n[patch.\"{key}\"]\ncfg-if = {{ path = \"{rel}\" }}\n"); + let decl = + |index: &str| format!("cfg-if = {{ version = \"1\", registry-index = \"{index}\" }}"); + for (member, extra, attested) in [ + ( + decl("https://My-Corp.example/index/"), + table("https://my-corp.example/index"), + true, + ), + ( + decl("sparse+https://my-corp.example/index/"), + table("sparse+https://my-corp.example/index"), + true, + ), + ( + decl("https://github.com/rust-lang/crates.io-index"), + String::new(), + true, + ), + ( + decl("sparse+https://my-corp.example/index/"), + table("https://my-corp.example/index"), + false, + ), + ( + decl("https://other.example/index"), + table("https://my-corp.example/index"), + false, + ), + ( + decl("sparse+https://index.crates.io/"), + String::new(), + false, + ), + ] { + let out = run(&vendored_workspace(&member, &extra, &[])).await; + assert_vendored_attested(&out, attested, &member); + } + } + + /// REVIEW: the remedy follows the evidence — a declaration cannot be + /// fixed by re-vendoring; a crates.io lock entry beside a + /// `[patch.crates-io]` copy is stale (re-lock); another source's entry + /// is some dependency's (`cargo tree -i` finds it). + #[tokio::test] + async fn the_bypass_remedy_follows_its_evidence() { + let out = run(&vendored_workspace( + "cfg-if = { version = \"1\", registry = \"my-corp\" }", + "", + &[], + )) + .await; + let u = bypassed_mark(&out, "crates/a/Cargo.toml"); + assert!( + u.detail + .contains("Re-running `vendor` does not change this"), + "{}", + u.detail + ); + + let out = run(&vendored_workspace( + "cfg-if = \"1\"", + "", + &[("1.0.4", CRATES_IO)], + )) + .await; + let u = bypassed_mark(&out, "Cargo.lock"); + assert!( + u.detail.contains("stale") + && u.detail.contains("cargo update -p cfg-if") + && !u.detail.contains("Re-running `vendor` does not"), + "{}", + u.detail + ); + + let out = run(&vendored_workspace( + "cfg-if = \"1\"", + "", + &[("1.0.4", MY_CORP)], + )) + .await; + let u = bypassed_mark(&out, "Cargo.lock"); + assert!( + u.detail.contains("cargo tree -i cfg-if@1.0.4") && !u.detail.contains("stale"), + "{}", + u.detail + ); + } + + /// REVIEW: git URLs compare as cargo's `CanonicalUrl` spells them — a + /// GitHub URL case-insensitively, any host's case aside, one trailing + /// `/` and `.git` dropped — so another path on a non-GitHub host is + /// another repository. + #[tokio::test] + async fn a_git_patch_table_matches_cargos_canonical_url() { + let rel = vendor_path(UUID_A, "cfg-if-1.0.4"); + let table = |key: &str| format!("\n[patch.\"{key}\"]\ncfg-if = {{ path = \"{rel}\" }}\n"); + let decl = |url: &str| format!("cfg-if = {{ git = \"{url}\" }}"); + for (member, extra, attested) in [ + ( + decl("https://GitHub.com/Foo/CFG-IF.git"), + table("https://github.com/foo/cfg-if"), + true, + ), + ( + decl("https://EXAMPLE.com/foo/cfg-if/"), + table("https://example.com/foo/cfg-if"), + true, + ), + ( + decl("https://example.com/Foo/cfg-if"), + table("https://example.com/foo/cfg-if"), + false, + ), + ] { + let out = run(&vendored_workspace(&member, &extra, &[])).await; + assert_vendored_attested(&out, attested, &member); + } + } + /// REGRESSION (Bugbot on #2024): a member pinned to ANOTHER Socket + /// patch builds that patch's copy. When the lock resolves cfg-if from + /// it, its hosted ref stands beside the vendored one and the CLI's + /// conflict gate refuses both; when the lock does not (stale), the + /// vendored copy is marked bypassed rather than attested alone. + #[tokio::test] + async fn a_member_pinned_to_another_patch_bypasses_the_vendored_copy() { + let p = vendored_workspace(&pinned("cfg-if", "1", UUID_B), "", &[]); + let out = run(&p).await; + assert_refs( + &out, + &[("pkg:cargo/cfg-if@1.0.4", UUID_A, WiringMode::Vendored)], + ); + let u = bypassed_mark(&out, "crates/a/Cargo.toml"); + assert!( + u.detail.contains("crates/a/Cargo.toml declares cfg-if") + && u.detail.contains(UUID_B) + && u.detail.contains("stale Cargo.lock"), + "{}", + u.detail + ); + + // Locked from that patch: the conflict pair, no bypass mark on A. + let b = index(UUID_B); + let p = vendored_workspace(&pinned("cfg-if", "1", UUID_B), "", &[("1.0.4", b.as_str())]); + let out = run(&p).await; + assert_refs( + &out, + &[ + ("pkg:cargo/cfg-if@1.0.4", UUID_B, WiringMode::Hosted), + ("pkg:cargo/cfg-if@1.0.4", UUID_A, WiringMode::Vendored), + ], + ); + assert!( + out.unattested.iter().all(|u| u.uuid != UUID_A), + "{:#?}", + out.unattested + ); + + // Locked from that patch, but the project's registry definition + // indexes another patch: the hosted pass emits no ref for it, so + // nothing pairs with the vendored copy and it is withheld. + let p = vendored_workspace(&pinned("cfg-if", "1", UUID_B), "", &[("1.0.4", b.as_str())]); + p.write( + ".cargo/config.toml", + format!( + "[registries.socket-patch-{UUID_B}]\nindex = \"{}\"\n", + index(UUID_A) + ), + ); + let out = run(&p).await; + assert!(out.refs.iter().all(|r| r.uuid != UUID_B), "{:#?}", out.refs); + bypassed_mark(&out, "crates/a/Cargo.toml"); + + // A requirement that excludes the vendored version says nothing. + let p = vendored_workspace(&pinned("cfg-if", "0.1", UUID_B), "", &[]); + let out = run(&p).await; + assert!( + out.unattested.iter().all(|u| u.uuid != UUID_A), + "{:#?}", + out.unattested + ); + } } diff --git a/crates/socket-patch-core/src/vex/discover/mod.rs b/crates/socket-patch-core/src/vex/discover/mod.rs index d1b9bdbd7..0097d9562 100644 --- a/crates/socket-patch-core/src/vex/discover/mod.rs +++ b/crates/socket-patch-core/src/vex/discover/mod.rs @@ -641,6 +641,13 @@ pub enum UnattestedKind { /// declaration from its own source as a separate package, so the crate /// declaring it builds an unpatched copy, possibly of this version. CargoUnpinnedDeclaration, + /// A vendored Cargo copy that a `[patch.]` entry wires (in v5, + /// the root's `[patch.crates-io]`) beside a copy of the crate from a + /// source that entry does not redirect: a declaration (the root's or a + /// workspace member's) from another registry or git whose requirement + /// accepts the patched version, or a same-version `Cargo.lock` entry + /// from any source. Cargo builds that copy unpatched. + CargoPatchBypassed, /// A pnpm lock's pin while any `pnpm-lock..yaml` exists (#556), /// whatever pnpm's `gitBranchLockfile` setting says (discovery reads no /// environment, so the setting cannot be decided), or while the members diff --git a/crates/socket-patch-core/tests/fixtures/vex-discover-golden/redirect-cargo.json b/crates/socket-patch-core/tests/fixtures/vex-discover-golden/redirect-cargo.json index 99be573f0..c14a317f3 100644 --- a/crates/socket-patch-core/tests/fixtures/vex-discover-golden/redirect-cargo.json +++ b/crates/socket-patch-core/tests/fixtures/vex-discover-golden/redirect-cargo.json @@ -634,7 +634,13 @@ "lockfile_basis_ok": true } ], - "diagnostics": [], + "diagnostics": [ + { + "code": "patched_ref_invalid", + "file": "Cargo.toml", + "detail": "Cargo.toml: serde's Socket patch registry pins nothing there: no manifest inherits that `[workspace.dependencies]` entry" + } + ], "recognized": [ { "uuid": "11111111-1111-1111-1111-111111111111",