aboutsummaryrefslogtreecommitdiff
path: root/scripts/tests/ai-launcher-runtime.bats
blob: b93f7784dc88e535128816af03a07d8ab34919e8 (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
#!/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"
}

teardown() {
    rm -rf "$PROJ"
}

@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"* ]]
}