Files
Karthik Kalyan c58cae6612 [Docs] Cookbook update for child workflows pattern (#2100)
* docs(cookbook): replace child workflow polling with hook resume pattern

Recommend startAndWait() with withChildCompletionHook() for v4 and v5 child
workflow orchestration instead of getRun().status polling loops.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Fix child-workflows cookbook review feedback

Tighten resumeParentCompletion to a discriminated union so hook.resume
typechecks, add zod to the vitest workbench, remove unused resumeHook
import, and add an empty changeset per AGENTS.md.

Co-authored-by: Cursor <cursoragent@cursor.com>

* docs(cookbook): trim child-workflows hook resume guide

Remove redundant polling comparison copy, the getRun() alternative section, and v5-only start() tips to keep the cookbook focused on the hook pattern.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-25 16:02:19 -07:00
..

@workflow/vitest-workbench

This workbench demonstrates how to test workflows with Vitest using the @workflow/vitest plugin.

How It Works

  1. Vitest Plugin: The workflow() plugin from @workflow/vitest handles SWC transforms, bundle building, and in-process handler registration automatically.
  2. No Server Required: Workflows execute entirely in-process using a Local World instance — no HTTP server needed.
  3. Tests: Use start(workflow, args) and await run.returnValue, plus helpers like waitForSleep() and waitForHook().

Usage

pnpm test

Project Structure

workbench/vitest/
├── workflows/
│   ├── simple.ts          # Basic workflow with arithmetic steps
│   ├── sleeping.ts        # Workflows with sleep() calls
│   ├── hooks.ts           # Workflow with createHook() for external data
│   └── webhook.ts         # Workflow with createWebhook() for HTTP payloads
├── test/
│   └── workflow.test.ts   # Integration tests for all workflow types
├── vitest.config.ts       # Vitest config with workflow() plugin
├── MOCKING.md             # Analysis of mocking limitations
└── package.json

Test Coverage

  • Simple workflow: Start and await return value
  • Sleep workflow: waitForSleep() → wakeUp() to skip sleep
  • Multi-sleep workflow: Targeted wakeUp() with correlation IDs
  • Hook workflow: waitForHook() → resumeHook() with approval/rejection
  • Webhook workflow: waitForHook() → resumeWebhook() with Request payload