A plain HTTP entry carries no bearer; Claude Code then attempts OAuth dynamic client registration against ai-memory and fails. The stdio bridge reads [auth].bearer_token_file from the client config. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
63 lines
2.9 KiB
Bash
Executable File
63 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Eval checks for coding.aiMemory against m3-kratos in nixos-config, using
|
|
# this checkout of m3ta-home. Usage: ai-memory.test.sh [path/to/nixos-config]
|
|
set -euo pipefail
|
|
|
|
home_repo="$(cd "$(dirname "$0")/../../../.." && pwd)"
|
|
nixos_repo="${1:-$home_repo/../nixos-config}"
|
|
hm="#nixosConfigurations.m3-kratos.config.home-manager.users.m3tam3re"
|
|
fail=0
|
|
|
|
ev() { # attr [extra nix eval args...]
|
|
local attr="$1"; shift
|
|
nix eval --raw --override-input m3ta-home "path:$home_repo" "$nixos_repo$hm.$attr" "$@" 2>/dev/null
|
|
}
|
|
|
|
check() { # name, haystack, needle
|
|
if [[ "$2" == *"$3"* ]]; then echo "ok $1"; else echo "FAIL $1: missing '$3'"; fail=1; fi
|
|
}
|
|
refute() { # name, haystack, needle
|
|
if [[ "$2" == *"$3"* ]]; then echo "FAIL $1: found '$3'"; fail=1; else echo "ok $1"; fi
|
|
}
|
|
|
|
check "server url" "$(ev home.sessionVariables.AI_MEMORY_SERVER_URL)" "https://memory.m3ta.dev"
|
|
|
|
conf="$(ev 'home.file.".local/share/ai-memory/config.toml".text')"
|
|
check "client config server_url" "$conf" 'server_url = "https://memory.m3ta.dev"'
|
|
check "client config token file" "$conf" 'bearer_token_file = "/run/agenix/ai-memory-token"'
|
|
|
|
mcp="$(ev programs.mcp.servers.ai-memory.args --apply 'builtins.concatStringsSep " "')"
|
|
check "mcp bridge" "$mcp" "mcp-bridge --no-session-id --server-url https://memory.m3ta.dev/mcp"
|
|
refute "mcp carries no token" "$mcp" "ai-memory-token"
|
|
|
|
opencode="$(cat "$(nix build --no-link --print-out-paths --override-input m3ta-home "path:$home_repo" \
|
|
"$nixos_repo$hm.xdg.configFile.\"opencode/opencode.json\".source" 2>/dev/null)")"
|
|
check "opencode gets mcp" "$opencode" "mcp-bridge"
|
|
|
|
marker="$(ev 'home.file.".ai-memory.toml".text')"
|
|
check "home marker workspace" "$marker" 'workspace = "private"'
|
|
check "marker section" "$marker" "[capture]"
|
|
for p in "/run/agenix/**" "~/.config/sops/**" "~/.ssh/**" "**/.env*"; do
|
|
check "marker $p" "$marker" "\"$p\""
|
|
done
|
|
|
|
az="$(ev 'home.file."p/AZ/.ai-memory.toml".text' 2>/dev/null || true)"
|
|
check "AZ marker workspace" "$az" 'workspace = "az"'
|
|
check "AZ marker repeats capture" "$az" "[capture]"
|
|
|
|
act="$(ev home.activation.aiMemoryInstall.data)"
|
|
check "hooks claude-code" "$act" "install-hooks --agent claude-code --apply"
|
|
check "hooks opencode2" "$act" "install-hooks --agent opencode2 --apply"
|
|
check "auth-token symlink" "$act" "ln -sfn /run/agenix/ai-memory-token "
|
|
refute "no token on command lines" "$act" "--auth-token"
|
|
refute "activation must not write opencode.json (home-manager symlink)" "$act" "install-mcp --client opencode"
|
|
check "claude mcp is the session-aware bridge" "$act" "install-mcp --client claude-code --apply --session-aware"
|
|
|
|
# Missing token file: skip with a warning, exit 0, never call ai-memory.
|
|
script="$(printf '%s\n' "$act" | sed 's|/run/agenix/ai-memory-token|/nonexistent/ai-memory-token|g')"
|
|
out="$(run() { echo "CALLED $*"; }; eval "$script" 2>&1)"
|
|
check "skip warning" "$out" "token file /nonexistent/ai-memory-token missing, skipping"
|
|
refute "no installer without token" "$out" "CALLED"
|
|
|
|
exit "$fail"
|