Skip to content

How workflow tests run

A workflow test is only worth writing when its answer is the answer a user would get. This page explains how the runner achieves that, what it fixes so that two runs agree, and which things it leaves alone. The syntax is in Workflow tests. A walkthrough is in Test a workflow of your app.

The runner starts the engine’s own HTTP handler and talks to it over TLS. It does not call a save function, and it does not read a page into a data structure.

  • as <user> signs in through the login form, and the session cookie keeps the shape that it has in production: Secure, HttpOnly, with the __Host- prefix.
  • open asks the engine’s routing for the address of a page. A test never contains a URL.
  • fill and submit read the form out of the HTML that the engine drew for this user. The controls, the hidden fields, the CSRF token and the return address travel as a browser would send them.
  • The runner reads the first response and follows no redirect, so a 303 to the login page is an answer and not a page. There is one exception. A public page of an application with several languages is answered with a 302 to its address under the language prefix when the request names another language, and the runner follows that redirect once, as a browser does, and notes it. It recognises the redirect by what the engine does and with the engine’s own code for the prefix, so it never follows a login redirect or any other.
  • open … from <page> is the request of a click on a link of the site. It carries the headers that a browser sends for one (Sec-Fetch-Site: same-origin and the address of the first page as the Referer), because the engine serves a click and a first visit differently. The runner follows no language redirect for a click. When the page after from is on the screen, the runner also reads the page that the engine drew and checks that it holds a link to the address. It does not work out which links a page should draw. The page of the engine is the one answer to that question, as it is for the forms.
  • download asks the engine for the address that a link to a stored file draws, and the engine writes the address. A page routed by an unguessable column writes the token of its row into the address, and serves the file to the holder of the token only. download … with token … requests that address with the value of a column of a bound row. The runner writes no parameter name: a test that sends the token fails when the engine changes how a token page writes it.
  • sign out sends the sign-out form of the account menu, with the CSRF token of the session, and the engine revokes the session on the server. The user is then anonymous. The next as <user> is a new sign-in with a new session, and as <user> with no sign out goes back to the session that the user already holds.
  • dev() is false. A page that you closed for production stays closed, unless the suite says dev: true. The command prints a note when it does.

The routing, the session, the CSRF check, the authorization and the write path are therefore all in the test, and a test fails when one of them changes the answer.

The engine draws a transition button only for a user whose rule allows it, and only on a row in a source state. A test that says an author cannot publish has no button to press. The runner sends the request that the button would have sent: the same address, the CSRF token of the page and the same fields. The request goes through the same code as every other request, and the engine’s 403 is the answer. The test notes record each such step. A delete that the page did not offer is sent the same way. When the page draws no form of the region at all, the delete also needs anyway, as a save does.

A save does this only when you ask for it. A plain fill of a form that the engine did not draw fails, because a form that vanished for a reason you did not expect must not pass silently. When the page replaced the form with the sentence of a deny when, write fill <table> anyway { … }. The runner then sends the save that the form would have sent, with the token, the region number and the language of the page, and records a note. The engine still decides: a rule that the page enforces by drawing nothing must also be enforced by the write, and this step is the test of that.

The same rule chooses the form of a fill. A page can hold two forms of one table, such as the time entry form of a consultant and the one of backoffice. The page the engine drew for the user is the one answer to “which form is this user shown”, so a fill is for the form that the page drew to the user who acts. The runner does not copy the access rules of the engine. When the page draws two forms to one user, a fill names the form with the test_id: of its region. A delete has no fields to tell the forms apart, so submit delete in region <test_id> names the form of a delete in the same way.

The box that removes a stored file is the same kind of thing. The engine draws the box only for a row that stores a file, and a test that writes remove file ticks the box that the page drew. The runner sends what a browser sends for a ticked box and does not clear any column itself. When the page has no box, the step fails and says so.

A sheet region is a grid with JavaScript, and the engine accepts one save for it: a JSON document with the rows that changed, each with the stamp that the engine computed for it. A form step has no form to read, so the sheet step does what the grid does. It reads the grid configuration out of the page, reads the rows that the sheet lists from the same address as the grid, and sends the document to the address that the configuration names. The engine turns the document into the same fields as a form and runs one write for both. This means that the stamp check, the grants, the hooks and the transaction of a test are the ones that a person’s save meets. The runner does not run the JavaScript of the grid: it sends what the grid would send for the cells that you name.

The stamp is the one thing a test cannot invent. A row that the sheet does not list has none, so a plain step names such a row and stops. With anyway, the runner sends the row with a stamp of no row. The engine looks for the row under the where: of the sheet before it compares a stamp, so its answer, “at least one row no longer exists”, is the answer to the row and not to the stamp. The whole save fails, and the test shows that no row changed.

Two refusals of a transition look the same on the page, because in both the page drew no button. The engine answers them with different statuses, and so the words differ.

What the user lacks The engine answers The word
The role of the transition’s access: rule. 403 refused
The row. The user holds the role, but the where of the rule, or the page’s row filter, excludes this row. 404 missing

The engine asks the role question first, before it reads any row, so a role that the user does not hold is a 403 for every row. Only after that does it read the row under the filter of the transition. A row that the filter excludes is a row that the user cannot see for this purpose, and the engine answers 404 for it, as for a row that does not exist. A 403 for it would tell the user that the row exists. A user can also be able to open the page of a row and still get 404 from the transition: the page and the transition each carry their own filter.

