---
title: Lock and verify
description: stoic lock freezes the tests and the spec; stoic verify holds every change to them, and with --coverage every changed line of code. Every verdict it can give, and how to gate CI with it.
kicker: Lock
---

# Lock and verify

A spec is a promise. The lock is the promise written down where it can't quietly change, and verify is the moment it's checked. Everything else in Stoic exists to make these two steps trustworthy.

## Lock

```sh
$ stoic lock spec/
locked 4 tests from 1 file(s) into stoic.lock
```

`stoic.lock` records every test, two hashes for each (its whole definition, and its own text alone), each checked value, and a hash of every spec. Commit it and review it like code. Paths in it always use `/`, and line endings don't count: a checkout where git writes `\r\n` hashes, verifies and formats exactly as one with `\n`, so a lock written on Windows is the one written on macOS or Linux. Relocking prints what changed, test by test, and every checked value that moved. Here the rounding changed on purpose:

```sh
$ stoic lock spec/
locked 4 tests from 1 file(s) into stoic.lock
  ~ fee600  test of `fee`: given nothing; on call with "600"; expect `fee` exactly "53" (reported back and compared); expect "52.5 rounds up to 53" (not checked)
  value fee600 fee: 52 -> 53 (spec/fees.stoic:15)
  tests: 1 changed, 0 only through their target, 0 added, 0 removed
```

A relock never fails on a changed value, because changing behaviour on purpose means changing a value. It just can't do it quietly.

A test renamed in the same edit would otherwise read as one test removed and an unrelated one added, its old and new values never side by side. So a removed test and an added one in the same file, testing the same target, that differ only in their IDs and checked values are paired as one rename:

```sh
$ stoic lock spec/
locked 4 tests from 1 file(s) into stoic.lock
  ~ fee600 -> fee600_round  test of `fee`: given nothing; on call with "600"; expect `fee` exactly "53" (reported back and compared); expect "52.5 rounds to the even 52" (not checked)
  value fee600 -> fee600_round fee: 52 -> 53 (spec/fees.stoic:15)
  tests: 0 changed, 0 only through their target, 0 added, 0 removed, 1 renamed
```

Nothing pairs loosely: when two removed or two added tests could pair, none do.

## Verify

```sh
$ stoic verify results.txt --run "npm test" --strict
```

`--run` deletes the old results, runs your tests (with `sh -c`, or `cmd /S /C` on Windows, so `--run "npm test"` works on both), and reads the fresh file they wrote, so nothing stale or hand-written counts. It sets `STOIC_RESULTS` to the results file you named, and Stoic's reporters write there. Then every locked test gets a line, and the run gets a verdict that says how much the pass proves:

```sh
verified: 4/4 locked tests passed (4 checked, 0 asserted only, 0 examples)
```

A run that isn't verified ends with one more line, so the last line alone (`stoic verify … | tail -1`) says what went wrong and what to do: how many lines of each kind it printed, and the one next step.

```sh
WRONG    fee600 fee: expected 52, observed 53

NOT verified: 3/4 locked tests passed (4 checked, 0 asserted only, 0 examples)
next: 1 WRONG above. Fix the code until every locked test runs under its ID, passes and reports the values it checks; don't edit a spec or the lock to make this pass.
```

## Every verdict

| Line | Means |
| --- | --- |
| `pass` | Ran, passed, and reported the locked value if it has one. |
| `WRONG` | Passed, but a value it reported isn't the locked one. |
| `MISSING` | A locked test isn't in the results at all. |
| `FAILED` / `SKIPPED` | The test said so itself. |
| `DRIFT` | The spec or a test changed since the lock (a renamed test says so, with its old and new ID), or the lock differs from the trusted one. |
| `VALUE` | Which checked value a drifted test moved, from what to what. |
| `DISPUTE` | A test objected that it looks wrong. Listed first; fails until an owner settles it, with [`stoic review`](/docs/agents/#owner-review). |
| `UNKNOWN` | With `--strict`: results name a test that isn't locked. |
| `SCOPE` | With segments: a part of the spec changed, and no relock by its owner or claim holder made the change. |
| `STALE` | With claims: a relock made under a claim that has since been taken over or released. Its `next:` line says to stop and report it, and names the `stoic claim … --take-over` that would hand the segment back once the claim expires. |
| `UNSPECIFIED` | With `--coverage`: implementation lines changed since `--against` that no locked test runs. `--strict` fails on them. |
| `ERROR` | A lock that names a spec out of sight (outside its folder, in a hidden folder, through a symlink), or a name two locked files both define. With `--strict`: a rule with no witness, a test with nothing checked, a spec the lock doesn't cover. |

Exit codes mean what they say: `0` verified, `1` not, `2` a bad call. Each command takes only its own options, so a flag meant for another command is an error, never silently ignored.

## Drift: what changed, and who changed it

Verify tells two kinds of change apart. A test whose **own text** changed (an expectation, an input, a step) gets its own line, because that's where tests get loosened. Tests that changed **only through what they test** (a field's rule moved) share one line per target, so you review the spec change once.

```sh
DRIFT    spec/fees.stoic: the spec changed since it was locked
DRIFT    test `fee600` changed since it was locked
VALUE    fee600 fee: 52 -> 53 (spec/fees.stoic:15)
```

A renamed test is paired as the relock pairs it, so its values still sit side by side:

```sh
DRIFT    test `fee600` in spec/fees.stoic was renamed `fee600_round` (same target and steps)
VALUE    fee600 -> fee600_round fee: 52 -> 53 (spec/fees.stoic:15)
```

