返回 CodeWhale
app-server-smoke.test.sh
根目录 / scripts / release / app-server-smoke.test.sh
1 #!/usr/bin/env bash
2 # Tests for app-server-smoke.sh: drive it against a fake `codewhale` binary so
3 # the stdio-probe assertions, auth-list matrix parser, cheap-model mapping, and
4 # secret redaction are all exercised without a real build or any model tokens.
5
6 set -euo pipefail
7
8 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
9 SMOKE="$SCRIPT_DIR/app-server-smoke.sh"
10 TESTS=0
11 FAILED=0
12
13 WORK="$(mktemp -d)"
14 trap 'rm -rf "$WORK"' EXIT
15
16 FAKE="$WORK/codewhale"
17 cat >"$FAKE" <<'FAKE_EOF'
18 #!/usr/bin/env bash
19 set -euo pipefail
20 if [[ "${1:-}" == "app-server" ]]; then
21 [[ "$HOME" == "$CODEWHALE_HOME" && -d "$HOME" && -z "${OPENAI_API_KEY:-}" ]] || exit 4
22 if [[ -f "$(dirname "$0")/stall" ]]; then
23 sleep 30
24 fi
25 cat >/dev/null # drain the JSON-RPC requests
26 printf '%s\n' \
27 '{"id":0,"result":{"userAgent":"fixture","codexHome":"/tmp","platformFamily":"unix","platformOs":"macos"}}' \
28 '{"id":1,"result":{"status":"ok","service":"deepseek-app-server","transport":"stdio"}}' \
29 '{"id":2,"result":{"methods":["thread/request","prompt/run","prompt/request","thread/goal/get"]}}' \
30 '{"id":3,"result":{"ok":true,"data":{"transport":"stdio+http"}}}' \
31 '{"id":4,"result":{}}' \
32 '{"id":5,"result":{}}' \
33 '{"id":6,"result":{"ok":true}}'
34 exit 0
35 fi
36 if [[ "${1:-}" == "auth" && "${2:-}" == "list" ]]; then
37 printf '%s\n' \
38 'provider config store env active' \
39 'deepseek yes - no config' \
40 'zai no - yes env' \
41 'openrouter no - no missing' \
42 'arcee yes - no config'
43 exit 0
44 fi
45 # exec form: --provider <slug> --model <model> exec <prompt>
46 slug=""; model=""
47 while [[ $# -gt 0 ]]; do
48 case "$1" in
49 --provider) slug="$2"; shift 2 ;;
50 --model) model="$2"; shift 2 ;;
51 exec) shift; break ;;
52 *) shift ;;
53 esac
54 done
55 # Emit a fake secret on the reply line to prove redaction scrubs it.
56 printf 'pong [%s/%s] token=sk-DEADBEEFCAFE12345\n' "$slug" "$model"
57 exit 0
58 FAKE_EOF
59 chmod +x "$FAKE"
60
61 # run_smoke <expected_exit> -- <args...> : capture combined output, check exit.
62 LAST_OUT=""
63 run_smoke() {
64 local expected="$1"; shift
65 [[ "$1" == "--" ]] && shift
66 local rc=0
67 LAST_OUT="$(bash "$SMOKE" --bin "$FAKE" "$@" 2>&1)" || rc=$?
68 TESTS=$((TESTS + 1))
69 if [[ "$rc" != "$expected" ]]; then
70 printf '\033[1;31mFAIL\033[0m exit %s (wanted %s) for: %s\n' "$rc" "$expected" "$*"
71 printf '%s\n' "$LAST_OUT" | sed 's/^/ /'
72 FAILED=$((FAILED + 1))
73 return 1
74 fi
75 return 0
76 }
77
78 want() { TESTS=$((TESTS + 1)); if printf '%s' "$LAST_OUT" | grep -qF "$1"; then :; else printf '\033[1;31mFAIL\033[0m output missing: %s\n' "$1"; FAILED=$((FAILED + 1)); fi; }
79 want_not(){ TESTS=$((TESTS + 1)); if printf '%s' "$LAST_OUT" | grep -qF "$1"; then printf '\033[1;31mFAIL\033[0m output should not contain: %s\n' "$1"; FAILED=$((FAILED + 1)); fi; }
80
81 # 1. Default: stdio probe only, passes, matrix skipped.
82 run_smoke 0 -- || true
83 want "healthz reports ok"
84 want "capabilities advertise thread/* methods"
85 want "app/capabilities reports transport"
86 want "matrix skipped"
87
88 # 2. Dry-run matrix: maps known providers, flags unmapped, skips 'missing'.
89 run_smoke 0 -- --matrix || true
90 want "deepseek -> deepseek-chat"
91 want "zai -> glm-4-flash"
92 want "arcee -> (UNMAPPED"
93 want_not "openrouter"
94
95 # 3. Real exec for a mapped provider passes; secret is redacted.
96 run_smoke 0 -- --matrix --real --provider deepseek || true
97 want "deepseek/deepseek-chat exec ok"
98 want "REDACTED"
99 want_not "sk-DEADBEEFCAFE12345"
100
101 # 4. Real exec across all configured providers fails on the unmapped one.
102 run_smoke 1 -- --matrix --real || true
103 want "arcee has no cheap-model mapping"
104
105 # 5. Override supplies a model for the otherwise-unmapped provider.
106 TESTS=$((TESTS + 1))
107 LAST_OUT="$(SMOKE_MODEL_ARCEE=arcee-cheap bash "$SMOKE" --bin "$FAKE" --matrix 2>&1)" || { FAILED=$((FAILED + 1)); printf 'FAIL override run errored\n'; }
108 want "arcee -> arcee-cheap"
109
110 # A non-answering binary must fail within a deadline instead of hanging release.
111 touch "$WORK/stall"
112 SMOKE_STDIO_TIMEOUT=1 run_smoke 1 -- || true
113 want "did not shut down within the probe deadline"
114 rm "$WORK/stall"
115
116 # Ambient provider credentials must never reach the stdio probe.
117 OPENAI_API_KEY=non-secret-test-sentinel run_smoke 0 -- || true
118 want "healthz reports ok"
119
120 echo ""
121 if [[ "$FAILED" -eq 0 ]]; then
122 printf '\033[1;32mapp-server-smoke.test.sh: all %s checks passed\033[0m\n' "$TESTS"
123 else
124 printf '\033[1;31mapp-server-smoke.test.sh: %s/%s checks failed\033[0m\n' "$FAILED" "$TESTS"
125 exit 1
126 fi
127
127 lines BASH