Skip to main content

Testing

The test pyramid as it is on this branch: a pure domain under a mutation gate, use cases and adapters with unit and httptest tests, a godog BDD suite that drives the real router and the real consumers over in-memory doubles, testcontainers integration tests against real Postgres and Kafka, architecture fitness tests, spec linting and chart tests.

LayerCount / thresholdCommand
Unit, domain107 top-level test functions in 7 packages (purchaseorder 36, shared/gs1 26, inbound 19, vendor 8, network 7, submission 7, shared 4)make test
Unit, application60 in internal/application/{usecases,requests,gateway} (53 + 5 + 2)make test
Unit and httptest, adapters and cmd/*inbound/kafka 40, inbound/http 32, inbound/mcp 25, inbound/a2a 16, outbound/kafka 18, outbound/outbox 12, outbound/telemetry 11, outbound/httpclient 8, outbound/memory 8, kafka/cloudevents 6, outbound/postgres 3, requestlog 4, ids 2, clock 1, cmd/a2a 15, cmd/api 14, cmd/mcp 12, bootretry 6make test
Coverage gate90 % over ./internal/domain/...,./internal/application/... (COVERAGE_THRESHOLD in the Makefile)make coverage
BDD (godog / Gherkin)20 feature files, 152 scenario definitions (Scenario and Scenario Outline blocks), 230 executed with the Examples rows, 1841 executed stepsmake bdd
Integration (testcontainers)20 top-level tests behind //go:build integration: cmd/api 2, cmd/mcp 2, cmd/a2a 2, inbound/kafka 1, outbound/kafka 1, outbound/outbox 5, outbound/postgres 7make integration
Architecture fitness32 top-level test functions in internal/architecturemake arch-test
Mutation (gremlins)efficacy 99, mutant coverage 99 (.gremlins.yaml, pinned v0.6.0); the file records 100 % / 100 % measured for network, purchaseorder, shared, submission and vendor on 2026-10-23make mutation, make mutation-full
Spec linting (Spectral)apis/openapi.yaml and apis/asyncapi.yaml, --fail-severity=warnCI api-lint
Chart testscharts/vendor-connectivity/tests/render_test.sh and test_service_selectors.pyCI chart-tests
Web remotelint, tsc -b, npm test and npm run build in web/CI web
Contract (consumer-driven or schemathesis)none: no Pact or schemathesis configuration and no CI job. Consumed event shapes are pinned by tests that restate the producers' payloads as raw JSON, and TestEventCatalogueMatchesContract ties the published catalogue to apis/asyncapi.yamlnone
Evalsnone: EVALS.md is the harness template's note; it measures nothing in this reponone

Counts come from ^func Test per package on this commit (test files only, integration files counted separately); many tests are table-driven, so the number of cases is larger. Run go test ./... -v for the cases.

Make targets​

Every target mirrors a CI job; the Makefile is the only definition of the coverage scope.

TargetRunsNotes
make helpprints the target listdefault target
make buildgo build ./...compiles the three binaries
make vetgo vet ./...
make fmt / make fmt-checkgofmt -w . / fail if gofmt -l . is non-empty
make lintgolangci-lint run --allow-parallel-runners ./...pinned v2.14.0, config .golangci.yml
make testgo test ./... -raceunit, httptest and BDD (the godog runner is a normal Test function); no database needed
make coveragego test ./... -race -coverprofile=coverage.out -coverpkg=./internal/domain/...,./internal/application/..., then the 90 % gateThe CI test job runs exactly this
make arch-testgo test ./internal/architecture/... -v
make bddgo test ./... -run TestFeatures -vthe runner is internal/bdd/bdd_test.go; the module root holds no Go file
make integrationgo test -tags=integration ./... -race -count=1needs only Docker: each test boots its own Postgres and Kafka. Not part of check
make mutationgremlins unleash on each package under ./internal/domain/*/the fast, blocking subset
make mutation-fullgremlins unleash ./internal/domain --workers 1 --timeout-coefficient 30the exhaustive scheduled run
make vulngovulncheck ./...
make checkfmt-check vet build lint testthe pre-push hook (lefthook) runs this
make check-allcheck coverage arch-test bddrun before pushing

