Skip to main content

Testing

The pyramid​

LayerWhereHow it runsRun it
Unit*_test.go next to the code (no build tag): domain aggregates, use cases with fakes (internal/application/usecases/fakes_test.go), HTTP handlers via httptest, encoders, relay/consumer logic with fake writersIn-process, in-memory adapters, -racemake test
BDD (godog)20 files in features/ with 153 Scenario/Scenario Outline blocks (268 executed with Examples rows expanded), driven by features_test.go (TestFeatures)Black-box over HTTP against the real chi router wired to the in-memory repositories, a fixed clock and a recording publisher, so scenarios assert responses and the domain events raisedmake bdd
Contractscripts/contract-test.sh; internal/adapters/inbound/http/reports_contract_test.goBuilds cmd/pathmgmt, boots it on real Postgres 16 and Kafka (DATABASE_URL + KAFKA_BROKERS; docker-compose.yml locally, service containers in CI) on 127.0.0.1:18085, waits for /readyz, runs Schemathesis 4.28.0 against apis/openapi.yaml (100 examples per operation, 4 workers, --generation-allow-x00 false, a hook gives each Idempotency-Key request a fresh key; ADR 0037). The reports router is checked against apis/openapi-reports.yaml by Go tests (ADR 0031)make contract; the Go tests run in make test
Integration26 files tagged //go:build integration (25 under internal/adapters/..., plus internal/application/usecases/usecases_wiring_integration_test.go)Each test starts its own Postgres 16 and/or Kafka with testcontainers-go; no DATABASE_URL, no composemake integration (needs Docker)
Architecture fitnessinternal/architecture/Static checks over the source tree and import graphmake arch-test
MCP evalsinternal/adapters/inbound/mcp/eval_*_test.go, evalsuite_test.go, testdata/features/mcp_tools.feature (14 scenarios)In-process MCP client/server sessionsgo test ./internal/adapters/inbound/mcp/... -race -run '^TestEval|^TestMCPEvalSuite' -v
Mutation.gremlins.yamlgremlins v0.6.0 over ./internal/domainmake mutation-fast (alias make mutation)
Chartcharts/process-path-management/tests/render_test.sh, test_service_selectors.pyhelm template assertions: the api Deployment mounts the ConfigMap via envFrom (D14), OUTBOX_MAX_ATTEMPTS (ADR 0030), a zero housekeeping interval, the analytics pods' LOG_LEVEL/ENVIRONMENT/SERVICE_VERSION (ADR 0029); each Service selects exactly one Deploymentmake chart-test (helm + PyYAML)
Frontendweb/ESLint, tsc -b, the remote's own tests, Vite buildcd web && npm run lint && npx tsc -b && npm test && npm run build

BDD features​

