Skip to content

fix(cli): 10.x follow-ups: end tests after TEST/POST observers, per-test a11y verdict, failed-hook tests reported as failed - #388

Open
kamal-kaur04 wants to merge 11 commits into
mainfrom
fix/v10-cli-followups
Open

kamal-kaur04 wants to merge 11 commits into
mainfrom
fix/v10-cli-followups

Conversation

@kamal-kaur04

Copy link
Copy Markdown
Collaborator

What is this about?

CLI-flow fixes for the 10.x line, combined into one PR. It replaces #384, #359 and #387. Two of the fixes are ports of v9 fixes that already shipped in 9.44.2 / 9.44.3; the third is new for WebdriverIO 10.

1. End a test after its TEST/POST observers (port of #358, shipped in 9.44.2)

On the CLI flow, a test's test_ended_at was stamped before the TEST/POST observers ran. The accessibility pre-save scan and save run in those observers, so they landed after the test's reported finish. Scans attributed by the test's time window were dropped, which is most visible with includeTagsInTestingScope.

  • Cucumber: test_ended_at is restamped after the observers. TestHubModule holds TestRunFinished while they run, and the framework releases it from a finally. The next-test / worker-end flush is the fallback.
  • Mocha: test_ended_at is restamped after the observers; the send was already deferred.
  • The event payload sent to the binary is unchanged.
  • Commits: 51950d7, 6c6591e.

2. Send the per-test accessibility verdict on test events (port of #360, shipped in 9.44.3)

  • Sends the per-test accessibility verdict on test events.
  • Marks cascade-skipped scenarios as not accessibility tests.
  • Leaves auto-scanning out of the per-test verdict.
  • The patches are identical to the v9 commits 454f2f3, f01547b and 703b4d3.
  • Commits: ff5b911, 8e752b8, 75d605e.

3. Report tests behind a failed before/beforeEach hook as failed (new)

@wdio/mocha-framework 10 turns on Mocha's failHookAffectedTests when the user leaves it unset. Mocha 12 then marks the tests behind a failed before/beforeEach hook as failed, but the service still reported them as skipped. Its cascade runs inside the hook wrapper, before Mocha marks the tests, and Mocha's later fail was dropped because the test never started.

  • The failed-hook cascade (CLI reportSuiteSkipped and the non-CLI insights handler) now reports BEFORE_ALL/BEFORE_EACH-affected tests as failed with the hook's error, unless mochaOpts.failHookAffectedTests is false.
  • AFTER_EACH, a this.skip() hook, the bail cascade, Cucumber and Jasmine are unchanged.
  • Commit: 975612e.

The per-fix changeset from #387 is dropped; this PR's template generates one changeset.

Verification

  • All six commits cherry-picked onto current main without conflicts.
  • On this branch: npm ci, build and lint pass, and the full package suite passes (58 files / 1,518 tests, including every fix's new tests).
  • Fix 1: the end-to-end check is in fix(cli): end a test after its TEST/POST observers so a11y scan/save stay inside it #358. With accessibility scoped by tag on the CLI flow, the pre-save scan and save now fall inside the tagged test.
  • Fix 3, end to end on BrowserStack:
    • setup: WebdriverIO 10.2.0, Mocha 12.0.3, CLI flow, Chrome on Windows 11; one spec whose beforeEach throws, with 2 tests;
    • there are no duplicate test rows, and the tests stay linked to the session;
    • not covered end to end: an outer-suite beforeEach failing for a child suite, maxParallelContexts, and multiremote.
Run Test Reporting build Test 1 Test 2
main qffjianrcxbd4nf3i2xdrulrbb1ww47qeg8ehh59 skipped skipped
fix cnxniqlqr4giogckdbaaygqzvymlezqazywlrqc8 failed (hook error + stack) failed
fix, failHookAffectedTests: false 0dwf0uec0f2i22op6vjeau14evhdddylx4r0ymat skipped skipped

Related Jira task/s

  • N/A (tracked internally)

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 accessibility results being attributed outside the test that produced them when using tag-scoped accessibility testing on the BrowserStack CLI flow.
  • Fixed tests outside includeTagsInTestingScope / excludeTagsInTestingScope being reported as accessibility tests when using the CLI.
  • Fixed Mocha tests that fail because of a failed before/beforeEach hook showing as skipped in Test Reporting. They are now reported as failed with the hook's error, matching WebdriverIO 10's default failHookAffectedTests.

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

kamal-kaur04 and others added 7 commits November 25, 2026 20:38
On the CLI flow, test_ended_at was stamped before the TEST/POST observers ran,
so the accessibility pre-save scan and save landed after the test's finish
time. Restamp ended_at once the observers have run; for cucumber, hold the
TestRunFinished send until then and release it from a finally block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 7dd78e4)
(cherry picked from commit 097625a)
(cherry picked from commit 2ab2034)
Count the send right after releaseHeldFinish and before the worker-end flush,
and make the observers' elapsed time explicit in the mocha ended_at test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 75499f5)
(cherry picked from commit 58ec954)
On the CLI flow the binary set product_map.accessibility from the platform
check alone, so every test in a tag-scoped build was reported as an
accessibility test. The accessibility module now sets test_accessibility
(accessibility on, auto-scanning on, test in the include/exclude tag scope),
matching the classic flow's setTestRunAccessibilityVar. Its TEST/PRE observer
is prepended so the value is on the instance before TestRunStarted is sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit e2847bd)
Scenarios abandoned by a failed BeforeAll are built straight into TEST/POST,
so the TEST/PRE verdict never ran for them and the binary fell back to its
platform check. They never ran or scanned, so they now carry
test_accessibility: false. The in-scope rule is computed by one helper for
both the reported verdict and the scan gate, and a failure to set the verdict
is logged at error level.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit ef1b7cc)
With autoScanning off, tests scanned manually with performScan() still need
their accessibility test row, so test_accessibility is now accessibility on and
test in the include/exclude tag scope. Auto-scanning still gates the automatic
scans.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 898a81f)
…ha fails them

