Clara Docs
All docs

M1 evidence: the library

Evidence8 min readEdit on GitHub

On this page

Date: 2026-11-17. Machine: macOS 26.3, Apple silicon, Node 22.17.1, npm 11.5.2. Commits 2b7ddeb to fd6f6df, plus the review fixes listed at the end.

The brief's proof for M1: "unit and property suites, the coverage gate, the multi-process claim race, a first 10,000-ticket benchmark."

Acceptance

Check Result
Unit and property suites pass 2,016 tests in 53 files, output below
Library line coverage at least 90% 98.32% lines, 96.12% branches
Exactly one of eight processes wins a claim on one ticket yes, 20 runs out of 20
Board data for 10,000 tickets, warm, under 500 ms 73.4 ms
npm run ci exits 0 locally and in a clean clone yes
The packed package works from an empty folder through clara, clara/node and clara/schemas yes

Tests and coverage

$ npx vitest run --coverage
 Test Files  53 passed (53)
      Tests  2016 passed (2016)

Statements   : 97.87% ( 4321/4415 )
Branches     : 96.12% ( 2731/2841 )
Functions    : 98.6% ( 848/860 )
Lines        : 98.32% ( 3632/3694 )

The gate fails below 90% of lines or 85% of branches (vitest.config.ts).

Property suites

Every property test runs with a fixed seed (test/helpers/property.ts), so a failure reproduces exactly.

$ npx vitest run test/property --reporter=verbose
✓ format > scalars > any text survives being written and read by a YAML reader
✓ format > scalars > text judged safe without quotes really is
✓ format > front matter > whatever the writer writes, a YAML reader and Clara read back the same
✓ format > front matter > the fast reader never disagrees with the full one
✓ format > tickets > writing a ticket and reading it back returns the same ticket
✓ format > tickets > a ticket Clara wrote is read without the full YAML parser
✓ format > tickets > survives a file saved with Windows line endings
✓ format > the activity log > every event is one line, and reads back the same
✓ format > the activity log > never throws, whatever is in the file
✓ format > ticket bodies > a section that was set can be read back, whatever the body held before
✓ format > ticket bodies > removing a section leaves no trace of it
✓ format > ticket bodies > ticking a criterion changes that criterion and nothing else
✓ format > ticket bodies > added criteria appear at the end of the list, and the old ones stay
✓ query > parseQuery > answers any string without throwing
✓ query > parseQuery > answers any string built from the pieces of the language
✓ query > parseQuery > answers text that is nearly a query, too long, or too deep
✓ query > formatQuery > writes a query that parses again and finds the same tickets
✓ query > compileQuery > agrees with deciding the same tree of terms by hand
✓ query > runQuery > returns some of the tickets it was given, in one fixed order, cut to the limit
✓ ops > any sequence of operations > by agents alone never reaches done without an approval the review mode allows
✓ ops > any sequence of operations > by people and agents keeps one holder, fresh ids, and a log that replays to the files

Two more live beside the unit tests they extend: ranks (test/unit/rules/rank.test.ts: a rank between any two ranks sorts between them) and the JSON Schemas (test/unit/model/json-schemas.test.ts: any ticket the serialiser writes passes the published schema, checked by Ajv in strict mode).

Many processes on one folder

test/integration/storage-disk.test.ts starts real Node processes against one .clara on disk and releases them at the same moment.

$ npx vitest run test/integration/storage-disk.test.ts --reporter=verbose
✓ disk storage across processes > lets exactly one of eight racing processes win 335ms
✓ disk storage across processes > gives a ticket to exactly one of eight agents claiming it at once 679ms
✓ disk storage across processes > loses no update when six processes append to one file 591ms
✓ disk storage across processes > finishes the commit of a process that died at "journaled" 195ms
✓ disk storage across processes > finishes the commit of a process that died at "applied-one" 195ms
✓ disk storage across processes > finishes the commit of a process that died at "applied-all" 202ms
✓ disk storage across processes > finishes the commit of a process that died at "versioned" 198ms
✓ disk storage across processes > leaves no trace of a commit whose process died before the journal 179ms
✓ disk storage across processes > never shows a reader half a commit 651ms
Tests  9 passed (9)

The claim race: eight processes run ticket.claim on GEN-1 as eight different agents. The test asserts that exactly one exits 0 and seven exit 3 with CLAIM_HELD, that the ticket is in_progress and held by the winner, and that the log holds exactly one claimed event, by the winner. A race that passes once can be luck, so it was run twenty times in a row:

$ for i in $(seq 1 20); do npx vitest run test/integration/storage-disk.test.ts -t "eight agents"; done
passed 20, failed 0

