Skip to content
/ Lonca
Documentation contents

Orchestration

Tests, the gate and jobs

Scoped tests for stage agents, the full suite once before the pull request, and how Lonca runs and watches jobs.

The expensive check runs once. Each stage agent tests only its own change, quickly and in the foreground; the full suite and the repository’s verify run once, before the pull request, and Lonca runs them, not a stage agent. Three optional keys on a repository say how: tests: for what a stage agent may run, gate: for the pre-PR gate, jobs: for the long commands a stage agent hands to Lonca.

Without them a repository has neither scoped rules nor a gate: Lonca guesses no command. The Configurator writes all three from the repository and checks each command by running it, in a narrowed form, before it keeps it (see The Configurator).

What a stage agent may run

config.yaml (a repository)
tests:
  match: ['^(pnpm|npx)\s+(exec\s+)?(vitest|jest)\b', '^(pnpm\s+)?nx\s+(test|lint|typecheck|affected)\b']
  forbidden: ['^pnpm\s+verify\b', '^(pnpm\s+)?nx\s+run-many\b', '^(pnpm\s+)?nx\s+test\s+\S+\s*$']
  timeout_minutes: 10
  guide: |
    Related specs: pnpm vitest related --run <files>. Lint: pnpm nx lint <project>.
match
Regular expressions for the shell commands that are test runs. Lonca’s hook caps their timeout at timeout_minutes (1–10, default 10, the shell tool’s own ceiling), refuses one started in the background, and logs each with its duration and result.
forbidden
Commands a stage agent never runs: the full suite, verify. The hook refuses them and tells the agent why; they show as Denied in the Tests section. The E2E runner is not held to them: it builds and starts the app for Lonca’s runner as the repository’s e2e: block says.
guide
Quoted into the implementer’s prompt: how this repository runs a scoped test, lint and typecheck.

How a pattern matches

  • Each pattern is tried on the whole command and on each command of a chain (&&, ||, ;, |), past leading VAR=value assignments.
  • Anchor patterns with ^, as above. Then cd apps/sales && pnpm verify is caught, while grep -rn "pnpm verify" docs or a commit message that mentions vitest is not taken for a test run. An unanchored pattern matches the text anywhere.
  • The policy holds every stage agent.
  • The policy is enforced by Lonca’s hooks, so a Codex stage agent needs {{hooks}} in its command (see Stage agents). Codex is held to forbidden, the background rule and the test slots, but not to the timeout cap (its shell tool takes none), and its test runs are logged with their result unknown, as it reports no exit code.

The pre-PR gate

config.yaml (a repository)
gate:
  commands:
    - [pnpm, nx, test, sales]
    - [pnpm, exec, vitest, run, --reporter=default, --reporter=junit, '--outputFile.junit={{junit}}/unit.xml']
  rerun_spec: [pnpm, exec, vitest, run, --config, apps/sales/vite.config.mts, '{{file}}']
  timeout_minutes: 90
  • After a clean review and before the PR, Lonca runs commands in the worktree, in order, each as an argument list, never through a shell. Nx’s cache stays on. If the repository’s verify already runs the suite, list only verify.
  • The result is recorded as it is, failures included: in pipeline/r<N>/gate.md in the task’s context directory, with each command’s output in gate-<i>.log, and in the Tests section.
  • A failing gate sends the work back to implementation with only its failures. Under consultant or autopilot, a gate that failed only on specs outside the change, which also fail alone, is held for the task’s lead to look at first; under assistant, or with no task leads, it comes to you at once. The card offers Set aside (those specs are skipped at the gate from now on, listed in the PR, and the gate runs again) or Send back to implementation.
  • Before the gate, Lonca checks the branch against its base and rebases when it is behind. After a clean rebase the gate runs whole. The gate never runs on the old base.
  • The gate does not repeat work on a commit that already passed it. On the clean commit where the test stage passed, an E2E scenario that passed there and reads the same is not run again; with none left, the app is not even built. After a gate that did not finish (an error, a pause), the commands that passed on the same commit are listed as passed in an earlier gate run and not run again. A new commit or a rebase runs everything.
  • While a gate command or a job runs, Lonca keeps the Mac from idle sleep.

