Skip to content

feat: explicit declaration phases, clearer diagnostics, CI - #6

Merged
jacoelho merged 1 commit into
mainfrom
feat/explicit-declaration-phases
Nov 10, 2026
Merged

jacoelho merged 1 commit into
mainfrom
feat/explicit-declaration-phases

Conversation

@jacoelho

Copy link
Copy Markdown
Owner

What changes for callers

Two behaviour changes that can fail existing tests:

  • Declaring on an enclosing Suite while a nested Rule builder runs now fails with this Suite is suspended while its nested Rule builder runs. Previously f.Scenario, f.Outline and f.Rule called inside f.Rule(..., func(r) { ... }) were accepted and filed outside the Rule, without its tags, hooks or Background, and an otherwise empty Rule passed its non-empty check.
  • Sealed-scope panic messages changed. bdd: Suite builder has returned and bdd: ScenarioSpec builder has returned are replaced by a message naming the call site, the call and the fix, for example bdd: <file>:<line>: Suite.Before called on a sealed Suite: .... Code that matches the old strings will no longer match. Nil and zero receiver panics are unchanged.

Additions:

  • ScenarioChain and BackgroundChain are exported (previously unexported return types). go doc now lists their methods, and helpers can accept and return a chain.
  • Ordering errors append the legal declaration order.
  • A scenario stopped by Error, Fatal, Skip or panic during setup, a hook or an operation logs one line: the operation it stopped in, where that operation was declared, and the operations that did not run.
  • Log lines of a running scenario are attributed to the bdd.Feature call line instead of suite.go:N.
  • Compose errors include the Compose(...) call site.

Exported signatures other than the two chain type names, generated test names, and lifecycle order are unchanged.

Why

The declaration order was enforced by three independent booleans on Suite and by sealed plus len(steps) > 0 on ScenarioSpec, spread across every method and documented nowhere. That left the nested-Rule hole above. Suite now has one phase value and one pure transition function (suitePhase.next); ScenarioSpec has one phase value.

Also in this PR

  • Tests: 37 subprocess call sites share one runSelf helper and run in parallel.
  • CI workflow: gofmt, go vet, go test -race, govulncheck, with actions pinned by commit SHA (actions/checkout v7.0.1, actions/setup-go v7.0.0).
  • ARCHITECTURE.md, a "Declaration order" section in the README and package doc, and a README and comment clean-up.

Verification

Run locally on Go 1.27.3, darwin/arm64:

  • gofmt -l . reports nothing; go vet ./... is clean.
  • go test -race -count=1 ./... passes; three consecutive race runs passed after parallelising. The race run takes about 5.5s, down from about 19s.
  • govulncheck ./... reports no vulnerabilities.
  • Four mutations of the new logic (drop the suspended transition, off-by-one in the stop report, drop a Helper call, reorder the operation sequence) each failed a test.
  • The README Quick start was extracted into a scratch module and passes.

The CI workflow is new in this PR; this PR is its first run.

Where to look

  • suite.go: suitePhase.next, Suite.Rule (suspend and resume), featurePlan.runLeaf (operation sequence and stop report).
  • The stop report is logged from a t.Cleanup, so it appears after the scenario's own cleanups.
  • A setup function or step that itself calls t.Helper() now has its failure attributed to the bdd.Feature line rather than suite.go:N; the stop report names the operation.

Not done

  • Declaration errors still carry a suite.go:N or scenario.go:N prefix; the message itself contains the call site.
  • A sealed-scope misuse is still a panic and still aborts the test binary.

Suite and ScenarioSpec track their declaration order as one phase value
instead of independent flags. Enclosing Suites are now suspended while a
nested Rule builder runs, so a declaration on an outer Suite inside a
Rule builder fails instead of being filed outside the Rule.

Diagnostics:
- ordering errors state the legal order
- a stopped scenario logs the operation it stopped in, its declaration
  site, and the operations that did not run
- scenario log lines are attributed to the Feature call site
- sealed-scope panics name the call site, the call, and the fix
- Compose errors name the Compose call site

ScenarioChain and BackgroundChain are exported so go doc lists their
methods and helpers can accept and return a chain.

Tests share a runSelf helper for subprocess runs and run in parallel.
Add a CI workflow (gofmt, vet, race tests, govulncheck) and
ARCHITECTURE.md.
@jacoelho
jacoelho merged commit 71fd5dd into main Nov 10, 2026
1 check passed
@jacoelho
jacoelho deleted the feat/explicit-declaration-phases branch November 10, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant