blob: 3f0ad69c7b7aaa2b45fa1abdfca9a8bbce5c8550 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
#!/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:"* ]]
}
|