Test your flow
A flow test runs the same flow engine that runs your agent, on text instead of audio. It needs no VoiceThere key, no LLM key and no network, so it fits in the CI you already have: every push and pull request can check that the flow still says what you wrote down and takes the path you expect. A test never blocks a deploy. It tells you something changed, and you decide what to do about it.
The tests come with the flow-agent template and need @voicethere/agent 0.41.0 or later. See the Flow builder guide for the flow file itself.
Run the tests in CI
The template ships .github/workflows/flow-tests.yml at the project root. It needs no secret. On every push and pull request it validates the flow file, runs the Jest tests, runs the scenarios file and uploads the result as flow-tests.xml. Commit your package-lock.json so npm ci works.
The commands below run from the project root, the folder with package.json. They assume the flow files sit in flow-agent/, which is where the template puts them. If you moved them, change the paths. For GitLab CI:
flow-tests:
image: node:22
script:
- npm ci
- npx @voicethere/agent flow validate flow-agent/voicethere.flow.json
- npm test
- npx @voicethere/agent flow test --reporter junit --file flow-agent/voicethere.flow.tests.json --flow flow-agent/voicethere.flow.json --mocks flow-agent/voicethere.flow.mocks.json > flow-tests.xml
artifacts:
when: always
reports:
junit: flow-tests.xmlIn a plain shell script, run the same four commands one after another and stop at the first one that fails.
Three ways to answer the flow's outside calls
The shipped flow has a lookup node that calls https://api.example.com/invoices/latest. The template's flow.test.ts shows all three approaches against it.
- Mock answers.
createFlowTestRun(flow, { mocks })answershttp,mcp,llmandroutenodes fromvoicethere.flow.mocks.json. Withoutcases, each node uses its first case. Pick another withcases: { lookup: "missing" }, or write an answer inline withoverride: { lookup: { http: { error: "HTTP_TIMEOUT" } } }, which wins overcases. A node with no case fails the test withMOCK_MISSINGand the node id. It never falls back to a made-up answer. - Your own server. Start your backend on port 0 and let the flow call it for real.
createFlowTestRun(flow, { mocks, http: realHttp({ only: ["lookup"], baseUrl: { "https://api.example.com": base } }) })sends the calls of thelookupnode tobaseand keeps the path and query. The match is on the exact origin. Every otherhttpnode keeps its mock.realHttpcomes from@voicethere/agent/flow/testing/node. - nock.
http: realHttp({ only: ["lookup"] })sends the call through the globalfetch, so nock (version 14 or later) or msw can answer it. The test then also checks the real request: URL, headers and body.
A real call is bounded by the node's timeoutMs (default 5 seconds, in real time). When it runs out, the node fails with HTTP_TIMEOUT.
Where supertest fits
request(app).get("/invoices/latest").expect(200) sends a request into your server and checks the answer. That tests your API, not your flow, and it cannot see what the flow sends out. This is why the second approach above starts the same Express app on a port: one app then serves your API tests and your flow tests.
Write a Jest test
import { fileURLToPath } from "node:url";
import { createFlowTestRun } from "@voicethere/agent/flow/testing";
import { loadFlowFiles } from "@voicethere/agent/flow/testing/node";
import "@voicethere/agent/flow/testing/jest";
const { flow, mocks } = loadFlowFiles(fileURLToPath(new URL(".", import.meta.url)));
test("an invoice question gets the invoice status", async () => {
const run = createFlowTestRun(flow, { mocks });
await run.start();
await run.say("I have a question about my invoice");
expect(run).toHaveVisited(["greet", "ask", "topic", "lookup", "billingReply"]);
expect(run).toHaveSaid(/latest invoice is paid/i);
expect(run).toHaveEndedWith("done");
});The template uses Jest as ES modules, because @voicethere/agent is an ES module package. The test script passes --experimental-vm-modules, and flow-agent/jest.config.js uses @swc/jest to compile the TypeScript. Node prints an experimental warning; that is expected. Vitest works too, because createFlowTestRun and the matchers do not depend on Jest.
A project created before the template had tests has no test script. Add the dev dependencies and the script by hand:
npm install --save-dev jest @swc/core @swc/jest supertest nock express
"scripts": {
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config flow-agent/jest.config.js"
}From CLI 0.25.0, voicethere init --template flow-agent writes the script, the dev dependencies and the workflow for you. With an older CLI, or a project that was already created, use the commands above.
What a run gives you
run.say(text)sends one caller turn.run.silence()is a caller who stays quiet: it fires thelistennode's no-input timer, so the flow takes itsonNoInputpath. Both return the replies, path and end state of that turn alone.run.repliesis everything the agent said, in order.run.pathlists every node entered, in order.run.varsholds the variables.run.endedis{ reason }once the call has ended.run.errorslists node failures withnodeId,codeandhandled.run.traceis the full trace with values.- Matchers:
toHaveVisited(in order, other nodes may sit between),toHaveSaid(text or regex),toHaveEndedWith,toHaveHandledError,toHaveUnhandledErrorandtoHaveVar. Their failure messages show the actual path and replies.
Errors use the engine's own codes: HTTP_TIMEOUT, HTTP_NETWORK, HTTP_<status> such as HTTP_404, and the codes of mcp, llm and route nodes.
Scenarios without code
voicethere.flow.tests.json holds the same kind of test as data. Each scenario lists its turns (say or silence), the cases and vars to use, and what to expect after each turn and at the end: said (a substring, or { "regex": "..." }), visited (the nodes of that turn, in order), ended, vars and errors. The schema is at @voicethere/agent/flow/tests-schema.json. Add "$schema": "./node_modules/@voicethere/agent/schema/voicethere.flow.tests.schema.json" for editor hints.
Run the file with the agent package alone, no Jest needed. From the flow-agent/ folder, where the flow files sit:
npx @voicethere/agent flow test npx @voicethere/agent flow test --filter billing npx @voicethere/agent flow test --reporter junit > flow-tests.xml
--filter text runs only the scenarios whose name contains the text. --reporter junit prints a JUnit XML report to stdout and sends everything else to stderr, so the redirect stays valid XML. Exit codes:
| Code | Meaning |
|---|---|
| 0 | Every scenario passed. |
| 1 | A scenario failed, the flow is invalid, --filter matched no scenario, or the command was used wrongly (unknown option, bad --reporter). |
| 2 | The tests file cannot be read, is not JSON, or does not match the schema. |
flow validate exits 1 on any error.
The Tests panel in the dashboard
The Flow tab has a Tests panel for the same scenarios. It lists them, and Run all runs them in the browser against your mock answers, with no real service called. Each scenario shows pass or fail and its first failure. Click a failure to open the simulator and replay that scenario.
To create a scenario, open the simulator, talk to the flow, name the run and choose Save as test. The scenario records the messages you typed, the mock cases used, the first sentence of each reply, the nodes visited and the end reason. Save the flow to keep it: the scenarios are saved in voicethere.flow.tests.json next to the flow, and a file that does not match the schema is refused with an error. Because the file lives in your project, the same scenarios also run in CI with flow test.
The dashboard runs scenarios on your mocks. It does not call your server. To check the real request your flow sends, use the second or third approach above in CI.