Skip to content

Commit a774082

Browse files
committed
Verify legacy collect against a real loopback OpenCLI Agent
1 parent 8da04d3 commit a774082

3 files changed

Lines changed: 111 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# OpenCLI 1.8.8 与 opencli-admin Agent 回环联调
2+
3+
使用 [partme-ai/opencli-admin 的锁定源码](https://github.com/partme-ai/opencli-admin/blob/f3879eb2e30f5dedb4df249f0b15a7d007bbfe9e/backend/agent_server.py)。`backend/agent_server.py` 的 SHA-256 为 `a9a53e003234b3615d2097e96bbdceea6642febf89b29f32ae321d8b7fff3530`。使用 OpenCLI 1.8.8、Node 24.18.0、Python 3.14.8、FastAPI 0.165.0、Pydantic 2.14.3、Uvicorn 0.54.0 和 PyYAML 6.0.3。Agent 仅监听回环地址,禁用中心注册。OpenCLI 使用隔离用户、配置和缓存目录。
4+
5+
| 请求 | 观察结果 |
6+
| --- | --- |
7+
| 默认 Agent 桥接端口 19825,查询 npm search 帮助 | OpenCLI 1.8.8 拒绝该端口并退出 78,Agent 返回 HTTP 200 和业务失败。三个 Java 客户端均观察到业务失败。 |
8+
| Agent 桥接端口 61735,查询 npm search 帮助 | HTTP 200,Agent 返回实际 OpenCLI 的结构化帮助,SDK 标记业务成功。 |
9+
| 同一端口,调用 npm search 时省略必填位置参数 | OpenCLI 退出 1,Agent 返回 HTTP 200 和业务失败。SDK 保留 HTTP 200,将兼容退出值标明为合成值,并保留业务错误。 |
10+
| 同一端口,再次查询帮助并显式启用原文捕获 | SDK 保留原始 Agent 响应。关闭捕获的成功及失败请求均验证原文为空。 |
11+
12+
带 61735 配置的一轮在 Java 8 `8da04d3`、Java 17 `4fb8c73` 和 Java 21 `df3b58c` 各通过三项。Agent 日志共记录六次成功及三次缺参失败。验证范围为明文回环 legacy 收集协议、CLI 帮助及参数校验。生产 TLS 和认证由独立部署环境验收。此次联调没有调用 npm 注册表、浏览器或用户账户。
13+
14+
## 复跑
15+
16+
从上述提交提取 `backend/agent_server.py` 到临时目录。从已安装的 OpenCLI 1.8.8 包取得 `dist/src/main.js` 的绝对路径,作为 `OPENCLI_ENTRY`。在临时目录保存 `isolate.mjs`,将 `os.homedir()` 指向 `OPENCLI_FIXTURE_HOME`。
17+
18+
```javascript
19+
import os from 'node:os';
20+
import { syncBuiltinESMExports } from 'node:module';
21+
os.homedir = () => process.env.OPENCLI_FIXTURE_HOME;
22+
syncBuiltinESMExports();
23+
```
24+
25+
在同一目录保存可执行文件 `opencli-isolated`。使用临时目录及回环端口启动 Agent。
26+
27+
```sh
28+
#!/bin/sh
29+
exec node --import "$OPENCLI_FIXTURE_HOME/isolate.mjs" "$OPENCLI_ENTRY" "$@"
30+
```
31+
32+
```sh
33+
chmod 700 opencli-isolated
34+
export OPENCLI_FIXTURE_HOME="$PWD" OPENCLI_CONFIG_DIR="$PWD/config" OPENCLI_CACHE_DIR="$PWD/cache"
35+
export OPENCLI_BIN="$PWD/opencli-isolated" CI=1 NO_COLOR=1
36+
export AGENT_REGISTER=off CENTRAL_API_URL='' AGENT_DEPLOY_TYPE=shell OPENCLI_DAEMON_PORT=61735
37+
uv run --no-project --with fastapi==0.165.0 --with pydantic==2.14.3 \
38+
--with uvicorn==0.54.0 --with pyyaml==6.0.3 \
39+
python -m uvicorn agent_server:app --host 127.0.0.1 --port 19823
40+
```
41+
42+
在 SDK 功能分支以对应 JDK 执行 `OpenCliRemoteAgentHttpClientTest`,从生成的 Surefire XML 读取 `java.class.path`。用该 classpath 编译 [OpenCliAdminLoopbackProbe](fixtures/OpenCliAdminLoopbackProbe.java),再用同一 classpath 加上探针输出目录运行,唯一参数为 `http://127.0.0.1:19823`。复现旧端口问题时,在无其他请求的临时 Agent 上改用 19825 并执行同一探针,首个成功断言会得到业务失败,Agent 日志会显示子进程退出 78。
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import io.github.easy4j.opencli.OpenCliExecutionTarget;
2+
import io.github.easy4j.opencli.OpenCliProperties;
3+
import io.github.easy4j.opencli.core.OpenCliExecutor;
4+
import io.github.easy4j.opencli.core.OpenCliRemoteExecutionDetails;
5+
import io.github.easy4j.opencli.core.OpenCliResult;
6+
import io.github.easy4j.opencli.exception.OpenCliNonZeroExitException;
7+
import java.net.URI;
8+
import java.util.Objects;
9+
10+
public final class OpenCliAdminLoopbackProbe {
11+
12+
public static void main(String[] args) {
13+
URI endpoint = URI.create(args[0]);
14+
require("127.0.0.1".equals(endpoint.getHost()), "test Agent must be on IPv4 loopback");
15+
try (OpenCliExecutor executor = executor(endpoint, false)) {
16+
OpenCliResult help = executor.invoke("npm", "search", "fixture", "--help=true", "-f", "json");
17+
verify(help, true);
18+
require(help.getStdout().contains("opencli npm search"), "structured CLI help is missing");
19+
require(Objects.isNull(help.getRemoteRawHttpBody()), "raw capture must be off by default");
20+
21+
try {
22+
executor.invoke("npm", "search", "-f", "json");
23+
throw new AssertionError("missing CLI query unexpectedly succeeded");
24+
} catch (OpenCliNonZeroExitException failure) {
25+
OpenCliResult result = failure.getPartialResult();
26+
verify(result, false);
27+
require(Objects.isNull(result.getRemoteRawHttpBody()), "failed response was captured by default");
28+
require(result.getStderr().contains("opencli exit"), "the Agent's business error is missing");
29+
}
30+
}
31+
try (OpenCliExecutor executor = executor(endpoint, true)) {
32+
OpenCliResult help = executor.invoke("npm", "search", "fixture", "--help=true", "-f", "json");
33+
verify(help, true);
34+
require(Objects.nonNull(help.getRemoteRawHttpBody()) && help.getRemoteRawHttpBody().contains("opencli npm search"),
35+
"explicit capture did not retain the original Agent body");
36+
}
37+
System.out.println("PASS: real Agent help, missing-argument failure, and opt-in raw HTTP capture");
38+
}
39+
40+
private static OpenCliExecutor executor(URI endpoint, boolean capture) {
41+
OpenCliProperties properties = new OpenCliProperties();
42+
properties.setExecutionTarget(OpenCliExecutionTarget.REMOTE_AGENT_HTTP);
43+
properties.setRemoteAgentBaseUrl(endpoint.toString());
44+
properties.setRemoteCollectMode("bridge");
45+
properties.setRemoteCaptureRawHttpResponse(capture);
46+
return new OpenCliExecutor(properties);
47+
}
48+
49+
private static void verify(OpenCliResult result, boolean success) {
50+
require(result.isSuccess() == success, "wrong business status");
51+
require(Integer.valueOf(success ? 0 : 1).equals(result.getExitCode()), "wrong mapped exit value");
52+
OpenCliRemoteExecutionDetails details = result.getRemoteExecutionDetails();
53+
require(details.getObservedHttpStatus().orElse(-1) == 200, "HTTP status was lost");
54+
require(details.getOutcome() == (success ? OpenCliRemoteExecutionDetails.Outcome.SUCCESS
55+
: OpenCliRemoteExecutionDetails.Outcome.COMMAND_FAILURE), "wrong outcome classification");
56+
require(details.getExitCodeSource() == OpenCliRemoteExecutionDetails.ExitCodeSource.SYNTHETIC_COMPATIBILITY,
57+
"legacy mapping must be marked synthetic");
58+
require(!details.getObservedRemoteExitCode().isPresent(), "legacy response contains no CLI exit field");
59+
require(Objects.isNull(result.getExecutionDetails()), "legacy response contains no local process evidence");
60+
}
61+
62+
private static void require(boolean condition, String message) {
63+
if (!condition) {
64+
throw new AssertionError(message);
65+
}
66+
}
67+
}

‎openspec/changes/harden-opencli-remote-collect/tasks.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,5 @@ argv 入口继续限制为 SDK 已登记适配器和可保真转换的参数。
8484
三线 macOS、Windows 平台工作流同时在 Maven 选择器和协议层报告中登记 OpenCliRemoteAgentHttpClientTest。将该套件从现有报告副本移除后,协议层和整体结果均为 FAIL,即使 Maven 退出码为 0。
8585

8686
本地 macOS 按平台步骤分别运行 Java 8、17、21,三线各执行 202 项,协议层各记录 93 项,其中 HTTP 套件 58 项。两个非法响应字符集用例均实际执行,覆盖收到 HTTP 200 和 503 时保留状态。三线零失败、零错误、零跳过。GitHub 平台结果按对应功能提交核验。
87+
88+
实际 Agent 与 OpenCLI 1.8.8 的三线回环验收及默认端口兼容性差异见 [联调记录](evidence/2026-11-19-live-agent.md)。

0 commit comments

Comments
 (0)