Unit tests​

  • Domain (internal/domain/*): pure Go, no fixtures. They pin the aggregate invariants: the vendor account's 1 h to 24 h acknowledgement window and its suspend/reinstate states, the purchase order's full-acknowledgement, window, label and confirmation rules, the submission's one-outcome rule, GS1 check digits and SSCC/GTIN parsing (shared/gs1), and the ordered domain events.
  • Use cases (internal/application/usecases): run against the in-memory adapters (internal/adapters/outbound/memory), which are test doubles only: the shipped binaries never import them (TestRuntimeBinaryHasNoInMemoryAdapters). The repository contract (internal/adapters/outbound/repocontract) is one shared suite run against both the memory store and Postgres.
  • HTTP adapter: httptest over the real router: handler groups, the idempotency capture (replay, reuse, rollback on 5xx and on a RETRYABLE refusal, the replay class of every problem type), NUL rejection, readiness, telemetry.
  • Kafka consumers: a fake Reader drives the run loop (consume_loop_test.go: retry, backoff, dead-letter after 5 attempts, no commit before success), plus deadletter_* tests and per-consumer tests whose fixtures restate the producers' contracts as raw JSON.
  • Outbox relay: ordering, the attempt cap (relay_cap_test.go) and the ERROR record with outbox_id for a capped row.
  • MCP and A2A: tool and skill outputs, read-only governance (internal/adapters/inbound/mcp/governance_test.go), the Agent Card (internal/adapters/inbound/a2a/card_test.go: no streaming, no security schemes).
  • cmd/*: env parsing and boot configuration, shutdown order, telemetry bring-up.

Run one package or one test:

go test ./internal/domain/purchaseorder -v
go test ./internal/adapters/inbound/kafka -run TestConsumeLoop -v

BDD (godog)​

features/*.feature holds twenty files; the runner is internal/bdd/bdd_test.go (TestFeatures, Strict: true, path ../../features). It drives the real chi router over HTTP and feeds the local copies and the releases through the real consumers' HandleMessage with raw CloudEvents, on the in-memory doubles wired the way cmd/api wires the real adapters. BDD_TAGS selects scenarios; the default is ~@known-bug (a scenario tagged @known-bug states a spec behaviour the code does not meet and must fail when run alone; none is tagged today).

Definitions are the Scenario and Scenario Outline lines (git grep -c -E "^[[:space:]]*Scenario" -- features, an Outline counts once); executed adds one run per Examples row and is the N scenarios line of make bdd.

Feature fileDefinitionsExecuted
purchase_order_lifecycle.feature1212
node_and_inventory_transactions.feature99
inbound_shipments_and_receipts.feature88
vendor_accounts.feature88
node_profile_and_scorecard.feature77
labels_and_shipment.feature55
polling_pagination.feature33
release_withdrawn.feature33
simulation_knobs.feature22
release_policy_rules.feature1735
submission_rules.feature1423
label_shipment_rules.feature1229
acknowledgement_rules.feature1126
vendor_account_rules.feature918
acknowledgement_window_rules.feature88
poll_rules.feature811
read_model_rules.feature55
inbound_rules.feature411
transaction_outcome_rules.feature44
rate_limit_rules.feature33
Total152230

The first nine files are the original suite (57), written from the OpenAPI contract and coverage gaps; the eleven *_rules files pin the documented rules: the acknowledgement window and its sweep, transaction outcomes, fill-or-kill acknowledgement, labels and shipment confirmation, vendor accounts and suspension, the release policies, submission retries and retention, polling, the node and packaging read models, inbound receipts and the rate limit.

Step files: steps_test.go, steps_inbound_test.go, steps_wave2_test.go, steps_withdrawn_test.go, steps_rules_test.go.

Integration tests​

Every integration test boots its own containers through internal/testing/pgtest and internal/testing/kafkatest; there is no DATABASE_URL, no docker compose and no t.Skip gate (TestPostgresIntegrationTestsUseTestcontainers and TestKafkaIntegrationTestsUseTestcontainers enforce it). They cover the Postgres repositories against the shared contract, the transactional outbox and relay (including the attempt cap), the consumers against a real broker, and the three binaries end to end (cmd/api/e2e_integration_test.go and the main_integration_test.go files).

Architecture fitness tests​

internal/architecture (32 test functions) enforces what the layout promises:

  • TestHexagonalArchitecture, TestMCPAdapterDependencyRule, TestA2AAdapterDependencyRule: the dependency rule between domain, application and adapters.
  • TestRuntimeBinaryHasNoInMemoryAdapters: cmd/** never imports the memory adapter or repocontract.
  • TestNoGoFilesAtRepoRoot: Go files live under cmd/ and internal/.
  • TestNoAuthMiddlewareReintroduced: no auth middleware on REST, MCP or A2A.
  • TestA2AAgentIsReadOnly, TestMCPOptionalToolInputsCarryOmitempty: the agent surfaces stay read-only and their optional inputs stay optional.
  • TestCloudEventsOnly, TestNoEventEnvelopeToggleOrFlatEnvelope, TestEventCatalogueMatchesContract: CloudEvents 1.0 only, and the event catalogue equals apis/asyncapi.yaml.
  • Kafka hygiene: consumer groups never hard-coded (TestKafkaConsumerGroupNeverHardcodedInline), writers set RequiredAcks, never set the topic twice, dead-letter calls guard cancellation, and relays pass the attempt cap.

Most sensors have a companion ...SensorBites / ...FailsOnBadFixtures test that proves the sensor fails on a bad fixture.

Mutation testing​

.gremlins.yaml: one worker, timeout coefficient 30, efficacy and mutant coverage thresholds 99 (gremlins fails at or below the threshold). make mutation runs every package matched by ./internal/domain/*/; make mutation-full runs ./internal/domain whole.

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

JobWhat it runsWhen
lintgolangci-lint v2.14.0push, PR
guide-lintscripts/harness/guide_lint.py, test_hook.pyadvisory (continue-on-error)
complexitygocyclo, gocognit, cyclop, funlen, nestifpush, PR
file-lengthrevive file-length budget (300 code lines)blocking on PRs into develop, informational otherwise
testbuild, vet, make coveragepush, PR
bddgo test ./... -run TestFeatures -vpush, PR
integrationgo test -tags=integration ./... -race -count=1push, PR
mutation-fastgremlins on every ./internal/domain/*/push, PR
mutationgremlins on ./internal/domainschedule, manual
driftdeadcode, go mod tidy -diff, knip, coverage-qualityschedule, manual (advisory)
api-lintSpectral on both specspush, PR
vulngovulncheck ./...push, PR
helm-lintct lint and the service-selector testPR only
chart-testsevery charts/vendor-connectivity/tests/*.sh and test_*.pypush, PR
arch-testgo test ./internal/architecture/... -vpush, PR
weblint, tsc -b, tests and build of web/push, PR
docker-publish, releaseimage to GHCR (cosign-signed) and a GitHub release with the chartpush to main only

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