v5: record per-step code from the @wdio/session agent history and drop MCP's per-action templates
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 30/100
- Tipo di issue
- Refactoring
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- nodejs, typescript
Direzione di ricerca
The helper goes in src/session/agent.ts beside runActionWithChanges (line 75); read that together with #197's run_code history logic and src/recording/step-recorder.ts, which stores step.code. Model the new test on tests/tools/run-code.test.ts (real agent, stub browser) and use set_geolocation on classic Chromium as the regression. Then remove the routed-tool cases from generateStep in src/recording/code-generator.ts (lines 292-311) and confirm nothing reaches the navigateAction/tapAction fallbacks before deleting them. Done means npm test, tsc --noEmit and npm run lint are green.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Target: feature/v5 (checked at b2b1bf2).
Depends on: #197 (run_code), which already reads exec code from the agent history. Upstream, not blocking: webdriverio/webdriverio#16493 (exec through the agent API), the S5 exporter draft and S6 (frame code is TypeScript) in docs/architecture/v5-upstream-issue-drafts.md.
Problem
docs/architecture/v5-proposal.md:224 plans to "reduce src/recording/code-generator.ts to what session cannot generate; per-action code comes from the agent". On feature/v5 this is half done, and the code comes from two sources.
- Agent-routed tools record
AgentActionResult.code:runActionWithChangescallsrecordCode(result.code)(src/session/agent.ts:75),withRecordingstores it asstep.code(src/recording/step-recorder.ts:11,:52), andgenerateStepprintsstep.codebefore it looks at any per-tool case (src/recording/code-generator.ts:145). run_code(#197) records the history entry instead: it remembersagent.history.at(-1)?.nbefore the call and records the firstexecentry with a highern.
result.code is the code shown to the agent. The history entry (HistoryEntry { n, time, kind, code, action?, args?, path? }, node_modules/@wdio/session/build/types.d.ts:165-175) is what session's own exporter replays. The two are not always the same. In @wdio/session 10.2.0 (node_modules/@wdio/session/build/agent.js, the bundle behind @wdio/session/agent):
geolocationon a classic Chromium session returns only theEmulation.setGeolocationOverridecall ascode. The history entry adds the preload and execute scripts, so the location survives a reload (agent.js:6050-6072). MCP's generated script drops them today.execreturns nocode, only a history entry (agent.js:4303-4308; refs are rewritten to selectors byrewriteRefs,agent.js:4221,build/index.js:7104). This is why #197 had to read the history.- Read actions (
get,is) returncodeand append no history entry (agent.js:4326-4395). MCP routes none of them today. If one is routed later, the current wiring would record a line that reads but does not act. - Session appends an entry only when the action's
historyis non-empty (agent.js:8181-8189), and stripshistoryfrom the result (:8191).
The per-tool templates that duplicate agent code are still in generateStep:
click_element(code-generator.ts:294) andset_value(:297): without an agent these tools returnnoSession(), which is recorded as an error step, so these cases are never reached.navigate(:292) and the selector branch oftap_element(:311): reached only through the no-agent fallbacksnavigateActionandtapAction.agentFor()returnsundefinedonly when the active session has no metadata, wheregetBrowser()throws anyway (src/session/state.ts:35-41). Unverified whether any path reaches them.switch_frame(:301): reached when the agent returns empty code, which happens fortop/parenton BiDi when there is no current page (agent.js:1824,:1845).isSnapshotRef/unreplayableRef(:125-134): routed tools never hit this, because the agent resolves a ref to a stable selector before it emits code (resolveTarget,agent.js:1108-1131).
Which tools go through the agent (feature/v5)
Through agentFor + runAction/runActionWithChanges, so their code comes from the agent:
| MCP tool | Agent action |
|---|---|
click_element |
click |
set_value |
fill |
select_option |
select |
press_key |
press |
perform_actions |
click, fill, select, check, uncheck, press (src/tools/page-input.tool.ts:41-46) |
navigate |
navigate |
switch_frame |
frame |
set_cookie, delete_cookies |
cookies (set/clear) |
set_geolocation |
geolocation, web only and only without altitude (src/tools/device.tool.ts:76-80) |
tap_element |
tap, selector form only (src/tools/gestures.tool.ts:32-34) |
snapshot |
snapshot / find (read-only, not instrumented) |
run_code (#197) |
exec via runAction |
They call WebdriverIO directly through getBrowser(), so MCP has to write their code itself:
execute_script(usesagent.scopeas the browser, but callsexecuteitself;src/tools/execute-script.tool.ts:35-36)scroll,swipe,drag_and_drop, coordinatetap_elementset_geolocationon mobile or withaltitudeswitch_context,rotate_device,hide_keyboardswitch_tab,emulate_devicemock,get_mock_calls,manage_mockexecute_electron_script,trigger_electron_deeplinkopen_web_extension,launch_chrome,get_elementsstart_session/attach_session(the agent is used only for the page report)
Proposal
-
Read the history in one place. Add a helper in
src/session/agent.tsthat takesnbefore the action, and after a successful action records thecodeof every entry whosenis higher. Use every matching entry, notfind: one call can append more than one.runActionWithChangesandrun_codeboth go through it. DroprecordCode(result.code). A failed action appends nothing, so error steps are unchanged. -
Remove the per-tool templates for routed tools:
click_element,set_value, the selector branch oftap_element, andnavigatetogether with thenavigateAction/tapActionno-agent fallbacks once it is confirmed that nothing reaches them. Replace theswitch_framecase with one generic line for a successful routed step that recorded no code (e.g.// switch_frame: no code recorded), so no tool needs its own case for that. -
code-generator.tskeeps what session cannot produce:- the session-start /
remote()preamble, including cloud (BrowserStack, Sauce Labs, TestMu, TestingBot, Digital.ai), Appium and Electron - the attach file shape
- teardown and cloud status marking
- error-step comments
- the
__session_transition__sentinel - the
$/$$shim (:137,:423-425) - the cases for tools that do not go through the agent (list above)
Shrinking it further depends on the upstream exporter (S5).
- the session-start /
The line numbers cited in v5-proposal.md:224 refer to main at 982d6e7 (710 lines). On feature/v5 the file has 732 lines, so those citations need updating when this lands.
Gaps
These are agent actions the routed tools use whose history entry has no code, or has code that does not replay:
snapshot,find: no entry. They only read, so this is expected.frameon BiDi:top/parentwith no current page produce no entry (agent.js:1824,:1845).- The page lookup carries a TypeScript non-null assertion
!(agent.js:1534), so a generated script with a frame switch does not parse as JavaScript. This is upstream S6.
- Ref with no stable selector: the agent emits
ref("eN") /* no selector matches this element, this step only replays in this session */(agent.js:1124). That does not run in a standalone script, and session's owngenerateSpecrejects anyref((agent.js:6726-6731). MCP should comment out such a step, not emit it. exec: no entry when the code is read-only orhistory: false(agent.js:4303). #197 already covers this.cookiesget/list: no code. MCP does not route these.
Every other action in scope does write history code in 10.2.0:
click, including coordinates and new tab (:2795,:2829,:2833)fill(:3046-3095),type(:3335,:3341),press(:3378),select(:3401-3403),check/uncheck(:3495)navigate(:2760)cookiesset/clear(:6416,:6421)geolocation(:6049,:6064,:6074)tap(:2875),swipe(:3541),long-press(:3547),drag(:3508),scroll(:3516-3525)
Out of scope here, noted so they are not lost:
- Direct tools that are recorded but have no generator case print
// [unknown tool] <name>:switch_context,rotate_device,hide_keyboard. switch_tabandemulate_deviceare not wrapped ininstrument(src/server.ts:166,:169), so they are missing from generated scripts entirely.- Session has code-emitting actions for all five (
contexts,rotate,keyboard,tabs,emulate). Routing them is a separate change. swipeanddragwith a duration, coordinate tap and offset drag, and MCP'sscroll(window.scrollByvs session's wheelbrowser.scroll) have no agent equivalent and stay direct (v5-proposal.md:181-187).
Acceptance
- For every agent-routed tool, a step's recorded code equals the joined
codeof the history entries appended during that call. A test uses the real agent against a stub browser, astests/tools/run-code.test.tsdoes in #197. - A regression test:
set_geolocationon a classic Chromium session records the preload and execute lines. runActionWithChangesandrun_coderecord through the same helper, and nothing readsresult.codefor recording.generateStephas no case forclick_element,set_valueor the selector form oftap_element, and none fornavigateonce its fallback is gone. Routed tools leave no per-action template behind.- A step whose code contains
ref(is emitted as a comment, not as code. npm test,./node_modules/.bin/tsc --noEmitandnpm run lintare green.
- Lingua principale
- TypeScript
- Stelle
- 45
- Fork
- 20
- Merge medio
- 2g 9h
- PR unite (30g)
- 16
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di webdriverio/mcp
-
Issue templates with a required 'MCP client' fieldForse già presa @Winify l’ha presa 4 giorni fa. Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
webdriverio/mcp#208 ·
I maintainer di solito rispondono entro 2 giorni
-
Generated code skips switch_context, rotate_device, hide_keyboard, switch_tab and emulate_deviceForse già presa @VB-Blue l’ha presa 2 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 78/100
webdriverio/mcp#213 ·
I maintainer di solito rispondono entro 2 giorni
-
WDIO_MCP_TOOLS=code: a fixed code-mode tool set (session, navigate, snapshot, query_docs, run_code)Apertaenhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 22/100
webdriverio/mcp#212 ·
I maintainer di solito rispondono entro 2 giorni
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
webdriverio/mcp#209 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
enhancement
Difficoltà 3/5 Mezza giornata Idoneità per principianti 65/100
webdriverio/mcp#206 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di webdriverio/mcp
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
rel: fix
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Deltares/fews-web-oc#2400 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
ardia-browser/ardia#4426 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug report: isValidISODateDashOnly accepts text before or after the date-timeForse già presa @bardrop l’ha presa oggi. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
pnp/cli-microsoft365#7713 ·
I maintainer di solito rispondono entro 1 giorno
-
Diagram: Journey Type: Bug / Error
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
mermaid-js/mermaid-v13#1293 ·
I maintainer di solito rispondono entro 1 giorno