Skip to content

Commit 0bcb405

Browse files
committed
test: verify OpenCLI typed Browser operations retain bound tabs
1 parent 97aee9a commit 0bcb405

3 files changed

Lines changed: 54 additions & 10 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Browser 领域结果与严格解析
22

3-
> Proposal specification. Status: DRAFT / NOT_IMPLEMENTED.
3+
> The declared typed scope is verified on the feature branches. PR review and merge are pending.
44
55
## ADDED Requirements
66

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
# C07 Tasks · Browser 领域结果与严格解析
22

3-
> 全部为待执行实现任务。文档/格式检查通过不允许提前勾选。
3+
> 已核对声明支持的叶子及各自的实现和证据。PR 评审与合并仍待完成。
44
55
关联规范:[spec](specs/opencli-browser-result-models/spec.md)。
66

77
## 1. 输出证据
88

9-
- [ ] 1.1 固定第一批leaf的真实输出fixtures、版本/平台/hash;无样本者在支持表标pending。
10-
- [ ] 1.2 先补 malformed/truncated/empty/unknownfields/largeID/AX 的失败测试。
9+
- [x] 1.1 固定第一批leaf的真实输出fixtures、版本/平台/hash;无样本者在支持表标pending。
10+
- [x] 1.2 先补 malformed/truncated/empty/unknownfields/largeID/AX 的失败测试。
1111

1212
## 2. 模型与decoder
1313

14-
- [ ] 2.1 实现Java8公共模型与各Jackson分支兼容decoder,避免以double中转ID。
15-
- [ ] 2.2 保留raw/JsonNode与旧close返回签名,新增strict访问而非破坏旧API。
16-
- [ ] 2.3 建立每leaf字段约束和parse-state,未验证shape不自动转成空成功。
14+
- [x] 2.1 实现Java8公共模型与各Jackson分支兼容decoder,避免以double中转ID。
15+
- [x] 2.2 保留raw/JsonNode与旧close返回签名,新增strict访问而非破坏旧API。
16+
- [x] 2.3 建立每leaf字段约束和parse-state,未验证shape不自动转成空成功。
1717

1818
## 3. 集成验收
1919

20-
- [ ] 3.1 与C03错误/trace、C02截断、C08上下文保持一致,禁止自动读取sitemap路径。
21-
- [ ] 3.2 在三线共享fixtures上验证字段与失败语义等价。
22-
- [ ] 3.3 生成实际typed支持表,区分已验证和仅raw支持,补迁移示例。
20+
- [x] 3.1 与C03错误/trace、C02截断、C08上下文保持一致,禁止自动读取sitemap路径。
21+
- [x] 3.2 在三线共享fixtures上验证字段与失败语义等价。
22+
- [x] 3.3 生成实际typed支持表,区分已验证和仅raw支持,补迁移示例。
2323

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

@@ -36,3 +36,15 @@
3636
## OC-BROWSER-001/002/003/005 find、console、network 与 analyze
3737