@wdio/mocha-framework 10 turns Mocha's failHookAffectedTests on by default,
so tests behind a failed before/beforeEach hook are failed, not dropped.
The hook cascade still reported them as skipped, and the reporter's later
fail event for them is dropped, so Test Reporting showed skipped while CI
showed failed.

Report them as failed with the hook's error unless the user sets
mochaOpts.failHookAffectedTests to false. afterEach failures and
this.skip() hooks keep the skipped report. Applies to both the CLI
cascade and the legacy insights cascade.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 868b5bb)
…es one

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

coderabbitai Bot commented Nov 25, 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

  • Source mode: Auto (fallback from Default branch)
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML (base), Organization UI (inherited), Workspace UI (inherited); Enforced overrides: Organization
  • Review profile: ASSERTIVE
  • Plan: Enterprise
  • Run ID: aa47f82d-ad58-459c-b5bc-01e444d9c026

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
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@kamal-kaur04

kamal-kaur04 commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

⚠️ Needs human review

File Status
packages/browserstack-service/src/cli/modules/testHubModule.ts ✅ All Clear
packages/browserstack-service/tests/cli/modules/testHubModule.deferredFinish.test.ts ✅ All Clear

Only the files above changed since the previous review (5c8e746) and were re-judged. The previously reported held-finish finding on testHubModule.ts is no longer raised: the worker-end drain now awaits in-flight sends. All other files were unchanged and were not re-judged this run.

Process integrity

