Repository navigation
Do not wire a hosted Maven pin behind a mirror that would take its repository - #2135
Conversation
A hosted or vendored scan could change which version of a dependency a Maven build resolves and exit 0 without saying so. The candidates were a superset of the build (every version any pom of the graph declares, and every cached version behind a range or an undefined property), and a <dependencyManagement> pin makes every occurrence of the artifact one version. A patch for a version that lost mediation, was excluded, or was only cached by another project therefore replaced the version that won: a downgrade when the winner was newer, an upgrade when it was older. A pin is now written only where Maven selects the patch's base version already. - crawlers/maven_selection reads what Maven selects in each module from the project's poms and the poms the local repository holds, without running Maven: own and inherited dependencies, compile/runtime non-optional transitives, exclusions, declared or managed versions (the module's management over every transitive one), ranges through the cached maven-metadata files, and mediation with parents settled first (nearest wins, first declared on a tie, what a losing version depends on leaves the graph). formats/maven/version holds Maven's version order and range grammar. - Every answer is certain or not. A missing pom, a property that is undefined or that a profile redefines, a profile with dependencies or management, a relocation, a cycle, an unread module and a Maven 4 build are not certain, and nothing is pinned on them. - Hosted: redirect_maven_version_not_selected when the build selects another version (or none), redirect_maven_selection_undetermined when it cannot be told and no declaration names the base version. - Vendored: vendor_maven_version_not_selected, a skip decided before any download; the planner pins a local root only when every module under it selects the base version or does not resolve the artifact, and leaves a pin alone when it cannot tell. vendor --check accepts either answer. - A declaration that already names the base version is rewritten under any answer: that replaces a version where it stands. - Agent mode patches cached jars in place and is unchanged, except that a version directory holding a pom and no artifact is left out of an agent scan instead of failing it as a targeted patch not found on disk. - The nothing_wired refusal no longer says Maven keeps resolving the base version. Outcomes that change: the six shapes above exit 0 with nothing written and one line naming the version Maven selects; vendored used to exit 1 on a project that declares another version itself; agent mode used to exit 1 on a pom-only version; a transitive-only dependency of a project whose poms are not in the local repository is reported as undetermined instead of pinned. Refs #595, #882. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The version_not_selected and selection_undetermined warnings lost the line continuation in their format strings and carried a run of spaces in the middle of the sentence. The planner test now compares the whole warning. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Maven builds a pom that declares one dependency twice from its last declaration, in the place of the first (and warns). The selection model kept the first, which could call a version selected that Maven does not select. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A vendored pin was only ever written in a local root pom, which every module of the reactor inherits. Where the modules select different versions of one artifact, a root pin moved the ones that select another version (5.1.0), or no pin was written at all and a module that selects the base version only through other artifacts stayed unpatched (the previous commit). The pin now goes in the highest pom whose modules all select the patch's base version or do not resolve the artifact: the local root when every module that inherits it agrees, else the poms below it that do, down to one module's own pom.xml. A module that resolves another version is never reached by a pin, and patches for two versions of one artifact are each pinned in the modules that select them. A pin an earlier run wrote in a pom that would move a module is taken out and written where it belongs. A pom that manages the artifact itself takes no pin, and a module whose selection is not certain gets no new pin and keeps the one it has. The fallback repository stays in each local root. A literal <base>-socket.<hex8> of another patch of the same artifact is no longer reported as conflicting_literal_version when a second patch is planned, and the version_not_selected degraded reason is gone: a sibling that selects another version is not a degradation. Reactors whose modules agree and single-module projects are planned byte for byte as before. Refs #595, #882. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review fixes for the Maven selection work.
Determinism. Where the pins go is decided when a patch is first wired,
and the committed poms are the record. A later plan over poms that
already wire the patch keeps every pin and adds none, whatever the local
repository of that machine can tell, so one checkout plans the same
everywhere and a re-run is a no-op. `vendor --check` no longer judges
where a pin belongs: it takes every pin, and every absence of one, as
committed. Before, a project vendored where nothing could be told (the
declaration rewritten, no pin) drifted in `--check` and was rewritten by
a re-scan on a machine with a full local repository.
- A held pom still moves an older patch's pin to the new suffix: the
tree the old suffix names is replaced by the same run.
- A plan left unwired because one module's answer holds the root back is
the vendor_maven_selection_undetermined skip, whatever the other
modules select. It used to be the nothing_wired refusal.
- A pin for a version the build no longer selects is taken out of the
poms when the patch is skipped as not selected, and the skip says so.
It used to stay and keep forcing that version.
- A range is resolved only on the version lists cached for the
repositories the module's poms declare (and central and local). A list
cached for any other repository id leaves it undetermined.
- The undetermined line names the remedy that fits its cause: resolving
the project only when something is missing from the local repository.
- Property lookup goes through the shared lookup_property, so a bare
${version} reads a property of that name before the project's own.
- One artifact check for Coursier and Maven directories; the agent scan
filters pom-only versions through the crawler, off the async runtime.
- The selection is read off the async runtime, kept between the stages
and patches of one run while every file it read is unchanged, and not
read at all for a hosted reactor root, which is refused whole.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Brings in the determinism rule (pins stay where they were committed, on every machine), the suffix update of a held pin, the undetermined skip, the removal of a pin the build no longer selects, and the model fixes. With per-module placement the rule reads: a patch the poms already wire keeps every pin in every pom and gets no new one, unless a pin is certain to move a module, in which case the pins are placed afresh. The test for a plan one undetermined module holds back now uses a parent that resolves the artifact itself, since a sibling that selects the base version gets a pin of its own here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review fixes for the per-module placement of vendored Maven pins. - A pom was held (its pin kept) whenever any module under it could not be told, even when another module under it was certain to resolve another version. A pin that moves a module now goes whatever its siblings are; only a pom with doubt and no dissent is held, and a root a declaration rules out is never held. - vex attested a patch as soon as any pom wired it. A pin can sit in one module's pom, so the patch is now attested only when every module that resolves the base version (or may: its selection cannot be told) is reached by a pin, by the project's own management at the patched version, or by a declaration at it. `vendor --check` does not ask this. - A pin moved out of a pom carries the record of the section the first run created for it, so the revert takes the empty shell out again and restores the pom byte for byte. - A parent pom that resolves the base version itself above a module that resolves another cannot be pinned without moving that module, and Maven has no management that reaches a parent and not its children. It takes no pin and the plan says so (pin_would_move_module); when it is the only pom that selects the base version the patch is the vendor_maven_pin_would_move_module skip instead of nothing_wired. - A sibling that declares another version itself is no conflicting_literal_version once the selection says it resolves that version. - Undetermined modules are reported in one line, naming the first and counting the rest. - A root a declaration rules out no longer keeps the modules below it from their pins: it is descended like a root with a dissenting module. - A plan made without a selection keeps the pins the poms already hold, in whichever pom they are, instead of pulling them up into the roots. - Each module is asked for its selection once per plan and the answer marked up its chain. - Tests: one manifest staging helper, one table for the reactor fixture. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…olds The selection of a project is kept between the calls of one process and was given again while each file it was read from had the same length and modification time. That is not the same as the same content: - a pom rewritten to the same length within one tick of the file system's clock (a few milliseconds on Linux) has both unchanged, so the old selection was returned for the new pom. This is what failed on CI: `a_version_the_build_does_not_select_is_skipped_before_any_download` rewrites the project pom from 1.11.0 to 1.10.0 and asks again at once; - a version list was checked by its directory's length and time, which rewriting a `maven-metadata-*.xml` in place never changes; - a vendored run holds its writes to the project in memory until it commits them, and its readers answer from them: the selection read such a pom, the check looked at the file on disk; - the subprojects Maven 4 finds by listing a directory were not part of the check at all, so one that appeared was not seen. The walk now notes every read it makes of the file system (`Reads`): the path, whether it was a file or a directory listing, and the SHA-256 of the very bytes or entries it went on to use, through the readers the check repeats. A kept selection is given again only when repeating each read returns the same digest, so it cannot be older than the files: a missing file, a listing, and an uncommitted write of the run are reads like any other, and there is no gap between a read and its record. The selection touches the file system only through the walk (a test holds `maven_selection.rs` to that), and the one listing the walk does not note, the scope queue's, asserts it is never made on a noting walk. Reading the noted files again and hashing them costs a fraction of parsing them and walking the graph. Tests, each failing on the old check when run alone: a project pom, a repository pom and a version list rewritten to the same length with no delay and with the modification time put back; a pom, a version list and a discovered subproject that appear; a pom written inside an open group commit and read before it is committed. The selection fixture keeps its own answer, so another test's selection no longer replaces it and hides a stale one. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…-module Brings in the selection kept by the content of every read it was made from (a pom rewritten to the same length within one tick of the file system's clock was taken for the old one), which fixes the Linux failure of `a_version_the_build_does_not_select_is_skipped_before_any_download` on this branch. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A range is a hard requirement at any depth: Maven's resolver backtracks to a version inside it even when a plain version sits nearer the root. A range the model could not resolve (its only version list is cached for a repository the build does not declare, such as a settings.xml mirror; it cannot be parsed; or no listed version is in it) became an unread version that only cast doubt when it was no deeper than the winner. A nearer plain version outside the range was then reported as certainly selected, and hosted or vendored mode pinned it through <dependencyManagement>, downgrading what Maven resolves. Mark such edges as hard and make any of them leave the pick undetermined. Also restore the spaces lost in the three unpin messages. Assisted-by: Claude Code:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeRJTv8HGEveVfgkPgS
Hosted mode read only the root pom.xml. A multi-module reactor was
refused whole (`redirect_maven_multimodule_unsupported`), and so was a
declaration whose version is a `${property}`
(`redirect_maven_dep_unpinned`), so the default mode patched nothing in
either, where vendored mode patches both.
The pom rewriter now hands both to a hosted entry point of the reactor
planner vendored mode already uses (`maven_reactor::plan_hosted`), with
the same selection model and the same placement:
- a declaration that names the base version is rewritten where it
stands, in whichever pom holds it;
- the `<dependencyManagement>` pin goes in the highest pom whose modules
all select the base version or do not resolve the artifact, down to
one module's own pom; a module that resolves another version is never
reached, and a module a declaration already wires has no say;
- a `${property}` version only the patched artifact's declarations read
has the property's value rewritten (the declarations keep their text,
no sibling is stranded); any other one takes the literal suffixed
version, with the text it replaced recorded in a comment right after
the element (`<!-- socket-patch:version ${x} -->`); a property a
parent outside the checkout defines is read from what Maven selects
for the modules that read the declaration;
- the `<repository>` goes in each local root a wired pom inherits from,
and the Trusted Checksums files stay at the project root.
Hosted mode keeps no ledger, so each edit says what it replaced by its
own text, and `unwire_hosted` reads it back. The planner unwires every
pom it would change before returning and leaves a pom alone when that
does not give the text it had, so no edit is written that could not be
taken back byte for byte (a pin in an empty `<dependencyManagement>` is
the case found; reported as `redirect_maven_edit_not_reversible`).
The engine reads every pom the planner reads by asking it until it asks
for nothing new, and confirms a planned dep from the planner's own
report: a pin in a module pom, a property or a recorded declaration is
no substring of the root pom.
The placement code is shared with vendored mode (`place_pins`, moved out
of `plan_with_selection` unchanged), `Reactor::under` can leave modules
out, and `rewrite_declarations` can be told what a version the checkout
does not define reads.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Discovery read only the root pom.xml, and restore only undid a pin
there: a pin in a module pom was invisible to `list`, `vex`, `rollback`
and `remove`, and a reactor root's pin was withheld from `vex` whatever
the modules did.
Discovery now reads a reactor whole (the poms the reactor planner
reads, asked until it asks for nothing new): a pin's comment names its
patch, any other suffixed version is tied to a `socket-patch-<uuid>`
repository by its 8-hex suffix as before, and a `${property}` version is
read through the properties of the declaring pom's chain. Every pom
that carries part of the wiring (the pin, a rewritten declaration, the
property, the repository) is a file of the ref. The patch is attested
by the rule vendored mode uses: no declaration may still build the base
version, and every module that resolves it, or may, is reached by a pin
or a declaration of the patch. What Maven selects is read from the
local Maven repository, on disk only. A reactor whose poms cannot all
be read falls back to its root pom, whose pin stays a ref and is not
attested, as before.
Restore undoes a pin in every pom discovery found it in, or in none: the
planner's edits through `unwire_hosted` (the tagged pin, the recorded
`${...}` version, the property), the `<repository>` in whichever pom
declares it, and the `.mvn` files at the project root. A suffixed
declaration in a reactor, or in a pom that carries one of the planner's
marks, is a rewritten one and gets its base version back; only a single
pom with no mark is read as an earlier release wrote it, where an added
`<dependencyManagement>` entry is told from a rewritten one by its
shape. A project's own management entry that happens to have that shape
is therefore no longer removed in a reactor.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Two capstones on the hosted suite's harness and fake registry, each
checking the invariant (the artifacts Maven resolves after the scan are
the ones it resolved before, the patched one in its patched build), that
a second scan writes nothing, and that `rollback` restores every file
byte for byte and leaves none behind:
- a reactor (the V3 shape): the module that reaches the base version
through another artifact is pinned in its own pom, the module that
declares it has the declaration rewritten, the module that resolves a
newer version is untouched and resolves what it resolved before; a
Maven started in a module directory resolves the patched jar too;
`vex` attests the patch, and withholds it naming the module once a
module declares the base version itself;
- a `${property}` version: a property only the patched artifact reads, a
property a sibling artifact reads too, and a property a parent pom
from the repository defines.
The fixture repository gains a sibling artifact at the victim's version
and a parent pom that defines a version property.
Docs: the CLI contract and the ecosystem guide describe hosted reactors
and property versions (where the pins, the repository and the Trusted
Checksums go, how a `${...}` version is wired and restored, what `vex`
attests, what happens to a pin an earlier release wrote), with the new
warning codes `redirect_maven_pin_would_move_module` and
`redirect_maven_edit_not_reversible`, the edit kind
`redirect_maven_property`, and the narrowed meaning of
`redirect_maven_multimodule_unsupported` and `vex_maven_reactor_root`.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…t tell A hosted scan over a cold local Maven repository rewrites the declarations that name the base version and pins nothing where what Maven selects cannot be told, saying so with the remedy: resolve the project once and scan again. That second scan then found the patch already wired and, by the rule vendored mode keeps (pins are placed when a patch is first wired), added nothing, so the reactor stayed half patched whatever was done. A patch the poms already wire still keeps every pin where it is. A module that no pin or declaration reaches and that is now certain to select the base version is pinned all the same, by the usual placement over the unreached modules only. A scan told nothing new still writes nothing. The pieces of `place_pins` this needs are split out (`keeps_placement`, `undetermined_note`); vendored planning is unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Module poms were read as rewrite targets, so one that is a link out of the repository, not UTF-8, or (in memory) linked or without content refused the whole hosted run with exit 1, as an unreadable root pom does. Before module poms were read at all, such a reactor was left alone with exit 0. They are now read as advisory input, and a module pom that is a symbolic link is not read at all (the rewrite would replace the link with a copy). The planner then finds the reactor incomplete and leaves it as it is, `redirect_maven_multimodule_unsupported` with the reason, exit 0. The guard on linked or unreadable rewrite targets is unchanged and has nothing to refuse. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Restore told a reactor from a single pom by the root's model alone, so a Maven 4 root that could discover subprojects but has none was read as a reactor: an entry an earlier release added to its `<dependencyManagement>` was put back at the base version instead of removed. It now asks what discovery asks (the root lists modules, or Maven 4 finds a subproject under it), so such a root is restored as the single pom it is. A test pins both readings: the added entry goes from a single pom, and in a reactor a managed entry at the suffixed version keeps its place at the base version, since there it cannot be told from the project's own. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review of the hosted reactor work found six ways a scan or a rollback could leave a pom naming a `-socket.<hex8>` version with nothing to serve it, or wiring no rollback would find, and two ways a large reactor was not read. They share one invariant, now enforced in one place. The invariant: once a plan is written, no pom names the suffixed version unless the repository that serves it is declared in that pom's local root and a declaration Maven always reads resolves to it (so discovery finds the patch, and every pom that carries part of it); a rollback returns every pom the plan first wired to its bytes; when no pom names the suffixed version any more its repository and checksum lines go too, and an earlier patch's go only once no pom of the reactor names it. `HostedReactor::plan` plans declarations, properties, pins and the `<repository>` together, checks the result against that (running the rollback's own restore over each pom it would write), and returns the whole plan or a refusal that leaves every pom as it was: - a declaration only a `<profile>` holds was rewritten with no repository and no way for a rollback to find it: now refused whole; - a root the repository could not be added to was skipped while the modules below kept their pins: now refused whole; - an earlier patch's repository and checksum lines were dropped by looking at the poms the plan changed, while an unchanged pom still named that patch: now every pom of the reactor is asked; - a scan that took out the last pin left its repository and checksum lines, which no rollback could clear: they go with the pin; - the warning for a module with a `.mvn` of its own was given only by the scan that wrote the pin: now by every scan. Reading. The engine learned the reactor one module per round, parsing every pom again each round, and stopped after 64 rounds, so a reactor of more than 64 modules was refused. `read_reactor` walks the files itself: each pom is fetched and parsed once, and a missing file stops nothing. The engine, discovery and restore read through it, with one rule for what is read (a module pom that is a symbolic link is not), so what one plans over the others find. The rewriter reads the reactor once per run and plans every patch over it; discovery reads it once for all pins. Discovery reads a single pom together with the parent poms it inherits from inside the checkout, where a property rewrite and the repository may sit. A reactor one of whose poms cannot be read is read for the pins of the others (found, never attested), where it fell back to the root pom alone. Restore reads the reactor itself and restores a pin in every pom that carries part of it, whatever discovery listed, or in none: a pin found through the root alone no longer leaves a module naming a version whose repository the rollback just removed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Three more capstones on the hosted suite: - a reactor whose only declaration of the version sits in a module's profile: the scan exits 0, says why, writes nothing, and the build with that profile resolves what it did; - a single pom whose version is a property a parent pom of the checkout defines: the property and the repository are written in the parent, Maven resolves the patched jar, and a rollback restores both poms byte for byte; - a newer patch superseding an earlier one while a module still reads the earlier version through a property a profile may redefine: the earlier patch keeps its repository and checksum lines, and Maven resolves each module from the repository of the patch its pom names. The CLI contract and the ecosystem guide state the rule a hosted plan is held to (written whole or not at all), what refuses a plan and under which code, what a later scan removes with the last pin, how rollback and remove read a reactor, and how a single pom is read with a parent pom of the checkout. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…en fixtures
The shared `redirect/maven/pom` golden still expected a `${property}`
version to be left alone (`property-version-warn`: no file, no edit), which
the hosted rewriter no longer does, so `redirect_golden_fixtures_match`
failed in CI. Only `--lib` and the CLI suites had been run before the push;
this time every core test target was.
Each expectation below was written from the behaviour the change intends,
then compared with what the rewriter does; none was regenerated unread.
- `property-version-warn` becomes `property-version`: a property that is
defined once and read only by the patched artifact takes the suffixed
version as its value, the pom gets the repository, and nothing warns.
- `property-shared-sibling` (new): a second artifact reads the property,
so the property stays and the declaration takes the literal with the
`<!-- socket-patch:version ${x} -->` comment that rollback reads.
- `property-external-parent-warn` (new): no pom of the checkout defines
the property and nothing says what Maven selects, so nothing is written
(`redirect_maven_dep_unpinned`, `redirect_maven_selection_undetermined`).
- `profile-property-warn` (new): only a profile declares the artifact, so
the plan is refused whole (`redirect_maven_profile_dependency_unpatched`).
- `reactor-module-literal`, `reactor-root-property` (new): a reactor with
no selection to read; the declaration or the root's property is
rewritten, the repository goes in the root, no pin is placed, and the
run says so (`redirect_maven_selection_undetermined`).
- `parent-in-checkout` (new): a single pom whose parent is in the checkout
and holds the property; both edits land in the parent pom.
The five that write files also run through `maven_goldens_round_trip`
(discovery, then restore, byte for byte), and every side of every case has
its entry in the discovery golden, whose only other change is the renamed
key. The other nineteen `maven/pom` cases pass unchanged.
depscan reads the same fixtures (`golden.test.ts`); the PR description lists
the seven for its `TS_LAGGING`.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…pository A `<mirror>` in Maven's `settings.xml` replaces every repository its `<mirrorOf>` matches. Companies commonly set `<mirrorOf>*</mirrorOf>` (or `external:*`), which sends the `socket-patch-<uuid>` repository of a hosted pin to their repository manager. The patched version is not there, so after a hosted scan the build could not resolve it. Hosted Maven never read the settings. On disk, the engine now reads the mirrors Maven is configured with on the scanning machine and hands them to the pom rewriter, which evaluates Maven's own rule against the repository each pin would add. When a mirror would take it over, nothing is written for that dep: the poms and `.mvn/` stay as they are, the scan exits 0, and `redirect_maven_mirror_captures_repository` names the mirror, its `<mirrorOf>`, the settings file, the exclusion that lets the repository through, and vendored mode, which works behind a mirror. The line says that only this machine's settings were read. In memory no machine exists, and nothing changes. Settings read: the user settings (`-s` from `MAVEN_ARGS`, then from `.mvn/maven.config`, else `~/.m2/settings.xml`) merged over the global ones (`-gs` likewise, else `conf/settings.xml` of the wrapper's unpacked distribution, of `$MAVEN_HOME` / `$M2_HOME`, or of the `mvn` on `PATH`), and a `.mvn/settings.xml` the project keeps, as a second way the build may be started. The rule is `DefaultMirrorSelector`'s: a mirror whose whole `<mirrorOf>` is the repository's id wins and is not a capture (it was written for that repository); else the first mirror whose pattern matches, read left to right (`*`, `external:*`, `external:http:*`, ids, `!id`), with `<mirrorOfLayouts>` honoured. Every case in the matcher's tests was run through that class from Maven 3.6.3, 3.9.4, 3.9.16 and 4.0.0-rc-7, and the surprising ones through real builds: a list segment is compared as written, so `*, !id` (with a space) excludes nothing, and ids are whole ids, so `*,!socket-patch-*` excludes nothing either. The documentation recommended exactly that glob; it now says what works. The repository id stays one per patch. A single id would need one URL that serves every patch, which the server does not have, and Maven has no pattern for a family of ids. The message therefore prints the exact exclusion for the patch at hand. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`maven_hosted_is_not_wired_behind_a_mirror_that_takes_every_repository`, against the suite's fake registry standing in for a company's repository manager behind `<mirrorOf>*</mirrorOf>`: - a project wired where no mirror is configured fails to build behind the mirror, on the patched version it cannot find there; - the scan that is told of the mirror (through `MAVEN_ARGS`, where it looks for the `-s` Maven would be started with) exits 0, writes nothing, and names the mirror, the settings file, the exclusion and vendored mode; the project then builds behind the mirror as it did; - with the Socket repository left out of the mirror, the same scan wires the project and Maven resolves the patched jar behind it. The suite's CLI runs now name two settings files that do not exist, so the mirrors of whoever runs it decide nothing. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
#2100 was squash-merged to main, with two commits this branch never had (the selection failing closed when it is unreadable, and a pom the local repository lacks holding a module's pins back) and the rest of main since. This branch still carried #2100's individual commits as of the point it forked from it (7795510). The tree is main plus this branch's own changes: the three-way merge was taken with that fork point as its base, so what #2100 became on main wins over the copy carried here. The diff against main is the same 66 files and the same line counts as this branch's diff against the fork point. One conflict: a single long line of CLI_CONTRACT.md, where main changed the Bun lock versions and this branch the Maven clauses; both are kept. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The hosted engine, discovery and the restore each read a reactor's module and parent poms through a reader that dropped every read error, so a pom that exists but is not UTF-8 text looked like a module with no pom: - the scan reported the reactor as short of a pom it has (`redirect_maven_multimodule_unsupported`) instead of refusing the run for a file whose content it does not know; - discovery left the pom out without a word, and a pin was attested or withheld for the wrong reason; - a rollback restored the poms it could read and left the undecodable one naming a version whose repository was gone. Each now tells "there, but not UTF-8" from "not there": - the engine records such poms and its guard refuses the run for the first, by name, with `candidate_file_unreadable`, as it does for an undecodable root pom. They are judged by what read them, not by their file name: a module's pom may be called anything. A linked or unopenable module pom still only leaves the reactor alone; - discovery reports the file as unreadable and treats it as a pom of the reactor it could not read: the pins of the other poms stay refs and none is attested, for that reason; - the restore refuses every pin of the reactor, names the file, and writes nothing: a pin is restored in every pom that carries part of it or in none, and with a pom unread "every" cannot be kept. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…mirror-guard Brings in dc3ccc2: a reactor pom that is there but is not UTF-8 text is refused or reported as unreadable, never read as a missing module. No conflicts. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
main gained the rule that this repository names no private repository, and the rewording that goes with it, and conflicted here in one long line of CLI_CONTRACT.md: main changed its cargo clause, this branch its Maven clause. Both are kept. Nothing this branch adds over main names a private repository, a path in one, or one of its pull requests. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…mirror-guard Carries main's public-wording pass and the hosted reactors branch's merge of it into the mirror guard. No conflicts. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The gate now decides before anything is written, and only where a repository is at stake. Each dep a mirror captures is planned on its own first: it is gated when that plan would declare its repository in a pom, or a pom already declares it. A dep the rewriter would not wire anyway (the build selects another version, no pom can take the pin) goes through as usual and is told its own reason, with no advice about a mirror that plays no part in it. A gated dep is never handed to the rewriter, so no file is touched for it: the gate used to sit after the block that drops checksum lines, and a gated dep could still rewrite the checksums file. A gated patch is no longer confirmed by what an earlier run left in the poms. It is recorded as decided and not confirmed, so the run does not count it as redirected or attest it while the build behind the mirror cannot resolve it. A mirror that names the repository's id, alone or in a list (`central,socket-patch-<uuid>`), is the operator's choice to serve it and is no capture. The suggested exclusion changed nothing for such a mirror, and the dep was skipped for good. The settings are read as Maven reads them in four more places: a `<mirror>` with no `<id>` has the default id; the global settings are the wrapper's, then those of the `mvn` on `PATH`, and `$MAVEN_HOME` / `$M2_HOME` only with no `mvn` there (the launcher ignores them since 3.5); the wrapper's distribution is found in the layout the `only-script` wrapper unpacks to as well as the wrapper jar's; and the wrapper's properties go through the shared Java-properties reader. The machine is injectable. `read_candidate_files_in` takes the environment the settings are looked up through; the engine's tests run with an empty one, and both CLI test harnesses name two settings files that do not exist, so the mirrors of whoever runs the tests decide nothing. The unit tests of the settings lookup use the platform's own path rules instead of Unix ones with native paths. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview Gated patches are tracked as decided-but-not-confirmed so prior pins are not counted as redirected/attested behind a capturing mirror; deps that would not be wired anyway still get their existing warning codes. Test harnesses default Docs correct the mistaken Reviewed by Cursor Bugbot for commit ebd8524. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit ebd8524. Configure here.
The last commit kept the machine's Maven settings out of the CLI tests by putting `-s` and `-gs` paths that do not exist into `MAVEN_ARGS`, in both test harnesses. socket-patch reads a missing settings file as no settings. A real Maven reads `MAVEN_ARGS` too, and refuses to start: `The specified user settings file does not exist`. `jvm_env::isolate_cli` is also how the production legs isolate the real `mvn` they spawn, so the upstream build of all three Maven legs failed before socket-patch did anything. One rule now, in one place. `hermetic::command`, which builds the command of the socket-patch binary and of nothing else, sets `MAVEN_ARGS` to a settings file the harness creates: real, valid and empty, one per account in the temp directory, never removed. `isolate_cli` no longer sets anything: it removes the ambient `MAVEN_ARGS` as before and puts back only a value the command already carries, so a command built for a Maven child has none. The Bazel harness, whose children are built on `hermetic::command`, removes the variable for them. So the value reaches the socket-patch process alone, and if it ever leaked it could no longer stop a Maven from starting. A self-test holds both halves: the path handed out is an existing file with empty settings, the socket-patch command carries it through the isolation, and a Maven child is started with no `MAVEN_ARGS`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The last commit added `MAVEN_ARGS` to the variables the Bazel harness removes for its children, and not to the names its self-test sets in the shell it plays and looks for in a child. That test requires every removed name to be one it exercises, and failed. `MAVEN_ARGS` is now among those names: the shell the test plays sets it, `hermetic::command` sets its own value on top, and the child sees neither. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…e only where it works Two review comments on the mirror guard. The settings lookup split every line of `.mvn/maven.config` on whitespace. Maven 3.9 and later read that file one argument per line, so a `-s` or `--settings` path that holds a space is one argument there. Read split, it named no file, the mirror in it went unseen, and the pin was written into a build that cannot resolve it: the break this guard exists to prevent. The file is now read as the project's Maven reads it (measured on Maven 3.8.9, 3.9.9 and 4.0.0-rc-7): one argument per line under a Maven Wrapper that pins 3.9 or later, split on whitespace under one that pins an older Maven, and both ways, each as a way the build may be started, when no wrapper says which. The line reading is the one the property reader already uses (`maven_config_line_args`). A value joined to the short option (`-spath`) is read too, as Maven reads it. The warning told the operator that `scan --mode vendored` works behind a mirror, with no bound. Vendored mode gets past a mirror through `maven.repo.local.tail`, which Maven reads from 3.9.2 on; an older Maven reads a vendored patch through the `socket-patch-vendor` file repository, which a mirror of everything takes as well. The text now gives that bound, and when the project's Maven Wrapper pins an older Maven (read as vendored mode itself reads it) it does not offer vendored mode as the project stands: it says what makes it work, a wrapper at 3.9.2 or later, or the mirror also leaving `socket-patch-vendor` out. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
[agent] PR shepherd: review brief for the approver. Stacked on #2114; merge only after #2114. What it does Risk: low to medium. With no capturing mirror nothing changes: the gate goes straight to the old rewriter. Behind a capturing mirror, a hosted scan now skips the patch with a warning; before, it wrote a pin that broke the build. Only the scanning machine's settings are seen, so a Look here
Verified
Changes I made Open questions (owner decisions already listed in the PR; none blocks merging)
Generated by Claude Code |
Wenxin Jiang (Wenxin-Jiang)
left a comment
There was a problem hiding this comment.
[agent] Reviewed at 8641210. The mirror matcher, the gate ahead of the rewriter, and the confirmation path (a gated pin is recorded as decided, never attested) read correctly, and both earlier review threads are fixed. Non-blocking: a -s path in .mvn/maven.config using ${session.rootDirectory} is not interpolated, and a relative -s/-gs path resolves against the project root rather than the working directory; in both cases the mirrors go unseen and the pin is written as before this PR. Lands after #2114.
#2114, which this branch was stacked on, landed on main as a squash (6014caf). Merged against its tip (7bdc058) as the base, so the reactor/property work is taken once and #2150 (f297a90) comes in unchanged. Two conflicts kept both sides: the MAVEN_ARGS and REPIN entries in the Bazel harness, and the mirror and declared_maven modules in formats/maven. CHANGELOG.md is main's. Assisted-by: Claude Code:claude-opus-5-5

