Files
pipelines/internal/server/chat_notify_ping_test.go
T
alan fc7dbb0ac0 Remove ntfy: notifications go only through the app notification stream
Server: drop ntfy publishing (stage hooks, run outbox, chat attention, chat
tool notify, auto-switch and schedule notices), the chat push outbox (its
table is dropped at startup), ntfy status/endpoints and PIPELINES_NTFY_*.
The app_notifications stream, subscribe/clear and kinds are unchanged.
Notification settings keep run_finished/chat_needs_you/chat_reply_finished;
ntfy_enabled is accepted and ignored and its stored row is never read.

Stage type=ntfy is rejected: "ntfy stages were removed; notifications go to
the Pipelines apps — use the stage notify hook". The notify hook remains.

Installer: no ntfy build, accounts, config or supervisor child; manifest
gets top-level "mode" (legacy ntfy.mode still read). Reinstall retires an
old ntfy (safe PID-file stop, deletes binary, config, data dir, token, log,
with a note in logs/install.log); uninstall cleans leftovers.

App: ntfy settings section replaced by "Notification events"; texts updated.
Docs: docs/ntfy.md folded into docs/notifications.md; install, docker, cli,
author skill references updated; security review M1 marked resolved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 23:24:24 +00:00

96 lines
3.6 KiB
Go

package server
import (
"context"
"testing"
"time"
"github.com/coder/websocket"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
// One turn, one ping: a turn that already sent an agent notify does not also
// announce its end, while a later turn without one does, and a notify sent
// after a turn ended (background work) does not silence the next turn.
func TestAgentNotifySuppressesThatTurnsReplyNotification(t *testing.T) {
store := newOperatorStore(t)
ctx := context.Background()
if _, err := store.UpdateNotificationSettings(ctx, map[string]any{protocol.NotifyChatReplyFinished: true}); err != nil {
t.Fatal(err)
}
h := chatAttentionHub(t, "ses_n")
h.settings = store
h.notes = newAppNotifier(store)
start := func(turn string) {
h.emit(protocol.ChatEventFrame{SessionID: "ses_n", Kind: protocol.ChatEventStep, Step: &protocol.ChatStep{Status: protocol.ChatStepStarted, TurnID: turn}})
}
end := func(turn string) {
h.emit(protocol.ChatEventFrame{SessionID: "ses_n", Kind: protocol.ChatEventStep, Step: &protocol.ChatStep{Status: protocol.ChatStepEnded, TurnID: turn}})
h.attentionWG.Wait()
}
kinds := func() []string {
t.Helper()
active, _, err := store.ActiveAppNotifications(ctx, "", time.Now())
if err != nil {
t.Fatal(err)
}
var got []string
for _, n := range active {
got = append(got, n.Kind+":"+n.Title)
}
return got
}
start("turn_1")
if got := h.publishToolNotification(ctx, "ses_n", chatToolNotice{ID: "n1", Title: "Halfway", Message: "Tests pass"}); !got.App {
t.Fatalf("delivery = %+v", got)
}
end("turn_1")
if got := kinds(); len(got) != 1 || got[0] != protocol.NotificationChatNotify+":Halfway" {
t.Fatalf("turn with a notify recorded %+v", got)
}
// Background work notifies after the turn; the next turn still announces.
h.publishToolNotification(ctx, "ses_n", chatToolNotice{ID: "n2", Title: "Deploy done", Message: "Live"})
start("turn_2")
end("turn_2")
got := kinds()
if len(got) != 3 || got[2] != protocol.NotificationChatReply+":Chat replied" {
t.Fatalf("later deliveries = %+v", got)
}
}
// Clearing a chat app notification on one device pushes the clear to every
// other connected client.
func TestClearingAChatNotificationClearsEveryClient(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
f := newAppNotificationFixture(t, ctx)
hub := f.handlerHub()
web, desktop, phone := dialAckClient(t, ctx, f.url), dialAckClient(t, ctx, f.url), dialAckClient(t, ctx, f.url)
subscribeNotifications(t, ctx, web, "")
subscribeNotifications(t, ctx, desktop, "")
subscribeNotifications(t, ctx, phone, "")
if got := hub.publishToolNotification(ctx, "ses_c", chatToolNotice{ID: "shown_c", Title: "Look", Message: "Now"}); !got.App {
t.Fatalf("delivery = %+v", got)
}
id := "chat:ses_c:notify:shown_c"
for _, conn := range []*websocket.Conn{web, desktop, phone} {
if push := readFrame(t, ctx, conn, protocol.NotificationPush).Notification; push == nil || push.ID != id {
t.Fatalf("push = %+v", push)
}
}
// Tapped on the phone: the phone gets the reply, every other client a push.
writeChat(t, ctx, phone, protocol.Message{Type: protocol.ClearNotifications, ID: "tap", IDs: []string{id}})
if reply := readFrame(t, ctx, phone, protocol.NotificationsCleared); reply.ID != "tap" || len(reply.IDs) != 1 || reply.IDs[0] != id {
t.Fatalf("phone reply = %+v", reply)
}
for name, conn := range map[string]*websocket.Conn{"web": web, "desktop": desktop} {
if push := readUntil(t, ctx, conn, protocol.NotificationsCleared); len(push.IDs) != 1 || push.IDs[0] != id {
t.Fatalf("%s cleared push = %+v", name, push)
}
}
}