The crash tests stop a process with process.exit at each step of a commit and check that the next process to open the folder finishes the commit or leaves no trace of it.

Budgets

$ node scripts/budgets.mjs
node itself starts in 35.6 ms on this machine

Budget                                   Measured      Limit
clara --version cold start               41.8 ms       100 ms  ok
Packed npm tarball                       0.24 MB       3 MB  ok
Board data for 10,000 tickets, warm      73.4 ms       500 ms  ok

What the 10,000-ticket number measures, and the cold and fsync numbers beside it, are in docs/BENCHMARKS.md.

The package from an empty folder

$ node scripts/pack-smoke.mjs
clara --version -> 0.1.0
clara-pm --version -> 0.1.0
import { VERSION } from 'clara' -> 0.1.0
require('clara').VERSION -> 0.1.0
types -> ./dist/types/library/index.d.ts
clara/node types -> ./dist/types/library/node.d.ts
clara/node board on disk -> GEN-1 in_progress agent:claude
clara/schemas/ticket.schema.json -> Clara ticket
package smoke test passed

"clara/node board on disk" is two processes: one writes a board through the installed package and claims a ticket, and the other reads it back.

The public API

test/unit/core/public-api.test.ts holds clara to the names in test/fixtures/api/clara.txt, so nothing joins or leaves the public API by accident. It also checks that every operation in the registry is exported under its own name; that check found ticketApprove missing, and it was added. The example at the top of library/index.ts runs as a test.

What was not verified

  • Disk storage on real Linux and Windows file systems. The platform differences (Windows reporting a file busy while another process has it open, and how a failed lock file is reported) are tested here through a stubbed platform; the real ones run when hosted CI runs.
  • Bun: not installed on this machine.

Fresh-eyes review

A subagent that had not written the code read the library against the brief and tried to break it. It was asked for the ten most serious problems with a repro for each. It found nine and reproduced every one; it named no tenth. All nine are fixed, each with a regression test that fails without the fix.

# Problem Severity Fixed in
1 Appending to a log saved without its last newline glued two events into one unreadable line, and both left replay silent data loss 1461c6b: the disk adapter starts a new line first, also when it finishes a stopped commit
2 Finishing a stopped commit wrote its old bytes over whatever git pull had written since data loss 1461c6b: the journal records each file's state before the commit, and recovery goes ahead only over files nobody touched; otherwise it refuses and names the journal
3 A lock older than 30 seconds was taken over while its owner was alive and still writing, so a committed write was lost and the version went backwards data loss 1461c6b: on the same machine a lock is stale only when its process is gone, and a commit checks it still holds the lock before each step
4 A teammate's fast clock put their event after later ones, so replay disagreed with the files wrong result 040a009: every write takes an id after the newest event in the month file it appends to
5 An event id that was not a ULID, such as zz-merged, sorted after everything forever, and doctor --fix reported it fixed wrong result, trusting repo content dea8d11: only ULID ids are read; a lowercase one is read as its uppercase form
6 .clara itself could be a symlink, so a cloned repo could send Clara's writes anywhere security (D15 paths) 1461c6b: a linked board folder is refused
7 A ticket file from another project (OPS-900.md on a GEN board) made the next ticket GEN-901 and showed in lists wrong result 34a8232: it stays off the board as a problem and its number is not counted
8 Creating a sprint, view or release over a file that could not be read failed with "the board changed, run it again", which never helped misleading error (C4.6) 2bb60c7: the next sprint number counts unreadable files, and a create over one names the file and clara doctor
9 A ticket whose file could not be read was reported as not existing misleading error 2bb60c7: the error quotes the parse problem and points to clara doctor

It also named parts of the brief that M1 lacked:

  • docs/FORMAT.md (C4.8). Written in 7b66ca5, and a test holds it to the code: every file kind, field and event kind the code knows is described, and nothing else.
  • docs/SECURITY-MODEL.md and test/security/ (D15). Not written in M1. The path tests lived in test/unit/storage/fs.test.ts. Taken up at the end of M2, see docs/EVIDENCE/M2.md.
  • test/perf/ (E1). The budgets run as the budgets gate from scripts/budgets.mjs; see M2.
  • C4.1's test that every operation can be reached through each door it declares could not exist before there was a door. The command line's half is in test/unit/cli/commands.test.ts (M2); MCP and REST add theirs in M3 and M4.

Checked and not reported: two versions of one ticket merged by git keep the newer side (D-031), and both stay in git history; the query parser's depth and length limits; validation of ticket ids, slugs and agent names; dependencies on missing tickets count as unmet; CRLF files; the claim race on one machine.