specgate/docs v1.8.0

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.


One change, one pull request: what the author does, what the gate does, what the reviewer reads Three lanes, time running down: the author, the gate and the reviewer. One, the author proposes the change with specgate propose invoices-pdf, then writes discover.md, which says why, and the delta, each requirement with its kind. Two, a person approves it at a terminal with specgate change approve invoices-pdf; an agent cannot. Approval writes the feature files. Three, the author writes the test, mentioning REQ-007 and SCN-007a, which is the link, then the code. Four, the author delivers it with specgate apply, which is refused while no test names the requirement; the gate runs, and the requirement is Implemented only when it is green. When it is red nothing is written, and the author fixes the code and runs apply again. Five, the author archives the change with specgate archive invoices-pdf, runs check, commits everything including traceability.md, and opens the pull request. In CI, the gate runs specgate check on every pull request. When it is green, six, the reviewer reads what no tool can judge: is the requirement one obligation, does the scenario use real values for this behaviour, does the test assert what the Then says, and discover.md says why; the reviewer skips traceability.md, which is generated. Seven, merge: the spec and the code arrive together. The gate blocks a merge only when the repository requires it: on GitHub, the checks spec-gate (ubuntu-latest), (macos-latest) and (windows-latest). AUTHOR THE GATE REVIEWER 1Propose the change specgate propose invoices-pdf then write discover.md and the delta (kind=…) 2A person approves specgate change approve invoices-pdf at a terminal; writes the feature files 3The test, then the code // REQ-007 SCN-007a — … the test mentions it: that is the link 4Deliver it specgate apply refused while no test names it 5Archive, then open the PR specgate archive invoices-pdf check, commit all — traceability.md too The gate Implemented only when green CI specgate check on every PR 6Read what no tool can judge the requirement: one obligation? the scenario: real values, this behaviour? the test: does it assert the Then? discover.md: why the change exists skip traceability.md — it is generated 7Merge the spec and the code arrive together waits for a green gate green red: nothing written opens the PR The gate blocks a merge only when the repository requires it: require spec-gate (ubuntu-latest), (macos-latest), (windows-latest).
The author proposes, gets a person's approval and delivers through the gate; CI runs the same gate, and the reviewer reads only what no tool can judge.

Once per repository#

