Skip to content

Commit a05e3c0

Browse files
committed
test: verify the installed Windows OpenCLI launch path
1 parent 6fcd9ba commit a05e3c0

4 files changed

Lines changed: 96 additions & 0 deletions

File tree

‎.github/workflows/contracts.yml‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,23 @@ jobs:
189189
--suite process=io.github.easy4j.opencli.contract.OpenCliProcessBoundaryTest \
190190
--output platform-evidence/report.json
191191
exit "$result"
192+
- name: Verify npm-installed OpenCLI on Windows
193+
if: runner.os == 'Windows'
194+
run: |
195+
install_dir="$RUNNER_TEMP/opencli-launcher-check"
196+
npm install --prefix "$install_dir" --ignore-scripts --no-audit --no-fund @jackwener/opencli@1.8.8
197+
package_dir="$install_dir/node_modules/@jackwener/opencli"
198+
cli_entry="$package_dir/dist/src/main.js"
199+
registry="$install_dir/registry.json"
200+
node "$cli_entry" --version | tee platform-evidence/installed-opencli-version.txt
201+
grep -Fx '1.8.8' platform-evidence/installed-opencli-version.txt
202+
node "$cli_entry" list -f json > "$registry"
203+
OPENCLI_INSTALLED_NODE="$(node -p 'process.execPath')"
204+
OPENCLI_INSTALLED_ENTRY="$(cygpath -w "$cli_entry")"
205+
OPENCLI_INSTALLED_REGISTRY="$(cygpath -w "$registry")"
206+
OPENCLI_INSTALLED_BATCH_SHIM="$(cygpath -w "$install_dir/node_modules/.bin/opencli.cmd")"
207+
export OPENCLI_INSTALLED_NODE OPENCLI_INSTALLED_ENTRY OPENCLI_INSTALLED_REGISTRY OPENCLI_INSTALLED_BATCH_SHIM
208+
mvn -B --no-transfer-progress -Dtest=OpenCliInstalledLauncherIT test
192209
- name: Upload platform subprocess evidence
193210
if: always()
194211
uses: actions/upload-artifact@v7

‎README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ Notes:
196196
- In remote mode the `stdout` is the JSON `items` the agent returned (parsed into line items per `format`), which may differ from local raw subprocess text; `leadingArguments` are local-only and are not injected on the remote path.
197197
- `execution-target=REMOTE_AGENT_HTTP` makes the availability probe report `SKIPPED_REMOTE_MODE` (treated as startable).
198198

199+
### Windows npm launcher
200+
201+
For an npm-installed OpenCLI, configure the full path to `node.exe` and place the package's JavaScript entry point first in `leadingArguments`. Use the entry declared in the installed package's `bin.opencli` field. The SDK rejects `.cmd` and `.bat` executables because Windows batch shims parse arguments through a shell.
202+
203+
```java
204+
OpenCliProperties props = new OpenCliProperties();
205+
props.setExecutable("C:/Program Files/nodejs/node.exe");
206+
props.getLeadingArguments().add("C:/path/to/node_modules/@jackwener/opencli/dist/src/main.js");
207+
```
208+
199209
<a id="8-core-usage"></a>
200210
## 8. Core Usage
201211

‎README.zh-CN.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ cli.gemini().deepResearch("topic",
196196
- 远程模式下 `stdout` 为 Agent 返回的 `items` 的 JSON(已按 `format` 解析为行列表),与本地原始子进程文本可能不同;`leadingArguments` 等仅影响本地进程拼装,**远程路径不注入**。
197197
- `execution-target=REMOTE_AGENT_HTTP` 时可用性探测报告 `SKIPPED_REMOTE_MODE`(视为可启动)。
198198

199+
### Windows npm 启动入口
200+
201+
通过 npm 安装 OpenCLI 时,将 `executable` 配为 `node.exe` 的完整路径,并将包的 JavaScript 入口放在 `leadingArguments` 首位。入口以已安装包的 `bin.opencli` 字段为准。Windows 批处理通过 Shell 解析参数,SDK 会明确拒绝将 `.cmd` 或 `.bat` 用作可执行文件。
202+
203+
```java
204+
OpenCliProperties props = new OpenCliProperties();
205+
props.setExecutable("C:/Program Files/nodejs/node.exe");
206+
props.getLeadingArguments().add("C:/path/to/node_modules/@jackwener/opencli/dist/src/main.js");
207+
```
208+
199209
<a id="8-core-usage"></a>
200210
## 8. 核心用法
201211

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package io.github.easy4j.opencli.contract;
2+
3+
import com.fasterxml.jackson.databind.JsonNode;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import io.github.easy4j.opencli.OpenCliClient;
6+
import io.github.easy4j.opencli.OpenCliProperties;
7+
import io.github.easy4j.opencli.core.OpenCliResult;
8+
import java.io.File;
9+
import java.nio.file.Path;
10+
import java.nio.file.Paths;
11+
import java.util.Collections;
12+
import java.util.Objects;
13+
import org.junit.jupiter.api.Test;
14+
import org.junit.jupiter.api.condition.EnabledOnOs;
15+
import org.junit.jupiter.api.condition.OS;
16+
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertThrows;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
20+
21+
class OpenCliInstalledLauncherIT {
22+
23+
@Test
24+
void nativeNodeLaunchReachesInstalledOpenCli() throws Exception {
25+
OpenCliProperties properties = new OpenCliProperties();
26+
properties.setExecutable(requireFixture("OPENCLI_INSTALLED_NODE").toString());
27+
properties.setLeadingArguments(Collections.singletonList(requireFixture("OPENCLI_INSTALLED_ENTRY").toString()));
28+
properties.setCommandTimeoutMillis(30_000L);
29+
30+
try (OpenCliClient client = new OpenCliClient(properties)) {
31+
OpenCliResult result = client.meta().list("json");
32+
assertTrue(result.isSuccess());
33+
ObjectMapper mapper = new ObjectMapper();
34+
JsonNode actual = mapper.readTree(result.getStdout());
35+
JsonNode expected = mapper.readTree(requireFixture("OPENCLI_INSTALLED_REGISTRY").toFile());
36+
assertTrue(actual.isArray());
37+
assertTrue(actual.size() > 0);
38+
assertEquals(expected, actual);
39+
}
40+
}
41+
42+
@Test
43+
@EnabledOnOs(OS.WINDOWS)
44+
void installedNpmBatchShimIsRejectedExplicitly() {
45+
File shim = requireFixture("OPENCLI_INSTALLED_BATCH_SHIM").toFile();
46+
assertTrue(shim.isFile(), "npm must provide the Windows batch shim");
47+
OpenCliProperties properties = new OpenCliProperties();
48+
properties.setExecutable(shim.getAbsolutePath());
49+
try (OpenCliClient client = new OpenCliClient(properties)) {
50+
UnsupportedOperationException error = assertThrows(UnsupportedOperationException.class,
51+
() -> client.meta().list("json"));
52+
assertTrue(error.getMessage().contains("native node executable"));
53+
}
54+
}
55+
56+
private static Path requireFixture(String name) {
57+
return Paths.get(Objects.requireNonNull(System.getenv(name), name + " fixture is required"));
58+
}
59+
}

0 commit comments

Comments
 (0)