Skip to content

Commit 488ff85

Browse files
committed
Verify typed browser failures preserve the original subprocess result
1 parent 432dac2 commit 488ff85

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎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)