test(tui): synchronize resident activity rendering
- commit
- dd4ecde0b98c20b2cef0e8a41666206ce90c1d97
- author
- brice · · 2026-08-20 14:09 UTC
- parent
- 9f470d3
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +32 -3
M packages/agent/modes/resident_subagent_indicator_test.go +32 -3
| @@ -51,7 +51,7 @@ func TestInteractiveResidentSubagentActivityRendersAllActiveChildrenWhenHeightAl | |||
| 51 | 51 | }, nil | |
| 52 | 52 | }) | |
| 53 | 53 | t.Cleanup(func() { _ = manager.Close(context.Background()) }) | |
| 54 | - | spawnResidentIndicatorChildren(t, manager, 10) | |
| 54 | + | spawnRunningResidentIndicatorChildren(t, manager, 10) | |
| 55 | 55 | ||
| 56 | 56 | term := &residentIndicatorTerminal{cols: 80, rows: 40} | |
| 57 | 57 | interactive := NewInteractive(InteractiveConfig{Terminal: term, ResidentManager: manager, Theme: tui.Dark}) | |
| @@ -86,7 +86,7 @@ func TestInteractiveResidentSubagentActivitySummarizesBoundedPageUnderShortHeigh | |||
| 86 | 86 | }, nil | |
| 87 | 87 | }) | |
| 88 | 88 | t.Cleanup(func() { _ = manager.Close(context.Background()) }) | |
| 89 | - | spawnResidentIndicatorChildren(t, manager, 6) | |
| 89 | + | spawnRunningResidentIndicatorChildren(t, manager, 6) | |
| 90 | 90 | ||
| 91 | 91 | term := &residentIndicatorTerminal{cols: 80, rows: 8} | |
| 92 | 92 | interactive := NewInteractive(InteractiveConfig{Terminal: term, ResidentManager: manager, Theme: tui.Dark}) | |
| @@ -112,7 +112,7 @@ func TestInteractiveResidentSubagentActivityShowsAllActiveChildrenWhenShortHeigh | |||
| 112 | 112 | }, nil | |
| 113 | 113 | }) | |
| 114 | 114 | t.Cleanup(func() { _ = manager.Close(context.Background()) }) | |
| 115 | - | spawnResidentIndicatorChildren(t, manager, 2) | |
| 115 | + | spawnRunningResidentIndicatorChildren(t, manager, 2) | |
| 116 | 116 | ||
| 117 | 117 | term := &residentIndicatorTerminal{cols: 80, rows: 8} | |
| 118 | 118 | interactive := NewInteractive(InteractiveConfig{Terminal: term, ResidentManager: manager, Theme: tui.Dark}) | |
| @@ -132,6 +132,35 @@ func TestInteractiveResidentSubagentActivityShowsAllActiveChildrenWhenShortHeigh | |||
| 132 | 132 | } | |
| 133 | 133 | } | |
| 134 | 134 | ||
| 135 | + | func spawnRunningResidentIndicatorChildren(t *testing.T, manager *subagents.ResidentManager, count int) { | |
| 136 | + | t.Helper() | |
| 137 | + | updates := make(chan string, count*2) | |
| 138 | + | manager.SetUpdateObserver(func(childID string) { | |
| 139 | + | select { | |
| 140 | + | case updates <- childID: | |
| 141 | + | default: | |
| 142 | + | } | |
| 143 | + | }) | |
| 144 | + | spawnResidentIndicatorChildren(t, manager, count) | |
| 145 | + | defer manager.SetUpdateObserver(nil) | |
| 146 | + | ||
| 147 | + | running := make(map[string]struct{}, count) | |
| 148 | + | timer := time.NewTimer(time.Second) | |
| 149 | + | defer timer.Stop() | |
| 150 | + | for len(running) < count { | |
| 151 | + | select { | |
| 152 | + | case childID := <-updates: | |
| 153 | + | snapshot, ok := manager.SnapshotFor(childID) | |
| 154 | + | if ok && snapshot.State == subagents.ResidentRunning { | |
| 155 | + | running[childID] = struct{}{} | |
| 156 | + | } | |
| 157 | + | case <-timer.C: | |
| 158 | + | snapshots, _ := manager.ActiveSnapshotPage(0) | |
| 159 | + | t.Fatalf("running resident children = %d, want %d; active snapshots=%#v", len(running), count, snapshots) | |
| 160 | + | } | |
| 161 | + | } | |
| 162 | + | } | |
| 163 | + | ||
| 135 | 164 | func spawnResidentIndicatorChildren(t *testing.T, manager *subagents.ResidentManager, count int) { | |
| 136 | 165 | t.Helper() | |
| 137 | 166 | for index := 0; index < count; index++ { | |
| @@ -51,7 +51,7 @@ func TestInteractiveResidentSubagentActivityRendersAllActiveChildrenWhenHeightAl | |||||
| 51 | }, nil | 51 | }, nil | ||
| 52 | }) | 52 | }) | ||
| 53 | t.Cleanup(func() { _ = manager.Close(context.Background()) }) | 53 | t.Cleanup(func() { _ = manager.Close(context.Background()) }) | ||
| 54 | - | spawnResidentIndicatorChildren(t, manager, 10) | 54 | + | spawnRunningResidentIndicatorChildren(t, manager, 10) |
| 55 | 55 | ||||
| 56 | term := &residentIndicatorTerminal{cols: 80, rows: 40} | 56 | term := &residentIndicatorTerminal{cols: 80, rows: 40} | ||
| 57 | interactive := NewInteractive(InteractiveConfig{Terminal: term, ResidentManager: manager, Theme: tui.Dark}) | 57 | interactive := NewInteractive(InteractiveConfig{Terminal: term, ResidentManager: manager, Theme: tui.Dark}) | ||
| @@ -86,7 +86,7 @@ func TestInteractiveResidentSubagentActivitySummarizesBoundedPageUnderShortHeigh | |||||
| 86 | }, nil | 86 | }, nil | ||
| 87 | }) | 87 | }) | ||
| 88 | t.Cleanup(func() { _ = manager.Close(context.Background()) }) | 88 | t.Cleanup(func() { _ = manager.Close(context.Background()) }) | ||
| 89 | - | spawnResidentIndicatorChildren(t, manager, 6) | 89 | + | spawnRunningResidentIndicatorChildren(t, manager, 6) |
| 90 | 90 | ||||
| 91 | term := &residentIndicatorTerminal{cols: 80, rows: 8} | 91 | term := &residentIndicatorTerminal{cols: 80, rows: 8} | ||
| 92 | interactive := NewInteractive(InteractiveConfig{Terminal: term, ResidentManager: manager, Theme: tui.Dark}) | 92 | interactive := NewInteractive(InteractiveConfig{Terminal: term, ResidentManager: manager, Theme: tui.Dark}) | ||
| @@ -112,7 +112,7 @@ func TestInteractiveResidentSubagentActivityShowsAllActiveChildrenWhenShortHeigh | |||||
| 112 | }, nil | 112 | }, nil | ||
| 113 | }) | 113 | }) | ||
| 114 | t.Cleanup(func() { _ = manager.Close(context.Background()) }) | 114 | t.Cleanup(func() { _ = manager.Close(context.Background()) }) | ||
| 115 | - | spawnResidentIndicatorChildren(t, manager, 2) | 115 | + | spawnRunningResidentIndicatorChildren(t, manager, 2) |
| 116 | 116 | ||||
| 117 | term := &residentIndicatorTerminal{cols: 80, rows: 8} | 117 | term := &residentIndicatorTerminal{cols: 80, rows: 8} | ||
| 118 | interactive := NewInteractive(InteractiveConfig{Terminal: term, ResidentManager: manager, Theme: tui.Dark}) | 118 | interactive := NewInteractive(InteractiveConfig{Terminal: term, ResidentManager: manager, Theme: tui.Dark}) | ||
| @@ -132,6 +132,35 @@ func TestInteractiveResidentSubagentActivityShowsAllActiveChildrenWhenShortHeigh | |||||
| 132 | } | 132 | } | ||
| 133 | } | 133 | } | ||
| 134 | 134 | ||||
| 135 | + | func spawnRunningResidentIndicatorChildren(t *testing.T, manager *subagents.ResidentManager, count int) { | |||
| 136 | + | t.Helper() | |||
| 137 | + | updates := make(chan string, count*2) | |||
| 138 | + | manager.SetUpdateObserver(func(childID string) { | |||
| 139 | + | select { | |||
| 140 | + | case updates <- childID: | |||
| 141 | + | default: | |||
| 142 | + | } | |||
| 143 | + | }) | |||
| 144 | + | spawnResidentIndicatorChildren(t, manager, count) | |||
| 145 | + | defer manager.SetUpdateObserver(nil) | |||
| 146 | + | ||||
| 147 | + | running := make(map[string]struct{}, count) | |||
| 148 | + | timer := time.NewTimer(time.Second) | |||
| 149 | + | defer timer.Stop() | |||
| 150 | + | for len(running) < count { | |||
| 151 | + | select { | |||
| 152 | + | case childID := <-updates: | |||
| 153 | + | snapshot, ok := manager.SnapshotFor(childID) | |||
| 154 | + | if ok && snapshot.State == subagents.ResidentRunning { | |||
| 155 | + | running[childID] = struct{}{} | |||
| 156 | + | } | |||
| 157 | + | case <-timer.C: | |||
| 158 | + | snapshots, _ := manager.ActiveSnapshotPage(0) | |||
| 159 | + | t.Fatalf("running resident children = %d, want %d; active snapshots=%#v", len(running), count, snapshots) | |||
| 160 | + | } | |||
| 161 | + | } | |||
| 162 | + | } | |||
| 163 | + | ||||
| 135 | func spawnResidentIndicatorChildren(t *testing.T, manager *subagents.ResidentManager, count int) { | 164 | func spawnResidentIndicatorChildren(t *testing.T, manager *subagents.ResidentManager, count int) { | ||
| 136 | t.Helper() | 165 | t.Helper() | ||
| 137 | for index := 0; index < count; index++ { | 166 | for index := 0; index < count; index++ { | ||