One gate at a time

Gates run gate_concurrency at a time across all tasks (default 1): two full suites at once are what make specs fail at random. A waiting gate says its place in line on the task. With load control on, the setting is a ceiling and Lonca may run fewer while the machine is busy (see Load control and concurrency).

JUnit reports

Lonca reads the gate’s failures from JUnit reports, never from a command’s console output. The reports stay out of the repository: before each command, Lonca empties a folder of its own for it, pipeline/r<N>/junit/<i>/ in the task’s context directory, and names it to the command twice, as the environment variable LONCA_JUNIT_DIR and as {{junit}} in its argument list. No .gitignore entry is needed, and an earlier run’s report is never read.

Under nx, where one command runs many projects, let each project’s test config write its own file:

vite.config.mts
outputFile: { junit: process.env.LONCA_JUNIT_DIR ? `${process.env.LONCA_JUNIT_DIR}/${name}.xml` : 'reports/junit/unit.xml' }

For jest-junit, set addFileAttribute: true, or the report names no file at all.

Flaky specs

A spec that fails at the gate outside the task’s change may be flaky, not broken. With rerun_spec, Lonca runs such a spec alone, once:

The failing specWhat happens
Outside the change, passes aloneA flake: recorded, listed under Flaky specs, and not held against the task.
Outside the change, fails alone tooA real failure, sent back (or held for a look, above).
Inside the changeSent back to implementation, with only those failures.
Cannot be placed on exactly one file in the worktreeA blocker, and its finding says so.
  • {{file}} is the spec’s path relative to the repository, and rerun_spec runs from the repository root; {{name}} is the file’s name without its extension, for runners that take a class name (Maven: [mvn, -B, test, '-Dtest={{name}}', -Dsurefire.failIfNoSpecifiedTests=false]).
  • A path in the report may be absolute, relative to the repository, or relative to its project, as vitest and jest write it under nx; Lonca takes the one tracked file that ends with it.
  • When every failure of a command turns out to be a flake, the command runs once more and must exit 0: a verify that also failed on lint, typecheck or a suite-level error is a blocker however its specs did.
  • Without rerun_spec, or when a failing command wrote no readable report, the command runs once more. Failing again, it goes back with both runs’ output. Passing, the gate goes on, gate.md lists it under “Passed when run again”, and the PR’s description names it.
  • Run rerun_spec once by hand on a known spec before you rely on it.

A slow command is not a stuck one

A command that runs past timeout_minutes (default 90) is not stopped while it keeps working: a full suite on a loaded machine is slow, not stuck.

  • Every five minutes Lonca checks the CPU its processes used, counting those that moved to a group or session of their own (Nx runs each task in a terminal of its own), and whether it wrote any output.
  • One that did neither is stuck: the task goes back to implementation with what was still running, since a spec that never ends hangs the same way on every run.
  • One still working at three times timeout_minutes is stopped too. Stopping it stops everything it started.
  • While it runs, the Flow tab says under the gate how long it has run and whether it is working (the CPU cores it uses) or quiet, and every five minutes the log gets the same line, in your local time.
  • A command stopped at three times its time, or one that cannot start, stops the gate as an environment failure. Under consultant or autopilot Lonca runs the gate again by itself first, then asks you; answering runs it again.

E2E at the gate

With Lonca’s E2E runner, the gate also runs the full E2E suite, after its commands. e2e_parallel: true runs it beside the commands instead, and the gate takes as long as the longer of the two. Turn it on only when no command changes what the running app reads (an install, a codegen into the sources, a build the app serves). Without it, Lonca stops the app it started for the E2E run before the commands, and the E2E run starts it again. gate.md says how long the whole gate took. See E2E runner and sign-in.

