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
| Target | Runs | Needs |
|---|---|---|
make test | go test ./... -race — unit, httptest, the BDD suite and the MCP evals | Go only |
make coverage | the same with -coverprofile=coverage.out -coverpkg=./internal/domain/...,./internal/application/..., failing below 90 % | Go |
make bdd | go test ./... -run TestFeatures -v | Go |
make arch-test | go test ./internal/architecture/... -v | Go |
make integration | go test -tags=integration ./... -race -count=1 | Docker (testcontainers starts Postgres and Kafka) |
make contract | scripts/contract-test.sh | st (pip install 'schemathesis==4.28.0') |
make mutation | gremlins unleash ./internal/domain/release (the blocking subset) | gremlins v0.6.0 |
make mutation-all | gremlins unleash ./internal/domain (slow) | gremlins |
make vuln | govulncheck ./... | govulncheck |
make lint | golangci-lint run ./... (pinned v2.13.1) | golangci-lint |
make check | fmt-check vet build lint test | Go + golangci-lint |
make check-all | check + coverage arch-test bdd | same |
make check-fast | fmt-check vet arch-test + tests of the packages changed vs HEAD (agent Stop hook) | Go, Python |
make guide-lint / make harness-test | scripts/harness/guide_lint.py / scripts/harness/test_hook.py | Python 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 file | Scenario headings | Executed scenarios |
|---|---|---|
completion_telemetry.feature | 2 | 2 |
consumed_events.feature | 15 | 17 |
consumed_rules.feature | 10 | 16 |
plan_and_work_unit_rules.feature | 9 | 24 |
planning_moved.feature | 3 | 9 |
pool_configuration.feature | 15 | 17 |
read_model_views.feature | 8 | 8 |
rebalance.feature | 2 | 2 |
relocation_rules.feature | 18 | 26 |
request_validation_and_probes.feature | 5 | 5 |
slot_plan_relocation.feature | 5 | 5 |
work_pool_capacity.feature | 2 | 2 |
work_pool_rules.feature | 15 | 27 |
work_release.feature | 2 | 2 |
work_unit_enqueue.feature | 12 | 17 |
| 15 files | 123 | 179 (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 matchestestdata/tool_registry.golden(name, read-only, destructive), tool names are unique across the fleet snapshottestdata/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):
| Test | Rule |
|---|---|
TestHexagonalDependencyRule | domain depends on nothing; application only on domain; inbound and outbound adapters never on each other; only cmd/ wires every layer (ADR-0007) |
TestApplicationPortsContainOnlyInterfaces | internal/application/ports holds interfaces only |
TestMCPAdapterDependencyRule | the MCP adapter depends only on application/domain, and nothing depends on it (ADR-0008) |
TestNoAuthMiddlewareReintroduced | no bearer/JWT middleware in the inbound adapters (ADR-0016) |
TestKafkaConsumerGroupNeverHardcodedInline | consumer 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 |
TestCloudEventsOnly | CloudEvents is the only envelope; no envelope-mode toggle (ADR-0027) |
TestReplayConsumersSetCommitInterval | a process-unique replay consumer must set CommitInterval |
TestKafkaWritersSetRequiredAcks, TestKafkaWriterAcksSensorBites | every 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/): thewebCI job runsnpm run lint,npx tsc -b,npm test(Vitest) andnpm run build. - Helm chart:
python3 charts/wes-work-planning/tests/test_service_selectors.pyproves each Service selects exactly one Deployment. It is not run byci.yml;helm-lint(chart-testingct lint) runs only on PRs intomain. - Agent harness:
guide-lintjob runsguide_lint.py,repo_lint.py,test_hook.pyandtest_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.
| Job | Runs | When |
|---|---|---|
lint | golangci-lint v2.13.1 | every push/PR |
guide-lint | the four harness scripts above | every push/PR |
complexity | golangci-lint --enable-only gocyclo,gocognit,cyclop,funlen,nestif + informational gocyclo report (over 10; gate 15) | every push/PR |
test | go build, go vet, then make coverage (go test ./... -race with the Makefile's coverage scope and 90 % gate) | every push/PR |
bdd | go test ./... -run TestFeatures -v | every push/PR |
contract | scripts/contract-test.sh with Schemathesis 4.28.0 | every push/PR |
evals-tests | go test ./internal/adapters/inbound/mcp/... -race -run '^TestEval|^TestMCPEvalSuite' -v | every push/PR |
integration | go test -tags=integration ./... -race -count=1 | every push/PR |
mutation-fast | gremlins unleash ./internal/domain/release | every push/PR |
vuln | govulncheck v1.8.0 | every push/PR |
api-lint | Spectral on apis/openapi.yaml and apis/asyncapi.yaml, --fail-severity=warn | every push/PR |
arch-test | go test ./internal/architecture/... -v | every push/PR |
docs-api-drift | in docs/: npm ci, clean-api-docs wes + gen-api-docs wes, fail on any diff under docs/api/rest | every push/PR |
web | lint, typecheck, Vitest, build of web/ | every push/PR |
mutation | gremlins unleash ./internal/domain; opens/closes a red issue | schedule / dispatch only |
drift | deadcode, go mod tidy -diff, knip on web/, coverage-quality report; opens/closes a red issue | schedule / dispatch only |
helm-lint | ct lint on the chart | PRs into main only |
trivy-scan | image build + Trivy (SARIF upload and a blocking table scan) | PRs into main only |
docker-publish | build, push to ghcr.io/iqvo/wes-work-planning, cosign sign, SBOM attest | push to main, after every blocking job |
release | next v* tag, image re-tag, Helm chart package, GitHub release | push 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.