Skip to main content

Testing

The test pyramid as it is on this branch, the make targets that run each layer, and the CI jobs that enforce them. Counts were taken from the source tree (func Test... per file, Scenario: per feature file).

The pyramid​

LayerWhat it coversWhereCountRun with
Unit: domainPaymentAuthorization and Refund aggregates, shared money / id rulesinternal/domain/*/40 tests (23 paymentauthorization, 10 refund, 7 shared)make test
Unit: use casesevery command, query, consumer and policy over in-memory doublesinternal/application/usecases/36 testsmake test
Unit: adaptersHTTP handlers and routes (httptest over the real chi router), Kafka consumer loop / dead-letter / tracing, CloudEvents codec, outbound encoder and writer, payment provider client (httptest), telemetry, MCP and A2A adapters, boot configuration of each cmd/*internal/adapters/**, cmd/*/*_test.go, internal/bootretrythe rest of the 307 (about 200 outside the fitness tests and the godog runner)make test
Behaviour (godog / Gherkin)acceptance scenarios through the real router and use cases, in-memory doublesfeatures/*.feature, runner internal/bdd/features_test.go (TestFeatures, Strict: true)5 feature files, 56 Scenario and Scenario Outline blocks, all plain scenarios so the runner reports 56 scenarios (56 passed) (authorization 4, capture_release 5, payment_rules 31, reads_and_policies 12, refunds 4)make bdd
Contract: repositoriesone contract suite every repository implementation must pass, run against the memory doubles and against real Postgresinternal/adapters/outbound/repocontract/ (driven by memory_test.go and repositories_integration_test.go)shared suitemake test, make integration
Contract: wire formatsgolden CloudEvents per event type (internal/adapters/outbound/kafka/testdata/*.golden.json), MCP tool registry golden (internal/adapters/inbound/mcp/testdata/tool_registry.golden.json), the event catalogue checked against apis/asyncapi.yaml and ADR 0003 (TestEventCatalogueMatchesContract), OpenAPI and AsyncAPI linted with spectral in CI (api-lint)as listed10 event goldens, 1 tool goldenmake test, make arch-test; spectral in CI only
Integrationreal Postgres and real Kafka started by testcontainers: repositories, migrations, outbox relay, outbox trace headers, the cmd/api end to end, /readyz wiring, the cmd/mcp binaryfiles tagged //go:build integration (9 files)13 testsmake integration
Mutationgremlins over every package under internal/domain.gremlins.yamlthresholds: efficacy 85, mutant coverage 85 (measured 2026-10-26: paymentauthorization 85.94 / 85.33, refund 86.05 / 100, shared 100 / 100)make mutation (blocking subset), make mutation-full
Architecture fitnessstructure and policy as executable testsinternal/architecture/32 testsmake arch-test

Totals: 307 unit-tagged and 13 integration-tagged test functions plus the 56 godog scenarios. Integration tests never read DATABASE_URL or KAFKA_BROKERS and never t.Skip on them: each boots its own containers (TestPostgresIntegrationTestsUseTestcontainers, TestKafkaIntegrationTestsUseTestcontainers), so they need only Docker.

Fitness tests (internal/architecture/)​

TestEnforces
TestHexagonalArchitecturethe domain imports no outer layer; adapters do not reach sideways into siblings
TestMCPAdapterDependencyRule, TestMCPOptionalToolInputsCarryOmitemptythe MCP adapter stays read-only and its optional inputs are omitempty
TestA2AAdapterDependencyRule, TestA2AServerIsReadOnlyAndHasNoOutboundClient, TestA2ASDKIsImportedByTheAdapterAndItsCommandOnlythe A2A agent is read-only, holds no outbound client, and the SDK is confined
TestNoAuthMiddlewareReintroducedno bearer / JWT check under internal/adapters/inbound (auth was removed fleet-wide)
TestRuntimeBinaryHasNoInMemoryAdaptersno cmd/** imports internal/adapters/outbound/memory
TestNoGoFilesAtRepoRootGo files live under cmd/, internal/
TestCloudEventsOnly, TestNoEventEnvelopeToggleOrFlatEnvelopeCloudEvents 1.0 is the only envelope; no toggle, no flat envelope
TestEventCatalogueMatchesContractevery CloudEvents type that apis/asyncapi.yaml declares for this service appears in the type catalogue of ADR 0003
TestReplayConsumersSetCommitInterval, TestKafkaConsumerGroupNeverHardcodedInlineconsumer commit and group-id rules
TestKafkaWritersSetRequiredAcks, TestKafkaWriterTopicNotSetTwicewriters use RequiredAcks: All and never set the topic on both writer and message
TestDeadLetterCallsGuardCancellationdead-letter publishes respect context cancellation (shutdown)
TestOutboxRelaysPassAttemptCapevery relay is built with the attempt cap
TestPostgresIntegrationTestsUseTestcontainers, TestKafkaIntegrationTestsUseTestcontainersintegration tests start their own containers

Most carry a companion ...SensorBites / ...FailsOnBadFixtures test proving the sensor fails on a bad fixture.

Idempotency replay classes (internal/adapters/inbound/http/)​

Every problem type of the catalogue declares a replay class (FINAL, OUTCOME, RETRYABLE; ADR 0008). These unit tests need no Docker:

TestEnforces
TestEveryProblemTypeDeclaresAReplayClass, TestTheUnclassifiedEntryCheckBitesa catalogue entry without a class (or a 5xx entry that is not RETRYABLE) fails
TestEveryProblemTypeIsReplayedOrReExecutedByItsClass and the per-class teststhe real middleware over the in-memory store: FINAL and OUTCOME replay, RETRYABLE and every 5xx run again, a 2xx is stored, a panic is not
TestAnUnclassifiedErrorAnswerIsNotStored, TestACopyWaitingOnARetryableFirstRunsItselfan error answer with no class is released; a concurrent duplicate takes a released key over
TestTheADRDeclaresTheClassOfEveryProblemthe class table of ADR 0008 equals the catalogue, both ways
TestHandlersAnswerErrorsOnlyThroughWriteErrorno handler writes a problem by hand, so the class always marks the capture

The repository contract suite (repocontract, memory and Postgres) pins the store side (a released answer stores nothing), and cmd/api/retryable_integration_test.go pins a released concurrent-update and not-found over the real router and Postgres (make integration).

make targets​

TargetRunsIn check / check-all?
make buildgo build ./...check
make vetgo vet ./...check
make fmt / make fmt-checkgofmt -w . / fail if gofmt -l . lists filesfmt-check in check
make lintgolangci-lint run --allow-parallel-runners ./... (v2.14.0; config .golangci.yml, complexity gates)check
make testgo test ./... -race (unit + httptest + godog)check
make coveragego test ./... -race -coverprofile=coverage.out -coverpkg=./internal/domain/...,./internal/application/..., then fails below 90 %check-all
make arch-testgo test ./internal/architecture/... -vcheck-all
make bddgo test ./... -run TestFeatures -vcheck-all
make integrationgo test -tags=integration ./... -race -count=1 (Docker needed)neither (slow)
make mutation / make mutation-fullgremlins per internal/domain/*/ package (-full uses --workers 1 --timeout-coefficient 30)neither
make vulngovulncheck ./...neither
make checkfmt-check vet build lint testthe pre-push gate (lefthook)
make check-allcheck coverage arch-test bddrun before pushing
make check-fastfmt-check vet arch-test plus the tests of packages changed vs HEADthe agent Stop hook
make guide-lint, make harness-testagent-guide lint and the unit tests of scripts/harness/hook.pyCI guide-lint

