Testing
Every layer below exists in the repository today. Counts were taken from
the develop tree on 2026-10-12 (func Test… declarations, Gherkin
Scenario: headings); they drift as tests are added. The BDD counts were
re-measured on 2026-11-15, after the documentation-derived scenarios.
Source: features/*.feature, **/*_test.go, .github/workflows/ci.yml, Makefile.
Make targets
| Target | Command | Needs |
|---|---|---|
make test | go test ./... -race | Go only |
make coverage | go test ./... -race -coverprofile=coverage.out -coverpkg=./internal/domain/...,./internal/application/... and the 90 % gate on the total | Go only |
make bdd | go test ./... -run TestFeatures -v | Go only |
make arch-test | go test ./internal/architecture/... -v | Go only |
make integration | go vet -tags=integration ./... then go test -tags=integration ./... -race -count=1 | Docker (each test starts its own containers) |
make contract | ./scripts/contract-test.sh | st from schemathesis==4.28.0, a free port (default 18084) |
make mutation-fast | gremlins unleash ./internal/domain/order | gremlins v0.6.0 |
make mutation | gremlins unleash ./internal/domain --workers 1 --timeout-coefficient 30 | gremlins v0.6.0; slow |
make vuln | govulncheck ./... | govulncheck |
make chart-test | bash charts/order-management/tests/render_test.sh then python3 charts/order-management/tests/test_service_selectors.py | helm, Python 3 with PyYAML |
make check | fmt-check vet build lint test | golangci-lint v2.13.1 |
make check-all | check coverage arch-test bdd | as above |
make check-fast | fmt-check vet arch-test plus the tests of packages changed against HEAD | used by the agent Stop hook |
make guide-lint, make harness-test | scripts/harness/guide_lint.py, scripts/harness/test_hook.py | Python 3 |
lefthook.yml runs make fmt-check, make vet and make lint before
each commit and make check before each push, once a clone has run
lefthook install.
Unit tests
- Domain (
internal/domain/order,processpath,shared,releaseconfirmation): the aggregate, line state machine, status derivation, promise policy and promise groups, path selection and eligibility, planned-capacity windows, and the release-confirmation state machine (PENDING->CONFIRMED,PENDING->UNCONFIRMEDonce, late and duplicate confirmation, the overdue boundary; ADR 0043). Pure Go, no fakes needed.path_selection_intake_test.gopins ADR 0042: onlyCUSTOMER_ORDERpaths are candidates, and the live catalogue before seeding (PACK/PICK/REBIN/SLAM at 2h, no intake) resolves topick, never PACK. - Application (
internal/application/usecases): every use case against in-memory repositories and the fakes infakes_test.go(inventory client, publisher, metrics counter, clock).release_confirmation_test.gopins ADR 0043: thePENDINGrow is written in the release's own unit of work (a later failure rolls it back) and only for lines released in that pass, an event withoutreference/line_noor for an unknown line is ignored and counted without opening a transaction, and the timeout sweep flags overdue rows exactly once (0disables it). - Adapters: the HTTP router through
httptest(status codes, problem types, idempotency, readiness, logging), the Kafka consumers against fake readers and DLQ writers (release_confirmation_consumer_test.go: fixture JSON with and without the new fields, malformed data to the DLQ, unknown types committed past, shutdown never dead-letters), the publishers against fake writers, the inventory-storage client against a fakeHTTPDoer, the circuit breaker, the telemetry instruments (including the two release-confirmation counters), the composition root's wiring helpers incmd/order(release_confirmation_test.go: theRELEASE_CONFIRMATION_*boot validation, the15mand168hdefaults). - Golden files pin wire formats:
internal/adapters/outbound/kafka(cloudevents_golden_test.go),internal/adapters/outbound/events/testdata/log_payloads.golden,internal/adapters/inbound/mcp/testdata/tool_registry.goldenandfleet_tool_snapshot.golden.
Coverage is measured on internal/domain/... and
internal/application/... only, and must stay at or above 90 %.
Integration tests (-tags=integration)
Every suite starts its own throwaway container with testcontainers-go
v0.44.0 (postgres and kafka modules). There is no shared
DATABASE_URL, no t.Skip on a missing environment variable, and no
localhost:9092: the architecture fitness tests below fail the build if
one appears. Postgres packages migrate once into a template database and
clone one database per test.
| Package | Files | What it proves |
|---|---|---|
cmd/order | 1 | The housekeeping sweeper wiring against real Postgres. |
internal/adapters/inbound/http | 2 | The Idempotency-Key middleware and the router over real Postgres. |
internal/adapters/inbound/kafka | 8 | Re-promise consumer end to end, its version-conflict retry, its DLQ (including auto-creating a missing .dlq topic), the planned-capacity and product-classification consumers, the consumer-shutdown dead-letter guard, and the release-confirmation consumer (release_confirmation_consumer_integration_test.go, ADR 0043: a produced WorkUnitCreated CloudEvent ends CONFIRMED, a malformed one lands in the DLQ, and cancelling Run mid-handle returns nil with the DLQ empty). |
internal/adapters/inbound/mcp | 1 | initialize, tools/list and tools/call over the real Streamable HTTP transport, with real Postgres (OLTP and analytics) behind it. |
internal/adapters/outbound/analyticsstore | 2 | Projection and report queries. |
internal/adapters/outbound/kafka | 1 | Publisher on a real broker, CloudEvents envelope asserted. |
internal/adapters/outbound/kafkacatalog, kafkacptschedule, kafkapathcapacity | 3, 1, 1 | The replay caches, including two catalogue consumers side by side, and the catalogue's decoded intake driving PathSelectionPolicy on a real broker (TestConsumer_RealBroker_IntakeDrivesPathSelection, ADR 0042). |
internal/adapters/outbound/postgres | 10 | Order repository and version column, outbox and relay, outbox lag gauge, release events through the outbox, planned capacity, pool limits (MaxConns, statement_timeout), sweeper, trace headers through the outbox, and the release-confirmation repository and sweeper hook (release_confirmation_integration_test.go, ADR 0043, including two concurrent sweepers flagging a row once). |
internal/adapters/outbound/productclassificationcopy | 1 | The Postgres copy and its version guard. |
internal/application/usecases | 1 | Receive, allocate, release, retry, cancel against the real repository and UnitOfWork. |
The CI job and make integration both use ./....
TestEveryIntegrationPackageRunsInCI fails if a package with a
//go:build integration file is not reached by an integration command in
ci.yml. In CI, TESTCONTAINERS_RYUK_DISABLED=true is set because the
parallel test processes contend for the reaper.
BDD (godog)
TestFeatures (features_test.go at the repo root) runs every file in
features/ with Strict: true, so an undefined or pending step fails
the suite. Step definitions live in features_test.go,
features_planned_capacity_test.go, features_fulfillment_site_test.go,
features_wave2_test.go, steps_rules_test.go and steps_closeout_test.go. The
scenarios drive the use cases, and for the REST contract scenarios the
router through httptest, all on in-memory adapters.
The default tag filter is ~@known-bug; BDD_TAGS overrides it
(BDD_TAGS=@known-bug go test . -run TestFeatures runs only the tagged
scenarios). No scenario carries @known-bug today; the tag and the filter
stay for the next documented-but-unimplemented rule. The former occupant,
"A shipped order can no longer be cancelled" (event_driven_rules.feature),
passes by default since Order.EnsureCancellable rejects a Shipped line as
well as a Released one (internal/domain/order/order.go, ADR 0004 addendum
2026-11-15).
| Feature file | Scenarios |
|---|---|
allocation_events.feature | 5 |
allocation_failure.feature | 2 |
api_contract.feature | 8 |
cancellation.feature | 2 |
cancellation_extended.feature | 2 |
domain_events.feature | 2 |
error_paths.feature | 4 |
event_driven_rules.feature | 32 (consumer rules driven through the use cases: repromise ADR 0018, release confirmation ADR 0043, shipment ADR 0051, missed load, shipped order not cancellable) |
fulfillment_site.feature | 7 |
held_orders.feature | 5 |
held_orders_extended.feature | 3 |
intake_validation.feature | 4 |
mutation_closeout.feature | 10 (rules the first rule files left unpinned: found by mutation) |
order_lifecycle.feature | 2 |
order_rules.feature | 55 (REST-reachable documented rules: intake, path selection, allocation and retry, held orders, cancellation, promise policy, demand projection, readiness) |
partial_shipment.feature | 2 |
planned_capacity.feature | 10 |
planned_capacity_extended.feature | 5 |
required_ship_by.feature | 2 |
ship_complete.feature | 2 |
| 20 files | 164 |
The counts are Scenario and Scenario Outline definitions
(git grep -c -E "^[[:space:]]*Scenario" -- features). With outline rows
expanded the runner executes 195 scenarios, none skipped by the default
filter.
Contract tests (Schemathesis)
scripts/contract-test.sh builds cmd/order, starts it in memory on
127.0.0.1:${CONTRACT_PORT:-18084} with
PLANNED_CAPACITY_CONSUMER_GROUP=contract-test-planned-capacity and
PLANNED_CAPACITY_SITE_ID=SIM1 (so GET /planned-capacity exists), waits
for /healthz, then runs Schemathesis 4.28.0 with
CONTRACT_MAX_EXAMPLES (default 100) examples per operation against
apis/openapi.yaml. receiveOrder is excluded, because the "held order
must be ship-complete" rule links two booleans in a way OpenAPI 3.0 cannot
express; the BDD scenario and the domain unit test cover it instead.
cmd/order-reports needs an analytical database to start, so its contract,
apis/openapi-reports.yaml (ADR 0039), is checked by two Go tests in the
test job instead of Schemathesis: TestReportsContract_RoutesMatchSpec
(the chi router's routes equal the spec's paths) and
TestReportsContract_ResponsesMatchSpec (every documented status of every
operation, driven through a stub store, answers a declared status and media
type with exactly the documented properties).
Mutation testing (gremlins)
Thresholds live in .gremlins.yaml: efficacy 97, mutant-coverage
99, with workers: 1 and timeout-coefficient: 30. gremlins fails when
the measured value is less than or equal to the threshold. The last
recorded run (2026-10-10, ./internal/domain/order) measured 137 killed,
3 lived, 1 not covered: efficacy 97.86 %, mutant coverage 99.29 %. The
three survivors are listed as accepted near-equivalents in the README.
Architecture fitness tests (internal/architecture)
| Test | Rule |
|---|---|
TestHexagonalDependencyRule | domain imports nothing internal; application imports only domain; inbound and outbound adapters never import each other; only cmd/ wires every layer. |
TestAnalyticsIsolation | internal/analytics never imports the OLTP layers (ADR 0006). |
TestPortsAreCustomerOwned | internal/application/ports never imports an adapter or cmd/ (ADR 0002). |
TestMCPAdapterDependencyRule | the MCP adapter depends only on application and domain, and nothing else imports it. |
TestNoAuthMiddlewareReintroduced | no bearer-auth middleware comes back (ADR 0012). |
TestKafkaConsumerGroupNeverHardcodedInline | consumer groups are named constants or configuration. |
TestKafkaIntegrationTestsUseTestcontainers, TestPostgresIntegrationTestsUseTestcontainers | no env-gated or localhost:9092 integration tests. |
TestDomainHasNoSerializationTags | no json: tags in internal/domain. |
TestCloudEventsOnly, TestReplayConsumersSetCommitInterval | every Kafka message goes through the CloudEvents helper; replay readers set CommitInterval. |
TestKafkaWritersSetRequiredAcks, TestKafkaWriterAcksSensorBites | every kafka-go Writer{...} literal in a non-test file under internal/ or cmd/ sets RequiredAcks (kafka-go defaults to RequireNone, acks=0, which silently drops messages on a broker blip); the sensor is proven to fail. |
TestDeadLetterCallsGuardCancellation (+ TestDeadLetterShutdownSensorBites, kafka_dlq_shutdown_fitness_test.go) | Every function in a non-test file under internal/adapters/inbound/kafka that sends to the dead-letter topic must reference ctx.Err() (any context-named value) or context.Canceled in its own body, or carry a //dlq:deterministic <reason> comment on the call line or the line above it. A handler that fails because the process is stopping must not dead-letter a good message and commit past it (network-fulfillment #89); a guard in the caller does not count. The sensor test proves the detector flags the pre-fix shape. |
TestKafkaWriterTopicNotSetTwice (+ TestKafkaWriterTopicSensorBites, kafka_writer_topic_fitness_test.go) | kafka-go rejects every write whose Message.Topic is set when the Writer also has a Topic. Per Go package under internal/ and cmd/: once any kafka-go Message literal sets Topic, every Writer literal in that package must leave Topic empty, unless it carries //kafka:fixed-topic-writer <reason> and no Topic-setting Message is provably written through it. Writers configured after construction and WriterConfig are not covered. (Escape: warehouse-planning's domain DLQ writer, where no dead letter ever landed.) |
TestEventCatalogueMatchesContract | every CloudEvents type apis/asyncapi.yaml declares for this service also appears in an ADR (the event catalogue). |
TestOptionalMCPInputsCarryOmitempty | a struct field whose jsonschema description says "optional" carries omitempty, so the MCP SDK does not mark it required (fleet decision D16). |
TestEveryIntegrationPackageRunsInCI | see above. |
Several sensors have a companion test (TestPostgresIntegrationDetector,
TestEventCatalogueDetector, TestDomainTagSensorFailsOnBadFixtures,
TestIntegrationCoverageSensorFailsOnBadFixtures,
TestOptionalMCPInputSensorFailsOnBadFixtures) that proves the sensor
flags a known-bad fixture.
MCP evals (internal/adapters/inbound/mcp)
| Level | Tests | What |
|---|---|---|
| E1 governance | TestEval_InputSchemasResolveAndConstrain, TestEval_ParametersAreDescribed, TestEval_ToolRegistryMatchesGolden, TestEval_FleetToolNamesAreGloballyUnique | Schemas resolve, every parameter has a description, the registry matches tool_registry.golden, tool names are unique across the fleet snapshot. |
| E2 conformance | nine TestEvalConformance_* tests | Handshake, unknown tool, wrong-typed and extra arguments, exactly one resource template and one prompt advertised (ADR 0049), session close. |
| E3 behaviour | TestMCPEvalSuite | 13 scenarios in testdata/features/mcp_tools.feature, run through godog with Strict: true. |
Frontend (web/)
Vitest tests (src/config.test.ts, src/api.test.ts,
src/screens/OrderManagementScreen.test.tsx, with an MSW mock server) run in
the web CI job together with lint, tsc -b and the production build. They
are not part of make check. api.test.ts and four screen cases pin the
Idempotency-Key contract of ADR 0038 (a UUID per submission, reused when
the request got no answer, new after an answer or an edit);
TestCORS_PreflightAllowsIdempotencyKey pins the CORS side.
The chart has a selector test, python3 charts/order-management/tests/test_service_selectors.py (make chart-test),
which proves each Service selects exactly one Deployment and that the
startupProbe outlasts the boot retry budget. The chart-tests CI job runs it
on every push and PR with Helm v3.16.4 and PyYAML; without PyYAML the script
fails instead of skipping. Before it, the same job runs
charts/order-management/tests/render_test.sh (helm only), which asserts
the api Deployment mounts the chart ConfigMap with envFrom (gap fix D14),
that config.outboxRelayInterval and config.outboxMaxAttempts reach it
(default OUTBOX_MAX_ATTEMPTS 20, ADR 0040), that the housekeeping keys
render only with a database, and that the projector, reports and MCP
Deployments do not mount it.
The outbox relay attempt cap (ADR 0040) is pinned by
TestOutboxRelay_MaxAttempts_PoisonRowIsExcludedAndTheNextRowPublishes and
TestOutboxRelay_WithoutMaxAttempts_RetriesWithoutBound (testcontainers
Postgres, internal/adapters/outbound/postgres/outbox_integration_test.go),
TestOutboxMaxAttemptsFromEnv (cmd/order), and the architecture fitness
test TestOutboxRelayCallsSetMaxAttempts, which fails when a file under
cmd/ builds a relay without WithMaxAttempts.
Trace continuity across the outbox (ADR 0041, the fleet D27 reference) is
pinned by TestOutboxTrace_TraceparentCrossesTheOutboxToKafka and
TestOutboxTrace_RowWithoutTraceHeadersRelaysUnchanged
(internal/adapters/outbound/postgres/outbox_trace_integration_test.go,
integration tag). They boot the package's shared Postgres container plus
their own Kafka container: a use case runs inside a request span, the relay
sends the row on a context without that span, and the consumed message's
traceparent must extract to the request's trace and span.
CI jobs (.github/workflows/ci.yml)
| Job | Runs | When |
|---|---|---|
lint | golangci-lint v2.13.1 | every push and PR |
guide-lint | guide_lint.py, repo_lint.py, test_hook.py, test_repo_lint.py | every push and PR |
complexity | golangci-lint with only gocyclo, gocognit, cyclop, funlen, nestif; gocyclo > 10 report | every push and PR |
test | build, vet, gofmt, then make coverage (go test ./... -race with the Makefile's coverage scope and 90 % gate) | every push and PR |
bdd | go test ./... -run TestFeatures -v | every push and PR |
contract | scripts/contract-test.sh | every push and PR |
evals-tests | go test ./internal/adapters/inbound/mcp/... -race -run '^TestEval|^TestMCPEvalSuite' -v | every push and PR |
integration | go vet -tags=integration ./..., go test -tags=integration ./... -race -count=1 | every push and PR |
mutation-fast | gremlins unleash ./internal/domain/order | every push and PR |
vuln | govulncheck v1.8.0 | every push and PR |
api-lint | Spectral on apis/openapi.yaml, apis/openapi-reports.yaml and apis/asyncapi.yaml | every push and PR |
arch-test | go test ./internal/architecture/... -v | every push and PR |
docs-api-drift | clean-api-docs:all + gen-api-docs:all; fails on any change under docs/docs/api-reference/rest or rest-reports | every push and PR |
web | MFE lint, typecheck, test, build | every push and PR |
chart-tests | charts/order-management/tests/render_test.sh and test_service_selectors.py (Helm v3.16.4, PyYAML) | every push and PR |
mutation | full-domain gremlins; opens or closes a harness:red issue | schedule (Mondays 06:00 UTC) and manual dispatch |
drift | deadcode, go mod tidy -diff, knip, coverage quality | schedule and manual dispatch |
helm-lint, trivy-scan | chart-testing lint; image scan | PRs into main only |
docker-publish, release | push the image, tag, chart and GitHub release | pushes to main only |
The documentation site is built by .github/workflows/docs.yml on every
pull request that touches docs/**, apis/** or the workflow (build only,
no Pages artifact, no deploy) and built and published on pushes to main.
Run npm ci and npm run build in docs/ to reproduce it locally.