Files
pipelines/internal/server/chat_lost_end_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

90 lines
2.9 KiB
Go

package server
import (
"context"
"path/filepath"
"sync"
"testing"
"time"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
// reportingChat is an observedChat that also reports its turn state without
// I/O, as Claude Code does.
type reportingChat struct {
*observedChat
rmu sync.Mutex
running bool
}
func (c *reportingChat) TurnRunning(string) bool {
c.rmu.Lock()
defer c.rmu.Unlock()
return c.running
}
// Prompt starts a turn, as Claude Code's does before it returns.
func (c *reportingChat) Prompt(ctx context.Context, sessionID, text string) error {
if err := c.observedChat.Prompt(ctx, sessionID, text); err != nil {
return err
}
c.setRunning(true)
return nil
}
func (c *reportingChat) setRunning(running bool) {
c.rmu.Lock()
c.running = running
c.rmu.Unlock()
}
// The live incident: a Claude turn's end frame was dropped on the way (a full
// watcher buffer), so the room's own turn stayed "working" forever and every
// later prompt queued behind it. Once the harness reports itself idle for the
// settle period and its probe agrees, the turn is ended, the client told to
// resync, and the queued prompt delivered. While it reports running, it waits.
func TestChatRunnerEndsItsTurnWhoseEndFrameWasLost(t *testing.T) {
fastUnattended(t)
fastStaleTurnSettle(t)
store := openQueueStore(t, filepath.Join(t.TempDir(), "queue.db"))
broker := &reportingChat{observedChat: newObservedChat()}
server := startQueueServer(t, broker, store)
conn := dialChatConn(t, server.ctx, server.srv)
broker.setProbe(true)
sendPrompt(t, server.ctx, conn, "p1", "build it", "op-1")
waitFor(t, "first prompt", func() bool { return broker.promptCount() == 1 })
broker.push(stepFrameFor(protocol.ChatStepStarted, "turn_1"))
waitStepFrame(t, server.ctx, conn, protocol.ChatStepStarted, "turn_1")
if ack := sendPrompt(t, server.ctx, conn, "p2", "continue", "op-2"); !ack.ChatQueued {
t.Fatalf("second prompt was not queued behind the running turn: %+v", ack)
}
time.Sleep(4 * chatQueueStaleTurnSettle)
if n := broker.promptCount(); n != 1 {
t.Fatalf("prompt delivered while the harness reports its turn running: %v", broker.promptTexts())
}
// The turn ends in the harness, but its end frame never arrives.
broker.setRunning(false)
broker.setProbe(false)
sawResync := false
for {
message := readChatMessage(t, server.ctx, conn)
if message.Type != protocol.ChatEvent || message.ChatEvent == nil {
continue
}
if message.ChatEvent.Kind == protocol.ChatEventResync {
sawResync = true
}
if step := message.ChatEvent.Step; step != nil && step.Status == protocol.ChatStepEnded && step.TurnID == "turn_1" {
break
}
}
if !sawResync {
t.Fatal("the client was not told to resync after the lost end")
}
waitFor(t, "queued prompt delivered after the lost end", func() bool { return broker.promptCount() == 2 })
if texts := broker.promptTexts(); texts[1] != "continue" {
t.Fatalf("delivered = %v", texts)
}
}