# A spec without a harness is a document nobody enforces

> Source: <https://dev.to/speccoding/a-spec-without-a-harness-is-a-document-nobody-enforces-39c7>
> Published: 2026-12-01 08:06:30+00:00

**Recommendation:** Add a spec-gate CI check that fails pull requests touching files outside the spec's allowed list or missing a test for each AC-n criterion, using grep -w to avoid AC-1 matching AC-10.
More in the playbook "Working with AI coding agents": <https://wpnews.pro/playbooks/coding-agents>

Two terms keep getting mixed up in AI coding: spec-driven development and harness engineering. They answer different questions. A spec decides what one change must do before the agent starts. A harness is everything around the agent except the model: what it reads, what it may touch, which checks run on its output, and what happens when one fails.

Teams that let agents write real code end up needing both, and each one fails in a predictable way without the other.

Birgitta Böckeler's article on martinfowler.com defines a harness as "everything in an AI agent except the model itself". The term took off in February 2026, when OpenAI's Ryan Lopopolo described a five-month experiment in which a small team shipped an internal product with zero manually written lines: about a million lines and roughly 1,500 merged pull requests. The engineers' job, in the post's words, became "to design environments, specify intent, and build feedback loops that allow Codex agents to do reliable work."

Two ideas from that post matter most here:

|  | Spec-driven development | Harness engineering | 
|---|---|---|
| Question it answers | What must this change do? | How do we make any change trustworthy? | 
| Scope | One change or feature | The whole repository, for its whole life | 
| Main artifacts | `spec.md` ,`tasks.md` , acceptance criteria | `AGENTS.md` , linters, structural tests, test harness, CI | 
| Changes when | Every new feature | The same failure happens twice | 
| Failure if missing | People argue about intended behaviour in code review | People agree on the behaviour but cannot prove it cheaply | 

Böckeler splits a harness into **guides**, which steer the agent before it acts, and **sensors**, which observe after it acts so it can correct itself. A functional spec is on her list as a guide. It is the only guide that changes with every feature, which makes it the most important one for behaviour.

When you write a section of the spec, decide which harness control it feeds:

| Spec section | Harness control | 
|---|---|
| Context, goal, non-goals | Linked from `AGENTS.md` so the agent reads it first | 
| Allowed files | CI fails if the diff touches anything else | 
| Acceptance criteria AC-1…n | Each has a test that names it; CI fails if one is missing | 
| Edge cases | Fixtures and factory states that reproduce them | 
| API contract | Contract tests generated from the OpenAPI document | 
| Rollback | A feature flag exists and defaults off | 

The two rows that catch the most agent mistakes, allowed files and acceptance criteria, fit in one short script. It reads the spec, fails when the diff leaves the allowed list, and fails when a criterion has no test that mentions it. We ran it against a sample repository on bash 3.2, the version macOS ships:

``` bash
#!/usr/bin/env bash
# Usage: scripts/spec-gate.sh <change-name> [base-ref]
# Fails if the diff leaves the spec's allowed files, or an AC has no test.
set -euo pipefail
spec="specs/active/$1/spec.md"
base="${2:-origin/main}"
status=0

allowed=$(sed -n '/^## Allowed files/,/^## /p' "$spec" | sed -n 's/^- //p')
while read -r file; do
  grep -qxF "$file" <<<"$allowed" || { echo "out of scope: $file"; status=1; }
done < <(git diff --name-only "$base"...HEAD)

for ac in $(grep -o 'AC-[0-9]\+' "$spec" | sort -u); do
  grep -rqw -- "$ac" tests/ || { echo "no test mentions $ac"; status=1; }
done

exit "$status"
```

It expects the spec to carry an `## Allowed files` list of exact paths and criteria numbered `AC-1`, `AC-2`, and so on. The `-w` flag matters: without it, a test named after `AC-10` would satisfy `AC-1`. As a pull request check, with the branch name used as the change folder:

```
name: spec-gate
on: pull_request
jobs:
  gate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - run: scripts/spec-gate.sh "$GITHUB_HEAD_REF" "origin/$GITHUB_BASE_REF"
```

It does not prove the tests are good. It proves the agent stayed inside the boundary and did not skip a criterion.

Take "retry refunds when the payment gateway times out". The spec is short:

```
## Acceptance
- AC-1: a gateway timeout retries once with the same idempotency key
- AC-2: a second timeout leaves the refund pending, no duplicate refund_id
- AC-3: every attempt writes an audit event

## Allowed files
- src/billing/refund-worker.ts
- tests/refund-worker.test.ts
- specs/active/refund-retry/evidence.md
```

This is the kind of failure the harness is for. The agent writes a plausible retry loop and a test that mocks the gateway to succeed on the second call. The test passes, AC-2 is never exercised, and the agent adds a helper to `src/billing/ledger.ts` because it seemed tidy. Without a harness, review catches some of that, late.

With a harness, the same run hits three sensors before a human looks. The scope gate flags `ledger.ts`. The AC check reports that no test mentions AC-2. And the gateway mock is part of the test harness rather than something each test improvises, so it already has a "times out twice" state and the missing test costs the agent one line.

**A spec without a harness** is a document nobody enforces. The agent mostly follows it and drifts at the edges: an extra field, a refactor outside scope, a criterion quietly dropped. Each of those is found in human review, the most expensive place to find it and the one that scales worst as agents open more pull requests. A note in OpenSpec's community schema catalog says it plainly: "OpenSpec only checks that artifacts exist."

**A harness without a spec** is a fast, green pipeline pointed at the wrong target. Lint passes, the tests are thorough, and the feature does something nobody asked for. Anthropic's March 2026 post on harness design found a related trap: "When asked to evaluate work they've produced, agents tend to respond by confidently praising the work." Its fix was a separate evaluator grading against criteria agreed before coding started, which is a spec by another name.

For a team that already writes specs, in order of return:

`AGENTS.md` a short map to where specs, architecture notes and commands live.
The full article covers the prompt, context, harness and loop layers, the test-harness layers in more detail, and links to every source quoted here: [Harness engineering vs spec-driven development](https://spec-coding.dev/blog/harness-engineering-vs-spec-driven-development).