bash
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:

  1. Require a pull request before merging.
  2. Require status checks to pass before merging, then search for and select the checks of the job specgate ci init wrote. It runs on three systems, so GitHub lists spec-gate (ubuntu-latest), spec-gate (macos-latest) and spec-gate (windows-latest) — select all three (the --minimal job is plain spec-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#

bash
specgate status                     # what is open, and the next command
specgate propose invoices-pdf       # discover, design, tasks, a delta, REQ ids reserved

propose opens docs/specs/changes/invoices-pdf/ with change.yaml, discover.md, design.md, tasks.md and the delta. Write two things in it:

  1. discover.md — why the change exists: who has the problem, the use case and its acceptance criteria. The reviewer reads it first; design.md says how, tasks.md the steps.
  2. The delta, specs/invoices-pdf/spec.md — each requirement as ### Requirement: REQ-007 — <name>, one obligation with SHALL or MUST, a scenario of plain - GIVEN / - WHEN / - THEN bullets with real values, not "valid data", and a trace comment with its kind: <!-- specgate:trace kind=functional … --> (or non-functional, business-rule). Approval refuses a requirement with no kind= (approve_blocked). The template propose wrote is not judged yet — check says delta not written yet, not judged until it is and 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:

bash
specgate change approve invoices-pdf   # --layer discover|design|tasks for one layer

Approval 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:

js
// 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:

bash
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 runs

While 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 branch feature/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 with specgate 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:

ReadAsk
The ## REQ-NNN section in spec.mdIs it one obligation? Could two people test it and agree? Is it what the ticket asked for?
The scenarioDo 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-NNNDoes 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 statusdiscover.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#

text
✖  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#

text
  ✖  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#

text
✖  --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#

text
✖  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: ." with the note <code>specgate new</code> left below it. Write the real obligation and delete the note. A Draft owes nothing yet.</p> <h3 id="check-tests-failed-done-tests-failed"><code>check_tests_failed</code> / <code>done_tests_failed</code><a class="anchor" href="#check-tests-failed-done-tests-failed" aria-label="Link to this section">#</a></h3> <p>The project's tests failed. These run only when a test command is configured (<code>--test-cmd "npm test"</code>, or <code>specgate config set test_cmd "npm test"</code> once). Without one, <code>check</code> and <code>apply</code> say they checked the specification and not the code — read that warning as "nothing ran", not as a pass.</p> <h3 id="apply-no-test"><code>apply_no_test</code><a class="anchor" href="#apply-no-test" aria-label="Link to this section">#</a></h3> <p>No test mentions the requirement yet. Name it in the test that covers it (<code>REQ-007</code>, and its scenario <code>SCN-007a</code>), then run <code>specgate apply REQ-007</code> again.</p> <h3 id="done-validate-failed"><code>done_validate_failed</code><a class="anchor" href="#done-validate-failed" aria-label="Link to this section">#</a></h3> <p><code>apply</code> ran the gate and it failed; the output above it says why. Nothing was written. Fix it and run <code>apply</code> again. <code>apply --no-check</code> writes the status anyway — keep it for the rare case you know the gate is wrong, and say so in the PR.</p> <h3 id="archive-requirements-pending"><code>archive_requirements_pending</code><a class="anchor" href="#archive-requirements-pending" aria-label="Link to this section">#</a></h3> <p><code>archive</code> found a requirement of the change that is not <code>Implemented</code>. Run the <code>specgate apply REQ-…</code> it names; <code>--force</code> does not skip this.</p> <hr> <h2 id="the-agreement-to-make-as-a-team">The agreement to make as a team<a class="anchor" href="#the-agreement-to-make-as-a-team" aria-label="Link to this section">#</a></h2> <p>Three sentences are enough. Put them in the repository's contributing guide:</p> <ol> <li>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.</li> <li><code>specgate check</code> is green before review is requested.</li> <li>The reviewer reads the requirement, the scenario and the test — not the matrix.</li> </ol> <hr> <h2 id="next">Next<a class="anchor" href="#next" aria-label="Link to this section">#</a></h2> <ul> <li><a href="commands.html">The four verbs, and the rest</a></li> <li><a href="writing-specs.html">Write a scenario that is worth testing</a></li> <li><a href="reviewing-changes.html">Change a requirement that already shipped</a></li> <li><a href="validating.html">What the gate checks, flag by flag</a></li> </ul> </article> <nav class="pager" aria-label="Neighbouring pages"><a class="pager__prev" href="reverse.html"><span>Previous</span>Specify a system that already runs</a><a class="pager__next" href="reviewing-changes.html"><span>Next</span>Change a shipped requirement</a></nav> <footer class="page-foot"> <p class="page-foot__ask">Was this page useful?</p> <a href="https://github.com/rsaglobaltech/specgate/edit/main/docs/first-pr.md" target="_blank" rel="noreferrer">Edit this page</a> <span aria-hidden="true">·</span> <a href="https://github.com/rsaglobaltech/specgate/issues/new" target="_blank" rel="noreferrer">Something wrong? Open an issue</a> </footer> </main> <div class="rail"><nav class="toc" aria-label="On this page"><h2>On this page</h2><ul><li class="toc__l2"><a href="#once-per-repository">Once per repository</a></li><li class="toc__l3"><a href="#make-the-gate-a-required-check">Make the gate a required check</a></li><li class="toc__l2"><a href="#the-author-one-change-one-pull-request">The author: one change, one pull request</a></li><li class="toc__l3"><a href="#from-a-ticket">From a ticket</a></li><li class="toc__l3"><a href="#fixes-and-refactors">Fixes and refactors</a></li><li class="toc__l2"><a href="#the-reviewer-what-to-read-what-to-skip">The reviewer: what to read, what to skip</a></li><li class="toc__l2"><a href="#when-check-fails">When check fails</a></li><li class="toc__l3"><a href="#scenario-placeholder-step">scenario_placeholder_step</a></li><li class="toc__l3"><a href="#matrix-stale">matrix_stale</a></li><li class="toc__l3"><a href="#tdd-1-delivered-without-a-test">[TDD-1] — delivered without a test</a></li><li class="toc__l3"><a href="#declared-artifact-missing">declared_artifact_missing</a></li><li class="toc__l3"><a href="#requirement-template-obligation">requirement_template_obligation</a></li><li class="toc__l3"><a href="#check-tests-failed-done-tests-failed">check_tests_failed / done_tests_failed</a></li><li class="toc__l3"><a href="#apply-no-test">apply_no_test</a></li><li class="toc__l3"><a href="#done-validate-failed">done_validate_failed</a></li><li class="toc__l3"><a href="#archive-requirements-pending">archive_requirements_pending</a></li><li class="toc__l2"><a href="#the-agreement-to-make-as-a-team">The agreement to make as a team</a></li><li class="toc__l2"><a href="#next">Next</a></li></ul></nav></div> </div> <div class="palette" id="palette" hidden> <div class="palette__scrim" data-close="1"></div> <div class="palette__box" role="dialog" aria-modal="true" aria-label="Search documentation"> <div class="palette__field"> <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg> <input type="search" id="palette-input" placeholder="Search the documentation…" autocomplete="off" spellcheck="false" aria-label="Search documentation" aria-controls="results" aria-expanded="true"> <kbd class="palette__esc">Esc</kbd> </div> <div class="palette__results" id="results" role="listbox" aria-label="Results"></div> <p class="palette__hint"> <kbd>↑</kbd><kbd>↓</kbd> to navigate · <kbd>↵</kbd> to open · <kbd>Esc</kbd> to close </p> </div> </div> <script src="assets/docs.js" defer></script> </body> </html>