In the expenses example, finance opens an employee’s draft claim and the page answers ok. The submit transition is employee where employee = :user.employee_id, and finance also holds the employee role, so run transition submit is missing. An employee who holds no approve right and runs approve gets refused. A test that proves “this role cannot press this button” has to choose the word by this rule. The test notes say “drew no button” in both cases.

Once per suite the runner installs your application into a template tenant, the way matterdata install -seed does: the schema, the model, the seed rows and the logins. Once per test it copies that template, with its blob files, into a directory of its own and serves the copy. When the test ends, it removes the directory.

  • A test cannot see the rows of another test, and it does not depend on the order of the tests. The example suites pass when their tests run in reverse and in a shuffled order.
  • Requests commit as they do in production. A test is not wrapped in one transaction that is rolled back.
  • The runner never touches an existing tenant.

The copy is cheap. On 2026-10-01, for the 63 tests that the example suites held on that day, the template cost 0.25 s in total and the copies cost 0.44 ms each. A fresh install for each test would have cost 1.2 s more. The suites have more tests now, and these are the figures of that day. See docs/measurements/2026-10-01-workflow-test-examples.md in the repository.

These are the sources of variation that the runner fixes, and how:

Source What the runner does
The time Every request, every default, every rule, every hook, every audit stamp and every session reads the clock: of the suite. The seeded rows carry it too.
The language The locale: of the suite, or of the user, is the Accept-Language of every request, and the notation of the values in fill.
Random numbers in hooks Math.random is seeded from the names of the suite and the test.
Slugs They come out of the title by a fixed rule, so you can assert them.
Tokens An unguessable value is random by design. A test reads it from a binding and never asserts it.
Login limits The rate limit of the login form is off. The lockout of an account is not.
Passwords They are hashed with a cheaper setting than production. A login still checks a hash.
Jobs and mail No scheduler runs. Mail is a row in the outbox, and nothing delivers it.

Timeouts and size limits stay on real time and keep their production values. Two things carry the real clock: the created_at of the engine’s own rows (the login and the model record), and the log lines of the server. No assertion reads them.

expect row, expect none and expect count read the committed rows through a second connection to the tenant file. The connection is read-only. It applies no right, no row filter, no app scope and no gone exclusion. That is deliberate. A filter could hide the row that a wrong write produced, and the test would pass for the wrong reason.

The consequence is that a row in the database does not prove that a user can see it. To test a denied write, assert twice: once the outcome, and once with expect row or expect count that the rows did not change. To test what a user is shown, read the page, as the next section describes.

Page assertions read the response, not the database

Section titled “Page assertions read the response, not the database”

expect shows, expect hides and expect rows are a second kind of assertion. They read the response that the runner already holds after open … expect ok, or after a save or a transition that the engine answered by drawing the page again. They send no new request and run no query.

The runner does not decide what a user may see. A row filter, a scope, a grant, a gone state and a where: of a region are decided by the engine when it draws the page. If the test package asked the same question again, it would hold a second answer, and the two answers could differ. The test reads the one answer that the engine gave.

The runner reads the HTML as a person reads it. It takes the text of the <main> element and not the header or the footer, and it finds a region by one of two markers that the engine writes. The first is the id of its heading, which the engine writes for every region that has a label, from the position of the region on the page. The second is data-testid, which the engine writes for a region whose source declares a test_id:. The runner uses the engine’s own functions for the position, the id and the test id. A region that the engine did not draw for this user is not found, and the step fails. Without this rule, expect hides in a region that the user may not see would hold, and the test would prove nothing.

The result is true of this page, for this user, in this state of the data. It is not a test of the look of the page. The text of a label is copy, and a change of words can break a shows. A number of rows and a value from your data are stable. Read Check what the page shows for the syntax and the limits.

An outcome word is one shape of response of the engine: 200, a 303 to a page, a 303 to the login page, a 403, a 404, a 410, a form with marked controls, or a 200 with the message of a rule and no marked control. A step that is expected to end in saved and ends in a 403 fails with both words, the status, the Location and the messages that the page showed. A response that fits no word is reported as it is, with the reason. When the engine means to give such an answer, the test says its status: expect 400. Only a 4xx that no word names may be written, so a status that has a word, a redirect and a server error cannot hide behind a number. One server answer has a word: unavailable is a 503, the answer of a page that cannot be built yet, such as a page of an app with a scope before the first scope row. The engine gives that answer on purpose, and the page that it draws says why. Any other 5xx is a defect, and a test that expects it would pass while the defect stays.

A 200 can mean three things, and the runner tells them apart by what the engine drew. A page without a message is ok. A form with marked controls is invalid. A page that shows the message of a rule and marks no control is rejected: a table check, a unique over several columns, a deny when, a require or a hook stopped the step. The engine draws that message in two places only, the top of the form that was sent and the warning note of the lifecycle. The runner reads those two places. A note that your page shows by its own note declaration is not a refusal.

A stopped transition is therefore rejected and never ok. Before the word existed, a test could write expect ok after a transition that a rule had stopped, and the test passed for a reason that was not the rule. Now a run cannot end in ok at all: its 303 is saved, and its 200 always carries the sentence of a rule, so it is rejected. The validator refuses expect ok after a run before any request.

A delete that a delete { access: … } block withholds from the user is a 403, so it is expect refused. A delete that the form does not have at all (actions: does not list it) is a 400, and no outcome word fits it. The test writes expect 400. The same answer refuses a save sent to a form region that the access: of the region withholds from the user, and it is the answer for a region that does not exist, so the test learns nothing about which regions exist.

Website privacy policy