52 lines
2.1 KiB
Go
52 lines
2.1 KiB
Go
package server
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
)
|
|
|
|
func TestShellMetadataSurvivesPartialReplayAndUsesByteBudget(t *testing.T) {
|
|
turn := &chatTurn{}
|
|
task := protocol.ChatShell{ID: "task", Status: protocol.ChatShellRunning, Command: "sleep 30", StartedAt: 1793870280000, Description: "Review release", Progress: "Checking tests"}
|
|
turn.applyShell(&task)
|
|
size := protocol.ChatShellRetainedBytes(task)
|
|
if turn.size != size {
|
|
t.Fatalf("metadata not counted: size=%d want=%d", turn.size, size)
|
|
}
|
|
turn.applyShell(&protocol.ChatShell{ID: "task", Status: protocol.ChatShellRunning})
|
|
if turn.shells["task"].Command != "sleep 30" || turn.shells["task"].StartedAt != task.StartedAt || turn.shells["task"].Progress != "Checking tests" || turn.size != size {
|
|
t.Fatal("partial frame lost metadata/budget")
|
|
}
|
|
turn.applyShell(&protocol.ChatShell{ID: "task", Status: protocol.ChatShellRunning, Command: "sleep 30", Description: strings.Repeat("x", chatRetainedLimit)})
|
|
if !turn.overflow || turn.size != size {
|
|
t.Fatal("metadata bypassed byte cap")
|
|
}
|
|
turn.applyShell(&protocol.ChatShell{ID: "task", Status: protocol.ChatShellExited})
|
|
if turn.size != 0 || len(turn.shells) != 0 {
|
|
t.Fatal("exit did not release metadata budget")
|
|
}
|
|
}
|
|
|
|
func TestAuthoritativeShellReadbackPreservesKnownTiming(t *testing.T) {
|
|
hub := newChatHub()
|
|
task := protocol.ChatShell{ID: "task", Status: protocol.ChatShellRunning, Command: "sleep 30", StartedAt: 1793870280000, Description: "Review"}
|
|
hub.replaceShells("session", []protocol.ChatShell{task})
|
|
hub.replaceShells("session", []protocol.ChatShell{{ID: "task", Status: protocol.ChatShellRunning, Command: "sleep 30"}})
|
|
hub.mu.Lock()
|
|
turn := hub.turnLocked("session")
|
|
got := turn.shells["task"]
|
|
size := turn.size
|
|
hub.mu.Unlock()
|
|
if got.StartedAt != task.StartedAt || got.Description != "Review" || size != protocol.ChatShellRetainedBytes(task) {
|
|
t.Fatalf("readback lost timing: %+v size=%d", got, size)
|
|
}
|
|
hub.replaceShells("session", nil)
|
|
hub.mu.Lock()
|
|
defer hub.mu.Unlock()
|
|
if turn.size != 0 || len(turn.shells) != 0 {
|
|
t.Fatal("stale shell metadata remained after authoritative removal")
|
|
}
|
|
}
|