1package subagents
2
3import (
4 "testing"
5 "time"
6)
7
8func TestTurnClassificationUsesStableBoundaryFieldsAcrossProtocolVersions(t *testing.T) {
9 cases := []struct {
10 name string
11 event Event
12 class turnEventClass
13 delegated bool
14 }{
15 {
16 name: "current delegated",
17 event: NewEvent(EventTurnStarted, map[string]any{
18 "lifetime_turns": 4,
19 "current_run_turns": 2,
20 }),
21 class: turnEventDelegated,
22 delegated: true,
23 },
24 {
25 name: "current nested",
26 event: NewEvent(EventTurnStarted, map[string]any{
27 "nested_turn": true,
28 "step": 3,
29 }),
30 class: turnEventNested,
31 },
32 {
33 name: "protocol v1 delegated fallback",
34 event: Event{Type: EventTurnStarted, Version: 1, Time: time.Now()},
35 class: turnEventDelegated,
36 delegated: true,
37 },
38 {
39 name: "protocol v1 nested turn_start",
40 event: Event{Type: "turn_start", Version: 1, Time: time.Now()},
41 class: turnEventNested,
42 },
43 }
44 for _, tc := range cases {
45 t.Run(tc.name, func(t *testing.T) {
46 if got := classifyTurnEvent(tc.event); got != tc.class {
47 t.Fatalf("classifyTurnEvent = %d, want %d", got, tc.class)
48 }
49 if got := isDelegatedTurnStart(tc.event); got != tc.delegated {
50 t.Fatalf("isDelegatedTurnStart = %v, want %v", got, tc.delegated)
51 }
52 })
53 }
54}
55
56func TestTurnClassificationKeepsNestedAndDelegatedEndsSeparate(t *testing.T) {
57 if isDelegatedTurnEnd(NewEvent("turn_end", map[string]any{"stop": "tool_use"})) {
58 t.Fatal("provider turn_end was classified as delegated")
59 }
60 if !isDelegatedTurnEnd(NewEvent("turn_end", map[string]any{"step": 2})) {
61 t.Fatal("worker turn_end was not classified as delegated")
62 }
63}