Skip to content

Commit 867de53

Browse files
committed
test(client): expose config propagation regressions
1 parent 823424b commit 867de53

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

‎src/test/java/io/github/easy4j/codex/CodexClientTest.java‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,34 @@ private static CodexClient echoClient() {
6464
return new CodexClient(echoConfig());
6565
}
6666

67+
private static final class CapturingExecutor extends CodexCliExecutor {
68+
private final String stdout;
69+
private String[] lastArgs;
70+
71+
private CapturingExecutor(CodexClientConfig config, String stdout) {
72+
super(config);
73+
this.stdout = stdout;
74+
}
75+
76+
@Override
77+
public CodexCliResult execute(String... args) {
78+
this.lastArgs = args;
79+
return new CodexCliResult(0, stdout, "");
80+
}
81+
82+
private boolean hasArg(String expected) {
83+
if (lastArgs == null) {
84+
return false;
85+
}
86+
for (String arg : lastArgs) {
87+
if (expected.equals(arg)) {
88+
return true;
89+
}
90+
}
91+
return false;
92+
}
93+
}
94+
6795
// ----------------------------------------------------------------
6896
// Constructor
6997
// ----------------------------------------------------------------
@@ -148,6 +176,17 @@ void shouldDelegateExecWithPrompt() {
148176
assertTrue(out.contains("hello"));
149177
}
150178

179+
@Test
180+
void shouldHonorJsonOutputFalseForNormalExec() {
181+
CodexClientConfig config = echoConfig();
182+
config.setJsonOutput(false);
183+
184+
CodexCliResult result = new CodexClient(config).exec("hello");
185+
186+
assertFalse(result.getStdout().contains("--json"),
187+
"normal exec must honor CodexClientConfig.jsonOutput=false");
188+
}
189+
151190
@Test
152191
void shouldDelegateExecWithPromptAndModel() {
153192
CodexCliResult result = echoClient().exec("hello", "gpt-5");
@@ -251,6 +290,22 @@ void shouldReturnEmptyListForBlankOutput() {
251290
// (failed parse lines are skipped)
252291
}
253292

293+
@Test
294+
void shouldForceJsonForExecAndParseEvenWhenDefaultJsonOutputIsFalse() {
295+
CodexClientConfig config = echoConfig();
296+
config.setJsonOutput(false);
297+
CapturingExecutor executor = new CapturingExecutor(
298+
config, "{\"type\":\"message\",\"message\":\"hi\"}");
299+
CodexClient client = new CodexClient(config, new CodexCli(executor));
300+
301+
List<CodexEvent> events = client.execAndParse("hello");
302+
303+
assertTrue(executor.hasArg("--json"),
304+
"execAndParse must force --json independently of the normal exec default");
305+
assertEquals(1, events.size());
306+
assertEquals("message", events.get(0).getType());
307+
}
308+
254309
@Test
255310
void shouldParseValidJsonlOutput() throws Exception {
256311
// Create a custom client that returns valid JSON-Lines
@@ -278,6 +333,17 @@ void shouldDelegateStartSessionWithPrompt() {
278333
assertTrue(result.getStdout().contains("hello"));
279334
}
280335

336+
@Test
337+
void shouldPropagateNoAltScreenToDefaultInteractiveSession() {
338+
CodexClientConfig config = echoConfig();
339+
config.setNoAltScreen(true);
340+
341+
CodexCliResult result = new CodexClient(config).startSession("hello");
342+
343+
assertTrue(result.getStdout().contains("--no-alt-screen"),
344+
"default interactive session must honor CodexClientConfig.noAltScreen=true");
345+
}
346+
281347
@Test
282348
void shouldDelegateStartSessionWithOpts() {
283349
CodexCli.GlobalOptions opts = new CodexCli.GlobalOptions().model("gpt-5");

0 commit comments

Comments
 (0)