|
2 | 2 |
|
3 | 3 | import io.github.easy4j.opencli.OpenCliClient; |
4 | 4 | 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; |
5 | 9 | import io.github.easy4j.opencli.core.OpenCliResult; |
6 | 10 | import io.github.easy4j.opencli.exception.OpenCliNonZeroExitException; |
7 | 11 | import io.github.easy4j.opencli.exception.OpenCliTimeoutException; |
|
16 | 20 | import java.nio.file.StandardOpenOption; |
17 | 21 | import java.util.Arrays; |
18 | 22 | import java.util.Collections; |
| 23 | +import java.util.List; |
19 | 24 | import java.util.Scanner; |
20 | 25 | import org.junit.jupiter.api.Test; |
21 | 26 | import org.junit.jupiter.api.io.TempDir; |
@@ -113,6 +118,27 @@ void realSubprocessPreservesFailureAndDoesNotFollowRetrySuggestion(@TempDir Path |
113 | 118 | } |
114 | 119 | } |
115 | 120 |
|
| 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 | + |
116 | 142 | @Test |
117 | 143 | void incompleteTimeoutKeepsPrimaryFailure(@TempDir Path temp) { |
118 | 144 | OpenCliProperties properties = child(temp.resolve("unused")); |
@@ -160,6 +186,15 @@ public static void main(String[] args) throws Exception { |
160 | 186 | System.err.print(fixture("empty-result-autofix")); |
161 | 187 | System.exit(1); |
162 | 188 | 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; |
163 | 198 | case "malformed": |
164 | 199 | System.err.print("{\"ok\":false,\"private-fixture-value\":"); |
165 | 200 | System.exit(1); |
|
0 commit comments