Skip to main content

Testing

The test pyramid as it is on develop: a pure domain under a mutation gate, use cases and adapters with unit and httptest tests, a godog BDD suite over the real use cases, testcontainers integration suites against real Postgres and Kafka, architecture fitness tests, and spec linting.

LayerCount / thresholdCommand
Unit, domain88 top-level test functions in 4 packages (policy 17, recommend 19, stationtrip 43, travel 9); recommend includes the PICK parity and candidate-bound tests of ADR 0012make test
Unit, application24 in internal/application/{usecases,outbox} (23 + 1)make test
Unit and httptest, adapters and cmd/*inbound/http 72, inbound/kafka 57, inbound/expiry 11, inbound/a2a 17, inbound/mcp 21, outbound/memory 23, outbound/events 13, outbound/outbox 13, outbound/kafka 12, kafka/cloudevents 6, outbound/system 2, outbound/analyticsstore 1, outbound/postgres 1 (DSN selection), analytics/report 9, telemetry 1, cmd/api 36, cmd/a2a 12, cmd/mcp 7, cmd/ti-projector 6, cmd/ti-reports 3, bootretry 6make test
Coverage gate90% over ./internal/domain/...,./internal/application/...; measured 99.9% on this commitmake coverage
BDD (godog / Gherkin)13 feature files, 182 scenarios executed (124 Scenario / Scenario Outline definitions, 16 of them outlines whose Examples rows expand), 1818 steps; all passmake bdd
Integration (testcontainers)73 top-level functions behind //go:build integration (TestMain included): cmd/api 13, cmd/a2a 2, cmd/mcp 2, inbound/kafka 7, outbound/analyticsstore 5, outbound/outbox 8, outbound/postgres 36make integration
Architecture fitness42 top-level test functions in internal/architecture (none skips)make arch-test
Load (tagged, not in CI)3 tests behind //go:build load: the recommender over a 1 000-task and a 10 000-task pool at PICK volume (recommend 2) and the full completion path (usecases 1), ADR 0012. They assert generous wall-clock limits (50 ms and 500 ms per call, 5 s end to end), not benchmarksmake load
Mutation (gremlins)efficacy 90, mutant coverage 90 (.gremlins.yaml); measured 100% / 100% on the four domain packagesmake mutation, make mutation-full
Spec linting (Spectral)OpenAPI and AsyncAPI, --fail-severity=warnCI api-lint
Contract (schemathesis)none: no schemathesis configuration and no CI job. Response shapes are checked against the OpenAPI document by a Go test instead (internal/adapters/inbound/http/shape_test.go)none
Evalsnone: EVALS.md at the repo root is a copy of the harness template's note about agent evaluation on inventory-storage; it measures nothing in this reponone

Counts come from grep '^func Test' per package on this commit; many tests are table-driven, so the number of cases is larger. Run go test ./... -v for the cases.

Make targets​

All targets mirror a CI job; the Makefile is the only definition of the coverage scope and the mutation package list.

TargetRunsNotes
make helpprints the target listdefault target
make buildgo build ./...compiles cmd/api
make vetgo vet ./...
make fmt / make fmt-checkgofmt -w . / fail if gofmt -l . is non-empty
make lintgolangci-lint run ./...pinned v2.14.0, config .golangci.yml
make testgo test ./... -raceunit, httptest and BDD (the BDD suite is a normal Test function)
make coveragego test ./... -race -coverprofile=coverage.out -coverpkg=./internal/domain/...,./internal/application/... then the 90% gateThe CI test job runs exactly this; a workflow that defined its own -coverpkg would fail repo_lint R11.
make arch-testgo test ./internal/architecture/... -v
make bddgo test ./... -run TestFeatures -vthe godog suite, features/features_test.go (the module root holds no Go file)
make integrationgo test -tags=integration ./... -race -count=1needs only Docker; every test boots its own Postgres and Kafka
make loadgo test -tags=load ./... -race -count=1 -run '^TestLoad(Recommend|Completion)' -vthe PICK-volume envelope of ADR 0012; deliberately outside make check, make check-all and CI
make mutationgremlins unleash on each of ./internal/domain/stationtrip ./internal/domain/recommend ./internal/domain/travel ./internal/domain/policythe fast, blocking subset (MUTATION_FAST_PKGS)
make mutation-fullgremlins unleash ./internal/domain --workers 1 --timeout-coefficient 30the exhaustive scheduled run
make vulngovulncheck ./...
make checkfmt-check vet build lint testthe pre-push hook runs this
make check-allcheck coverage arch-test bddrun before pushing
make check-fastfmt-check vet arch-test plus go test of the packages changed vs HEADthe agent Stop hook
make guide-lint / make harness-testscripts/harness/guide_lint.py / scripts/harness/test_hook.pyagent-guide checks, not product tests

A new package under internal/domain/ must be added to MUTATION_FAST_PKGS and to the for pkg in ... loop of the mutation-fast CI job; the two lists are kept in sync by hand.

Unit tests​

  • Domain (policy, travel, recommend, stationtrip): pure, standard library only, no fixtures. They pin the site-id token rules, the policy boundaries (MaxDetourM, MaxCandidates 1 to 5, HintTTL, VerticalWeight), the rule unknown geometry is unknown, never zero, ranking by detour then task id independent of pool order, the claim time window (one nanosecond before issue, before expiry, at expiry), one Active hint per station, consumption at most once, and ordered domain events. Two recommend tests pin ADR 0012: PICK ranks against RELOCATE and REPLENISH by detour only, and every candidate survives up to the MaxCandidates bound.
  • Use cases (internal/application/usecases): run against the in-memory adapters, which are test doubles only (the shipped binary never imports them; internal/architecture/runtime_no_memory_fitness_test.go enforces it), including injected faults (faults_test.go), input validation (inputs_test.go) and the completion path (completion_station_test.go).
  • HTTP adapter: httptest over the real router, one file per handler group plus idempotency_test.go (replay, reuse, FINAL stored and RETRYABLE released, rollback on 4xx and 5xx, concurrent first writers), idempotency_inflight_test.go (an in-flight copy that decides an unstored refusal replays the stored answer, within the 24 h window; a failed re-read is logged at WARN), idempotency_window_test.go (a stored answer replays for 24 h and not 1 µs longer), idempotency_classes_test.go (the ADR 0013 table equals the catalogue, problems are built only by newProblem, no OUTCOME) and the harness template idempotency_replay_classes_test.go over an in-memory wiring (and over Postgres in the integration job), health_test.go and shape_test.go, which walks the OpenAPI schema and checks that the responses have exactly the documented shape.
  • Kafka consumers: a fake Reader drives the run loop (consume_loop_test.go: retry, backoff sequence, dead-letter after 5 attempts, no commit before success), deadletter_test.go, and per-consumer tests whose fixtures restate the producers' published contracts as raw JSON, never built with this service's own helper.
  • Outbox relay and events: relay cap and ordering with a fake store, golden CloudEvents bytes in outbound/events/testdata.
  • cmd/api: env parsing and boot configuration (config_test.go, bootconfig_test.go), consumer planning and the supervised restart (consumers_test.go), shutdown order (shutdown_test.go), boot (main_test.go).

Run one package or one test:

go test ./internal/domain/recommend -run TestRecommendDetourBoundary -v
go test ./internal/application/usecases -v

BDD (godog)​

features/*.feature holds thirteen files. The six original ones: hints.feature (13 scenarios: hint lifecycle, supersede, consume, expiry, duplicates), inert.feature (3), policy.feature (12 blocks, one outline with 5 rows), ranking.feature (16), simulation.feature (10) and tasks.feature (10: pool and claim copies). Seven *_rules.feature files pin the rules the context documentation states (use-cases, aggregate canvas invariants and transitions, ubiquitous language, troubleshooting), one rule per scenario with boundaries as Outline rows: hint_lifecycle_rules (8: claim window [issued_at, expires_at), final states, stale completions, HintIssued context), hint_expiry_rules (3: only due and Active hints, 200-station batch), policy_rules (15: bounds, replacement, versions, site id), recommender_rules (9: rectilinear distance, vertical weight, detour limit, eligibility), consumer_rules (16: malformed payloads, duplicates, claimer and completer, decommission, geometry), hint_query_rules (5: listing, filters, paging, not-found) and simulation_rules (4). Their steps are in features/features_rules_test.go and features/features_rules_assert_test.go. Definitions in all: 124 (^[[:space:]]*Scenario in features/), 16 of them outlines. The godog runner features/features_test.go (package features_test, godog Paths ["."]) and its features/features_setup/flow/assertions_test.go companions live in the same directory as the .feature files; the repository root holds no .go file at all (TestNoGoFilesAtRepoRoot in internal/architecture enforces it). They wire the real use cases over the in-memory adapters with a fake clock, so the scenarios are fast and need no Docker. go test ./features -run TestFeatures -v ends with 182 scenarios (182 passed) and 1818 steps (1818 passed).

Integration (testcontainers)​

All files carry //go:build integration and boot their own containers (internal/testing/pgtest, internal/testing/kafkatest); TestMain in cmd/api, outbound/outbox and outbound/postgres starts the shared Postgres, and a missing Docker is a test failure, never a skip.

SuitePackageWhat it proves
Service over Postgrescmd/api (6)boot migrates, Idempotency-Key is enforced, the simulation writes no outbox row, policy PUT is version guarded, a RETRYABLE refusal leaves no row and its key retries, a FINAL one is stored and replays, concurrent requests with one key store one answer, an in-flight copy blocked on the original's key replays its answer (TestPostgresAnInFlightDuplicateReplaysTheOriginalsAnswer), a stored answer replays for 24 h and is then replaced, the expiry worker expires a hint and enqueues the fact, boot fails closed on an unreachable database
Real entry pointcmd/api/e2e_integration_test.go (2)run() is booted in-process on real Postgres and a real Kafka whose topic auto-creation is off: /readyz is 200 while none of the four topics exists (topics are not part of readiness, ADR 0006 Amendment 1), then the test creates them; layout, policy, task and completion events published to Kafka produce an InterleavingHintIssued ranked by detour (read from REST, Postgres and the produced topic); a claim of the top candidate consumes the hint; a restart halfway and a full replay lose and duplicate nothing; the service stays alive but not ready while Kafka is unreachable
Repositories and contractoutbound/postgres (36)the repository contract suite (internal/testing/repocontract) for policies, trips, task pool, location book, processed events and the idempotency store; one Active hint per station even under racing issuers; version-guarded policy writes under races; unit-of-work rollback and nesting; outbox ordering, retry, attempt cap and trace-context headers; migrations apply, re-run as a no-op, every down restores the previous schema, and run from the unpooled URL only
Outbox relayoutbound/outbox (8)exact envelopes published for issued/consumed/expired, crash and restart without duplicates, a crash between send and mark republishes the same id, the attempt cap excludes a poison row, re-arming claims it again, no cap lets a poison row block later rows
Consumersinbound/kafka (7)the fulfillment consumer and the layout consumer over a real Kafka and Postgres, the no-policy case issuing no hint, the analytics consumer, and the PICK parity pair of ADR 0012 (pick_parity_integration_test.go: a mixed PICK/RELOCATE/REPLENISH pool interleaves by detour from the producer's pinned TaskAvailable JSON, and a five-candidate hint keeps every candidate)

make integration and the CI integration job run the same command, go test -tags=integration ./... -race -count=1, which covers every package, so every suite above runs in CI. An architecture fitness test fails the build if an integration test gates on DATABASE_URL/KAFKA_BROKERS or hard-codes localhost:9092.

Mutation testing​

.gremlins.yaml sets workers: 1, timeout-coefficient: 30, and the thresholds efficacy: 90 and mutant-coverage: 90. Gremlins fails when the measured value is less than or equal to the threshold, so a threshold sits strictly below what the code achieves. The file records a measurement of 2026-10-17 on the four domain packages (stationtrip, recommend, travel, policy): efficacy 100% and mutator coverage 100% in each, with 0 lived mutants. Only the domain is mutated; use cases and adapters are not.

The scheduled mutation job (Monday 06:00 UTC and on manual dispatch) mutates ./internal/domain as a whole. The drift job additionally runs scripts/coverage-quality.py to flag functions with high line coverage and a surviving mutant. A failing scheduled run opens or refreshes a harness:red issue (scripts/harness/red_issue.py).

Architecture fitness tests​

internal/architecture carries the dependency-direction rules and source-scanning sensors listed with their rules on Architecture. Each sensor that scans source also has a test that proves it can fail (...SensorBites, ...SensorFailsOnBadFixtures, TestEventCatalogueDetector). No sensor skips: the MCP sensors run against internal/adapters/inbound/mcp and the A2A sensors against internal/adapters/inbound/a2a and cmd/a2a.

make arch-test

CI jobs​

.github/workflows/ci.yml runs on push and pull request to main and develop, weekly (Monday 06:00 UTC, mutation and drift only) and on manual dispatch.

JobRunsWhen
lintgolangci-lint v2.14.0, --timeout=5malways
guide-lintscripts/harness/guide_lint.py and scripts/harness/test_hook.py; advisory (continue-on-error)always
complexitygolangci-lint with only gocyclo,gocognit,cyclop,funlen,nestif (gate 15) plus an informational gocyclo reportalways
testgo build ./..., go vet ./..., then make coverage (90% gate); uploads coverage.outalways
bddgo test ./... -run TestFeatures -valways
integrationgo test -tags=integration ./... -race -count=1 (testcontainers boots Postgres and Kafka on the runner's Docker)always
mutation-fastinstalls gremlins v0.6.0, then gremlins unleash on stationtrip, recommend, travel, policyalways; blocking
mutationgremlins unleash ./internal/domain --workers 1 --timeout-coefficient 30, harness:red issue on failureschedule and dispatch only
driftdeadcode, go mod tidy -diff, knip in web/, coverage-quality; advisoryschedule and dispatch only
api-lintSpectral on apis/openapi.yaml (.spectral.yaml) and apis/asyncapi.yaml (.spectral.asyncapi.yaml), --fail-severity=warnalways
vulngovulncheck ./...always
chart-testsevery charts/task-interleaving/tests/*.sh and test_*.py (render_test.sh, test_service_selectors.py, test_kong_config.py); with none it prints a warning and exits 0always
arch-testgo test ./internal/architecture/... -valways
docker-publishbuild, push to ghcr.io/iqvo/task-interleaving, cosign signature, SBOM; needs the jobs abovepush to main only
releasetags the next patch version, retags the image, packages and pushes the Helm chart, creates the GitHub releasepush to main only, after docker-publish

.github/workflows/docs.yml builds this site (npm ci, npm run build in docs/) on pull requests that touch docs/**, apis/** or the workflow, and deploys to GitHub Pages only on push to main. .github/workflows/ai-review.yml is an advisory architecture review on pull requests into develop; it does nothing without the ANTHROPIC_API_KEY secret.

Jobs that show skipping on a pull request into develop (mutation, drift, docker-publish, release) are gated on events or branches by their if: conditions; that is expected, not a failure.

What the pipeline assumes that develop does not have​

These are mismatches between ci.yml and the tree, reported so nobody reads a green check as more than it is:

  • ci.yml has no helm-lint job (HARNESS.md lists it as a sensor for PRs into main); helm lint charts/task-interleaving with ci/default-values.yaml and ci/all-components-values.yaml is run by hand.
  • The drift job runs npm ci in web/, which does not exist.
  • HARNESS.md lists docs-api-drift, helm-lint, trivy-scan and CodeQL as sensors; none is in ci.yml. There is no job that regenerates the REST reference and fails on a diff, so regenerate it yourself after any spec change.

Reproducing the docs build​

cd docs
npm ci
npx tsc --noEmit -p .
npm run build

The build fails on a broken link or anchor (onBrokenLinks and onBrokenAnchors are throw). Mermaid diagrams are checked with scripts/validate-mermaid.cjs of the warehouse-docs repository, because docusaurus build alone never catches a broken diagram.