Skip to content

Commit c64d2cc

Browse files
authored
Merge pull request #335 from midagedev/feat/issue-284-classpath-auto-discovery
[node][runtime] Harden Java classpath auto-discovery fallback (#284)
2 parents 61bc447 + 8c63aca commit c64d2cc

5 files changed

Lines changed: 497 additions & 41 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ All notable changes to this project are documented in this file.
3535
- Added Node debug bundle collector CLI and issue template for reproducible support reports.
3636
- Added startup latency telemetry hook for launch attempts (including auto fallback success/failure events).
3737
- Added `node:doctor` launcher preflight diagnostics command with structured report output.
38+
- Added Java classpath auto-discovery fallback hardening for `auto`/`java` launch modes with configurable probe command/cwd.
3839

3940
## [0.1.3] - 2026-02-24
4041

docs/NODE_TROUBLESHOOTING_PLAYBOOK.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Use this playbook when `@jongodb/memory-server` startup or test-runtime integrat
1616
| `No launcher runtime configured` | neither binary nor Java classpath resolved | set `binaryPath` / `JONGODB_BINARY_PATH`, or set `classpath` / `JONGODB_CLASSPATH` |
1717
| `Binary launch mode requested but no binary was found` | `launchMode: "binary"` but executable is not resolvable | provide explicit `binaryPath` or set `JONGODB_BINARY_PATH` |
1818
| `Java launch mode requested but Java classpath is not configured` | `launchMode: "java"` without classpath | pass `classpath` option or export `JONGODB_CLASSPATH` |
19+
| `Classpath auto-discovery probe failed` | Gradle classpath probe command/cwd is invalid or unavailable | set explicit `classpath`/`JONGODB_CLASSPATH`, or fix `classpathDiscoveryCommand`/`classpathDiscoveryWorkingDirectory` |
1920
| `Failed to start jongodb with available launch configurations` | all launch candidates failed (binary/java) | inspect aggregated `[binary:...]` / `[java:...]` messages and fix per candidate |
2021
| `Launcher emitted empty JONGODB_URI line` | launcher started but did not emit valid URI contract | verify launcher command args/env; update runtime/binary to a compatible build |
2122
| `Requested topologyProfile=singleNodeReplicaSet but URI is missing replicaSet query` | topology profile and emitted URI are mismatched | ensure launcher emits `?replicaSet=<name>` or switch to `topologyProfile: "standalone"` |
@@ -34,6 +35,13 @@ Resolve Java classpath in repo:
3435
export JONGODB_CLASSPATH="$(./.tooling/gradle-8.10.2/bin/gradle --no-daemon -q printLauncherClasspath | tail -n 1)"
3536
```
3637

38+
Customize classpath auto-discovery probe:
39+
40+
```bash
41+
export JONGODB_CLASSPATH_DISCOVERY_CMD="./.tooling/gradle-8.10.2/bin/gradle"
42+
export JONGODB_CLASSPATH_DISCOVERY_CWD="$PWD"
43+
```
44+
3745
Run node compatibility smoke after fix:
3846

3947
```bash
@@ -50,6 +58,7 @@ rm -f .jongodb/jest-memory-server.json
5058
## Configuration Sanity Checklist
5159

5260
- `launchMode` is one of `auto`, `binary`, `java`.
61+
- `classpathDiscovery` is `auto` or `off` (`auto` default).
5362
- `host`, `port`, `databaseName` values are valid/non-empty.
5463
- `topologyProfile` and `replicaSetName` match expected URI contract.
5564
- `envVarName` / `envVarNames` are valid and unique for your test runtime.

packages/memory-server/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ Bundled targets:
254254

255255
Java fallback:
256256
- set `classpath` option or `JONGODB_CLASSPATH`
257+
- if both are missing, classpath auto-discovery probes:
258+
- command: `options.classpathDiscoveryCommand` -> `JONGODB_CLASSPATH_DISCOVERY_CMD` -> repo-local Gradle -> `gradle`
259+
- args: `--no-daemon -q printLauncherClasspath`
260+
- working directory: `options.classpathDiscoveryWorkingDirectory` -> `JONGODB_CLASSPATH_DISCOVERY_CWD` -> `process.cwd()`
261+
- disable probe: `classpathDiscovery: "off"` or `JONGODB_CLASSPATH_DISCOVERY=off`
257262

258263
Launcher contract:
259264
- stdout ready line: `JONGODB_URI=mongodb://...`
@@ -294,6 +299,9 @@ Core:
294299
- `launchMode`: `auto` | `binary` | `java` (default: `auto`)
295300
- `binaryPath`: binary executable override path
296301
- `classpath`: Java classpath string or string array
302+
- `classpathDiscovery`: `auto` | `off` (default: `auto`)
303+
- `classpathDiscoveryCommand`: override command used for classpath auto-discovery probe
304+
- `classpathDiscoveryWorkingDirectory`: cwd for classpath auto-discovery probe
297305
- `javaPath`: Java executable path (default: `java`)
298306
- `launcherClass`: Java launcher class (default: `org.jongodb.server.TcpMongoServerLauncher`)
299307
- `topologyProfile`: `standalone` | `singleNodeReplicaSet` (default: `standalone`)
@@ -358,6 +366,7 @@ const runtime = createJongodbEnvRuntime({
358366
- `No launcher runtime configured`: set `binaryPath` / `JONGODB_BINARY_PATH` / `classpath` / `JONGODB_CLASSPATH`
359367
- `Binary launch mode requested but no binary was found`: provide `binaryPath` or `JONGODB_BINARY_PATH`
360368
- `Java launch mode requested but Java classpath is not configured`: provide `classpath` or `JONGODB_CLASSPATH`
369+
- `Classpath auto-discovery probe failed`: set explicit `classpath` / `JONGODB_CLASSPATH`, or fix Gradle probe command/cwd
361370
- `spawn ... ENOENT`: missing runtime executable path
362371
- startup timeout: launcher did not emit `JONGODB_URI=...`
363372
- `Launcher URI topology options are out of sync`: emitted URI query does not match requested `topologyProfile`/`replicaSetName`

0 commit comments

Comments
 (0)