Skip to main content

Testing

The test pyramid as it exists in this repository, the make targets that run each layer locally and the CI jobs (.github/workflows/ci.yml) that run them on every push and pull request into develop/main.

Layers​

LayerWhereHow it runsNeeds
Domain unit testsinternal/domain/{asn,appointment,receipt,shared}/*_test.gomake testnothing
Use-case unit testsinternal/application/usecases/*_test.go (fakes in fakes_test.go)make testnothing
Adapter unit testsinternal/adapters/**/*_test.go (httptest handlers, MCP tools + testdata/tool_registry.golden.json, Kafka consumers with fake readers, encoders with golden CloudEvents, relay, telemetry, memory store)make testnothing
Analytics rulesinternal/analytics/report/report_test.go (range parsing, day windows, percentiles, freshness)make testnothing
Composition rootscmd/*/main_test.go (env validation, admin mux, drain delay; the in-memory doubles come from cmd/api/testdoubles_test.go)make testnothing
BDD acceptance (godog)features/*.feature, steps in features_test.go + the sibling features_*_test.go files (rule steps in features_rules_test.go)make bdd (also part of make test)nothing: in-memory adapters behind an httptest server and a stepping clock
Architecture fitnessinternal/architecture/*_test.go (including TestRuntimeBinaryHasNoInMemoryAdapters)make arch-test (also part of make test)nothing
Integration (testcontainers)files with //go:build integration, including cmd/api/e2e_integration_test.go (TestRunOnRealPostgresAndKafka)make integrationDocker
Mutationgremlins over internal/domainmake mutation / make mutation-fullgremlins v0.6.0
Frontend remoteweb/ (vitest + Testing Library)npm test in web/Node 22, sibling warehouse-ui-kit checkout
Chart render testscharts/inbound-receiving/tests/render_test.sh, charts/inbound-receiving/tests/test_service_selectors.pybash .../render_test.sh, python3 .../test_service_selectors.py (CI chart-tests)helm, PyYAML

There are 170 *_test.go files; 32 of them are integration-tagged.

BDD features​

19 feature files, 226 scenario definitions (35 of them Scenario Outlines), which the runner executes as 342 scenarios once every Examples row is expanded (the N scenarios line of go test . -run TestFeatures -count=1 -v). godog runs with Strict: true, so an undefined or pending step fails the suite. BDD-only statement coverage over ./internal/... (go test . -run TestFeatures -count=1 -coverpkg=./internal/...) is 77.5 %.

The four *_rules.feature files pin the rules written in the documentation (canvas invariants, use cases, troubleshooting, ADR 0017, apis/openapi.yaml) one rule per scenario, with boundaries as Outline rows (at the limit accepted, one past it refused).

Feature fileFeatureScenario definitions
register_asn.featureRegister an ASN11
register_asn_cartons.featureRegister an ASN with cartons (ADR 0012)8
asn_timeliness.featureASN timeliness and flat S-O-I ASNs (ADR 0025)8
asn_rules.featureASN rules from the documentation: number, supplier ref, quantity and line-number bounds, cancel and If-Match rules, ASNRegistered / ASNCancelled payloads16
dock_appointments.featureAppointment writes answer 410; the appointments local copy fed by dock-scheduling (ADR 0019)14
receiving.featureReceive goods against an ASN13
receiving_rules.featureReceipt rules from the documentation: discrepancy kinds, running-total bounds, atomic open, receipt events, closed-receipt scans25
receiving_advice.featureReceiving advice at close, with the standard discrepancy vocabulary (ADR 0023)11
carton_receiving.featureReceive cartons by scan (ADR 0012)13
carton_discrepancies.featureCarton discrepancies (ADR 0012, ADR 0014)13
receipt_carton_discrepancies.featureCarton discrepancies are part of the receipt (ADR 0015)4
gs1_label_receiving.featureGS1 logistic-label receiving (ADR 0024)7
dock_to_stock.featureDock-to-stock KPI (ADR 0021)9
feeds_rules.featureLocal copies and dock-to-stock rules from the documentation: appointment and pack-level copies, dock-to-stock edge cases18
dock_door_registry.featureDock-door registry fed by facility-layout10
idempotent_replays.featureIdempotent creating requests6
list_receipts_and_docks.featureListing receipts, appointments and dock doors17
operations_rules.featureOperational rules from the documentation: idempotency, list problem slugs, /readyz, the reports service22
probes.featureHealth probe1
Total226 (342 executed)

Integration suites​

Every integration test boots its own Postgres and/or Kafka through testcontainers; there is no DATABASE_URL, no docker compose and no t.Skip gate (enforced by the fitness tests below).

FileCovers
internal/adapters/outbound/postgres/repositories_integration_test.gorepositories, cursors, version guards, constraints
internal/adapters/outbound/postgres/usecases_integration_test.gouse cases over a real unit of work
internal/adapters/outbound/postgres/analytics_outbox_integration_test.gofan-out rows (integration + analytics) in one transaction
internal/adapters/outbound/postgres/helper_integration_test.goshared container helper
internal/adapters/outbound/postgres/pgtx/pgtx_integration_test.gotransaction propagation through context
internal/adapters/outbound/outbox/relay_integration_test.gorelay draining Postgres to Kafka
internal/adapters/outbound/outbox/relay_cap_integration_test.gorelay attempt cap over real Postgres: a poison row is excluded after N failures and the good row behind it (same key) publishes; the re-arm SQL; 0 = unlimited (ADR 0007)
internal/adapters/outbound/outbox/outbox_trace_integration_test.gotrace continuity across the outbox, real Postgres + Kafka: TestOutboxTrace_TraceparentCrossesTheOutboxToKafka, TestOutboxTrace_RowWithoutTraceHeadersRelaysUnchanged (ADR 0009)
internal/adapters/inbound/http/idempotency_replay_classes_test.go, idempotency_replay_adapter_test.go, idempotency_replay_classes_integration_test.go, replay_catalogue_test.gothe fleet replay-class suite (FINAL stored and replayed, RETRYABLE released so the retry executes, 2xx stored, 5xx and panic never stored, an OUTCOME stand-in keeps its writes) run over the in-memory store and, in the integration build, over Postgres; every problem type declares a class; the ADR 0027 table and the OpenAPI text equal the catalogue; the middleware names no slug (ADR 0027)
internal/adapters/inbound/http/idempotency_retryable_integration_test.gothe real router over Postgres: a genuine optimistic-lock race (concurrent-modification loser has no key row, its retry executes, is stored and replayed), unknown-asn then the ASN arrives under the same key, a FINAL refusal still replayed
internal/adapters/outbound/postgres/sweeper_integration_test.goOLTP housekeeping sweeper: only expired idempotency keys, PUBLISHED outbox rows past retention and old processed_events marks go (unpublished rows of any age stay); multi-batch loop; 0 disables a part; Run sweeps at start and stops on cancel (ADR 0010)
internal/adapters/outbound/analyticsstore/sweeper_integration_test.goanalytics sweeper: expired analytics_processed_events marks go in batches, the newest mark (freshness) always stays; retention / interval 0 disable it
internal/adapters/outbound/kafka/publisher_integration_test.goRelaySink against a real broker
internal/adapters/inbound/kafka/consumers_integration_test.goproduct and dock-door consumers end to end
internal/adapters/inbound/kafka/analytics_consumer_integration_test.goprojector consumer, DLQ
internal/adapters/outbound/analyticsstore/postgres_integration_test.goanalytical store (the same contract test also runs against the in-memory store in contract_test.go)
internal/adapters/inbound/http/rest_api_integration_test.goREST over Postgres
internal/adapters/inbound/mcp/streamable_http_integration_test.goMCP over Streamable HTTP
cmd/mcp/main_integration_test.gothe MCP binary's wiring
cmd/a2a/main_integration_test.gothe A2A binary's wiring: skills over the real router and Postgres, outbox unchanged
internal/application/usecases/usecases_wiring_integration_test.gouse-case wiring
analytics_e2e_integration_test.goapi → outbox → Kafka → projector → reports, end to end

make integration and the integration CI job both run go test -tags=integration ./... -race -count=1, so every tagged package is covered.

Architecture fitness tests​

TestRule
TestHexagonalArchitecturearch-go rules: domain imports nothing internal but itself; layers only point inwards; adapters never import each other
TestMCPAdapterDependencyRulethe MCP adapter depends only on the application and domain layers, and nothing but cmd/mcp imports it
TestA2AAdapterDependencyRule, TestA2AAdapterIsReadOnlyAndHasNoOutboundClient, TestA2AReadOnlyBinaryWiresNoWriteUseCase, TestA2AReadOnlySensorBitesthe A2A adapter depends only on the application and domain layers, nothing imports it but cmd/a2a, and neither it nor the binary names a use case beyond the three reads, an outbox, a unit of work or an outbound A2A client (ADR 0016)
TestNoAuthMiddlewareReintroducedno auth middleware on REST or MCP (fleet rule)
TestKafkaConsumerGroupNeverHardcodedInlineconsumer group ids come from env, never literals
TestReplayConsumersSetCommitIntervala full-replay cache consumer (a per-process unique group) must set CommitInterval; this repo has none, so the rule is dormant
TestCloudEventsOnly, TestNoEventEnvelopeToggleOrFlatEnvelopeevery Kafka message is a CloudEvents 1.0 envelope built by internal/adapters/kafka/cloudevents; no envelope toggle
TestEventCatalogueMatchesContract, TestEventCatalogueDetectorpublished event types match apis/asyncapi.yaml
TestKafkaIntegrationTestsUseTestcontainers, TestPostgresIntegrationTestsUseTestcontainers, TestPostgresIntegrationSensorFailsOnBadFixturesintegration tests use testcontainers, never an external DSN or a skip
TestMCPOptionalToolInputsCarryOmitempty, TestMCPOptionalToolInputsSensorFailsOnBadFixturesevery MCP tool input field whose jsonschema description calls it optional ("optional" or "omitted") carries omitempty, so the SDK does not mark it required (gap fix D16)
TestOutboxRelaysPassAttemptCap, TestOutboxRelayCapSensorFailsOnBadFixturesevery non-test file under cmd/ that builds an outbox relay (NewRelay) passes WithMaxAttempts(...) (ADR 0007)
TestCompositionRootsWireTheHousekeepingSweeper, TestHousekeepingSweeperSensorFailsOnBadFixturescmd/api constructs postgres.NewSweeper and cmd/inbound-projector constructs analyticsstore.NewSweeper (ADR 0010)
TestKafkaWritersSetRequiredAcks, TestKafkaWriterAcksSensorBitesEvery kafka-go Writer composite literal in a non-test file under internal/ or cmd/ sets RequiredAcks (the import alias is resolved per file). kafka-go defaults it to RequireNone (acks=0): the broker never confirms the write, so a broker blip silently drops the message while WriteMessages returns nil. The twin proves the sensor flags a bad fixture under any alias.
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.)

violation_test.go holds deliberately failing fixtures that prove the detectors work.

Mutation testing​

.gremlins.yaml: workers: 1, timeout-coefficient: 30, thresholds efficacy: 99 and mutant-coverage: 99 (gremlins fails when the measured value is ≤ the threshold). The file records the 2026-10-08 measurement: shared 12 mutants, asn 52, appointment 38, receipt 57, all 100 % efficacy and coverage, so a single surviving mutant fails the gate.

  • make mutation: gremlins on each of ./internal/domain/{receipt,asn,appointment,shared}.
  • make mutation-full: gremlins unleash ./internal/domain --workers 1 --timeout-coefficient 30.

Not present​

  • Contract tests against a running server (schemathesis): none in this repo. The REST contract is guarded by Spectral linting (api-lint), the docs-api-drift job and the handler tests; the event contract by TestEventCatalogueMatchesContract and golden CloudEvents tests.
  • Evals: EVALS.md and tools/harness_eval*.py measure the agent harness (run against other fleet repos), not this service's behaviour; no CI job runs them.

Make targets​

TargetCommand
make testgo test ./... -race
make coveragego test ./... -race -coverprofile=coverage.out -coverpkg=./internal/domain/...,./internal/application/... + a 90 % gate
make bddgo test ./... -run TestFeatures -v
make arch-testgo test ./internal/architecture/... -v
make integrationgo test -tags=integration ./... -race -count=1
make mutation / make mutation-fullsee above
make vulngovulncheck ./...
make checkfmt-check vet build lint test (lefthook pre-push runs it)
make check-allcheck + coverage arch-test bdd
make check-fastfmt-check vet arch-test + tests of changed packages (agent Stop hook)
make guide-lint / make harness-testlint the agent guides / test the agent hooks

lefthook (lefthook.yml) runs fmt-check, vet and lint on pre-commit and make check on pre-push.

CI jobs (ci.yml)​

JobRunsWhen
lintgolangci-lint v2.14.0push + PR
guide-lintscripts/harness/guide_lint.py, test_hook.py (advisory, continue-on-error)push + PR
complexitygolangci-lint with only gocyclo,gocognit,cyclop,funlen,nestif + an informational gocyclo reportpush + PR
testbuild, vet, then make coverage (go test ./... -race with the Makefile's coverage scope, domain + application, and the 90 % gate)push + PR
bddgo test ./... -run TestFeatures -vpush + PR
integrationgo test -tags=integration ./... -race -count=1 (testcontainers on the runner's Docker)push + PR
mutation-fastgremlins on each domain package (blocking)push + PR
mutationgremlins on ./internal/domain; opens/closes a harness:red issueschedule (Mon 06:00 UTC) + dispatch
driftdeadcode, go mod tidy -diff, knip on web/, coverage-quality (advisory)schedule + dispatch
api-lintSpectral on apis/openapi.yaml and apis/asyncapi.yaml (--fail-severity=warn)push + PR
vulngovulncheckpush + PR
helm-lintct lint + charts/inbound-receiving/tests/test_service_selectors.pyPR only
chart-testsbash charts/inbound-receiving/tests/render_test.sh (api Deployment mounts the ConfigMap via envFrom, OUTBOX_MAX_ATTEMPTS default, ENVIRONMENT on every backend Deployment) + test_service_selectors.pypush + PR
docs-api-driftnpm run clean-api-docs && npm run gen-api-docs, fails on a diff under docs/api-reference/restpush + PR
webin web/: npm run lint, npx tsc -b, npm test, npm run build (after building warehouse-ui-kit from its develop)push + PR
arch-testgo test ./internal/architecture/... -vpush + PR
trivy-scanbuilds the image, Trivy SARIF upload + blocking gate on CRITICAL/HIGH with a fixPR only
docker-publishbuild, push to GHCR, cosign sign, SBOM attestpush to main
releaseversion tag, Helm chart package, GitHub releasepush to main after docker-publish

Other workflows: docs.yml builds this site on PRs touching docs/** or apis/** and publishes to GitHub Pages only from main; selftest.yml tests the harness scripts; ai-review.yml posts an advisory architecture review on PRs into develop that touch domain, application, apis/ or charts/.