## Trust the lock on main

An agent can run `stoic lock` too. So in CI, verify against the lock that was reviewed, not the one in the branch:

```sh
$ stoic verify results.txt --run "npm test" --strict --against origin/main
DRIFT    spec/fees.stoic: the spec changed since it was locked
DRIFT    test `fee600` changed since it was locked
DRIFT    stoic.lock differs from origin/main: relocking needs review
VALUE    fee600 fee: 52 -> 53 (spec/fees.stoic:15)
pass     fee_amount_accepts_500
pass     fee_amount_rejects_0
pass     fee_amount_rejects_1_5
pass     fee600

NOT verified: 4/4 locked tests passed (4 checked, 0 asserted only, 0 examples), 3 change(s) since the lock (tests: 1 changed, 0 only through their target, 0 added, 0 removed)
next: 3 DRIFT, 1 VALUE above. Stop: stoic.lock changed since origin/main (1 value change(s)); this needs review before going on. Report the DRIFT and VALUE lines and wait; don't relock, or edit a spec or a test, to make this pass.
```

Every test passed, and it still isn't verified: the branch relocked a value, and only a review can accept that. So under `--against` the next step is a stop. An agent is told to report the change and wait, not to relock its way past it.

When several agents share a codebase, `stoic.segments` and claims let verify say whose change it was; see [Agents](/docs/agents/#many-agents-one-truth).

`stoic init` writes a GitHub Actions workflow that does exactly this on pull requests, pinned to the base commit (add `--coverage` to it to fail a pull request that adds code no locked test runs), plus a `.gitattributes` rule so lock conflicts are relocked rather than merged line by line, and a CODEOWNERS example so the lock needs an owner's review.

## Code no locked test runs

A spec can only enforce what its tests run. A new function, a branch an agent added "while it was there", another agent's quiet change: code that no locked test runs passes every test and verifies, unspecified. `--coverage` catches it, whoever wrote it and in whatever order. The tests' run writes an LCOV report, and git says which lines changed since the reviewed base:

```sh
$ stoic verify results.txt --strict --against origin/main --coverage lcov.info --run "node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info"
pass     fee_amount_accepts_500
pass     fee_amount_rejects_0
pass     fee_amount_rejects_1_5
pass     fee600
pass     fee_minimum
UNSPECIFIED  src/fees.js:6-7  (changed since origin/main; no locked test runs it)
coverage: 3/5 changed line(s) in 1 implementation file(s) since origin/main run by locked tests

NOT verified: 5/5 locked tests passed (5 checked, 0 asserted only, 0 examples), 2 changed line(s) no locked test runs
next: 1 UNSPECIFIED above. Specify the behaviour first: add or change a test in the spec that runs this code and relock (after review), or remove the code; a test that isn't locked doesn't count.
```

Every locked test passed, and two new lines still ran under none of them. The way out is the spec: a test that runs that code, locked after review, or no code. With the branch gone:

```sh
coverage: 1/1 changed line(s) in 1 implementation file(s) since origin/main run by locked tests

verified: 5/5 locked tests passed (5 checked, 0 asserted only, 0 examples)
```

The rules are decided once. It needs `--against`: the lines checked are the ones changed since the reviewed base, because a total percentage enforces nothing. The report must be fresh: `--run` deletes it before the tests run, so one left from another run can't count. A report that can't be read whole fails closed. Give `--coverage` once per report (one per package or per language) and their hits add up. A changed file the report lacks is unspecified whole, since no test even loaded it.

Only implementation counts, and `stoic.code` beside the lock says what that is, with the same globs as [the gate](/docs/agents/#spec-first-as-the-agent-writes). Paths are from the project root, the git work tree's top folder, so a lock in `spec/` checks the code in `src/`. Without `stoic.code`, it's every file but specs, Stoic's own files, tests, `*.md`, hidden paths and what git ignores.

Every mainstream coverage tool writes LCOV. `stoic help verify` prints the command for each:

| Runner | Writes LCOV with |
| --- | --- |
| node 22+ | `node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info` |
| c8, Jest, Vitest | `c8 --reporter=lcovonly`, `jest --coverage --coverageReporters=lcovonly`, `vitest run --coverage.enabled --coverage.reporter=lcovonly` (to `coverage/lcov.info`) |
| Python | `coverage run -m pytest && coverage lcov -o lcov.info`, or `pytest --cov=. --cov-report=lcov:lcov.info` |
| Rust | `cargo llvm-cov --lcov --output-path lcov.info` |
| Go | `go test -coverprofile=cover.out ./...`, then `gcov2lcov -infile=cover.out -outfile=lcov.info` |

Two limits, by construction. Coverage counts whatever the run executes, so a test that isn't locked covers code too: keep the test command to the locked tests (`--strict` lists any reported test that isn't locked as `UNKNOWN`). And a diff is by line, so a new line identical to the one it replaced reads as unchanged.

## Before you relock

`stoic check` is the one call to make first: it compiles every spec, checks formatting, and shows what changed since the lock.

```sh
$ stoic check spec
checked 1 file(s): they compile, are formatted and match stoic.lock
```

## What verify can't do

Stoic is honest about its edges, so we will be too. Verify sees results and, with `--coverage`, which changed lines ran; it never reads what the code does. An expectation in words, `=>"shows a toast"`, is only as good as the test someone wrote for it, which is why checked values exist and why `--strict` insists on them. And the results file is only as trustworthy as whoever ran the tests, which is why `--run` exists and why CI should be the one running it.
