Skip to main content

Testing

The test pyramid as it is on this branch. Every layer has a make target; the CI jobs of .github/workflows/ci.yml call the same targets, so a green local make check-all predicts a green pipeline (apart from the Docker-based jobs).

LayerWhat it provesWhereRun with
Unitdomain invariants, use cases over in-memory doubles, HTTP handlers over httptest, adapters (encoder, gateway, relay, consumers)internal/domain/*, internal/application/usecases, internal/adapters/**, cmd/*make test (go test ./... -race)
BDD acceptancethe real HTTP API against Gherkin scenariosfeatures/*.feature, run by internal/bddmake bdd
Repository contractthe same contract suite runs against the in-memory and the Postgres repositoriesinternal/adapters/outbound/repocontract, used by memory and postgres testsmake test, make integration
Integrationreal Postgres and Kafka via testcontainers: repositories, migrations, the relay, checkout compensation, consumed outcomes, the real entry points of cmd/api, cmd/mcp, cmd/a2afiles named *_integration_test.go (build tag integration), 12 files, 17 test functionsmake integration (needs only Docker)
Contract (events)the encoder output equals golden CloudEvents, and the catalogue matches apis/asyncapi.yamlinternal/adapters/outbound/kafka/testdata/*.golden.json, internal/architecture/catalogue_fitness_test.gomake test, make arch-test
Architecture fitnessthe hexagon and the fleet rules are executable testsinternal/architecture/make arch-test
Mutationthe domain tests assert rather than merely execute.gremlins.yaml, internal/domain/*make mutation, make mutation-full
Coverage gateat least 90% over internal/domain and internal/applicationMakefile (COVERAGE_THRESHOLD)make coverage
Weblint, tsc -b, vitest and build of the console remoteweb/npm run lint && npx tsc -b && npm test && npm run build inside web/

Targets​

TargetRuns
make checkfmt-check vet build lint test, the pre-push gate (lefthook runs it on git push; pre-commit runs fmt-check vet lint)
make check-fastfmt-check vet arch-test and the tests of the packages changed against HEAD
make check-allcheck plus coverage arch-test bdd
make integrationgo test -tags=integration ./... -race -count=1, deliberately not part of check
make mutationgremlins on every internal/domain/<pkg> in turn (the fast blocking gate)
make mutation-fullgremlins on ./internal/domain with --workers 1 --timeout-coefficient 30
make vulngovulncheck ./...
make guide-lint, make harness-testlint the agent guides, unit-test the agent hooks

BDD scenarios​

Twelve feature files, 122 scenario definitions that the runner executes as 183 scenarios (the Examples rows of the Scenario Outlines expand), counted with git grep -c -E "^[[:space:]]*Scenario" -- features and the 183 scenarios (183 passed) line of go test ./internal/bdd -run TestFeatures -count=1 -v:

FileDefinitionsExecuted
checkout_rules.feature2464
fulfilment_rules.feature1834
cancellation_rules.feature1116
checkout.feature1111
fulfilment_status.feature1010
shopper.feature88
api_errors.feature88
orders_history.feature88
cancellation.feature77
tracking_rules.feature77
api_orders.feature55
api_idempotency.feature77

The four *_rules.feature files pin the rules the context's documentation states (ADR 0002, 0003, 0009 and 0012 to 0016): the PlaceOrder checks and delivery-promise failures, the pickup destination (ADR 0016), the consolidation key and the stored consolidated choice (ADR 0012, 0013), the cancel request and the CancelOnUnfulfillable policy, the consumed facts, the order status table, shared packages, revisions, and the tracking-view rules (ADR 0014, 0015, 0016).

internal/bdd/features_test.go (TestFeatures) runs them in-process against the real HTTP router with in-memory repositories, a fake delivery-promise and a fake clock, so they need no database and no broker.

Fitness tests​

make arch-test runs internal/architecture/. The rules, by test:

TestRule
TestHexagonalArchitecturedependencies point inward only: domain imports nothing of the application or adapters, application imports no adapter
TestRuntimeBinaryHasNoInMemoryAdapters (+ sensor)cmd/** never imports outbound/memory or repocontract
TestMCPServerIsReadOnly, TestMCPAdapterDependencyRule, TestMCPOptionalToolInputsCarryOmitemptycmd/mcp wires no write use case and never imports the REST adapter; optional tool inputs carry omitempty
TestA2AAdapterDependencyRule, TestA2AServerIsReadOnlyAndHasNoOutboundClient, TestA2ASDKIsImportedByTheAdapterAndItsCommandOnlythe same for cmd/a2a, plus no outbound A2A client
TestNoAuthMiddlewareReintroducedno bearer, JWT or API-key check under the inbound adapters
TestEventCatalogueMatchesContractthe event types in code equal apis/asyncapi.yaml
TestCloudEventsOnly, TestNoEventEnvelopeToggleOrFlatEnvelope, TestReplayConsumersSetCommitIntervalevery Kafka message is a CloudEvent; replaying consumers set a commit interval
TestKafkaWriterTopicNotSetTwice, TestKafkaWritersSetRequiredAckswriters never set the topic on both writer and message; acks are RequireAll
TestKafkaConsumerGroupNeverHardcodedInlinegroup ids come from configuration
TestOutboxRelaysPassAttemptCapa relay is built with WithMaxAttempts so a poison row cannot block it
TestDeadLetterCallsGuardCancellationdead-letter calls respect context cancellation on shutdown
TestKafkaIntegrationTestsUseTestcontainers, TestPostgresIntegrationTestsUseTestcontainersintegration tests start their own containers: no KAFKA_BROKERS or DATABASE_URL gate, no hard-coded localhost:9092
TestNoGoFilesAtRepoRootGo files live under cmd/ and internal/

Several rules have a companion ...SensorBites test that feeds the detector a bad fixture and expects it to fail, so a rule cannot go green by finding nothing.

Mutation testing​

.gremlins.yaml sets one worker, a timeout coefficient of 30 and thresholds efficacy: 99, mutant-coverage: 99 (plain numbers: a quoted YAML string is read as 0 by gremlins v0.6.0 and leaves the gate dormant). The last measurement recorded in the file (2026-11-15, gremlins v0.6.0) is 100% efficacy and mutant coverage for each domain package: shared (49 killed), shipto (21), shopper (22), customerorder (205), notice (26), 0 lived. make mutation and the mutation-fast job loop over every internal/domain/*/ package.

