Skip to content

Commit 004c328

Browse files
committed
Exercise OpenCLI browser query and capture through the real bridge
1 parent a35219a commit 004c328

3 files changed

Lines changed: 78 additions & 18 deletions

File tree

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
11
# 真实 Browser Bridge 验收
22

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`,与发布记录一致。
3+
使用 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`,与发布记录一致。
44

55
在临时浏览器 profile 加载扩展。为避开宿主机已有 daemon,仅在两份测试副本改用独立回环端口。OpenCLI 包的 `dist/src/constants.js` 与扩展的 `dist/background.js` 使用同一测试端口,扩展的 daemon host 显式设为 `127.0.0.1`。实际扩展通过 WebSocket 连上真实 daemon。浏览器使用无头模式和临时钥匙串,页面来自独立的本地 HTTP 服务。
66

77
| 入口 | 验收 |
88
| --- | --- |
9-
| `openTyped` 与 `tabListTyped` | 导航到测试 URL,列表含相同的活动 page ID |
9+
| `openTyped` 与 `tabListTyped` | 导航到测试 URL,列表含相同的 page ID,活动状态与原始字段一致 |
1010
| `snapshotTyped(DOM)` | 相同 URL,含测试页面按钮文本 |
1111
| `snapshotTyped(AX)` | 相同 URL,含测试页面的可访问性根节点和标题 |
1212
| `compareStateSourcesTyped` | DOM 和 AX 均报告成功 |
13+
| `findTyped` | CSS `#go` 返回唯一按钮、原始文本和 ref |
14+
| `consoleTyped` | 返回该 session 的有效空集合 |
15+
| `networkTyped` | 捕获本地 `GET /api/items` 和 HTTP 200 |
16+
| `analyzeTyped` | 报告真实页面 URL 与标题 |
1317

14-
三条 JDK 线分别执行 `./mvnw -B -ntp -Dtest=OpenCliBrowserBridgeIT test`,各通过 1 项,零失败、零错误、零跳过。报告位于 `target/surefire-reports/TEST-io.github.easy4j.opencli.contract.OpenCliBrowserBridgeIT.xml`。
18+
以 `e7ca1c0`、`a35219a5`、`15126bf` 为基线,三条 JDK 线分别执行 `./mvnw -B -ntp -Dtest=OpenCliBrowserBridgeIT test`,各通过 2 项,零失败、零错误、零跳过。报告位于 `target/surefire-reports/TEST-io.github.easy4j.opencli.contract.OpenCliBrowserBridgeIT.xml`。
1519

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 命令。
20+
复跑时提供独立运行的测试 daemon、加载该扩展的临时浏览器,以及 `http://127.0.0.1:<port>/fixture.html`,页面使用下方 HTML,服务器为 `/api/items` 返回 `application/json` 和 `{"items":[{"id":17}]}`。设置 `OPENCLI_INSTALLED_NODE` 为 Node 可执行文件,`OPENCLI_INSTALLED_ENTRY` 为测试 CLI 的 `dist/src/main.js`,`OPENCLI_BRIDGE_FIXTURE_URL` 为本地页面 URL,然后执行上述 Maven 命令。
1721

18-
本次 AX 返回页面根节点,未观察到按钮节点。真实账户、外部站点、其余 leaf 及 macOS GitHub runner 不属于本次证据范围。
22+
```html
23+
<!doctype html>
24+
<title>Bridge fixture</title>
25+
<main><button id="go">Continue</button></main>
26+
<script>
27+
const capture = setInterval(() => {
28+
console.warn('Bridge fixture warning');
29+
fetch('/api/items');
30+
}, 250);
31+
setTimeout(() => clearInterval(capture), 45000);
32+
</script>
33+
```
34+
35+
本次无头 AX 返回页面根节点,未观察到按钮节点。Chrome 日志收到了测试 warning,OpenCLI 1.8.8 的真实扩展路径仍返回空控制台列表。非空控制台记录由隔离页面桩测试覆盖。真实账户、外部站点及托管 macOS runner 未参与。

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ Java 17 基线 `b1d83867` 的定向测试把含重复回车的分隔行误判为
5959

6060
## OC-BROWSER-001/002/004 真实 Browser Bridge
6161

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)。
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、双源对比、find、console、network 和 analyze。Java 8、17、21 各执行 2 项,零失败、零错误、零跳过。详见 [真实 Browser Bridge 验收及复跑条件](evidence/2026-11-19-real-browser-bridge.md)。