20 feature files hold 153 Scenario/Scenario Outline blocks (33 of them outlines; git grep -c -E "^[[:space:]]*Scenario" -- features). With the Examples rows expanded, make bdd runs 268 scenarios and 2001 steps (268 scenarios (268 passed), 2001 steps (2001 passed), godog's own summary from go test . -run TestFeatures -count=1 -v). The suite found no divergence between the specification and the code, so no scenario is a known bug.

FileScenariosExecutedCovers
features/case_flow_paths.feature1012The full-case and cross-dock process paths
features/catalogue_growth_report.feature66The catalogue growth report from the analytics topic
features/cpt_rules.feature1239CPTSchedule rules from the aggregate design: every cutoff field invariant (localTime, days, shipMethod, eligible paths, cptId), IANA timezone accepted and refused, the documented check order, cptId unique per site only, every single-field change republishes the full snapshot
features/cpt_schedule.feature77Define and get a site schedule, 404 before definition, unknown or deactivated path in a cutoff, duplicate cptId, unrecognised timezone
features/cpt_schedule_boundaries.feature79Site-scoped CPT schedules, revision, validation and path protection
features/deactivate.feature55Deactivate, idempotent re-deactivate, 404, 409 while a CPT schedule lists the path, success once the schedule no longer lists it
features/define_and_read.feature55Define a path, read it back, 404 for an unknown id, duplicate id rejected, list returns only active paths by default
features/define_boundaries.feature34Define-time boundaries of a path definition
features/define_validation.feature66Empty and upper-case matchPrefix, no capabilities, unknown destinationLocationRole, a declared role and eligibility carried on the path
features/list_and_problems.feature55Listing paths and unknown-path problems
features/path_rules.feature3293ProcessPath rules from the aggregate design: PathId case-sensitivity, matchPrefix, destinationLocationRole and cycleTimeP95 rules, eligibility and intake as sets, what a Revise changes (13 single-field rows) and what is a no-op, deactivation and the CPT protection (ADR 0026), list paging (limits, cursors)
features/process_path_intake.feature814Intake (ADR 0034): define/read/publish, [] on the wire when absent, 422 invalid-intake for an unknown or repeated source, intake-only revise publishes ProcessPathUpdated, an omitted intake is kept, [] clears it, and the declared intake of PICK/PACK/REBIN/SLAM/RELOCATE/DISPATCH/REPLENISH (outline)
features/published_events.feature55Published events on the wire
features/relocate_path.feature44The declared RELOCATE entry: defined Active, published with intake SLOT_RELOCATION and no fake eligibility, re-seed refused 409, sits beside PICK
features/replenish_path.feature66The declared REPLENISH entry (ADR 0036): defined Active, published with intake REPLENISHMENT, re-seed refused 409, sits beside PICK, REPLENISHMENT accepted and a near miss rejected 422 invalid-intake
features/republish_catalogue.feature33Republishing the current catalogue at startup
features/revise.feature33Revise an Active path, 404 for an unknown id, a deactivated path rejects revision
features/revise_and_events.feature66ProcessPathCreated/Updated/Deactivated published (deactivation exactly once), no-op revision publishes nothing, malformed cycleTimeP95, re-defining a deactivated id rejected
features/revise_boundaries.feature45Revision boundaries and what a revision publishes
features/runtime_rules.feature1631Runtime failure modes and the analytics projection: SIGTERM flips /readyz to 503 not_ready while /healthz stays 200, unreachable Postgres/Kafka are 503 dependency-unavailable, a database outage is 500 internal-error, 409 concurrent-modification and path-already-exists, report query errors, the projector's dispatch on the full event type and dedupe on the CloudEvents id
20 files153268

path_rules.feature, cpt_rules.feature and runtime_rules.feature pin the rules written in the documentation (their steps are in steps_rules_test.go).

Contract test exclusions​

scripts/contract-test.sh disables two Schemathesis checks, each documented in the script:

  • positive_data_acceptance: the API correctly returns 422 for schema-valid data that OpenAPI 3.0.3 cannot express (lower-case matchPrefix, positive cycleTimeP95, IANA timezone, Active-only revise and eligiblePathIds). Each rule is covered by a BDD scenario and a unit test.
  • use_after_free: DELETE /process-paths/{pathId} is a soft, idempotent retirement; GET after DELETE returns 200 with status: DEACTIVATED by design.

Schemathesis runs only against the REST API in apis/openapi.yaml. The reports routes are contract-tested in Go instead: TestReportsContract_RoutesMatchSpec walks the real chi router and fails when a served route is missing from apis/openapi-reports.yaml (or the reverse); TestReportsContract_ResponsesMatchSpec drives every documented status (200/400/500) and fails on an undeclared status or media type, a missing required property or an undocumented one. MCP has no Schemathesis coverage (it has the evals instead).

Integration tests​

AreaFiles (all internal/adapters/...)What they prove against real infrastructure
Postgres repositoriesoutbound/postgres/process_path_repo_integration_test.go, process_path_create_integration_test.go, cpt_schedule_repo_integration_test.go, intake_integration_test.go, integration_test.goMapping, insert-only create, schedule persistence; the intake column (migration 0009) round-trips, a pre-0009 row reads as [], an unknown stored value fails the read (TestPostgres_IntakeRoundTrip, TestPostgres_RowWithoutIntake_ReadsAsTheEmptySet, TestPostgres_UnknownStoredIntake_FailsTheRead, ADR 0034)
Concurrencydefine_concurrent_integration_test.go, version_integration_test.go, process_path_locks_integration_test.go, cpt_path_race_integration_test.go, deactivate_cpt_integration_test.goDuplicate-create race, optimistic version column, FOR UPDATE/FOR SHARE serialisation of deactivate vs CPT schedule (ADR 0028)
Outboxoutbox_integration_test.go, analytics_outbox_integration_test.go, outbox_trace_integration_test.go, outbox_trace_kafka_integration_test.goTwo rows per event, relay ordering and retry, the attempt cap (TestOutboxRelay_MaxAttempts_PoisonRowIsExcludedAndTheNextRowPublishes, TestOutboxRelay_WithoutMaxAttempts_RetriesWithoutBound, ADR 0030), trace context stored and sent, and end to end through a real broker (TestOutboxTrace_TraceparentCrossesTheOutboxToKafka, TestOutboxTrace_RowWithoutTraceHeadersRelaysUnchanged, gap fix D27)
Housekeeping and poolssweeper_integration_test.go, pool_limits_integration_test.goBatch deletes, MaxConns and statement_timeout actually applied
Idempotencyinbound/http/idempotency_integration_test.goReplay, key reuse 409, concurrent same-key requests
Kafkaoutbound/kafka/publisher_balancer_integration_test.go, inbound/kafka/analytics_consumer_integration_test.go, analytics_consumer_dlq_integration_test.go, analytics_shutdown_integration_test.go, analytics_atomic_claim_integration_test.goSame key → same partition, projector end to end, DLQ routing, clean shutdown without dead-lettering, and claim + apply in one transaction (TestAnalyticsConsumer_CrashBetweenClaimAndApply_RedeliveryAppliesExactlyOnce: the projector stops after the claim and before the apply commits; no claim is left and the redelivery applies the event exactly once, ADR 0032)
Runtimecmd/pathmgmt/e2e_integration_test.go (TestRunOnRealPostgresAndKafka)Boots the real run() in-process on testcontainers Postgres + Kafka with nothing but the deployment's environment; REST only; asserts rows, outbox drain, CloudEvents on both topics, Idempotency-Key replay, NUL guard, restart, /readyz following the dependencies
Analytics storeoutbound/analyticsstore/postgres_integration_test.go, unit_of_work_integration_test.goProjection idempotency, report query, freshness on an empty store; the analytics UnitOfWork rolls back the consumer claim, the projection claim and the rollup row together (TestUnitOfWork_ClaimAndProjectionRollBackTogether, TestUnitOfWork_CommitsClaimAndProjectionAndJoinsNestedScope)

The fitness tests TestPostgresIntegrationTestsUseTestcontainers and TestKafkaIntegrationTestsUseTestcontainers fail the build if an integration test gates on DATABASE_URL/KAFKA_BROKERS or hardcodes localhost:9092, because a skip-gated test silently proves nothing in CI.

Architecture fitness tests​

TestEnforces
TestHexagonalArchitecture (architecture_test.go, arch-go)domain → nothing; application → domain; adapters inward only
TestMCPAdapterDependencyRuleinternal/adapters/inbound/mcp depends only on application and domain, and nothing imports it except cmd/mcp
TestNoAuthMiddlewareReintroducedNo bearer/JWT middleware in internal/adapters/inbound (ADR 0005)
TestNoSiblingContextOutboundCalls (+ _DetectsViolation)No REST/MCP client to another fleet context
TestRuntimeBinaryHasNoInMemoryAdapters (+ TestRuntimeBinarySensorBites, runtime_no_memory_fitness_test.go)No non-test file under cmd/** imports internal/adapters/outbound/memory: the binaries run only on real Postgres and Kafka (ADR 0037)
TestKafkaConsumerGroupNeverHardcodedInlineConsumer GroupID comes from a named symbol, never an inline literal
TestKafkaIntegrationTestsUseTestcontainers, TestPostgresIntegrationTestsUseTestcontainers (+ _DetectsViolation)See above
TestEventCatalogueMatchesContract, TestEventCatalogueDetector (catalogue_fitness_test.go)The CloudEvents types in the code match the event catalogue declared in apis/asyncapi.yaml
TestCloudEventsOnly, TestReplayConsumersSetCommitInterval (events_fitness_test.go)CloudEvents 1.0 is the only envelope (no envelope-mode switch); a Kafka reader whose group id is generated per instance must set a commit interval
TestOutboxRelaysPassAttemptCap (+ TestOutboxRelayCapSensorFailsOnBadFixtures, outbox_relay_cap_fitness_test.go)Every non-test cmd/ call to NewOutboxRelay passes WithMaxAttempts (ADR 0030)
TestKafkaWritersSetRequiredAcks (+ TestKafkaWriterAcksSensorBites, kafka_writer_acks_fitness_test.go)Every kafka-go Writer literal in a non-test file under internal/ or cmd/ sets RequiredAcks (publishers use syncWriterRequiredAcks, the analytics DLQ writer kafkago.RequireAll): kafka-go defaults to RequireNone (acks=0), which silently drops a write on a broker blip while WriteMessages returns nil (fleet rollout 2026-10-13)
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.)
TestMCPOptionalToolInputsCarryOmitempty (+ TestMCPOptionalToolInputsSensorFailsOnBadFixtures, mcp_optional_inputs_test.go)An MCP tool input field whose jsonschema description says "optional" carries omitempty, so the SDK does not mark it required (gap fix D16)

MCP evals​

TestEval_* (governance: input schemas resolve and constrain, every parameter described, tool registry matches a golden list, fleet-unique tool names, conditional tools pinned), TestEvalConformance_* (wire: initialize handshake, unknown tool / wrong-typed / extra arguments rejected, no resources or prompts, session close) and TestMCPEvalSuite (behavioural scenarios from mcp_tools.feature). See ADR 0023 and the Governance charter.

Mutation testing​

.gremlins.yaml: workers: 1, timeout-coefficient: 30, thresholds efficacy: 99 and mutant-coverage: 99 (gremlins fails when the measured value is at or below the threshold, so any surviving mutant fails the job). When the thresholds were set (2026-09-05) the domain produced 11 mutants, all in internal/domain/processpath, all killed. The README records a re-measurement on 2026-09-25, after cptschedule and shared joined the domain layer: 63 mutants, all killed.

Make targets​

TargetRuns
make buildgo build ./...
make vetgo vet ./...
make fmt / make fmt-checkgofmt -w . / fail if gofmt -l . lists files
make lintgolangci-lint run ./... (CI pins v2.14.0)
make testgo test ./... -race
make coveragego test ./... -race -coverprofile=coverage.out -coverpkg=./internal/domain/...,./internal/application/...,./internal/analytics/... and a 90 % gate
make bddgo test ./... -run TestFeatures -v
make arch-testgo test ./internal/architecture/... -v
make integrationgo build, go vet and go test -tags=integration ./... -race -count=1
make mutation-fast / make mutationgremlins unleash ./internal/domain --workers 1 --timeout-coefficient 30
make api-lintSpectral on apis/openapi.yaml and apis/openapi-reports.yaml (.spectral.yaml) and apis/asyncapi.yaml (.spectral.asyncapi.yaml), --fail-severity=warn
make chart-testbash charts/process-path-management/tests/render_test.sh and python3 charts/process-path-management/tests/test_service_selectors.py
make vulngovulncheck ./...
make contract./scripts/contract-test.sh
make checkfmt-check vet build lint test (the lefthook pre-push gate)
make check-allcheck + coverage + arch-test + bdd
make check-fast, make guide-lint, make harness-testAgent-harness gates (scripts/harness/)
make catalogue-testpython3 scripts/test_seed_catalogue.py: the declared-catalogue seed against an in-process fake API (ADR 0033)
make seed-catalogue BASE_URL=... [SEED_ARGS=--dry-run]applies catalogue/paths.json to a running service through the REST API (not a test; see the runbook)

The declared catalogue (catalogue/paths.json, ADR 0033) has its own tests: internal/domain/processpath/declared_catalogue_test.go defines every entry through the aggregate, requires an intake array on every entry, pins the per-path intake table and exactly one CUSTOMER_ORDER entry point (PICK, ADR 0034), and pins RELOCATE and DISPATCH (ADR 0035) and REPLENISH (ADR 0036) field by field; internal/adapters/outbound/kafka/relocate_golden_test.go, dispatch_golden_test.go and replenish_golden_test.go pin the ProcessPathCreated CloudEvent of RELOCATE, DISPATCH and REPLENISH byte for byte on both streams; internal/adapters/outbound/postgres/declared_catalogue_replenish_integration_test.go (integration build tag, testcontainers) defines the declared REPLENISH entry through Postgres, the outbox and a real Kafka broker and decodes the result with a copy of wes-work-planning's catalogue payload; features/relocate_path.feature and features/replenish_path.feature (step the client defines the declared catalogue entry "<id>" in features_catalogue_test.go) posts the file's bytes through the real router; and scripts/test_seed_catalogue.py covers every row of the seed's convergence table (it also runs in the CI guide-lint job).

The Makefile is the single source of the coverage scope and threshold (gap 16d): the CI test job runs make coverage instead of its own go test -coverpkg=... command, which had drifted to ./internal/domain/...,./internal/application/... only (it left out ./internal/analytics/...). repo_lint.py rule R11 (CI guide-lint job) fails a PR whose workflow passes -coverpkg itself, or whose Makefile gate no workflow runs. Measured on this change: Coverage: 98.7% (gate: 90%).

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

Triggers: push and pull request to main, develop; weekly schedule (Monday 06:00 UTC); manual dispatch.

JobRunsWhen
lintgolangci-lint v2.14.0every run
guide-lintscripts/harness/guide_lint.py, repo_lint.py (R1-R7 and R11; R11 = coverage scope only in the Makefile), test_hook.py, test_repo_lint.pyevery run
complexitygolangci-lint --enable-only gocyclo,gocognit,cyclop,funlen,nestif, plus an informational gocyclo report (> 10)every run
testbuild, vet, gofmt, then make coverage (unit tests with the Makefile's coverage scope and 90 % gate)every run
bddgo test ./... -run TestFeatures -vevery run
contractSchemathesis via scripts/contract-test.shevery run
evals-testsgo test ./internal/adapters/inbound/mcp/... -race -run '^TestEval|^TestMCPEvalSuite' -vevery run
integrationgo test -tags=integration ./... -race -count=1 (testcontainers on the runner's Docker)every run
mutation-fastgremlins over ./internal/domainevery run
api-lintSpectral on the three specsevery run
vulngovulncheck v1.8.0every run
arch-testgo test ./internal/architecture/... -vevery run
docs-api-driftin docs/: npm ci, npm run clean-api-docs:all && npm run gen-api-docs:all, then fails on any git status --porcelain change under docs/api-reference/rest or rest-reportsevery run
chart-testshelm v3.16.4 + PyYAML 6.0.3: render_test.sh and test_service_selectors.pyevery run
webchecks out warehouse-ui-kit develop, builds it, then lint, tsc -b, tests and build of web/every run
driftdeadcode, go mod tidy -diff, knip, coverage-quality; opens/closes a harness:red issueschedule and dispatch only (advisory)
helm-lintct lint on the chartPRs into main only
trivy-scanbuilds the image, Trivy SARIF + blocking CRITICAL/HIGH gatePRs into main only
docker-publishbuild, push to GHCR, cosign sign, SBOM attestpush to main only
releasetag, versioned image, Helm chart to oci://ghcr.io/iqvopush to main after docker-publish

Other workflows: docs.yml builds this Docusaurus site on pull requests touching docs/** or apis/** (build only, gap fix D25) and builds and deploys GitHub Pages on push to develop; codeql.yml; scorecard.yml (OpenSSF); ai-review.yml (advisory).

Before you push​

make check-all # what the pre-push hook runs, plus coverage/arch/bdd
make integration # if you touched an adapter (needs Docker)
make contract # if you touched the REST API or apis/openapi.yaml
make chart-test # if you touched charts/ (needs helm + PyYAML)
cd docs && npm ci && npm run build # if you touched docs/