Files
pipelines/internal/codex/detach_test.go
T
alan a627b38ef3 Merge main; use the shared chatShutdownDetacher for OpenCode and Codex
OpenCode and Codex chats implement Detach (called by chatManager.Close)
instead of a parallel DetachSessions interface. Docs follow the Claude Code
host and the systemd KillMode=process unit. The opt-in live restart check
copies only the stage provider's login row into its scratch OpenCode
database, builds the CLI for skill install and removes its scratch tree.
2026-11-04 16:24:17 +00:00

49 lines
1.5 KiB
Go

package codex
import (
"context"
"encoding/json"
"sync"
"sync/atomic"
"testing"
)
// A server restart detaches from the App Server without interrupting the
// thread's turn; the next server's fresh connection still sees the turn in
// progress, then completed, through the read-only turn list.
func TestDetachLeavesTurnRunningForNextConnection(t *testing.T) {
var completed atomic.Bool
var mu sync.Mutex
var methods []string
appServer := func(method string, _ json.RawMessage) any {
mu.Lock()
methods = append(methods, method)
mu.Unlock()
status := "inProgress"
if completed.Load() {
status = "completed"
}
return json.RawMessage(`{"data":[{"id":"turn","status":"` + status + `","items":[]}],"nextCursor":null}`)
}
before := modelTestChat(t, appServer)
if running, err := before.ProbeTurn(context.Background(), fixtureThread); err != nil || !running {
t.Fatalf("turn not running before the restart: %v %v", running, err)
}
before.Detach()
after := modelTestChat(t, appServer)
if running, err := after.ProbeTurn(context.Background(), fixtureThread); err != nil || !running {
t.Fatalf("turn did not survive the restart: %v %v", running, err)
}
completed.Store(true) // finished while nobody was watching
if running, err := after.ProbeTurn(context.Background(), fixtureThread); err != nil || running {
t.Fatalf("completed turn still reported running: %v %v", running, err)
}
mu.Lock()
defer mu.Unlock()
for _, method := range methods {
if method == "turn/interrupt" {
t.Fatalf("detaching interrupted the turn: %v", methods)
}
}
}