Skip to main content

Testing

Every layer below is a real suite in this repository; counts were taken on develop (the documentation-derived BDD wave, PR #279, is merged there).

Source: Makefile, .github/workflows/ci.yml, .gremlins.yaml, features/*.feature, internal/architecture/*_test.go.

Make targets​

TargetRunsNeeds
make testgo test ./... -race — unit, httptest, the BDD suite and the MCP evalsGo only
make coveragethe same with -coverprofile=coverage.out -coverpkg=./internal/domain/...,./internal/application/..., failing below 90 %Go
make bddgo test ./... -run TestFeatures -vGo
make arch-testgo test ./internal/architecture/... -vGo
make integrationgo test -tags=integration ./... -race -count=1Docker (testcontainers starts Postgres and Kafka)
make contractscripts/contract-test.shst (pip install 'schemathesis==4.28.0')
make mutationgremlins unleash ./internal/domain/release (the blocking subset)gremlins v0.6.0
make mutation-allgremlins unleash ./internal/domain (slow)gremlins
make vulngovulncheck ./...govulncheck
make lintgolangci-lint run ./... (pinned v2.13.1)golangci-lint
make checkfmt-check vet build lint testGo + golangci-lint
make check-allcheck + coverage arch-test bddsame
make check-fastfmt-check vet arch-test + tests of the packages changed vs HEAD (agent Stop hook)Go, Python
make guide-lint / make harness-testscripts/harness/guide_lint.py / scripts/harness/test_hook.pyPython 3

Git hooks (lefthook.yml, after lefthook install): pre-commit runs make fmt-check, make vet and make lint; pre-push runs make check. Neither needs a database.

Unit tests​

131 _test.go files. The domain (internal/domain/**) and use cases (internal/application/usecases) carry most of them because they have no I/O to fake; in-memory adapters (internal/adapters/outbound/memory) stand in for repositories (test doubles only: the architecture test TestRuntimeBinaryHasNoInMemoryAdapters fails if a non-test file under cmd/** imports them, ADR-0044). The inbound HTTP adapter is tested with httptest (status mapping, problem types, idempotency errors, logging, otelchi telemetry), the Kafka adapters with fake readers/writers (retry-then-DLQ decisions, DLQ auto-create, CloudEvents golden files under internal/adapters/outbound/kafka/testdata/ce_*.golden.json), and the composition roots in cmd/wes and cmd/mcp (classification wiring, shutdown order, housekeeper wiring).

The CI test job enforces the 90 % coverage gate on ./internal/domain/... and ./internal/application/... only, by running make coverage.

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, so the local and the PR gate cannot drift; harness repo_lint rule R11 (coverage-scope) forbids a workflow passing -coverpkg itself. Change the scope or the threshold in the Makefile only.

BDD acceptance (godog)​

features_test.go / features_wave2_test.go define TestFeatures, which runs every file under features/ with Strict: true (an undefined or pending step fails) against the real use cases wired to in-memory test doubles.

Feature fileScenario headingsExecuted scenarios
completion_telemetry.feature22
consumed_events.feature1517
consumed_rules.feature1016
plan_and_work_unit_rules.feature924
planning_moved.feature39
pool_configuration.feature1517
read_model_views.feature88
rebalance.feature22
relocation_rules.feature1826
request_validation_and_probes.feature55
slot_plan_relocation.feature55
work_pool_capacity.feature22
work_pool_rules.feature1527
work_release.feature22
work_unit_enqueue.feature1217
15 files123179 (1143 steps)

planning_moved.feature pins that the two planning routes removed in stage E of ADR-0049 answer 404; the former charge-forecast, shift-plan and labour-plan reconciliation features went with the code.

"Executed" counts Scenario Outline example rows; the totals are godog's own summary from go test . -run TestFeatures -count=1 -v: 179 scenarios (179 passed), 1143 steps (1143 passed). All 123 headings (git grep -c -E "^[[:space:]]*Scenario" -- features) run. The former @known-bug scenario in relocation_rules.feature (completeWorkUnit on a cancelled unit: the specification and ADR-0040 say 409 work-unit-cancelled) now passes because WorkUnit.Complete refuses a Cancelled unit with ErrCancelled. The runner still excludes the tag by default (BDD_TAGS defaults to ~@known-bug) so a future known gap can be parked there; BDD_TAGS=@known-bug go test . -run TestFeatures -count=1 now selects no scenario.

The *_rules.feature files (consumed_rules, plan_and_work_unit_rules, relocation_rules, work_pool_rules) pin the rules written in the documentation: the slot-plan relocation rules of ADR-0040, the Work Pool invariants, the inbound-event rows of the use-case table and the REST error rows with their documented slugs. Their step definitions are in steps_rules_test.go.

MCP evals​

internal/adapters/inbound/mcp has its own godog suite, TestMCPEvalSuite, over testdata/features/mcp_tools.feature (17 scenarios, 82 steps, all passing), plus:

  • TestEvalConformance_* — protocol behaviour over a real client session: initialize handshake, unknown tool / wrong-typed / extra arguments rejected, resource-template discovery, unknown resource and prompt rejected, prompt listable, closed session ends calls;
  • TestEval_* governance checks — input schemas resolve and constrain, every parameter is described, the tool registry matches testdata/tool_registry.golden (name, read-only, destructive), tool names are unique across the fleet snapshot testdata/fleet_tool_snapshot.golden, and the report tool is registered only when a reports client exists.

CI runs them in the evals-tests job.

Integration tests (testcontainers)​

33 files behind //go:build integration. Each test boots its own Postgres (testcontainers-go/modules/postgres) and/or Kafka (testcontainers-go/modules/kafka); nothing reads DATABASE_URL or KAFKA_BROKERS from the environment, which the fitness tests enforce. They cover the Postgres repositories and migrations (including the 0001–0014 chain, pool limits and statement_timeout, optimistic concurrency on work_pools, gift-wrap / line-no / transfer / relocation columns and slot_plans), the outbox and its lag gauge, the housekeeper, the idempotency middleware, the Kafka consumer (atomic processed mark, DLQ and DLQ auto-create, WorkDemandReleased), partition affinity of the Hash balancer, the Kafka catalogue replay, the classification copy, the analytics store, OTel pgx tracing, the MCP Streamable HTTP transport, cmd/mcp and cmd/wes classification wiring, and use-case wiring end to end.

make integration # all of them, -race -count=1
go test -tags=integration ./internal/adapters/outbound/postgres/... -run Outbox -v

Contract tests (Schemathesis)​

scripts/contract-test.sh builds cmd/wes, writes a throw-away sortable-fc catalogue (pick, pack, rebin, slam prefixes), boots the service against a real Postgres (DATABASE_URL) and a real Kafka (KAFKA_BROKERS) on 127.0.0.1:18086 (CONTRACT_PORT), waits for /readyz, then runs st run apis/openapi.yaml --max-examples 100 --workers 4 --generation-allow-x00 false with the scripts/contract_hooks.py hook that gives every request a fresh Idempotency-Key (CONTRACT_MAX_EXAMPLES overrides 100). The CI contract job provides postgres:16 and confluentinc/confluent-local:7.6.1 service containers (the Kafka one advertises PLAINTEXT_HOST://localhost:<port>); locally start disposable ones (the commands are in the script header). The run excludes no operation: receiveChargeForecast and commitShiftPlan were excluded while they answered 410 for every body, and both exclusions went with the routes in stage E of ADR-0049 (TestPlanningRoutesAreGone and features/planning_moved.feature pin the 404). The /reports/* routes of cmd/wes-reports are specified separately in apis/openapi-reports.yaml (ADR-0038) and contract-tested in Go, without Schemathesis or a database: TestReportsContract_RoutesMatchSpec (the router's routes, walked with chi.Walk, equal the spec's paths) and TestReportsContract_ResponsesMatchSpec (every documented status of every operation, driven through the real router with a fake store; each body has every required property and no undocumented one) in internal/adapters/inbound/http/reports_contract_test.go.

Mutation testing (gremlins)​

.gremlins.yaml pins workers: 1, timeout-coefficient: 30 and the thresholds efficacy: 99 and mutant-coverage: 99. gremlins fails when the measured value is at or below the threshold, so 99 locks in the current 100 % and fails on the first surviving mutant. Last recorded measurements in that file: ./internal/domain/release 36/36 killed, ./internal/domain 73/73 killed.

Architecture fitness tests​

internal/architecture (run by make arch-test and the arch-test job):

TestRule
TestHexagonalDependencyRuledomain depends on nothing; application only on domain; inbound and outbound adapters never on each other; only cmd/ wires every layer (ADR-0007)
TestApplicationPortsContainOnlyInterfacesinternal/application/ports holds interfaces only
TestMCPAdapterDependencyRulethe MCP adapter depends only on application/domain, and nothing depends on it (ADR-0008)
TestNoAuthMiddlewareReintroducedno bearer/JWT middleware in the inbound adapters (ADR-0016)
TestKafkaConsumerGroupNeverHardcodedInlineconsumer group ids come from config/constants, never inline literals
TestKafkaIntegrationTestsUseTestcontainers / TestPostgresIntegrationTestsUseTestcontainers (+ TestPostgresIntegrationSensorFailsOnBadFixtures)integration tests start their own containers; no env-gated skips, no hard-coded localhost:9092
TestCloudEventsOnlyCloudEvents is the only envelope; no envelope-mode toggle (ADR-0027)
TestReplayConsumersSetCommitIntervala process-unique replay consumer must set CommitInterval
TestKafkaWritersSetRequiredAcks, TestKafkaWriterAcksSensorBitesevery kafka-go Writer{...} literal in a non-test file under internal/ or cmd/ sets RequiredAcks (kafka-go defaults to RequireNone, acks=0, which silently drops messages on a broker blip); the sensor is proven to fail
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.)
TestEventCatalogueMatchesContract (+ TestEventCatalogueDetector)every own CloudEvents type in apis/asyncapi.yaml appears in a CloudEvents ADR

violation_test.go holds the fixtures that prove the detectors can fail.

Other suites​

  • Frontend (web/): the web CI job runs npm run lint, npx tsc -b, npm test (Vitest) and npm run build.
  • Helm chart: python3 charts/wes-work-planning/tests/test_service_selectors.py proves each Service selects exactly one Deployment. It is not run by ci.yml; helm-lint (chart-testing ct lint) runs only on PRs into main.
  • Agent harness: guide-lint job runs guide_lint.py, repo_lint.py, test_hook.py and test_repo_lint.py.

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

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

JobRunsWhen
lintgolangci-lint v2.13.1every push/PR
guide-lintthe four harness scripts aboveevery push/PR
complexitygolangci-lint --enable-only gocyclo,gocognit,cyclop,funlen,nestif + informational gocyclo report (over 10; gate 15)every push/PR
testgo build, go vet, then make coverage (go test ./... -race with the Makefile's coverage scope and 90 % gate)every push/PR
bddgo test ./... -run TestFeatures -vevery push/PR
contractscripts/contract-test.sh with Schemathesis 4.28.0every push/PR
evals-testsgo test ./internal/adapters/inbound/mcp/... -race -run '^TestEval|^TestMCPEvalSuite' -vevery push/PR
integrationgo test -tags=integration ./... -race -count=1every push/PR
mutation-fastgremlins unleash ./internal/domain/releaseevery push/PR
vulngovulncheck v1.8.0every push/PR
api-lintSpectral on apis/openapi.yaml and apis/asyncapi.yaml, --fail-severity=warnevery push/PR
arch-testgo test ./internal/architecture/... -vevery push/PR
docs-api-driftin docs/: npm ci, clean-api-docs wes + gen-api-docs wes, fail on any diff under docs/api/restevery push/PR
weblint, typecheck, Vitest, build of web/every push/PR
mutationgremlins unleash ./internal/domain; opens/closes a red issueschedule / dispatch only
driftdeadcode, go mod tidy -diff, knip on web/, coverage-quality report; opens/closes a red issueschedule / dispatch only
helm-lintct lint on the chartPRs into main only
trivy-scanimage build + Trivy (SARIF upload and a blocking table scan)PRs into main only
docker-publishbuild, push to ghcr.io/iqvo/wes-work-planning, cosign sign, SBOM attestpush to main, after every blocking job
releasenext v* tag, image re-tag, Helm chart package, GitHub releasepush to main, after docker-publish

The docs site itself is built by .github/workflows/docs.yml, which runs only on pushes to main (and dispatch) — a pull request never builds the site, so run npm run build in docs/ locally before merging docs changes.