Files
pipelines/internal/opencode/chat_probe_test.go
T
alan 80022ea41a Keep observing chats with an in-flight turn after the last client leaves
Chat attention notifications (questions, approvals, finished replies) come
from a session's event stream, which the hub only read while a room existed;
detach destroyed the room when the last client left, so a turn that finished
or asked with the app closed notified nobody.

A room whose last client leaves now stays observing, unattended, while its
turn is in flight or it holds an unanswered question/approval, and is torn
down when the turn ends (or after 6h for a stuck turn); at most 16 such rooms.
At server start, recently used open sessions whose harness reports a running
turn (OpenCode /api/session/active, Codex thread/turns/list) are observed
again so their reply still notifies. Settings, dedupe and app_notifications
recording are unchanged.
2026-11-02 16:07:42 +00:00

45 lines
1.2 KiB
Go

package opencode
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"sync/atomic"
"testing"
)
// ProbeTurn reads the active-session list; a failed or malformed read is an
// error, never "idle".
func TestChatProbeTurn(t *testing.T) {
var malformed atomic.Bool
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/session/active" {
http.NotFound(w, r)
return
}
w.Header().Set("Content-Type", "application/json")
if malformed.Load() {
fmt.Fprint(w, `{"data":null}`)
return
}
fmt.Fprint(w, `{"data":{"ses_1":{"type":"running"}}}`)
}))
defer srv.Close()
chat := NewChat(&Connection{Backend: "v2", URL: srv.URL})
ctx := context.Background()
if running, err := chat.ProbeTurn(ctx, "ses_1"); err != nil || !running {
t.Fatalf("active session: %v %v", running, err)
}
if running, err := chat.ProbeTurn(ctx, "ses_2"); err != nil || running {
t.Fatalf("idle session: %v %v", running, err)
}
malformed.Store(true)
if _, err := chat.ProbeTurn(ctx, "ses_1"); err == nil {
t.Fatal("malformed readback treated as idle")
}
if _, err := chat.ProbeTurn(ctx, "bad id"); err == nil {
t.Fatal("invalid id accepted")
}
}