Skip to content

Commit 3138332

Browse files
committed
Verify typed browser failures preserve the original subprocess result
1 parent f2feb18 commit 3138332

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@
2828
## OC-BROWSER-001/002/003/005/006 首批叶子
2929

3030
`OpenCliBrowserResultTest` 首先因缺少结果类型无法编译。加入 tab list 和 open 的叶子模型后,验收真实 CLI action 的归档输出、合法空数组、畸形输出、截断、命令失败、精确 ID 和扩展元数据。两种命令通过现有会话入口运行,原始结果和既有 close 签名保留。见 [样本与复跑方式](evidence/2026-11-19-open-and-tab-list.md)。AX/state、其余叶子与真实浏览器接入继续验收。
31+
32+
### OC-BROWSER-002/005/006 三线失败语义
33+
34+
用已安装的 OpenCLI 1.8.8 和 Node 24.18.0 在隔离页面桩边界重新运行两次 tab list(非空与空)及 open。三份 stdout 与归档样本逐字节一致,Java 8、17、21 分支的样本均通过 `SHA256SUMS`。该验证未连接真实浏览器或外部站点。
35+
36+
`OpenCliErrorEnvelopeTest#typedBrowserListPreservesProcessFailureEvenWithAnEmptyArray` 启动独立 JVM,输出合法空数组和 YAML 错误信封,然后以 1 退出。类型化 tab list 保留原非零退出异常、报告退出码 77 和 trace 元数据。显式对 partial result 解码得到 `EXECUTION_FAILED` 并保留同一原始对象。参数记录只出现一次 tab list,没有触发额外的命令或关闭操作。
37+
38+
在 `3692329`、`f2feb186`、`432dac2` 上加入回归后,用对应 JDK 执行 `./mvnw -B -ntp clean verify`,三线均退出 0。全量分别通过 2215、2216、2215 项。每条线的 Browser 结果 4 项和错误信封 7 项完全一致,零失败、零错误、零跳过。报告在 `target/surefire-reports`。

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import io.github.easy4j.opencli.OpenCliClient;
44
import io.github.easy4j.opencli.OpenCliProperties;
5+
import io.github.easy4j.opencli.browser.OpenCliBrowserSession;
6+
import io.github.easy4j.opencli.browser.result.OpenCliBrowserDecoder;
7+
import io.github.easy4j.opencli.browser.result.OpenCliBrowserResult;
8+
import io.github.easy4j.opencli.browser.result.OpenCliBrowserTab;
59
import io.github.easy4j.opencli.core.OpenCliResult;
610
import io.github.easy4j.opencli.exception.OpenCliNonZeroExitException;
711
import io.github.easy4j.opencli.exception.OpenCliTimeoutException;
@@ -16,6 +20,7 @@
1620
import java.nio.file.StandardOpenOption;
1721
import java.util.Arrays;
1822
import java.util.Collections;
23+
import java.util.List;
1924
import java.util.Scanner;
2025
import org.junit.jupiter.api.Test;
2126
import org.junit.jupiter.api.io.TempDir;
@@ -113,6 +118,27 @@ void realSubprocessPreservesFailureAndDoesNotFollowRetrySuggestion(@TempDir Path
113118
}
114119
}
115120

121+
@Test
122+
void typedBrowserListPreservesProcessFailureEvenWithAnEmptyArray(@TempDir Path temp) throws Exception {
123+
Path marker = temp.resolve("browser-commands");
124+
try (OpenCliClient client = new OpenCliClient(child(marker))) {
125+
OpenCliBrowserSession session = new OpenCliBrowserSession(client.getExecutor(), "fixture", null);
126+
OpenCliNonZeroExitException failure = assertThrows(OpenCliNonZeroExitException.class, session::tabListTyped);
127+
OpenCliResult raw = failure.getPartialResult();
128+
OpenCliBrowserResult<List<OpenCliBrowserTab>> decoded = OpenCliBrowserDecoder.tabList(raw);
129+
130+
assertEquals("[]", raw.getStdout());
131+
assertEquals(Integer.valueOf(1), raw.getExitCode());
132+
assertEquals("BROWSER_FIXTURE", raw.getErrorEnvelope().getCode());
133+
assertEquals(Integer.valueOf(77), raw.getErrorEnvelope().getReportedExit());
134+
assertEquals("missing-fixture.json", raw.getErrorEnvelope().getTrace().get("summaryPath"));
135+
assertSame(raw, decoded.getRaw());
136+
assertEquals(OpenCliBrowserResult.Status.EXECUTION_FAILED, decoded.getStatus());
137+
assertNull(decoded.getValue());
138+
}
139+
assertEquals(Collections.singletonList("fixture tab list"), Files.readAllLines(marker, StandardCharsets.UTF_8));
140+
}
141+
116142
@Test
117143
void incompleteTimeoutKeepsPrimaryFailure(@TempDir Path temp) {
118144
OpenCliProperties properties = child(temp.resolve("unused"));
@@ -160,6 +186,15 @@ public static void main(String[] args) throws Exception {
160186
System.err.print(fixture("empty-result-autofix"));
161187
System.exit(1);
162188
break;
189+
case "browser":
190+
Files.write(Paths.get(args[0]),
191+
Collections.singletonList(String.join(" ", Arrays.copyOfRange(args, 2, args.length))),
192+
StandardOpenOption.CREATE, StandardOpenOption.APPEND);
193+
System.out.print("[]");
194+
System.err.print("ok: false\nerror: {code: BROWSER_FIXTURE, message: failed, exitCode: 77}\n"
195+
+ "trace: {summaryPath: missing-fixture.json}\n");
196+
System.exit(1);
197+
break;
163198
case "malformed":
164199
System.err.print("{\"ok\":false,\"private-fixture-value\":");
165200
System.exit(1);

0 commit comments

Comments
 (0)