Testing
An app is tested at two levels, and each sees what the other cannot.
- Its logic is tested as functions. A component’s operations on its own
type, and the decisions that write shared state, are pure functions, so a
top-level
expectchecks them with no engine and no browser. - Its behaviour is specified in
.scmspecs: short scripts that click, type and assert against the rendered UI, the way a user sees it. One spec runs twice — natively against a model of the DOM, and in headless Chrome against the real runtime — and both runs must agree.
Specs can also take control of everything that would otherwise depend on the outside world: HTTP answers, interval ticks, connectivity, page visibility, history and storage. And they can assert how much work an update did, so a change that makes a keystroke rebuild a whole list fails a test instead of slipping through.
Check the default first page
Every program must mount at the default environment: /, empty local and
session storage, online and visible, with the remaining boot defaults. A new
app’s main.roc binds mounted = Engine.mounts(main) as a U64 constant. The
compiler mounts that page and reports any reached contract error, crash or
failed inline expect in the app’s own file. An app’s explicit crash or
expect can point to that expression; engine contracts point to the constant.
The check reaches only the default page. Specs still cover routes, later
branches, rows and results. An app needing a session should draw a sign-in
page there; an app rejecting / can draw a not-found page. Removing the
constant disables this check. It costs work proportional to the default mount
on each compilation; it creates no extra runtime mount or retained state.
Decisions as functions
A decision returns the list of writes its transition makes
(Shared State), so its test needs only
the store: store.after(writes) applies a list to the store’s starting
values as a turn applies it, and read(cell) reads a cell of the result.
## Adding a product writes the cart and the notice together.
expect {
after = Shop.store.after(Shop.added({ name: "Tea", price: 4 }))
basket = Shop.cells.basket.cells
actual =
\\tea: ${after.read(basket.cart).quantity("Tea").to_str()}
\\notice: ${after.read(Shop.cells.notice)}
expected =
\\tea: 1
\\notice: Added Tea.
actual == expected
}
## Checking out an empty cart writes nothing.
expect Shop.checked_out(Cart.empty).len() == 0
- Put a
##comment before eachexpect:roc testprints it with a failure. afterenforces the same rule a turn does: a list that replaces a cell an earlier write of the same list wrote fails theexpect.- Chain
afterto set a scene:store.after(first).after(second). A start that depends on the boot data isstore.with_initial(cell, value). - A table is read like any cell, and its rows with
get:store.after(writes).read(table).get(key). - Each
afteris one pure turn. A written table starts its changes before its first modifier;store.after(writes).read(table).inverse()describes that list’s first earlier row for each written key. A table the list does not write retains its last writing turn’s changes.
Run them with roc test in the app’s directory; it runs every top-level
expect in main.roc and the modules it imports.
This is the test that sees a transition that left out a reset, or wrote the wrong cell of the right type. No type checker and no check on the engine can: both are faithful to what the decision said. A spec then checks that the right control runs the decision, and what the user sees when it does.
How specs run
Specs live in <app>/specs/*.scm, one test per file. They are read by one
parser, written in Roc (platform/Scm.roc), which turns the text into a
typed list of steps. Two runners consume that list:
- The native runner. The app’s
main.rocbuilt with--target=x64muslon Linux,arm64macorx64macon macOS, orx64winon Windows: the platform bundles the runner, which mounts the app’sProgramand drives it with the same bytes the browser runtime would send: boot data, DOM events and effect results. Every assertion readsDom.roc, an oracle that decodes the engine’s command stream into a small DOM model and shares no code with the engine. It is fast and deterministic, and it proves that the command stream the engine emitted describes the UI the spec expects. - The browser runner. The same steps, emitted as JSON by the same
parser, are replayed in headless Chrome against the app’s Wasm build and
runtime.mjs. Clicks are real mouse input,fillis a real input event, history, title and storage are the browser’s own. It proves that the runtime applies the stream correctly and that real browser events reach the app as the native runner modelled them.
For a deterministic startup entry, both runners finish cold construction and
its private acknowledgement before the first step. Initial Self/refusal
follow-ups settle there. Placeholder opportunities stay held in spec mode:
only run-opportunity supplies one, so elapsed test-process time cannot
activate a body. An environment task samples the current facts when its
callback runs, after acknowledgement effects, then answers through the ordinary
result turn, like storage reads.
roc signals.roc test prints compiler warnings before running the specs. Warnings
do not change its success status: a warning-only build can still run a passing
story. The tool’s build and serve commands show those reports too.
Neither runner proves the other’s half. The native runner never runs the JavaScript runtime or real event dispatch; the browser runner is too slow for long random walks and reads the engine’s counters only through its exports. Run both before you trust a change.
Both runners implement every step of the language with the same meaning, and a check fails the build if the grammar gains a step the browser runner has no handler for. Nothing is ever skipped or weakened, and no spec is allowed to pass in one runner and fail in the other.
A sample app needs only its module and two small entry points. This one searches over HTTP, with an optional auto-refresh interval:
view : State(Ctx, S) -> Elem(Ctx)
view = |st| {
v = st.signal()
Html.div(
"search",
[
Html.form(
"Search",
[Html.on_submit(st.update(|s| { ..s, query: s.draft, round: s.round + 1, status: Loading }))],
[
Html.text_input(Engine.const("Query"), "search", v.map(|s| s.draft), [], st.set_value(|s, t| { ..s, draft: t })),
Html.submit_button("Search", []),
],
),
Html.checkbox(Engine.const("Auto-refresh"), v.map(|s| s.live), [], st.set_value(|s, p| { ..s, live: p })),
Engine.when(
v.map(|s| s.live),
|| Engine.watch(Engine.const({}), |_| [Engine.interval(30000)], st.on_result(|s, _, _| { ..s, round: s.round + 1 })),
|| Engine.text(""),
),
Engine.watch_changes(v.map(|s| { query: s.query, round: s.round }), Search.requests, st.on_result(Search.answered)),
Html.p_s(v.map(|s| Search.shown(s.status)), [Engine.test_id("results")]),
],
)
}
Its effect site issues one request per search or refresh and keeps the typed result:
## One GET per search or refresh; nothing before the first search.
requests : { query : Str, round : U64 } -> List(Engine.Ask(Str, Engine.HttpError))
requests = |{ query, .. }|
if query == "" {
[]
} else {
[Engine.http_body({ url: search_url.append_query_param("q", query).request_target(), timeout: Ms(5000) })]
}
## Keep the body of a successful response, or the typed failure.
answered : S, { query : Str, round : U64 }, Try(Str, Engine.HttpError) -> S
answered = |s, _, res|
match res {
Ok(body) => { ..s, status: Found(body) }
Err(err) => { ..s, status: Failed(err) }
}
Its one entry point, main.roc, binds that program as main; built for
wasm32 it is the browser module, and built for your system’s native target
(x64musl, arm64mac, x64mac or x64win) it is the native spec runner:
app [main] { pf: platform "<package release URL here>" }
import pf.Engine
import Search
## `roc build --target=wasm32` gives the browser module and
## `roc build --target=x64musl` its native spec runner.
main : Engine.Program
main = Search.program
## Check that the default first page mounts while this app compiles.
mounted : U64
mounted = Engine.mounts(main)
Anatomy of a spec
(test "a search shows its results, and a failed one says why"
(steps
(expect-pending-effects 0)
(fill (label "Query") "roc")
(real-click (role button :name "Search"))
(expect-text (test-id "results") "Searching…")
(expect-pending-effects 1)
(stub-http "roc results" :url "/api/search?q=roc" :status 200 :body "3 results")
(run-effect 1)
(expect-text (test-id "results") "3 results")
; Searching again for the same query issues a second request.
(submit (role form :name "Search"))
(stub-http-reject "offline" :kind network :detail "offline")
(run-effect 2)
(expect-text (test-id "results") "Search failed: Network(\"offline\")")))
A spec file holds exactly one (test "name" ...) form:
(setup ...)is optional and comes first. It holds declarative state applied before the app mounts: initial location, storage, connectivity and visibility.(steps ...)is required and holds at least one step, run in order from a fresh mount.;starts a comment that runs to the end of the line. Strings accept the escapes\n,\r,\t,\"and\\.
Any malformed form, unknown step, unknown setup form, wrong argument count or argument of the wrong kind is a parse error naming its file, line and column. Setup forms are not steps and steps are not setup forms.
Locators
Steps find elements by what a user or assistive technology sees, never by CSS selector or DOM position. The first match in document order wins.
| Locator | Matches |
|---|---|
(role button :name "Save") | An element whose explicit role, or implicit role, is button and whose accessible name is Save |
(label "Email") | An element whose aria-label is Email |
(text "Loading") | The element holding a text node whose content is exactly Loading |
(test-id "status") | An element whose data-testid is status |
The implicit roles are button, link (a), region (section),
form, dialog and heading (h1–h6), of HTML elements with exactly
that local name; an SVG a is a link too. The accessible name is the
aria-label, or else the element’s text content. Inputs have no implicit
role here, so find controls by label: the Html controls put their name
in aria-label (see Reference). Give text you assert
on a test-id with Engine.test_id.
Step reference
This is every form the parser accepts, and both runners implement every
one: Chrome is the reference for what a step does, and the native runner
models it. LOC is a locator, "…" a string, N a non-negative integer,
BOOL is true or false.
Setup forms
The parser resolves one environment before either runner mounts the app. Without setup forms its values are:
| Value | Default |
|---|---|
| Location | / |
| Local storage | Available, with no seeded pairs |
| Session storage | Available, with no seeded pairs; retained across same-tab navigation |
| Clipboard | Empty text and HTML, no writes; writes allowed |
| Connectivity | Online |
| Visibility | Visible |
| Declared media query | False unless setup gives its match |
| Clock | 0 ms (1970-01-01T00:00:00Z) |
| Seed | 0, plus the zero-based document number |
| Languages | ("en-US") |
| Time zone | UTC, zero offset over all I64 time |
Both runners use these values, including when Chrome’s real browser facts
differ. A value that later steps can change uses initial-… in setup and
set-… in steps; a value fixed for the document uses its name directly.
Storage predates that naming rule: local-storage seeds it and the app’s
own writes change it. Files are fixtures and max-output-bytes is a
deployment limit.
| Form | Effect |
|---|---|
(initial-location "/path?q#h") | The URL the app boots at; must start with / and name a path the location model reports as Chrome does (see Location). Without it, / |
(initial-online online) | Boot connectivity, online or offline |
(initial-visibility hidden) | Boot page visibility, visible or hidden |
(initial-media "QUERY" BOOL) | A declared media query’s boot match |
(initial-time TIME) | Clock at mount: I64 milliseconds or strict UTC text |
(seed N) | U128 seed; document k from 0 uses N + k |
(languages "TAG" ...) | One to sixteen language strings, at most 64 UTF-8 bytes each |
(time-zone "NAME" MINUTES (FROM_MS MINUTES) ...) | Initial I32 offset and ascending changes at I64 integer milliseconds, true for all I64 time; at most 128 offsets, name at most 64 UTF-8 bytes |
(local-storage "key" "value") | Seed local storage before mount |
(local-storage-unavailable) | Every local-storage access throws, as with site data disabled. Seeding storage in the same setup is a spec error |
(session-storage "key" "value") | Seed session storage before mount |
(session-storage-unavailable) | Session storage is unavailable; seeding it is a spec error |
(local-storage-full), (session-storage-full) | Writes to that store fail with Quota; reads and removals work. Seeded values are allowed |
(clipboard-denied) | Clipboard writes answer ClipboardFailed(NotAllowed) |
(max-paste-bytes N) | The deployment’s paste-text byte limit, 4 MiB by default; 0 through 9007199254740991 |
(file "name" "type" "text" [REPEAT]) | Declare a file the steps can give the app: its name, its MIME type, and its contents, text repeated REPEAT times (once without it). The name is not empty, has no / or NUL byte, is not . or .., and is at most 255 bytes of UTF-8, since Chrome’s runner writes it to disk under that name; the type is lowercase printable ASCII, which a browser’s File keeps as written |
(max-crypto-bytes N) | Cryptographic byte ceiling, the runtime’s maxCryptoBytes: 0–67,108,864 bytes (8 MiB without it) |
(max-crypto-iterations N) | PBKDF2 iteration ceiling, the runtime’s maxCryptoIterations: 1–10,000,000 (1,000,000 without it) |
(max-output-bytes N) | The most bytes a task’s job may append to its builders, the runtime’s maxOutputBytes mount option (256 MiB without it) |
Effects never run on their own in a spec: HTTP requests, timers and worker
jobs wait for run-effect, and intervals for tick-interval. A worker
job’s timeout never expires on its own either: time-out-work expires it.
Storage reads and clipboard writes answer by themselves in the following
turn. A storage write failure is also delivered then, to each live
StorageWriteFailures subscription. None takes a run-effect occurrence
number.
Actions
| Step | What happens |
|---|---|
(click LOC) | A real mouse click: pointermove, mousemove, pointerdown, mousedown, focus moves to the nearest focusable element (or away), pointerup, mouseup, click, then the default action unless the click handler prevented it — a checkbox toggles and a radio checks (each with input and change), a submit button submits its form if the form’s controls are valid, a link navigates. A prevented pointerdown suppresses mousedown, mouseup and the focus change; click still fires. A disabled control gets no click |
(real-click LOC) | The same click, but a disabled control fails the step |
(fill LOC "text") | Playwright’s fill: focus an enabled text input or textarea and deliver the whole value as one input event. The control must be a textarea or an <input> of type text, password, email, search, tel, url or number, and not disabled (by itself or by a field set). A value the control cannot hold fails the step in both runners: anything but a floating-point number or "" in an <input type=number>, any text in a read-only control, text longer than maxlength, a line break in a single-line control, CR in a textarea, white space around an email address (or around one of a multiple control’s addresses) |
(change LOC "value") | Set the value and fire change; on a radio or checkbox the value must equal the control’s value, and it becomes checked. A value the control’s value setter would rewrite fails the step: a line break in a text, search, tel or password control, a line break or surrounding white space in an email or URL control, a malformed number, date, month or time, a color other than lowercase #rrggbb, CR in a textarea, and any value but "" in a file input. Natively, so does a range value that is not a canonical integer within the control’s integer min and max on its integer step, and any week or local date and time value, whose rewriting is not modelled |
(select-option LOC "value") | Choose an option of a <select>, firing input and change; the option must exist |
(check LOC) / (uncheck LOC) | Click a checkbox or radio that is not in that state; it must then be in it. A radio cannot be unchecked |
(submit LOC) | Submit a <form> as requestSubmit does: nothing is submitted while a control is invalid. The native runner judges required, email addresses and integer numbers within min and max, and knows that a range control’s min, max and step, pattern and minlength on an empty control, pattern on a textarea and step="any" never block a submission. Natively the step fails for a form whose enabled controls carry any other constraint: pattern or minlength on a control holding a value; step other than any on an input that is not a range; min or max on an input that is neither a number nor a range; a number control whose value, min or value attribute is not an integer; a URL control, or a multiple email control, holding a value; a required radio button; or a time, week or local date and time control holding a value. A submit through a click or Enter is judged the same way |
(press LOC "Shift+ArrowDown") / (press "Escape") | Focus the locator if supplied, then keydown and keyup; otherwise use current focus or body. See Keyboard steps |
(dismiss) | Press and release Escape at current focus, with normal key prevention and native dismissal |
(scroll LOC TOP LEFT) | Scroll to these nonnegative CSS-pixel offsets and report them; Chrome must reach and retain them |
(report-size LOC WIDTH HEIGHT) | Inject a content-box size report into an element with a size observation |
(report-seen LOC yes|no [PERMILLE]) | Inject visibility into an element with a seen observation; ratio defaults to 1000 for yes, 0 for no |
(set-media "QUERY" BOOL) | Report a declared media query’s new match |
(focus LOC) / (blur LOC) | Move focus, delivering blur and focus to handlers that listen. Focusing an element that cannot take focus does nothing |
Input and button actions use the HTML control’s effective type. An input with
missing, empty or invalid type behaves as a text input; a button with the same
kinds of type behaves as a submit button. Keyword matching ignores ASCII case
but does not trim spaces or fold non-ASCII letters. For example, type="txet"
can be filled and blocks implicit form submission just like type="text".
Checking it or choosing files still fails the step. These defaults apply to HTML
controls, not foreign elements with the same local name.
Likewise HTML’s hidden, popover and contenteditable mean nothing on an
SVG or MathML element: Chrome draws an SVG <g hidden>, and a link inside it
takes focus, in both runners. A link is an HTML a with href, or an SVG a
with href or xlink:href.
The type attribute remains raw: expect-attr sees the exact authored spelling,
including empty text, and expect-no-attr sees its absence. This does not change
the live property readings of value, checked or disabled described under
Assertions.
For a typed Html.select, ordinary select-option chooses by the stable
choice key and delivers its current application value. A scripted change
with a foreign or removed key exercises NotOffered; the spec then checks
the decision’s explicit behavior. Checkbox helpers receive Bool, including
when check or uncheck performs their native change sequence.
Focus follows Chrome in both runners: a text control the user changed gets
change when it loses focus, and a controlled input’s rewritten value waits
for blur while it has focus. The engine’s Focus, Blur and SelectText
and FocusInPlace commands also update focus and raise the same events after the batch, each
as its own turn. A focus loop stops the instance with resource_limit
after 4096 turns in one step. A handler with no listener for its event is not
an error: the event simply reaches nothing, as in a browser.
Hover is not driven by specs. Neither runner delivers pointerover,
pointerout, pointerenter, pointerleave or their mouse counterparts;
the browser replay filters them before the app sees them. Hover depends on
layout, including changes under a resting cursor, which the native oracle
cannot model. Contract tests cover dispatch of those events, and a hover
handler’s pure logic can be tested as a function. The move events in the
click sequence above are delivered in both runners.
contextmenu, gotpointercapture and lostpointercapture are also outside
the spec grammar. Context-menu timing differs by operating system; capture
lifecycle callbacks are outside the four pointer events modeled below.
The browser replay filters them, while production dispatch and its
contract tests retain them.
Pointer gestures
| Step | Meaning |
|---|---|
(pointer-down LOC ...) | Press; options :at X Y, :button main|middle|secondary, :pointer mouse|pen|touch, :id N, :modifiers (shift ctrl alt meta) |
(pointer-move LOC ...) | Move; options :at X Y and :id N |
(pointer-up LOC ...) | Release; options :at X Y and :id N |
(pointer-cancel ...) | Cancel one touch; option :id N |
Down defaults to main, mouse and no modifiers. Its id defaults to 1 for mouse or 2 for pen and touch. Move and up default to id 1; a nonmouse gesture names its id explicitly on them. Cancel defaults to id 2. Mouse always uses id 1, which nonmouse pointers cannot use. A second down for an active id, an up for one not down or a cancel for a nontouch pointer fails. A buttonless mouse move is allowed. Apps compare active pointer ids; specs do not assert the browser’s numeric choices.
Only one non-touch press (mouse or pen) can be active: Chrome’s automation channel shares their compatibility-mouse target. A second non-touch gesture fails before input in both runners. Touch and non-touch gestures cannot overlap either: the driver supports one mouse/pen gesture or a set of up to 16 touch pointers. A 17th touch fails before input. Local ids can use the full U32 range: replay maps them to reusable driver contact slots and separately tracks the browser-assigned pointer ids. Production pointer dispatch has none of these automation limits.
X Y are whole percentages, 0–100, in the nearest zone at or above LOC.
Without :at, LOC must itself be a zone (its centre is 50 50) or lie in
no zone (Outside). If it lies inside another element’s zone, give
:at explicitly. Chrome verifies that the point hits LOC or a descendant
and the same nearest zone, and checks the reported fractions exactly.
A nested zone covering the point or a box without positive area fails
the step. A click reaching a pointer-kind handler follows the same
centre rule; use pointer steps when it needs :at.
A paced move is a report: outside a hold it is one frame, and inside a hold only its newest waiting value per pointer reaches the app. An up delivers the waiting moves first. Capture changes the event target, while its reported zone remains the one beneath the point.
Mouse and pen also deliver their mouse and focus events: a main release
clicks, while a nonmain release delivers auxclick. A single-contact touch tap delivers
compatibility mouse events after its up; preventing its down suppresses
those mouse events while click still occurs. A moved touch produces none,
as do releases from a set that has contained multiple contacts, until the
last contact ends. Chrome checks touch-action:none before a touch
press, and a touch move must change its
logical point; Chrome also rejects a physical move inside its tap slop.
If an up’s turn moves or removes the pressed element or an ancestor,
mouseup goes to that node’s old parent and no click follows.
The browser input API cancels all touches together. To keep a cancel specific to its named pointer, both runners reject it when more than one touch is active. A gesture also cannot cross into a new document: release or cancel before navigating there. Same-document navigation is allowed. These are step errors, with no fabricated release or cancellation.
Assertions
| Step | Passes when |
|---|---|
(expect-text LOC "text") | The element’s text content is exactly text |
(expect-value LOC "value") | The control’s value is value; the element must be an input, textarea, select, option or button |
(expect-checked LOC BOOL) | The control’s checked state is BOOL; the element must be an input |
(expect-disabled LOC BOOL) | The control’s own disabled state is BOOL; the element must be a button, input, select, textarea, option, optgroup or fieldset |
(expect-attr LOC name "value") | The attribute name is present with that value. On property-table elements, value reads the live value and checked reads "true"/"false"; elsewhere they read ordinary attributes. disabled reads "true"/"false" |
(expect-has-attr LOC name) | The attribute reading is present, including an empty string, with any value |
(expect-no-attr LOC name) | The attribute name is absent; another step of this spec must show the same name present, on any locator |
(expect-no-attr LOC name :never-written) | The attribute is absent in a story that never shows that name present; another spec in this app’s suite must show it |
(expect-visible LOC) | The locator matches an element in the document |
(expect-absent LOC) | The locator matches nothing now. Another step of this spec must require the same locator to match, before or after this step |
(expect-absent LOC :never-drawn) | The locator matches nothing in a story that never draws it. No step of this spec may require that locator to match; another spec in this app’s suite must require it |
(expect-focused LOC) | The located element is the document’s active element |
(expect-no-focus) | No page element holds focus; the active element is the document body |
A state assertion on an element that has no such state fails in both runners rather than reading a default: a paragraph is not unchecked, enabled or hidden, it has no checked, disabled or shown state at all. These are HTML elements of exactly that local name.
An absence alone cannot catch a misspelt locator or one the app renamed. Show
where the story draws it with a step such as expect-visible, expect-text
or click, using exactly the same locator. The anchor may occur later when
the absence checks something not drawn yet. An anchor proves that spelling
matches at that step; it does not prove the two steps identify the same element.
Use :never-drawn for a branch the story never draws. The parser rejects that
marker if the story already has an anchor, naming its line. The suite also
checks that some other spec requires exactly that locator. A misspelt marker
cannot establish its own evidence; remove an absence assertion for a name
that no story ever shows.
Previously passing specs with an unanchored expect-absent fail to parse at
that step in both runners and --emit-steps. Add an assertion where the
existing story draws the element, or mark a branch the story never draws
with :never-drawn.
The suite check reads all the app’s spec files even when a filter selects one story to execute. Stories keep independent setup and can run in any order: positive evidence checks spelling, without making one story depend on another story’s execution.
The parser checks names using the strongest available evidence: program
declarations first, another step in this spec next, then an explicit marker
for a story that never shows the subject. Attribute names are anchored by
expect-attr or expect-has-attr, before or after the absence and on any
locator. Symbols and strings of the same text are one name. A misspelling
fails at the negative step; a redundant marker also fails and names the
anchor’s line. No anchor from another spec counts.
All three attribute assertions use the same reading. Present-empty values
count as present. disabled, and checked or value on applicable controls,
are always-present live readings: expect-has-attr adds no useful check there.
Use expect-disabled, expect-checked and expect-value instead. The parser
rejects those names in expect-no-attr. Ordinary raw attributes retain their
literal empty, false or named text. The name is compared exactly, in no
namespace: (expect-no-attr LOC "TITLE") holds on an element with a title,
and xlink:href names an attribute the app wrote with that local name, not
the XLink-namespaced href.
When upgrading existing specs, add an assertion where the existing story
already shows the name; no extra event turn is required. Use the family
marker only when that story never shows it. Unanchored expect-no-attr, zero
cleanup/interval counts and conditional ticks now fail during parse, including
--emit-steps, until anchored or explicitly marked.
expect-updates counts property commands whose row mirrors an attribute,
including control values and checked state. Both runners count the same
work: the native oracle reads the property commands, and Chrome observes
their mirrored attributes. patches_emitted includes PROP and HPROP.
Dialogs, popovers and scrolling
| Step | Passes when |
|---|---|
(expect-shown LOC hidden|open|modal|popover) | The live dialog or popover has exactly that shown state; any other element fails the step |
(expect-scroll K LOC into-view|to) | The K-th performed explicit scroll command targeted this element and had this kind; K starts at 1 |
(expect-scrolls N) | Exactly N explicit scroll commands were performed in this document |
expect-visible tests presence in the document, so a closed dialog or
hidden popover can still match it. Use expect-shown for shown state.
Actions on hidden dialog/popover content, outside the top modal, or on an
element the browser does not draw (an HTML element inside SVG outside
foreignObject or inside MathML outside a token element such as mi) fail;
assertions can inspect the inert background. No pixel layout or smooth
scroll completion is asserted. A scroll command targeting a missing
reference is stale and adds no performed scroll.
The manual scroll history keeps the newest 4096 commands, with absolute U64 ordinals and element identity rather than reusable engine ids. An assertion for an overwritten command fails explicitly. The history and count reset with a new document, unmount or recovery. At ordinal exhaustion, observation fails without stopping the app or suppressing its scroll. The browser history uses weak element references so it cannot retain removed subtrees.
Both runners settle native close and toggle callbacks after mount and after each step. Browser replay passively tracks pending callbacks and waits up to 20 seconds; it does not assume a timer tick is enough. A nonsettling app fails the step. Close and toggle use different browser task sources, whose relative order is unspecified; assert the settled outcome and test decisions in both orders. In particular, accept automatic popover hiding rather than making unrelated auto popovers reopen each other indefinitely.
The parser emits one activation table for both runners. An actual click,
including a check/uncheck that clicks, grants user activation; a disabled
click or already-satisfied check does not. Nonempty fill grants it,
while empty fill does not. Every supported press except Escape grants
it. Mouse/pen pointer down and touch pointer up grant it; move, cancel,
mouse/pen up, scripted changes, selects, submits and focus do not. A new
document resets the CloseWatcher cancellation allowance; preventing one
cancel can consume that allowance until the next interaction. Sticky
activation for a leave warning is separate and survives the supported
same-origin document navigation and reload. Existing same-document history
traversal preserves it; cross-document history traversal is still unsupported.
View transitions
| Step | Checks |
|---|---|
(expect-transitions N) | Exactly N marked batches have been applied in this document |
(expect-transition K TYPE ...) | The one-based K-th marked batch has exactly these types, in this order; an empty type list is allowed |
These assert the engine’s request to animate, whether or not the browser
supports transitions or the deployment enables them. Mount never adds a
transition. view_transitions checks the same intent as a work counter.
Native and browser observations retain the newest 4096 records and at most 1 MiB of encoded type bytes (four length bytes plus UTF-8 bytes for each type). Counts and ordinals are absolute U64 values; their JSON representation is a decimal string. An overwritten ordinal fails with a retained-history diagnostic. A record larger than that byte allowance clears older history and is itself unavailable, while the total count still advances. Exhausting U64 fails observation. None of these limits stops the app or caps the types it may actually ask the browser to animate.
Chrome replay skips the animation once its update has run and awaits the
runtime’s idle() until finished settles before the next step. Thus a
replayed click meets the final DOM without an overlay. Real animation,
capture boundaries and input during animation are runtime contract tests;
application specs assert the final DOM and transition intent.
Layout and media
(initial-media "QUERY" BOOL) in setup supplies a query’s boot match. A
query the program declares but setup omits starts false. Both runners use
these same facts; the page’s CSS keeps following the real browser.
(expect-media-subscriptions "QUERY" N) checks the live subscriptions;
(expect-observed N) checks live size/seen registrations. An element with
both observations contributes two. Disposing a row or scope must release
them before its nodes disappear; the native oracle checks that invariant.
Typed scroll, size, seen and media are reports, honor hold-reports and
grant no user activation. An ordinary text-kind scroll remains an
occurrence and drains earlier reports even inside a hold. A repeated scroll to the same position raises
nothing. Size and seen are injected in Chrome too, since the native oracle
has no geometry. Real observer behavior belongs in browser contracts.
A scroll step checks the real Chrome position again after its turn, so it
fails if drawing the window moved the scrollbar. ScrollTo with Start,
Px and Keep on a handled scroller updates the oracle and, if changed,
reports its position at the end of the step. Chrome waits a frame and
checks the same position, including raw signed offsets; negative physical
movement cannot pass by rounding or clamping its payload to zero. Prefer
Instant: Smooth, or Auto with CSS
smooth scrolling, can still be intermediate at that check. A handled
scroller means one carrying a typed or text-kind scroll handler.
ScrollTo with End on a handled scroller, or ScrollIntoView inside one,
fails in both runners because its destination depends on layout. Chrome
also fails a step that moved a handled scroller without a scroll step or
modelled command, including a click, focus or drawing that shifted it. The
failure names the element and says to scroll first. The native run alone
cannot detect that mistake; running both proves reachability and stable
scroll geometry.
Keyboard steps
press raises keydown and keyup. If keydown loads a new document, the
driver waits for its app to mount before releasing the key there; it
checks physical evidence for both phases.
press uses exact Control, Alt, Shift and Meta prefixes. Its one
US-key table is declared in Scm.roc and emitted for the browser runner:
printable ASCII, Enter, Escape, Tab, Space, Backspace, Delete, arrows,
Home, End, PageUp, PageDown and F1–F12. There is no ControlOrMeta.
Write Shift+? and Shift+A; omitting required Shift is a parse error,
as is Shift+a (use Shift+A). A named key may also carry Shift.
Tab moves focus by positive tabindex then document order, skipping disabled, hidden and inert elements. Enter activates a button or link or implicitly submits a form. Enter on a file or color input clicks the control instead; the chooser UI is outside the DOM model, as for a mouse click. Ctrl/Meta suppresses button, file/color and implicit-form activation; Alt/Shift retains it. Space activates buttons, checkboxes and radios on keyup, with any modifiers, if the original control still holds focus and its pressed ancestry has not been detached. Prevention suppresses the default. Escape performs native dialog and auto popover dismissal; function keys and caret-only movement have no modelled change.
Unprevented modified Enter on a link is refused for any Control, Alt, Shift or Meta modifier: its navigation, download or new-context default varies by platform. A keymap that prevents it permits the step. Plain Enter on a link remains supported, and this driver restriction does not limit production keyboard handling.
Use fill for text entry. A press refuses an unprevented default the native
model cannot reproduce: printable keys and Space without Ctrl/Meta,
Backspace/Delete and Ctrl/Meta+A/C/V/X/Y/Z in text entry, Enter in textarea
or contenteditable, and arrows/Home/End/PageUp/PageDown in selects, radios
and number, range, date, time, month, week or datetime-local inputs. The
refusal rules and their input-type selectors are emitted from Scm.roc;
Chrome checks the actual event’s defaultPrevented. A keymap that prevents
the default permits the step. Composition remains a browser contract test.
The sample checks Escape without losing focus and both ends of a Tab loop:
(test "Escape restores a focused draft and declared Tab chords trap focus"
(steps
(fill (label "Draft") "Changed")
(press "Escape")
(expect-value (label "Draft") "Original")
(expect-focused (label "Draft"))
(press (role button :name "Last") "Tab")
(expect-focused (role button :name "First"))
(press "Shift+Tab")
(expect-focused (role button :name "Last"))
(press "Control+k")
(expect-focused (role button :name "First"))))
Location, history, title and storage
| Step | Meaning |
|---|---|
(navigate "/path") | The user goes to a URL. One that differs from the current URL only in its #fragment stays in the document: a new history entry, and every live Popstate subscription hears it. Any other URL loads a new document, where the app mounts afresh with the same local storage |
(history-back) / (history-forward) | The browser’s back and forward buttons within the document; fails with no entry to move to, or when the entry belongs to another document |
(expect-current-location "/path") | Path, query and hash equal this |
(expect-document-title "Title") | The document title |
(expect-local-storage "key" "value") | Local storage holds value at key |
(expect-no-local-storage "key") | Local storage has no key |
App Push and Replace requests move the location without a popstate, as
browsers do.
A location the app reads at boot or after back and forward is the text Chrome
serializes, with spaces, quotes and non-ASCII bytes percent-encoded. An app
that puts its own text into a location decodes what it reads. URL input first
trims C0 controls and spaces at the edges and removes TAB, LF and CR throughout.
expect-current-location compares the reported pathname, search and hash;
empty query and fragment delimiters are omitted. The native runner retains
those delimiters in its existing URL/history strings and reports the location
at boot, popstate and location assertions. This preserves the distinction
between no query and an empty query for document identity. An explicit empty
fragment still identifies a same-document navigation. An exactly empty argument
to an app’s Push or Replace keeps its current URL, including its fragment;
a nonempty whitespace-only reference resolves against the current URL and drops
its fragment. A path also encodes ^ and |, as Chrome does. A link or push
to a URL with a scheme (mailto:a@b, tel:, https:) or another host (//h)
leaves the app, and the step fails in both runners. Dot segments, backslashes
and hosts remain outside the native runner’s location model: the parser
refuses a location whose path holds a backslash, a . or .. segment or
starts with //, and natively a link or an app’s Push or Replace to such
a path fails the step, saying what the model does not resolve. Write the
location Chrome reports instead.
Effects
| Step | Meaning |
|---|---|
(stub-http "label" :url "/api/x" :status 200 :body "…") | Stage an HTTP answer; optional :headers (("name" "value") …), default content-type: application/json. :status is 100–999. Staging a second answer before one is used fails |
(stub-http-reject "label" :kind network :detail "offline") | Stage a failure: network with the browser’s message, or timeout with an empty :detail |
(run-effect N) | Answer the N-th HTTP request, upload, fetch, timer, worker job, cryptographic operation or operation on a file the current document issued (1-based, in issue order; port calls share the numbering but are answered with answer-port (see Ports); subscriptions, commands and storage reads not counted). It must still be pending. A timer fires; a worker job runs its task (in Chrome in a real worker, natively in a child process that serves the job’s effects from the setup files, the step waiting for its result: a task that crashes loses its job with the crash’s fault class, and one that has not finished after 30 s fails the step); an HTTP request or an upload takes the staged answer, and an HTTP response’s :url must equal the request’s; a page read, a digest or a file URL is performed on the setup file (see Files); cryptography performs real PBKDF2, AES-GCM or SHA-2, with the same deterministic test entropy in both runners |
(run-opportunity) | Deliver exactly one currently armed placeholder opportunity through the ordinary turn. Fails when none is armed; grants no user activation. Earlier held reports drain first; the hold itself remains in force |
(expect-request N :method "GET" :url "/api/status" :cache no-store :credentials include) | Assert selected fields of currently pending HTTP, upload or fetch occurrence N; every keyword is optional. Cache values are default, no-store, reload, no-cache, force-cache; credentials are same-origin, include |
(progress-effect N sending 1024 4096) | Report progress for pending occurrence N without answering it; direction is sending or receiving, counts are exact U64, and the total may be unknown. Fails when N did not ask for progress; honours hold-reports |
(expect-pending-effects N) | Exactly N HTTP requests, uploads, fetches, timers, worker jobs, operations on files, cryptographic operations and port calls are waiting to be answered |
(expect-pending-work "task" N) | Exactly N worker jobs of the task of that name are waiting |
(lose-work N FAULT) | Answer the N-th effect occurrence, a pending worker job, as WorkLost(FAULT) without running it. FAULT is contract, resource_limit, out_of_memory, app_crash, expect_failed, unavailable or executor |
(time-out-work N) | Expire the timeout of the N-th effect occurrence, a pending worker job: it receives Timeout without running. A job without a timeout fails the step |
(tick-interval MS) | Deliver one tick to every live Interval(MS); fails when none is live |
(tick-interval-if-active MS) | The same, but a no-op when none is live |
(expect-interval MS N) | Exactly N Interval(MS) subscriptions are live |
(set-online offline) | Change connectivity and notify OnlineChanges subscribers |
(set-visibility hidden) | Change page visibility and notify VisibilityChanges subscribers |
(expect-cleanup "name" N) | The on_cleanup site named name has run N times |
An interval step’s MS is a period an interval can have: 1 to 2147483647,
the longest a browser timer holds, past which the engine refuses an
interval. The parser refuses any other at its position, so a step never
names a period no interval can have, or one that would wrap onto another.
expect-request and progress-effect number the current pending list,
in issue order, including timers, calls and jobs. Completed and cancelled
entries no longer count. This differs from run-effect, which addresses the
document’s original issue occurrence.
Reports
A step normally acts as its own frame: any state reports it raises are
delivered before the next step. set-online, set-visibility and
emit-port on a Latest subscription and progress-effect raise reports. To check several
reports meeting before a frame, hold and release them explicitly:
| Step | Meaning |
|---|---|
(hold-reports) | Keep reports waiting until a release or an occurrence |
(release-reports) | Deliver all waiting reports in order and end the hold |
(expect-reports-replaced N) | Exactly N waiting reports have been replaced in this document |
Newer reports from one source replace its waiting value in place. An occurrence inside a hold, such as a click or an effect result, first delivers reports queued ahead of it; the hold continues. Assertions read the current drawn page without releasing reports. Setting an unchanged connectivity or visibility value raises no report.
A hold belongs to one document. Holding twice, releasing without a hold, ending a spec while holding or navigating to a new document while holding fails the step. The replacement count starts at zero in each document. These steps check the same delivery in both runners; browser contract tests check real frames and the fallback timer.
This spec sends three revisions before releasing the reports. Only the newest reaches the app:
(test "Notes — one frame of revisions lists only the newest"
(steps
(answer-port 1 reply "[]")
; A frame can contain several revisions of the store.
; The app keeps its earlier view until that frame is delivered.
(hold-reports)
(emit-port "example.org/notes/changed" "\"1\"")
(emit-port "example.org/notes/changed" "\"2\"")
(emit-port "example.org/notes/changed" "\"3\"")
(expect-reports-replaced 2)
(expect-text (test-id "notes") "No notes.")
(release-reports)
(expect-port-call 2 "example.org/notes/list" "{\"prefix\":\"\",\"revision\":\"3\"}")
(answer-port 2 reply "[{\"id\":\"n1\",\"title\":\"Newest\",\"saved_ms\":\"0\"}]")
(expect-text (test-id "notes") "Newest")))
Answering effects
Cryptographic operations use real cryptography with deterministic test entropy.
The crypto executor reserves capacity as the batch is performed. In manual
mode an operation refused by its 32-operation bound still waits for
run-effect to deliver Refused; freeing capacity does not retry it. It
therefore remains in expect-pending-effects until that result is delivered.
Stage one answer immediately before each run-effect that answers an HTTP
request: both runners hold a single staged answer, which that run-effect
consumes. A request that is answered after its owner was disposed is still
delivered to the surviving owner (see Effects and the browser),
and a request the app never issued, or that is already answered, fails the
step.
A worker job is numbered with the HTTP requests and timers, in issue order,
so the order of the steps is the order the jobs finish: (run-effect 2)
then (run-effect 1) says the newer job finishes first. lose-work and
time-out-work let a spec state how the app handles a job that fails
without writing a task that fails (see Workers
for a sample); a task that really crashes on some
input loses its job under run-effect, with the class app_crash, in both
runners. A job cancelled by disposing its site is no longer pending, and the
effects_cancelled metric below counts it.
In Chrome, set-online and set-visibility update the runtime’s
environment readers and dispatch the browser’s own events, so the
runtime’s real listeners run. Setting an unchanged value dispatches nothing
and causes no turn. The current environment carries into a later document:
setting offline and then following a link boots the next document offline.
Storage is seeded once per spec, so app writes and removals also survive
navigation. Nondeterministic browser facts must come from a spec or its
stated defaults in both runners.
This spec checks the auto-refresh interval: it mounts with the checkbox, ticks, answers the refetch, and is gone when unchecked.
(test "auto-refresh refetches on its interval and stops when unchecked"
(steps
(fill (label "Query") "roc")
(submit (role form :name "Search"))
(stub-http "first" :url "/api/search?q=roc" :status 200 :body "3 results")
(run-effect 1)
(expect-interval 30000 0)
(check (label "Auto-refresh"))
(expect-interval 30000 1)
(tick-interval 30000)
(expect-pending-effects 1)
(stub-http "second" :url "/api/search?q=roc" :status 200 :body "4 results")
(run-effect 2)
(expect-text (test-id "results") "4 results")
(uncheck (label "Auto-refresh"))
(expect-interval 30000 0)))
Drafts, other tabs and the clipboard
| Step | Meaning |
|---|---|
(expect-session-storage "key" "value") | The session store holds exactly that text |
(expect-no-session-storage "key") | The session store has no value for the key |
(storage-elsewhere "key" "value") | Another document changes a local key; report its new value |
(storage-elsewhere-removed "key") | Another document removes a local key |
(storage-elsewhere-cleared) | Another document clears local storage; report Missing to all subscriptions when anything was stored |
(paste-text LOC "text") | Dispatch a plain-text paste at the located element |
(expect-clipboard "text") | Last successful plain-text write observed in this document |
(expect-clipboard-html "html") | HTML of that write, empty for a plain-text write |
(expect-clipboard-writes N) | Successful writes observed in this document |
(leave-page "/url" stay) | The browser must ask before leaving; decline and retain the current document |
(leave-page "/url" leave) | The browser must ask; accept and mount afresh at the URL |
(leave-page "/url" unasked) | The browser must not ask; mount afresh at the URL |
Clipboard assertions observe writes, like the saved-file assertions; they never read the OS clipboard. A new document resets that observation to empty text, empty HTML and zero writes. A denied copy leaves it unchanged. U64 write-count exhaustion fails observation without stopping the app’s copy.
Storage changes honour hold-reports: several writes to one subscription
before release become one report carrying the last event’s value. A write
that changes nothing raises no event, nor does removal of a missing key or
clearing an empty store. Chrome performs these writes in a second page of
the origin, exercising the browser’s real storage event.
local-storage-unavailable makes this app’s window getter throw. Another
document can still write the origin’s store, and storage assertions can
observe that write, but this app acquired no local storage-area identity
with which to classify and report its event. This differs from an injected
store object whose reads throw: the object still has an identity, so its
matching events can be reported. The runtime never guesses that an
unidentified storage event is local rather than session storage.
A guard asks only after sticky activation: a prior step actually interacted
with this tab’s same-origin document. That fact survives same-origin
navigation and reload; it starts false in a fresh tab. paste-text, storage-elsewhere and its removal/clear
variants, and leave-page grant none. Any other step that tries to leave a
guarded, activated document fails and names leave-page; a dialog outside
that step also fails. Chrome navigates with location.assign and answers
the real dialog. The native runner checks the same guard and activation.
Time and document facts
TIME is an I64 integer or exactly YYYY-MM-DDTHH:MM:SS[.sss]Z with a valid
UTC date. Other zones and malformed dates are spec errors. Clock steps are:
| Step | What happens |
|---|---|
(set-time TIME) | Set the wall clock, forwards or backwards; deliver nothing |
(advance-time MS) | Add a nonnegative U64 duration; fail on I64 overflow; deliver nothing |
Only those steps move the clock. run-effect on a timer and tick-interval
read its current value for Fired(at_ms) without advancing it. Timers still
fire in issue order, never time order. Write (advance-time 30000) then
(tick-interval 30000) when thirty seconds pass and the interval fires.
The current clock survives a new document, whose seed is the next checked
U128 value. Seed exhaustion is a spec error rather than wrapping. Languages
and the supplied zone stay fixed; a spec zone covers all time, so the
platform and probe contract tests check OutsideZone separately. Emitted
JSON uses decimal strings for I64 times and U128 seeds.
Chrome uses the ordinary environment readers for these values, not a CDP zone override or a global Date patch. JavaScript the page supplies, including port handlers and simulated services, still reads its real time. An example that needs deterministic stamps makes them in Roc, as Reading List does.
Files
| Step | Meaning |
|---|---|
(choose-files LOC "name" …) | The user chooses the named setup files in the file input |
(drop-files LOC "name" …) | The user drops the named setup files on the element |
(paste-files LOC "name" …) | The user pastes the named setup files into the element |
(expect-keys N) | The app holds exactly N cryptographic key handles; a pending request may keep its browser key after its Roc handle is released |
(expect-files N) | The app holds exactly N file handles |
(expect-upload N "name" START LEN) | The N-th effect occurrence is a pending upload whose body is LEN bytes from START of the setup file name |
(expect-saved K "name" "text") | The K-th file (from 1) the app saved in this document (File.save) was saved under name and held exactly text |
(expect-saves N) | The app saved exactly N files in this document |
A spec writes out the contents of the files it uses, so both runners give
the app the same bytes; a step that names a file no file form declares
fails.
expect-files counts handles, so it shows when the app lets a file go:
after the state that held it is written without it, or its scope is
disposed. A file step gives the app exactly the declared name, type and
contents, in both runners and on every system. A browser’s own chooser
takes a file’s type from the operating system’s table of name extensions,
which differs between systems, so in Chrome choose-files chooses the
files from disk where the app cannot see them and gives the app files
made from them with the declared types, still read from disk, with the
input and change events of a choice. See
Files for a sample.
Operations on a file wait for run-effect like any awaited request, and
are then performed on the setup file’s bytes: a page read answers them (or
TooLarge over the default 8 MiB), a digest is computed for real (natively
by the runner’s host, in Chrome by WebCrypto), so a spec asserts the same
digest in both runners, and a file URL is answered with a URL of the
runner’s own making, so a spec asserts what the app does with it rather
than its text. An upload is an HTTP request: expect-upload checks which
file and range it sends, and run-effect answers it with the staged HTTP response.
Every worker job runs the same way, whatever its task’s
body does: run-effect runs it, in Chrome in a real worker and natively in
a child process whose effects read the setup files’ bytes, and a
preparation’s task is prepared afresh for each job natively, which is what
any reuse in the browser must equal. The files its answer holds are then
handles the app holds, with the bytes the job built, in both runners, so a
later read, digest or save of them gives the same bytes. A File.fetch
takes the staged stub-http answer, its body becoming the file. Neither
runner downloads anything: a save is logged, and expect-saved reads its
name and contents.
Ports
Neither runner calls the page’s port handlers: a spec answers a port call as it answers an HTTP request, and plays the JavaScript’s side of a subscription. A call is numbered with the other awaited requests.
| Step | Meaning |
|---|---|
(expect-port-call N "port" "json") | The N-th effect occurrence is a pending call on port whose message is exactly json |
(answer-port N reply "json") | Answer that call with json, as written (so a spec can answer what the app’s type does not accept) |
(answer-port N reply "json" :bytes ("BASE64" ...)) | Answer with JSON and explicit byte blocks, indexed by numeric $bytes markers in that JSON |
(answer-port N throw "message"), (answer-port N too-large), (answer-port N timeout) | Answer it Threw, TooLarge or, for a call with a timeout, Timeout |
(emit-port "port" "json") | Deliver a message to every live subscription on port; fails when none is live |
(emit-port "port" "json" :bytes ("BASE64" ...)) | Deliver JSON and explicit byte blocks to every live subscription on port |
(close-port "port"), (fail-port "port" "message") | End every live subscription on port with Closed or Threw |
(expect-port-subscriptions "port" N) | Exactly N subscriptions on port are live |
(expect-port-subscription-arg "port" k "json") | The one-based k-th currently active subscription on port has exactly this argument; no subscription history is retained |
(expect-port-sent "port" K "json") | The K-th command (from 1) sent on port carried exactly json |
(expect-port-sends "port" N) | Exactly N commands were sent on port |
The optional :bytes list holds standard canonical padded base64 strings.
The parser decodes them once, and both runners deliver the resulting blocks
beside the JSON, in list order. An empty string supplies an empty block;
{"$bytes":0} refers to the first block. JSON is delivered exactly as written,
so malformed JSON or an invalid index can still test the app’s decoding
failure. Unknown or repeated fields, invalid base64 and attachments on a
throw, too-large or timeout answer are spec errors.
run-effect on a port call fails and names answer-port. Commands are
not awaited, so expect-pending-effects does not count them. See
Ports for a sample.
Work assertions
Work assertions read the engine’s own counters, which it returns with every
call. (mark-metrics) snapshots them; each following
(expect-metric-delta METRIC N) asserts the exact change since the mark,
and (expect-metric-delta-at-most METRIC N) an upper bound. A delta without
an earlier mark fails.
(test "a result rewrites one text node and nothing else"
(steps
(fill (label "Query") "roc")
(submit (role form :name "Search"))
(stub-http "results" :url "/api/search?q=roc" :status 200 :body "3 results")
(mark-metrics)
(run-effect 1)
(expect-metric-delta set_text 1)
(expect-metric-delta create_element 0)
(expect-metric-delta scopes_created 0)
(expect-metric-delta-at-most derived_calls_into_roc 5)
(expect-updates (test-id "results") 3)))
Assert structural work exactly — elements, rows, scopes, text writes —
because it is the app’s observable cost. Bound incidental work, such as how
many app closures were evaluated, with -at-most, so an engine improvement
does not fail your spec.
| Metric | Counts |
|---|---|
rows_created | Rows created by mount, by an each reconciliation or by a table view’s window |
rows_removed | Rows a reconciliation removed and rows that left a table view’s window (rows disposed with their whole site count as disposed scopes instead) |
rows_reused | Old rows an each reconciliation kept; a reconciliation whose list equals the old one counts nothing. A table view compares no list and counts nothing here |
rows_updated | Rows kept whose content was written: a row of an each whose item changed, and a drawn row a table view draws before and after the event whose row in the table was written. Pinned beside rows_created, rows_removed and rows_moved, it says exactly which drawn rows of a table view a write woke |
rows_moved | Rows moved |
view_transitions | Host-call batches marked for animation, including result turns; never mount |
startup / startup_ack / startup_complete | Cold frame declarations, private acknowledgement requests and completed bootstrap records |
opportunity_commands | Arm/cancel records for the one browser-task opportunity |
opportunity_requested / opportunity_cancelled | Opportunity registrations armed / cancelled |
opportunity_delivered / opportunity_stale | Accepted / obsolete opportunity occurrences |
create_element | Elements created |
bind_event | Event listeners bound |
set_metadata | Document title writes |
set_text | Text writes and text nodes created |
set_value / set_checked | Control value / checked the engine set |
patches_emitted | DOM commands; excludes RELEASE, TRANSITION and GUARD, which do not change the DOM |
registrations_released | RELEASE commands emitted for nodes owning document-key registrations or layout observations |
derived_calls_into_roc | Evaluations of app closures: holes, conditions, list reads, derive inputs, remount_on keys, watched values, cleanup values. For a table view: each read of its query or its window, and each row it places with the query’s keep and sort (two for a written key, the row before and after; every row of the table for a mount or a rebuild) |
scopes_created / scopes_disposed | when and switch branches, remount_on bodies, and the rows of each and table view sites, mounted / disposed |
dirty_source_roots | What a turn wrote: the local states and the cells. A decision that returns no write counts nothing |
each_key_hashes / each_key_compares | Keys hashed and full-key comparisons in keyed reconciliation |
effects_issued | Awaited requests issued (HTTP, timers, storage reads, subscriptions, worker jobs); a refused request is not issued |
effects_delivered | Results delivered to their site, including Refused and answers withheld by keep_current; progress excluded |
effects_progress | Transfer progress reports delivered to their site, including those keep_current withholds from its progress handler; replaced reports excluded |
effects_stale | Results dropped because their request was no longer in flight |
effects_refused | Requests refused because the in-flight table was full |
effects_cancelled | Requests stopped because their site was disposed or superseded |
effects_reparented | Admitted requests handed to a surviving ancestor when their site was disposed |
effects_skipped | Writes a reparented result or progress report made to state that no longer exists |
Any other metric name is a parse error. Two more steps measure work on one element or service:
(expect-updates LOC N)— the element was written N times: its creation plus every later attribute or text write on it or a text node directly inside it. In the work spec above,resultsis created, then showsSearching…, then the answer: 3.(expect-interval MS N)and(expect-cleanup "name" N)(above) check that a disposed scope released its subscriptions and ran its cleanups. A zero cleanup count requires a positive count of the same name somewhere in this spec, or:never-runs. A zero interval count andtick-interval-if-active MSrequire a positive interval count ortick-interval MSof the same period, or:never-started. A marker is rejected when the spec has that evidence. The assertions still check the exact count; a conditional tick still delivers nothing when inactive. A marked subject must have that positive evidence in another spec in the app’s suite, even when the run selects only this story.
Natively, every work step also checks that the engine’s per-command
counters agree with the commands the oracle decoded, and that every issued
request was one FX command and every cancelled one a CANCEL, so the
counters cannot drift from what was emitted.
The settle check
After mount and after every step, the native runner also asks the engine
whether the step left anything stale. The engine runs one more observation
pass over a copy of the instance, as if every local state and every cell had
changed: every text and attribute is re-read, every when, switch and
remount_on decides again, every each reconciles, every derive,
resource and effect site re-reads its input, and the pass reaches into
every row. Each compares with its last observation: the emitted value, or
for a shown property the browser-echoed state. After a complete turn the
pass emits nothing. The scratch transition collection starts empty, and a
new request fails the check even if its types duplicate the real call’s.
If a write never reached one of its
readers, the pass emits the update the turn should have, and the step fails
naming it:
click: a reader was left stale: a settle pass over every signal emitted
SETTEXT=1; first write: <p data-testid="late">late 0</p> -> <p
data-testid="late">late 1</p> (in test-id "late")
A table view keeps itself up to date from the rows each turn wrote, not by comparing values, so in the same pass every table view is also built from scratch, for its query and window as they are then, and must equal the one the engine kept: the same rows, in the same order, in the same window.
A settle failure is an engine defect, not a spec error: the step did what it says, and the engine left a reader showing an old value. Do not change the spec to avoid it; reduce it and report it against the engine.
The check needs nothing from the spec, so every spec guards against stale
readers without asserting them. It is an oracle on the engine, not a step:
the browser runner has no equivalent and needs none, since it replays the
same engine. It sees only propagation. A reducer or a decision that writes
the wrong value, or a command the engine encodes wrongly, settles as
faithfully as a correct one; expects and specs catch those.
Running specs
The project’s tasks run the registered apps’ specs:
| Command | Runs |
|---|---|
blueprint run spec | Every app’s specs, natively |
blueprint run spec -- kanban-board | One app’s specs, natively |
blueprint run spec -- --browser kanban-board | Natively, then in headless Chrome |
blueprint run spec -- --filter 'add*' kanban-board | Only specs whose file name matches the glob |
blueprint run check | The pull-request gate: every app’s specs in both runners, the documentation samples’ specs, and the rest of the suite |
For an app of your own, roc signals.roc test in the app’s directory
builds its native spec runner for the system it runs on and runs every spec
in specs/, printing one line per spec and, for a failure, the step that
did not hold with its file, line and column (see
Getting Started). It exits with 1 when
any spec fails, so CI can run it as it is. The runner builds and behaves
alike on Linux x86-64 (x64musl), macOS on Apple silicon (arm64mac) or
Intel (x64mac), and Windows x86-64 (x64win, where the runner is
build/app-specs.exe); a spec means the same on each, and in Chrome. By
hand, build the entry point for your system’s target and pass the runner
spec files:
roc build --target=x64musl main.roc --output=build/app-specsbuild/app-specs --check-suite specs/*.scmchecks every negative marker’s positive evidence across the full app suite without mounting. Run it before selecting stories by hand; the tool and repository tasks do this for you.build/app-specs specs/*.scmruns them and prints one JSON result line per spec, with the failing step’s file, line and column;--filter GLOBselects by file name.build/app-specs --emit-steps specs/*.scmprints the parsed steps that the browser runner (tests/browser/replay.mjs) replays.build/app-specs --soak 48 specs/round-trip.scmrepeats the engine calls after the lastmark-metrics, requiring the same structural work and flat live allocations. Placeholder opportunities resolve the current armed task each cycle; a missing task fails the round trip.build/app-specs --startup-catalogueprints the compiled concrete entry paths and root facts without initializing an instance. A legacy entry refuses this mode with the explicit--no-prerendermigration path.build/app-specs --prerender PATH --template index.html --build-token TOKENprints, as one JSON line, the annotated first page the default build writes (see Build a first page): PATH must exactly name a declared entry. It captures the cold frame before queued Self/refusal follow-ups, validates ordinary and binding profiles with their separate acknowledgements, and renders throughDom.roc, without performing hosted effects or giving external answers. TOKEN must match the published loader’s asset receipt. Legacy replacement pictures retain--prerender URL --template index.htmlwithout a token.--picture-path URLprojects only the output filename. These modes take no spec files.
No ordinary step asserts on the cold HTML itself. A spec starting at its entry
with (initial-location URL) tests the app after bootstrap, then controls its
later effects and placeholder opportunities. Native producer and real-browser
contracts separately check the cold frame, retained DOM identities and startup
barrier.
Walks
The same runner can walk an app: build/app-specs --walk 300 specs/*.scm
mounts it as the first spec’s setup says and takes 300 seeded steps
(--seed N chooses another sequence). Each step is something a user could
do to a control that is live at that moment, or a service the browser would
perform: answering a pending request from the answers the specs stage,
ticking a live interval, supplying an armed placeholder opportunity, or
delivering a message a spec emits on a port. An opportunity is an explicit
chosen service; merely taking another step does not activate a body. After
every step the settle check must pass, and at the end nothing the app
allocated may be left live. A failure names the step and the last things
the walk did.
A walk needs nothing written for it: no entry point of its own, no target
and no harness. Its sequences are ones no spec spells out. It checks the
engine under your app rather than your app’s rules, so it knows nothing of
what the app should show: expects and specs say that.
Fuzzing your own logic
Specs check the paths you thought of. Where an app has pure logic of its
own with a rule you can state, check it over inputs you did not think of
with roc-fuzz: a parser
that must read back what its writer wrote, a reducer that must agree with a
simpler model of itself, an invariant that must hold after any sequence of
operations. That is a test of your logic, apart from roc-signals: the
target is an ordinary roc-fuzz app whose platform is a roc-fuzz release,
and it imports your pure modules and nothing of the platform. Keep the
logic you fuzz in modules that import nothing from pf, as you would to
test it in any Roc program. A component’s module imports the platform for
its view, so operations worth fuzzing belong in a domain module the
component uses.
Name the target for what it checks, fuzz-<subject>.roc, beside the
modules it imports. The CSV Converter’s examples/csv-converter/fuzz-csv.roc
is one: it generates tables of awkward fields and checks that what its
Csv module writes reads back, and that reading in chunks of any size reads
the same lines. Build and run one with roc-fuzz’s own commands:
roc build --fuzz fuzz-csv.roc --output=build/fuzz-csv
build/fuzz-csv check # its declared examples
build/fuzz-csv explore corpus --time=60 # a minute of exploration
A round trip, a spec that takes the app back to where it started, stays an ordinary spec like any other.
Debug output
Both runners print real dbg evaluations, without a spec step to observe
them. Browser replay forwards page-console [dbg lines to its standard
error. Native settle checks mute their speculative reader evaluations, so
a reader prints once for each real evaluation. Observation differences
remain: native prints every entry while Chrome retains the newest 4096 entry
bytes per call; native prepares afresh for every job while a browser worker
may reuse prepared state. A dbg reached while constructing a top-level
constant or checking the default mount can print during compilation instead
of a runner invocation. Declaration evaluation counts are not guaranteed.
None changes a job answer or an assertion’s meaning.
See Debugging for faults, bounds and deployment settings.