Stacked on #2114 (base
fix/maven-hosted-reactors-and-properties). Independent of the repository-scoping PR (#2133); the two touch the same docs sections and will need a trivial merge.What was wrong
Many companies set
<mirrorOf>*</mirrorOf>(orexternal:*) in Maven'ssettings.xml, which sends every repository to their Nexus or Artifactory, thesocket-patch-<uuid>repository of a hosted pin included. The patched coordinate does not exist there, so afterscan --mode hostedthe build could not resolve it. Hosted Maven never read the settings. Vendored mode is unaffected from Maven 3.9.2 (maven.repo.local.tail).What changes
Before
scan --mode hostedwrites anything for a Maven patch on disk, it reads the mirrors Maven is configured with on that machine and evaluates Maven's own rule against the repository the pin would add. When a mirror would take the repository over, nothing is written for that dep:pom.xmland.mvn/stay byte-identical, the scan exits 0, andredirect_maven_mirror_captures_repositorynames the mirror, its<mirrorOf>, the settings file that declares it, and the two ways forward (exclude the repository id from the mirror, orscan --mode vendored). The line says that only the scanning machine's settings were read.Settings read (
crawlers/maven_crawler/settings_mirrors.rs):-s/--settingsfromMAVEN_ARGS, else from.mvn/maven.config, else<user.home>/.m2/settings.xml;-gs/--global-settingslikewise, elseconf/settings.xmlof the Maven that would run: the Maven Wrapper's unpacked distribution, else$MAVEN_HOME/$M2_HOME, else themvnonPATH;.mvn/settings.xmlin the project is weighed as a second way the build may be started (Maven 4 loads it; Maven 3 builds are often given it with-son a command line the scan cannot see).The rule (
formats/maven/mirror.rs), which isDefaultMirrorSelector's:<mirrorOf>is the repository's id wins over every pattern, and is not a capture (it was written for that repository);*,external:*,external:http:*, exact ids, comma lists,!idexclusions, read left to right;<mirrorOfLayouts>must acceptdefault.How the rule was checked against Maven
org.eclipse.aether.util.repository.DefaultMirrorSelectorfrom Maven 3.6.3, 3.9.4, 3.9.16 and 4.0.0-rc-7. The answers agree, except that Maven 3.6.3 does not knowexternal:http:*(added in 3.8.1), which never matches the HTTPS Socket repository anyway.<mirrorOf>**,!socket-patch-<uuid>*, !socket-patch-<uuid>(a space)*,!socket-patch-**(padded)docs/ecosystems.mdadvised<mirrorOf>*,!socket-patch-*</mirrorOf>. That exclusion does nothing; the section is rewritten.The id decision
A mirror can only leave a repository out by its exact id, and hosted mode's id is one per patch (
socket-patch-<patch uuid>).…/patch-registry/maven/<grant>/<uuid>/maven2). Two patches under one id would be one repository that serves only one of them.<mirrorOf>has no id wildcard, as measured above.socket-patch-<patch uuid>, document it as the stable pattern, and have the message print the exact exclusion for the patch at hand (<mirrorOf>*,!socket-patch-<uuid></mirrorOf>), saying that each patch needs its own. For a company behind a mirror the durable answer is vendored mode, which the message names.Reason code
redirect_maven_mirror_captures_repository(warnings[], exit 0, the dep not counted as redirected). No exit status changes. Natural outcome change: on a machine whose Maven settings mirror everything, a hosted Maven scan now reports the patch as not applied instead of writing a pin that breaks the build.Tests
*,external:*,external:http:*, lists,!id), the left-to-right reading, layouts, the exact-id rule, the user-over-global merge.${env.X}, a mirror without<mirrorOf>dropped), and each place a settings file is found (~/.m2,-s/-gsin.mvn/maven.configin every spelling,MAVEN_ARGSwinning,$MAVEN_HOME,PATH, the wrapper's distribution,.mvn/settings.xml).${property}, a reactor and a same-GAV grant are each left alone behind*,external:*and lists that do not exclude the id; a mirror that excludes the id, the HTTP blocker, and a mirror written for the repository change nothing; a pin already wired is left and reported.e2e_redirect_maven_build:maven_hosted_is_not_wired_behind_a_mirror_that_takes_every_repository. WithmirrorOf=*: a project wired without the guard fails to build; the guarded scan exits 0, writes nothing, names the mirror, and the project builds as before; with*,!socket-patch-<uuid>the same scan wires it and Maven resolves the patched jar behind the mirror. Passed locally on Maven 3.6.3, 3.8.9, 3.9.4, 3.9.16 and 4.0.0-rc-7 (the last also with skips turned into failures); 3.9.3 was not run.Golden fixtures
None added, renamed or changed. The in-memory engine has no machine and reads no settings, so the shared
redirect/maven/pomfixtures, and with them the rewriter's other implementation in Socket's backend, are unaffected.What I ran
On macOS, head
8641210ed(#2114's head3b8dd673cmerged in, no conflicts):cargo fmt --all -- --check: clean.cargo clippy --locked --workspace --all-features -- -D warnings: clean.cargo test -p socket-patch-core --tests --no-fail-fast: 8697 passed, 0 failed, 1 ignored (the discovery golden regenerated first, with no change).common_selftests21 passed,spawn_env_hygiene21 passed, and the tests ofe2e_bazel_buildthat need no Bazel, 8 passed.e2e_redirect_maven_buildwith real Maven, required and not skipped: 8 passed on 3.9.4 and 3.9.16. On 4.0.0-rc-7: 7 passed, 1 failed,maven_hosted_patches_a_reactor_module_by_module_and_rolls_back_clean, a test of Patch Maven reactors and ${property} versions in hosted mode #2114. It fails the same way on Patch Maven reactors and ${property} versions in hosted mode #2114's own head with that Maven (Maven 4 writes a.mvn/target/project-local-repoof its own into the project, which that test's snapshot compares), so it does not come from this PR; this PR's own real-Maven test passes on all of them.On
ac2213c35and1f0057f3b, which this head differs from in the settings lookup, the warning text and their tests only:maven_hosted_jackson_databind_delivery,maven_vendored_jackson_databind_deliveryandmaven_agent_jackson_databind_deliveryall pass.cargo test -p socket-patch-cli): 5378 passed. Three failed, none from this change: two old-toolchain tests ofe2e_vendor_cargo_buildcannot execute an x86_64 cargo on this machine, and one signal test ofe2e_gem_native_ext_buildfailed because that run was started detached, with SIGINT ignored (e2e_safety_lockhung in two signal tests for the same reason). Both signal suites pass when run attached: 25 and 14 passed.e2e_vendor_maven_buildwith real Maven on 3.9.16: 5 passed.The selector comparison and the mirror builds in the table ran separately, with an isolated home and local repository. Not run: Linux and Windows (CI).
Review findings
/code-review highreturned ten. Each was confirmed against the code first.maven_is_not_wired_behind_a_mirror_that_would_take_its_repository(its earlier-wired part),a_maven_project_behind_a_capturing_mirror_is_left_alone(engine: nothing confirmed with the wiring in place)only-scriptlayout too (dists/apache-maven-<ver>/<hash>/conf)the_global_and_project_settings_are_weighed_tooOs::Unixwith native pathsOs::current(), and the launcher's name for the platform<mirror>with no<id>was droppeddefault, and shadows a global mirror of that idmirrors_are_read_as_maven_reads_them$MAVEN_HOME/$M2_HOMEwere preferred over themvnonPATHPATH, then those variables as a last resortthe_global_and_project_settings_are_weighed_too.mvn/checksums/checksums.sha256maven_mirror_gate_touches_no_file_of_a_gated_depmaven_mirror_gate_leaves_a_dep_that_would_not_be_wired_to_its_own_reason,maven_mirror_gate_is_per_depcentral,socket-patch-<uuid>) was called a capture, with advice that changes nothinga_mirror_that_lists_the_repository_is_no_capture, and the rewriter test's list of mirrors that leave the repository aloneread_candidate_files_intakes the environment; the engine's tests run with an empty one;hermetic::commandpoints every socket-patch child at an empty settings file (see "The test harness and real Maven")a_maven_project_behind_a_capturing_mirror_is_left_alone(the settings named in the injectedMAVEN_ARGSare the ones read)the_global_and_project_settings_are_weighed_too(a:separator and a continued line)Bugbot findings (on
ebd8524f0)Both confirmed against the code, both fixed in
8641210ed..mvn/maven.configon whitespace. Maven 3.9 and later read the file one argument per line, so a-s/--settingspath that holds a space is one argument there; read split, it named no file, the mirror in it went unseen and the pin was written. The file is now read as the project's Maven reads it (measured on Maven 3.8.9, 3.9.9 and 4.0.0-rc-7): one argument per line under a Maven Wrapper that pins 3.9 or later, split on whitespace under one that pins an older Maven, and both ways, each as a way the build may be started, when no wrapper says which. The line reading is the one the property reader already had, now shared (maven_config_line_args).maven_config_is_read_one_argument_per_line_and_split_on_whitespacecovers every spelling Maven takes, both readings and the wrapper's choice; the engine testa_maven_project_behind_a_capturing_mirror_is_left_aloneshows a-spath with a space on its own line being opened and its mirror gating the pin.scan --mode vendoredworks behind a mirror, with no bound. Vendored mode gets past a mirror throughmaven.repo.local.tail, which Maven reads from 3.9.2 on; an older Maven reads a vendored patch through thesocket-patch-vendorfile repository, which a mirror of everything takes as well. The text now gives that bound. When the project's Maven Wrapper pins an older Maven (read as vendored mode itself reads it), vendored mode is not offered as the project stands; the text says what makes it work: a wrapper at 3.9.2 or later, or the mirror also leavingsocket-patch-vendorout.maven_mirror_warning_offers_vendored_mode_only_where_it_workstests the wording with no wrapper, with wrappers at 3.9.2, 3.9.16 and 4.0.0, and with wrappers at 3.6.3, 3.8.9 and 3.9.1.The test harness and real Maven
The first version of the finding 9 fix (
ebd8524f0) failedhosted-e2e: it put-s/-gspaths that do not exist intoMAVEN_ARGSin both harnesses, andjvm_env::isolate_cliis also how the production legs isolate the realmvnthey spawn. socket-patch reads a missing settings file as no settings; a real Maven refuses to start on one (The specified user settings file does not exist), so the upstream build of all three Maven production legs failed before socket-patch ran.ac2213c35replaces it with one rule in one place:hermetic::command, which builds the command of the socket-patch binary and nothing else, setsMAVEN_ARGSto a settings file the harness creates: real, valid, empty, one per account in the temp directory, never removed.isolate_clisets nothing. It removes the ambientMAVEN_ARGSas before and puts back only a value the command already carries, so a command built for a Maven child has none. The Bazel harness, whose children are built onhermetic::command, removes it for them.the_neutral_maven_settings_are_a_real_file_and_never_reach_a_maven_childasserts that the path handed out exists and is a file with empty settings, that the socket-patch command carries it through the isolation, and that a Maven child is started with noMAVEN_ARGS; the production harness's own test asserts the same of the command it builds.1f0057f3baddsMAVEN_ARGSto the names the Bazel harness's own self-test sets in the shell it plays and looks for in a child (a_bazel_child_sees_no_tool_setting_of_the_shell): that test requires every removed name to be one it exercises, andac2213c35had added the name to the removed list only.Every place a test starts Maven, Gradle or sbt was checked: the production legs go through
isolate_cli(fixed above); the real-Maven suites and the Gradle and sbt suites build their own commands and scrubMAVEN_ARGSthemselves.Review findings not fixed
-s/-gs, the wrapper orPATH. Making it follow them changes whichsettings.xmlthe Maven crawler takes<localRepository>from, on every Maven scan in every mode, which is not this PR's subject and needs its own measurements. Another open PR (Read jars within jar-sized limits and compare patched jars member by member #2132) also reworks that lookup. The mirror guard keeps its own lookup here.Decisions for the owner
!socket-patchexclusion would cover every patch. Worth building?.mvn/settings.xmlis treated as a way the build may be started, so amirrorOf=*in it skips the wiring even when the build would not use it. That errs toward a missed patch rather than a broken build.Known gaps
-sgiven on a build's command line, a CI image's settings or a wrapper distribution that is not unpacked here are not seen. The message says so.hermetic::commandis pointed at an empty settings file, and the engine's tests run with an empty environment, so the settings of whoever runs them decide nothing. Suites that call the scan inside the test process still see that process's environment (see "Review findings not fixed").<activeProfiles>and servers are not read: none of them changes mirror selection.Generated by Claude Code