Skip to content

Move duplicated adapter code into core - #522

Merged
vishnuv688 merged 1 commit into
mainfrom
refactor/adapter-duplicates-to-core
Nov 2, 2026
Merged

vishnuv688 merged 1 commit into
mainfrom
refactor/adapter-duplicates-to-core

Conversation

@vishnuv688

@vishnuv688 vishnuv688 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

What & why

Closes #528 (the last of three cleanup PRs). Part of #494. Stacked on #521.

A duplicate-block scan found the same code in two or three adapters, word for word, plus repeats inside single adapters. Each true duplicate now lives once. No behaviour change: log text, logger names and every adapter's BiDi attach behaviour are as before.

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Polish (an improvement to an existing feature)
  • Breaking change (existing behavior changes for users)
  • Documentation
  • Internal (build, CI, dependencies, tooling)

Packages touched

  • shared (types and contracts)
  • core (framework-agnostic capture/reporting)
  • elements (published element/snapshot API — @wdio/elements)
  • service (WebdriverIO adapter)
  • nightwatch-devtools (Nightwatch adapter)
  • selenium-devtools (Selenium adapter)
  • selenium-devtools-py (Selenium Python adapter)
  • backend (server)
  • app (UI)
  • script (page-injected runtime)
  • trace (Trace mode)

Capability matrix

  • packages/conformance/src/features.ts updated, and tables regenerated with pnpm docs:capabilities, if this adds or changes user-facing behaviour

Not needed: no behaviour change.

Notes for reviewers

Why this is in core, though it touches every adapter: the screencast lifecycle logging existed in three adapters and the BiDi sink wiring in two, word for word, so a change to either had to land in every copy, which is CLAUDE.md's rule for core. Each adapter still owns what is its own: its logger name, Nightwatch's screenshot transport, and Selenium's console evidence latch.

Finding Decision
Screencast start, stop and unavailable log lines, 3 copies Core. ScreencastRecorderBase writes them through a logger each adapter sets (ScreencastLogger), so logger names are unchanged; no logger means silent, as before
Selenium and Nightwatch buildBidiSinks Core, copied verbatim. Selenium's console evidence latch (bidiConsoleObserved) stays in Selenium, passed in as onConsoleEntry. Each adapter's attachBidiHandlers wrapper stays: it only binds its logger name
Selenium mocha, cucumber and jest run summaries One helper in the adapter, runnerHooks/run-summary.ts (jest's log text is identical, as it always reports 0 pending)
Selenium and Nightwatch PluginInternals repeating their context types extends the context interfaces, redeclaring only fields whose readonly differs. Type-only
Nightwatch captured and replaced command rows One private #commandEntry; a retry still keeps the previous row's id
WDIO launcher and standalone argv parsing service/src/invocation-args.ts, its own module because the launcher patches http.Server.prototype.listen at load during a rerun, which must not reach the worker bundle
Selenium and Nightwatch types.ts Kept: re-exports of shared types under stable local names, as CLAUDE.md endorses

Scan, pairs involving an adapter: 14 before, 2 after (the types.ts re-exports, and the backend vs Nightwatch config-file search kept in #521).

New core exports: ScreencastLogger, buildBidiSinks, BidiSinkTarget. The one renamed function, detectInvocationConfigPath to configPathFromArgv, was documented as not public API, so no changeset. None of these has a Python mirror.

Testing

  • pnpm install --frozen-lockfile, pnpm build, pnpm test (3437 passed, twice, to rule out the flaky conformance failure seen once while developing) and pnpm lint are green.
  • Dist leak grep: every .js/.cjs file in the service, Selenium and Nightwatch bundles searched, none found.
  • New tests: the recorder's log lines with and without a logger; buildBidiSinks hook order, latch, and replace vs append; the run summary lines and payload.

Screenshots / recordings

Not applicable: no UI change.

🤖 Generated with Claude Code

The same logic sat in two or three adapters word for word, so a change to it
had to land in every copy, which is CLAUDE.md's rule for core:

- The screencast recorder's start, stop and unavailable log lines were
  written by each adapter's subclass; ScreencastRecorderBase now writes
  them through a logger each adapter supplies, keeping its logger name.
- Selenium and Nightwatch built their BiDi console and network sinks the
  same way; buildBidiSinks is now in core, with Selenium's console
  evidence latch passed in as a hook, since only Selenium has one.

Within one adapter: Selenium's mocha, cucumber and jest hooks share one run
summary; Selenium's and Nightwatch's PluginInternals extend the context
types they repeated; Nightwatch builds its captured and replaced command
rows through one helper; the WDIO launcher and standalone mode share their
argv parsing, in a module of its own so the launcher's rerun patch never
reaches the worker bundle.

Kept: each adapter's attachBidiHandlers only binds its own logger name, and
the types.ts files re-export shared types under stable local names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vishnuv688
vishnuv688 force-pushed the refactor/library-duplicates branch from aea93af to 7aa154b Compare October 30, 2026 10:13
@vishnuv688
vishnuv688 force-pushed the refactor/adapter-duplicates-to-core branch from 2b01d71 to f00bd8d Compare October 30, 2026 10:13
@vishnuv688
vishnuv688 changed the base branch from refactor/library-duplicates to main November 2, 2026 10:16
@vishnuv688
vishnuv688 merged commit 6644ede into main Nov 2, 2026
8 checks passed
@vishnuv688
vishnuv688 deleted the refactor/adapter-duplicates-to-core branch November 2, 2026 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove duplicated code across the app, libraries and adapters

1 participant