Skip to content

MCP test runner ignores Test / javaOptions from build.sbt (and .jvmopts/env vars)Β #8305

@ckipp01

Description

@ckipp01

Describe the bug

When running tests via MCP, JVM options configured in build.sbt under Test / javaOptions are silently ignored, causing test failures that don't occur when running via bloop, sbt, or the editor UI (DAP).

The MCP test path in McpTestRunner.runTests() constructs ScalaTestSuites with hardcoded empty JVM options:

  // McpTestRunner.scala
  val testSuites = new b.ScalaTestSuites(
    List(testSelection).asJava,
    Nil.asJava,  // jvmOptions β€” always empty
    Nil.asJava,  // environmentVariables β€” always empty
  )

It then creates a TestSuiteDebugAdapter and runs the test directly inside Metals, completely bypassing the build server. TestSuiteDebugAdapter.run() forks the JVM using only testClasses.getJvmOptions(), which is the empty list above.

This contrasts with the DAP path, which calls DebugProvider.startDebugSession(). That method checks buildServer.isDebuggingProvider || buildServer.isSbt and β€” for both bloop and sbt β€” forwards the debug session request to the build server. The build server then handles test execution with full knowledge of Test / javaOptions from the build definition.

Two separate issues:

  1. McpTestRunner doesn't call JvmOpts.fromWorkspaceOrEnvForTest(workspace), so even .test-jvmopts, TEST_JVM_OPTS, .jvmopts, and JVM_OPTS are ignored. The DAP path reads these via DebugDiscovery.createScalaTestSuites() and DebugProvider.startTestSuite().
  2. More fundamentally, because the MCP path bypasses the build server entirely, Test / javaOptions defined in build.sbt can never be picked up β€” regardless of whether bloop or sbt is the build server.

Expected behavior

Tests run via MCP should respect the same JVM options as when run via the editor UI or directly via the build tool.

Operating system

macOS

Editor/Extension

Nvim (nvim-metals)

Version of Metals

Latest snapshot

Scala version/s

All

Extra context or search terms

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions