aboutsummaryrefslogtreecommitdiff
path: root/scripts/tests/agent-text.bats
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-20 16:47:39 -0500
committerCraig Jennings <c@cjennings.net>2026-07-20 16:47:39 -0500
commit61454894349e75b593ede5901a7b348ad580d3ce (patch)
treeca88583c053049e53299612bbad632b39f466a9c /scripts/tests/agent-text.bats
parent302b062680c8fbd9743d4e083154ac5fc314955a (diff)
downloadrulesets-61454894349e75b593ede5901a7b348ad580d3ce.tar.gz
rulesets-61454894349e75b593ede5901a7b348ad580d3ce.zip
feat(notify): reserve "page me" for desktop, "text me" for Signal
"page me" and "text me" now name distinct channels: page is the desktop notification, text is the Signal phone push, and "text and page me" fires both. Before, "page me" defaulted to desktop and the phone was an unnamed "on my phone" variant, so you couldn't name the phone without naming the machine. I renamed the Signal tool agent-page to agent-text to match, with a deprecated agent-page shim delegating to it so callers and other machines don't break before their next install. The dispatch and tests are otherwise unchanged. I rewrote protocols.org "Reaching Craig", page-me.org, and work-the-backlog's away-run logic around the three phrasings, and updated the runbook.
Diffstat (limited to 'scripts/tests/agent-text.bats')
-rw-r--r--scripts/tests/agent-text.bats78
1 files changed, 78 insertions, 0 deletions
diff --git a/scripts/tests/agent-text.bats b/scripts/tests/agent-text.bats
new file mode 100644
index 0000000..e5d80fc
--- /dev/null
+++ b/scripts/tests/agent-text.bats
@@ -0,0 +1,78 @@
+#!/usr/bin/env bats
+# agent-text — the runtime-neutral Signal phone messenger ("text me"). Reaches
+# Craig over Signal from any machine on the tailnet: sends directly wherever the
+# 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. The final test covers the deprecated agent-page shim.
+
+setup() {
+ REPO_ROOT="$(cd "$(dirname "$BATS_TEST_FILENAME")/../.." && pwd)"
+ PAGE="$REPO_ROOT/claude-templates/bin/agent-text"
+ SHIM="$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
+ # HAS_ACCOUNT controls the listAccounts answer: "1" → the account is
+ # local (send direct), unset/"0" → not local (relay).
+ cat > "$STUBS/signal-cli" <<EOF
+#!/bin/bash
+if [ "\$1" = "listAccounts" ]; then
+ [ "\${HAS_ACCOUNT:-0}" = "1" ] && echo "Number: +15045173983"
+ exit 0
+fi
+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 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"* ]]
+}
+
+@test "the deprecated agent-page shim delegates to agent-text" {
+ HAS_ACCOUNT=1 PATH="$STUBS:$PATH" run bash "$SHIM" via shim
+ [ "$status" -eq 0 ]
+ # Reaches the same direct-send path as agent-text.
+ grep -q "^signal-cli -a +15045173983 send " "$LOG"
+}