Commit 4a1b546
test: harden flaky tests against parallel-suite contention
Four file changes that fix every flake reported in the last CI run plus
the cascade ones the audit subagent traced back to root causes. Local
full suite: 7965 pass / 0 fail / 181s (was 7849 pass / 7 fail / 9 errors
before). All four prior failure classes addressed; no test was simply
disabled.
1. test/cli/tui/thread.test.ts — root cause of multi-suite cascade
The original test used `mock.module()` to stub @/util/log, @/project/instance,
@/util/rpc, @/cli/cmd/tui/app, @/cli/network. Per the project's saved
memory rule (no mock.module for shared modules in Bun's multi-file
runner), those mocks survived to subsequent test files and turned
Log.Default.* into no-ops + fake Instance.provide. Downstream tests
that depended on real logger / Instance behaviour failed cascade-style
under parallel load — including the 8 issue #704 theme fallback tests
that have nothing to do with logging or instance state but couldn't
complete cleanly when the cascade ran.
Fix: extracted the directory-resolution logic into a pure helper
`resolveProjectDirectory(project, pwd, cwd)` in src/cli/cmd/tui/thread.ts.
Tests now call the helper directly with controlled inputs — no mocks,
no leaks. The original test exercised only the resolution logic anyway;
the mocks were just intercepting downstream calls to verify what
`directory` got passed to Instance/tui.
Local sanity: bun test test/cli/tui/thread.test.ts → 4/4 pass.
2. test/session/prompt.test.ts — wall-clock starvation + timer leak
"does not loop empty assistant turns" + "records aborted errors when
prompt is cancelled mid-stream" both timed out at 5s under suite load
(the package.json --timeout 30000 only applies to bare `bun test`;
`bun test <paths>` reverts to default 5s). The cancelled-stream test
also leaked a 10s setTimeout in the `hanging()` helper that was only
cleared via stream.cancel — server.stop didn't propagate cancel.
Fix: added explicit `, 30_000)` to both tests; refactored hanging()
to expose `dispose()` so the test's finally block can clear the timer.
3. test/session/llm.test.ts — FIFO queue cross-contamination
"sends responses API payload for OpenAI" timed out at 5s; its in-flight
request landed in the next test's deferred via the shared FIFO
`state.queue`, making "sends Google API payload for Gemini" see
"/v1/responses" instead of "/v1beta/...:streamGenerateContent".
Fix: replaced the FIFO queue with a path-keyed Map. The server matches
incoming requests by path suffix; out-of-order requests can no longer
resolve another test's deferred. beforeEach now also rejects (not just
clears) leftover deferreds so tests fail fast rather than hang. Both
tests get explicit 30_000 timeouts for the slow-SDK case.
4. test/cli/tui/thread.test.ts (covered above)
Verified
- bun test test/cli/tui/thread.test.ts → 4/4 pass
- bun test test/session/prompt.test.ts → 9/9 pass
- bun test test/session/llm.test.ts → 8/8 pass + 2 skip
- bun test test/cli/tui/theme-light-mode-704.test.ts → 26/26 pass
- bun test (full suite, --timeout 30000) → 7965 pass / 503 skip / 0 fail / 181s
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 69ebaae commit 4a1b546
4 files changed
Lines changed: 129 additions & 173 deletions
File tree
- packages/opencode
- src/cli/cmd/tui
- test
- cli/tui
- session
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
65 | 81 | | |
66 | 82 | | |
67 | 83 | | |
| |||
119 | 135 | | |
120 | 136 | | |
121 | 137 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
| 138 | + | |
126 | 139 | | |
127 | 140 | | |
128 | 141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
2 | 16 | | |
3 | 17 | | |
4 | 18 | | |
| 19 | + | |
5 | 20 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
105 | 34 | | |
106 | | - | |
107 | | - | |
| 35 | + | |
108 | 36 | | |
109 | | - | |
| 37 | + | |
110 | 38 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | 39 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 40 | + | |
| 41 | + | |
133 | 42 | | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
139 | 47 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | 48 | | |
147 | 49 | | |
148 | | - | |
| 50 | + | |
149 | 51 | | |
150 | | - | |
151 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
152 | 56 | | |
153 | 57 | | |
154 | | - | |
155 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
156 | 62 | | |
157 | 63 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
92 | 94 | | |
93 | 95 | | |
94 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
95 | 102 | | |
96 | 103 | | |
97 | 104 | | |
98 | | - | |
99 | | - | |
| 105 | + | |
| 106 | + | |
100 | 107 | | |
| 108 | + | |
101 | 109 | | |
102 | 110 | | |
103 | 111 | | |
104 | 112 | | |
105 | 113 | | |
106 | 114 | | |
107 | | - | |
| 115 | + | |
108 | 116 | | |
109 | 117 | | |
110 | 118 | | |
111 | 119 | | |
112 | 120 | | |
113 | 121 | | |
114 | 122 | | |
115 | | - | |
116 | | - | |
117 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
118 | 132 | | |
| 133 | + | |
| 134 | + | |
119 | 135 | | |
120 | | - | |
121 | 136 | | |
122 | 137 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | 138 | | |
129 | 139 | | |
130 | 140 | | |
131 | 141 | | |
132 | 142 | | |
133 | 143 | | |
134 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
135 | 151 | | |
136 | 152 | | |
137 | 153 | | |
| |||
430 | 446 | | |
431 | 447 | | |
432 | 448 | | |
433 | | - | |
| 449 | + | |
434 | 450 | | |
435 | 451 | | |
436 | 452 | | |
| |||
652 | 668 | | |
653 | 669 | | |
654 | 670 | | |
655 | | - | |
| 671 | + | |
656 | 672 | | |
0 commit comments