From ed4ac005b2f433980fa3e0fb5ad28af441f8f83a Mon Sep 17 00:00:00 2001 From: Jeffery Date: Wed, 24 Jun 2026 10:44:28 +0000 Subject: [PATCH] =?UTF-8?q?test(entrypoint):=20=E8=A3=9C=E4=B8=8A=20Codex?= =?UTF-8?q?=20=E5=9F=B7=E8=A1=8C=E8=B7=AF=E5=BE=91=E6=B8=AC=E8=A9=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/entrypoint_test.sh | 145 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100755 tests/entrypoint_test.sh diff --git a/tests/entrypoint_test.sh b/tests/entrypoint_test.sh new file mode 100755 index 0000000..e8cb987 --- /dev/null +++ b/tests/entrypoint_test.sh @@ -0,0 +1,145 @@ +#!/bin/bash + +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +fail() { + echo "FAIL: $1" >&2 + exit 1 +} + +make_fake_codex() { + local dir="$1" + local exit_code="$2" + local message="$3" + + cat > "$dir/codex" < "$tmpdir/stdout" 2> "$tmpdir/stderr" +} + +assert_status() { + local actual="$1" + local expected="$2" + + [[ "$actual" -eq "$expected" ]] || fail "expected status $expected, got $actual" +} + +test_missing_oauth() { + local tmpdir + tmpdir="$(mktemp -d)" + make_fake_codex "$tmpdir" 0 "unused" + + set +e + run_entrypoint "$tmpdir" MODEL="gpt-test" PROMPT="hello" + local status="$?" + set -e + + assert_status "$status" 1 + grep -q "OAUTH is required" "$tmpdir/stderr" || fail "missing OAUTH error" + rm -rf "$tmpdir" +} + +test_missing_model() { + local tmpdir + tmpdir="$(mktemp -d)" + make_fake_codex "$tmpdir" 0 "unused" + + set +e + run_entrypoint "$tmpdir" OAUTH="$(encoded_json '{}')" PROMPT="hello" + local status="$?" + set -e + + assert_status "$status" 1 + grep -q "MODEL is required" "$tmpdir/stderr" || fail "missing MODEL error" + rm -rf "$tmpdir" +} + +test_invalid_base64() { + local tmpdir + tmpdir="$(mktemp -d)" + make_fake_codex "$tmpdir" 0 "unused" + + set +e + run_entrypoint "$tmpdir" OAUTH="not-base64" MODEL="gpt-test" PROMPT="hello" + local status="$?" + set -e + + assert_status "$status" 1 + grep -q "valid base64" "$tmpdir/stderr" || fail "invalid base64 error" + rm -rf "$tmpdir" +} + +test_non_object_json() { + local tmpdir + tmpdir="$(mktemp -d)" + make_fake_codex "$tmpdir" 0 "unused" + + set +e + run_entrypoint "$tmpdir" OAUTH="$(encoded_json '[]')" MODEL="gpt-test" PROMPT="hello" + local status="$?" + set -e + + assert_status "$status" 1 + grep -q "JSON object" "$tmpdir/stderr" || fail "non-object JSON error" + rm -rf "$tmpdir" +} + +test_success_output() { + local tmpdir + tmpdir="$(mktemp -d)" + make_fake_codex "$tmpdir" 0 "codex ok" + + run_entrypoint "$tmpdir" OAUTH="$(encoded_json '{}')" MODEL="gpt-test" PROMPT="hello" + + grep -q "status=completed" "$tmpdir/github-output" || fail "completed status output" + grep -q "codex ok" "$tmpdir/github-output" || fail "codex output" + [[ ! -e "$tmpdir/codex-home/auth.json" ]] || fail "auth.json was not cleaned up" + rm -rf "$tmpdir" +} + +test_failure_output() { + local tmpdir + tmpdir="$(mktemp -d)" + make_fake_codex "$tmpdir" 7 "codex failed" + + set +e + run_entrypoint "$tmpdir" OAUTH="$(encoded_json '{}')" MODEL="gpt-test" PROMPT="hello" + local status="$?" + set -e + + assert_status "$status" 7 + grep -q "status=failed" "$tmpdir/github-output" || fail "failed status output" + grep -q "codex failed" "$tmpdir/github-output" || fail "failed codex output" + [[ ! -e "$tmpdir/codex-home/auth.json" ]] || fail "auth.json was not cleaned up after failure" + rm -rf "$tmpdir" +} + +test_missing_oauth +test_missing_model +test_invalid_base64 +test_non_object_json +test_success_output +test_failure_output + +echo "entrypoint tests passed"