lefthook: pre-commit runs fmt-check, vet, lint; pre-push runs make check. integration and mutation are deliberately outside the hooks.

CI (.github/workflows/ci.yml)​

Triggers: push and pull request on main and develop, a weekly schedule (Monday 06:00 UTC, for the exhaustive mutation job only) and manual dispatch.

JobWhat it runs
lintgolangci-lint v2.14.0
guide-lintscripts/harness/guide_lint.py and test_hook.py (advisory: continue-on-error)
complexitygolangci-lint restricted to gocyclo, gocognit, cyclop, funlen, nestif, plus an informational gocyclo report
testgo build, go vet, then make coverage (90 % gate), coverage artifact
bddgo test ./... -run TestFeatures -v
integrationgo test -tags=integration ./... -race -count=1 (testcontainers on the runner)
mutation-fastgremlins on every ./internal/domain/*/ package, blocking
mutationthe same with --workers 1 --timeout-coefficient 30, on schedule or dispatch only; opens or closes a harness:red issue
api-lintspectral on apis/openapi.yaml and apis/asyncapi.yaml (--fail-severity=warn)
vulngovulncheck ./...
helm-lintpull requests only: ct lint on charts/customer-payments with both ci/*-values.yaml, then the Service-selector test
chart-testsevery charts/customer-payments/tests/*.sh and test_*.py on every push
arch-testgo test ./internal/architecture/... -v
docker-publishneeds lint, complexity, test, bdd, integration, mutation-fast, vuln, api-lint, arch-test; builds and pushes the image
releaseneeds docker-publish; tags and packages the chart

The documentation site is built by its own workflow, docs.yml (build on pull request, deploy on push to main).

Running one layer​

go test ./internal/domain/... -race # domain only
go test ./internal/application/usecases/ -run TestAuthorize -v
make bdd # the 56 scenario blocks
make integration # Docker required
go test ./cmd/api -count=1 # boot-configuration tests, no containers

When adding behaviour, write the failing godog scenario or domain test first; a new event type also needs its golden file, its entry in apis/asyncapi.yaml and the catalogue test to agree.