Skip to content

fix(cli): record a timed-out mocha test's failure when mocha reports it (SDK-7843) [v8] - #273

Open
AakashHotchandani wants to merge 6 commits into
v8from
fix/SDK-7843-record-timeout-at-source-v8
Open

AakashHotchandani wants to merge 6 commits into
v8from
fix/SDK-7843-record-timeout-at-source-v8

Conversation

@AakashHotchandani

@AakashHotchandani AakashHotchandani commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

What is this about?

v8 port of #272. On the CLI flow, a mocha test that hits mocha's timeout has its session marked passed on the Automate / App Automate dashboard.

Why: wdio runs afterTest inside the test's runnable. When the test times out, mocha fails it (and emits fail to reporters) while the body and its afterTest are still pending. With bail, or on the worker's last test, wdio runs after() first. after() emits EXECUTE/POST, and AutomateModule.onAfterExecute marks the session from results that only afterTest supplies. There is none yet, so the session is marked passed. The classic flow reads after(result), mocha's own failure count, and was correct.

Same fix as #272:

  • cli/earlyTestFinish.ts (identical file): beforeTest (CLI, mocha) registers a finisher per test.
  • The reporter's onTestFail reports the failure through it, with mocha's own result, the moment mocha fails the test.
  • after() awaits those finishes before EXECUTE/POST.
  • afterTest stands down only for a test the reporter already reported.

The CLI finish (LOG_REPORT/POST → TEST/POST) moved unchanged into finishCliTest(), including the existing suiteTite payload key.

Difference from main: v8 has no deferred TEST/POST and no bail cascade, so its Test Reporting results were already right. On v8 this fixes the session status only.

