Skip to content

Tests that only need a project load its index, and an index names the JDK it holds - #140

Open
Pelotrio wants to merge 4 commits into
1.21.1from
claude/test-suite
Open

Pelotrio wants to merge 4 commits into
1.21.1from
claude/test-suite

Conversation

@Pelotrio

@Pelotrio Pelotrio commented Oct 5, 2026

Copy link
Copy Markdown
Member

M2, first PR (plan: docs/TEST_SUITE.md, local on 1.21.1, after Codex's review).

What was wrong

  • ProjectTreeTest built the whole runtime index, 27,837 JDK classes, every time a project opened. Its await for the index (withWindow:91) came near its 5 s limit, and on 2026-10-05 a full local run failed there twice. Its mod archive held only pack.mcmeta, so the index had nothing but the JDK, and an index without classes is refused.
  • assertReveals slept 300 ms after every reveal, eight times in one case, though the reveal's future had already completed. InspectionReadsTest slept 500 ms before asserting a count it could wait for.
  • The index read Companion's own JDK but recorded the game's Java home. A runtime cache is keyed by the game's inventory alone, so a Companion on another JVM, such as the IntelliJ run, could load an index of another JDK. The mod starts Companion on the game's Java, so in normal use the two agree.

What changes

  • ProjectTreeTest's mod archive holds one class, and its index is cached before the project opens with RuntimeTestSources.writeLocalCache, as the cache-loading tests already do. No production seam.
  • The two fixed sleeps wait for the state they assert.
  • The index's JDK source names java.home of the JVM that read it. IndexCache.requireSourcePaths, which both loading paths use, refuses a cache holding another Java runtime, so it is rebuilt. Existing caches made by a Companion the game started keep loading.

Measured

Companion's suite alone, on this machine:

Suite time Wall ProjectTreeTest
Before 215 s 226 s 40.2 s
After, three runs 192-207 s 197-213 s 19.5 s

In the three runs no UiTestScope.await took more than 1 s (logged with temporary instrumentation, not committed). The index's own suites still index the whole JDK. About 50 s of suite time remain there, which is the plan's second PR.

Tests

  • IndexCacheTest.anIndexOfAnotherJavaRuntimeIsNotUsed
  • These suites pass: ProjectTreeTest, InspectionReadsTest, LocalIndexTest, RuntimeIndexRecoveryTest, RuntimeIndexServiceTest, OfflineProjectIntegrationTest, LiveRuntimeStartupTest, RuntimeInstallationTest.
  • Companion's whole suite passed three times.

🤖 Generated with Claude Code

… JDK it holds

ProjectTreeTest built the runtime index, the whole JDK, every time a project opened, and its await for the index
came near its five-second limit on a loaded machine. Its mod archive now holds a class and its index is cached
before the project opens, as cache-loading tests already do. Two waits wait for what they assert instead of a
fixed time.

The index read Companion's own JDK but recorded the game's Java home, and a runtime cache is keyed by the game's
inventory alone: a Companion on another JVM could load an index of another JDK. The JDK source now names the one
read, and a cache holding another is rebuilt.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-05T22:36:43.342568Z 49dcbc2 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a0ee9011ce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (!Files.isRegularFile(path) && !Files.isDirectory(path)) {
throw new IOException("Prepared runtime source is unavailable: " + path);
}
if (source.module().kind() == ModuleKind.JAVA_RUNTIME && !path.equals(javaHome())) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Normalize java.home before comparing cache paths

When Companion is launched with a valid but non-normalized java.home such as /opt/jdk/. or a relative path, every generated Java-runtime Source stores an absolute normalized path, but this comparison uses the raw system-property path. The paths therefore compare unequal; cached indexes are rejected, and rebuilding also fails when IndexCache.write validates the newly written manifest. Return an absolute normalized path from javaHome() before comparing it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 2751799: javaHome() returns the absolute, normalized path, as Source stores it. aJavaHomeWrittenWithRedundantPartsIsTheSameRuntime sets java.home to <home>/.; it fails without the fix.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2751799b4e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +158 to +159
if (source.module().kind() == ModuleKind.JAVA_RUNTIME && !path.equals(javaHome())) {
throw new IOException("The index holds the classes of another Java runtime: " + path);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate JDK contents, not only its install path

When Companion uses a different JVM from the game—explicitly supported for IDE/offline launches—and that JVM is upgraded or replaced in place, the saved game inventory ID remains unchanged and this path equality still accepts the old cache. The loaded index then describes the previous JDK while RuntimeSnapshotBytecodeSource.readJdk reads classes from the current JRT filesystem, causing stale or missing search results and potentially mismatched class metadata. Persist and validate a Companion-JDK version/build fingerprint (for example, the runtime version plus the JDK release metadata), not just java.home.

AGENTS.md reference: AGENTS.md:L7-L7

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 747455e: the manifest records java.runtime.version (version and build) beside the path, and an index written on another build is rebuilt. anIndexWrittenOnAnotherBuildOfTheJavaRuntimeIsNotUsed changes the version under the same path.

Pelotrio and others added 2 commits October 6, 2026 00:33
…e in place changes

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
CompanionRenderingDefaultsTest's probe did not start within 15 s while two CI runs shared the runner. The waits end
when the process exits, so the limit costs nothing when it starts at once; a deadlock still fails.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant