Skip to content

build: quote the Mockito -javaagent path in surefire argLine - #1540

Open
innoprej wants to merge 1 commit into
google:mainfrom
innoprej:build/quote-mockito-javaagent
Open

innoprej wants to merge 1 commit into
google:mainfrom
innoprej:build/quote-mockito-javaagent

Conversation

@innoprej

Copy link
Copy Markdown

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

2. Or, if no issue exists, describe the change:

Problem:

Since #1483, every module whose tests use Mockito sets mockito.javaagent.arg to -javaagent:${org.mockito:mockito-core:jar}, and the parent pom prepends it to the surefire argLine. The value is not quoted. Surefire splits argLine into JVM arguments at unquoted whitespace, so when the local Maven repository path contains a space (for example a Windows user profile such as C:\Users\First Last\.m2\repository) the agent path is cut at the space and the forked JVM exits before running a single test:

[ERROR] Error occurred during initialization of VM
[WARNING] [stderr] Error opening zip file or JAR manifest missing : C:\Users\First
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD FAILURE

The JaCoCo agent argument in the same argLine is not affected because jacoco-maven-plugin quotes its own argument when the path contains a space. CI runs on Ubuntu with a space-free repository path, so it cannot see this.

Solution:

Quote the value in the seven modules that set it (a2a, core, dev, contrib/firestore-session-service, contrib/langchain4j, contrib/planners, contrib/spring-ai), which is the form the parent pom's comment already shows, and add a sentence to that comment saying the quotes must stay. The quotes belong in the value rather than around ${mockito.javaagent.arg} in the parent's surefire.argLine: contrib/firestore-session-service splices the property into its own argLine, so a parent-level change would not reach it, and a value that carries its own quotes works for every consumer, the same way the JaCoCo property does. No other build change.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change. (Build configuration only; verified by the runs below.)
  • All unit tests pass locally, except one pre-existing Windows-only failure described below.

Windows 11, Microsoft OpenJDK 17.0.19, Maven 4.0.0-rc-3 via mvnw, with the local repository under a user profile path that contains a space unless noted:

Run main This change
mvn -pl core test -Dtest=ToolConfirmationTest fork exits at VM init, 0 tests 3 tests pass; the module's other surefire executions start too
mvn -pl a2a test -Dtest=EventConverterTest fork exits at VM init, 0 tests 9 tests pass
mvn -pl contrib/firestore-session-service test -Dtest=FirestoreMemoryServiceTest (module with its own argLine) fork exits at VM init, 0 tests 7 tests pass
mvn -pl core test not run (same argLine as above) 1883 run, 24 skipped, 1 failure: the pre-existing Windows path-separator case LocalSkillSourceTest.testListResources, which fails the same way on main with a space-free repository path
mvn -pl core test -Dtest=ToolConfirmationTest with a space-free repository path 3 tests pass 3 tests pass

The same comparison also ran on GitHub-hosted runners in my fork (run), with -Dmaven.repo.local pointing at a directory whose path contains spaces:

Runner main (-pl core -Dtest=ToolConfirmationTest) This change (one test class in each of the seven modules)
ubuntu-latest fork exits at VM init (... missing : /home/runner/work/_temp/m2), 0 tests all seven modules' tests pass
windows-latest fork exits at VM init (... missing : D:\a\_temp\m2), 0 tests all seven modules' tests pass
macos-latest fork exits at VM init (... missing : /Users/runner/work/_temp/m2), 0 tests all seven modules' tests pass

The same run also executed the validation workflow's command (./mvnw -Prelease clean package, then git diff --exit-code) on this change with JDK 17, 21 and 25; all three passed.

With mvn -X, the forked command line now carries the agent as one quoted argument, next to the JaCoCo one:

"-javaagent:C:\Users\First Last\.m2\repository\org\mockito\mockito-core\5.23.0\mockito-core-5.23.0.jar" "-javaagent:C:\\Users\\First Last\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.8.14\\org.jacoco.agent-0.8.14-runtime.jar=destfile=..."

Manual End-to-End (E2E) Tests:

On Windows with a user profile path that contains a space, run ./mvnw -pl core test -Dtest=ToolConfirmationTest on main: the surefire fork fails with the error above and no test runs. With this change the same command runs the tests, and the forked command line shows the agent as a single quoted argument, like the JaCoCo one next to it. On Linux and macOS the same happens with -Dmaven.repo.local set to a path with spaces (see the fork run above). IntelliJ's own test runner was not tried.

Checklist

  • I have read the CONTRIBUTING.md document.
  • My pull request contains a single commit.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes, apart from the pre-existing Windows-only failure noted above.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

Found while running the core tests on Windows for #1534. The remaining Windows-only test failure (LocalSkillSourceTest.testListResources, which compares \ with /) is unrelated and left for a separate change.

The -javaagent argument added in google#1483 is set per module as
-javaagent:${org.mockito:mockito-core:jar} without quotes. Surefire
splits argLine into JVM arguments at unquoted whitespace, so when the
local Maven repository path contains a space (for example a Windows
user profile such as C:\Users\First Last) the forked JVM receives a
truncated agent path and exits before running any test:

  Error opening zip file or JAR manifest missing : C:\Users\First

Quote the value in every module that sets it, which is how
jacoco-maven-plugin already passes its own agent argument when the
path contains a space, and note in the parent pom that the quotes must
stay. CI runs on Ubuntu with a space-free repository path, so it could
not catch this.
@hemasekhar-p

Copy link
Copy Markdown
Contributor

Hi @innoprej, We greatly appreciate your contribution and the effort you put into this pull request. It is currently under review by our team. We will notify you if any additional details are needed. Thank you.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants