Skip to content

Commit 7aaac86

Browse files
committed
Preserve the OpenCLI console level field in typed results
1 parent 115b095 commit 7aaac86

7 files changed

Lines changed: 40 additions & 4 deletions

File tree

‎openspec/changes/add-opencli-browser-result-models/evidence/2026-11-19-find-console-network-analyze.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
| state | `snapshotTyped(tab, source)` | URL 头和正文 | DOM、AX |
1010
| state --compare-sources | `compareStateSourcesTyped(tab)` | 两侧指标对象 | 成功、AX 单侧失败 |
1111
| find | `findTyped(locator, tab, options)` | 总匹配数和条目 | CSS、限量及精确 ref |
12-
| console | `consoleTyped(tab, options)` | 单次采集对象 | 记录与合法空数组 |
12+
| console | `consoleTyped(tab, options)` | 单次采集对象 | `type`、`level` 和合法空数组 |
1313
| network | `networkTyped(options, tab)` | 单次采集对象 | 请求条目、形状和扩展元数据 |
1414
| analyze | `analyzeTyped(url, tab)` | 报告对象 | URL、标题、分类与扩展报告 |
1515
| console/network --follow、network --detail、其余叶子 | raw 会话 API | 流或其它形状 | 保持 raw |
1616

1717
原始输出、SHA-256 与采集 preload 保存在 [样本目录](../../../../src/test/resources/opencli-contracts/v1/browser-output-1.8.8/)。沿用 [启动方式](2026-11-19-open-and-tab-list.md) 并设置 `OPENCLI_FIXTURE_FIXED_CLOCK=1`。调用 `browser fixture find --css '#fixture' --limit 1`、`browser fixture console`、`browser fixture network` 和 `browser fixture analyze http://127.0.0.1:18765/basic.html`。实际浏览器、网络请求和账户状态未参与本次验收。
1818

1919
typed 捕获返回原始执行结果。对现有异常中的 partial result,可按 leaf 显式调用 `OpenCliBrowserDecoder`。分析提示、网络详情提示与 sitemap 路径保留为数据,由调用者明确决定后续动作。流式和详情参数可继续交给现有 raw 方法。
20+
21+
`console-level.json` 由同一发布包运行 `browser fixture console --level warning` 采集。通过 `OPENCLI_FIXTURE_CONSOLE_LEVEL=1` 让隔离页面桩仅报告 `level`,CLI 仍返回该条记录。类型化结果优先读取 `type`,缺少时使用 `level`。原始元数据保留 CLI 输出字段。

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ Java 17 基线 `b1d83867` 的定向测试把含重复回车的分隔行误判为
5050
## OC-BROWSER-001/002/003/005 find、console、network 与 analyze
5151

5252
`OpenCliBrowserEvidenceResultTest` 首先因缺少模型和门面而无法编译。实现后验收有限的 find 条目、整数 ref 保真、采集 count 与数组一致性、分析扩展信息和原有执行失败。流式采集及网络详情在 typed 入口启动前拒绝,保留 raw 方法。见 [输出证据、支持表和迁移方式](evidence/2026-11-19-find-console-network-analyze.md)。
53+
54+
### OC-BROWSER-003 console 级别回归
55+
56+
锁定版 CLI 的 console 过滤同时识别 `type` 和 `level`。Java 17 基线 `115b0955` 在仅含 `level` 的 [CLI 输出](evidence/2026-11-19-find-console-network-analyze.md) 上返回空级别,定向测试退出 1。补齐兼容读取后,调用方通过 `getType()` 取得原级别,元数据仍保留原始键。
57+
58+
以 `a0c66c9`、`115b0955`、`7992972` 为基线,在 Java 8、17、21 执行 `./mvnw -B -ntp clean verify`,分别通过 2224、2225、2224 项,全量零失败、零错误、零跳过。每条线均运行 5 项 `OpenCliBrowserEvidenceResultTest`,报告见 `target/surefire-reports`。

‎src/main/java/io/github/easy4j/opencli/browser/result/OpenCliBrowserDecoder.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,12 @@ private static OpenCliBrowserFindResult readFind(JsonNode json) {
207207
private static OpenCliBrowserConsoleResult readConsole(JsonNode json) {
208208
JsonNode reported = json.path("messages");
209209
validateCount(json, reported);
210-
List<OpenCliBrowserConsoleResult.Message> messages = entries(reported, item ->
211-
new OpenCliBrowserConsoleResult.Message(optionalText(item.path("type")), optionalText(item.path("text")),
212-
text(item.path("timestamp")), item));
210+
List<OpenCliBrowserConsoleResult.Message> messages = entries(reported, item -> {
211+
String type = optionalText(item.path("type"));
212+
String level = Objects.nonNull(type) ? type : optionalText(item.path("level"));
213+
return new OpenCliBrowserConsoleResult.Message(level, optionalText(item.path("text")),
214+
text(item.path("timestamp")), item);
215+
});
213216
return new OpenCliBrowserConsoleResult(text(json.path("session")), text(json.path("captured_at")), messages, json);
214217
}
215218

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ void decodesConsoleAndNetworkCaptureEnvelopes() {
5555
assertEquals(Status.EXECUTION_FAILED, OpenCliBrowserDecoder.network(failed).getStatus());
5656
}
5757

58+
@Test
59+
void readsTheConsoleLevelWhenTheTypeFieldIsAbsent() {
60+
OpenCliBrowserConsoleResult console = OpenCliBrowserDecoder.console(raw("console-level")).getValue();
61+
OpenCliBrowserConsoleResult.Message message = console.getMessages().get(0);
62+
assertEquals("warning", message.getType());
63+
assertEquals("warning", message.getMetadata().get("level").asText());
64+
assertFalse(message.getMetadata().has("type"));
65+
}
66+
5867
@Test
5968
void retainsAnalysisMetadataWithoutFollowingAdvice() {
6069
OpenCliBrowserAnalysisResult analysis = OpenCliBrowserDecoder.analyze(raw("analyze")).getValue();

‎src/test/resources/opencli-contracts/v1/browser-output-1.8.8/SHA256SUMS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ e6dc6071a233af759b96ed8948bf692be4ceb2f79edd71db2fc16b99b20ec429 state-compare.
99
c81e67d4ed3c58ec33d80f9d0c2feceee33a3588792c5f51e4a74a6069fed8b2 tab-list.json
1010
a3ba63353d2f970d5edbcf8eb0d1ede2688605ff5a97013cbfd70a9e54f344fd state-ax.stdout
1111
592bd1b129c0687569d865cdc3d1d28152628267ef2a6732d2afa23f58c1f035 state-dom.stdout
12+
fa91f0245e5c8060c94ee75683cec751ee57d6b2d21a40ac796695a5b7f2b3f2 console-level.json

‎src/test/resources/opencli-contracts/v1/browser-output-1.8.8/capture.mjs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ BrowserBridge.prototype.connect = async ({ session }) => {
3939
] }).text;
4040
},
4141
async consoleMessages() {
42+
if (process.env.OPENCLI_FIXTURE_CONSOLE_LEVEL === '1') {
43+
return [{ level: 'warning', text: 'Fixture warning', timestamp: 1735689600000 }];
44+
}
4245
return [{ type: 'warning', text: 'Fixture warning', timestamp: 1735689600000 }];
4346
},
4447
async readNetworkCapture() {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"session": "fixture",
3+
"captured_at": "2025-01-01T00:00:00.000Z",
4+
"count": 1,
5+
"messages": [
6+
{
7+
"level": "warning",
8+
"text": "Fixture warning",
9+
"timestamp": "2025-01-01T00:00:00.000Z"
10+
}
11+
]
12+
}

0 commit comments

Comments
 (0)