Every scenario runs on a task’s first gate. Once a gate passed, the next one runs only the scenarios that cover what changed since when every round since was light, and none at all when no scenario covers what changed (only tests or docs, say); otherwise every scenario.

A lighter gate after a light round

scope_after_light (off by default) says how a gate command runs on only the files a round changed, written with the repository’s own tooling: vitest’s related, jest’s --findRelatedTests --passWithNoTests. Lonca knows no tool’s command line and never makes one up.

config.yaml (under gate:)
scope_after_light:
  - command: [pnpm, exec, vitest, run, --reporter=default, --reporter=junit, '--outputFile.junit={{junit}}/unit.xml']
    scoped: [pnpm, exec, vitest, related, --run, --reporter=default, --reporter=junit, '--outputFile.junit={{junit}}/unit.xml', '{{files}}']

Each command must be one of gate.commands, written the same, and named once; scoped names {{files}} once, as an argument of its own. Each changed file becomes one argument.

  • The scoped form runs only when the last gate passed with every command whole, every round since was light (findings that change no behaviour, or a CI fix the implementer says changes no behaviour), and the code still sits on that gate’s base.
  • Every command runs whole on a task’s first gate, after any other round, after a gate that failed or ran scoped, after a rebase, and when the changed files cannot be told, are none, are more than 200, or include a deleted file.
  • The scoped form must exit 0 when no test relates to the files, since a round may change only docs or types. One that fails with no failing test in its reports runs once more whole, and the whole run decides.
  • gate.md marks a scoped row, and the Tests section does not count it as a full-suite run. CI on the push is then the full check: leave it out when CI does not run the whole suite.

Skipping the gate

While a task is at the gate, Skip the gate in its menu (the header's ⋯, or the row's ⋯ or right-click) stops it and sends the task on to the PR without the gate’s commands or its E2E run. The confirmation, Skip the pre-PR gate, says the PR will say the gate was skipped, so its reviewers and its CI know the suite did not run here; its “Steps not run” section lists it. It is your call, per task: the configuration keeps the gate for every other.

Jobs

A long command, such as a whole Playwright suite, is better run by Lonca than held in a stage agent’s shell:

config.yaml (a repository)
jobs:
  playwright-all:
    command: [pnpm, playwright, test]
    timeout_minutes: 30
  • A stage agent starts one with node "$LONCA_JOB" playwright-all. It returns at once with the path of the job’s output; the agent ends its turn, and Lonca writes into its terminal when the job is done.
  • While the job runs, the agent is not taken for quiet: no reminder, no retry, and the time does not count against its step.
  • Only the names written here run, at most 20 per repository. A name starts with a lowercase letter, then lowercase letters, digits and dashes, 32 characters at most; e2e-fix, e2e-regression and e2e-all are Lonca’s own. timeout_minutes is 1–240, default 30.
  • A stage agent under Claude Code’s Bash sandbox reaches the job socket without a setting of yours: Lonca allows it, and its other socket, in the session’s own settings.

The Tests section

The Flow tab’s Tests fold shows how a task was tested. Its line counts test runs, not test cases: 12 runs · 1 failed, with · 2 denied when the hook refused a command, and nothing until a test has run. Opened, it shows:

  • The setup: Tests: config or Tests: none, Gate: config or Gate: none, and the gate’s commands.
  • Full-suite runs: 1 (target: 1): green at one, orange above it.
  • Per stage agent and for the Pre-PR gate: Runs, Time, Failed, Denied.
  • Per round: the implementer’s time (Implementing), and how much of it went on testing (Of which testing).
  • Flaky specs (passed alone, outside the change).
  • The latest runs: when, by whom, the command, its time and its result.

With load control on, tests across tasks share a pool of test slots (test_concurrency): only a step that runs tests waits for one, and the task says who waits and who holds the slots (see Load control and concurrency). One gate run takes one slot for its commands and its E2E run together.