specgate/docs v1.8.0

A faster gate#

The gate costs what your test suite costs, and the suite grows with every requirement — while apply runs the gate once per requirement. This page is the three ways specgate check costs less: running only what the change touches, not running again what passed on the same code, and running the architecture check beside the tests.

You need: a project in git where specgate check already passes (Validating).

What specgate check --affected runs, and when it runs everything specgate check --affected starts from the files changed since the base: --base, else SPECGATE_BASE, else origin's default branch, counting uncommitted and untracked files. From them it finds the touched requirements: those whose spec, feature, code or test changed, found through the traceability matrix and, in JavaScript and TypeScript, the relative imports. Their tests run, passed to the test command as {files} in test_cmd_affected. A test that already passed on the same code is not run again: it comes from the cache and is listed under selection.cached. When it cannot say what the change needs, it runs the whole suite and says why under selection.reason: a change to package.json, a lockfile, harness.config.yaml, a tsconfig or build configuration, or a file matching a full_on: glob, or a changed file that nothing links to. check --ci always runs the whole suite: it ignores --affected (affected_ignored_ci) and never uses the cache. check with no flag runs the whole suite too, and --no-cache runs every selected test. SPECGATE CHECK --AFFECTED — ONLY WHAT THE CHANGE TOUCHES Changed since base --base · SPECGATE_BASE or origin's default + uncommitted, untracked Touched requirements spec, feature, code or test changed — found by the matrix and imports Their tests run as {files} in test_cmd_affected From the cache passed on the same code: not run again selection.cached Runs the whole suite — and says why package.json · a lockfile · harness.config.yaml a tsconfig or build config · a full_on: glob a file nothing links to · in selection.reason --ci runs everything, always --affected is ignored: affected_ignored_ci and the cache is never used it cannot tell what the change needs specgate check with no flag runs the whole suite too; --no-cache runs every selected test.
--affected runs only the tests of the requirements a change touches, skips the ones that already passed on the same code, and runs the whole suite, saying why, whenever it cannot tell.

Run only what the change touches#

check --affected runs the tests of what changed since the base branch — --base <ref>, else SPECGATE_BASE, else origin's default branch, main, master or develop — counting uncommitted and untracked files:

bash
specgate config set test_cmd_affected "npx vitest run {files}"
specgate check --affected
  • A requirement is touched when a changed line of a spec falls in its section or names it, when its feature file changed, or when a code or test file the matrix links to it changed.
  • The tests that run are the ones the matrix links to the touched requirements, every changed test, and — in JavaScript and TypeScript — the tests whose relative imports reach a changed file.
  • They go to the test command as {files}, each quoted for your shell; {req} is the requirement, when exactly one is touched. test_cmd_affected: is the command --affected and apply use, so test_cmd stays the whole suite. A command with neither placeholder runs whole, and the finding affected_needs_files says how to add {files}.
  • When apply ran the whole suite for one requirement and it took two minutes or more, the delivery says so, with the config set test_cmd_affected line built from your own command.

When it runs everything#

It runs the whole suite instead, and says why under selection.reason, whenever it cannot say what the change needs:

  • package.json, a lockfile, harness.config.yaml, a tsconfig, a build or runner configuration (pom.xml, build.gradle, pyproject.toml, go.mod, jest.config.js, …), or a file matching a glob under full_on: changed;
  • a changed or removed file is linked to nothing — no requirement, test or import;
  • nothing changed, no base branch was found, or what changed has no test.

A test that passed is not run again#

A test file that passed under --affected is not run again while its content, the files its imports reach, the code the matrix links to its requirements, the test command and the lockfiles are unchanged; the answer lists it under selection.cached. A test that is not JavaScript or TypeScript, whose imports cannot all be followed, or that reaches the file system, a process or the network is re-run on any change to the project's source. The record is kept in the git folder, beside the last gate result. --no-cache runs everything selected; a failing run forgets what it ran.

Where the whole suite still runs#

check with no flag runs the whole suite, as before, and check --ci always does — with --affected too, which it ignores (affected_ignored_ci) — and never uses the cache. apply fills {files} with the test files of the requirement it delivers.

A test that reaches code by starting a process or a browser is selected by the matrix, through its requirement — not by its imports. Name the requirement in it, and --affected finds it.

The architecture check beside the tests#

After validate --strict, which runs alone because it fails fast, arch_cmd and the tests run at the same time, each with its own output; both are reported before the gate decides. When both build into the same folder — two Maven runs on target/, say — run them one after the other:

bash
specgate config set gate_parallel false

What it says#

Every check --json answer has selection: mode (affected or full), reason, base, changed, requirements, tests, cached and the command that ran. Each entry of stages has ms, the time it took (null when it did not run). Only on a colour terminal does a stage's line end with its time — not in a pipe, a log or CI. The Tests line names the command as configured (npm test), not what that runs underneath (node --test). specgate check --last --json gives both back.