test(entrypoint): 補齊 timeout 與輸出限制測試
This commit is contained in:
@@ -23,6 +23,39 @@ SH
|
|||||||
chmod +x "$dir/codex"
|
chmod +x "$dir/codex"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
make_fake_sleeping_codex() {
|
||||||
|
local dir="$1"
|
||||||
|
|
||||||
|
cat > "$dir/codex" <<'SH'
|
||||||
|
#!/bin/sh
|
||||||
|
trap 'exit 143' TERM
|
||||||
|
while true; do
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
SH
|
||||||
|
chmod +x "$dir/codex"
|
||||||
|
}
|
||||||
|
|
||||||
|
make_fake_signaled_codex() {
|
||||||
|
local dir="$1"
|
||||||
|
|
||||||
|
cat > "$dir/codex" <<'SH'
|
||||||
|
#!/bin/sh
|
||||||
|
kill -TERM $$
|
||||||
|
SH
|
||||||
|
chmod +x "$dir/codex"
|
||||||
|
}
|
||||||
|
|
||||||
|
make_fake_large_output_codex() {
|
||||||
|
local dir="$1"
|
||||||
|
|
||||||
|
cat > "$dir/codex" <<'SH'
|
||||||
|
#!/bin/sh
|
||||||
|
printf '0123456789'
|
||||||
|
SH
|
||||||
|
chmod +x "$dir/codex"
|
||||||
|
}
|
||||||
|
|
||||||
encoded_json() {
|
encoded_json() {
|
||||||
printf '%s' "$1" | base64 | tr -d '\n'
|
printf '%s' "$1" | base64 | tr -d '\n'
|
||||||
}
|
}
|
||||||
@@ -190,6 +223,70 @@ test_missing_codex_command_output() {
|
|||||||
rm -rf "$tmpdir"
|
rm -rf "$tmpdir"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_codex_timeout_output() {
|
||||||
|
local tmpdir
|
||||||
|
tmpdir="$(mktemp -d)"
|
||||||
|
make_fake_sleeping_codex "$tmpdir"
|
||||||
|
|
||||||
|
set +e
|
||||||
|
run_entrypoint "$tmpdir" OAUTH="$(encoded_json '{}')" MODEL="gpt-test" PROMPT="hello" CODEX_TIMEOUT_MS="100"
|
||||||
|
local status="$?"
|
||||||
|
set -e
|
||||||
|
|
||||||
|
assert_status "$status" 143
|
||||||
|
grep -q "status=failed" "$tmpdir/github-output" || die "timeout failed status output"
|
||||||
|
grep -q "Codex execution timed out after 100 ms" "$tmpdir/github-output" || die "timeout message output"
|
||||||
|
[[ ! -e "$tmpdir/codex-home/auth.json" ]] || die "auth.json was not cleaned up after timeout"
|
||||||
|
rm -rf "$tmpdir"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_codex_signal_output() {
|
||||||
|
local tmpdir
|
||||||
|
tmpdir="$(mktemp -d)"
|
||||||
|
make_fake_signaled_codex "$tmpdir"
|
||||||
|
|
||||||
|
set +e
|
||||||
|
run_entrypoint "$tmpdir" OAUTH="$(encoded_json '{}')" MODEL="gpt-test" PROMPT="hello"
|
||||||
|
local status="$?"
|
||||||
|
set -e
|
||||||
|
|
||||||
|
assert_status "$status" 1
|
||||||
|
grep -q "status=failed" "$tmpdir/github-output" || die "signal failed status output"
|
||||||
|
grep -q "Codex process terminated by signal SIGTERM" "$tmpdir/github-output" || die "signal message output"
|
||||||
|
rm -rf "$tmpdir"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_codex_output_truncation() {
|
||||||
|
local tmpdir
|
||||||
|
tmpdir="$(mktemp -d)"
|
||||||
|
make_fake_large_output_codex "$tmpdir"
|
||||||
|
|
||||||
|
run_entrypoint "$tmpdir" OAUTH="$(encoded_json '{}')" MODEL="gpt-test" PROMPT="hello" CODEX_OUTPUT_LIMIT_BYTES="5"
|
||||||
|
|
||||||
|
grep -q "status=completed" "$tmpdir/github-output" || die "truncated output completed status"
|
||||||
|
grep -q "01234" "$tmpdir/github-output" || die "truncated output prefix"
|
||||||
|
grep -q "\\[Output truncated\\]" "$tmpdir/github-output" || die "truncation message output"
|
||||||
|
rm -rf "$tmpdir"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_invalid_execution_config_uses_defaults() {
|
||||||
|
local tmpdir
|
||||||
|
tmpdir="$(mktemp -d)"
|
||||||
|
make_fake_large_output_codex "$tmpdir"
|
||||||
|
|
||||||
|
run_entrypoint "$tmpdir" \
|
||||||
|
OAUTH="$(encoded_json '{}')" \
|
||||||
|
MODEL="gpt-test" \
|
||||||
|
PROMPT="hello" \
|
||||||
|
CODEX_TIMEOUT_MS="invalid" \
|
||||||
|
CODEX_OUTPUT_LIMIT_BYTES="invalid"
|
||||||
|
|
||||||
|
grep -q "status=completed" "$tmpdir/github-output" || die "invalid config completed status"
|
||||||
|
grep -q "0123456789" "$tmpdir/github-output" || die "invalid output limit did not use default"
|
||||||
|
! grep -q "\\[Output truncated\\]" "$tmpdir/github-output" || die "invalid output limit unexpectedly truncated"
|
||||||
|
rm -rf "$tmpdir"
|
||||||
|
}
|
||||||
|
|
||||||
test_missing_oauth
|
test_missing_oauth
|
||||||
test_missing_model
|
test_missing_model
|
||||||
test_invalid_base64
|
test_invalid_base64
|
||||||
@@ -199,5 +296,9 @@ test_empty_prompt
|
|||||||
test_prompt_with_shell_characters
|
test_prompt_with_shell_characters
|
||||||
test_failure_output
|
test_failure_output
|
||||||
test_missing_codex_command_output
|
test_missing_codex_command_output
|
||||||
|
test_codex_timeout_output
|
||||||
|
test_codex_signal_output
|
||||||
|
test_codex_output_truncation
|
||||||
|
test_invalid_execution_config_uses_defaults
|
||||||
|
|
||||||
echo "entrypoint tests passed"
|
echo "entrypoint tests passed"
|
||||||
|
|||||||
Reference in New Issue
Block a user