Skip to content

Test the undo of a Maven pin that another build's file holds too - #2171

Merged
Mikola Lysenko (mikolalysenko) merged 3 commits into
mainfrom
fix/maven-undo-two-build-pin
Nov 20, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 3 commits into
mainfrom
fix/maven-undo-two-build-pin

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

No user-visible change.

What this is

Tests only. The fix this pull request first carried is on main already: it landed with #2163, which needed it. rollback and remove restore pom.xml for a hosted Maven patch that a second build of the same checkout pins too (an sbt build, a Gradle build, a Bazel hub). Before that fix they left the pom pinned and reported success.

What is left here are the tests a code review of that fix asked for. They hold what follows when two restorers act on one pin. After the merge with main the diff is three files, +161 −52, none of it product code.

The tests

  • The sbt golden harness (crates/socket-patch-core/tests/redirect_sbt_golden.rs). It undid each wiring case with hand-built pins that listed only socket-patch.sbt and asserted every other file untouched. For the case pom-also-present it therefore asserted that the pinned pom.xml stays pinned, which is why the goldens never saw the defect. It now restores the pins that discovery finds in the wired tree, as rollback does, and compares the whole tree with the case's input.
  • A Gradle build beside a pom (upstream/maven.rs). One scan wires a Gradle build and the pom.xml beside it, discovery gives one pin with both files, and the undo puts the tree back byte for byte. The fix's commit only read this case; now it runs.
  • All or nothing (upstream/maven.rs). A pin is restored in every file that wires it or in none. With an edited socket-patch.sbt the sbt restorer refuses, and pom.xml and the .mvn files stay pinned. With a pom that names the patched version outside a dependency the Maven restorer refuses, and socket-patch.sbt keeps its row. Nothing is written in either case.
  • vendor over such a pin (crates/socket-patch-cli/tests/e2e_sbt_vendor.rs). The takeover restores the whole pin, so after one run pom.xml is the upstream one, the sbt build is vendored, and the run gives the advisory vendor_sbt_pom_ignored. Before the fix the same run left pom.xml pinned and a second run unpinned it. The takeover itself is not changed here.

What was run

On macOS arm64, on top of current main: the unit tests of the Maven restorer (25 passed), the sbt golden target, --test e2e_sbt_vendor (21 passed) and cargo clippy --workspace --all-features -- -D warnings.

When the commit was written, every new expectation failed with the fix taken out, except the half where the sbt restorer refuses: that one fails when the driver writes the files of a pass in which a pin was refused. Those runs were not repeated after the merge with main.

Left open

  • The driver masks a restorer that passes over a pin it was handed. In upstream/mod.rs the set of handled pins is a union over formats, so when one format's restorer silently skips a pin and another format handles it, the run reports the pin restored. That is how this defect stayed unseen. Refusing every such pin would turn the next defect of this kind into a refusal, but it changes behaviour for other ecosystems and wants a pull request of its own.
  • A reactor module named by a file path (<module>child/custom-pom.xml</module>) is classed as an unsupported file, and its pin always refuses. That was so before the fix and is unchanged.

🤖 Generated with Claude Code

…s too

