Skip to content

Write a reach script

At the end of this guide, a feature folder holds a reach.ts that ashlar map shows and ashlar drive walks.

The examples come from a Tauri app in apps/desktop, whose features live in apps/desktop/src/features/*.

  1. Find the feature folders that have no reach script yet:

    Terminal window
    $ pnpm exec ashlar map
    Cart apps/desktop/src/features/cart
    Open cart › Cart
    0 proofs
    Search apps/desktop/src/features/search
    no reach script yet
    1 proof

    Every folder in an app's features is a feature folder, and the feature-reach rule counts one break in each that has no reach script that reads. ashlar check names the file to write:

    Terminal window
    $ pnpm exec ashlar check
    Ashlar checked 11 files in 0.2 s: 1 count rose.
    feature-reach in apps/desktop/src/features/search/reach.ts: 1, up from 0
    apps/desktop/src/features/search/reach.ts:1:1
    Every feature folder holds a reach script, `reach.ts`: the developer's way to the feature as drive steps, ending on a snapshot of what it reaches. It is plain data that imports only types. Write one, then run it with `ashlar drive <feature>`.

    It exits with 1 here because the folder is new. If you took the baseline before the features had reach scripts, the baseline holds these breaks and the check passes until you write them.

  2. Write reach.ts in the feature's folder:

    import type { ReachScript } from '@kurvball/ashlar/reach';
    export default {
    name: 'Search',
    steps: [
    { key: 'ControlOrMeta+k' },
    { type: 'red shoes' },
    { key: 'Enter' },
    { snapshot: 'Results', role: 'list' },
    ],
    } satisfies ReachScript;

    The default export is the feature's name and its steps, the way a person reaches it from the app's home. It is plain data. Node loads it as it is, so it imports only types: no component, no other module and nothing that runs.

    The name is what the developer and the agents call the feature. No two features may share one, and it is at most 60 characters.

    Each step is one of four:

    Step Does Takes
    { click: 'Open cart' } Clicks the one element with that accessible name. role, when more than one element has the name
    { type: 'red shoes' } Types the text into what has focus. nothing more
    { key: 'ControlOrMeta+k' } Presses a key. nothing more
    { snapshot: 'Results' } Reads the element with that name, and fails if nothing on screen has it. role, when more than one element has the name

    The last step is a snapshot of what the reach gets to, so a run proves it got there, and only the last step is one. A script holds at most 40 steps. A name in a click or a snapshot is the words on screen, as a snapshot shows them, and at most 120 characters.

    A role is one of alertdialog, article, button, checkbox, combobox, complementary, dialog, grid, gridcell, group, heading, link, list, listitem, main, menu, menuitem, menuitemcheckbox, menuitemradio, navigation, option, radio, region, row, searchbox, status, switch, tab, tablist, tabpanel, textbox, toolbar, tree or treeitem.

    A key is named as Playwright names it: Enter, Escape, Tab, Backspace, Delete, Space, ArrowUp, ArrowDown, ArrowLeft, ArrowRight, Home, End, PageUp, PageDown, F1 to F12, a lower-case letter or a digit, or one of , . / ; ' ` [ ] \ = -. Put modifiers in front, joined by +: ControlOrMeta, Meta, Control, Alt and Shift. ControlOrMeta+k is ⌘K on a Mac and Ctrl+K elsewhere.

  3. Read it on the map:

    Terminal window
    $ pnpm exec ashlar map
    Cart apps/desktop/src/features/cart
    Open cart › Cart
    0 proofs
    Search apps/desktop/src/features/search
    ControlOrMeta+k › “red shoes” › Enter › Results
    1 proof

    A proof is a test in the feature's folder. ashlar map --json gives each step the drive command it runs:

    {
    "says": "Results",
    "run": ["snapshot", "--name", "Results", "--role", "list"]
    }

    The feature-reach break for the folder is gone, and ashlar check --shrink lowers the baseline.

  4. Fix a script that doesn't read. Ashlar says which step is wrong and why:

    Terminal window
    $ pnpm exec ashlar map
    Cart apps/desktop/src/features/cart
    Open cart › Cart
    0 proofs
    Search apps/desktop/src/features/search
    its reach script doesn’t read: see below
    1 proof
    Search’s reach script doesn’t read. Step 1 presses a key drive doesn't know: name it as Playwright does, such as Meta+k.

    That script pressed Cmd+k. A script that doesn't read still counts as a feature-reach break. Each refusal says one of these:

    Refusal What Ashlar says
    not_a_script A reach script's default export is an object: its name and its steps.
    no_name Give the reach script the name the developer and the agents say the feature by.
    long_name A feature's name is at most 60 characters.
    no_steps Give the reach script its steps, ending on a snapshot of what it reaches.
    too_many_steps A reach is at most 40 steps.
    bad_step Step n isn't a drive step: one of click (with a role, if it helps), type, key or snapshot.
    bad_key Step n presses a key drive doesn't know: name it as Playwright does, such as Meta+k.
    bad_role Step n names a role drive doesn't know.
    not_ending_on_snapshot A reach ends on a snapshot of what it reaches, so a run proves it got there.
    snapshot_midway Step n is a snapshot: only the last step is.

    A script that Node can't load, or that takes another feature's name, doesn't read either, and Ashlar says why in the same place.

  5. Name your drive command in the config. It is the command that drives your running app:

    import { defineConfig } from '@kurvball/ashlar';
    export default defineConfig({
    include: ['apps', 'packages'],
    drive: 'pnpm drive',
    apps: [{ root: 'apps/desktop', stack: 'tauri' }],
    });

    Ashlar runs it from the root, once for each step, with the step's arguments and --json:

    Terminal window
    pnpm drive click --name 'Open cart' --role button --json
    pnpm drive type 'red shoes' --json
    pnpm drive key ControlOrMeta+k --json
    pnpm drive snapshot --name Results --role list --json

    It runs stop before the first step and after the last, so each walk starts the app afresh. The command answers with one JSON object on its last line of output: { "ok": true } when the step worked, or ok: false with a failure (not_found, ambiguous, not_running, timed_out or crashed) and what it says. A command that prints no JSON is taken at its exit code. Each step has 60 seconds.

    A drive command written in TypeScript can read these arguments with parseDrive from @kurvball/ashlar/drive. Without a drive command, a reach script is still data: the map, the brief and the onboarding guide show it, and ashlar drive says the config names none.

  6. Walk the reach:

    Terminal window
    $ pnpm exec ashlar drive search
    Search: reached in 4 steps.

    Name the feature by its name or its folder. --scheme dark asks for the dark colour scheme: Ashlar runs each step with DRIVE_SCHEME=dark. --all walks every feature:

    Terminal window
    $ pnpm exec ashlar drive --all
    Cart: reached in 2 steps.
    Search: its reach stopped at “Results”, step 4 of 4. Nothing on screen is named “Results”.
    1 of 2 features reached.

    It exits with 1 when a reach stops. If the work broke the way in, fix the work. Change the reach script only when the way in itself changed. --json prints each walk as an object:

    {
    "version": 1,
    "feature": "Cart",
    "folder": "apps/desktop/src/features/cart",
    "stoppedAt": 1,
    "step": "Open cart",
    "ms": 60,
    "outcome": "stopped",
    "steps": 2,
    "says": "Nothing on screen is named “Open cart”."
    }