|
11 | 11 | import io.github.easy4j.opencli.exception.OpenCliTimeoutException; |
12 | 12 | import io.github.easy4j.opencli.parser.OpenCliErrorEnvelope; |
13 | 13 | import io.github.easy4j.opencli.parser.OpenCliErrorDecoder; |
| 14 | +import java.io.ByteArrayOutputStream; |
14 | 15 | import java.io.File; |
15 | 16 | import java.io.InputStream; |
| 17 | +import java.io.PrintStream; |
16 | 18 | import java.nio.charset.StandardCharsets; |
17 | 19 | import java.nio.file.Files; |
18 | 20 | import java.nio.file.Path; |
|
22 | 24 | import java.util.Collections; |
23 | 25 | import java.util.List; |
24 | 26 | import java.util.Scanner; |
| 27 | +import java.util.UUID; |
25 | 28 | import org.junit.jupiter.api.Test; |
26 | 29 | import org.junit.jupiter.api.io.TempDir; |
27 | 30 |
|
@@ -118,6 +121,31 @@ void realSubprocessPreservesFailureAndDoesNotFollowRetrySuggestion(@TempDir Path |
118 | 121 | } |
119 | 122 | } |
120 | 123 |
|
| 124 | + @Test |
| 125 | + void malformedYamlRetainsRawStderrWithoutExposingParserDetails(@TempDir Path temp) throws Exception { |
| 126 | + String canary = "yaml-secret-" + UUID.randomUUID(); |
| 127 | + ByteArrayOutputStream diagnostics = new ByteArrayOutputStream(); |
| 128 | + PrintStream previousErr = System.err; |
| 129 | + OpenCliNonZeroExitException failure; |
| 130 | + try (OpenCliClient client = new OpenCliClient(child(temp.resolve("unused"))); |
| 131 | + PrintStream capture = new PrintStream(diagnostics, true, StandardCharsets.UTF_8.name())) { |
| 132 | + System.setErr(capture); |
| 133 | + try { |
| 134 | + failure = assertThrows(OpenCliNonZeroExitException.class, |
| 135 | + () -> client.getExecutor().invoke("malformed-yaml", canary)); |
| 136 | + failure.printStackTrace(capture); |
| 137 | + } finally { |
| 138 | + System.setErr(previousErr); |
| 139 | + } |
| 140 | + } |
| 141 | + OpenCliResult partial = failure.getPartialResult(); |
| 142 | + assertEquals(OpenCliErrorEnvelope.Status.INVALID, partial.getErrorEnvelope().getStatus()); |
| 143 | + assertEquals(OpenCliErrorEnvelope.Format.YAML, partial.getErrorEnvelope().getFormat()); |
| 144 | + assertEquals(Integer.valueOf(1), partial.getExitCode()); |
| 145 | + assertTrue(partial.getStderr().contains(canary)); |
| 146 | + assertFalse(diagnostics.toString(StandardCharsets.UTF_8.name()).contains(canary)); |
| 147 | + } |
| 148 | + |
121 | 149 | @Test |
122 | 150 | void typedBrowserListPreservesProcessFailureEvenWithAnEmptyArray(@TempDir Path temp) throws Exception { |
123 | 151 | Path marker = temp.resolve("browser-commands"); |
@@ -199,6 +227,10 @@ public static void main(String[] args) throws Exception { |
199 | 227 | System.err.print("{\"ok\":false,\"private-fixture-value\":"); |
200 | 228 | System.exit(1); |
201 | 229 | break; |
| 230 | + case "malformed-yaml": |
| 231 | + System.err.print("ok: false\nerror: {code: FAIL, " + args[2] + ": [\n"); |
| 232 | + System.exit(1); |
| 233 | + break; |
202 | 234 | case "timeout": |
203 | 235 | System.err.print("ok: false\nerror:"); |
204 | 236 | Thread.sleep(30_000); |
|
0 commit comments