Files
pipelines/internal/codex/shell_metadata_test.go
T

39 lines
1.7 KiB
Go

package codex
import (
"encoding/json"
"testing"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
func TestCommandLifecycleUsesRecordedTimingAndKeepsItAcrossReadback(t *testing.T) {
c := &Chat{subs: map[string]map[chan protocol.ChatEventFrame]struct{}{}}
c.handleNotification(rpcMessage{Method: "item/started", Params: json.RawMessage(`{"threadId":"thread","turnId":"turn","startedAtMs":1793870280123,"item":{"id":"cmd","type":"commandExecution","command":"sleep 30","status":"inProgress"}}`)})
c.recordCommand("thread", item{ID: "cmd", Command: "sleep 30", Status: "inProgress"}, false)
id := codexShellID("thread", "cmd")
c.mu.Lock()
task := c.commands["thread"][id].shell
c.mu.Unlock()
if task.StartedAt != 1793870280123 || task.TaskType != "command" || task.UpdatedAt != 0 {
t.Fatalf("start=%+v", task)
}
c.handleNotification(rpcMessage{Method: "item/completed", Params: json.RawMessage(`{"threadId":"thread","turnId":"turn","completedAtMs":1793870310123,"item":{"id":"cmd","type":"commandExecution","command":"sleep 30","status":"completed","durationMs":30000}}`)})
c.mu.Lock()
task = c.commands["thread"][id].shell
c.mu.Unlock()
if task.StartedAt != 1793870280123 || task.UpdatedAt != 1793870310123 || task.DurationMS == nil || *task.DurationMS != 30000 || task.Status != protocol.ChatShellExited {
t.Fatalf("completion=%+v", task)
}
}
func TestHistoricalCommandDoesNotInventAStart(t *testing.T) {
c := &Chat{}
duration := int64(1200)
c.recordCommand("thread", item{ID: "cmd", Status: "inProgress", DurationMS: &duration}, false)
task := c.commands["thread"][codexShellID("thread", "cmd")].shell
if task.StartedAt != 0 || task.UpdatedAt != 0 || task.DurationMS == nil || *task.DurationMS != 1200 {
t.Fatalf("history=%+v", task)
}
}