Testing
The pyramid
| Layer | Where | How it runs | Run 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 writers | In-process, in-memory adapters, -race | make 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 raised | make bdd |
| Contract | scripts/contract-test.sh; internal/adapters/inbound/http/reports_contract_test.go | Builds 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 |
| Integration | 26 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 compose | make integration (needs Docker) |
| Architecture fitness | internal/architecture/ | Static checks over the source tree and import graph | make arch-test |
| MCP evals | internal/adapters/inbound/mcp/eval_*_test.go, evalsuite_test.go, testdata/features/mcp_tools.feature (14 scenarios) | In-process MCP client/server sessions | go test ./internal/adapters/inbound/mcp/... -race -run '^TestEval|^TestMCPEvalSuite' -v |
| Mutation | .gremlins.yaml | gremlins v0.6.0 over ./internal/domain | make mutation-fast (alias make mutation) |
| Chart | charts/process-path-management/tests/render_test.sh, test_service_selectors.py | helm 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 Deployment | make chart-test (helm + PyYAML) |
| Frontend | web/ | ESLint, tsc -b, the remote's own tests, Vite build | cd 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.
| File | Scenarios | Executed | Covers |
|---|---|---|---|
features/case_flow_paths.feature | 10 | 12 | The full-case and cross-dock process paths |
features/catalogue_growth_report.feature | 6 | 6 | The catalogue growth report from the analytics topic |
features/cpt_rules.feature | 12 | 39 | CPTSchedule 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.feature | 7 | 7 | Define and get a site schedule, 404 before definition, unknown or deactivated path in a cutoff, duplicate cptId, unrecognised timezone |
features/cpt_schedule_boundaries.feature | 7 | 9 | Site-scoped CPT schedules, revision, validation and path protection |
features/deactivate.feature | 5 | 5 | Deactivate, idempotent re-deactivate, 404, 409 while a CPT schedule lists the path, success once the schedule no longer lists it |
features/define_and_read.feature | 5 | 5 | Define a path, read it back, 404 for an unknown id, duplicate id rejected, list returns only active paths by default |
features/define_boundaries.feature | 3 | 4 | Define-time boundaries of a path definition |
features/define_validation.feature | 6 | 6 | Empty and upper-case matchPrefix, no capabilities, unknown destinationLocationRole, a declared role and eligibility carried on the path |
features/list_and_problems.feature | 5 | 5 | Listing paths and unknown-path problems |
features/path_rules.feature | 32 | 93 | ProcessPath 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.feature | 8 | 14 | Intake (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.feature | 5 | 5 | Published events on the wire |
features/relocate_path.feature | 4 | 4 | The declared RELOCATE entry: defined Active, published with intake SLOT_RELOCATION and no fake eligibility, re-seed refused 409, sits beside PICK |
features/replenish_path.feature | 6 | 6 | The 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.feature | 3 | 3 | Republishing the current catalogue at startup |
features/revise.feature | 3 | 3 | Revise an Active path, 404 for an unknown id, a deactivated path rejects revision |
features/revise_and_events.feature | 6 | 6 | ProcessPathCreated/Updated/Deactivated published (deactivation exactly once), no-op revision publishes nothing, malformed cycleTimeP95, re-defining a deactivated id rejected |
features/revise_boundaries.feature | 4 | 5 | Revision boundaries and what a revision publishes |
features/runtime_rules.feature | 16 | 31 | Runtime 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 files | 153 | 268 |
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-casematchPrefix, positivecycleTimeP95, IANA timezone, Active-only revise andeligiblePathIds). Each rule is covered by a BDD scenario and a unit test.use_after_free:DELETE /process-paths/{pathId}is a soft, idempotent retirement;GETafterDELETEreturns 200 withstatus: DEACTIVATEDby 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
| Area | Files (all internal/adapters/...) | What they prove against real infrastructure |
|---|---|---|
| Postgres repositories | outbound/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.go | Mapping, 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) |
| Concurrency | define_concurrent_integration_test.go, version_integration_test.go, process_path_locks_integration_test.go, cpt_path_race_integration_test.go, deactivate_cpt_integration_test.go | Duplicate-create race, optimistic version column, FOR UPDATE/FOR SHARE serialisation of deactivate vs CPT schedule (ADR 0028) |
| Outbox | outbox_integration_test.go, analytics_outbox_integration_test.go, outbox_trace_integration_test.go, outbox_trace_kafka_integration_test.go | Two 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 pools | sweeper_integration_test.go, pool_limits_integration_test.go | Batch deletes, MaxConns and statement_timeout actually applied |
| Idempotency | inbound/http/idempotency_integration_test.go | Replay, key reuse 409, concurrent same-key requests |
| Kafka | outbound/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.go | Same 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) |
| Runtime | cmd/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 store | outbound/analyticsstore/postgres_integration_test.go, unit_of_work_integration_test.go | Projection 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
| Test | Enforces |
|---|---|
TestHexagonalArchitecture (architecture_test.go, arch-go) | domain → nothing; application → domain; adapters inward only |
TestMCPAdapterDependencyRule | internal/adapters/inbound/mcp depends only on application and domain, and nothing imports it except cmd/mcp |
TestNoAuthMiddlewareReintroduced | No 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) |
TestKafkaConsumerGroupNeverHardcodedInline | Consumer 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
| Target | Runs |
|---|---|
make build | go build ./... |
make vet | go vet ./... |
make fmt / make fmt-check | gofmt -w . / fail if gofmt -l . lists files |
make lint | golangci-lint run ./... (CI pins v2.14.0) |
make test | go test ./... -race |
make coverage | go test ./... -race -coverprofile=coverage.out -coverpkg=./internal/domain/...,./internal/application/...,./internal/analytics/... and a 90 % gate |
make bdd | go test ./... -run TestFeatures -v |
make arch-test | go test ./internal/architecture/... -v |
make integration | go build, go vet and go test -tags=integration ./... -race -count=1 |
make mutation-fast / make mutation | gremlins unleash ./internal/domain --workers 1 --timeout-coefficient 30 |
make api-lint | Spectral on apis/openapi.yaml and apis/openapi-reports.yaml (.spectral.yaml) and apis/asyncapi.yaml (.spectral.asyncapi.yaml), --fail-severity=warn |
make chart-test | bash charts/process-path-management/tests/render_test.sh and python3 charts/process-path-management/tests/test_service_selectors.py |
make vuln | govulncheck ./... |
make contract | ./scripts/contract-test.sh |
make check | fmt-check vet build lint test (the lefthook pre-push gate) |
make check-all | check + coverage + arch-test + bdd |
make check-fast, make guide-lint, make harness-test | Agent-harness gates (scripts/harness/) |
make catalogue-test | python3 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.
| Job | Runs | When |
|---|---|---|
lint | golangci-lint v2.14.0 | every run |
guide-lint | scripts/harness/guide_lint.py, repo_lint.py (R1-R7 and R11; R11 = coverage scope only in the Makefile), test_hook.py, test_repo_lint.py | every run |
complexity | golangci-lint --enable-only gocyclo,gocognit,cyclop,funlen,nestif, plus an informational gocyclo report (> 10) | every run |
test | build, vet, gofmt, then make coverage (unit tests with the Makefile's coverage scope and 90 % gate) | every run |
bdd | go test ./... -run TestFeatures -v | every run |
contract | Schemathesis via scripts/contract-test.sh | every run |
evals-tests | go test ./internal/adapters/inbound/mcp/... -race -run '^TestEval|^TestMCPEvalSuite' -v | every run |
integration | go test -tags=integration ./... -race -count=1 (testcontainers on the runner's Docker) | every run |
mutation-fast | gremlins over ./internal/domain | every run |
api-lint | Spectral on the three specs | every run |
vuln | govulncheck v1.8.0 | every run |
arch-test | go test ./internal/architecture/... -v | every run |
docs-api-drift | in 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-reports | every run |
chart-tests | helm v3.16.4 + PyYAML 6.0.3: render_test.sh and test_service_selectors.py | every run |
web | checks out warehouse-ui-kit develop, builds it, then lint, tsc -b, tests and build of web/ | every run |
drift | deadcode, go mod tidy -diff, knip, coverage-quality; opens/closes a harness:red issue | schedule and dispatch only (advisory) |
helm-lint | ct lint on the chart | PRs into main only |
trivy-scan | builds the image, Trivy SARIF + blocking CRITICAL/HIGH gate | PRs into main only |
docker-publish | build, push to GHCR, cosign sign, SBOM attest | push to main only |
release | tag, versioned image, Helm chart to oci://ghcr.io/iqvo | push 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/