AI default/tests: env-passed key, secure creation, harness install, isolated strict mocks
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QKxGW1raAWaqeU8WdHsMsp
This commit is contained in:
+22
-11
@@ -29,6 +29,13 @@ codex) agent="codex" ;;
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
command=$(cn_ai_harness_field "$harness" command)
|
||||||
|
if ! command -v "$command" > /dev/null 2>&1; then
|
||||||
|
install=$(cn_ai_harness_field "$harness" install)
|
||||||
|
echo "Installing $harness: $install"
|
||||||
|
$install
|
||||||
|
fi
|
||||||
|
|
||||||
key=$(omarchy-cn-ai-secret get "$provider")
|
key=$(omarchy-cn-ai-secret get "$provider")
|
||||||
|
|
||||||
case "$harness" in
|
case "$harness" in
|
||||||
@@ -44,17 +51,21 @@ claude-code)
|
|||||||
current=$(cat "$settings")
|
current=$(cat "$settings")
|
||||||
cp "$settings" "$settings.omarchycn-bak-$(date +%Y%m%d-%H%M%S)"
|
cp "$settings" "$settings.omarchycn-bak-$(date +%Y%m%d-%H%M%S)"
|
||||||
fi
|
fi
|
||||||
jq --arg base "$base" --arg key "$key" --arg model "$model" --arg fast "$fast" \
|
# Key reaches jq via environment, never the argument list
|
||||||
'.env = (.env // {}) + {
|
rm -f "$settings.omarchycn-new"
|
||||||
ANTHROPIC_BASE_URL: $base,
|
(
|
||||||
ANTHROPIC_AUTH_TOKEN: $key,
|
umask 077
|
||||||
ANTHROPIC_API_KEY: $key,
|
CN_AI_KEY="$key" jq --arg base "$base" --arg model "$model" --arg fast "$fast" \
|
||||||
ANTHROPIC_MODEL: $model,
|
'.env = (.env // {}) + {
|
||||||
ANTHROPIC_DEFAULT_SONNET_MODEL: $model,
|
ANTHROPIC_BASE_URL: $base,
|
||||||
ANTHROPIC_DEFAULT_OPUS_MODEL: $model,
|
ANTHROPIC_AUTH_TOKEN: env.CN_AI_KEY,
|
||||||
ANTHROPIC_DEFAULT_HAIKU_MODEL: $fast
|
ANTHROPIC_API_KEY: env.CN_AI_KEY,
|
||||||
}' <<<"$current" > "$settings.omarchycn-new"
|
ANTHROPIC_MODEL: $model,
|
||||||
chmod 600 "$settings.omarchycn-new"
|
ANTHROPIC_DEFAULT_SONNET_MODEL: $model,
|
||||||
|
ANTHROPIC_DEFAULT_OPUS_MODEL: $model,
|
||||||
|
ANTHROPIC_DEFAULT_HAIKU_MODEL: $fast
|
||||||
|
}' <<<"$current" > "$settings.omarchycn-new"
|
||||||
|
)
|
||||||
mv "$settings.omarchycn-new" "$settings"
|
mv "$settings.omarchycn-new" "$settings"
|
||||||
;;
|
;;
|
||||||
codex)
|
codex)
|
||||||
|
|||||||
@@ -19,6 +19,17 @@ cleanup() {
|
|||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
export HOME="$TEST_HOME"
|
export HOME="$TEST_HOME"
|
||||||
|
|
||||||
|
# Force the file backend: production Secret Service / pass must never be touched
|
||||||
|
mkdir -p "$TEST_HOME/stubs"
|
||||||
|
printf '#!/bin/bash
|
||||||
|
exit 1
|
||||||
|
' > "$TEST_HOME/stubs/secret-tool"
|
||||||
|
printf '#!/bin/bash
|
||||||
|
exit 1
|
||||||
|
' > "$TEST_HOME/stubs/pass"
|
||||||
|
chmod +x "$TEST_HOME/stubs/secret-tool" "$TEST_HOME/stubs/pass"
|
||||||
|
export PATH="$TEST_HOME/stubs:$PATH"
|
||||||
|
|
||||||
# Registries parse and carry the P0 providers and harnesses
|
# Registries parse and carry the P0 providers and harnesses
|
||||||
for reg in ai-providers ai-harnesses ai-compatibility; do
|
for reg in ai-providers ai-harnesses ai-compatibility; do
|
||||||
jq -e . "$ROOT/cn/registry/$reg.json" > /dev/null || fail "$reg.json parses"
|
jq -e . "$ROOT/cn/registry/$reg.json" > /dev/null || fail "$reg.json parses"
|
||||||
@@ -91,11 +102,15 @@ python3 - "$port" <<'PYEOF' &
|
|||||||
import http.server, sys
|
import http.server, sys
|
||||||
class H(http.server.BaseHTTPRequestHandler):
|
class H(http.server.BaseHTTPRequestHandler):
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
self.rfile.read(int(self.headers.get("Content-Length", 0)))
|
body = self.rfile.read(int(self.headers.get("Content-Length", 0)))
|
||||||
key = self.headers.get("x-api-key") or (self.headers.get("Authorization") or "").replace("Bearer ", "")
|
key = self.headers.get("x-api-key") or (self.headers.get("Authorization") or "").replace("Bearer ", "")
|
||||||
if key != "sk-secret-1":
|
if key != "sk-secret-1":
|
||||||
code = 401
|
code = 401
|
||||||
elif self.path in ("/v1/messages", "/responses", "/chat/completions"):
|
elif self.path == "/v1/messages" and b"messages" in body and self.headers.get("anthropic-version"):
|
||||||
|
code = 200
|
||||||
|
elif self.path == "/responses" and b"input" in body and b"messages" not in body:
|
||||||
|
code = 200
|
||||||
|
elif self.path == "/chat/completions" and b"messages" in body:
|
||||||
code = 200
|
code = 200
|
||||||
else:
|
else:
|
||||||
code = 404
|
code = 404
|
||||||
@@ -122,6 +137,10 @@ fi
|
|||||||
pass "mock regression: 200 pass, 401 fail, responses path exercised"
|
pass "mock regression: 200 pass, 401 fail, responses path exercised"
|
||||||
|
|
||||||
# ai-default merges into claude settings without clobbering user config
|
# ai-default merges into claude settings without clobbering user config
|
||||||
|
printf '#!/bin/bash
|
||||||
|
exit 0
|
||||||
|
' > "$TEST_HOME/stubs/claude"
|
||||||
|
chmod +x "$TEST_HOME/stubs/claude"
|
||||||
echo "sk-secret-1" | omarchy-cn-ai-secret set deepseek > /dev/null
|
echo "sk-secret-1" | omarchy-cn-ai-secret set deepseek > /dev/null
|
||||||
mkdir -p "$HOME/.claude"
|
mkdir -p "$HOME/.claude"
|
||||||
printf '{"permissions":{"allow":["Bash"]},"env":{"KEEP":"1"}}' > "$HOME/.claude/settings.json"
|
printf '{"permissions":{"allow":["Bash"]},"env":{"KEEP":"1"}}' > "$HOME/.claude/settings.json"
|
||||||
@@ -130,4 +149,5 @@ omarchy-cn-ai-default good > /dev/null
|
|||||||
[[ $(jq -r '.permissions.allow[0]' "$HOME/.claude/settings.json") == Bash ]] || fail "ai-default preserves permissions"
|
[[ $(jq -r '.permissions.allow[0]' "$HOME/.claude/settings.json") == Bash ]] || fail "ai-default preserves permissions"
|
||||||
[[ $(jq -r '.env.ANTHROPIC_BASE_URL' "$HOME/.claude/settings.json") == "https://api.deepseek.com/anthropic" ]] || fail "ai-default env written"
|
[[ $(jq -r '.env.ANTHROPIC_BASE_URL' "$HOME/.claude/settings.json") == "https://api.deepseek.com/anthropic" ]] || fail "ai-default env written"
|
||||||
[[ $(cat "$HOME/.config/omarchy/defaults/agent") == claude ]] || fail "upstream default agent set"
|
[[ $(cat "$HOME/.config/omarchy/defaults/agent") == claude ]] || fail "upstream default agent set"
|
||||||
|
[[ $(stat -c %a "$HOME/.claude/settings.json") == 600 ]] || fail "claude settings 0600"
|
||||||
pass "ai-default maps the profile onto the upstream agent entry"
|
pass "ai-default maps the profile onto the upstream agent entry"
|
||||||
|
|||||||
Reference in New Issue
Block a user