Your team's first pull request with Specgate#
For the people who write the pull request and for the people who review it.
It assumes the repository has already run specgate init; if it has not, the
Quickstart gets it there in ten minutes.
Once per repository#
specgate init # adopts the existing code; writes spec.md, the matrix and
# the gate as a CI job — for the CI .github/, .gitlab-ci.yml, …
# or the origin remote shows; GitHub when nothing does
specgate ci status # what the gate checks, and what it lacks
git add -A && git commit -m "chore: adopt Specgate"The CI job runs specgate check on every pull request — the specification,
then your tests — after setting up what the project needs: a JDK for a
pom.xml or build.gradle, npm ci for a lockfile. It is the check you run
on your machine, so a green there is a green in CI. It runs the test_cmd you
configured (specgate config set test_cmd …), or the one it detects; with
neither yet, check validates the specification, says the test command is not
configured and how to set it, and passes.
Make the gate a required check#
A red CI job only blocks a merge when the repository requires it. On GitHub,
open Settings → Branches, add a protection rule for the branch pull
requests target (main, and develop if you use it), and turn on:
- Require a pull request before merging.
- Require status checks to pass before merging, then search for and
select the checks of the job
specgate ci initwrote. It runs on three systems, so GitHub listsspec-gate (ubuntu-latest),spec-gate (macos-latest)andspec-gate (windows-latest)— select all three (the--minimaljob is plainspec-gate). They appear in the list once the job has run on one pull request.
GitLab (protected branches, "Pipelines must succeed") and Azure DevOps (a build validation branch policy) have the same setting. Without it, a pull request can be merged while the gate is red.
The author: one change, one pull request#
specgate status # what is open, and the next command
specgate propose invoices-pdf # discover, design, tasks, a delta, REQ ids reservedpropose opens docs/specs/changes/invoices-pdf/ with change.yaml,
discover.md, design.md, tasks.md and the delta. Write two things in it:
discover.md— why the change exists: who has the problem, the use case and its acceptance criteria. The reviewer reads it first;design.mdsays how,tasks.mdthe steps.- The delta,
specs/invoices-pdf/spec.md— each requirement as### Requirement: REQ-007 — <name>, one obligation withSHALLorMUST, a scenario of plain- GIVEN/- WHEN/- THENbullets with real values, not "valid data", and a trace comment with its kind:<!-- specgate:trace kind=functional … -->(ornon-functional,business-rule). Approval refuses a requirement with nokind=(approve_blocked). The templateproposewrote is not judged yet —checksaysdelta not written yet, not judged until it isand passes; once you start writing it, a step that still has its<placeholder>fails (scenario_steps_unwritten).
Leave docs/specs/traceability.md alone. It is generated.
Then a person approves the change, in a terminal (an agent cannot:
approve_needs_person), or in the studio's Review:
specgate change approve invoices-pdf # --layer discover|design|tasks for one layerApproval writes the change's feature files (features/…), its scenarios
ready to run before any code. apply refuses a change nobody approved
(change_not_approved), and a requirement edited after approval fails the
gate (approved_requirement_changed) until it is approved again.
Then write the test, and mention the requirement in it. The mention is the link; there is nothing else to declare:
// REQ-007 SCN-007a — customers download invoices as PDF
test("a paid invoice downloads as a PDF", () => {
/* … */
});Write the code, then deliver the requirement and close the change:
specgate apply # the next requirement: refused while no test names it,
# Implemented only when the gate passes
specgate archive invoices-pdf # every requirement Implemented: merged into the specs
specgate check # the whole gate, the one CI runsWhile the change is open its requirements already count: status lists
them, apply judges the project as it will be after archive and writes the
status in the delta. archive refuses while one is still pending, naming the
specgate apply REQ-… to run. So the spec and the code merge together, in
this pull request, after the gate passed.
Commit everything approve, archive and check touched — the change folder
moved to docs/specs/changes/archive/, the capability spec, the feature file,
the tests, the code and docs/specs/traceability.md. A matrix left behind
makes a noisy diff on the next pull request (see matrix_stale below).
A requirement too small for a change: specgate new "<title>" writes it
straight into spec.md with a scenario to fill in, and specgate apply REQ-007 delivers it the same way.
From a ticket#
When the work is a Jira story, the same pull request starts from the ticket. The differences:
- Open the change with
specgate propose --from-ticket KAN-13. It creates and pushes the branchfeature/KAN-13-…. - Start every commit message with the key:
KAN-13 REQ-151: normalize plates. - Run
specgate archive <change-id>on the branch, commit, then open the pull request withspecgate alm pr <change-id>. Archive comes first, so the spec and the code reach review together.
The setup and the full loop are in From a Jira ticket.
Fixes and refactors#
A bugfix or a refactor that does not change contracted behaviour needs no new requirement. The gate runs on every pull request, but it only asks for what a delivered requirement owes; a PR that adds none owes nothing new.
If the fix changes what a delivered requirement promises, change its
spec.md section and scenario in the same PR. For a larger change to
behaviour that already shipped, use a change.
The reviewer: what to read, what to skip#
The gate already proved the mechanical part: every delivered requirement has a scenario, the scenario has real steps, a test names it, and the files the matrix points at exist. Do not re-check that by hand. Spend the review on what no tool can judge:
| Read | Ask |
|---|---|
The ## REQ-NNN section in spec.md | Is it one obligation? Could two people test it and agree? Is it what the ticket asked for? |
| The scenario | Do Given / When / Then describe this behaviour with real values, or a generic happy path? Is the interesting edge case missing? |
The test that mentions REQ-NNN | Does it assert what the scenario's Then says — or only that nothing throws? A test that mentions the ID and checks nothing passes the gate. |
| The discover and the status | discover.md says why. Each requirement is Implemented — archive would not have run otherwise — and its code is in this PR. |
Skip docs/specs/traceability.md. It is generated from the files above —
check, locally and in CI, regenerates it before it judges — so a diff there
is a consequence, not a decision.
The one thing the gate cannot catch is a test that names a requirement and does not test it. That is the reviewer's job, and it is the most valuable five minutes of the review.
When check fails#
Every failure says what is wrong and how to fix it, and most carry a code in brackets you can search for. The ones a first PR meets:
scenario_placeholder_step#
✖ features/invoices.feature:4 unfilled placeholder in "given <the state before the action>" … [scenario_placeholder_step]A feature file still has the <placeholders> new wrote. A Draft requirement
may keep them; one being delivered may not, because Cucumber reports a
scenario of placeholders as 0 steps · exit 0. Write the real steps.
In a change's delta the same problem is scenario_steps_unwritten, and it
fails check as soon as the change is open (check_change_invalid): write the
scenario before you push the change.
matrix_stale#
✖ docs/specs/traceability.md no longer matches spec.md, the feature tags and the tests.
Run `specgate matrix` and commit the result — `specgate check` does it for you.Only from specgate validate run on its own: a test or a tag changed and the
regenerated matrix was not committed. specgate check — what the CI job
specgate ci init wrote runs — regenerates the matrix first and does not fail
on it. Run specgate check locally and commit traceability.md.
[TDD-1] — delivered without a test#
✖ --strict-tdd violations detected:
[TDD-1] Test artifact is TBD but status is 'Implemented' (scenario: SCN-007a)
TDD-1: Write a test that mentions the requirement (REQ-NNN) — that is the link; …check reports it under validate --strict and fails with
check_validate_failed. The requirement is past Draft and no test mentions
it — usually the test was renamed or deleted. Mention REQ-007 in the test
that covers it, or set status=Draft back in its specgate:trace comment.
declared_artifact_missing#
✖ docs/specs/traceability.md REQ-007's test artifact `test/invoice.test.js` does not exist. [declared_artifact_missing]A file the requirement points at explicitly is gone — a path written in its
specgate:trace comment (test='…', artifact='…'), or in a hand-kept matrix.
Restore it, or fix the path. A test linked only by mentioning the requirement
does not produce this: delete that test and you get [TDD-1] instead.
requirement_template_obligation#
The requirement claims delivery while its ## REQ-NNN section still says
"The system MUST satisfy:
specgate new left below it. Write
the real obligation and delete the note. A Draft owes nothing yet.
check_tests_failed / done_tests_failed#
The project's tests failed. These run only when a test command is configured
(--test-cmd "npm test", or specgate config set test_cmd "npm test" once). Without
one, check and apply say they checked the specification and not the code —
read that warning as "nothing ran", not as a pass.
apply_no_test#
No test mentions the requirement yet. Name it in the test that covers it
(REQ-007, and its scenario SCN-007a), then run specgate apply REQ-007
again.
done_validate_failed#
apply ran the gate and it failed; the output above it says why. Nothing was
written. Fix it and run apply again. apply --no-check writes the status
anyway — keep it for the rare case you know the gate is wrong, and say so in
the PR.
archive_requirements_pending#
archive found a requirement of the change that is not Implemented. Run
the specgate apply REQ-… it names; --force does not skip this.
The agreement to make as a team#
Three sentences are enough. Put them in the repository's contributing guide:
- A pull request that delivers behaviour carries its requirement, its scenario and a test that mentions it — as a change, archived in the same pull request.
specgate checkis green before review is requested.- The reviewer reads the requirement, the scenario and the test — not the matrix.