Remove redundant claude_anthropic wrapper
This commit is contained in:
@@ -109,229 +109,3 @@ test_fix5_gemini_revalidate() {
|
||||
fi
|
||||
}
|
||||
|
||||
# ── Fix 6: prompt [C/q] matches default C in 429 handler ─────────────────────
|
||||
test_fix6_prompt_default() {
|
||||
# The prompt should now show [C/q] (capital C = default) matching case "${_ans:-C}"
|
||||
if grep -q '\[C/q\]' "$SCRIPT"; then
|
||||
ok "Fix6: prompt shows [C/q] — capital C signals default=continue"
|
||||
else
|
||||
fail "Fix6: prompt still shows [c/Q] (misleading) or was changed incorrectly"
|
||||
fi
|
||||
|
||||
# Confirm the default in case is still C
|
||||
local anthropic_section
|
||||
anthropic_section=$(awk '/^claude_anthropic\(\)/,/^}/' "$SCRIPT")
|
||||
if echo "$anthropic_section" | grep -q '${_ans:-C}'; then
|
||||
ok "Fix6: default in case is still C (continue on Enter)"
|
||||
else
|
||||
fail "Fix6: default in case changed unexpectedly"
|
||||
fi
|
||||
}
|
||||
|
||||
# ── Fix 7: trap quotes $TMP correctly ────────────────────────────────────────
|
||||
test_fix7_trap_tmp() {
|
||||
# Should be single-quoted trap so $TMP expands at execution, not definition
|
||||
if grep -q "trap 'rm -rf \"\$TMP\"' EXIT" "$SCRIPT"; then
|
||||
ok "Fix7: trap uses single quotes with quoted \"\$TMP\""
|
||||
else
|
||||
fail "Fix7: trap still uses double quotes or $TMP still unquoted at execution"
|
||||
fi
|
||||
|
||||
# Old bad form should be gone
|
||||
if grep -q 'trap "rm -rf \$TMP" EXIT' "$SCRIPT"; then
|
||||
fail "Fix7: old unquoted trap form still present"
|
||||
else
|
||||
ok "Fix7: old unquoted trap form removed"
|
||||
fi
|
||||
}
|
||||
|
||||
# ── _claude_test_api function isolation ──────────────────────────────────────
|
||||
test_globals_set_by_test_api() {
|
||||
_source_functions
|
||||
|
||||
# Mock curl to return a fake 200 response
|
||||
curl() {
|
||||
echo '{"id":"msg_test"}'
|
||||
echo "200"
|
||||
}
|
||||
export -f curl
|
||||
|
||||
_CLAUDE_TEST_CODE=""
|
||||
_CLAUDE_TEST_BODY=""
|
||||
_claude_test_api "http://fake.api/v1/messages" "x-api-key: testkey" "test-model"
|
||||
|
||||
if [ "$_CLAUDE_TEST_CODE" = "200" ]; then
|
||||
ok "test_api: _CLAUDE_TEST_CODE set to 200"
|
||||
else
|
||||
fail "test_api: _CLAUDE_TEST_CODE='$_CLAUDE_TEST_CODE' expected '200'"
|
||||
fi
|
||||
|
||||
if echo "$_CLAUDE_TEST_BODY" | grep -q '"id"'; then
|
||||
ok "test_api: _CLAUDE_TEST_BODY contains response body"
|
||||
else
|
||||
fail "test_api: _CLAUDE_TEST_BODY='$_CLAUDE_TEST_BODY' missing body"
|
||||
fi
|
||||
|
||||
unset -f curl
|
||||
}
|
||||
|
||||
test_globals_set_on_curl_fail() {
|
||||
_source_functions
|
||||
|
||||
# curl fails → fallback "000"
|
||||
curl() { return 1; }
|
||||
export -f curl
|
||||
|
||||
_CLAUDE_TEST_CODE=""
|
||||
_claude_test_api "http://unreachable/" "x-api-key: k" "m"
|
||||
|
||||
if [ "$_CLAUDE_TEST_CODE" = "000" ]; then
|
||||
ok "test_api: _CLAUDE_TEST_CODE=000 on curl failure"
|
||||
else
|
||||
fail "test_api: expected 000 on curl failure, got '$_CLAUDE_TEST_CODE'"
|
||||
fi
|
||||
|
||||
unset -f curl
|
||||
}
|
||||
|
||||
# ── _claude_extract_error ────────────────────────────────────────────────────
|
||||
test_extract_error_message() {
|
||||
_source_functions
|
||||
|
||||
local body='{"type":"error","error":{"type":"authentication_error","message":"Invalid API key"}}'
|
||||
local result
|
||||
result=$(_claude_extract_error "$body")
|
||||
|
||||
if [ "$result" = "Invalid API key" ]; then
|
||||
ok "extract_error: extracts error.message from JSON"
|
||||
else
|
||||
fail "extract_error: expected 'Invalid API key', got '$result'"
|
||||
fi
|
||||
}
|
||||
|
||||
test_extract_error_empty_body() {
|
||||
_source_functions
|
||||
|
||||
local result
|
||||
result=$(_claude_extract_error "not json at all")
|
||||
|
||||
if [ -z "$result" ]; then
|
||||
ok "extract_error: returns empty string on non-JSON input"
|
||||
else
|
||||
fail "extract_error: unexpected output '$result' on bad input"
|
||||
fi
|
||||
}
|
||||
|
||||
# ── _claude_offer_reauth ─────────────────────────────────────────────────────
|
||||
test_offer_reauth_yes() {
|
||||
_source_functions
|
||||
|
||||
# Simulate user typing "Y"
|
||||
local result
|
||||
result=$(echo "Y" | (
|
||||
_claude_offer_reauth "TestProvider"
|
||||
echo "retcode:$?"
|
||||
))
|
||||
|
||||
if echo "$result" | grep -q "retcode:0"; then
|
||||
ok "offer_reauth: returns 0 on 'Y'"
|
||||
else
|
||||
fail "offer_reauth: expected retcode 0 on Y, got: $result"
|
||||
fi
|
||||
}
|
||||
|
||||
test_offer_reauth_no() {
|
||||
_source_functions
|
||||
|
||||
local result
|
||||
result=$(echo "n" | (
|
||||
_claude_offer_reauth "TestProvider"
|
||||
echo "retcode:$?"
|
||||
))
|
||||
|
||||
if echo "$result" | grep -q "retcode:1"; then
|
||||
ok "offer_reauth: returns 1 on 'n'"
|
||||
else
|
||||
fail "offer_reauth: expected retcode 1 on n, got: $result"
|
||||
fi
|
||||
}
|
||||
|
||||
test_offer_reauth_enter_defaults_yes() {
|
||||
_source_functions
|
||||
|
||||
local result
|
||||
result=$(echo "" | (
|
||||
_claude_offer_reauth "TestProvider"
|
||||
echo "retcode:$?"
|
||||
))
|
||||
|
||||
if echo "$result" | grep -q "retcode:0"; then
|
||||
ok "offer_reauth: Enter (empty) defaults to Yes (retcode 0)"
|
||||
else
|
||||
fail "offer_reauth: Enter should default to Yes, got: $result"
|
||||
fi
|
||||
}
|
||||
|
||||
# ── Fix8: no double login — [L] branch calls claude directly, not auth login ─
|
||||
test_fix8_no_double_login() {
|
||||
# [L] branch must NOT call "claude auth login"; must call claude directly and return.
|
||||
|
||||
# Find the line number of [Ll])
|
||||
local ll_line
|
||||
ll_line=$(grep -n '^\s*\[Ll\])' "$SCRIPT" | head -1 | cut -d: -f1)
|
||||
|
||||
# Extract the next 20 lines starting at [Ll]) — enough to cover the whole arm
|
||||
local ll_branch
|
||||
ll_branch=$(awk "NR>=$ll_line && NR<=$((ll_line+20))" "$SCRIPT")
|
||||
|
||||
# Check for actual invocation (not just a comment mentioning the command)
|
||||
if echo "$ll_branch" | grep -v '^\s*#' | grep -q 'claude auth login'; then
|
||||
fail "Fix8: [L] branch still calls 'claude auth login' — double login present"
|
||||
else
|
||||
ok "Fix8: [L] branch does NOT call 'claude auth login' (only mentions it in a comment)"
|
||||
fi
|
||||
|
||||
if echo "$ll_branch" | grep -qF 'return "$?"'; then
|
||||
ok "Fix8: [L] branch returns after launching claude (no fallthrough to outer call)"
|
||||
else
|
||||
fail "Fix8: [L] branch missing 'return \"\$?\"' — outer claude call still reached"
|
||||
fi
|
||||
|
||||
if echo "$ll_branch" | grep -q 'ANTHROPIC_MODEL='; then
|
||||
ok "Fix8: [L] branch sets model env vars before launching claude"
|
||||
else
|
||||
fail "Fix8: [L] branch missing model env vars"
|
||||
fi
|
||||
}
|
||||
|
||||
# ── bash syntax of the whole script ─────────────────────────────────────────
|
||||
test_script_syntax() {
|
||||
if bash -n "$SCRIPT" 2>&1; then
|
||||
ok "syntax: claude_setup.sh passes 'bash -n'"
|
||||
else
|
||||
fail "syntax: claude_setup.sh has syntax errors"
|
||||
fi
|
||||
}
|
||||
|
||||
# ── run all tests ─────────────────────────────────────────────────────────────
|
||||
test_script_syntax
|
||||
test_fix8_no_double_login
|
||||
test_fix1_export_api_key
|
||||
test_fix2_trap_return
|
||||
test_fix3_readiness_loop
|
||||
test_fix3b_exit7_logic
|
||||
test_fix4_gpt_revalidate
|
||||
test_fix5_gemini_revalidate
|
||||
test_fix6_prompt_default
|
||||
test_fix7_trap_tmp
|
||||
test_globals_set_by_test_api
|
||||
test_globals_set_on_curl_fail
|
||||
test_extract_error_message
|
||||
test_extract_error_empty_body
|
||||
test_offer_reauth_yes
|
||||
test_offer_reauth_no
|
||||
test_offer_reauth_enter_defaults_yes
|
||||
|
||||
echo ""
|
||||
echo "Results: $PASS passed, $FAIL failed"
|
||||
[ "$FAIL" -eq 0 ] && exit 0 || exit 1
|
||||
|
||||
Reference in New Issue
Block a user