diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index 8f2665cba..1e3b0c751 100644 --- a/crates/socket-patch-cli/CLI_CONTRACT.md +++ b/crates/socket-patch-cli/CLI_CONTRACT.md @@ -402,7 +402,7 @@ Pinned by `tests/scan/scan_proxy_fallback_e2e.rs`, `tests/cli/api_client_errors_ **Grant gate (additive).** A reference grant is the patch API's answer, and its fields are written into files the project commits. Each granted reference is therefore checked once, before anything is planned for it (no takeover, no artifact fetch, no rewriter sees one that fails): the patch uuid is a canonical lowercase uuid; the artifact URL and a registry override's index URL are `https` URLs of plain URL characters (no whitespace or control character, no quote, backslash, `$`, `{`, `}`, `<`, `>`, `&`, `#`, `;`, `|` or `^`; cargo's `sparse+` prefix is kept); `sha1` is 40 hex digits, `sha256` 64, `sha512` exactly one `sha512-` token, the Go hashes `h1:` hashes, the yarn berry checksum `/`, the cargo and gem checksums 64 hex digits; the package's name and version, and every identifier of a registry override, are in their ecosystem's coordinate grammar (letters, digits and that ecosystem's punctuation; Maven coordinates as the JVM backends accept them). A Maven grant's sha256 digests may also be spelled `sha256-…` / `sha256:…`: the pom, Gradle and sbt planners read those, and a digest that is still not 64 hex digits writes no checksum pin (`redirect_maven_trusted_checksums_invalid_hash`). An absent or empty optional field is not checked. A grant that fails is refused for that package only: a `skipped` event whose `errorCode` is `redirect_grant_malformed` and whose `reason` names the field (never its value), the same code and detail in `warnings[]`, nothing written for it, the rest of the run and the exit code unchanged. A plain-`http` artifact or index URL is refused the same way with `redirect_grant_insecure_url` (every later install would send the grant token in clear text), unless its origin is the `--patch-server-url` / `SOCKET_PATCH_SERVER_URL` origin (scheme, host and port) or a loopback address (`localhost`, `127.0.0.0/8`, `::1`). The in-memory engine applies the same gate; it has no configured origin. -The rewriter reads a fixed set of candidate files from the project root: the npm-family locks (`package-lock.json`, `npm-shrinkwrap.json`, `pnpm-lock.yaml`, `shrinkwrap.yaml`, `yarn.lock`, plus `.yarnrc.yml` for the berry cache-config gate, `bun.lock` / `bun.lockb`, and `vlt-lock.json` with `vlt.json` and `node_modules/.vlt-lock.json` read only), `requirements.txt` / `uv.lock` / `Pipfile.lock` (pipfile-spec 6; see the Pipenv section below) / `poetry.lock` (every Poetry lock generation from 1.0 on — the 0.12 `[metadata.hashes]` layout is refused because that installer ignores URL sources; a Poetry < 1.4 writer additionally gets `redirect_poetry_stale_install_risk`, see `docs/testing/poetry-compatibility.md`) / `pdm.lock` (PDM lock formats `2` and `4.3`–`4.5.1`; the identity-losing `3.1` / `4.0`–`4.2` formats and unknown future formats are refused with `redirect_pdm_refused`, and a lock-format-`2` writer additionally gets `redirect_pdm_legacy_sync_required`, see `docs/testing/pdm-compatibility.md`; when `uv.lock` or `poetry.lock` sits beside it they drive and `pdm.lock` is left alone), `Cargo.toml` / `Cargo.lock` / `.cargo/config.toml` (plus the legacy extensionless `.cargo/config` — cargo reads that spelling in preference when both exist, so the managed `[registries.…]` block is written into whichever one is present; the hosted redirect is a `sparse+` registry, which cargo loads only from **1.68**, so `rust-toolchain.toml` / `rust-toolchain` are read too (never edited) and a project whose declared floor — the lowest `rust-version` of the root and the member manifests read here (a `rust-version.workspace = true` inheritor reads `[workspace.package]`), else the channel rustup picks from the root (the legacy `rust-toolchain` over `rust-toolchain.toml`; a dated `nightly-`/`beta-YYYY-MM-DD` maps to its release train) — is below 1.68 is refused `redirect_cargo_old_cargo` per crate (nothing written, an earlier run's pins left in place with the `rollback` that drops them named; `--mode vendored` builds on cargo 1.41+), while an undeclared or rolling-channel floor still redirects (toolchain files in ancestor directories are not read); **cargo also reads every workspace-member manifest** — the `[workspace] members` globs minus `exclude` — and every in-root path-dependency manifest, recursively, reached without crossing a symbolic link and never under `.socket/`, and pins the crate in each one that declares it, so those `/Cargo.toml` files can appear in `rewrittenFiles`. A crate is redirected only when every declaration pins and every other `Cargo.lock` package depending on it is a planned member: one a registry or git crate — or a path package outside the root or behind a link — also depends on is refused `redirect_cargo_transitive_dependents` (a pin reaches only the declarations it sits on), a crate no manifest declares keeps `redirect_cargo_toml_dep_not_found` with a transitive-only detail naming `--mode vendored`, a crate every declaration of which requires another version (no requirement accepts the patched version) is refused `redirect_cargo_toml_dep_unrewritable`, and so is a requirement that also matches another locked version of the crate — each a transactional skip, never recorded or attested. With NO `Cargo.lock` there is no resolved graph to ask, so the dependents question is answered from the manifests instead: a crate declared beside any other dependency — anything but a path dependency on a manifest this run also pins, or a `workspace = true` inheritor of a table it scans — or beside a workspace member this run did not read (a `members` glob, or a member outside the project or behind a symbolic link, which member discovery drops) is refused `redirect_cargo_lockless_dependents`, whose detail names the remedies (commit a lockfile, or `--mode vendored`); a project whose only dependency is the patched crate has nothing that could pull it in and still redirects. All-CRLF manifests, locks and configs are rewritten with CRLF kept (mixed endings keep refusing where the grammar does not match), and `remove` / rollback match the recorded fragments across a later CRLF↔LF checkout conversion), `composer.lock`, `nuget.config` / `packages.lock.json` (plus, v5.0 #353/#514, every lock a project under the root restores into: a member project's `packages.lock.json`, a per-project `packages..lock.json`, a literal `NuGetLockFilePath` — each pinned with the root config; a `NuGetLockFilePath` it cannot evaluate warns `redirect_nuget_lock_path_unresolved` and a project tree it cannot list warns `redirect_nuget_lock_unreadable`, both skipping the nuget redirect with nothing written), `Gemfile` / `Gemfile.lock`, `pom.xml` (+ `.mvn/maven.config` / `.mvn/checksums/checksums.sha256` for maven Trusted Checksums merge, and, for a Gradle build, every settings, build, `buildSrc`, included-build, applied and plugin-source script, version catalog and lock file the script graph reaches, plus `gradle/verification-metadata.xml`, `gradle/wrapper/gradle-wrapper.properties` and the owned `.socket/gradle/` files), and the sbt build files (`socket-patch.sbt`, `socket-patch-vendor.sbt`, `build.sbt`, `project/build.properties`, `.sbtopts`, `.jvmopts`; `build.sbt.lock` and the Mill / scala-cli build files `build.mill`, `build.mill.yaml`, `build.sc`, `.mill-version`, `project.scala` for their presence only) — read, never edited; `socket-patch.sbt` is the only sbt file hosted mode writes (see **Hosted sbt** below). **npm-family flavor coverage**: package-lock / npm-shrinkwrap (a package the project patches itself with npm ≥ 12.1's native `npm patch` — a root `patchedDependencies` key, or the lock entry's `patched` record — is left on its registry entry in every npm lock, `redirect_npm_patched_dependency_skipped`), pnpm (root OR any nested `*/pnpm-lock.yaml`), yarn classic (a yarn 2+ install migrates a v1 `yarn.lock` and drops its pins, so a run whose v1 lock carries a hosted pin warns `redirect_yarn_classic_berry_migration_risk` — the hosted twin of the vendored `yarn_classic_berry_migration_risk` — unless the root `package.json`, read as advisory input, declares `"packageManager": "yarn@1…"`), **yarn berry** (the pin yarn writes for a root `resolutions` entry: the root `package.json` — edited only beside a berry `yarn.lock` — gains one `"@npm:": ""` selector per locked range (`redirect_yarn_berry_resolution` edits), and only that `yarn.lock` entry is re-keyed `"@"` with the same `resolution:` + `yarnBerry10c0` checksum (`redirect_yarn_berry_entry`), moved to yarn's key order; never an `npm:` locator, whose fetcher sends npm registry auth to the patch host, nor a tarball locator under an `npm:` key, which hardened mode rejects (YN0078). An older release's `npm:::__archiveUrl=` pin is still recognized and is re-pinned on the next run; rollback rebuilds the key from the selectors and drops them. Refused, nothing written: a user-authored `resolutions` entry for the package `redirect_yarn_berry_resolutions_conflict`, no root manifest `redirect_yarn_berry_manifest_missing`, a builtin `patch:` entry wrapping the same descriptor `redirect_yarn_berry_shared_descriptor`, an artifact URL yarn cannot fetch as a tarball `redirect_yarn_berry_artifact_url_unsupported`; cacheKey `10c0` and `.yarnrc.yml compressionLevel 0` gated by `redirect_yarn_berry_cache_unsupported`), and **bun** (text `bun.lock` lockfileVersion 0 to 3 — 0 is the `--save-text-lockfile` opt-in lock of Bun 1.1.39–1.1.45, 1 the 1.2–1.3 default, 2 the 1.4+ default, 3 what Bun 1.4+ writes when `package.json` has a nested override or a yarn-style path resolution (only the lock's head differs: its `overrides` object nests); all four emit one `packages` grammar, so the registry 4-tuple → URL 3-tuple rewrite is version-independent and the lock's own version line is kept. Any other or missing version, or a `packages` section outside bun's single-line grammar, is refused `redirect_bun_lock_unsupported` — the detail is the shared version gate's text (a newer version: update socket-patch, re-locking would reproduce it; no integer: re-lock with Bun ≥ 1.2), identical to the vendored refusal. A version-0 lock holding `workspace:` packages is refused `redirect_bun_workspace_unsupported` (its 2-tuple workspace grammar cannot keep the hosted tuple through a frozen install); the remedy is to delete `bun.lock` and re-run `bun install` with Bun ≥ 1.2, which writes lockfileVersion 1 (accepted). A plain in-place `bun install` bumps the version only when a workspace depends on another workspace (e.g. root → member — the shape the matrix measured); otherwise Bun 1.2.0 keeps version 0 and Bun 1.2.23+ fail to resolve, so the in-place bump is not the documented remedy. Bun lock version, grammar and workspace compatibility are checked before a vendored takeover, including during dry-run: these refusals preserve the existing lock, artifact and vendor ledger. Version-1 and version-2 workspace locks are rewritten, nested versions included. A granted dep with no rewritable entry warns `redirect_bun_entry_not_found` (or `redirect_bun_non_registry_entry_skipped` when the only same-version entry is a user URL / `file:` tarball, #497), a grant without a sha512 `redirect_bun_missing_sha512`; a CRLF lock keeps `\r\n` on the rewritten line, and a hosted URL left by an earlier grant of the same `name@version` is re-pinned in place. **Digest-less re-saves (Bun 1.1.39–1.3.9)**: every text-lock Bun below 1.3.10 re-saves a URL tuple WITHOUT its `sha512` whenever the lock is re-saved for another reason (`bun add`, `bun install` after a package.json or workspace change), leaving the 2-tuple `["name@", {meta}]` — the spec Bun installs from is intact. The CLI treats that spelling as its own wiring: a repeat hosted run counts the dep as redirected (no `redirect_bun_entry_not_found`) and HEALS the line back to the 3-tuple with the current `sha512`, recording the heal as a further `redirect_bun_lock_package` edit whose `original` is the 2-tuple (a stale URL is re-pinned from either spelling); `rollback`, scoped `rollback ` / `remove ` and the vendored takeover accept the digest-less spelling of a recorded `new` line (same key, spec and meta, only the trailing `"sha512-…"` missing) and restore the recorded original over it, so the chain always unwinds to the pristine registry line. Anything else — another uuid/token, another version, a re-laid meta object — is still drift. **Native `bun.lockb`**: when no text `bun.lock` exists, binary format versions 1, 2 and 3 are read and rewritten directly. Socket Patch does not invoke Bun or convert the project to a text lockfile. Exact matching package records are rewritten to hosted tarballs with the granted integrity, preserving dependency resolution IDs, workspace/dependency topology and unrelated package metadata; binary pointers and the package metadata hash are updated. Per-package `redirect_bun_lockb_package` snapshots support scoped rollback, repeat runs, superseding grants and hosted ↔ vendored takeover. A regular binary lock is discoverable even with no Bun runtime or `node_modules`; a dry run previews the same binary edits without writing them. A malformed, unreadable, unsupported or unverified binary structure is `redirect_bun_lockb_invalid` (exit 0, `redirected: 0`), and it refuses the npm rewrite before any takeover or sibling npm-family lock mutation. A symlinked binary write target is `redirect_symlinked_file_unsupported` (exit 1, including dry-run). `bun.lock` wins when both spellings exist. Binary-only projects do not receive `redirect_npm_no_lockfile`. Measured boundaries and the real-Bun matrix: `docs/testing/bun-compatibility.md`), and **vlt** (`vlt-lock.json` without `lockfileVersion`, `0` or `1`; see the vlt hosted-mode contract below). **Rush monorepos**: when `rush.json` is present the rewriter also reads `common/config/rush/pnpm-lock.yaml` and each `common/config/subspaces//pnpm-lock.yaml` (sorted for determinism) under their repo-relative keys and repoints them in place; editing them emits `redirect_rush_repo_state_stale` when the `repo-state.json` beside a rewritten lock exists (`common/config/rush/repo-state.json` for the common lock, `common/config/subspaces//repo-state.json` for a subspace lock; the `pnpmShrinkwrapHash` desync is refreshed by `rush update`, which the redirect survives), and `redirect_pnpm_trust_lockfile` carries the Rush pnpm >=11 install remedy (see the trust paragraph above). **maven** is fail-closed via version suffixing: a `mavenSuffixedVersion` + `mavenPomSha256` override pins the Socket-only `-socket.` by rewriting the literal `` (`redirect_maven_dep_version`) or adding a `` entry (`redirect_maven_dep_management_added`), plus optional Trusted Checksums (`redirect_maven_trusted_checksums`, conflicts as `redirect_maven_trusted_checksums_conflict`; the `.mvn/maven.config` line that names the checksums directory is spelled `${maven.multiModuleProjectDirectory}/.mvn/checksums`, which no Maven 3 build fails on wherever it is started, or `${session.rootDirectory}/.mvn/checksums` for a project that declares Maven 4 (a wrapper that pins it, or a root pom whose model is newer than 4.0.0: its ``, else the version its namespace names), the only form Maven 4 reads. The six settings hosted mode wrote, standing together in the other spelling, are respelled in that one line by every `scan --mode hosted` that reads the file (`redirect_maven_config`, `rewritten`, `key: "trustedChecksumsDirectory"`; the edit that merges the settings in keeps `key: "trustedChecksums"`), whatever the run redirects: with no Maven patch in the run, in a reactor root, in a root another rewriter owns, with no checksum line left, with a later line that switches the pin off. A scan with nothing to redirect reads `.mvn/maven.config` for that alone, and takes the write lock for it when it can. The respelling is never the reason a run fails: when the lock cannot be had, or the file is a symbolic link (which a write would replace), the line is left as it is and nothing is reported for it. This is what removes the line an earlier release wrote for every project, which stops Maven 3.9.2 to 3.9.8 from starting with `-f` from outside the project. A directory line that stands apart from the other five is the user's and is never rewritten. When the respelling takes `${session.rootDirectory}` out of a project that declares no Maven, a Maven 4 build of it stops enforcing the pin (Maven 3.9.4 and later 3.x go on enforcing it): the additive warning `redirect_maven_trusted_checksums_maven3_only` says so, once, with the remedy (declare Maven 4 and scan again). A directory line in the launcher's spelling that the user wrote, in a project that declares Maven 4, names no directory there: it is left as written and reported as `redirect_maven_trusted_checksums_conflict`. Either form is recognised by `vex`, `rollback` and `remove`; when the Maven the project declares does not enforce the pin as the config stands (the wrapper pins a Maven older than 3.9.4, or the project declares Maven 4 and the line is in the spelling Maven 4 does not read), the additive warning `redirect_maven_trusted_checksums_unenforced`, whose detail names the remedy for that case; a grant sha256 that is not 64 hex digits writes no checksum line, `redirect_maven_trusted_checksums_invalid_hash`); a `${property}` version is wired through the property's own value (`redirect_maven_property`) or a literal that records the text it replaced (`redirect_maven_dep_version` with the `${...}` text as `original`), and stays `redirect_maven_dep_unpinned` only when what it reads cannot be told, a reactor root (a `` / `` declaration, a profile's included, or a Maven 4 root that lists none but whose subprojects Maven discovers: model version not `4.0.0`, `pom` packaging, a direct subdirectory holding a `pom.xml`, and `maven.project.discoverSubprojects` not turned off in `.mvn/maven.config`) is planned over every pom of the reactor, each module `pom.xml` that takes an edit appearing in `rewrittenFiles` (see [Hosted Maven reactors and property versions](#hosted-maven-reactors-and-property-versions)); a reactor one of whose poms cannot be read, and a same-GAV grant in a reactor, are refused whole with `redirect_maven_multimodule_unsupported`: the poms and `.mvn/` are left untouched and the dep is not counted as redirected (a Gradle build beside it is still planned by the Gradle rewriter, but a dep in a root with a `pom.xml` is confirmed only when the poms pin it too), a non-matching literal skipped (`redirect_maven_dep_version_mismatch`), a `` variant (sources, tests, a native build) left at its version (`redirect_maven_classifier_unsupported`; the grant serves the main jar only, and the dep is skipped, with nothing written, when a variant other than `sources` / `javadoc`, live or inside ``, may resolve any version but the suffixed pin — the patched release, another one, a `${property}` a profile moves, or no version in the pom once its classifier-keyed `` (a profile's too) is consulted — since `vex` would never attest that pin: `vex_maven_classifier_unpatched`), a versioned declaration inside `` (a literal or a `${property}`) left as-is (`redirect_maven_profile_dependency_unpatched`): when any version it may resolve — its own, or what its own profile's or any combination of profiles' `` make of it, read as `vex` reads it — is not the suffixed pin, the dep is refused with nothing written, since it overrides the pin whenever that profile is active and `vex` would never attest it (a profile `` entry only when management governs the pin, i.e. no live direct declaration carries a version); a versionless one takes the pin, and the dep is also skipped when a profile holds its only declaration, a `${property}` groupId / artifactId resolved from the pom's own `` before matching (one the pom does not define, which may be the patched GA and whose own version would then win, refuses the dep with nothing written: `redirect_maven_coordinate_unresolved`), and a `${property}` groupId / artifactId some profile's `` (or several profiles' together) redefine so that the declaration a pin would go into names another package, or another declaration names the GA's main jar at another version (or one of its executable classifier copies, a `test-jar` included), refuses the dep with nothing written too (`redirect_maven_profile_coordinates_unpatched`): `vex` would never attest that pin (`vex_maven_profile_unpatched`), and a pom not readable as one left untouched (`redirect_maven_pom_unreadable`). Matches and anchors skip comments, CDATA, ``, ``, ``, `` and `` (the scope `vex` reads), and an existing self-closed `` / `` is expanded in place, never duplicated; an override without a suffixed version falls back to same-GAV repository injection (`redirect_maven_same_gav_fallback`, NOT fail-closed). A pin is written only where Maven selects the patch's base version already (`redirect_maven_version_not_selected`, `redirect_maven_selection_undetermined`): see [Maven version selection](#maven-version-selection-hosted-and-vendored-maven). **gradle** (v5.0) is automated wiring, no longer a pasted snippet: the owned settings script `.socket/gradle/socket-patch.hosted.settings.gradle` with its index `.socket/gradle/hosted-index.tsv`, one apply line per build's settings file, every lock entry of the GA moved to the suffixed version, and the suffixed component in an existing `gradle/verification-metadata.xml`. A refused dep writes nothing and keeps `redirect_gradle_manual_snippet` as its fallback; same-GAV grants are refused (`redirect_gradle_same_gav_unsupported`). Rules, refusals and codes: [Gradle builds](#gradle-builds-v50). +The rewriter reads a fixed set of candidate files from the project root: the npm-family locks (`package-lock.json`, `npm-shrinkwrap.json`, `pnpm-lock.yaml`, `shrinkwrap.yaml`, `yarn.lock`, plus `.yarnrc.yml` for the berry cache-config gate, `bun.lock` / `bun.lockb`, and `vlt-lock.json` with `vlt.json` and `node_modules/.vlt-lock.json` read only), `requirements.txt` / `uv.lock` / `Pipfile.lock` (pipfile-spec 6; see the Pipenv section below) / `poetry.lock` (every Poetry lock generation from 1.0 on — the 0.12 `[metadata.hashes]` layout is refused because that installer ignores URL sources; a Poetry < 1.4 writer additionally gets `redirect_poetry_stale_install_risk`, see `docs/testing/poetry-compatibility.md`) / `pdm.lock` (PDM lock formats `2` and `4.3`–`4.5.1`; the identity-losing `3.1` / `4.0`–`4.2` formats and unknown future formats are refused with `redirect_pdm_refused`, and a lock-format-`2` writer additionally gets `redirect_pdm_legacy_sync_required`, see `docs/testing/pdm-compatibility.md`; when `uv.lock` or `poetry.lock` sits beside it they drive and `pdm.lock` is left alone), `Cargo.toml` / `Cargo.lock` / `.cargo/config.toml` (plus the legacy extensionless `.cargo/config` — cargo reads that spelling in preference when both exist, so the managed `[registries.…]` block is written into whichever one is present; the hosted redirect is a `sparse+` registry, which cargo loads only from **1.68**, so `rust-toolchain.toml` / `rust-toolchain` are read too (never edited) and a project whose declared floor — the lowest `rust-version` of the root and the member manifests read here (a `rust-version.workspace = true` inheritor reads `[workspace.package]`), else the channel rustup picks from the root (the legacy `rust-toolchain` over `rust-toolchain.toml`; a dated `nightly-`/`beta-YYYY-MM-DD` maps to its release train) — is below 1.68 is refused `redirect_cargo_old_cargo` per crate (nothing written, an earlier run's pins left in place with the `rollback` that drops them named; `--mode vendored` builds on cargo 1.41+), while an undeclared or rolling-channel floor still redirects (toolchain files in ancestor directories are not read); **cargo also reads every workspace-member manifest** — the `[workspace] members` globs minus `exclude` — and every in-root path-dependency manifest, recursively, reached without crossing a symbolic link and never under `.socket/`, and pins the crate in each one that declares it, so those `/Cargo.toml` files can appear in `rewrittenFiles`. A crate is redirected only when every declaration pins and every other `Cargo.lock` package depending on it is a planned member: one a registry or git crate — or a path package outside the root or behind a link — also depends on is refused `redirect_cargo_transitive_dependents` (a pin reaches only the declarations it sits on), a crate no manifest declares keeps `redirect_cargo_toml_dep_not_found` with a transitive-only detail naming `--mode vendored`, a crate every declaration of which requires another version (no requirement accepts the patched version) is refused `redirect_cargo_toml_dep_unrewritable`, and so is a requirement that also matches another locked version of the crate — each a transactional skip, never recorded or attested. With NO `Cargo.lock` there is no resolved graph to ask, so the dependents question is answered from the manifests instead: a crate declared beside any other dependency — anything but a path dependency on a manifest this run also pins, or a `workspace = true` inheritor of a table it scans — or beside a workspace member this run did not read (a `members` glob, or a member outside the project or behind a symbolic link, which member discovery drops) is refused `redirect_cargo_lockless_dependents`, whose detail names the remedies (commit a lockfile, or `--mode vendored`); a project whose only dependency is the patched crate has nothing that could pull it in and still redirects. All-CRLF manifests, locks and configs are rewritten with CRLF kept (mixed endings keep refusing where the grammar does not match), and `remove` / rollback match the recorded fragments across a later CRLF↔LF checkout conversion), `composer.lock`, `nuget.config` / `packages.lock.json` (plus, v5.0 #353/#514, every lock a project under the root restores into: a member project's `packages.lock.json`, a per-project `packages..lock.json`, a literal `NuGetLockFilePath` — each pinned with the root config; a `NuGetLockFilePath` it cannot evaluate warns `redirect_nuget_lock_path_unresolved` and a project tree it cannot list warns `redirect_nuget_lock_unreadable`, both skipping the nuget redirect with nothing written), `Gemfile` / `Gemfile.lock`, `pom.xml` (+ `.mvn/maven.config` / `.mvn/checksums/checksums.sha256` for maven Trusted Checksums merge, and, for a Gradle build, every settings, build, `buildSrc`, included-build, applied and plugin-source script, version catalog and lock file the script graph reaches, plus `gradle/verification-metadata.xml`, `gradle/wrapper/gradle-wrapper.properties` and the owned `.socket/gradle/` files), and the sbt build files (`socket-patch.sbt`, `socket-patch-vendor.sbt`, `build.sbt`, `project/build.properties`, `.sbtopts`, `.jvmopts`; `build.sbt.lock` and the Mill / scala-cli build files `build.mill`, `build.mill.yaml`, `build.sc`, `.mill-version`, `project.scala` for their presence only) — read, never edited; `socket-patch.sbt` is the only sbt file hosted mode writes (see **Hosted sbt** below). **npm-family flavor coverage**: package-lock / npm-shrinkwrap (a package the project patches itself with npm ≥ 12.1's native `npm patch` — a root `patchedDependencies` key, or the lock entry's `patched` record — is left on its registry entry in every npm lock, `redirect_npm_patched_dependency_skipped`), pnpm (root OR any nested `*/pnpm-lock.yaml`), yarn classic (a yarn 2+ install migrates a v1 `yarn.lock` and drops its pins, so a run whose v1 lock carries a hosted pin warns `redirect_yarn_classic_berry_migration_risk` — the hosted twin of the vendored `yarn_classic_berry_migration_risk` — unless the root `package.json`, read as advisory input, declares `"packageManager": "yarn@1…"`), **yarn berry** (the pin yarn writes for a root `resolutions` entry: the root `package.json` — edited only beside a berry `yarn.lock` — gains one `"@npm:": ""` selector per locked range (`redirect_yarn_berry_resolution` edits), and only that `yarn.lock` entry is re-keyed `"@"` with the same `resolution:` + `yarnBerry10c0` checksum (`redirect_yarn_berry_entry`), moved to yarn's key order; never an `npm:` locator, whose fetcher sends npm registry auth to the patch host, nor a tarball locator under an `npm:` key, which hardened mode rejects (YN0078). An older release's `npm:::__archiveUrl=` pin is still recognized and is re-pinned on the next run; rollback rebuilds the key from the selectors and drops them. Refused, nothing written: a user-authored `resolutions` entry for the package `redirect_yarn_berry_resolutions_conflict`, no root manifest `redirect_yarn_berry_manifest_missing`, a builtin `patch:` entry wrapping the same descriptor `redirect_yarn_berry_shared_descriptor`, an artifact URL yarn cannot fetch as a tarball `redirect_yarn_berry_artifact_url_unsupported`; cacheKey `10c0` and `.yarnrc.yml compressionLevel 0` gated by `redirect_yarn_berry_cache_unsupported`), and **bun** (text `bun.lock` lockfileVersion 0 to 3 — 0 is the `--save-text-lockfile` opt-in lock of Bun 1.1.39–1.1.45, 1 the 1.2–1.3 default, 2 the 1.4+ default, 3 what Bun 1.4+ writes when `package.json` has a nested override or a yarn-style path resolution (only the lock's head differs: its `overrides` object nests); all four emit one `packages` grammar, so the registry 4-tuple → URL 3-tuple rewrite is version-independent and the lock's own version line is kept. Any other or missing version, or a `packages` section outside bun's single-line grammar, is refused `redirect_bun_lock_unsupported` — the detail is the shared version gate's text (a newer version: update socket-patch, re-locking would reproduce it; no integer: re-lock with Bun ≥ 1.2), identical to the vendored refusal. A version-0 lock holding `workspace:` packages is refused `redirect_bun_workspace_unsupported` (its 2-tuple workspace grammar cannot keep the hosted tuple through a frozen install); the remedy is to delete `bun.lock` and re-run `bun install` with Bun ≥ 1.2, which writes lockfileVersion 1 (accepted). A plain in-place `bun install` bumps the version only when a workspace depends on another workspace (e.g. root → member — the shape the matrix measured); otherwise Bun 1.2.0 keeps version 0 and Bun 1.2.23+ fail to resolve, so the in-place bump is not the documented remedy. Bun lock version, grammar and workspace compatibility are checked before a vendored takeover, including during dry-run: these refusals preserve the existing lock, artifact and vendor ledger. Version-1 and version-2 workspace locks are rewritten, nested versions included. A granted dep with no rewritable entry warns `redirect_bun_entry_not_found` (or `redirect_bun_non_registry_entry_skipped` when the only same-version entry is a user URL / `file:` tarball, #497), a grant without a sha512 `redirect_bun_missing_sha512`; a CRLF lock keeps `\r\n` on the rewritten line, and a hosted URL left by an earlier grant of the same `name@version` is re-pinned in place. **Digest-less re-saves (Bun 1.1.39–1.3.9)**: every text-lock Bun below 1.3.10 re-saves a URL tuple WITHOUT its `sha512` whenever the lock is re-saved for another reason (`bun add`, `bun install` after a package.json or workspace change), leaving the 2-tuple `["name@", {meta}]` — the spec Bun installs from is intact. The CLI treats that spelling as its own wiring: a repeat hosted run counts the dep as redirected (no `redirect_bun_entry_not_found`) and HEALS the line back to the 3-tuple with the current `sha512`, recording the heal as a further `redirect_bun_lock_package` edit whose `original` is the 2-tuple (a stale URL is re-pinned from either spelling); `rollback`, scoped `rollback ` / `remove ` and the vendored takeover accept the digest-less spelling of a recorded `new` line (same key, spec and meta, only the trailing `"sha512-…"` missing) and restore the recorded original over it, so the chain always unwinds to the pristine registry line. Anything else — another uuid/token, another version, a re-laid meta object — is still drift. **Native `bun.lockb`**: when no text `bun.lock` exists, binary format versions 1, 2 and 3 are read and rewritten directly. Socket Patch does not invoke Bun or convert the project to a text lockfile. Exact matching package records are rewritten to hosted tarballs with the granted integrity, preserving dependency resolution IDs, workspace/dependency topology and unrelated package metadata; binary pointers and the package metadata hash are updated. Per-package `redirect_bun_lockb_package` snapshots support scoped rollback, repeat runs, superseding grants and hosted ↔ vendored takeover. A regular binary lock is discoverable even with no Bun runtime or `node_modules`; a dry run previews the same binary edits without writing them. A malformed, unreadable, unsupported or unverified binary structure is `redirect_bun_lockb_invalid` (exit 0, `redirected: 0`), and it refuses the npm rewrite before any takeover or sibling npm-family lock mutation. A symlinked binary write target is `redirect_symlinked_file_unsupported` (exit 1, including dry-run). `bun.lock` wins when both spellings exist. Binary-only projects do not receive `redirect_npm_no_lockfile`. Measured boundaries and the real-Bun matrix: `docs/testing/bun-compatibility.md`), and **vlt** (`vlt-lock.json` without `lockfileVersion`, `0` or `1`; see the vlt hosted-mode contract below). **Rush monorepos**: when `rush.json` is present the rewriter also reads `common/config/rush/pnpm-lock.yaml` and each `common/config/subspaces//pnpm-lock.yaml` (sorted for determinism) under their repo-relative keys and repoints them in place; editing them emits `redirect_rush_repo_state_stale` when the `repo-state.json` beside a rewritten lock exists (`common/config/rush/repo-state.json` for the common lock, `common/config/subspaces//repo-state.json` for a subspace lock; the `pnpmShrinkwrapHash` desync is refreshed by `rush update`, which the redirect survives), and `redirect_pnpm_trust_lockfile` carries the Rush pnpm >=11 install remedy (see the trust paragraph above). **maven** is fail-closed via version suffixing: a `mavenSuffixedVersion` + `mavenPomSha256` override pins the Socket-only `-socket.` by rewriting the literal `` (`redirect_maven_dep_version`) or adding a `` entry (`redirect_maven_dep_management_added`), plus optional Trusted Checksums (`redirect_maven_trusted_checksums`, conflicts as `redirect_maven_trusted_checksums_conflict`; the `.mvn/maven.config` line that names the checksums directory is spelled `${maven.multiModuleProjectDirectory}/.mvn/checksums`, which no Maven 3 build fails on wherever it is started, or `${session.rootDirectory}/.mvn/checksums` for a project that declares Maven 4 (a wrapper that pins it, or a root pom whose model is newer than 4.0.0: its ``, else the version its namespace names), the only form Maven 4 reads. The six settings hosted mode wrote, standing together in the other spelling, are respelled in that one line by every `scan --mode hosted` that reads the file (`redirect_maven_config`, `rewritten`, `key: "trustedChecksumsDirectory"`; the edit that merges the settings in keeps `key: "trustedChecksums"`), whatever the run redirects: with no Maven patch in the run, in a reactor root, in a root another rewriter owns, with no checksum line left, with a later line that switches the pin off. A scan with nothing to redirect reads `.mvn/maven.config` for that alone, and takes the write lock for it when it can. The respelling is never the reason a run fails: when the lock cannot be had, or the file is a symbolic link (which a write would replace), the line is left as it is and nothing is reported for it. This is what removes the line an earlier release wrote for every project, which stops Maven 3.9.2 to 3.9.8 from starting with `-f` from outside the project. A directory line that stands apart from the other five is the user's and is never rewritten. Since that respelling is decided by the file and by no dep, a Maven reason code that says *the run writes nothing for the dep* means that dep in that run: no pin in a pom, and no line or file under `.mvn/`, the checksum lines a malformed grant hash would drop included. It says nothing of wiring an earlier run left in the poms, nor of that one respelled line. When the respelling takes `${session.rootDirectory}` out of a project that declares no Maven, a Maven 4 build of it stops enforcing the pin (Maven 3.9.4 and later 3.x go on enforcing it): the additive warning `redirect_maven_trusted_checksums_maven3_only` says so, once, with the remedy (declare Maven 4 and scan again). A directory line in the launcher's spelling that the user wrote, in a project that declares Maven 4, names no directory there: it is left as written and reported as `redirect_maven_trusted_checksums_conflict`. Either form is recognised by `vex`, `rollback` and `remove`; when the Maven the project declares does not enforce the pin as the config stands (the wrapper pins a Maven older than 3.9.4, or the project declares Maven 4 and the line is in the spelling Maven 4 does not read), the additive warning `redirect_maven_trusted_checksums_unenforced`, whose detail names the remedy for that case; a grant sha256 that is not 64 hex digits writes no checksum line, `redirect_maven_trusted_checksums_invalid_hash`); a `${property}` version is wired through the property's own value (`redirect_maven_property`) or a literal that records the text it replaced (`redirect_maven_dep_version` with the `${...}` text as `original`), and stays `redirect_maven_dep_unpinned` only when what it reads cannot be told, a reactor root (a `` / `` declaration, a profile's included, or a Maven 4 root that lists none but whose subprojects Maven discovers: model version not `4.0.0`, `pom` packaging, a direct subdirectory holding a `pom.xml`, and `maven.project.discoverSubprojects` not turned off in `.mvn/maven.config`) is planned over every pom of the reactor, each module `pom.xml` that takes an edit appearing in `rewrittenFiles` (see [Hosted Maven reactors and property versions](#hosted-maven-reactors-and-property-versions)); a reactor one of whose poms cannot be read, and a same-GAV grant in a reactor, are refused whole with `redirect_maven_multimodule_unsupported`: the run writes nothing for the dep and it is not counted as redirected (a Gradle build beside it is still planned by the Gradle rewriter, but a dep in a root with a `pom.xml` is confirmed only when the poms pin it too), a non-matching literal skipped (`redirect_maven_dep_version_mismatch`), a `` variant (sources, tests, a native build) left at its version (`redirect_maven_classifier_unsupported`; the grant serves the main jar only, and the dep is skipped, and the run writes nothing for it, when a variant other than `sources` / `javadoc`, live or inside ``, may resolve any version but the suffixed pin — the patched release, another one, a `${property}` a profile moves, or no version in the pom once its classifier-keyed `` (a profile's too) is consulted — since `vex` would never attest that pin: `vex_maven_classifier_unpatched`), a versioned declaration inside `` (a literal or a `${property}`) left as-is (`redirect_maven_profile_dependency_unpatched`): when any version it may resolve — its own, or what its own profile's or any combination of profiles' `` make of it, read as `vex` reads it — is not the suffixed pin, the dep is refused, and the run writes nothing for it, since it overrides the pin whenever that profile is active and `vex` would never attest it (a profile `` entry only when management governs the pin, i.e. no live direct declaration carries a version); a versionless one takes the pin, and the dep is also skipped when a profile holds its only declaration, a `${property}` groupId / artifactId resolved from the pom's own `` before matching (one the pom does not define, which may be the patched GA and whose own version would then win, refuses the dep, and the run writes nothing for it: `redirect_maven_coordinate_unresolved`), and a `${property}` groupId / artifactId some profile's `` (or several profiles' together) redefine so that the declaration a pin would go into names another package, or another declaration names the GA's main jar at another version (or one of its executable classifier copies, a `test-jar` included), refuses the dep the same way (`redirect_maven_profile_coordinates_unpatched`): `vex` would never attest that pin (`vex_maven_profile_unpatched`), and a pom not readable as one left untouched (`redirect_maven_pom_unreadable`). Matches and anchors skip comments, CDATA, ``, ``, ``, `` and `` (the scope `vex` reads), and an existing self-closed `` / `` is expanded in place, never duplicated; an override without a suffixed version falls back to same-GAV repository injection (`redirect_maven_same_gav_fallback`, NOT fail-closed). A pin is written only where Maven selects the patch's base version already (`redirect_maven_version_not_selected`, `redirect_maven_selection_undetermined`): see [Maven version selection](#maven-version-selection-hosted-and-vendored-maven). **gradle** (v5.0) is automated wiring, no longer a pasted snippet: the owned settings script `.socket/gradle/socket-patch.hosted.settings.gradle` with its index `.socket/gradle/hosted-index.tsv`, one apply line per build's settings file, every lock entry of the GA moved to the suffixed version, and the suffixed component in an existing `gradle/verification-metadata.xml`. A refused dep writes nothing and keeps `redirect_gradle_manual_snippet` as its fallback; same-GAV grants are refused (`redirect_gradle_same_gav_unsupported`). Rules, refusals and codes: [Gradle builds](#gradle-builds-v50). **Hosted sbt (v5.0, additive)**: an sbt build root (`project/build.properties` naming an `sbt.version`, 0.13.18 or later) is wired through ONE generated root file, `socket-patch.sbt` — no user file is edited. It pins every granted Maven patch build-wide (a `ThisBuild` `dependencyOverrides +=` of the Socket-only `-socket.` version plus a `file:` resolver over `.socket/sbt-hosted/maven2/`, moved ahead of the default repositories on sbt 0.13 / 1.x so an unreachable one never blocks it offline), downloads the pinned pom and jar there on the first sbt load (sha256-checked, gitignored by the file itself), and installs a load-time verifier that fails `update` when any project resolves another version or a pinned artifact whose bytes are not pinned. Edits: `redirect_sbt_pin` (added), `redirect_sbt_pin_updated` (an existing row replaced: same GA and base under a new uuid, or the same uuid with new served values; `original` names the previous uuid and version), `redirect_sbt_pin_rechecked` (an existing row re-verified after the build's dependencies changed: its dependency digest is recorded anew, `original`/`new` are `{deps}`). The load-time verifier also fails `update` when a project declares a pinned GA at a version newer than the pin's base (the build-wide override would otherwise force it back down). A new pin is gated on sbt's own resolution records under `target/` (never the machine-wide cache): run-level stops wire nothing, warn once and exit 0 — `redirect_sbt_no_resolution_evidence` (none; run `sbt update` first; always the in-memory engine's answer), `redirect_sbt_resolution_incomplete` (a declared project left no evidence, or the project definitions cannot be read statically), `redirect_sbt_resolution_stale` (a build source is newer than some project's evidence: each project is dated by its own newest record, so a partial `sbt /update` does not vouch for the others). Per-patch refusals (never confirmed): `redirect_sbt_missing_override` (no `maven2` override or no suffixed version), `redirect_sbt_integrity_missing` (jar or pom sha256 missing), `redirect_sbt_unsafe_value` (a value unsafe in a Scala literal, or an index URL not naming the uuid), `redirect_sbt_version_conflict` (some project resolves another version, or a build source declares the GA newer than the patch's base), `redirect_sbt_override_conflict` (two patches for one GA in a run, or another base already pinned), `redirect_sbt_vendored_conflict` (the GA is pinned by `socket-patch-vendor.sbt`, or that file cannot be parsed — then every Maven patch), `redirect_sbt_owned_file_modified` / `redirect_sbt_owned_file_foreign` (`socket-patch.sbt` edited, or not socket-patch's — every Maven patch), `redirect_sbt_owned_file_unreadable` (a whole-run refusal: `socket-patch.sbt` is on disk but cannot be read as UTF-8 text, so writing it would replace it; nothing is written), `redirect_sbt_unsupported_version`, `redirect_sbt_build_root_unknown` (sbt files but no versioned build root — every Maven patch), `redirect_sbt_overrides_assignment` / `redirect_sbt_resolvers_assignment` (a build source reassigns `dependencyOverrides` / `resolvers` with `:=`, `~=`, `--=` or `<<=`), `redirect_sbt_onload_assignment` (a build source reassigns `onLoad`, in any scope, with `:=`, `~=`, `--=` or `<<=` without keeping its previous value — a `:=` reading `(Global / onLoad).value`, or a `~=` that composes with `andThen` / `compose`, keeps it — which drops the generated file's load-time verifier and resolver order), `redirect_sbt_dependency_lock_present` (a `build.sbt.lock`), `redirect_sbt_scala_runtime_unsupported` (`org.scala-lang`), `redirect_sbt_classifier_unsupported`; a GA no library configuration resolves is skipped silently (`redirect_sbt_meta_build_only` when only the meta-build resolves it). Advisories: `redirect_sbt_version_untested` (sbt 2.1+, still wired), `redirect_sbt_override_build_repos` (`sbt.override.build.repos=true`), `redirect_maven_pom_ignored_sbt_build` (a `pom.xml` beside the sbt build, which sbt never reads; the Maven rewriter still edits it for the Maven build). A re-run keeps an existing row and re-checks it. When the build's dependency digest changed since the pin, evidence resolved after the change (fresh, newer than the generated file) re-verifies it and the row's digest is refreshed (`redirect_sbt_pin_rechecked`); the uuid is NOT confirmed on `redirect_sbt_pin_declared_newer` (a build source now declares the GA newer than the pin's base; the row stays, sbt's load-time verifier fails the build, and the remedy is `socket-patch rollback` or declaring the base again), `redirect_sbt_pin_unverifiable` (the digest changed and the evidence predates the change, or the digest cannot be computed: run `sbt update`, then re-run socket-patch), `redirect_sbt_override_shadowed` (the evidence still resolves the base version) or `redirect_sbt_resolved_elsewhere` (the pinned version resolves from outside the pin repository from a file whose sha256 is not the pinned jar's; a copy holding the pinned bytes, such as the Ivy cache a second checkout reads, is fine — at most 64 pinned artifact files of up to 256 MiB are hashed, anything else counts as elsewhere), and also when a build source now reassigns `dependencyOverrides` / `resolvers` / `onLoad` or a `build.sbt.lock` appeared (the same `redirect_sbt_overrides_assignment` / `redirect_sbt_resolvers_assignment` / `redirect_sbt_onload_assignment` / `redirect_sbt_dependency_lock_present` codes; the row stays and sbt's load-time verifier fails the build). For a pure sbt root (no `pom.xml` / Gradle script beside it), maven confirmation is decided only by the sbt rewriter's report; on a mixed root a uuid the sbt rewriter refused is still confirmed by the Maven rewriter's own `pom.xml` pin (the generated sbt files never prove a pin by substring). **Mill and scala-cli** are guidance only: per Maven patch `redirect_mill_manual_snippet` / `redirect_scala_cli_manual_snippet` carry a paste-able snippet (repository + forced suffixed version), nothing is written or confirmed, and a pure Mill / scala-cli root gets no `redirect_maven_no_pom`; there, a Maven patch the server sent without a `maven2` registry override gets `redirect_maven_missing_override` instead of a snippet (with a `pom.xml` beside the Mill / scala-cli files the pom rewriter reports it). `rollback` / `remove` restore `socket-patch.sbt` offline (the rows removed, the file deleted with its last pin; the gitignored downloads are left). Manifest-less VEX reads every strictly parsed pin as a hosted reference but grants it the lockfile basis only when the local evidence shows every recorded version of the GA is the pinned one and every recorded artifact hashes to a pinned sha256 (else `sbt_resolution_unverified`, and the suffixed copy sbt downloaded into `.socket/sbt-hosted` is its only basis). Where the build provably does not use the pinned bytes, that copy proves nothing and the patch is omitted (`vex_sbt_pin_bypassed`): a build source reassigns `dependencyOverrides` (`:=`, `~=`, `--=`; replacing the generated override) or reassigns `onLoad` without keeping its previous value (dropping the installer that holds the load-time verifier and resolver order), whether or not any evidence exists, or a resolution record dated after the generated files and every build source shows the GA's base version (the override shadowed), or the pinned version from outside the pin repository with bytes that are not pinned (judged exactly as the hosted rewriter re-checks a pin, `redirect_sbt_override_shadowed` / `redirect_sbt_resolved_elsewhere`). A record older than the wiring (a project or cross build not re-resolved since) proves nothing, and current records that verify the pin always keep it. A `resolvers` reassignment or `sbt.override.build.repos=true` alone is no bypass: the override still forces the Socket-only version and the load-time verifier checks its bytes, so the build runs the pinned bytes or fails (which is why an `onLoad` reassignment dropping that verifier is one). Stale or partial evidence, project definitions that cannot be read statically and a `build.sbt.lock` only withhold the lockfile basis. A file under a generated name without socket-patch's header is read as the root build definition sbt loads it as. @@ -2318,12 +2318,12 @@ command's integration tests check its output. | `upstream_gem_install_would_refresh` | `warnings[]` (note) | the same on `--dry-run`: what a wet unwind would replace. | | `redirect_gem_version_not_locked` | `warnings[]` (warning) | scan `--mode hosted` (gem): the crawled gem version is installed on the machine but no `GEM` section of the project's lock resolves it (another project's copy in the shared gem home). The gem is skipped and the Gemfile and lock stay byte-identical. | | `redirect_maven_trusted_checksums_maven3_only` / `maven_trusted_checksums_maven3_only` | `warnings[]` (warning) | scan / get `--mode hosted` (the first code) and rollback / remove (the second), Maven: the Trusted Checksums settings hosted mode wrote into `.mvn/maven.config` named the checksums directory through `${session.rootDirectory}`, which stops Maven 3.9.2 to 3.9.8 from starting with `-f` from outside the project, and this run respelled that line with `${maven.multiModuleProjectDirectory}` in a project that declares no Maven (no Maven Wrapper naming an Apache Maven release, a root pom of model 4.0.0). Maven 3.9.4 and later 3.x enforce the checksums as before; a Maven 4 build of the project no longer does. Reported once, by the run that changes the line. The remedy for a project Maven 4 builds: declare Maven 4 (a wrapper that pins it, or a root pom of model 4.1.0); the next hosted scan then writes the spelling Maven 4 reads. Status and exit code are unchanged. | -| `redirect_maven_version_not_selected` | `warnings[]` (warning) | scan / get `--mode hosted` (Maven): the build does not resolve the artifact at the patch's base version; the detail names the version Maven selects instead, or says that the build does not resolve the artifact. `pom.xml` and `.mvn/` stay byte-identical and the dep is not counted as redirected. See [Maven version selection](#maven-version-selection-hosted-and-vendored-maven). | -| `redirect_maven_selection_undetermined` | `warnings[]` (warning) | scan / get `--mode hosted` (Maven): what the build selects for the artifact cannot be read and `pom.xml` declares no version of it to replace, so no `` pin is written on a guess. `pom.xml` and `.mvn/` stay byte-identical; the detail carries the reason and the remedy (resolve the project once and re-run, or declare the artifact at the base version). In a reactor it names the first module whose selection cannot be read and counts the rest: those modules get no new pin, while the modules that are certain are still pinned and a declaration that names the base version is still rewritten, so the dep may be counted as redirected beside this warning. | -| `redirect_maven_multimodule_unsupported` | `warnings[]` (warning) | scan / get `--mode hosted` (Maven): the root `pom.xml` heads a reactor that cannot be planned: a module pom is missing or not readable as a pom, a `` path is a property or leaves the project, or the grant serves the patched artifact under its original version (a same-GAV grant). The detail carries the reason. The poms and `.mvn/` stay byte-identical and the dep is not counted as redirected. A reactor that can be read is patched module by module: see [Hosted Maven reactors and property versions](#hosted-maven-reactors-and-property-versions). | +| `redirect_maven_version_not_selected` | `warnings[]` (warning) | scan / get `--mode hosted` (Maven): the build does not resolve the artifact at the patch's base version; the detail names the version Maven selects instead, or says that the build does not resolve the artifact. The run writes nothing for the dep and it is not counted as redirected. See [Maven version selection](#maven-version-selection-hosted-and-vendored-maven). | +| `redirect_maven_selection_undetermined` | `warnings[]` (warning) | scan / get `--mode hosted` (Maven): what the build selects for the artifact cannot be read and `pom.xml` declares no version of it to replace, so no `` pin is written on a guess. The detail carries the reason and the remedy (resolve the project once and re-run, or declare the artifact at the base version). For a single pom the run then writes nothing for the dep. In a reactor the warning is a note on a plan that may still be written: it names the first module whose selection cannot be read and counts the rest; those modules get no new pin, while the modules that are certain are still pinned and a declaration that names the base version is still rewritten, so the dep may be counted as redirected beside this warning. | +| `redirect_maven_multimodule_unsupported` | `warnings[]` (warning) | scan / get `--mode hosted` (Maven): the root `pom.xml` heads a reactor that cannot be planned: a module pom is missing or not readable as a pom, a `` path is a property or leaves the project, or the grant serves the patched artifact under its original version (a same-GAV grant). The detail carries the reason. The run writes nothing for the dep and it is not counted as redirected. A reactor that can be read is patched module by module: see [Hosted Maven reactors and property versions](#hosted-maven-reactors-and-property-versions). | | `redirect_maven_pin_would_move_module` | `warnings[]` (warning) | scan / get `--mode hosted` (Maven reactor): a parent pom resolves the base version itself above a module that resolves another version, so the parent takes no pin (Maven's management always reaches the children); the modules below it that select the base version are pinned. Also reported when a pin an earlier run wrote is taken out because a module it reaches now resolves another version, which the pin would hold back (the `redirect_maven_dep_management` edit has `action: "removed"`). Exit 0. | -| `redirect_maven_edit_not_reversible` | `warnings[]` (warning) | scan / get `--mode hosted` (Maven): a pom would take an edit that `rollback` could not undo byte for byte from the pom alone. A pin in a `` that holds no entry (which would be left changed or removed) leaves that one pom as it is: the modules it would have wired stay unpatched, and `vex` withholds the statement while one of them resolves the base version. Any other case (a `` section that would not come back as it was) refuses the whole plan for the patch: nothing is written and the dep is not counted as redirected. Exit 0. See [Hosted Maven reactors and property versions](#hosted-maven-reactors-and-property-versions). | -| `redirect_maven_mirror_captures_repository` | `warnings[]` (warning) | scan / get `--mode hosted` (Maven, on disk): the Maven settings of the scanning machine declare a `` whose `` matches the `socket-patch-` repository the pin needs (`*`, `external:*`, or a list without `!socket-patch-`), without naming that repository itself (alone, or as one id of a list). The mirror does not hold the patched version, so the build could not resolve it: nothing is written for the dep, `pom.xml` and `.mvn/` stay byte-identical, and the dep is not counted as redirected or attested by the same run's `--vex`, whatever an earlier run left in the poms. Exit 0. Reported only for a dep that would get (or already has) the repository. The detail names the mirror id, its ``, the settings file and the exclusion to add, and says that only this machine's settings were read. It offers `scan --mode vendored` with its bound: vendored mode gets past a mirror through `maven.repo.local.tail`, which Maven reads from 3.9.2 on. When the project's Maven Wrapper pins an older Maven the detail does not offer it as the project stands, and says what makes it work (a wrapper at 3.9.2 or later, or the mirror also leaving `socket-patch-vendor` out). See [Hosted Maven behind a mirror](#hosted-maven-behind-a-mirror) | +| `redirect_maven_edit_not_reversible` | `warnings[]` (warning) | scan / get `--mode hosted` (Maven): a pom would take an edit that `rollback` could not undo byte for byte from the pom alone. A pin in a `` that holds no entry (which would be left changed or removed) leaves that one pom as it is: the modules it would have wired stay unpatched, and `vex` withholds the statement while one of them resolves the base version. Any other case (a `` section that would not come back as it was) refuses the whole plan for the patch: the run writes nothing for the dep and it is not counted as redirected. Exit 0. See [Hosted Maven reactors and property versions](#hosted-maven-reactors-and-property-versions). | +| `redirect_maven_mirror_captures_repository` | `warnings[]` (warning) | scan / get `--mode hosted` (Maven, on disk): the Maven settings of the scanning machine declare a `` whose `` matches the `socket-patch-` repository the pin needs (`*`, `external:*`, or a list without `!socket-patch-`), without naming that repository itself (alone, or as one id of a list). The mirror does not hold the patched version, so the build could not resolve it: the run writes nothing for the dep, and the dep is not counted as redirected or attested by the same run's `--vex`. Wiring an earlier run left in the poms stays in place; the detail then says so, says that a build behind the mirror fails on it, and names the command that takes it out (`socket-patch rollback `). Exit 0. Reported only for a dep that would get (or already has) the repository. The detail names the mirror id, its ``, the settings file and the exclusion to add, and says that only this machine's settings were read. It offers `scan --mode vendored` with its bound: vendored mode gets past a mirror through `maven.repo.local.tail`, which Maven reads from 3.9.2 on. When the project's Maven Wrapper pins an older Maven the detail does not offer it as the project stands, and says what makes it work (a wrapper at 3.9.2 or later, or the mirror also leaving `socket-patch-vendor` out). See [Hosted Maven behind a mirror](#hosted-maven-behind-a-mirror) | | `redirect_gem_no_checksums_section` | `warnings[]` (warning) | scan/get `--mode hosted` (gem): the lock has no `CHECKSUMS` section (Bundler < 2.6 does not write one), so it cannot record the sha256 of the patched gems. They are redirected all the same (manifest and lock converged, frozen installs accept the pair) and pinned by source alone. Reported once per run, naming the gems; relock with Bundler ≥ 2.6 (`bundle lock --add-checksums`) and re-run to pin the checksums too. | | `redirect_gem_merged_lock_layout` | `warnings[]` (warning) | scan/get `--mode hosted` (gem): the lock was written by Bundler < 2.2 (`BUNDLED WITH`), which lists every gem source in ONE `GEM` section, so this run added the patch registry to that section's `remote:` lines. The pair installs with that Bundler, frozen / deployment mode included. Newer Bundlers deprecate such a section and from 2.5 on refuse the pair under frozen / deployment mode: if a newer Bundler installs the project, run `bundle lock` with it, commit the lock and re-run the hosted scan. Raised only by a run that wrote the lock. | | `redirect_gem_unrecognized_declaration` | `warnings[]` (warning) | scan/get `--mode hosted` (gem): the gem's declaration cannot take a `source:` option in place (the detail gives the reason). The gem is skipped and the manifest and lock stay byte-identical for it; write the declaration as one `gem "", …` call with literal arguments on a line of its own, or use `--mode vendored` / `--mode agent`. | @@ -2983,7 +2983,7 @@ other cause leaves a declaration nearer the module than it is certain. | Mode | The build selects another version, or does not resolve the artifact | The selection is not certain | |---|---|---| -| hosted | `redirect_maven_version_not_selected` (warning); nothing written | a declaration that names the base version is rewritten where it stands (that replaces the version in place and moves nothing); otherwise `redirect_maven_selection_undetermined` (warning), nothing written | +| hosted | `redirect_maven_version_not_selected` (warning); the run writes nothing for the dep | a declaration that names the base version is rewritten where it stands (that replaces the version in place and moves nothing); otherwise `redirect_maven_selection_undetermined` (warning), and for a single pom the run writes nothing for the dep | | vendored | `vendor_maven_version_not_selected` (`skipped`, exit 0), decided before any download; nothing written | a declaration that names the base version is rewritten; a module whose selection is not certain gets no new pin (`vendor_jvm_degraded`, `reason: selection_undetermined`, naming it), and a pin already there is kept. With no such declaration and no module that is certain: `vendor_maven_selection_undetermined` (`skipped`, exit 0), nothing written | | agent | not applicable: the cached jar is patched in place under its own coordinates, which cannot change what a build resolves. A version whose directory in the local repository holds its pom and no jar (Maven read the pom while mediating and never downloaded the artifact) is not a package agent mode can patch: the scan leaves it out instead of failing it as a targeted patch that matched no installed package | | @@ -3052,13 +3052,18 @@ Maven's own rule against the repository the pin would add (its id space, excludes nothing), as in Maven; * `` must accept `default`. -When a mirror captures the repository, nothing is written for that dep and -the run reports `redirect_maven_mirror_captures_repository` (exit 0). The -dep is not counted as redirected and the same run's `--vex` does not attest -it, also when a pin an earlier run wrote is still in the poms: that pin -stays as it is, and the build behind the mirror cannot resolve it. No file -is touched for a gated dep, `.mvn/checksums/checksums.sha256` included. The -other patches of the run are unaffected. +When a mirror captures the repository, the run writes nothing for that dep +and reports `redirect_maven_mirror_captures_repository` (exit 0). The dep is +not counted as redirected and the same run's `--vex` does not attest it, +also when wiring an earlier run wrote is still in the poms: that wiring +stays in place, and a build behind the mirror cannot resolve it. The detail +then says so and names the command that takes the wiring out +(`socket-patch rollback `), beside the ways to make it resolve. No +file is touched for a gated dep, `.mvn/checksums/checksums.sha256` included. The +other patches of the run are unaffected. So is the respelling of a +`.mvn/maven.config` line an earlier release wrote (`redirect_maven_config`, +`key: "trustedChecksumsDirectory"`): the file decides it, not a dep, so a run +that gates every Maven patch makes it all the same. The gate applies only where a repository is at stake. A dep the rewriter would not wire anyway (the build selects another version, no pom can take diff --git a/crates/socket-patch-core/src/formats/maven/mod.rs b/crates/socket-patch-core/src/formats/maven/mod.rs index e16444076..f74b584d9 100644 --- a/crates/socket-patch-core/src/formats/maven/mod.rs +++ b/crates/socket-patch-core/src/formats/maven/mod.rs @@ -17,8 +17,8 @@ pub(crate) use properties::{ use super::xml::{blank_non_markup, child_text, elements, open_tags, Element}; -pub(crate) mod mirror; pub(crate) mod declared_maven; +pub(crate) mod mirror; pub(crate) mod trusted_checksums; pub(crate) mod version; diff --git a/crates/socket-patch-core/src/patch/redirect/mod.rs b/crates/socket-patch-core/src/patch/redirect/mod.rs index 78a61276f..ee056a78e 100644 --- a/crates/socket-patch-core/src/patch/redirect/mod.rs +++ b/crates/socket-patch-core/src/patch/redirect/mod.rs @@ -9184,6 +9184,11 @@ pub fn maven_reactor_root(files: &BTreeMap) -> bool { /// decided and not confirmed ([`RewriteResult::maven_reactor_uuids`]), /// so wiring an earlier run left is not counted as a redirect, or /// attested, by a substring it still matches. +/// +/// The gate holds deps back and nothing else: the respelling of a +/// `.mvn/maven.config` an earlier release wrote ([`heal_mvn_config`]) is +/// decided by that file, and the rewriter proper makes it whichever deps it +/// is handed, none included. fn rewrite_maven_pom( files: &BTreeMap, overrides: &[DepOverride], @@ -9220,11 +9225,15 @@ fn rewrite_maven_pom( ); let mut wired: Vec = Vec::with_capacity(overrides.len()); for dep in overrides { + // An earlier run's wiring is in the poms already, or this run + // would write it. + let mut in_place = false; let gate = (dep.ecosystem == "maven") .then(|| captured(dep)) .flatten() .filter(|(repo_id, _)| { - declares(files, repo_id) || { + in_place = declares(files, repo_id); + in_place || { let mut alone = RewriteResult::default(); rewrite_maven_poms(files, std::slice::from_ref(dep), selection, &mut alone); declares(&alone.files, repo_id) @@ -9249,9 +9258,11 @@ fn rewrite_maven_pom( ), None => full_name(dep), }; + let earlier = + in_place.then(|| format!("pkg:maven/{}@{}", ga.replace(':', "/"), dep.version)); result.warnings.push(RewriteWarning { code: "redirect_maven_mirror_captures_repository".into(), - detail: maven_mirror_detail(&ga, &repo_id, mirror, wrapper), + detail: maven_mirror_detail(&ga, &repo_id, mirror, wrapper, earlier.as_deref()), }); result.maven_reactor_uuids.insert(dep.patch_uuid.clone()); } @@ -9396,22 +9407,31 @@ fn rewrite_maven_poms( .as_ref() .is_some_and(|(jar, pom)| !is_hex64_lower(jar) || !is_hex64_lower(pom)); let checksum_hashes = checksum_hashes.filter(|_| !bad_checksum_hashes); - if let Some(suffixed) = suffixed_version.as_deref().filter(|_| bad_checksum_hashes) { - // No pin is written for the suffixed version, so none may stay - // either: an earlier release wrote such a grant's hash mangled - // (lowercased base64), and Maven fails the build on a line - // whose hash does not match. Dropped whether or not the version - // pin lands this run (a re-run with the pin present too). - for ext in ["jar", "pom"] { - checksum_drops.push(crate::vendor::jvm::layout::artifact_path( - &group_id, - &artifact_id, - suffixed, - None, - ext, - )); - } - } + // No checksum pin is written for the suffixed version of a grant + // whose hash is malformed, so none may stay either: an earlier + // release wrote such a grant's hash mangled (lowercased base64), + // and Maven fails the build on a line whose hash does not match. + // The lines go with the pin: when it lands this run, and when an + // earlier run's is in place (a re-run). They are queued only then. + // A dep this run refuses or skips has no file touched for it, this + // one included, which is what its warning says. + let stale_checksums: Vec = suffixed_version + .as_deref() + .filter(|_| bad_checksum_hashes) + .map(|suffixed| { + ["jar", "pom"] + .map(|ext| { + crate::vendor::jvm::layout::artifact_path( + &group_id, + &artifact_id, + suffixed, + None, + ext, + ) + }) + .to_vec() + }) + .unwrap_or_default(); // The pom for the rest of this iteration; edits land in place. let Some(pom_text) = pom.as_mut() else { @@ -9478,6 +9498,9 @@ fn rewrite_maven_poms( "jar", )); } + if run.wired { + checksum_drops.extend(stale_checksums); + } checksum_drops.extend(run.drops); if run.landed { pin_maven_checksums( @@ -9866,6 +9889,9 @@ fn rewrite_maven_poms( "jar", )); } + if run.wired { + checksum_drops.extend(stale_checksums); + } checksum_drops.extend(run.drops); if run.landed { pin_maven_checksums( @@ -10005,6 +10031,11 @@ fn rewrite_maven_poms( "jar", )); } + // (A dep whose only declaration names another version is skipped: + // no pin landed and none is in place.) + if pin_landed || versioned.iter().any(|(_, _, v)| *v == suffixed_version) { + checksum_drops.extend(stale_checksums); + } // The superseded generations' wiring: once no literal names an old // suffix any more, its `socket-patch-` repository and trusted @@ -10250,10 +10281,24 @@ fn pin_maven_checksums( } } +/// What a hosted Maven warning says this run did for a dep it did not +/// wire: one clause, for the mirror gate and the reactor planner's refusal +/// alike. It speaks of the run and of the dep, not of the state of the +/// files: an earlier run's pin may still be in the poms, and the same run +/// may respell a `.mvn/maven.config` line that no dep decides +/// ([`heal_mvn_config`]). +const MAVEN_WROTE_NOTHING: &str = + "this run wrote nothing for it (no pin in a pom, no line or file under .mvn/)"; + /// Why a dep is not wired behind `mirror`, and the ways forward. The /// settings read are the scanning machine's, which the line says: the /// machine that builds may be configured otherwise. /// +/// `earlier` is the purl of the dep when the poms already hold the wiring +/// an earlier run wrote for it. That wiring is left in place, and a build +/// behind the mirror fails on it: the line says so, and names the command +/// that takes it out beside the ways to make it resolve. +/// /// The second way forward is vendored mode, and only where it is one. A /// vendored patch gets past a mirror through `maven.repo.local.tail`, /// which Maven reads from 3.9.2 on; an older Maven reads it through @@ -10262,11 +10307,13 @@ fn pin_maven_checksums( /// Maven Wrapper pins an older Maven (`wrapper`, as vendored mode itself /// reads it) it does not offer vendored mode as it stands, but says what /// makes it work. +/// fn maven_mirror_detail( ga: &str, repo_id: &str, mirror: &crate::formats::maven::mirror::Mirror, wrapper: Option<(u32, u32, u32)>, + earlier: Option<&str>, ) -> String { let vendor_repo = crate::vendor::jvm::maven_reactor::REPO_ID; let exclude = format!( @@ -10296,12 +10343,21 @@ fn maven_mirror_detail( too)" ), }; + let left = match earlier { + Some(purl) => format!( + " The wiring an earlier run wrote for it is still in the poms and was left in \ + place: a build behind this mirror fails to resolve the patched version until the \ + mirror leaves the repository out or that wiring is taken out (`socket-patch \ + rollback {purl}`)." + ), + None => String::new(), + }; format!( "{ga}: on this machine Maven's settings send the {repo_id} repository to the mirror \ `{id}` ({of} in {source}), which does not serve the patched \ - artifact, so the build could not resolve it; pom.xml and .mvn/ were left as they are \ - and the dep is not counted as redirected. {ways}. Only this machine's settings were \ - read: the machine that builds needs the same exclusion", + artifact, so the build could not resolve it; {MAVEN_WROTE_NOTHING} and the dep is \ + not counted as redirected.{left} {ways}. Only this machine's settings were read: \ + the machine that builds needs the same exclusion", id = mirror.id, of = mirror.mirror_of, source = mirror.source, @@ -10460,9 +10516,8 @@ impl MavenReactorRewrite { result.warnings.push(RewriteWarning { code: code.into(), detail: format!( - "{ga}: {why}; the poms and .mvn/ were left as they are and the dep is not \ - counted as redirected (`scan --mode vendored` commits the patched \ - artifact instead)" + "{ga}: {why}; {MAVEN_WROTE_NOTHING} and the dep is not counted as \ + redirected (`scan --mode vendored` commits the patched artifact instead)" ), }); }; @@ -12090,7 +12145,8 @@ mod tests { /// A gated dep has nothing written for it at all: not even the /// checksum lines a grant with a malformed hash would otherwise have - /// dropped. The warning says `.mvn/` was left as it is, and it is. + /// dropped. The warning says nothing was written for the dep, and + /// nothing is. #[test] fn maven_mirror_gate_touches_no_file_of_a_gated_dep() { let mut dep = granted_maven_override(); @@ -12125,6 +12181,149 @@ mod tests { warning_codes(&r), ["redirect_maven_mirror_captures_repository"] ); + // The line speaks of this run. Nothing of an earlier one is in the + // poms, so it names none and no command to take it out. + let detail = &r.warnings[0].detail; + assert!(detail.contains(MAVEN_WROTE_NOTHING), "{detail}"); + assert!( + !detail.contains("left in place") && !detail.contains("socket-patch rollback"), + "{detail}" + ); + } + + /// A dep this run refuses or skips has no file touched for it: no pom, + /// and not the checksum lines that a grant with a malformed hash drops + /// once its pin lands or is in place. One case for each way out of the + /// rewriter: the reactor planner's refusal, a version the build does + /// not select (a single pom, and a reactor), and a selection that + /// cannot be read. (The mirror gate's is the test above.) + #[test] + fn maven_dep_that_is_refused_or_skipped_touches_no_file() { + let mut dep = granted_maven_override(); + dep.integrity.sha256 = Some("sha256-q83vEjRWeJA=".into()); + let stale = format!( + "{} org/slf4j/slf4j-api/{MAVEN_SUFFIXED}/slf4j-api-{MAVEN_SUFFIXED}.jar\n", + "c".repeat(64) + ); + let project = |poms: &[(&str, &str)]| -> BTreeMap { + poms.iter() + .map(|(rel, text)| (rel.to_string(), text.to_string())) + .chain([(MVN_CHECKSUMS.to_string(), stale.clone())]) + .collect() + }; + let run = |files: &BTreeMap, picks: &[(&str, Result<&str, &str>)]| { + let modules: Vec<&str> = files + .keys() + .map(String::as_str) + .filter(|rel| rel.ends_with("pom.xml")) + .collect(); + let picks: Vec<_> = picks + .iter() + .map(|(pom, pick)| (*pom, "org.slf4j", "slf4j-api", *pick)) + .collect(); + let selection = MavenSelection::answering(&modules, &picks); + rewrite_registry_redirect_with_host( + files, + std::slice::from_ref(&dep), + &BTreeMap::new(), + None, + false, + &std::collections::BTreeSet::new(), + &yarnrc::OuterYarnMirror::default(), + &CratesIoSource::Registry, + Some(&selection), + ) + }; + let untouched = |r: &RewriteResult, code: &str, what: &str| { + assert!(r.files.is_empty(), "{what}: {:?}", r.files.keys()); + assert!(r.edits.is_empty(), "{what}: {:?}", r.edits); + assert_eq!(warning_codes(r), [code], "{what}"); + }; + + // Control: where the pin lands the stale line goes with it. + let direct = pom_with_dep("\n 1.7.36", ""); + let landed = run( + &project(&[("pom.xml", &direct)]), + &[("pom.xml", Ok("1.7.36"))], + ); + assert!(landed.files["pom.xml"].contains(MAVEN_SUFFIXED)); + assert!( + !landed.files[MVN_CHECKSUMS].contains(MAVEN_SUFFIXED), + "{}", + landed.files[MVN_CHECKSUMS] + ); + + // The reactor planner refuses the plan: a module pom is missing. + let headless = direct.replace( + " ", + " pom\n \n app\n \n ", + ); + let files = project(&[("pom.xml", &headless)]); + assert!(maven_reactor_root(&files)); + let r = run(&files, &[]); + untouched(&r, "redirect_maven_multimodule_unsupported", "refused"); + assert!( + r.warnings[0].detail.contains(MAVEN_WROTE_NOTHING), + "{}", + r.warnings[0].detail + ); + + // The build selects another version: a single pom, and a reactor. + let r = run( + &project(&[("pom.xml", TRANSITIVE_ONLY_POM)]), + &[("pom.xml", Ok("2.0.9"))], + ); + untouched(&r, "redirect_maven_version_not_selected", "single pom"); + let reactor = project(&[ + ("pom.xml", REACTOR_ROOT), + ("a/pom.xml", &reactor_module("a", "")), + ("b/pom.xml", &reactor_module("b", "")), + ]); + let r = run( + &reactor, + &[("a/pom.xml", Ok("2.0.9")), ("b/pom.xml", Ok("2.0.9"))], + ); + untouched(&r, "redirect_maven_version_not_selected", "reactor"); + + // The pom names another version of the artifact: the dep is + // skipped where it stands, past every earlier way out. + let other = pom_with_dep("\n 2.0.0", ""); + let r = run( + &project(&[("pom.xml", &other)]), + &[("pom.xml", Ok("2.0.0"))], + ); + assert!(r.files.is_empty(), "mismatch: {:?}", r.files.keys()); + assert!(r.edits.is_empty(), "mismatch: {:?}", r.edits); + + // What the build selects cannot be read, and no pom names a + // version to replace. + let r = run( + &project(&[("pom.xml", TRANSITIVE_ONLY_POM)]), + &[( + "pom.xml", + Err("the pom of ch.qos.logback:logback-classic:1.4.14 is not in the local Maven repository"), + )], + ); + untouched(&r, "redirect_maven_selection_undetermined", "undetermined"); + } + + /// `plain` as a hosted scan of an earlier release left it, and what + /// that scan writes today: the project wired for `dep`, with the + /// Trusted Checksums directory named through `${session.rootDirectory}` + /// where today's scan names it through the launcher's property. + fn wired_by_an_earlier_release( + plain: &BTreeMap, + dep: &DepOverride, + ) -> (BTreeMap, RewriteResult) { + use trusted_checksums::Basedir::{Launcher, Session}; + let wired = rewrite_registry_redirect(plain, std::slice::from_ref(dep)); + let mut earlier = plain.clone(); + earlier.extend(wired.files.clone()); + let value = trusted_checksums::basedir_value; + let old = earlier[MVN_CONFIG].replace(value(Launcher), value(Session)); + assert_ne!(old, earlier[MVN_CONFIG]); + earlier.insert(MVN_CONFIG.to_string(), old); + (earlier, wired) } /// A dep the gate holds back does not keep another dep of the same @@ -12175,6 +12374,59 @@ mod tests { assert!(!r.maven_reactor_uuids.contains(second_uuid)); } + /// The gate holds a dep back, never the respelling of a + /// `.mvn/maven.config` an earlier release wrote: that line stops Maven + /// 3.9.2 to 3.9.8 from starting with `-f` from outside the project + /// whether or not a mirror takes the Socket repository. So a project + /// an earlier release wired, scanned behind a mirror that now captures + /// its repository, gets the mirror's warning for the dep and the heal + /// for the config, and nothing else is written. + #[test] + fn maven_mirror_gate_does_not_hold_back_the_heal_of_an_earlier_config() { + let dep = granted_maven_override(); + let plain = BTreeMap::from([( + "pom.xml".to_string(), + pom_with_dep("\n 1.7.36", ""), + )]); + let (mut earlier, wired) = wired_by_an_earlier_release(&plain, &dep); + earlier.extend([maven_mirrors(&[("corp", "*")])]); + + let r = rewrite_registry_redirect(&earlier, std::slice::from_ref(&dep)); + assert_eq!(r.files.keys().collect::>(), [MVN_CONFIG]); + assert_eq!(r.files[MVN_CONFIG], wired.files[MVN_CONFIG]); + assert_eq!( + r.edits + .iter() + .map(|e| (e.path.as_str(), e.key.as_deref())) + .collect::>(), + [(MVN_CONFIG, Some(MVN_CONFIG_HEAL_KEY))] + ); + assert_eq!( + warning_codes(&r), + [ + "redirect_maven_mirror_captures_repository", + "redirect_maven_trusted_checksums_maven3_only", + ] + ); + // The mirror's line speaks of this run, which wrote nothing for + // the dep. The earlier run's wiring is still there: the line says + // that it was left, that a build behind the mirror fails on it, + // and how to take it out. + let detail = &r.warnings[0].detail; + for part in [ + MAVEN_WROTE_NOTHING, + "The wiring an earlier run wrote for it is still in the poms and was left in place", + "a build behind this mirror fails to resolve the patched version", + "`socket-patch rollback pkg:maven/org.slf4j/slf4j-api@1.7.36`", + ] { + assert!(detail.contains(part), "{part}: {detail}"); + } + // Gated, so decided and not confirmed: the wiring the earlier run + // left is not counted as this run's redirect. + assert!(r.maven_reactor_uuids.contains(MAVEN_UUID)); + assert!(r.confirmed_maven_reactor_uuids.is_empty()); + } + /// [`maven_override`] as the patch service grants it: the suffix is the /// first eight hex digits of the patch uuid, which is what ties a pin /// to its repository and what the reactor planner writes. @@ -13640,11 +13892,8 @@ mod tests { assert_eq!(form(&run(&model_4_1)), Some(Session)); // An earlier release's wiring: the same files, the session's form. - let mut earlier = plain.clone(); - earlier.extend(wired.files.clone()); - let old = earlier[MVN_CONFIG].replace(value(Launcher), value(Session)); - assert_ne!(old, earlier[MVN_CONFIG]); - earlier.insert(MVN_CONFIG.to_string(), old); + let (earlier, rewired) = wired_by_an_earlier_release(&plain, &maven_override()); + assert_eq!(rewired.files, wired.files); let healed = run(&earlier); assert_eq!(healed.files.keys().collect::>(), [MVN_CONFIG]); assert_eq!(healed.files[MVN_CONFIG], wired.files[MVN_CONFIG]); @@ -13816,6 +14065,13 @@ mod tests { warning_codes(&r), [trade, "redirect_maven_multimodule_unsupported"] ); + // The refusal speaks of what this run did for the dep, not of + // `.mvn/`: the same run respelled a line there. + assert!( + r.warnings[1].detail.contains(MAVEN_WROTE_NOTHING), + "{}", + r.warnings[1].detail + ); // A root the sbt rewriter owns (no pom.xml beside the build). let sbt_root = BTreeMap::from([ diff --git a/docs/ecosystems.md b/docs/ecosystems.md index 236ad6665..852746122 100644 --- a/docs/ecosystems.md +++ b/docs/ecosystems.md @@ -988,8 +988,9 @@ Honest limits of the Maven and NuGet flows — documented behavior, not bugs: A `${property}` groupId or artifactId is resolved from the pom's own `` before matching, so `${ct.group}` is rewritten like a literal. One the pom does not define (a parent's) may be the patched GA, and then its own version - wins: the dep is refused with nothing written (`redirect_maven_coordinate_unresolved`), - and `vex` does not attest a pin past such a declaration. + wins: the dep is refused and the run writes nothing for it + (`redirect_maven_coordinate_unresolved`), and `vex` does not attest a pin past such a + declaration. The grant serves the main jar only: a `` variant keeps its version (`redirect_maven_classifier_unsupported`), and the literal-or-pin decision is made from the classifier-less declarations. A `sources` / `javadoc` variant at the patched release @@ -1005,7 +1006,7 @@ Honest limits of the Maven and NuGet flows — documented behavior, not bugs: cached `maven-metadata-*.xml` lists. When the build selects another version (a newer or older one nearer the root, the project's own declaration, an excluded path, a range), or does not resolve the artifact at all, the patch for that base version has - nothing to patch: nothing is written, the run exits 0, and one line names the version + nothing to patch: the run writes nothing for it, exits 0, and one line names the version Maven selects instead (`redirect_maven_version_not_selected`, vendored `vendor_maven_version_not_selected`). A patch for the version that is selected is still looked up and applied. When the selection cannot be read (most often because @@ -1038,11 +1039,11 @@ Honest limits of the Maven and NuGet flows — documented behavior, not bugs: Checksums stay in the project root's `.mvn/`, which Maven also reads when it is started in a module directory or with `-f`; a module with a `.mvn` of its own is reported (`redirect_maven_trusted_checksums_unenforced`), since a Maven started there - reads that one. A reactor one of whose poms cannot be read is left untouched - (`redirect_maven_multimodule_unsupported`, with the reason). A pom that is there but is - not UTF-8 text (re-saved as Latin-1 or UTF-16, say) is never taken for a missing one: - the scan refuses the run and names it (`candidate_file_unreadable`), `vex` reports it - as unreadable and attests no pin of that reactor, and `rollback` / `remove` change + reads that one. When a pom of a reactor cannot be read, the run writes nothing for the + patch (`redirect_maven_multimodule_unsupported`, with the reason). A pom that is there + but is not UTF-8 text (re-saved as Latin-1 or UTF-16, say) is never taken for a missing + one: the scan refuses the run and names it (`candidate_file_unreadable`), `vex` reports + it as unreadable and attests no pin of that reactor, and `rollback` / `remove` change nothing until it is UTF-8 again, since it may hold part of a pin. The plan for a patch is written whole or not at all: a pom is never left naming a patched version without the repository that serves it, its checksum lines, and wiring a rollback can find. So a @@ -1169,8 +1170,9 @@ Honest limits of the Maven and NuGet flows — documented behavior, not bugs: `originAware=false` and `failIfMissing=false`, so one checksum matches the artifact from any repository and a dependency with no committed checksum still resolves — only a *mismatch* fails. A grant whose sha256 is not 64 hex digits writes no checksum line - (and drops any line an earlier run wrote for that suffixed version) and warns - `redirect_maven_trusted_checksums_invalid_hash`. `vex` takes a pin's checksum as the + and warns `redirect_maven_trusted_checksums_invalid_hash`; a line an earlier run wrote + for that suffixed version goes once the pin lands or is in place, and stays untouched + for a dep the run refuses or skips. `vex` takes a pin's checksum as the content the project pins only when the pin is known to be enforced: `maven.config` enforces the file as Maven 3.9+ reads it (all five settings above with the values hosted writes, the directory in either form; `failIfMissing` aside), and the Maven the @@ -1230,8 +1232,8 @@ Honest limits of the Maven and NuGet flows — documented behavior, not bugs: included. The patch resolves only at its suffixed version, which the mirror does not hold, so a project wired behind such a mirror **fails to build**. `scan --mode hosted` therefore reads the Maven settings of the machine it runs on before it writes a Maven - pin, and wires nothing for a patch whose repository a mirror would take over: the - poms and `.mvn/` stay as they are, the scan exits 0, and + pin, and wires nothing for a patch whose repository a mirror would take over: the run + writes nothing for it (no pin in a pom, no line or file under `.mvn/`), exits 0, and `redirect_maven_mirror_captures_repository` names the mirror, the settings file that declares it, and the two ways forward: - **Leave the repository out of the mirror.** Add `!socket-patch-` to its @@ -1265,7 +1267,9 @@ Honest limits of the Maven and NuGet flows — documented behavior, not bugs: behind a mirror that takes every repository, and a project skipped here may have built there. The in-memory engine (a Socket-opened pull request) reads no settings at all. A project an earlier scan wired is left as it is and reported the same way, and is no - longer counted as redirected or attested by that scan's `--vex`. The skip is only for + longer counted as redirected or attested by that scan's `--vex`. Its warning also says + that the earlier wiring is still in the poms, that a build behind the mirror fails on + it, and how to take it out (`socket-patch rollback `). The skip is only for a patch that would get the repository: one the scan would not wire anyway (the build selects another version) is reported under its own reason. * **Gradle (hosted Maven).** Gradle builds get automated wiring, not a pasted snippet: