Skip to content

Make the Gradle --global-prefix tests fail when the flag is ignored - #2267

Open
Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
arch-refactor/1982-gradle-global-prefix-tests
Open

Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
arch-refactor/1982-gradle-global-prefix-tests

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code

Fixes #1982.

Problem

Three Gradle tests are named for --global-prefix, and all three pass with the flag's handling broken:

Test What it claims Why it could not fail
gradle_agent_cli::global_prefix_apply_vex_rollback (fabricated cache, every platform) apply, vex and rollback reach the cache the prefix names its run() sets GRADLE_USER_HOME to that same cache, so project discovery reaches it with the flag ignored
e2e_gradle_agent_build::gradle_agent_global_prefix (real Gradle) the same, checked by what a real build consumes its socket() sets GRADLE_USER_HOME to the cell's home, the cache the prefix names
e2e_gradle_discovery_build::global_prefix_scan_says_nothing_about_the_user_home scan --global-prefix never prints gradle_user_home_differs the note is never printed while GRADLE_USER_HOME is set, and jvm_env::isolate_cli always sets it

So no CLI test fails when apply, vex or rollback ignore --global-prefix for a Gradle cache, or when scan --global-prefix starts printing the note that CLI_CONTRACT.md says is "never emitted with --global-prefix". Someone who changes the JVM cache-root selection or the note's guard gets a green run either way. No user sees a wrong result today.

Evidence on main (cfc870f)

Two one-line mutations of production code, never committed:

 // core crawlers/maven_crawler.rs, get_jvm_cache_roots_with: the prefix is ignored for JVM caches
