test(agent): synchronize subagent wait completion
- commit
- 3ee53c5c3bf65d53a05a8de2cf88968a59b9fbac
- author
- brice · · 2026-08-08 05:41 UTC
- parent
- f976a5c
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +13 -13
M packages/agent/modes/subagents_slash_test.go +13 -13
| @@ -290,20 +290,20 @@ func TestRunSupervisorWaitReportsCompletionBeforeCancellation(t *testing.T) { | |||
| 290 | 290 | if err != nil { | |
| 291 | 291 | t.Fatal(err) | |
| 292 | 292 | } | |
| 293 | + | watcherDone := make(chan struct{}) | |
| 294 | + | iv.subagentsWaitWatcherDone = func() { close(watcherDone) } | |
| 293 | 295 | iv.runSubagents(context.Background(), []string{"wait", a.ID}) | |
| 294 | - | deadline := time.After(time.Second) | |
| 295 | - | for { | |
| 296 | - | iv.mu.Lock() | |
| 297 | - | status := iv.statusOK | |
| 298 | - | iv.mu.Unlock() | |
| 299 | - | if status == "completed "+a.ID { | |
| 300 | - | return | |
| 301 | - | } | |
| 302 | - | select { | |
| 303 | - | case <-deadline: | |
| 304 | - | t.Fatalf("wait did not report completion; status = %q", status) | |
| 305 | - | case <-time.After(time.Millisecond): | |
| 306 | - | } | |
| 296 | + | select { | |
| 297 | + | case <-watcherDone: | |
| 298 | + | case <-time.After(5 * time.Second): | |
| 299 | + | t.Fatal("timed out waiting for wait watcher to report completion") | |
| 300 | + | } | |
| 301 | + | ||
| 302 | + | iv.mu.Lock() | |
| 303 | + | status := iv.statusOK | |
| 304 | + | iv.mu.Unlock() | |
| 305 | + | if status != "completed "+a.ID { | |
| 306 | + | t.Fatalf("wait completion status = %q; want %q", status, "completed "+a.ID) | |
| 307 | 307 | } | |
| 308 | 308 | } | |
| 309 | 309 | ||
| @@ -290,20 +290,20 @@ func TestRunSupervisorWaitReportsCompletionBeforeCancellation(t *testing.T) { | |||||
| 290 | if err != nil { | 290 | if err != nil { | ||
| 291 | t.Fatal(err) | 291 | t.Fatal(err) | ||
| 292 | } | 292 | } | ||
| 293 | + | watcherDone := make(chan struct{}) | |||
| 294 | + | iv.subagentsWaitWatcherDone = func() { close(watcherDone) } | |||
| 293 | iv.runSubagents(context.Background(), []string{"wait", a.ID}) | 295 | iv.runSubagents(context.Background(), []string{"wait", a.ID}) | ||
| 294 | - | deadline := time.After(time.Second) | 296 | + | select { |
| 295 | - | for { | 297 | + | case <-watcherDone: |
| 296 | - | iv.mu.Lock() | 298 | + | case <-time.After(5 * time.Second): |
| 297 | - | status := iv.statusOK | 299 | + | t.Fatal("timed out waiting for wait watcher to report completion") |
| 298 | - | iv.mu.Unlock() | 300 | + | } |
| 299 | - | if status == "completed "+a.ID { | 301 | + | |
| 300 | - | return | 302 | + | iv.mu.Lock() |
| 301 | - | } | 303 | + | status := iv.statusOK |
| 302 | - | select { | 304 | + | iv.mu.Unlock() |
| 303 | - | case <-deadline: | 305 | + | if status != "completed "+a.ID { |
| 304 | - | t.Fatalf("wait did not report completion; status = %q", status) | 306 | + | t.Fatalf("wait completion status = %q; want %q", status, "completed "+a.ID) |
| 305 | - | case <-time.After(time.Millisecond): | |||
| 306 | - | } | |||
| 307 | } | 307 | } | ||
| 308 | } | 308 | } | ||
| 309 | 309 | ||||