The review gate could NOT certify this run — the verdict is held at ⚠️ pending regardless of findings:

  • G3 — u001: no full read receipt for pack:docs
  • G3 — u001: no full read receipt for slice
  • G3 — u002: no full read receipt for card:cards/_shared.md
  • G3 — u002: no full read receipt for card:cards/wdio-service.md
  • G3 — u002: no full read receipt for pack:default
  • G3 — u002: no full read receipt for pack:external
  • G3 — u002: no full read receipt for pack:integration
  • G3 — u002: no full read receipt for pack:node
  • G3 — u002: no full read receipt for pack:observability
  • G3 — u002: no full read receipt for pack:tests
  • G3 — u002: no full read receipt for slice
  • G3 — u003: no full read receipt for card:cards/_shared.md
  • G3 — u003: no full read receipt for card:cards/wdio-service.md
  • G3 — u003: no full read receipt for pack:default
  • G3 — u003: no full read receipt for pack:external
  • G3 — u003: no full read receipt for pack:integration
  • G3 — u003: no full read receipt for pack:node
  • G3 — u003: no full read receipt for pack:observability
  • G3 — u003: no full read receipt for slice
  • G3 — u004: no full read receipt for card:cards/_shared.md
  • G3 — u004: no full read receipt for card:cards/wdio-service.md
  • G3 — u004: no full read receipt for pack:default
  • G3 — u004: no full read receipt for pack:external
  • G3 — u004: no full read receipt for pack:integration
  • G3 — u004: no full read receipt for pack:node
  • G3 — u004: no full read receipt for pack:observability
  • G3 — u004: no full read receipt for slice
  • G3 — u005: no full read receipt for card:cards/_shared.md
  • G3 — u005: no full read receipt for card:cards/wdio-service.md
  • G3 — u005: no full read receipt for pack:default
  • G3 — u005: no full read receipt for pack:external
  • G3 — u005: no full read receipt for pack:integration
  • G3 — u005: no full read receipt for pack:node
  • G3 — u005: no full read receipt for pack:observability
  • G3 — u005: no full read receipt for pack:tests
  • G3 — u005: no full read receipt for slice
  • G3 — u006: no full read receipt for card:cards/_shared.md
  • G3 — u006: no full read receipt for card:cards/wdio-service.md
  • G3 — u006: no full read receipt for pack:default
  • G3 — u006: no full read receipt for pack:external
  • G3 — u006: no full read receipt for pack:integration
  • G3 — u006: no full read receipt for pack:node
  • G3 — u006: no full read receipt for pack:observability
  • G3 — u006: no full read receipt for pack:tests
  • G3 — u006: no full read receipt for slice
  • G3 — u007: no full read receipt for card:cards/_shared.md
  • G3 — u007: no full read receipt for card:cards/wdio-service.md
  • G3 — u007: no full read receipt for pack:default
  • G3 — u007: no full read receipt for pack:external
  • G3 — u007: no full read receipt for pack:integration
  • G3 — u007: no full read receipt for pack:node
  • G3 — u007: no full read receipt for pack:observability
  • G3 — u007: no full read receipt for pack:tests
  • G3 — u007: no full read receipt for slice
  • G3 — u009: no full read receipt for card:cards/_shared.md
  • G3 — u009: no full read receipt for card:cards/wdio-service.md
  • G3 — u009: no full read receipt for pack:default
  • G3 — u009: no full read receipt for pack:external
  • G3 — u009: no full read receipt for pack:integration
  • G3 — u009: no full read receipt for pack:node
  • G3 — u009: no full read receipt for pack:observability
  • G3 — u009: no full read receipt for pack:tests
  • G3 — u009: no full read receipt for slice
  • G3 — u010: no full read receipt for card:cards/_shared.md
  • G3 — u010: no full read receipt for card:cards/wdio-service.md
  • G3 — u010: no full read receipt for pack:default
  • G3 — u010: no full read receipt for pack:external
  • G3 — u010: no full read receipt for pack:integration
  • G3 — u010: no full read receipt for pack:node
  • G3 — u010: no full read receipt for pack:observability
  • G3 — u010: no full read receipt for slice
  • G3 — u011: no full read receipt for card:cards/_shared.md
  • G3 — u011: no full read receipt for card:cards/wdio-service.md
  • G3 — u011: no full read receipt for pack:default
  • G3 — u011: no full read receipt for pack:external
  • G3 — u011: no full read receipt for pack:integration
  • G3 — u011: no full read receipt for pack:node
  • G3 — u011: no full read receipt for pack:observability
  • G3 — u011: no full read receipt for pack:tests
  • G3 — u011: no full read receipt for slice
  • G3 — u012: no full read receipt for card:cards/_shared.md
  • G3 — u012: no full read receipt for card:cards/wdio-service.md
  • G3 — u012: no full read receipt for pack:default
  • G3 — u012: no full read receipt for pack:external
  • G3 — u012: no full read receipt for pack:integration
  • G3 — u012: no full read receipt for pack:node
  • G3 — u012: no full read receipt for pack:observability
  • G3 — u012: no full read receipt for pack:tests
  • G3 — u012: no full read receipt for slice
  • G6 — 1 kb proposal(s) but no proposal PR recorded (kb-pr.txt) — run pr-kb-proposal.sh

