This guide is for developers and tech leads handing bounded TypeScript work to a coding agent. You need Node 22.12 or later and a local directory; no paid code generator is required.
An acceptance criterion should help someone reject a wrong implementation. “Make task selection work” gives an agent room to choose behavior nobody asked for. A checkable contract names the input, expected output, constraints and explicit exclusions.
The book develops the continuous ticket→verified-PR walkthrough. The snippets below come from a small, runnable teaching example that the project keeps under test, so they stay checkable without importing private manuscript text.
Hypothetical arc (labeled, not a reported incident)
Situation: A backlog item asks to return only “ready” tasks from a list another step already ordered.
Desire: The agent delivers a green test run quickly.
Conflict: The agent sorts ready tasks alphabetically because that looks tidy.
Change: Acceptance criteria require input order and a test that fails when sorting is added.
Result: The wrong sort is rejected before human review; broader repository gates still apply separately.
This frame follows Tim Runia’s five-line story method. Alden Ingram is a pseudonym; do not read the above as a production case or testimonial.
Weak versus improved criteria
ClearSpec (retrieved 2026-10-11) argues that human-style acceptance criteria leave agents guessing. Cited as contrast only; Alden Ingram has no affiliation with ClearSpec and does not endorse its product.
| Aspect | Weak instruction | Improved contract |
|---|---|---|
| Trigger | “Return the ready tasks.” | Given a readonly array of { id, ready } tasks, include only rows where ready is true. |
| Output | Unspecified order | Preserve caller order; for C-3 ready, B-2 not ready, A-1 ready, IDs must be C-3, A-1. |
| Verification | “Add tests if needed.” | Name the command (node --experimental-strip-types --test check.mjs) and assertions that fail on sorting. |
| Exclusions | Silent | No sorting, deduplication, persistence, HTTP endpoint or UI. |
| Edge case | Omitted | Empty input → empty array; input array and objects unchanged. |
Hypothetical scope drift (labeled): If the ticket said “users can sign in” without exclusions, an agent might add password reset or OAuth. Improved criteria would name the auth path, expected error messages and forbidden features (for example “do not add registration”). That scenario is illustrative; it is not evidence of a reader’s production failure.
Start with a bounded task
This is a purpose-built teaching example, not a production case. We want a TypeScript function that selects tasks marked ready. The caller’s order matters: an earlier step has already arranged the list.
The weak instruction is: “Return the ready tasks.” A function that filters and then sorts alphabetically could look reasonable. That extra sort would still be wrong for this caller.
The stronger contract is:
- Given a readonly array of tasks with
idandready, include only tasks whosereadyvalue istrue. - Preserve their order in the input. For
C-3 ready,B-2 not ready,A-1 ready, the selected IDs must beC-3, A-1. - Leave the supplied array and objects unchanged. Produce a new array; deep-copying task objects is not required.
- For an empty input, produce an empty array.
- Do not add sorting, deduplication, persistence, a network endpoint or UI.
Each sentence either describes observable behavior or closes a boundary. There is no general claim that longer prompts produce better code.
Give the check a result that matters
Save this as select-ready-tasks.ts in a new local directory:
type Task = { id: string; ready: boolean };
export function selectReadyTasks(tasks: readonly Task[]): Task[] {
return tasks.filter((task) => task.ready);
}
Save the following as check.mjs beside it. Use Node 22.12 or later and run node --experimental-strip-types --test check.mjs.
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { selectReadyTasks } from './select-ready-tasks.ts';
test('ready tasks keep the caller order', () => {
const tasks = Object.freeze([
Object.freeze({ id: 'C-3', ready: true }),
Object.freeze({ id: 'B-2', ready: false }),
Object.freeze({ id: 'A-1', ready: true }),
]);
const selected = selectReadyTasks(tasks);
assert.deepEqual(selected.map(task => task.id), ['C-3', 'A-1']);
assert.deepEqual(tasks.map(task => task.id), ['C-3', 'B-2', 'A-1']);
assert.notEqual(selected, tasks);
});
test('an empty list stays empty', () => {
assert.deepEqual(selectReadyTasks([]), []);
});
The first assertion can detect unauthorized sorting. Frozen inputs also expose attempts to modify this supplied array or these objects during the call. The tests do not prove every possible input is valid, runtime type safety or that future callers will leave the shared task objects alone.
For a new implementation, begin with these checks and a function body that does not satisfy them yet. Confirm the failure is about the expected behavior before asking the agent to implement it.
From the repository root, run both checks:
node --experimental-strip-types --test examples/pr-evidence/check.mjsmust exit 0.PR_EXAMPLE_VARIANT=plausible node --experimental-strip-types --test examples/pr-evidence/check.mjsmust exit nonzero and report an order assertion failure;examples/pr-evidence/plausible.tsholds that deliberately wrong variant.
Practical cases to rehearse before handoff
| Case | What to write in the ticket | What a reviewer should see |
|---|---|---|
| Greenfield function | Full contract table above plus file paths | Failing test first, then minimal implementation |
| Agent “improvement” | Restate “preserve input order” in exclusions | Diff shows no .sort( on the return path |
| Empty backlog slice | Explicit empty-input row in AC | Test named for empty input, not only happy path |
| Repository gates | List commands the repo actually runs (for example pnpm quality:fast on this site) |
Logs attached; gaps called out if a gate could not run |
Check the boundary as well as the answer
Count-only assertions would accept both C-3, A-1 and A-1, C-3. Checking the actual IDs and order makes this particular criterion falsifiable. A repository’s existing typecheck, lint and integration checks still apply; this small test does not replace them.
An agent handoff can now name the two files, the contract, the command and the excluded changes. If a product decision is still missing, record the question instead of allowing a plausible default to become the requirement.
Continue with verifying an AI-generated pull request and the review checklist.