3838
`OpenCliBrowserEvidenceResultTest` 首先因缺少模型和门面而无法编译。实现后验收有限的 find 条目、整数 ref 保真、采集 count 与数组一致性、分析扩展信息和原有执行失败。流式采集及网络详情在 typed 入口启动前拒绝,保留 raw 方法。见 [输出证据、支持表和迁移方式](evidence/2026-11-19-find-console-network-analyze.md)。
39+
40+
## C07 实施核对与绑定标签页
41+
42+
- OC-BROWSER-001 / OC-BROWSER-002。版本锁定的值、状态与证据表覆盖已声明的 typed 入口。合法空数组、畸形结果、截断和进程失败各有独立状态。
43+
- OC-BROWSER-003。测试保留大于 IEEE 754 安全整数范围的 ID、前导零及未知字段。
44+
- OC-BROWSER-004。真实 Browser Bridge 运行 DOM、AX 和双源对比。参数回归检查原有 source 和 compare-sources,未知 raw source 原样传入。
45+
- OC-BROWSER-005。分析提示、sitemap 和 trace 保留为数据。相关 decoder 不读取文件或执行提示。
46+
- OC-BROWSER-006。已有 close 调用继续返回原始结果。新增真实扩展测试绑定隔离浏览器的活动标签页,验证 typed 成功、请求不存在的目标页失败,以及客户端关闭后,原标签页仍能通过同一 ID 列出。最后显式解绑。
47+
48+
以回环 HTTP 服务的 `/bound-fixture.html` 启动临时 Chrome profile,让它成为活动标签页。该 URL 可以返回与普通 fixture 相同的 HTML。
49+
50+
本分支以 `97aee9a451facfdc998ef039a59f7fa4f4e27476` 为基线,使用 JDK 21 执行 `./mvnw -B -ntp -o -Dtest=OpenCliBrowserBridgeIT,OpenCliBrowserResultTest,OpenCliBrowserEvidenceResultTest,OpenCliErrorEnvelopeTest test`。退出码为 0。运行 24 项,包含 3 项真实 Browser Bridge 用例,零失败、零错误、零跳过。报告位于 `target/surefire-reports`。外部认证网站验收仍保持独立。

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import io.github.easy4j.opencli.browser.result.OpenCliBrowserSourceComparison;
1515
import io.github.easy4j.opencli.browser.result.OpenCliBrowserTab;
1616
import io.github.easy4j.opencli.browser.support.OpenCliBrowserFindOptions;
17+
import io.github.easy4j.opencli.browser.support.OpenCliBrowserTabOptions;
18+
import io.github.easy4j.opencli.exception.OpenCliNonZeroExitException;
1719
import io.github.easy4j.opencli.browser.support.OpenCliBrowserSnapshotSource;
1820
import java.net.URI;
1921
import java.util.Collections;
@@ -24,6 +26,7 @@
2426
import static org.junit.jupiter.api.Assertions.assertEquals;
2527
import static org.junit.jupiter.api.Assertions.assertNotNull;
2628
import static org.junit.jupiter.api.Assertions.assertTrue;
29+
import static org.junit.jupiter.api.Assertions.assertThrows;
2730

2831
/** Opt-in verification against an externally provisioned disposable Browser Bridge. */
2932
class OpenCliBrowserBridgeIT {
@@ -86,6 +89,35 @@ void queryAndCaptureUseTheRealBridgeResponses() {
8689
}
8790
}
8891

92+
@Test
93+
void boundTabSurvivesTypedSuccessFailureAndClientShutdown() {
94+
String url = URI.create(fixtureUrl()).resolve("/bound-fixture.html").toString();
95+
String pageId;
96+
try (OpenCliClient client = new OpenCliClient(properties())) {
97+
OpenCliBrowserSession session = new OpenCliBrowserSession(client.getExecutor(), "sdk-bound-fixture", null);
98+
session.bind();
99+
pageId = boundPage(session, url).getPageId();
100+
assertEquals(url, parsed(session.snapshotTyped(null, OpenCliBrowserSnapshotSource.DOM)).getUrl());
101+
102+
OpenCliBrowserTabOptions missing = OpenCliBrowserTabOptions.builder().tab("missing-fixture-page").build();
103+
OpenCliNonZeroExitException failure = assertThrows(OpenCliNonZeroExitException.class,
104+
() -> session.snapshotTyped(missing, OpenCliBrowserSnapshotSource.DOM));
105+
assertNotNull(failure.getPartialResult());
106+
assertEquals(pageId, boundPage(session, url).getPageId());
107+
}
108+
try (OpenCliClient client = new OpenCliClient(properties())) {
109+
OpenCliBrowserSession session = new OpenCliBrowserSession(client.getExecutor(), "sdk-bound-fixture", null);
110+
assertEquals(pageId, boundPage(session, url).getPageId());
111+
session.unbind();
112+
}
113+
}
114+
115+
private static OpenCliBrowserTab boundPage(OpenCliBrowserSession session, String url) {
116+
return parsed(session.tabListTyped()).stream()
117+
.filter(tab -> url.equals(tab.getUrl())).findFirst()
118+
.orElseThrow(() -> new AssertionError("The original bound tab must remain open"));
119+
}
120+
89121
private static OpenCliProperties properties() {
90122
OpenCliProperties properties = new OpenCliProperties();
91123
properties.setExecutable(requiredEnvironment("OPENCLI_INSTALLED_NODE"));

0 commit comments

Comments
 (0)