All jobs

Write Tests for Temporal TypeScript Workflows That Have None

Yes. An agent finds the Temporal workflows in your repo with no test, writes Mocha tests on TestWorkflowEnvironment with mocked activities, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent starts by learning how this repository already tests a workflow, so the new tests look like the old ones. In a repository like temporalio/samples-typescript, hello-world/src/mocha/workflows.test.ts is the template: a before hook creates TestWorkflowEnvironment.createLocal(), the test builds a Worker on testEnv.nativeConnection with workflowsPath: require.resolve('../workflows') and the real activities, runs client.workflow.execute(example, { args, workflowId, taskQueue }) inside worker.runUntil, and asserts on the result; after tears the environment down. workflows-mocks.test.ts beside it shows the other half of the pattern, passing an activities object of stubs, a greet that returns a fixed greeting, instead of the real module. The test script in that sample's package.json is mocha --exit --require ts-node/register --require source-map-support/register src/mocha/*.test.ts, with @temporalio/testing, mocha and @types/mocha in devDependencies.

It then finds who has no tests. The repository is a pnpm workspace with one package.json per sample, and .github/workflows/ci.yml runs npm run build and npm test only for an explicit projects list of nineteen entries, after pnpm prewarm-test-server has downloaded the time-skipping test server once. Samples such as saga, signals-queries, child-workflows, continue-as-new and cron-workflows have a src/workflows.ts, a worker.ts and a client.ts but no src/mocha folder, no test script and no @temporalio/testing in their devDependencies, so nothing exercises them beyond tsc --build. The agent lists every sample in that state and takes the ones whose workflow logic has a branch worth testing.

Each test targets the behaviour the workflow is there to show. For saga, whose openAccount collects a compensations list after each successful step and runs it in reverse when a later activity throws, the agent stubs createActivities with recording functions, makes addBankAccount throw an ApplicationFailure, and asserts that removeClient and clearPostalAddresses ran in that order while disconnectBankAccounts did not, and that the workflow rejects with the original failure; a second test lets every step succeed and asserts no compensation ran. For signals-queries, it starts unblockOrCancel with client.workflow.start, queries isBlockedQuery and expects true, sends unblockSignal and awaits the result, and in a second test cancels the handle and expects a CancelledFailure. For child-workflows, it executes parentWorkflow with three names and asserts the joined string from the three executeChild calls. Workflows that sleep use TestWorkflowEnvironment.createTimeSkipping() so a day passes in milliseconds.

The proof is the suite running the way CI runs it. For each sample the agent adds the test script and the three devDependencies in the shape hello-world uses, writes the tests under src/mocha, runs pnpm install at the workspace root so the shared pnpm-lock.yaml picks them up, then npm run build and npm test inside each sample on Node 22 from .nvmrc. It adds the samples to the projects list in ci.yml so the matrix on Ubuntu, Windows and macOS runs them from now on, and runs pnpm lint and pnpm format:check because the second job in that workflow will.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Write tests for the Temporal workflows in this repository that have none. Read hello-world/src/mocha/workflows.test.ts and workflows-mocks.test.ts, hello-world/package.json, pnpm-workspace.yaml and .github/workflows/ci.yml first, and note the projects list CI tests and how the test server is pre-warmed. List every sample with a src/workflows.ts but no test script or src/mocha folder, and for each one with real logic, such as saga, signals-queries and child-workflows, write Mocha tests on TestWorkflowEnvironment that mock the activities and assert the workflow's behaviour: compensations in reverse order on a failing step for the saga, query then signal then cancel for signals-queries, the joined child results for child-workflows, and time skipping for any workflow that sleeps. Add the test script and @temporalio/testing, mocha and @types/mocha devDependencies in the same shape as hello-world, run pnpm install at the root, run build and test in each sample on the Node version in .nvmrc, add the samples to the projects list in ci.yml, run pnpm lint and pnpm format:check, and open a pull request with the test output per sample.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request on its own branch with one commit per sample: a new src/mocha/workflows.test.ts, the test script and three devDependencies in that sample's package.json, and the matching lines in the shared pnpm-lock.yaml. A final commit adds the samples to the projects list in ci.yml. No workflow or activity source is changed, so the tests describe the code as it is.

The description has a table of samples with the number of tests each gained and what they cover, the mocha output per sample, and the pnpm lint and pnpm format:check results. The transcript at GET /o/{org}/sessions/{id}/messages keeps each build and test run, including the one-time test server download.

Before merging, a reviewer reads the saga test, which encodes the order compensations must run in, and the cancellation test, which depends on CancelledFailure being rethrown as the workflow does today. Both are assertions about intended behaviour, so a reviewer who disagrees changes the test, not the workflow. The CI matrix on the pull request then shows the new samples green on all three operating systems.

Run it on every nightly

Create an automation in the Project that holds the repository with a schedule trigger, a cron such as 0 2 * * * in your timezone, and a prompt that asks for tests on the samples still outside the projects list in ci.yml. Each night one run picks the next untested workflows, writes their tests and opens one pull request; a night with nothing left opens none and says so. An automation run has its own max_runs_per_hour cap.

To start it from your own scheduler instead, send POST /o/{org}/sessions with this body and the repository in resources, with a request_id that is a UUID v5 of the repository and the date, so a retried call returns the run already started.

The use case this job follows, with its automation and trigger: Write the missing tests.

Why run it on Rush?

Testing a Temporal workflow is not like testing a function: it needs a test server, a worker bound to the workflow file, activities replaced by stubs, and sometimes skipped time, and each sample needs its own package.json wiring before Mocha can find anything. That setup is why the untested samples stay untested. An agent copies the pattern the repository already uses and applies it to each one in a sandbox of its own, with the test server download and the builds kept in the transcript.

The pull request carries each sample's test output and the CI change that keeps the tests running on three operating systems, so review is a read of the assertions rather than a rerun. The nightly form keeps the untested list shrinking without anyone scheduling the work.

Frequently asked questions

Does it use the real activities or mocks?

Mocks, in the shape workflows-mocks.test.ts already uses: an activities object of stub functions handed to Worker.create. For the saga, where the activities are produced by createActivities(clients), the stubs record their calls so the test can assert the order compensations ran in. One test per sample also runs the real activities where they have no external dependency.

What about workflows that sleep for days?

They get TestWorkflowEnvironment.createTimeSkipping(), the environment whose server CI pre-warms with pnpm prewarm-test-server. Timers fire as soon as the workflow is waiting on them, so a workflow that sleeps for a day completes in the test immediately and the assertion runs on the result, not on wall-clock time.

Will CI run the new tests?

Only if the samples are in the projects list in ci.yml, because that job loops over an explicit list rather than every workspace. The pull request adds each tested sample to the list, so the matrix on Ubuntu, Windows and macOS with Node 20, 22 and 24 runs them on the pull request itself.

Does it change the workflows to make them testable?

No. Workflow files are left as they are, and the tests assert current behaviour, including the saga rethrowing the original failure after compensating and unblockOrCancel rethrowing CancelledFailure. If a reviewer decides a behaviour is wrong, the test is the place to say what it should be, and a follow-up can change the workflow.

More Temporal jobs

More jobs like this: Write the missing tests

Keep reading