Skip to content

waygraph / Block

Interface: Block<In, Out> ​

Defined in: src/engine/block/block.ts:93

A Block wraps one instruction. Its Observed type is an internal detail, erased here. next is optional routing attached by branch() - unset on a plain or connect()-composed Block, meaning "terminal after one step" (today's behavior, unchanged). Returning the Block itself from next is a self-loop. requires is MemKeys this Block's act reads from mem and needs already set - declaring it lets preflight() catch a missing value before any browser action runs, instead of failing loud deep inside act after several real steps already happened.

withVerify/modVerify/modVerifyAll are optional - present (and discoverable by typing someBlock.) on any Block built via defineBlock(), absent on a raw object literal (which is still a perfectly valid Block, e.g. every test fixture in this codebase). They delegate to the identically-named free functions - same logic, chainable as methods for the common case, still callable as withVerify(block, ...) for a block that doesn't have them attached.

Extended by ​

Type Parameters ​

In ​

In extends Checkpoint<string>

Out ​

Out extends Checkpoint<string>

Properties ​

demoPace? ​

optional demoPace?: DemoPace

Defined in: src/engine/block/block.ts:138

Demo pacing for this Block (the { pace } step option). Demo/step only - runGraph ignores. Prefer fastForwardComposeBlock for blitz.


description? ​

optional description?: string

Defined in: src/engine/block/block.ts:105

A human-readable sentence describing what this Block actually tests or does - "the outsider case: a user outside a request's audience is denied its detail page," not a restatement of the code. Purely additive, optional narration for a human watching a run (demo tooling shows it before the Block runs) - never read by runGraph/connect/anything that decides behavior. A Block with none just shows its name instead.


instruction ​

instruction: Instruction<In, Out, unknown>

Defined in: src/engine/block/block.ts:107

The act/observe/resolve/verify pipeline itself. See Instruction.


name ​

name: string

Defined in: src/engine/block/block.ts:95

A short, stable label - shows up in every error this Block can produce ("Y: check X didn't pass").


requires? ​

optional requires?: readonly MemKey<unknown>[]

Defined in: src/engine/block/block.ts:133

MemKeys this Block's act reads from mem and needs already set. Declaring it lets preflight (built into runGraph) catch a missing value before any browser action runs, instead of failing loud deep inside act.

Example ​

ts
requires: [LoginCreds.key]

routes? ​

optional routes?: Readonly<Record<string, string | null>>

Defined in: src/engine/block/block.ts:125

branch()'s routing table as plain, readable data - Checkpoint tag -> target Block's .name (null for a terminal tag) - alongside next itself, which stays the actual runtime dispatch. next is an opaque closure a graph-introspection tool can't read; this is next's own routing decisions exposed as data instead, purely additive and never consulted by runGraph/connect - it exists only for tools like Flow's inspection method (and, eventually, toMermaid) to walk without executing anything. A route back to the Block itself (a self-loop) maps to that same Block's own name, not null.

Methods ​

instanceOptions()? ​

optional instanceOptions(page): Promise<readonly WaygraphInstanceOption<unknown>[]>

Defined in: src/engine/block/block.ts:151

Optional. When this Block's real choices depend on the live page (which of several items to add to cart, which of several rows to open) rather than being knowable ahead of time, this returns one option per live choice - waygraph auto lists one menu row per option (via label) instead of a single generic edge, and seeds mem.set(option.key, option.value) before this Block's own act() runs when a row is picked. Purely additive tooling data - runGraph/ connect/anything that decides behavior never consults it; a Block without it behaves exactly as before.

Parameters ​

page ​

Page

Returns ​

Promise<readonly WaygraphInstanceOption<unknown>[]>

Example ​

ts
instanceOptions: (page) => collectInventoryItems(page).then((items) => items.map((it) => ({ id: it.id, label: `Add "${it.name}" to cart`, key: SelectedItem.key, value: it })))

modVerify()? ​

optional modVerify(nameOrIndex, newCheck): Block<In, Out>

Defined in: src/engine/block/block.ts:169

Replaces one existing Trait in this Block's verify list, by its name (recommended) or numeric index, leaving every other check untouched - the v1/v2/legacy-app case, where one check needs a different selector but the rest of the Block is identical. Throws loud if the name/index doesn't exist - use Block.withVerify if there's nothing there yet to replace.

Parameters ​

nameOrIndex ​

string | number

newCheck ​

Trait | ((page, mem) => Promise<boolean | TraitResult>)

Trait


Function ​

(page, mem) => Promise<boolean | TraitResult>

Returns ​

Block<In, Out>

Example ​

ts
LoginBlock.modVerify("url-matches", urlMatches(/dashboard\.html/))

modVerifyAll()? ​

optional modVerifyAll(patches): Block<In, Out>

Defined in: src/engine/block/block.ts:175

Block.modVerify, but for several named checks in one call - a v2 variant that differs in five ways from v1 shouldn't need five nested calls.

Parameters ​

patches ​

Record<string, Trait["check"] | Trait>

Returns ​

Block<In, Out>

Example ​

ts
LoginBlock.modVerifyAll({ "url-matches": urlMatches(/v2/), "cart-badge": textEquals(".badge-v2", "1") })

next()? ​

optional next(checkpoint): SomeBlock | null | undefined

Defined in: src/engine/block/block.ts:113

Routing attached by branch. Unset on a plain or connect()-composed Block, meaning "terminal after one step". Returning the Block itself is a self-loop - see runGraph's maxSteps for the safety net that needs.

Parameters ​

checkpoint ​

Out

Returns ​

SomeBlock | null | undefined


withVerify()? ​

optional withVerify(verify): Block<In, Out>

Defined in: src/engine/block/block.ts:160

Replaces this Block's whole verify list - the only way to clear it to empty (the "I only care that I navigated this far" case) or go from no verify to some. For tweaking one existing check without restating the rest, use Block.modVerify instead.

Parameters ​

verify ​

Trait[] | ((out) => Trait[])

Returns ​

Block<In, Out>

Examples ​

ts
LoginBlock.withVerify([])              // navigation-only, no DOM confirmation
ts
LoginBlock.withVerify([urlMatches(/dashboard/)])

waygraph 0.18.3 (alpha) · Node 24+ · peer @playwright/test ^1.40.0 · syntax may change before 1.0: see what was removed