Skip to content

Commit 4c0689f

Browse files
DavertMikDavertMikclaude
authored
fix(mcp): kill zombie Mocha state when timeout fires before pause() (#5555)
* fix(mcp): kill zombie Mocha state when timeout fires before test reaches pause() When run_test's timeout was shorter than the time the test needed to reach pause() (e.g. 50ms timeout vs 30s Playwright helper timeout), Mocha kept running in the background, eventually entered paused state forever (because cancelRun had reset abortRun=false), and every subsequent run_test threw "Mocha instance is currently running tests". The only recovery was killing the MCP process. Three changes: - lib/codecept.js: capture the Runner returned by mocha.run() as mocha.runner, so callers have a clean handle to abort. Previously the return value was discarded. - cancelRun(): call mocha.runner.abort() to actually stop Mocha (sets the runner's _abort flag, makes the run callback fire fast). Drop the 5s race against pendingRunPromise — with runner.abort() the promise settles quickly; relying on a short race meant a 30s Playwright step would outlive the cancel and Mocha state stayed RUNNING. - abortRun lifecycle: stop resetting it inside cancelRun. Reset it at the start of each new run_test / run_step_by_step instead. This way if a late pause() fires after cancelRun returns (test reached pause asynchronously after the timeout), setPauseHandler still rejects it instead of trapping forever. Repro fixed: run_test({timeout: 50}) → Timeout after 50ms run_test({timeout: 60000}) → completed, stats: {tests:1, passes:1} (was: second call permanently failed with "Mocha is already running") Refs: testomatio/e2e-tests#103 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor(mcp): drop paranoid container.mocha type guard container.mocha is the static method on the Container class — always callable. The typeof-check ternary was dead defensive code. 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 8a1f081 commit 4c0689f

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

bin/mcp-server.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ function aiTraceHint() {
6060
}
6161

6262
function applyMochaGrep(grep) {
63-
if (!grep) return
64-
const mocha = typeof container.mocha === 'function' ? container.mocha() : container.mocha
65-
if (mocha && typeof mocha.grep === 'function') mocha.grep(grep)
63+
if (grep) container.mocha().grep(grep)
6664
}
6765

6866
function pauseAtMatcher(pauseAt) {
@@ -402,8 +400,7 @@ async function cancelRun() {
402400
if (typeof pendingRunCleanup === 'function') { try { pendingRunCleanup() } catch {} }
403401
if (pausedController) { try { pausedController.resolveContinue() } catch {} ; pausedController = null }
404402

405-
const mocha = typeof container.mocha === 'function' ? container.mocha() : container.mocha
406-
try { mocha?.runner?.abort?.() } catch {}
403+
try { container.mocha().runner?.abort() } catch {}
407404

408405
if (pendingRunPromise) {
409406
try { await pendingRunPromise.catch(() => {}) } catch {}

0 commit comments

Comments
 (0)