‎src/test/java/io/github/easy4j/opencli/contract/OpenCliBrowserBridgeIT.java‎

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
import io.github.easy4j.opencli.OpenCliClient;
44
import io.github.easy4j.opencli.OpenCliProperties;
55
import io.github.easy4j.opencli.browser.OpenCliBrowserSession;
6+
import io.github.easy4j.opencli.browser.result.OpenCliBrowserAnalysisResult;
7+
import io.github.easy4j.opencli.browser.result.OpenCliBrowserConsoleResult;
8+
import io.github.easy4j.opencli.browser.result.OpenCliBrowserFindResult;
9+
import io.github.easy4j.opencli.browser.result.OpenCliBrowserNetworkResult;
610
import io.github.easy4j.opencli.browser.result.OpenCliBrowserOpenResult;
711
import io.github.easy4j.opencli.browser.result.OpenCliBrowserResult;
812
import io.github.easy4j.opencli.browser.result.OpenCliBrowserResult.Status;
913
import io.github.easy4j.opencli.browser.result.OpenCliBrowserSnapshot;
1014
import io.github.easy4j.opencli.browser.result.OpenCliBrowserSourceComparison;
1115
import io.github.easy4j.opencli.browser.result.OpenCliBrowserTab;
16+
import io.github.easy4j.opencli.browser.support.OpenCliBrowserFindOptions;
1217
import io.github.easy4j.opencli.browser.support.OpenCliBrowserSnapshotSource;
1318
import java.net.URI;
1419
import java.util.Collections;
@@ -24,24 +29,18 @@
2429
class OpenCliBrowserBridgeIT {
2530
@Test
2631
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)) {
32+
String fixtureUrl = fixtureUrl();
33+
try (OpenCliClient client = new OpenCliClient(properties())) {
3734
OpenCliBrowserSession session = new OpenCliBrowserSession(client.getExecutor(), "sdk-bridge-fixture", "background");
3835
OpenCliBrowserOpenResult opened = parsed(session.openTyped(fixtureUrl, null));
3936
assertEquals(fixtureUrl, opened.getUrl());
4037
assertNotNull(opened.getPageId());
4138

4239
List<OpenCliBrowserTab> tabs = parsed(session.tabListTyped());
43-
assertTrue(tabs.stream().anyMatch(tab -> opened.getPageId().equals(tab.getPageId())
44-
&& fixtureUrl.equals(tab.getUrl()) && tab.isActive()));
40+
OpenCliBrowserTab openedTab = tabs.stream()
41+
.filter(tab -> opened.getPageId().equals(tab.getPageId()) && fixtureUrl.equals(tab.getUrl()))
42+
.findFirst().orElseThrow(() -> new AssertionError("The opened page must appear in the tab list"));
43+
assertEquals(openedTab.getMetadata().get("active").asBoolean(), openedTab.isActive());
4544

4645
OpenCliBrowserSnapshot dom = parsed(session.snapshotTyped(null, OpenCliBrowserSnapshotSource.DOM));
4746
assertEquals(fixtureUrl, dom.getUrl());
@@ -59,6 +58,50 @@ void typedResultsFromAnIsolatedChromePage() {
5958
}
6059
}
6160

61+
@Test
62+
void queryAndCaptureUseTheRealBridgeResponses() {
63+
String fixtureUrl = fixtureUrl();
64+
try (OpenCliClient client = new OpenCliClient(properties())) {
65+
OpenCliBrowserSession session = new OpenCliBrowserSession(client.getExecutor(), "sdk-capture-fixture", "background");
66+
parsed(session.openTyped(fixtureUrl, null));
67+
68+
OpenCliBrowserFindOptions options = OpenCliBrowserFindOptions.builder().css("#go").build();
69+
OpenCliBrowserFindResult found = parsed(session.findTyped(null, null, options));
70+
assertEquals(1, found.getMatchesN());
71+
assertEquals("Continue", found.getEntries().get(0).getText());
72+
assertNotNull(found.getEntries().get(0).getRef());
73+
74+
OpenCliBrowserConsoleResult console = parsed(session.consoleTyped(null, null));
75+
assertEquals("sdk-capture-fixture", console.getSession());
76+
assertTrue(console.getMessages().isEmpty());
77+
78+
String endpoint = URI.create(fixtureUrl).resolve("/api/items").toString();
79+
OpenCliBrowserNetworkResult network = parsed(session.networkTyped(null, null));
80+
assertTrue(network.getEntries().stream().anyMatch(entry ->
81+
endpoint.equals(entry.getUrl()) && "GET".equals(entry.getMethod()) && entry.getStatus() == 200));
82+
83+
OpenCliBrowserAnalysisResult analysis = parsed(session.analyzeTyped(fixtureUrl, null));
84+
assertEquals(fixtureUrl, analysis.getFinalUrl());
85+
assertEquals("Bridge fixture", analysis.getTitle());
86+
}
87+
}
88+
89+
private static OpenCliProperties properties() {
90+
OpenCliProperties properties = new OpenCliProperties();
91+
properties.setExecutable(requiredEnvironment("OPENCLI_INSTALLED_NODE"));
92+
properties.setLeadingArguments(Collections.singletonList(requiredEnvironment("OPENCLI_INSTALLED_ENTRY")));
93+
properties.setCommandTimeoutMillis(30_000L);
94+
return properties;
95+
}
96+
97+
private static String fixtureUrl() {
98+
String url = requiredEnvironment("OPENCLI_BRIDGE_FIXTURE_URL");
99+
URI uri = URI.create(url);
100+
assertEquals("http", uri.getScheme());
101+
assertEquals("127.0.0.1", uri.getHost());
102+
return url;
103+
}
104+
62105
private static String requiredEnvironment(String name) {
63106
return Objects.requireNonNull(System.getenv(name), name + " fixture is required");
64107
}

0 commit comments

Comments
 (0)