A hosted pin is one patch of one package in every file that wires it,
and each file format has a restorer of its own, which is handed the
pins that have a file of its format together with that format's files.
When hosted mode learned Maven reactors and `${property}` versions
(#2114), the Maven restorer went from a loop over its files to a loop
over its pins, and took every file of a pin for one of its poms. A pin
with a file the Maven restorer was not handed was then passed over
without a refusal: nothing was restored in pom.xml or under .mvn, while
the restorer of the other file took its part out and the run reported
the pin as restored.

A checkout that sbt builds beside Maven is such a case: the patch is
pinned in socket-patch.sbt and in pom.xml, and `rollback` (or `remove`)
exits 0, reports one rolled-back patch, and leaves pom.xml and the two
.mvn files pinned. The hosted Gradle index beside a pom.xml is a second
file of the same kind (read, not run).

The poms of a pin are now those of its files that the Maven restorer
was handed. A pin that only poms hold has all its files there, so it is
read exactly as before: a reactor's pin is restored in every pom that
carries part of it or in none, and a pom that cannot be read refuses
it. The existing tests of the Maven undo pass unedited.

The new test runs discovery and the undo over the existing fixture
sbt/redirect/pom-also-present: one pin with pom.xml and
socket-patch.sbt, and the tree is byte for byte its input afterwards.
Without the fix it fails, and no other test of the core suite does.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Tests only: no product code changes.

The fix before this commit lets the Maven restorer act on a hosted pin
that another build's file holds too. These tests hold what follows from
two restorers acting on one pin.

The sbt golden harness undid each wiring case with hand-built pins that
listed only socket-patch.sbt, and asserted every other file untouched.
For the case pom-also-present it therefore asserted that the pinned
pom.xml stays pinned, which is why the goldens never saw the defect. It
now restores the pins discovery finds in the wired tree, as `rollback`
does, and compares the whole tree with the case's input. The ten wiring
cases that create the file pass; without the fix pom-also-present fails.

In upstream/maven.rs:

- The hosted Gradle index beside a pom.xml is now run, not only read:
  one scan wires a Gradle build and the pom beside it, discovery gives
  one pin with both files, and the undo puts the tree back byte for
  byte. It is a second row of the existing two-build test.
- A pin is restored in every file that wires it or in none. With an
  edited socket-patch.sbt the sbt restorer refuses, and pom.xml and the
  .mvn files stay pinned. With a pom that names the patched version
  outside a dependency the Maven restorer refuses, and socket-patch.sbt
  keeps its row. Nothing is written in either case.

In the CLI, `vendor` over a hosted pin that pom.xml and socket-patch.sbt
both hold. The takeover restores the whole pin, so with the fix pom.xml
is the upstream one after one run, the sbt build is vendored, and the
run gives the advisory vendor_sbt_pom_ignored. Before the fix the same
run left pom.xml pinned, and a second `vendor` run unpinned it. The
test holds the new behaviour; the takeover itself is not changed.

Every new expectation fails with the fix taken out, except the half
where the sbt restorer refuses: that one fails when the driver writes
the files of a pass in which a pin was refused.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ild-pin

# Conflicts:
#	crates/socket-patch-core/src/patch/redirect/upstream/maven.rs
@mikolalysenko Mikola Lysenko (mikolalysenko) changed the title Restore pom.xml on rollback when another build's file holds the Maven pin too Test the undo of a Maven pin that another build's file holds too Nov 20, 2026
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 20, 2026 13:17
@cursor

cursor Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Test-only changes with no production code modified; risk is limited to CI/runtime of the test suite.

Overview
Tests only — no product code. Coverage for behavior fixed in #2163: rollback/remove and vendor eject must restore pom.xml when the same hosted pin is wired in another build’s file (sbt, Gradle) as well as Maven.

The sbt golden harness no longer rolls back with hand-built pins that only list socket-patch.sbt. It restores whatever discovery finds in the wired tree (same as real rollback) and asserts the whole tree matches input/, including a co-located pom.xml.

Maven upstream tests add a Gradle+pom scenario beside the existing sbt+pom fixture, extract pom_beside_sbt, and add all-or-nothing cases: if either restorer refuses (edited socket-patch.sbt or pom naming the suffix outside a dependency), nothing is written.

A new CLI e2e runs vendor takeover when pom.xml is pinned beside the sbt build: expects upstream pom.xml, removed .mvn wiring, vendored sbt, and advisory vendor_sbt_pom_ignored.

Reviewed by Cursor Bugbot for commit 108f5be. Configure here.

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 20, 2026
Merged via the queue into main with commit 064c0af Nov 20, 2026
90 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the fix/maven-undo-two-build-pin branch November 20, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants