62 lines
3.2 KiB
Bash
Executable File
62 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
|
|
|
test_tmp=$(mktemp -d)
|
|
trap 'rm -rf "$test_tmp"' EXIT
|
|
|
|
mkdir -p "$test_tmp/bin" "$test_tmp/home/.claude"
|
|
cat >"$test_tmp/bin/gum" <<'SH'
|
|
#!/bin/bash
|
|
count=$(($(cat "$GUM_COUNT") + 1))
|
|
printf '%s' "$count" >"$GUM_COUNT"
|
|
sed -n "${count}p" "$GUM_SCRIPT"
|
|
SH
|
|
chmod +x "$test_tmp/bin/gum"
|
|
export PATH="$test_tmp/bin:$PATH" HOME="$test_tmp/home" GUM_COUNT="$test_tmp/count" GUM_SCRIPT="$test_tmp/script"
|
|
|
|
settings="$HOME/.claude/settings.json"
|
|
run_setup() {
|
|
printf '%s\n' "$@" >"$GUM_SCRIPT"
|
|
printf '0' >"$GUM_COUNT"
|
|
"$ROOT/bin/omarchy-setup-claude-api" >/dev/null
|
|
}
|
|
|
|
echo '{"theme":"dark","env":{"KEEP_ME":"1"}}' >"$settings"
|
|
chmod 644 "$settings"
|
|
install -m 644 /dev/null "$settings.tmp"
|
|
echo '{"userID":"abc"}' >"$HOME/.claude.json"
|
|
run_setup DeepSeek sk-test "deepseek-flash[1m]"
|
|
|
|
expected='{"ANTHROPIC_AUTH_TOKEN":"sk-test","ANTHROPIC_BASE_URL":"https://api.deepseek.com/anthropic","ANTHROPIC_DEFAULT_HAIKU_MODEL":"deepseek-flash[1m]","ANTHROPIC_DEFAULT_OPUS_MODEL":"deepseek-flash[1m]","ANTHROPIC_DEFAULT_SONNET_MODEL":"deepseek-flash[1m]","ANTHROPIC_MODEL":"deepseek-flash[1m]","CLAUDE_CODE_SUBAGENT_MODEL":"deepseek-flash[1m]","KEEP_ME":"1"}'
|
|
[[ $(jq -cS .env "$settings") == "$expected" ]] || fail "DeepSeek writes the base URL, key and model for every tier" "$(jq -cS .env "$settings")"
|
|
[[ $(jq -r .theme "$settings") == "dark" ]] || fail "setup keeps unrelated Claude settings"
|
|
[[ $(stat -c %a "$settings") == "600" ]] || fail "the settings holding the key are private"
|
|
[[ $(jq -cS . "$HOME/.claude.json") == '{"hasCompletedOnboarding":true,"userID":"abc"}' ]] || fail "setup skips Anthropic sign-in and keeps Claude state"
|
|
pass "a provider preset writes Claude Code's env and skips Anthropic sign-in"
|
|
|
|
run_setup Custom https://example.com/anthropic sk-custom my-model
|
|
[[ $(jq -r '.env.ANTHROPIC_BASE_URL + " " + .env.ANTHROPIC_MODEL + " " + .env.ANTHROPIC_DEFAULT_HAIKU_MODEL' "$settings") == "https://example.com/anthropic my-model my-model" ]] ||
|
|
fail "Custom uses the typed base URL and model"
|
|
pass "Custom uses the typed base URL and model"
|
|
|
|
if run_setup Custom "" sk-custom my-model 2>/dev/null; then
|
|
fail "setup refuses an empty base URL"
|
|
fi
|
|
[[ $(jq -r .env.ANTHROPIC_MODEL "$settings") == "my-model" ]] || fail "a refused setup leaves the previous config"
|
|
pass "setup refuses an empty base URL and keeps the previous config"
|
|
|
|
"$ROOT/bin/omarchy-setup-claude-api" --remove >/dev/null
|
|
[[ $(jq -cS . "$settings") == '{"env":{"KEEP_ME":"1"},"theme":"dark"}' ]] || fail "remove deletes only the API setup" "$(jq -cS . "$settings")"
|
|
jq 'del(.env)' "$settings" >"$settings.tmp" && mv "$settings.tmp" "$settings"
|
|
run_setup MiniMax sk-mm "MiniMax-M3[1m]"
|
|
"$ROOT/bin/omarchy-setup-claude-api" --remove >/dev/null
|
|
[[ $(jq -cS . "$settings") == '{"theme":"dark"}' ]] || fail "remove drops an env it emptied" "$(jq -cS . "$settings")"
|
|
pass "remove deletes only the keys setup wrote"
|
|
|
|
grep -F '"setup.claude-api"' "$ROOT/default/omarchy/omarchy-menu.jsonc" | grep -qF '"when":"[[ \"$(omarchy-region)\" == \"China\" ]]"' ||
|
|
fail "the Claude Code API entry shows only in China"
|
|
pass "the Claude Code API entry shows only in China"
|