aboutsummaryrefslogtreecommitdiff
path: root/scripts/tests/agent-page.bats
blob: 071e4b9df8909e66bcf8529c40824e52f37c93da (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
#!/usr/bin/env bats
# agent-page — the runtime-neutral phone pager. Pages Craig over Signal from
# any machine on the tailnet: runs signal-cli directly on velox (where the
# pager identity lives), ssh-relays to velox from everywhere else. These tests
# stub ssh/uname/signal-cli on PATH to verify command construction without a
# network or a phone.

setup() {
    REPO_ROOT="$(cd "$(dirname "$BATS_TEST_FILENAME")/../.." && pwd)"
    PAGE="$REPO_ROOT/claude-templates/bin/agent-page"
    STUBS="$(mktemp -d)"
    LOG="$STUBS/calls.log"
    cat > "$STUBS/ssh" <<EOF
#!/bin/bash
echo "ssh \$*" >> "$LOG"
exit 0
EOF
    cat > "$STUBS/signal-cli" <<EOF
#!/bin/bash
echo "signal-cli \$*" >> "$LOG"
exit 0
EOF
    chmod +x "$STUBS/ssh" "$STUBS/signal-cli"
}

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

@test "no message exits 2 with usage" {
    run bash "$PAGE"
    [ "$status" -eq 2 ]
    [[ "$output" == *"usage"* ]]
}

@test "relays through ssh to velox with the pager account and Craig's UUID" {
    PATH="$STUBS:$PATH" run bash "$PAGE" build finished
    [ "$status" -eq 0 ]
    grep -q "^ssh .*velox" "$LOG"
    grep -q "15045173983" "$LOG"
    grep -q "b1b5601e-6126-47f8-afaa-0a59f5188fde" "$LOG"
    # printf %q escapes the space, so the relayed message reads build\ finished.
    grep -qF 'build\ finished' "$LOG"
}

@test "on velox itself, calls signal-cli directly (no ssh)" {
    cat > "$STUBS/uname" <<'EOF'
#!/bin/bash
[ "$1" = "-n" ] && { echo velox; exit 0; }
exec /usr/bin/uname "$@"
EOF
    chmod +x "$STUBS/uname"
    PATH="$STUBS:$PATH" run bash "$PAGE" hello
    [ "$status" -eq 0 ]
    grep -q "^signal-cli " "$LOG"
    ! grep -q "^ssh " "$LOG"
}

@test "a failed relay reports the desktop fallback and propagates failure" {
    cat > "$STUBS/ssh" <<'EOF'
#!/bin/bash
exit 255
EOF
    chmod +x "$STUBS/ssh"
    PATH="$STUBS:$PATH" run bash "$PAGE" urgent thing
    [ "$status" -ne 0 ]
    [[ "$output" == *"notify"* ]]
}