Also in this PR — the resolveInstance ERROR (same change as #265): console output from wdio's before hook (the customer's [SelfHealer] Installed …) reaches trackEvent(LOG, POST) before mocha's first hook, when no test or hook instance exists. resolveInstance then printed resolveInstance: unable to resolve/create instance for TestFrameworkState.LOG HookState.POST on every worker. WdioMochaTestFramework.trackEvent now drops a LOG with no tracked instance at debug level, as the classic flow does. New test: tests/cli/wdioMochaTestFramework.preTestLog.test.ts (3 cases). Verified on real sessions under #265: stock 8.53.1 build smosjpekx4… prints the ERROR, patched build djju5rlyfb… is clean.

Review follow-up (ab144e5):

Verification

Real WDIO 8 + mocha sessions on Automate (chrome/Win11), mochaOpts: { timeout: 10000, bail: true }. The timed-out test waits 40 s for a missing element.

build SDK session status of the timed-out test Test Reporting
gceel2cz0bnksiupe9w90rzx7ttnf06w4dgaqj8n stock 8.53.1 3eeef5f73f174165fb02f17f6616041f43656360 passed ❌ (CLIENT_STOPPED_SESSION) passed 1, failed 1
niszt4uhggs0bb2nnia3ngxookl2oemckau8wrmc this PR 0c835059b01822990f4e38cb092af6a9a934d438 failed, reason = mocha timeout passed 1, failed 1

Timing on both runs: reporter onTestFail (05:53:48.831) → after(result=1) (.840). On stock, the session status is set before the failed result exists.

Tests: the same 11 new cases as #272.

Full suite: 1131 passed with this PR (51/51 files) vs 1109 on v8, 0 failing tests on both. The only failing file is tests/crash-reporter.test.ts (needs a built build/), and it fails identically on v8. tsc -p tsconfig.prod.json --noEmit is clean. The v8 branch has no eslint config.

Related Jira task/s

SDK-7843

Release (mandatory for every PR — required for the ready-for-review label)

Version bump: (required — tick exactly one)

  • minor (backwards-compatible feature)
  • patch (bug fix or other small change)

Release notes type: (optional)

  • New Feature
  • Bug Fix
  • Other Improvement

Release notes (customer-facing): (optional but encouraged)

  • Fixed mocha tests that fail by exceeding their timeout being marked "passed" on the Automate / App Automate dashboard. Such sessions are now marked failed, with the timeout error as the reason.
  • Removed the resolveInstance: unable to resolve/create instance ... LOG POST error printed when a wdio before hook writes to the console.

Release notes (internal): (required — engineer-facing; what actually changed / why)

Checklist

  • Ready to review
  • Has it been tested locally?

PR Validations

Run Tests: Comment RUN_TESTS to trigger sanity tests.

🤖 Generated with Claude Code

…it (SDK-7843)

v8 port of the main-line fix. When a mocha test hits its timeout, mocha
fails it while the body and wdio's afterTest are still pending. With
`bail`, or on the worker's last test, wdio runs after() first, so on the
CLI flow AutomateModule.onAfterExecute marks the session `passed`: its
results only come from afterTest. The classic flow reads after(result)
and was correct.

The service now registers a finisher per mocha test in beforeTest
(cli/earlyTestFinish.ts). The reporter's onTestFail reports the failure
through it when mocha fails the test. after() waits for those finishes
before EXECUTE/POST, and the late afterTest stands down for a test that
was already reported. v8 sends TEST/POST inline (no deferred finish), so
its Test Reporting results were already right; this fixes the session
status.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AakashHotchandani
AakashHotchandani requested a review from a team as a code owner October 7, 2026 05:55
@AakashHotchandani
AakashHotchandani requested review from harshit-browserstack and kamal-kaur04 and removed request for a team October 7, 2026 05:55
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Central YAML (base), Organization UI (inherited), Workspace UI (inherited)
  • Review profile: ASSERTIVE
  • Plan: Enterprise
  • Run ID: 64596c73-14cd-4e4c-8862-68ef79a31da6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

🔴 SDK PR Review gate is red. Pending:

  • The SDK PR Review Agent has not been run on the current head commit yet — run the SDK PR Review Agent (its verdict is advisory; this gate only requires that it ran on the latest commit).

It turns green once the SDK PR Review Agent has run on the current head commit (any verdict — the gate only requires that the review ran). A native reviewer approval is separately required by branch protection before merge.

…ogging an ERROR (SDK-7843)

Console output from wdio's `before` hook reaches trackEvent(LOG, POST) before mocha's first
hook, when no test or hook instance exists, so resolveInstance printed
"resolveInstance: unable to resolve/create instance ... LOG POST" on every worker. Drop it at
debug level, as the classic path does. Same change as #265.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

🔴 SDK PR Review gate is red. Pending:

  • The SDK PR Review Agent has not been run on the current head commit yet — run the SDK PR Review Agent (its verdict is advisory; this gate only requires that it ran on the latest commit).

It turns green once the SDK PR Review Agent has run on the current head commit (any verdict — the gate only requires that the review ran). A native reviewer approval is separately required by branch protection before merge.

github-actions Bot and others added 2 commits October 7, 2026 10:31
- Finish a test mocha already failed from after() when no reporter claimed it, using mocha's
  own runnable, so the fix holds with Test Reporting, Accessibility and Percy all off (the
  reporter is only registered when Test Hub events are on).
- Key the finish hand-off per retry attempt, so a retried attempt's late afterTest closes that
  attempt and not the next one.
- Drop the try/catch around awaitCliTestFinishesOnFailure(); every finish catches its own error.
- Tests: no reporter, retries. Same changes as #272.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

🔴 SDK PR Review gate is red. Pending:

  • The SDK PR Review Agent has not been run on the current head commit yet — run the SDK PR Review Agent (its verdict is advisory; this gate only requires that it ran on the latest commit).

It turns green once the SDK PR Review Agent has run on the current head commit (any verdict — the gate only requires that the review ran). A native reviewer approval is separately required by branch protection before merge.

With no reporter, a timed-out test whose body finishes late gets an afterTest saying only whether
the body threw. If mocha already failed that attempt, claimCliTestFinish now reports mocha's
failure and afterTest stands down, instead of reporting it passed. Same change as #272.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

🔴 SDK PR Review gate is red. Pending:

  • The SDK PR Review Agent has not been run on the current head commit yet — run the SDK PR Review Agent (its verdict is advisory; this gate only requires that it ran on the latest commit).

It turns green once the SDK PR Review Agent has run on the current head commit (any verdict — the gate only requires that the review ran). A native reviewer approval is separately required by branch protection before merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant