From ee54c474b64eb3e73729823e1fc7c71a8d0afae0 Mon Sep 17 00:00:00 2001 From: PJ Date: Mon, 1 Jun 2026 16:31:37 +0530 Subject: [PATCH] refactor(spec): bridge data-tree nodes to the legacy goja picker tags --- pkg/spec/src/actions.ts | 57 +++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/pkg/spec/src/actions.ts b/pkg/spec/src/actions.ts index 2b85eea..b7a7a4e 100644 --- a/pkg/spec/src/actions.ts +++ b/pkg/spec/src/actions.ts @@ -22,10 +22,39 @@ import type { WaitAction, WeightedEntry, } from "./types.ts"; -import type { ActionDescriptor, GeneratorNode } from "./action-tree.ts"; +import type { ActionDescriptor, BuiltinVerb, GeneratorNode } from "./action-tree.ts"; + +// LEGACY GOJA BRIDGE. The new data-tree nodes carry the old goja picker's tags +// (__sanderlingKind / entries / per-verb kind) so worker.go keeps walking them +// unchanged until Phase 2 rewires goja onto pick.ts. pick.ts ignores these +// fields. Delete this bridge (and the goja picker) in Phase 2. +const VERB_LEGACY_KIND: Record = { + taps: "taps", + doubleTaps: "doubleTaps", + longPresses: "longPresses", + scrolls: "scrolls", + typing: "typing", + swipes: "swipes", + waitOnce: "waitOnce", + pressKeys: "pressKey", +}; + +function builtinNode(verb: BuiltinVerb): GeneratorNode { + return { + kind: "builtin", + verb, + __sanderlingActionGenerator: true, + __sanderlingKind: VERB_LEGACY_KIND[verb], + } as GeneratorNode; +} export function actions(generator: () => Action[]): GeneratorNode { - return { kind: "actions", generate: generator as () => ActionDescriptor[] }; + return { + kind: "actions", + generate: generator as () => ActionDescriptor[], + __sanderlingActionGenerator: true, + __sanderlingKind: "actions", + } as GeneratorNode; } export function whenRoute( @@ -42,7 +71,13 @@ export function whenRoute( } export function weighted(...entries: WeightedEntry[]): GeneratorNode { - return { kind: "weighted", branches: entries }; + return { + kind: "weighted", + branches: entries, + __sanderlingActionGenerator: true, + __sanderlingKind: "weighted", + entries, + } as GeneratorNode; } // samplerRng is the picker's Pcg while it evaluates an `actions` node's @@ -112,11 +147,11 @@ export function Wait(parameters: { durationMillis: number }): WaitAction { return { kind: "Wait", durationMillis: parameters.durationMillis }; } -export const taps: GeneratorNode = { kind: "builtin", verb: "taps" }; -export const doubleTaps: GeneratorNode = { kind: "builtin", verb: "doubleTaps" }; -export const longPresses: GeneratorNode = { kind: "builtin", verb: "longPresses" }; -export const scrolls: GeneratorNode = { kind: "builtin", verb: "scrolls" }; -export const typing: GeneratorNode = { kind: "builtin", verb: "typing" }; -export const swipes: GeneratorNode = { kind: "builtin", verb: "swipes" }; -export const waitOnce: GeneratorNode = { kind: "builtin", verb: "waitOnce" }; -export const pressKey: GeneratorNode = { kind: "builtin", verb: "pressKeys" }; +export const taps: GeneratorNode = builtinNode("taps"); +export const doubleTaps: GeneratorNode = builtinNode("doubleTaps"); +export const longPresses: GeneratorNode = builtinNode("longPresses"); +export const scrolls: GeneratorNode = builtinNode("scrolls"); +export const typing: GeneratorNode = builtinNode("typing"); +export const swipes: GeneratorNode = builtinNode("swipes"); +export const waitOnce: GeneratorNode = builtinNode("waitOnce"); +export const pressKey: GeneratorNode = builtinNode("pressKeys");