Skip to content

Commit c12df8d

Browse files
committed
Verify typed OpenCLI results through a real Browser Bridge
1 parent 3c9979e commit c12df8d

4 files changed

Lines changed: 98 additions & 1 deletion

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 真实 Browser Bridge 验收
2+
3+
以 `afeb522`、`3c9979ec`、`5c35d33` 为基线,使用 macOS arm64、Chrome for Testing 158.0.8127.18、Node 24.18.0、OpenCLI 1.8.8 与 [Browser Bridge 1.0.24 发布包](https://github.com/jackwener/OpenCLI/releases/tag/v1.8.8)。扩展 ZIP 的 SHA-256 为 `bad9163f32a66224404e302f52f35391672341d2bd0bf30c8bbaae3c6e6e246c`,与发布记录一致。
4+
5+
在临时浏览器 profile 加载扩展。为避开宿主机已有 daemon,仅在两份测试副本改用独立回环端口。OpenCLI 包的 `dist/src/constants.js` 与扩展的 `dist/background.js` 使用同一测试端口,扩展的 daemon host 显式设为 `127.0.0.1`。实际扩展通过 WebSocket 连上真实 daemon。浏览器使用无头模式和临时钥匙串,页面来自独立的本地 HTTP 服务。
6+
7+
| 入口 | 验收 |
8+
| --- | --- |
9+
| `openTyped` 与 `tabListTyped` | 导航到测试 URL,列表含相同的活动 page ID |
10+
| `snapshotTyped(DOM)` | 相同 URL,含测试页面按钮文本 |
11+
| `snapshotTyped(AX)` | 相同 URL,含测试页面的可访问性根节点和标题 |
12+
| `compareStateSourcesTyped` | DOM 和 AX 均报告成功 |
13+
14+
三条 JDK 线分别执行 `./mvnw -B -ntp -Dtest=OpenCliBrowserBridgeIT test`,各通过 1 项,零失败、零错误、零跳过。报告位于 `target/surefire-reports/TEST-io.github.easy4j.opencli.contract.OpenCliBrowserBridgeIT.xml`。
15+
16+
复跑时提供独立运行的测试 daemon、加载该扩展的临时浏览器,以及 `http://127.0.0.1:<port>/fixture.html`,页面标题为 `Bridge fixture` 且含 `Continue` 按钮。设置 `OPENCLI_INSTALLED_NODE` 为 Node 可执行文件,`OPENCLI_INSTALLED_ENTRY` 为测试 CLI 的 `dist/src/main.js`,`OPENCLI_BRIDGE_FIXTURE_URL` 为本地页面 URL,然后执行上述 Maven 命令。
17+
18+
本次 AX 返回页面根节点,未观察到按钮节点。真实账户、外部站点、其余 leaf 及 macOS GitHub runner 不属于本次证据范围。

‎openspec/changes/add-opencli-browser-result-models/tasks.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ Java 17 基线 `b1d83867` 的定向测试把含重复回车的分隔行误判为
5656
锁定版 CLI 的 console 过滤同时识别 `type` 和 `level`。Java 17 基线 `115b0955` 在仅含 `level` 的 [CLI 输出](evidence/2026-11-19-find-console-network-analyze.md) 上返回空级别,定向测试退出 1。补齐兼容读取后,调用方通过 `getType()` 取得原级别,元数据仍保留原始键。
5757

5858
以 `a0c66c9`、`115b0955`、`7992972` 为基线,在 Java 8、17、21 执行 `./mvnw -B -ntp clean verify`,分别通过 2224、2225、2224 项,全量零失败、零错误、零跳过。每条线均运行 5 项 `OpenCliBrowserEvidenceResultTest`,报告见 `target/surefire-reports`。
59+
60+
## OC-BROWSER-001/002/004 真实 Browser Bridge
61+
62+
`OpenCliBrowserBridgeIT` 使用 Chrome for Testing 158.0.8127.18、OpenCLI 1.8.8 和发布版 Browser Bridge 1.0.24,在 macOS arm64 的临时 Chrome profile 和本地测试页面上验证 open、tab list、DOM、AX 和双源对比。Java 8、17、21 各执行 1 项,零失败、零错误、零跳过。详见 [真实 Browser Bridge 验收及复跑条件](evidence/2026-11-19-real-browser-bridge.md)。

‎openspec/changes/add-opencli-context-and-diagnostics/tasks.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
- [x] 3.1 证明诊断不会执行login/refresh/restart/install/profile use等变更操作。
2121
- [x] 3.2 更新DEFERRED清单,移除未经证实的pipelineCLI/单进程承诺。
22-
- [ ] 3.3 三线验证上下文与诊断状态一致,并在指南中给出明确的只读使用示例。
22+
- [x] 3.3 三线验证上下文与诊断状态一致,并在指南中给出明确的只读使用示例。见三线只读验证。
2323

2424
## 证据交付模板(实施时填写)
2525

@@ -45,3 +45,7 @@ Java 17 基线 `2eb97e49` 的独立 JVM 定向测试在帮助探测暂停期间
4545
`diagnose()` 独立报告可执行文件、版本、历史帮助、Browser Bridge、认证、daemon 和远端传输。历史帮助有来源和观察时刻,配置或版本不匹配时保持 UNKNOWN。远端只读诊断跳过本机命令并保持传输未验证。三个本地运行时状态无法确认只读探测,保持 UNKNOWN。见 [只读边界与集成验证](evidence/2026-11-19-read-only-diagnostics.md)。
4646

4747
`OpenCliDiagnosticsTest` 初始缺少公开 API,编译失败。实现后回归记录只运行 `--version`,并验证显式发现的历史证据不提升为当前健康。已发布 CLI 的 opt-in `OpenCliReadOnlyDiagnosticsIT` 区分版本探测与执行启动钩子的显式帮助。报告位于 `target/surefire-reports`。
48+
49+
### 三线只读验证
50+
51+
以 `afeb522`、`3c9979ec`、`5c35d33` 为基线,使用 Java 8、17、21 执行 `./mvnw -B -ntp clean verify`,分别通过 2231、2232、2231 项,零失败、零错误、零跳过。每条线均执行 3 项 `OpenCliDiagnosticsTest`。配置 Node 24.18.0 与实际 OpenCLI 1.8.8 后,分别执行 `./mvnw -B -ntp -Dtest=OpenCliReadOnlyDiagnosticsIT test`,每条线均执行并通过 1 项。报告位于 `target/surefire-reports`。调用方式与各检查的证据类型见[只读诊断示例](evidence/2026-11-19-read-only-diagnostics.md)。
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package io.github.easy4j.opencli.contract;
2+
3+
import io.github.easy4j.opencli.OpenCliClient;
4+
import io.github.easy4j.opencli.OpenCliProperties;
5+
import io.github.easy4j.opencli.browser.OpenCliBrowserSession;
6+
import io.github.easy4j.opencli.browser.result.OpenCliBrowserOpenResult;
7+
import io.github.easy4j.opencli.browser.result.OpenCliBrowserResult;
8+
import io.github.easy4j.opencli.browser.result.OpenCliBrowserResult.Status;
9+
import io.github.easy4j.opencli.browser.result.OpenCliBrowserSnapshot;
10+
import io.github.easy4j.opencli.browser.result.OpenCliBrowserSourceComparison;
11+
import io.github.easy4j.opencli.browser.result.OpenCliBrowserTab;
12+
import io.github.easy4j.opencli.browser.support.OpenCliBrowserSnapshotSource;
13+
import java.net.URI;
14+
import java.util.Collections;
15+
import java.util.List;
16+
import java.util.Objects;
17+
import org.junit.jupiter.api.Test;
18+
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
23+
/** Opt-in verification against an externally provisioned disposable Browser Bridge. */
24+
class OpenCliBrowserBridgeIT {
25+
@Test
26+
void typedResultsFromAnIsolatedChromePage() {
27+
String fixtureUrl = requiredEnvironment("OPENCLI_BRIDGE_FIXTURE_URL");
28+
URI uri = URI.create(fixtureUrl);
29+
assertEquals("http", uri.getScheme());
30+
assertEquals("127.0.0.1", uri.getHost());
31+
32+
OpenCliProperties properties = new OpenCliProperties();
33+
properties.setExecutable(requiredEnvironment("OPENCLI_INSTALLED_NODE"));
34+
properties.setLeadingArguments(Collections.singletonList(requiredEnvironment("OPENCLI_INSTALLED_ENTRY")));
35+
properties.setCommandTimeoutMillis(30_000L);
36+
try (OpenCliClient client = new OpenCliClient(properties)) {
37+
OpenCliBrowserSession session = new OpenCliBrowserSession(client.getExecutor(), "sdk-bridge-fixture", "background");
38+
OpenCliBrowserOpenResult opened = parsed(session.openTyped(fixtureUrl, null));
39+
assertEquals(fixtureUrl, opened.getUrl());
40+
assertNotNull(opened.getPageId());
41+
42+
List<OpenCliBrowserTab> tabs = parsed(session.tabListTyped());
43+
assertTrue(tabs.stream().anyMatch(tab -> opened.getPageId().equals(tab.getPageId())
44+
&& fixtureUrl.equals(tab.getUrl()) && tab.isActive()));
45+
46+
OpenCliBrowserSnapshot dom = parsed(session.snapshotTyped(null, OpenCliBrowserSnapshotSource.DOM));
47+
assertEquals(fixtureUrl, dom.getUrl());
48+
assertTrue(dom.getText().contains("Continue"));
49+
50+
OpenCliBrowserSnapshot ax = parsed(session.snapshotTyped(null, OpenCliBrowserSnapshotSource.AX));
51+
assertEquals(fixtureUrl, ax.getUrl());
52+
assertTrue(ax.getText().contains("RootWebArea"));
53+
assertTrue(ax.getText().contains("Bridge fixture"));
54+
55+
OpenCliBrowserSourceComparison comparison = parsed(session.compareStateSourcesTyped(null));
56+
assertEquals(fixtureUrl, comparison.getUrl());
57+
assertTrue(comparison.getDom().isOk());
58+
assertTrue(comparison.getAx().isOk());
59+
}
60+
}
61+
62+
private static String requiredEnvironment(String name) {
63+
return Objects.requireNonNull(System.getenv(name), name + " fixture is required");
64+
}
65+
66+
private static <T> T parsed(OpenCliBrowserResult<T> result) {
67+
assertEquals(Status.PARSED, result.getStatus());
68+
assertNotNull(result.getValue());
69+
return result.getValue();
70+
}
71+
}

0 commit comments

Comments
 (0)