diff options
| author | amankumarsingh77 <amankumarsingh7702@gmail.com> | 2026-07-28 00:28:45 +0530 |
|---|---|---|
| committer | Aman Kumar <145339995+amankumarsingh77@users.noreply.github.com> | 2026-08-02 19:12:46 +0530 |
| commit | e46f080c03a511b626b21455cfd6094554b02733 (patch) | |
| tree | 54e9866e066ed14fd3a1d20bf14b4435b2fcd9ce /test | |
| parent | bfba73fa2f1373abd8a5a704c9c833d6fce1b44f (diff) | |
fix(domains): restore fill_form and set_checked, drop the stale fork
domains/forms.ts was a stale fork of form.ts imported only by a manual
test. It held two working tools the registry never registered: fill_form
and set_checked. Ported both onto the current pattern and deleted the
fork; form.ts versions of the shared tools win.
The fork's tools took ref as Type.Integer (a raw CDP backendNodeId).
browser_snapshot has since moved to string refs ('e7') resolved through
the session ref map, so as written the tools were not callable at all.
Ported them onto resolveRefToObjectId and Type.String refs; the only
user-facing strings that changed are the four that documented the old
[ref=N] syntax. All page-side JS is carried byte-for-byte.
form.ts exceeded 250 lines, so fillForm moved to form-batch.ts per the
single-field/batch split. form.ts is still 425 lines — the pre-existing
three tools account for that, so the split does not reach the target.
test/manual/forms-test.ts is repointed and adapted to publish an 'eN'
ref map, but NOT executed — it needs a live Chrome. Type-checked only.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'test')
| -rw-r--r-- | test/domains/registry-test.ts | 2 | ||||
| -rw-r--r-- | test/manual/forms-test.ts | 52 |
2 files changed, 36 insertions, 18 deletions
diff --git a/test/domains/registry-test.ts b/test/domains/registry-test.ts index a35f485..2003b6c 100644 --- a/test/domains/registry-test.ts +++ b/test/domains/registry-test.ts @@ -12,6 +12,8 @@ const SERIALIZED = new Set([ "browser_click", "browser_type", "browser_fill", + "browser_fill_form", + "browser_set_checked", "browser_select_option", "browser_focus", "browser_press_key", diff --git a/test/manual/forms-test.ts b/test/manual/forms-test.ts index f1c79f6..51c1600 100644 --- a/test/manual/forms-test.ts +++ b/test/manual/forms-test.ts @@ -12,13 +12,14 @@ */ import { createDaemonTransport } from "../../src/cdp/daemon-transport"; import { createBrowserClient } from "../../src/client"; -import { fillTool, fillFormTool, selectOptionTool, setCheckedTool } from "../../src/domains/forms"; +import { fillTool, selectOptionTool, setCheckedTool } from "../../src/domains/form"; +import { fillFormTool } from "../../src/domains/form-batch"; // NOTE: we intentionally do NOT import snapshotTool here — it pulls in pi-tui / // pi-coding-agent value imports that don't resolve under bare tsx. Instead we -// derive refs from Accessibility.getFullAXTree's backendDOMNodeId, which is the -// exact value browser_snapshot surfaces as [ref=N]. The snapshot's [ref=N] -// rendering is covered by `npm run typecheck` + the real-page smoke test. +// publish an 'eN' ref map onto the session from Accessibility.getFullAXTree, +// which is what browser_snapshot does when it prints [eN]. The snapshot's own +// ref rendering is covered by `npm run typecheck` + the real-page smoke test. let passed = 0; let failed = 0; @@ -59,15 +60,30 @@ const FIXTURE = ` </script> </body></html>`; -// Resolve a ref by accessible name via the AX tree — the same backendDOMNodeId -// that browser_snapshot prints as [ref=N]. -const refByName = async (client: any, name: string): Promise<number | undefined> => { +// Publish an 'eN' ref map onto the session for the given accessible names and +// return name → ref, mirroring what browser_snapshot does. +const publishRefs = async (client: any, names: ReadonlyArray<string>): Promise<Record<string, string | undefined>> => { const ax = await client.session().call("Accessibility.getFullAXTree", {}); - if (!ax.success) return undefined; + if (!ax.success) return {}; + const byName = new Map<string, number>(); for (const n of (ax.data as any).nodes as any[]) { - if (n?.name?.value === name && typeof n.backendDOMNodeId === "number") return n.backendDOMNodeId; + if (typeof n?.name?.value === "string" && typeof n.backendDOMNodeId === "number" && !byName.has(n.name.value)) { + byName.set(n.name.value, n.backendDOMNodeId); + } } - return undefined; + const refMap = new Map<string, number>(); + const refSig = new Map<string, string>(); + const out: Record<string, string | undefined> = {}; + names.forEach((name, i) => { + const backendId = byName.get(name); + if (backendId === undefined) return; + const ref = `e${i + 1}`; + refMap.set(ref, backendId); + refSig.set(ref, `|${name}||`); + out[name] = ref; + }); + client.session().setRefMap(refMap, refSig); + return out; }; async function main(): Promise<void> { @@ -84,16 +100,16 @@ async function main(): Promise<void> { // Give the inline script a beat to wire up listeners. await new Promise((r) => setTimeout(r, 300)); - // ── Resolve refs (the backendDOMNodeId browser_snapshot prints as [ref=N]) ── + const byName = await publishRefs(client, ["plain", "ta", "controlled", "country", "agree", "bio"]); const refs = { - plain: await refByName(client, "plain"), - ta: await refByName(client, "ta"), - controlled: await refByName(client, "controlled"), - sel: await refByName(client, "country"), - chk: await refByName(client, "agree"), - editable: await refByName(client, "bio"), + plain: byName["plain"], + ta: byName["ta"], + controlled: byName["controlled"], + sel: byName["country"], + chk: byName["agree"], + editable: byName["bio"], }; - for (const [k, v] of Object.entries(refs)) check(typeof v === "number", `ref present for ${k} (${v})`); + for (const [k, v] of Object.entries(refs)) check(typeof v === "string", `ref present for ${k} (${v})`); // ── Batch fill text fields ────────────────────────────────────────────────── const fill = await fillFormTool.handler({ |