CI jobs​

ci.yml runs on push to main and develop, on pull requests, weekly (Monday 06:00 UTC) and on manual dispatch.

JobWhat it runsWhen
lintgolangci-lint v2.14.0every push and PR
guide-lintscripts/harness/guide_lint.py, test_hook.py (advisory, continue-on-error)every push and PR
complexitygocyclo, gocognit, cyclop, funlen, nestif (gate 15)every push and PR
testbuild, vet, make coverage (90% gate), uploads coverage.outevery push and PR
bddgo test ./... -run TestFeatures -vevery push and PR
integrationgo test -tags=integration ./... -race -count=1every push and PR
mutation-fastgremlins over every internal/domain/*/every push and PR
mutationexhaustive gremlins run, opens a harness:red issue on a scheduled failureschedule and manual dispatch
driftdead code, go mod tidy -diff, knip on web/, coverage-quality (advisory)schedule and manual dispatch
api-lintSpectral on apis/openapi.yaml and apis/asyncapi.yamlevery push and PR
vulngovulncheck ./...every push and PR
helm-lintct lint --charts charts/customer-ordering, selector testpull requests
chart-testsevery charts/customer-ordering/tests/*.sh and test_*.py (a test that prints SKIP fails)every push and PR
arch-testgo test ./internal/architecture/... -vevery push and PR
webnpm ci, lint, tsc -b, vitest, build in web/ against a sibling warehouse-ui-kit checkoutevery push and PR
docker-publishimage to GHCR, cosign signature, SBOM attestationpush to main, after the gate jobs
releasetags the next patch version, publishes the chart as OCIpush to main, after docker-publish

The documentation site has its own workflow, .github/workflows/docs.yml: it builds the site on pull requests and deploys it on push to main.

Writing tests​

  • Domain and use-case tests use the in-memory doubles from internal/adapters/outbound/memory; they are never imported by cmd/**.
  • A new repository behaviour goes into repocontract so both implementations are held to it.
  • A new Postgres or Kafka test must be a *_integration_test.go file with the integration build tag and must start its containers through internal/testing/pgtest or kafkatest; the fitness tests reject an env gate.
  • A new Gherkin scenario goes into features/ and a step into internal/bdd.