#!/usr/bin/env bats # The ai launcher's --runtime flag: pick the agent CLI (claude, codex) that # a project window launches. Part of the generic-agent-runtime arc — the # tmux-side counterpart of .emacs.d's ai-term multi-LLM handoff. The # --print-launch mode exists for exactly these tests: it prints the launch # command a real run would send to the pane, without touching tmux or fzf. setup() { REPO_ROOT="$(cd "$(dirname "$BATS_TEST_FILENAME")/../.." && pwd)" AI="$REPO_ROOT/claude-templates/bin/ai" PROJ="$(mktemp -d)" mkdir -p "$PROJ/.ai" touch "$PROJ/.ai/protocols.org" STUB_BIN="$(mktemp -d)" } teardown() { rm -rf "$PROJ" "$STUB_BIN" } @test "default runtime launches claude" { run bash "$AI" --print-launch "$PROJ" [ "$status" -eq 0 ] [[ "$output" == claude\ * ]] [[ "$output" == *"protocols.org"* ]] } @test "--runtime codex launches codex with the same opening line" { run bash "$AI" --runtime codex --print-launch "$PROJ" [ "$status" -eq 0 ] [[ "$output" == codex\ * ]] [[ "$output" == *"protocols.org"* ]] [[ "$output" == *"$(basename "$PROJ")"* ]] } @test "AI_RUNTIME env selects the runtime without the flag" { AI_RUNTIME=codex run bash "$AI" --print-launch "$PROJ" [ "$status" -eq 0 ] [[ "$output" == codex\ * ]] } @test "--runtime local launches codex --oss over ollama with the default local model" { run bash "$AI" --runtime local --print-launch "$PROJ" [ "$status" -eq 0 ] [[ "$output" == "codex --oss --local-provider=ollama -m gpt-oss:120b "* ]] [[ "$output" == *"protocols.org"* ]] } @test "AI_LOCAL_MODEL overrides the local runtime's model" { AI_LOCAL_MODEL=qwen3-coder:30b run bash "$AI" --runtime local --print-launch "$PROJ" [ "$status" -eq 0 ] [[ "$output" == "codex --oss --local-provider=ollama -m qwen3-coder:30b "* ]] } @test "an unknown runtime errors and names the valid ones" { run bash "$AI" --runtime frobnitz --print-launch "$PROJ" [ "$status" -eq 2 ] [[ "$output" == *"claude"* ]] [[ "$output" == *"codex"* ]] } @test "--print-launch refuses a non-project directory" { run bash "$AI" --print-launch "$BATS_TEST_TMPDIR" [ "$status" -eq 1 ] [[ "$output" == *"protocols.org"* ]] } @test "--print-runtimes lists claude, codex, and one line per ollama model" { cat > "$STUB_BIN/ollama" <<'STUB' #!/bin/bash if [ "$1" = "list" ]; then printf 'NAME ID SIZE MODIFIED\n' printf 'gpt-oss:120b aaa 65 GB 1 hour ago\n' printf 'qwen3-coder:30b bbb 18 GB 1 hour ago\n' fi STUB chmod +x "$STUB_BIN/ollama" PATH="$STUB_BIN:$PATH" run bash "$AI" --print-runtimes [ "$status" -eq 0 ] [ "${lines[0]%% *}" = "claude" ] [[ "$output" == *"codex"* ]] [[ "$output" == *"local:gpt-oss:120b"* ]] [[ "$output" == *"local:qwen3-coder:30b"* ]] } @test "a dead ollama server just drops the local lines" { cat > "$STUB_BIN/ollama" <<'STUB' #!/bin/bash echo "Error: could not connect to a running Ollama instance" >&2 exit 1 STUB chmod +x "$STUB_BIN/ollama" PATH="$STUB_BIN:$PATH" run bash "$AI" --print-runtimes [ "$status" -eq 0 ] [[ "$output" == *"claude"* ]] [[ "$output" != *"local:"* ]] }