Commit 23b59f5
fix(mcp): timeout aborts Mocha runner so next run_test isn't blocked (#5551)
* fix(mcp): timeout aborts Mocha runner so next run_test isn't blocked
Previously the run_test / run_step_by_step timeout was just a setTimeout
that rejected the race promise — the Mocha runner kept going, the
recorder chain stayed queued, listeners stayed attached, and pause
sessions kept trapping. Subsequent run_test calls hit "Mocha instance
is currently running". cancel didn't help because pendingRunPromise was
only assigned in the paused branch, so it saw nothing to cancel.
- Assign pendingRunPromise immediately after runPromise creation in
both run_test and run_step_by_step (was set only on pause).
- Wrap the Promise.race in try/catch + finally; clear the setTimeout
and route timeout rejections through cancelRun(); return a clean
status: "failed" payload to the client.
- Make cancelRun() actually abort: look up the Mocha runner via
mocha._runner / _previousRunner / runner and call runner.abort();
recorder.reset() to drop any queued tasks. Existing abortRun + pause
release stay in place for stuck-on-pause cases.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(mcp): drop unused runner.abort + recorder.reset hacks
The pause-and-abortRun chain alone is enough: resolveContinue releases
the current pauseSession, abortRun causes the next pauseNow-queued
pauseSession to reject inside setPauseHandler, the rejection propagates
through the recorder to codecept.run, and Mocha's runningNow clears
naturally. Reaching into mocha._runner / _previousRunner / .runner and
calling recorder.reset() were speculative — the timeout repro still
clears Mocha state without them.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(mcp): extract raceRunOutcome helper to dedupe run_test/run_step_by_step
Both tools had the same Promise.race + try/catch + finally + cancelRun
+ failure-response block. Extracted into raceRunOutcome(runPromise,
timeout) which returns a tagged outcome ({outcome:'paused'|'completed'}
or {outcome:'aborted', error}) so the caller branches once.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(mcp): rename raceRunOutcome → waitForTestResult, outcome → status
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: DavertMik <davert@testomat.io>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 4f0fa49 commit 23b59f5
1 file changed
Lines changed: 33 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
412 | 412 | | |
413 | 413 | | |
414 | 414 | | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
415 | 432 | | |
416 | 433 | | |
417 | 434 | | |
| |||
1025 | 1042 | | |
1026 | 1043 | | |
1027 | 1044 | | |
| 1045 | + | |
1028 | 1046 | | |
1029 | | - | |
1030 | | - | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | | - | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
1037 | 1052 | | |
1038 | | - | |
1039 | | - | |
| 1053 | + | |
1040 | 1054 | | |
1041 | 1055 | | |
1042 | 1056 | | |
| |||
1046 | 1060 | | |
1047 | 1061 | | |
1048 | 1062 | | |
| 1063 | + | |
1049 | 1064 | | |
1050 | 1065 | | |
1051 | 1066 | | |
| |||
1121 | 1136 | | |
1122 | 1137 | | |
1123 | 1138 | | |
| 1139 | + | |
1124 | 1140 | | |
1125 | | - | |
1126 | | - | |
1127 | | - | |
1128 | | - | |
1129 | | - | |
1130 | | - | |
1131 | | - | |
1132 | | - | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
1133 | 1146 | | |
1134 | | - | |
1135 | | - | |
| 1147 | + | |
1136 | 1148 | | |
1137 | 1149 | | |
1138 | 1150 | | |
| |||
1142 | 1154 | | |
1143 | 1155 | | |
1144 | 1156 | | |
| 1157 | + | |
1145 | 1158 | | |
1146 | 1159 | | |
1147 | 1160 | | |
| |||
0 commit comments