-        if let Some(ref custom) = options.global_prefix {
+        if let Some(ref custom) = options.global_prefix.as_ref().filter(|_| false) {

 // CLI commands/scan/mod.rs, gradle_scan: the note is printed under --global-prefix too
-        let mismatch = (!prefixed && (global || gradle_build))
+        let mismatch = ((global || gradle_build) || prefixed)

With the first mutation, on main's tests:

$ cargo test -p socket-patch-cli --test gradle_agent_cli global_prefix_apply_vex_rollback
test global_prefix_apply_vex_rollback ... ok
$ SOCKET_PATCH_GRADLE_E2E_REQUIRED=1 cargo test -p socket-patch-cli --test e2e_gradle_agent_build -- --ignored gradle_agent_global_prefix
test gradle_agent_global_prefix ... ok          # Gradle 8.14.3, JDK 21

With the second alone:

$ cargo test -p socket-patch-cli --test e2e_gradle_discovery_build global_prefix_scan_says_nothing
test global_prefix_scan_says_nothing_about_the_user_home ... ok

Fix

Test code only.

  • The two apply / vex / rollback tests run the CLI under another, empty Gradle user home, so only the prefix names the cache. Each first runs apply --offline without the prefix as a control and checks it skips the package as package_not_installed and leaves the jar pristine. The real build in the e2e test still uses the cell's home.
  • The scan test runs with no GRADLE_USER_HOME, which its helper's doc already said None meant. It first runs a --global --ecosystems maven scan as a control and checks that scan does print the note, then checks the --global-prefix scan does not.

Red, then green

The same mutations with this PR's tests:

test global_prefix_apply_vex_rollback ... FAILED
  gradle_agent_cli.rs:363: {"command":"apply","status":"partialFailure", … "errorCode":"package_not_installed" …}
  left: Some(1)  right: Some(0)

test gradle_agent_global_prefix ... FAILED
  e2e_gradle_agent_build.rs:715: ["apply", "--offline", "--global-prefix", "/tmp/.tmprDKufl/.gradle"]: … "errorCode":"package_not_installed" …
  left: Some(1)  right: Some(0)

test global_prefix_scan_says_nothing_about_the_user_home ... FAILED
  e2e_gradle_discovery_build.rs:382:
  left: Some("Gradle's user home follows the account's home directory /root (not $HOME=/tmp/socket-patch-cli-home-); set GRADLE_USER_HOME to scan another Gradle cache")
  right: None

The crawler mutation stops all three commands at apply. To show the vex and rollback assertions hold on their own, I dropped --global-prefix from one call at a time in global_prefix_apply_vex_rollback: without it on vex the test fails at out.ok() (exit 1, no_applicable_patches), and without it on rollback at the final pristine_jar() comparison (the jar stays patched).

On the unchanged production code all three pass.

Deleted

Nothing.

Behavior change

None. No production code is changed.

Risk

  • The scan test's control reads the account's real Gradle cache. The note is only printed when the Gradle user home comes from the passwd home, so a scan that prints it necessarily reads <passwd home>/.gradle. I see no way around that without a test seam in production code. The control is a --global scan, which only reports. It asserts nothing about what that cache holds, and its failure message prints warnings[] only. I ran it with a fabricated module in /root/.gradle/caches/modules-2/files-2.1: the test passes, and the --global-prefix scan still queries exactly the fixture's package. On a machine with a large ~/.gradle this one test takes as long as a global Maven scan of it.
  • The control is skipped where the account has no passwd home (Windows, where the note is never printed, or a container user with no passwd entry). There the --global-prefix half is as weak as before. It ran on Linux in this PR's coverage jobs; the macOS test legs do not run per PR push.
  • No cfg(unix) or cfg(windows) code changed.

Review

/code-review high found no correctness bug and four smaller things:

  • Fixed: the control apply only checked that the jar stayed pristine, which an apply failing for another reason also satisfies. It now checks the package_not_installed skip, and the e2e test checks that it compared at least one cached jar.
  • Fixed: the scan control printed the whole envelope on failure, which lists the real cache's packages.
  • Fixed: a closure in the e2e test shadowed the suite's ok() helper.
  • Left: scan_annotates_lock_membership_without_filtering also passes --global-prefix with GRADLE_USER_HOME naming the same cache. That test is about the inLock annotation of a global run, not about the prefix reaching the cache; scan --global-prefix reaching it is covered by the queried assertion of the scan test above, which needs the flag.

Verification

  • CI on f26c483: 81 of 83 checks pass, and Bugbot found no issues. coverage (1) and coverage (2) ran the two fabricated-cache tests, and the Gradle 9.8.0 e2e leg ran gradle_agent_global_prefix. hosted-e2e and its aggregate ci-ok fail on CI: hosted-e2e gem leg fails on every PR: production published activestorage 6.0.3 patch 146ef6aa, not in GEM_UUIDS #2270 (production published a gem patch that e2e_hosted_production does not pin), which this PR does not touch; the comment below has the output.
  • cargo test -p socket-patch-cli --test gradle_agent_cli: 37 passed.
  • cargo test -p socket-patch-cli --test e2e_gradle_discovery_build: 22 passed, 1 ignored.
  • Locally, as CI's Gradle job runs them, with real Gradle 8.14.3 and JDK 21: SOCKET_PATCH_GRADLE_E2E_REQUIRED=1 cargo test -p socket-patch-cli --test e2e_gradle_discovery_build --test e2e_gradle_agent_build -- --ignored gradle_agent_: 1 and 11 passed (before the review fixes; gradle_agent_global_prefix re-run after them).
  • cargo test -p socket-patch-cli --test cli (the test-tree ratchets): 125 passed.
  • rustfmt --check on the three files: clean. cargo clippy over these test targets reports only what it reports on main (tests/common, tests/prebuilt_common, and one signature in gradle_agent_cli.rs this PR does not touch); CI's clippy does not lint test targets.

Diff

3 files, +84 −11, all test code: e2e_gradle_agent_build.rs +36 −5, gradle_agent_cli.rs +25 −5, e2e_gradle_discovery_build.rs +23 −1. Production +0 −0. No file here is changed by another open arch-refactor/ or agent/ PR.


Generated by Claude Code

Opens the branch for #1982: three Gradle tests named for
--global-prefix pass with the flag's handling broken, because their
harness hands the CLI the same cache through GRADLE_USER_HOME.

Assisted-by: Claude Code
@mikolalysenko Mikola Lysenko (mikolalysenko) added arch-refactor PR opened by the scheduled architecture refactor routine refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code labels Nov 26, 2026
Three tests named for --global-prefix passed with the flag's handling
broken, because their harness also set GRADLE_USER_HOME to the cache
the prefix names (or, for the scan note, to a stand-in that silences
the note either way):

- gradle_agent_cli::global_prefix_apply_vex_rollback and the real-
  Gradle e2e_gradle_agent_build::gradle_agent_global_prefix passed with
  the Maven crawler ignoring the prefix for JVM caches. Project
  discovery reached the same cache through GRADLE_USER_HOME.
- e2e_gradle_discovery_build's
  global_prefix_scan_says_nothing_about_the_user_home passed with scan
  emitting gradle_user_home_differs under --global-prefix. The note is
  never emitted while GRADLE_USER_HOME is set, and the harness always
  set it.

The two apply/vex/rollback tests now run the CLI under another, empty
Gradle user home, so only the prefix names the cache, and first check
that an apply without the prefix leaves the jar alone. The scan test
runs with no GRADLE_USER_HOME, as its helper's doc already said None
meant, and checks first that a --global scan does print the note.

Test code only. Each test fails on its mutation and passes on the
unchanged production code.

Fixes #1982.

Assisted-by: Claude Code
From review of the previous commit.

The control apply of the two apply/vex/rollback tests only checked
that the jar stayed pristine, which an apply failing for another
reason would also satisfy. It now checks the run skipped the package
as package_not_installed, and the real-Gradle test checks that it
compared at least one cached jar.

The scan test's control reads the account's own Gradle cache, so its
failure message prints the warnings and not the whole envelope, which
lists that cache's packages.

The real-Gradle test's closure no longer shadows the suite's ok()
helper.

Refs #1982.

Assisted-by: Claude Code
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 26, 2026 03:31
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Only Gradle CLI/e2e test harness and assertions change; no production paths are modified.

Overview
Test-only hardening for Gradle --global-prefix (#1982). Production behavior is unchanged.

The agent and e2e harnesses used to point GRADLE_USER_HOME at the same cache the prefix names, so apply, vex, and rollback could pass even when --global-prefix was ignored. They now expose socket_env / vex_env (and run_env patterns) so the CLI runs under a separate, empty Gradle user home while the prefix alone targets the real cache.

global_prefix_apply_vex_rollback and gradle_agent_global_prefix add a control apply --offline without the prefix (expect package_not_installed and pristine jars), then exercise apply/vex/rollback with --global-prefix.

global_prefix_scan_says_nothing_about_the_user_home clears GRADLE_USER_HOME when unset (so isolation does not pin a fake home), optionally runs a --global control that must emit gradle_user_home_differs on Unix, and asserts the --global-prefix scan still omits that warning.

Reviewed by Cursor Bugbot for commit f26c483. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit f26c483. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] CI on f26c483: 81 of 83 checks pass, and Bugbot found no issues. The two that fail are hosted-e2e and its aggregate ci-ok, for the cause tracked in #2270, which this PR does not touch:

gem_bundler_hosted_install_proof: the redirect wired patch 146ef6aa-f43e-42aa-9891-0983435220e2, which is not in the pinned any-of set […]. If production replaced or extended the 6.0.3 patches, verify the new patch and extend GEM_UUIDS.
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 19 filtered out
##[error]suite failed on all 3 attempts

It is e2e_hosted_production against the production patch service, and it failed the same way on all three attempts, so I did not re-run it. This PR changes three Gradle test files.

The changed tests ran and passed here: coverage (1) and coverage (2) run the two fabricated-cache tests on Linux, and e2e (… e2e_gradle_discovery_build e2e_gradle_agent_build, gradle, 9.8.0 …) ran gradle_agent_global_prefix with real Gradle 9.8.0. The macOS and Windows test legs and the Gradle 6.9.4 / 7.6.6 / 8.14.3 legs (e2e-extended) do not run per PR push.


Generated by Claude Code

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for approval

What it does. Test-only change for #1982. Three Gradle tests named for --global-prefix used to pass with the flag ignored, because each one also set GRADLE_USER_HOME to the same cache. Now they run the CLI under an empty Gradle user home, so only the prefix can reach the cache. Each test also runs a control first: without the prefix it finds nothing, and a --global scan does print gradle_user_home_differs.

Risk: low. Only tests change, in crates/socket-patch-cli/tests. No production code, CHANGELOG.md or CI changes.

Look here

  • gradle_agent_cli.rs:1327: the empty home and the control apply (package_not_installed, jar pristine)
  • [e2e_gradle_agent_build.rs:710](https://github.com/SocketDev/socket-patch/blob/f26c483d168857c211d9cdd80761134cd8dc299d/crates/socket-patch-cli/tests/e2e_gradle_agent_build.rs#L710): the same in the real-Gradle test. The build itself still uses the cell's home.
  • [e2e_gradle_discovery_build.rs:145](https://github.com/SocketDev/socket-patch/blob/f26c483d168857c211d9cdd80761134cd8dc299d/crates/socket-patch-cli/tests/e2e_gradle_discovery_build.rs#L145): scan(.., None, ..) now really runs with no GRADLE_USER_HOME
  • [e2e_gradle_discovery_build.rs:361](https://github.com/SocketDev/socket-patch/blob/f26c483d168857c211d9cdd80761134cd8dc299d/crates/socket-patch-cli/tests/e2e_gradle_discovery_build.rs#L361): the positive control runs only when the account has a passwd home (Unix). On Windows it is skipped.

Verified

Changes I made: none.
Open questions: none.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-refactor PR opened by the scheduled architecture refactor routine Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code

Projects

None yet

2 participants