#!/usr/bin/env bats # agent-page — the runtime-neutral phone pager. Pages Craig over Signal from # any machine on the tailnet: sends directly wherever the pager account is # registered locally (velox, or any linked device), and ssh-relays to velox # from a machine that doesn't hold the account. These tests stub # ssh/signal-cli on PATH to verify command construction without a network or # a phone. The signal-cli stub answers `listAccounts` to control which branch # the dispatch takes. 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" <> "$LOG" exit 0 EOF # HAS_ACCOUNT controls the listAccounts answer: "1" → the pager account is # local (send direct), unset/"0" → not local (relay). cat > "$STUBS/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 when the account is not local" { HAS_ACCOUNT=0 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 "sends directly (no ssh) when the pager account is registered locally" { HAS_ACCOUNT=1 PATH="$STUBS:$PATH" run bash "$PAGE" hello [ "$status" -eq 0 ] grep -q "^signal-cli -a +15045173983 send " "$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" HAS_ACCOUNT=0 PATH="$STUBS:$PATH" run bash "$PAGE" urgent thing [ "$status" -ne 0 ] [[ "$output" == *"notify"* ]] }