Change map (generated deterministically from the diff)

graph LR
  subgraph nwdio_service["wdio-service"]
    npackages_browserstack_service_tests_cli_modules_testHubModule_deferredFinish_test_ts["⚠ testHubModule.deferredFinish.test.ts<br/>~93 lines"]
    npackages_browserstack_service_src_cli_modules_testHubModule_ts["⚠ testHubModule.ts<br/>~83 lines"]
    npackages_browserstack_service_src_cli_frameworks_wdioCucumberTestFramework_ts["wdioCucumberTestFramework.ts<br/>~55 lines"]
    npackages_browserstack_service_tests_cli_wdioCucumberTestFramework_test_ts["wdioCucumberTestFramework.test.ts<br/>~55 lines"]
    npackages_browserstack_service_src_cli_modules_accessibilityModule_ts["accessibilityModule.ts<br/>~53 lines"]
    npackages_browserstack_service_tests_cli_modules_accessibilityModule_test_ts["accessibilityModule.test.ts<br/>~53 lines"]
    npackages_browserstack_service_src_service_ts["service.ts<br/>~51 lines"]
    npackages_browserstack_service_tests_service_test_ts["service.test.ts<br/>~51 lines"]
    npackages_browserstack_service_src_cli_skipReporter_ts["skipReporter.ts<br/>~17 lines"]
    npackages_browserstack_service_tests_cli_skipReporter_test_ts["skipReporter.test.ts<br/>~17 lines"]
    npackages_browserstack_service_src_cli_frameworks_wdioMochaTestFramework_ts["wdioMochaTestFramework.ts<br/>~15 lines"]
    npackages_browserstack_service_src_insights_handler_ts["insights-handler.ts<br/>~15 lines"]
    npackages_browserstack_service_tests_cli_wdioMochaTestFramework_test_ts["wdioMochaTestFramework.test.ts<br/>~15 lines"]
    npackages_browserstack_service_tests_insights_handler_test_ts["insights-handler.test.ts<br/>~15 lines"]
    npackages_browserstack_service_src_cli_eventDispatcher_ts["⚠ eventDispatcher.ts<br/>~10 lines"]
    npackages_browserstack_service_tests_cli_eventDispatcher_test_ts["⚠ eventDispatcher.test.ts<br/>~10 lines"]
    n_changeset_pr_388_md["pr-388.md<br/>~7 lines"]
    npackages_browserstack_service_src_cli_frameworks_testFramework_ts["testFramework.ts<br/>~5 lines"]
    npackages_browserstack_service_src_constants_ts["constants.ts<br/>~2 lines"]
    npackages_browserstack_service_src_cli_frameworks_constants_testFrameworkConstants_ts["testFrameworkConstants.ts<br/>~1 lines"]
  end
Loading

↻ This verdict comment is the review anchor — it's updated in place on each run (the gate posts its status separately).

