Spec-Kit Specification and TDD Workflow
This page documents the spec-driven development (SDD) machinery that governs how work enters this repository and how it is proven: the Spec-Kit core cycle (specify → plan → tasks → implement), the TDD extension that turns the implementation phase into a recorded red-green-refactor loop, and the artifact set that both leave behind under specs/<feature>/tdd/. It is a workflow page, not a testing-API page — for per-package test commands and the test layout, read Testing Strategy and Per-Package Commands; for the CI jobs and GYM exercises that gate master, read Continuous Integration, GYM Exercises, and Publishing.
The scope here is deliberately narrow: how a feature description becomes a specification, how a specification becomes an ordered task list whose test tasks are mandatory, how one behavior at a time is driven to green with the failure output recorded verbatim, and how a cold-context auditor later grades whether any of it actually happened.
Sources: AGENTS.md, .specify/extensions/tdd/README.md
Two Layers, One Pipeline
Section titled “Two Layers, One Pipeline”The workflow is layered. Spec-Kit core owns the documents and the review gates; the TDD extension owns the loop and the evidence. The extension deliberately does not reimplement specification or task generation — it reads their output and writes only three files inside the feature directory plus the checkboxes it earns.
flowchart TD A["/speckit.specify<br/>git.feature hook creates branch"] --> B["spec.md<br/>user stories, FR-xxx, SC-xxx"] B --> C["gate: review spec"] C --> D["/speckit.plan<br/>plan.md + Constitution Check"] D --> E["gate: review plan"] E --> F["/speckit.tasks<br/>tasks.md"] F --> G["/speckit.tdd.plan<br/>tdd/test-list.md + cycle-log baseline"] G --> H["/speckit.tdd.run<br/>mandatory before_implement hook"] H --> I["/speckit.implement<br/>only unmarked tasks remain"] I --> J["/speckit.tdd.verify<br/>tdd/verification.md verdict"] J --> K["/speckit.spec-stats.report<br/>portfolio dashboard"]Two gates in that diagram are explicit type: gate steps with approve/reject options and on_reject: abort: one after specify, one after plan. The bundled workflow declares speckit_version: ">=0.7.2" and accepts copilot, claude, or gemini integrations, while this repository runs the kimi integration with sh scripts and a - invoke separator.
Sources: workflow.yml, integration.json, init-options.json
The TDD extension contributes four commands and three hooks. The after_tasks and after_implement hooks are optional (they print an offer that can be declined); before_implement is not optional, on purpose — the extension’s own comment explains that spec-kit only waits for a hook whose optional flag is false, and an optional pre-hook would let /speckit.implement write the whole feature in the same run, which is precisely the test-after failure the hook exists to prevent.
Sources: extension.yml
Repository Layout of the Workflow
Section titled “Repository Layout of the Workflow”Everything the workflow reads and writes lives in two trees. specs/ holds per-feature documents; .specify/ holds configuration, memory, extensions, and the two sibling lanes (bugs, chores).
specs/<NNN>-<slug>/├── spec.md # spec-kit core: user stories, FR-xxx, SC-xxx├── plan.md # spec-kit core: technical context, structure, constitution check├── tasks.md # spec-kit core, reordered by /speckit.tdd.plan├── research.md / data-model.md / contracts/ / checklists/ / quickstart.md└── tdd/ ├── test-list.md # the plan: behaviors, traces, states ├── cycle-log.md # append-only evidence, one entry per cycle └── verification.md# the audit report and verdict
.specify/├── extensions.yml # installed extensions + all before_/after_ hooks├── feature.json # the active feature directory├── memory/ # constitution.md, tdd-profile.md├── scripts/bash/ # check-prerequisites.sh, create-new-feature.sh, common.sh …├── templates/ # spec/plan/tasks/checklist/constitution templates├── workflows/ # speckit/workflow.yml + workflow-registry.json├── extensions/ # tdd, git, bug, chore, gym, spec-stats, gh-triage, agent-context├── bugs/<slug>/ # assessment.md, issue.md, fix.md, test.md, tdd/└── chores/<slug>/ # assessment.md, implement.md, pr.mdOnly three extensions are recorded as installed in extensions.yml: agent-context, bug, and spec-stats. The tdd, git, chore, gym, and gh-triage directories are present on disk with their commands mirrored into every agent’s skill/command directory, but they are not in that installed: list — worth knowing before you assume a hook will fire for you.
Sources: extensions.yml, AGENTS.md
Feature Resolution: Which Feature Am I In?
Section titled “Feature Resolution: Which Feature Am I In?”Every TDD command begins by resolving the feature directory through spec-kit’s own resolver rather than a heuristic, and the rule is stated identically in all four commands: run .specify/scripts/bash/check-prerequisites.sh --json --paths-only and take FEATURE_DIR from its JSON. Resolution order is SPECIFY_FEATURE_DIRECTORY, then .specify/feature.json, and it errors when neither is set. Commands are explicitly forbidden from inferring the feature from the branch name or file timestamps, because a test list written into the wrong directory is a silent failure.
This matters more here than in a stock spec-kit repo, because feature.json in this checkout does not point into specs/ at all:
{ "feature_directory": ".specify/bugs/339-macos-useondownloadstart-is-dead"}That is the bug lane reusing the same resolver — the TDD artifacts for a fix live under .specify/bugs/<slug>/tdd/, exactly as they do for 309-macos-domexception-crash or macos-sourceframe-crash. Numbering for the feature lane is sequential (001, 002, … 018), configured in the git extension and matched by create-new-feature.sh, which skips timestamp-shaped directories when scanning for the highest existing number.
Sources: check-prerequisites.sh, common.sh, feature.json, git-config.yml, tdd.plan.md
Phase 1 — Specify: The Contract That Everything Traces To
Section titled “Phase 1 — Specify: The Contract That Everything Traces To”spec.md is generated from the mandated template, and its three id-bearing sections are what the rest of the pipeline consumes: prioritized user stories with Given/When/Then acceptance scenarios, functional requirements (FR-001…), and success criteria (SC-001…). The template insists each story be independently testable and carry a priority, and it provides an explicit [NEEDS CLARIFICATION: …] marker for requirements that are not yet decidable.
Two hooks bracket this phase. before_specify runs speckit.git.feature (non-optional) so the specification lands on its own branch; after_specify runs speckit.git.commit and then speckit.agent-context.update at priority 10, which rewrites the managed <!-- SPECKIT START --> … <!-- SPECKIT END --> section of AGENTS.md with the current plan path.
Sources: spec-template.md, spec-template.md, extensions.yml, extensions.yml, agent-context-config.yml
Phase 2 — Plan and Tasks, With the Constitution in the Loop
Section titled “Phase 2 — Plan and Tasks, With the Constitution in the Loop”plan.md follows a fixed skeleton — Summary, Technical Context, Constitution Check, Project Structure, Complexity Tracking — and that third section is the seam where project rules constrain the design before any code exists. tasks.md is generated from the stock task template, which by default treats tests as optional: “Tests are OPTIONAL - only include them if explicitly requested in the feature specification.” The TDD plan step exists largely to delete that sentence from the features it touches.
The constitution in this repo is mostly unfilled template, with one exception that is load bearing: Principle III, Test-Driven Development (NON-NEGOTIABLE). It states that a test must be observed failing for the right reason before the code that satisfies it, that the failure output is recorded in specs/<feature>/tdd/cycle-log.md, that test tasks are not optional and precede their implementation task, that tests are never weakened or filtered to reach green (with spec.md deciding which side is wrong), that every acceptance criterion has an acceptance test through the real entry point, and that refactoring happens only on green and never in the same commit as a behavior change.
Sources: plan-template.md, tasks-template.md, constitution.md
Phase 3 — TDD Setup: The Stack Profile
Section titled “Phase 3 — TDD Setup: The Stack Profile”/speckit.tdd.setup runs once per repository and produces .specify/memory/tdd-profile.md. Its governing rule is that every recorded command must have been executed successfully in this repository — no plausible guesses, no commands copied from a README. A capability that could not be verified is written as null with a reason, never as a hopeful value, because the profile’s worst failure mode is a single-test command that exits 0 while matching nothing: that turns every red into a false green.
The verification protocol has a specific two-way check for exactly that: run the single-test command against a known test name and confirm it ran that test, then run it with a name that matches nothing and confirm the runner reports zero tests rather than exiting silently. This repo passed both, and the profile records the consequence explicitly.
| Capability | Recorded value | Consequence for the loop |
|---|---|---|
single |
flutter test {file} --plain-name "{name}" |
One behavior per cycle is cheap |
file / suite |
flutter test {file} / flutter test |
Full-suite green gate per cycle (~36 s) |
coverage |
flutter test --coverage |
Corroboration only in the audit |
acceptance |
cd zikzak_inappwebview/example && flutter test integration_test/{file} -d {device} |
Outer loop needs a device |
mutation, property, watch, approval, contract |
null |
Audit falls back to deliberate mutants |
The profile also records the working-directory hazard as CRITICAL: flutter test must run inside the package that owns the test file, because there is no root pubspec to resolve against and running from the repo root is the fastest way to get a false green. It names one exemplar per test kind (disposable_pattern_test.dart for unit, types/console_message_test.dart for entity, webview_sessions_test.dart for behavioral), records that there is no mocking library and no shared helper package (inline hand-written fakes only), and forbids the loop from inventing a helpers module.
Phase 4 of setup proposes the constitution principle but applies it only with explicit approval; a declined principle is a recorded decision, not a failure.
Sources: speckit.tdd.setup.md, speckit.tdd.setup.md, tdd-profile.md, tdd-profile.md, tdd-profile.md, tdd-profile.md
Staleness warning. The profile is a snapshot, and this one has drifted: it records 10 umbrella test files / 112 tests and “no CI gating command (no
.github/workflows)”, whileAGENTS.mdstates the umbrella now has 27 files / 250 tests and that CI gatesmasterwith a 21-job matrix./speckit.tdd.planhandles this by comparingdetected_atagainstHEADand suggesting/speckit.tdd.setup refreshrather than silently trusting stale entries.
Sources: tdd-profile.md, AGENTS.md, AGENTS.md, speckit.tdd.plan.md
Phase 4 — TDD Plan: The Test List
Section titled “Phase 4 — TDD Plan: The Test List”/speckit.tdd.plan converts spec.md + plan.md into tdd/test-list.md, and its first hard rule is the one that decides whether the rest is honest: behaviors come from the specification, not from the implementation. Source is read only to place behaviors on components and to find existing tests. A list that mirrors current code cannot drive a change.
The derivation is two-tier. The outer loop gets one acceptance behavior per acceptance criterion, in spec.md order, each observable through the feature’s real entry point — the route, the CLI call, the rendered screen, the public function — because that is the only test that fails when the units are individually right and collectively wrong. The inner loop walks plan.md component by component and, for every rule, demands the happy path, both sides of every boundary (< and <= are not pinned by one test), specific error paths, invariants, and what is injected rather than reached for.
| Frontmatter field | Meaning |
|---|---|
loop |
outside-in (default) or inside-out for work with no user-visible surface |
spec_criteria |
count of acceptance criteria found in spec.md |
planned_at / updated_at |
short SHAs; the second is refreshed on refresh, the first never |
suite_baseline |
green / red / unknown at planning time |
| State | Meaning |
|---|---|
PENDING |
listed, no test yet |
RED |
failing for the right reason, evidence recorded |
GREEN |
passing, suite green, refactor not finished |
DONE |
passing, suite green, refactor done or explicitly judged unnecessary |
BASELINE |
characterization of existing behavior, green against untouched code |
BLOCKED / DROPPED |
one-line reason required; DROPPED rows are never deleted |
Behavior ids (A1, U1, …) are never reused or renumbered, because the cycle log references them. The plan step then makes the list binding in tasks.md: each behavior id is written into the task text in brackets ([U3]), the “OPTIONAL / only if tests requested” qualifiers are deleted, characterization tasks are placed before the tasks that change the code they cover, and one final task per acceptance criterion requires the outer-loop test to be green before the story counts as complete. That bracket marker is load bearing rather than decorative — /speckit.tdd.run only ticks a checkbox it can read a behavior id from, and /speckit.implement implements anything left unticked.
Sources: speckit.tdd.plan.md, speckit.tdd.plan.md, speckit.tdd.plan.md, tdd-test-list-template.md, tasks.md
Phase 5 — TDD Run: One Behavior, One Cycle
Section titled “Phase 5 — TDD Run: One Behavior, One Cycle”/speckit.tdd.run is the only command in the extension that writes tests and source. It runs all by default (because the before_implement hook invokes it with no arguments and it must drive every behavior), with next, explicit ids, outer, resume, tcr, and --no-commit as modifiers. Its preflight is strict: the profile must exist, the test list must exist, the full suite must be green before the first cycle — a red baseline is an escape hatch, not a starting condition, because no red produced afterwards could be attributed to your own change.
flowchart TD S["select one PENDING behavior"] --> W["write exactly one test<br/>imitate the profile exemplar"] W --> R{"run single-test command"} R -- "assertion failure" --> G["smallest change to green"] R -- "compile / import / fixture error" --> FX["fix the test, re-run"] FX --> R R -- "passes first run" --> M["deliberate mutant<br/>break code, expect fail, restore"] M --> G G --> F["run FULL suite"] F --> RF["refactor while green<br/>re-run after each move"] RF --> L["append cycle-log entry<br/>verbatim red command + output"] L --> T["tick tasks.md checkboxes<br/>for this behavior id"] T --> N{"more behaviors?"} N -- yes --> S N -- no --> I["/speckit.implement for unmarked tasks"]What counts as a valid red is enumerated, and so is what does not: an assertion failure with expected and actual values is valid; a broken test file, a wrong import, or an unrelated pre-existing failure is not, and each has a prescribed response. If the test passes on first run, the deliberate-mutant check decides: break the implementation in the smallest way that should violate the behavior, confirm the test fails, restore exactly, re-run the suite. A test that still passes with the mutant in place is worthless and must be rewritten.
The forbidden-shortcut list is the enforcement surface the auditor later looks for: implementation-first, weakening an assertion or widening a tolerance, deleting/skipping/filtering a failing test, assertion-free tests, tautological tests, testing private internals or exact log strings, changing the test to match the code, and broadening the run (lowered thresholds, mutation scoped away from changed files). Commit cadence is one commit per completed cycle at green, containing the test and its implementation and nothing else; structural refactors are their own commit; never commit on red, never push, never merge.
Sources: speckit.tdd.run.md, speckit.tdd.run.md, speckit.tdd.run.md, tdd-loop-playbook.md, tdd-loop-playbook.md
Phase 6 — Implement the Remainder
Section titled “Phase 6 — Implement the Remainder”Because the loop ticks the tasks it drove, /speckit.implement covers only what is left: scaffolding, configuration, wiring, and any task with no behavior marker. The run command is explicit that this handoff is safety-critical rather than bookkeeping — an unticked task the loop already drove gets implemented a second time, over freshly test-driven code. The loop deliberately leaves unmarked tasks alone and reports them by id.
Sources: speckit.tdd.run.md, speckit.tdd.run.md
Phase 7 — TDD Verify: The Cold Audit
Section titled “Phase 7 — TDD Verify: The Cold Audit”/speckit.tdd.verify exists because a loop cannot grade itself: the session that wrote the tests fills in every gap from memory. The auditor reads cold, fails closed (missing evidence is a gap, never an assumption of compliance), and never fixes what it finds — its only outputs are tdd/verification.md and a remediation section appended to tasks.md.
Three evidence sources are gathered before any judgment: the cycle log (self-reported), the git history for the feature’s commits (ordering), and the files as they stand (what is asserted today). Where they disagree, history beats the log, and the files beat both.
| Class | Criteria |
|---|---|
PROVEN |
log has the red command + output and history shows test changing in the same commit as, or before, the source |
LIKELY |
log has a red, but squashed/amended history cannot corroborate order |
TEST_AFTER |
no red recorded, or source landed earlier than its test |
NO_TEST |
behavior has no test |
NOT_APPLICABLE |
characterization baseline, green by definition |
| Verdict | Conditions |
|---|---|
PASS |
all behaviors PROVEN/LIKELY, no HIGH smells, every criterion has an end-to-end test, no survivor inside a DONE behavior |
PASS_WITH_GAPS |
no HIGH smells, no untested criterion, but weak evidence (e.g. mutation unmeasured) |
FAIL |
any HIGH smell, any TEST_AFTER/NO_TEST, any weakened existing test, any uncovered criterion, any surviving mutant in a DONE behavior |
BLOCKED |
audit could not run: no runner, red baseline unrelated to the feature, or no test list |
The highest-signal check in the whole audit is what the change did to pre-existing tests — assertions removed or loosened, a value check replaced by truthiness, a test renamed out of a filter’s reach, a skip or config exclusion added, a threshold lowered. Any of these is a FAIL on its own. Test strength is then measured, not assumed: mutation where the ecosystem has a tool, deliberate mutants on the highest-risk behaviors where it does not, with coverage used as corroboration only. A mandatory “What was not audited” section prevents a scoped report from reading as exhaustive.
Sources: speckit.tdd.verify.md, speckit.tdd.verify.md, tdd-test-quality-rubric.md, tdd-test-quality-rubric.md
What the Artifacts Actually Look Like Here
Section titled “What the Artifacts Actually Look Like Here”The repository carries TDD directories for all eighteen numbered features, but not in a uniform shape: 001–014 have the full triad (test-list.md, cycle-log.md, verification.md), 018 has a list and a log but no audit yet, and 015–017 have a cycle log only — the loop ran without a planned list. 018’s list is also not in the template shape: it is a free-form Requirement | Test entry point | Initial state table with no behavior ids, no traces, and no frontmatter, which means the tasks.md marker mechanism and the audit’s per-behavior evidence table have nothing to bind to.
| Feature | Verdict | Decisive content |
|---|---|---|
011-split-controller-domains |
PASS |
92 behaviors, 87 PROVEN, 0 HIGH smells, 6/6 criteria, 4 deliberate mutants all killed |
001, 002, 013 |
PASS_WITH_GAPS |
criteria covered, evidence weak (characterization only, mutation unmeasured) |
007, 010, 012, 014 |
FAIL |
e.g. 007: 5 of 18 behaviors NO_TEST, one HIGH smell inside a DONE behavior, one surviving mutant |
003–006, 008, 009 |
BLOCKED |
audit could not run |
002-dismiss-dialogues is the most instructive artifact set in the repo, because its test list documents a divergence finding rather than a clean trace: spec.md describes one boolean dismissDialogues implemented inline in onLoadStop, while a separate content-aware DialogueDismisser module exists but is not wired to that setting — so the acceptance behaviors trace to the inline implementation and the module’s seven green tests are recorded as BASELINE characterization, explicitly out of the acceptance trace. Its cycle log is equally honest about environment limits, recording per-platform outcomes (iOS simulator passed, macOS desktop and Android blocked by headless-WebView harness limits) instead of a single green claim.
Sources: test-list.md, cycle-log.md, verification.md, verification.md, verification.md, test-list.md, cycle-log.md
Hooks, Mirrors, and the Template Override Stack
Section titled “Hooks, Mirrors, and the Template Override Stack”The hook wiring is centralized in .specify/extensions.yml with auto_execute_hooks: true. Git hooks bracket nearly every core command (git.commit before and after clarify, plan, tasks, implement, checklist, analyze, taskstoissues, all marked optional), while agent-context.update fires after specify and plan at priority 10. Note that the git extension’s own config sets auto_commit.default: false with every per-command entry disabled, so the prompts appear but the commits do not happen unless enabled.
Every extension command is mirrored into four agent surfaces — .agents/skills/, .claude/skills/, .kimi-code/skills/ (as SKILL.md with metadata.source: tdd:commands/speckit.tdd.run.md), and .opencode/commands/ (dot-named .md) — which is why the same workflow is drivable regardless of which coding agent you use. Each TDD command also resolves its reference templates through a three-level stack, first match wins: .specify/templates/overrides/<name>.md, then .specify/presets/<preset-id>/templates/<name>.md, then the extension’s own copy. That is the sanctioned way to tune the discipline without forking the extension.
Sources: extensions.yml, git-config.yml, SKILL.md, speckit.tdd.run.md
Sibling Lanes: Bugs and Chores
Section titled “Sibling Lanes: Bugs and Chores”Bug and chore work does not use specs/; it uses .specify/bugs/<slug>/ and .specify/chores/<slug>/ with one Markdown report per stage (assessment.md, issue.md, fix.md/implement.md, pr.md, test.md). The bug extension declares a dependency on all four speckit.tdd.* commands and, when tdd_enabled is true (the default), drives fix and verify through the same red-green-refactor loop — which is why several bug directories contain their own tdd/ folder. Chores are constitution-aware by design: chore.assess consults the constitution and refuses approaches that violate its principles.
Sources: bug/extension.yml, bug/README.md, chore/README.md
Portfolio View
Section titled “Portfolio View”Once features carry tdd/ artifacts, the spec-stats extension renders them as a dashboard: stage, progress, health, plus a TDD Deep Stats table (A, U, char, DONE, loop, tasks.md) per feature. Only speckit.spec-stats.runs executes anything; report, open, and not-green are read-only scans, and not-green quotes the evidence line from the feature’s cycle-log.md rather than summarizing it.
Sources: spec-stats/README.md, speckit.spec-stats.not-green.md
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Action |
|---|---|---|
flutter test green but nothing ran |
wrong cwd, or a no-match filter |
run inside the owning package; a no-match exits 79 here, so a silent pass means the wrong directory |
/speckit.tdd.plan refuses to start |
.specify/memory/tdd-profile.md missing |
run /speckit.tdd.setup first; commands must not guess |
| Loop stops immediately | red baseline suite | fix or record the pre-existing reds; a loop cannot start on red |
/speckit.implement re-writes tested code |
behavior id missing from the task text, so the checkbox was never ticked | add [U#] markers via /speckit.tdd.plan refresh |
Audit returns BLOCKED |
no test list, no runner, or unrelated red baseline | plan the feature, or fix the baseline, then re-audit |
| Commands resolve the wrong feature | feature.json points elsewhere (currently a bug slug) |
set SPECIFY_FEATURE_DIRECTORY or update feature.json |
| Profile contradicts reality | snapshot drift | /speckit.tdd.setup refresh and read the diff it reports |
Sources: tdd-profile.md, tdd-profile.md, speckit.tdd.plan.md, tdd-loop-playbook.md
Where to Go Next
Section titled “Where to Go Next”The workflow page hands off in three directions. For the commands, matchers, per-package layouts, and the inline-fake conventions the profile encodes, read Testing Strategy and Per-Package Commands. For the gates that actually block a merge — the CI matrix, the GYM exercises under zikzak_inappwebview/.gym/, and the publish scripts — read Continuous Integration, GYM Exercises, and Publishing. And because several FAIL verdicts in this repo turn on lifecycle and disposal behavior (007’s eviction ordering, 012’s integration coverage, 013’s dispose standardization), the domain pages Disposal Lifecycle and KeepAlive Patterns and The Platform Interface: The Contract Seam explain the code those tests are trying to pin; Two-Tier Core/Module Split and the Grep Gate covers the structural gate that must stay green after any refactor the loop performs.