Skip to content

Commit e34e68d

Browse files
committed
fix(test): 测试替身 /bin/echo 改为可移植 echo-args.sh——GNU coreutils echo(Linux)把 --version 当旗标解析导致 CI 断言失败
1 parent f2d943b commit e34e68d

3 files changed

Lines changed: 32 additions & 8 deletions

File tree

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.github.easy4j.codex.model.CodexSession;
2626
import org.junit.jupiter.api.Test;
2727

28+
import java.nio.file.Path;
2829
import java.util.List;
2930

3031
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -36,19 +37,25 @@
3637
/**
3738
* Unit tests for {@link CodexClient}.
3839
*
39-
* <p>Uses {@code /bin/echo} as the CLI executable so that argument
40-
* assembly and JSON parsing can be verified without depending on the
41-
* real {@code codex} binary.</p>
40+
* <p>Uses the {@code echo-args.sh} test fixture as the CLI executable so that
41+
* argument assembly and JSON parsing can be verified without depending on the
42+
* real {@code codex} binary. {@code /bin/echo} cannot be used because GNU
43+
* coreutils echo (Linux) interprets {@code --version} as a flag while BSD echo
44+
* (macOS) prints it literally.</p>
4245
*
4346
* @since 3.0.0
4447
*/
4548
class CodexClientTest {
4649

4750
private static final ObjectMapper MAPPER = new JsonMapper();
4851

52+
/** Absolute path of the argument-echoing fixture script (surefire runs from the module base dir). */
53+
private static final String ECHO_ARGS_SCRIPT =
54+
Path.of("src", "test", "resources", "echo-args.sh").toAbsolutePath().toString();
55+
4956
private static CodexClientConfig echoConfig() {
5057
CodexClientConfig config = new CodexClientConfig();
51-
config.setLocalExecutable("/bin/echo");
58+
config.setLocalExecutable(ECHO_ARGS_SCRIPT);
5259
config.setLocalTimeoutSeconds(2);
5360
return config;
5461
}

‎src/test/java/io/github/easy4j/codex/cli/CodexCliTest.java‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import io.github.easy4j.codex.CodexClientConfig;
1919
import org.junit.jupiter.api.Test;
2020

21+
import java.nio.file.Path;
22+
2123
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2224
import static org.junit.jupiter.api.Assertions.assertEquals;
2325
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -27,17 +29,23 @@
2729
* Unit tests for {@link CodexCli} and its inner option builders
2830
* ({@link CodexCli.ExecOptions} and {@link CodexCli.GlobalOptions}).
2931
*
30-
* <p>Uses {@code /bin/echo} as the CLI executable so that argument
31-
* assembly can be verified without depending on the real {@code codex}
32-
* binary.</p>
32+
* <p>Uses the {@code echo-args.sh} test fixture as the CLI executable so that
33+
* argument assembly can be verified without depending on the real {@code codex}
34+
* binary. {@code /bin/echo} cannot be used because GNU coreutils echo (Linux)
35+
* interprets {@code --version} as a flag while BSD echo (macOS) prints it
36+
* literally.</p>
3337
*
3438
* @since 3.0.0
3539
*/
3640
class CodexCliTest {
3741

42+
/** Absolute path of the argument-echoing fixture script (surefire runs from the module base dir). */
43+
private static final String ECHO_ARGS_SCRIPT =
44+
Path.of("src", "test", "resources", "echo-args.sh").toAbsolutePath().toString();
45+
3846
private static CodexCli echoCli() {
3947
CodexClientConfig config = new CodexClientConfig();
40-
config.setLocalExecutable("/bin/echo");
48+
config.setLocalExecutable(ECHO_ARGS_SCRIPT);
4149
config.setLocalTimeoutSeconds(2);
4250
return new CodexCli(new CodexCliExecutor(config));
4351
}

‎src/test/resources/echo-args.sh‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
#
3+
# Test double for the `codex` CLI: prints every argument verbatim, joined by
4+
# single spaces on one line, and exits with 0 — the same output contract as
5+
# `/bin/echo` but portable. /bin/echo cannot be used directly because GNU
6+
# coreutils echo (Linux) interprets --version/--help as flags while BSD echo
7+
# (macOS) prints them literally.
8+
#
9+
printf '%s\n' "$*"

0 commit comments

Comments
 (0)