Files
tutti/packages/agent/store-sqlite/activity_state_read_test.go
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

74 lines
2.5 KiB
Go

package storesqlite
import (
"context"
"testing"
)
func TestGetAgentStateComposesCanonicalSessionsWithLatestTurns(t *testing.T) {
t.Parallel()
store := openTestStore(t, testOptions(&staticProjectPaths{}))
ctx := context.Background()
for _, report := range []ActivityStateReport{
{
Session: SessionStateReport{
WorkspaceID: "ws-state", AgentSessionID: "session-with-turn", Kind: SessionKindRoot,
Origin: "runtime", Provider: "codex", Status: "working", OccurredAtUnixMS: 20,
},
Turn: &TurnTransition{
WorkspaceID: "ws-state", AgentSessionID: "session-with-turn", TurnID: "turn-latest",
Phase: TurnPhaseRunning, StartedAtUnixMS: 20, OccurredAtUnixMS: 20,
},
},
{
Session: SessionStateReport{
WorkspaceID: "ws-state", AgentSessionID: "session-without-turn", Kind: SessionKindRoot,
Origin: "runtime", Provider: "claude-code", Status: "idle", OccurredAtUnixMS: 10,
},
},
} {
if _, err := store.ReportActivityState(ctx, report); err != nil {
t.Fatalf("ReportActivityState(%s) error = %v", report.Session.AgentSessionID, err)
}
}
if _, err := store.db.ExecContext(ctx, `
INSERT INTO workspace_agent_turns (
workspace_id, agent_session_id, turn_id, phase, outcome,
started_at_unix_ms, settled_at_unix_ms, created_at_unix_ms, updated_at_unix_ms
) VALUES ('ws-state', 'session-with-turn', 'turn-older', 'settled', 'completed', 1, 1, 1, 1)
`); err != nil {
t.Fatalf("insert older turn: %v", err)
}
state, ok, err := store.GetAgentState(ctx, " ws-state ")
if err != nil || !ok {
t.Fatalf("GetAgentState() ok=%v error=%v", ok, err)
}
if state.WorkspaceID != "ws-state" || len(state.Sessions) != 2 {
t.Fatalf("GetAgentState() = %#v", state)
}
bySessionID := make(map[string]AgentSessionState, len(state.Sessions))
for _, sessionState := range state.Sessions {
bySessionID[sessionState.Session.ID] = sessionState
}
withTurn := bySessionID["session-with-turn"]
if withTurn.LatestTurn == nil || withTurn.LatestTurn.TurnID != "turn-latest" {
t.Fatalf("session-with-turn state = %#v", withTurn)
}
withoutTurn := bySessionID["session-without-turn"]
if withoutTurn.LatestTurn != nil {
t.Fatalf("session-without-turn state = %#v", withoutTurn)
}
}
func TestGetAgentStateRejectsBlankWorkspace(t *testing.T) {
t.Parallel()
store := openTestStore(t, testOptions(&staticProjectPaths{}))
state, ok, err := store.GetAgentState(context.Background(), " ")
if err != nil || ok || len(state.Sessions) != 0 {
t.Fatalf("GetAgentState(blank) state=%#v ok=%v error=%v", state, ok, err)
}
}