— SDK PR Review Agent

@kamal-kaur04
kamal-kaur04 requested review from harshit-browserstack and removed request for dandonarahul2002 November 25, 2026 16:04
…inish wait

- Synthetic mocha rows (static skips, bail and failed-hook cascades) carry
  neverRan on TEST/PRE, so setTestAccessibility marks them as not
  accessibility tests, as the cucumber cascade already does.
- The cucumber scenario end waits at most 5s for its held TestRunFinished;
  the gRPC send has no deadline, and a stalled binary must not hang the
  scenario's after-hook. The send itself keeps going.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kamal-kaur04

Copy link
Copy Markdown
Collaborator Author

Replies to the review findings:

🔴 Mocha never-run tests flagged as accessibility tests: fixed in 23cb3a1. emitSkipReport now passes neverRan: true on TEST/PRE, so setTestAccessibility sets test_accessibility = false for every synthetic row: static skips, the bail cascade and the failed-hook cascade, including the rows this PR now reports as failed. This matches the cucumber cascade. New tests in accessibilityModule.test.ts and skipReporter.test.ts.

🟠 Held TestRunFinished on the afterTest path: fixed in 23cb3a1. Confirmed: testFrameworkEvent sets no gRPC deadline. The cucumber scenario end now waits at most HELD_TEST_FINISH_RELEASE_TIMEOUT_MS (5s) for the held finish. The send keeps running in the background, so nothing is lost, and the timer is cleared when the send finishes first. A new test with a never-settling release confirms the scenario end returns.

🟠 Prepended observer can block others / re-run during notify: not reachable. setTestAccessibility is the only prepend=true observer, and its body is wrapped in try/catch, so it cannot abort the observers after it. It is registered once in the AccessibilityModule constructor (accessibilityModule.ts:51), never while notifyObserver is running, so the mid-iteration case cannot happen.

🟠 failHookAffectedTests assumed on for every mocha run: intended. main is the WebdriverIO 10 line only (dependencies ^10, no v8/v9 code paths), and @wdio/mocha-framework 10 turns the option on when it is unset. Users can still opt out with failHookAffectedTests: false. The 9.x and 8.x lines are on their own branches.

Locally after 23cb3a1: build and lint pass, and the full suite passes (58 files / 1,520 tests). The 3 new tests fail without the fix.

kamal-kaur04 and others added 2 commits November 26, 2026 12:19
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kamal-kaur04

Copy link
Copy Markdown
Collaborator Author

Reply to the new review finding:

🔴 Held TestRunFinished outlasting the release timeout is untracked at worker end (testHubModule.ts, flushTestFinish): fixed in 265384f. Sends taken off pendingTestFinishes are now kept in inFlightTestFinishes until they settle. Both flushTestFinish and the batch flush add to that set, and flushPendingTestFinishEvent() waits on it, including when nothing is pending. So service.after() now waits for a held finish whose scenario end gave up after 5s. A new test in testHubModule.deferredFinish.test.ts keeps a released send open and checks that the worker-end flush stays pending until the send settles. It fails without the fix.

Locally after 265384f: build and lint pass, and the full suite passes (58 files / 1,521 tests).

@github-actions

Copy link
Copy Markdown
Contributor

🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: pending).

This gate confirms a review ran on the latest commit. The verdict itself is advisory — read the findings and use your judgement; it does not block merge. A native GitHub reviewer approval is still separately required by branch protection before this PR can merge.

@kamal-kaur04

Copy link
Copy Markdown
Collaborator Author

RUN_TESTS

@minionhelperappqa

Copy link
Copy Markdown

[SDK Wdio Test] TRA build state: failed | Stability 83% — verdict: failure. Passed: 48, Failed: 10, Aggregate: 58. TRA: https://observability.browserstack.com/builds/l94bz4fxtm2xu8s3zxewqjyez2w0knnztofivm3y

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