18. godog/Gherkin acceptance tests as executable specification
Status
Accepted (2026-10-08). Mirrors inventory-storage's ADR 0007 (the fleet's
canonical BDD pattern) and fills the gap
docs/operations-notes.md recorded ("bdd dropped,
no features/"). No REST, MCP or event contract changes.
Context
By now this context has deep layer-by-layer tests: table-driven aggregate
tests, use-case tests against in-memory adapters, httptest tests per
handler, wire goldens for every CloudEvent, and testcontainers integration
tests for Postgres and Kafka. What it did not have was a statement of its
behaviour in the domain's own vocabulary, nor anything that exercised the
whole stack as a black box:
- A
TestReceiveNetworkDemand_...test is precise but says nothing a non-Go reader can review about why an untranslatable product rejects the whole order, or whyNetworkOrderAcknowledgedis only published once the network's transaction-status record settles. - No test drove the poller, the use cases, the event encoders, the analytics projection and both HTTP routers together, the way an operator sees them.
This is a Supporting context whose correctness is defined by the counterparty's protocol (24-hour window, answered exactly once, in full or not at all, no partial acknowledgement) and by fleet rules (CloudEvents 1.0 only, no auth, no customer PII). Those are exactly the things worth reading as prose and failing the build on when they stop being true.
One constraint shapes the suite: demand never arrives over HTTP (ADR 0001
§5; apis/openapi.yaml is read-only apart from one write). "Creating" a
network order therefore means seeding the stub network and running the real
poller, then observing the result through REST.
Decision
We write executable specifications in Gherkin under features/, run them
with godog v0.16.0, and gate them in CI
as a blocking bdd job.
-
One feature file per concept, each starting with a
# Derived from:comment citing theapis/openapi.yamloperations and.claude/rules/domain-model.mdsections it specifies, and each scenario tagged@bdd:File Covers network_order_intake.featurepolling demand, ACL translation, accept/reject, idempotency, malformed demand network_order_queries.featureGET /network-orders[/{ref}], PII rule, unanswered list order, overdue boundaryacknowledgement_lifecycle.featurereconciliation (SUBMITTED to ACKNOWLEDGED / REJECTED), deadline sweep, reject-overdue shipment_confirmation.featurePOST /network-orders/{ref}/shipment-confirmation: 204/404/409/500, idempotencycapability_offers.featureGET /capability-offers,min(physical, throughput), ADR 0017 cycle-time eligibilityinbound_status.featureGET /inbound-status: counters, watermark, unanswered/overdueoperations.feature/healthz,/readyz,/metrics, read-only surface, no authenticationintegration_events.featureCloudEvents 1.0 envelope, type/dataschemaper event (NetworkOrderAcknowledgedis.v2), partition keyacknowledgement_report.featureGET /reports/acknowledgement[/freshness], rejection causes, window, 400s -
True black-box tests of the real routers.
features_test.go(plus siblingfeatures_*_test.gostep files in the samemain_testpackage) builds the composition root the waycmd/netfulfilandcmd/netfulfil-reportsdo:inboundhttp.Server.Routes()for the OLTP API and the chiinboundhttp.NewReportsRouterfor the report, both served byhttptest.NewServerand driven by plainnet/httpwith noAuthorizationheader. Redirects are not followed, because a router redirect is itself behaviour. -
Real adapters wherever they exist, doubles only for siblings. The scenarios use the real poller, use cases, in-memory repositories, the real
StubGateway(wrapped only to record what the network was told), the real Kafka encoders (Publisher,AnalyticsPublisher, writing into a recordingWriter, so no broker) and the realAnalyticsConsumerfeeding the realMemoryStoreread model. The suite makes no REST or MCP call to any sibling context: order-management, inventory-storage, process-path-management and wes-work-planning are in-process doubles of theportsinterfaces. -
Fresh state and a fixed clock per scenario. A
Beforehook rebuilds everything, and the clock only moves with "N hours pass", so the 24-hour window and freshness lag are exact, not slept. -
Real behaviour, not bugs. Where the implementation contradicts the spec, the scenario states the spec's behaviour. If the defect cannot be fixed safely in the same change, the scenario is tagged
@known-bugand excluded from the default run (Tags: "~@known-bug"); deleting the tag when the defect is fixed turns it into a regression test.BDD_TAGS=@known-bug make bddruns only those scenarios and must fail. -
Blocking in CI as the
bddjob (go test ./... -run TestFeatures -v, the same invocation asmake bdd), added todocker-publish'sneeds. The branch-protection required-check list is not changed here: addingbddto it is a repository-settings change for a maintainer, recorded inoperations-notes.md.
Findings recorded by the first run
Writing the scenarios from the spec surfaced three defects. They are listed
here so the @known-bug tags have a home; each still tagged is re-verified by
BDD_TAGS=@known-bug make bdd.
- A demand that fails during an order-management outage is never answered
on retry. (Fixed.)
ReceiveNetworkDemandsaves the order asNEWbefore asking order-management for a verdict, and its idempotency guard (FindByRef != nilreturned the existing order) short-circuited every retry. The poller counted the re-fetched demand asreceived, the order stayedNEW, and the sweep eventually rejected it asACKNOWLEDGEMENT_DEADLINE_MISSED.apis/openapi.yaml(failed) says a failed unit "will be re-fetched ... processing is idempotent onnetworkRef, which is what makes the retry safe". The original note held the fix back because a resume must not raise a second held order when the first attempt got pastRaiseHeldOrder; that is now covered by the stableIdempotency-Keyderived from the network ref (order-management #105), so a re-delivery of a still-NEWorder resumes at the held-order step and the retry replays the same local order. An order that is already answered, or whose acknowledgement window has closed (the sweep owns it), is returned unchanged. Because that middleware hashes the request body, the planner now sends the order lines sorted by SKU: they come from a map, and a different order on retry would have been refused422 idempotency-key-reused. Scenario: Demand that failed during an order-management outage is answered on a later pass (no longer@known-bug). 422 empty-network-refon shipment confirmation was unreachable. (Fixed.) The spec documents it, butnet/http'sServeMuxcleaned//and answered a 307 redirect before the handler ran, so the handler'sref == ""branch was dead over HTTP. The router has since moved to chi (ADR 0019, otelchi), which routes/network-orders//shipment-confirmationto the handler, so the documented 422 is returned and the spec stands. Scenario: An empty networkRef is a 422 problem document (no longer@known-bug).- A failed shipment submission is never retried. By design (and as
apis/openapi.yamlstates for500), the order is savedCONFIRMEDbefore the network is told, so a retry after a failedSubmitShipmentConfirmationanswers 204 without re-submitting: the network is never told about that shipment. The scenario encodes the documented behaviour and asserts the consequence (one attempt, no second one); it is flagged here because the consequence is an operational hazard, not because it contradicts the spec.
One further defect was fixed in this change because it is trivial and
safe: the in-memory NetworkOrderRepo.ListUnanswered returned Go's
randomised map order, contradicting apis/openapi.yaml ("soonest deadline
first") and the Postgres adapter (ORDER BY acknowledge_by). It now sorts by
acknowledgeBy, then networkRef; the scenario Unanswered orders are
listed soonest deadline first failed roughly one run in ten before the fix,
and memory/network_order_repo_test.go pins it at unit level.
Two documentation drifts were also found and are not fixed here (the files
are outside this change's remit): .claude/rules/domain-model.md still says
there is no SUBMITTED state, "no typed domain events", CapabilityOffer is
"planned" and ConfirmShipment has no use case; and the
ReceiveNetworkDemand comment on untranslatable demand says the order is
built with "a synthetic single line", while ReceiveUntranslatable builds it
lineless (the REST response has lines: []).
Consequences
Easier
- The behaviour is reviewable by someone who has never opened a Go file, in the ubiquitous language (NetworkOrder, acknowledgeBy, held order, requiredShipBy, CapabilityOffer).
- The fleet rules are executable here. Every message is asserted to be a
CloudEvents 1.0 envelope with the right
type,dataschema,subject, key and content-type header on both streams; every endpoint is asserted to answer without credentials; the order response is asserted to carry no property beyond the documented schema (the PII rule). - The seams between layers are covered: poller to use case to event encoder to analytics consumer to report router, which no single-layer test sees.
- Defects found by writing prose from the spec are recorded where they cannot be forgotten, without turning the suite red or encoding the bug.
Harder
- A second vocabulary to maintain. Step definitions are glue; a DTO or
route change updates
features_*_test.goas well as the handler. - Doubles can drift from siblings. The planner, inventory, path-capability and capacity doubles encode what this context asks of them; they are checked against the port interfaces by the compiler, not against the real sibling services (by design: no sibling calls).
@known-bugis an escape hatch. It must stay rare and each tag must point at a recorded finding; a tag with no finding is a silenced test.- Overlap with the
httptestsuite. Some assertions now exist twice. Accepted: thehttptesttests are exhaustive per endpoint, the scenarios are the readable specification of the journeys.