Commit 2fbcd36
authored
🤖 Add integration tests for stream error recovery (no amnesia) (#333)
## Summary
Adds integration test to verify that stream error recovery preserves
context (no amnesia bug).
## Changes
- **Debug IPC for testing**: Added `DEBUG_TRIGGER_STREAM_ERROR` IPC
channel
- **StreamManager debug method**: `debugTriggerStreamError()` triggers
artificial stream errors that follow the same code path as real errors
- **Integration test**: Single error + resume scenario verifies context
preservation via **structured markers**
## Test Design
**Structured-marker approach** for precise validation:
**Test Flow:**
1. Generate unique nonce for test run (random 10-char identifier)
2. Model counts 1-100 using structured format: `${nonce}-<n>: <word>`
(e.g. `ai7qcnc20g-1: one`)
3. Collect stream deltas until ≥10 complete markers detected
4. Trigger artificial network error mid-stream
5. Resume stream and wait for completion
6. Verify final message has **both** properties:
- **(a) Prefix preservation**: Starts with exact pre-error streamed text
- **(b) Exact continuation**: Contains next sequential marker
(${nonce}-11) shortly after prefix
**Validation:**
- Pre-error content captured from stream-delta events (user-visible data
path)
- Stable prefix truncated to last complete marker line (no partial
markers)
- Assertions directly prove both amnesia-prevention properties
- No coupling to internal storage formats or metadata
**Why this approach:**
- **Precise**: Detects exact continuation (not just "some work done")
- **Unambiguous**: Random nonce makes false positives virtually
impossible
- **Robust**: Structured format less likely to confuse model than
natural language
- **Fast**: Haiku 4.5 completes in ~18-21 seconds
## Bug Fix
Also fixed event collection bug in `collectStreamUntil`: properly track
consumed deltas to avoid returning the same event multiple times.
Previous logic returned first matching event on every poll, causing
duplicate processing.
## Related
Follow-up to #331 which fixed the amnesia bug by preserving accumulated
parts on error.
## Test Results
✅ Test passes reliably in ~18-21 seconds
✅ Validates **exact** prefix preservation and continuation
✅ No flaky failures from timing issues
✅ Integration tests pass: 1 passed, 1 total
_Generated with `cmux`_1 parent d363128 commit 2fbcd36
File tree
4 files changed
+411
-0
lines changed- src
- constants
- services
- tests/ipcMain
4 files changed
+411
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
855 | 855 | | |
856 | 856 | | |
857 | 857 | | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
858 | 877 | | |
859 | 878 | | |
860 | 879 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1271 | 1271 | | |
1272 | 1272 | | |
1273 | 1273 | | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
1274 | 1332 | | |
0 commit comments