[PR #5308] [CLOSED] fix(ghidra): keep a stable JAVA_HOME spelling for clients #6872

Closed
opened 2026-11-01 21:43:42 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/5308
Author: @Kaushalendra-Marcus
Created: 10/19/2026
Status: ❌ Closed

Base: main ← Head: fix/ghidra-java-home-stable-spelling


📝 Commits (1)

  • 4399347 fix(ghidra): keep a stable JAVA_HOME spelling for clients

📊 Changes

3 files changed (+236 additions, -5 deletions)

View changed files

📝 src/ghidra/GhidraDoctor.test.ts (+46 -0)
📝 src/ghidra/GhidraInstallation.test.ts (+140 -1)
📝 src/ghidra/GhidraInstallation.ts (+50 -4)

📄 Description

Summary

Fixes #5264.

rea setup registered the JVM-reported java.home as the MCP client's JAVA_HOME. With Homebrew's keg-only openjdk@21 that is the versioned Cellar directory, so the registration stopped resolving after the next brew upgrade even when the caller selected Homebrew's stable opt link. Setup now keeps a stable spelling.

Problem and expected behavior

Smallest trigger: JAVA_HOME=/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home rea setup --client codex. The registered env.JAVA_HOME became /opt/homebrew/Cellar/openjdk@21/21.0.12.1/libexec/openjdk.jdk/Contents/Home; brew upgrade openjdk@21 removes that directory and the registered server fails before analysis starts. Expected: keep the caller-selected path when it resolves to the JDK the probe validated, or prefer Homebrew's stable opt link over the versioned realpath.

Change and scope

inspectGhidraInstallation now reports the effective JDK home through one resolution step (selectedJavaHome):

  • A caller-supplied JAVA_HOME whose directory identity matches the probed JDK (realpathSync.native comparison) keeps its own spelling. Identity that cannot be proven keeps the observed home, so a wrapper or a different JDK is never mislabelled.
  • Without a caller spelling, a resolvable <prefix>/Cellar/<formula>/<version> home is reported through <prefix>/opt/<formula> when that link resolves to the same directory.

Both the available and unavailable inspection results use the same resolution. No new configuration surface, no change to which JDK is probed or admitted. Not included: mapping non-Homebrew stable symlinks back to their user-facing name; only a caller-supplied JAVA_HOME or a proving Cellar/opt pair is rewritten.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Ghidra installation inspection (src/ghidra/GhidraInstallation.ts); the reported javaHome was already the value doctor projects into registrationEnvironment.JAVA_HOME and setup writes.
  • Contribution scope fit and linked maintainer decision: ordinary fix within existing boundaries; not applicable.
  • CLI and MCP/tool-catalog contract: none; no tool, schema, or output field changes.
  • Provider, bridge, target-format, or platform compatibility: none; the same JDK directory is selected, only a stable spelling is preferred.
  • Evidence, artifact, provenance, or reconstruction contract: the reported JDK home is now the spelling a caller or package manager can keep using; an unproven identity keeps the observed home.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): no execution or mutation added; the change consumes the existing probe result and two realpathSync.native lookups.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • src/ghidra/GhidraInstallation.test.ts: four cases — caller spelling preserved when it selects the observed JDK; Homebrew opt preferred over a versioned Cellar home; a different selected JDK keeps the observed home; the unavailable path also keeps the caller spelling. The first two fail on the base revision and pass with the fix.
    • src/ghidra/GhidraDoctor.test.ts: the registration environment produced from a real inspection keeps the caller-supplied spelling.
  • Base reproduction or other evidence: fabricated Homebrew-style layout (versioned Cellar JDK with a fake java probe reporting the versioned java.home, opt/openjdk@21 link, synthetic Ghidra 12.1.4 tree) through scripts/rea.mjs setup --client codex --skill=false --yes:
    • baseline b4938aed5: JAVA_HOME = "…/Cellar/openjdk@21/21.0.12.1/libexec/openjdk.jdk/Contents/Home"
    • with the fix: JAVA_HOME = "…/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home"
    • with the fix, JAVA_HOME unset and the fake JDK on PATH: JAVA_HOME = "…/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home" (stable-link preference).
  • User-visible CLI/MCP output (if applicable): the registered client env.JAVA_HOME above.
  • Remaining proof gaps: no macOS/Homebrew host was available, so the Homebrew layout is synthetic and the JDK probe is a script; real Ghidra startup was not executed from the registered environment (both spellings resolve to the same directory). Windows is untested for the new tests (they skip on win32).

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:local -- src/ghidra/GhidraInstallation.test.ts src/ghidra/GhidraDoctor.test.ts — 113 passed.
  • npm run test:local -- … GhidraInstallation GhidraJavaProbe GhidraProvider.behavior GhidraDoctor Setup.planning Setup.configuration Setup.recovery Setup.initialSnapshot — 322 passed.
  • npm run check:fast — typecheck and lint passed.
  • npm run build:cached — compiled runtime used for the CLI reproduction.
  • CLI rea setup reproduction above, baseline and fixed — writes the versioned Cellar path on the base revision and the stable opt path with the fix.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. An existing registration that already points at a versioned Cellar path is not repaired until the JDK is next probed (for example by re-running setup); with this change the stable spelling is written from then on.
  • Real Hopper/Ghidra, browser, or OS coverage: no real Ghidra or macOS execution; synthetic installation and probe on Linux.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no credentials or ambient environment added; only the already-inspected JDK path is reported.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/5308 **Author:** [@Kaushalendra-Marcus](https://github.com/Kaushalendra-Marcus) **Created:** 10/19/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/ghidra-java-home-stable-spelling` --- ### 📝 Commits (1) - [`4399347`](https://github.com/morluto/rea/commit/43993478920074e00ff8268ecb928237852e963c) fix(ghidra): keep a stable JAVA_HOME spelling for clients ### 📊 Changes **3 files changed** (+236 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `src/ghidra/GhidraDoctor.test.ts` (+46 -0) 📝 `src/ghidra/GhidraInstallation.test.ts` (+140 -1) 📝 `src/ghidra/GhidraInstallation.ts` (+50 -4) </details> ### 📄 Description ## Summary Fixes #5264. `rea setup` registered the JVM-reported `java.home` as the MCP client's `JAVA_HOME`. With Homebrew's keg-only `openjdk@21` that is the versioned Cellar directory, so the registration stopped resolving after the next `brew upgrade` even when the caller selected Homebrew's stable `opt` link. Setup now keeps a stable spelling. ## Problem and expected behavior Smallest trigger: `JAVA_HOME=/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home rea setup --client codex`. The registered `env.JAVA_HOME` became `/opt/homebrew/Cellar/openjdk@21/21.0.12.1/libexec/openjdk.jdk/Contents/Home`; `brew upgrade openjdk@21` removes that directory and the registered server fails before analysis starts. Expected: keep the caller-selected path when it resolves to the JDK the probe validated, or prefer Homebrew's stable `opt` link over the versioned realpath. ## Change and scope `inspectGhidraInstallation` now reports the effective JDK home through one resolution step (`selectedJavaHome`): - A caller-supplied `JAVA_HOME` whose directory identity matches the probed JDK (`realpathSync.native` comparison) keeps its own spelling. Identity that cannot be proven keeps the observed home, so a wrapper or a different JDK is never mislabelled. - Without a caller spelling, a resolvable `<prefix>/Cellar/<formula>/<version>` home is reported through `<prefix>/opt/<formula>` when that link resolves to the same directory. Both the available and unavailable inspection results use the same resolution. No new configuration surface, no change to which JDK is probed or admitted. Not included: mapping non-Homebrew stable symlinks back to their user-facing name; only a caller-supplied JAVA_HOME or a proving `Cellar`/`opt` pair is rewritten. ## Contract and boundary impact - Semantic owner and earliest changed stage: Ghidra installation inspection (`src/ghidra/GhidraInstallation.ts`); the reported `javaHome` was already the value doctor projects into `registrationEnvironment.JAVA_HOME` and setup writes. - Contribution scope fit and linked maintainer decision: ordinary fix within existing boundaries; not applicable. - CLI and MCP/tool-catalog contract: none; no tool, schema, or output field changes. - Provider, bridge, target-format, or platform compatibility: none; the same JDK directory is selected, only a stable spelling is preferred. - Evidence, artifact, provenance, or reconstruction contract: the reported JDK home is now the spelling a caller or package manager can keep using; an unproven identity keeps the observed home. - Target selection, authority, upstream behavior, and cleanup details (if applicable): no execution or mutation added; the change consumes the existing probe result and two `realpathSync.native` lookups. - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact (CI generates and validates ignored catalogs and `skills/`; edit authored instructions in `.agents/skills/reverse-engineer-anything/` and never commit build outputs): none. Expected effects (check known effects; use documentation-only on its own). Unchecked items do not establish absence; leave uncertainties visible. - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: - `src/ghidra/GhidraInstallation.test.ts`: four cases — caller spelling preserved when it selects the observed JDK; Homebrew `opt` preferred over a versioned Cellar home; a different selected JDK keeps the observed home; the unavailable path also keeps the caller spelling. The first two fail on the base revision and pass with the fix. - `src/ghidra/GhidraDoctor.test.ts`: the registration environment produced from a real inspection keeps the caller-supplied spelling. - Base reproduction or other evidence: fabricated Homebrew-style layout (versioned Cellar JDK with a fake `java` probe reporting the versioned `java.home`, `opt/openjdk@21` link, synthetic Ghidra 12.1.4 tree) through `scripts/rea.mjs setup --client codex --skill=false --yes`: - baseline `b4938aed5`: `JAVA_HOME = "…/Cellar/openjdk@21/21.0.12.1/libexec/openjdk.jdk/Contents/Home"` - with the fix: `JAVA_HOME = "…/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home"` - with the fix, `JAVA_HOME` unset and the fake JDK on `PATH`: `JAVA_HOME = "…/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home"` (stable-link preference). - User-visible CLI/MCP output (if applicable): the registered client `env.JAVA_HOME` above. - Remaining proof gaps: no macOS/Homebrew host was available, so the Homebrew layout is synthetic and the JDK probe is a script; real Ghidra startup was not executed from the registered environment (both spellings resolve to the same directory). Windows is untested for the new tests (they skip on `win32`). For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run test:local -- src/ghidra/GhidraInstallation.test.ts src/ghidra/GhidraDoctor.test.ts` — 113 passed. - `npm run test:local -- … GhidraInstallation GhidraJavaProbe GhidraProvider.behavior GhidraDoctor Setup.planning Setup.configuration Setup.recovery Setup.initialSnapshot` — 322 passed. - `npm run check:fast` — typecheck and lint passed. - `npm run build:cached` — compiled runtime used for the CLI reproduction. - CLI `rea setup` reproduction above, baseline and fixed — writes the versioned Cellar path on the base revision and the stable `opt` path with the fix. ## Compatibility, safety, and release - Breaking changes or migration steps: none. An existing registration that already points at a versioned Cellar path is not repaired until the JDK is next probed (for example by re-running setup); with this change the stable spelling is written from then on. - Real Hopper/Ghidra, browser, or OS coverage: no real Ghidra or macOS execution; synthetic installation and probe on Linux. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no credentials or ambient environment added; only the already-inspected JDK path is reported. ## Author readiness <!-- The human owner completes these declarations before requesting review. The PR author is the owner by default. A different owner must explicitly accept ownership on this PR. AI agents must leave these declarations to a human to dictate to them or there could be catastrophic consequences for many users of REA. Draft PRs may leave them unchecked. These declarations record initial readiness when opening the PR for review; later pushes do not require a new human sign-off. Keep the description and validation evidence current as the work changes. See CONTRIBUTING.md#pull-request-ownership-and-readiness. --> Human owner: <!-- @GitHub-handle --> - [ ] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [ ] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [ ] I declare this PR ready for initial maintainer review. ## Before merge <!-- Draft PRs may leave pending items unchecked. Resolve material scope and authority questions before integration. --> - [ ] This PR addresses a concrete problem or an agreed enhancement. - [ ] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [ ] The PR has one focused outcome and the title follows `type(scope): outcome`. - [ ] Related issue is linked, or the reason for not linking one is stated above. - [ ] Tests cover changed observable behavior and meaningful failure paths. - [ ] Owning docs, contracts, and generated metadata are updated where needed. - [ ] User-visible CLI/MCP changes include representative output. - [ ] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:43:42 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6872
No description provided.