Skip to main content

Testing

Synced from warehouse-ops-agent

This page is a copy of docs/docs/development/testing.md on develop, derived from that repository's code. Edit it there, then re-sync.

Everything in this repo runs with plain go test and no external service: there is no database, no Kafka and no live MCP server to start. Upstreams are replaced by fakes (Go interfaces), by httptest servers or by in-process Streamable HTTP MCP stubs. No test calls the real Anthropic API.

The pyramid​

LayerWhereWhat it provesCommand
Domain unit testsinternal/domain/policy/*_test.gothe pure decision rules: flow balance, daily-brief exception correlation, stranded reservation, travel factor, utilization overlay, capacity outlook, master-data gaps, inbound outlook, transfer triage and imbalance, runtime-signal thresholds, LLM plan validation and arbitrationmake test
Use-case unit testsinternal/application/usecases/*_test.gofan-out and degradation with fake ports (fakes_test.go), including end_to_end_resilience_test.go and flow_balance_llm_test.go (shadow/on/off arbitration with a fake reasoner)make test
Adapter testsinternal/adapters/inbound/{http,mcp}/*_test.go, internal/adapters/outbound/{httpclient,mcpclient,restclient,telemetry,logs,llm/anthropic}/*_test.goREST status mapping, CORS, MCP tool registration and errors; the outbound clients' wire format against httptest and in-process MCP servers; every outbound client sends the caller's traceparent (*_PropagatesTraceContext, fixture httpclient/httpclienttest); the Anthropic adapter's retry, timeout, breaker and tool-argument validation against a fake APImake test
Config and composition rootinternal/config/config_test.go, cmd/agent/main_test.goenv parsing and its fail-fast cases; every MCP client is built only when its endpoint is set and the use cases degrade without it (ADR 0023); the startup route list comes from the routermake test
Acceptance (BDD)features/*.feature, driven by features_test.go and the steps_*_test.go / fakes_*_test.go files at the module rootblack-box scenarios against the real chi router and the real use cases, with fake outbound adapters (ADR 0022)make bdd
MCP tool-selection evalsinternal/adapters/outbound/mcpclient/agent_selection_eval_test.go (TestAgentEval_*)that the stranded-reservation use case calls exactly the right sibling tools, with the right arguments, in the right order, through the real mcpclient adapters against recording Streamable HTTP stubs; no LLM involvedgo test ./internal/adapters/outbound/mcpclient/... -race -run '^TestAgentEval' -v
Architecture fitnessinternal/architecture/*_test.gothe hexagonal dependency rules (arch-go), the MCP adapter rule, no auth middleware, no struct tags in the domain, CloudEvents-only and replay-consumer sensors, every outbound http.Client built by httpclient.New with the otelhttp transport (TestOutboundHTTPClientsUseOtelhttp)make arch-test
Zero-write guardrailinternal/architecture/zerowrite/*_test.gono outbound client uses a mutating HTTP method, every MCP client calls only read tools (product-master and inbound-receiving pinned to their tool lists), and every tool this server registers carries ReadOnlyHintmake arch-test
Mutationgremlins over ./internal/domainthe domain tests actually kill mutantsmake mutation-fast

At the time of writing the repo holds 280 func Test... functions across its _test.go files.

Acceptance features​

12 feature files with 102 Scenario/Scenario Outline blocks (11 of them outlines). With the outline examples expanded, the local make check-all run on this branch reported 142 scenarios (142 passed) and 1079 steps (1079 passed).

Feature fileScenario blocks
console_reports.feature11
flow_balance.feature11
llm_arbitration.feature10
transfer_watch.feature10
daily_brief.feature8
explain_travel_factor.feature8
inbound_outlook.feature8
master_data_gaps.feature8
reasoner_resilience.feature8
order_lifecycle.feature7
http_conventions.feature7
runtime_signals.feature6

TestFeatures runs godog with Strict: true, so an undefined or pending step fails the suite. It pins CORS_ALLOWED_ORIGINS to empty (the console default) and discards the use cases' warning logs. To run one feature:

go test . -run 'TestFeatures/The_WMS_dashboard' -v

What is absent, and why​

Fleet test typeStatus here
Integration tests with testcontainersnone: nothing to containerise (no Postgres, no Kafka). TestPostgresIntegrationTestsUseTestcontainers is a fleet sensor that passes because no -tags=integration test exists.
Contract tests (schemathesis)none: the repo has no apis/openapi.yaml. Every route is described by hand on HTTP routes.
AsyncAPI catalogueTestEventCatalogueMatchesContract skips with no apis/asyncapi.yaml: nothing to compare; the agent publishes no events.
Live-LLM evalsnone: every reasoner test uses a fake Anthropic server (fake_anthropic_test.go, internal/adapters/outbound/llm/anthropic/*_test.go).

Coverage​

WhereCommand-coverpkgGate
make coverage (local, part of make check-all, and the CI test job's coverage step)go test ./... -race -coverprofile=coverage.out -coverpkg=$(COVERPKG)./internal/domain/...,./internal/application/...,./internal/adapters/inbound/...90 % (COVERAGE_THRESHOLD)

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. repo_lint.py rule R11 (CI guide-lint job) fails a PR whose workflow passes -coverpkg itself, or whose Makefile gate no workflow runs. The local run on this branch printed Coverage: 97.9% (gate: 90%).

Mutation testing​

.gremlins.yaml runs the whole domain with workers: 1 and timeout-coefficient: 30, and fails below:

ThresholdValueMeaning
efficacy80killed / (killed + lived)
mutant-coverage96(killed + lived) / total

The file records the baseline measured on 2026-09-14 with gremlins v0.6.0: 97 mutants, 76 killed, 18 lived, 3 not covered, efficacy 80.85 %, mutant coverage 96.91 %. The survivors sit in policy/utilization_correlation.go. gremlins fails when the measured value is at or below the threshold, so the thresholds sit just under the baseline. Install the pinned version with go install github.com/go-gremlins/gremlins/cmd/gremlins@v0.6.0.

Make targets​

TargetRuns
make buildgo build ./...
make vetgo vet ./...
make fmt / make fmt-checkgofmt -w . / fail if any file is not gofmt-clean
make lintgolangci-lint run ./... (CI pins v2.13.1)
make testgo test ./... -race
make coveragecoverage run plus the 90 % gate
make bddgo test ./... -run TestFeatures -v
make arch-testgo test ./internal/architecture/... -v
make mutation-fastgremlins unleash ./internal/domain --workers 1 --timeout-coefficient 30
make vulngovulncheck ./...
make checkfmt-check vet build lint test
make check-allcheck coverage arch-test bdd
make check-fastfmt-check vet arch-test plus the tests of changed packages (agent Stop hook)
make guide-lint / make harness-testlint the agent guides / test the agent hooks

Local hooks (lefthook)​

lefthook.yml, activated once with lefthook install:

HookRuns
pre-commitmake fmt-check, make vet, make lint
pre-pushmake check-all

CI jobs​

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

JobRunsWhen
lintgolangci-lint v2.13.1every push and PR
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 push and PR
complexitygolangci-lint with only gocyclo,gocognit,cyclop,funlen,nestif, plus an informational gocyclo report (over 10; the gate is 15)every push and PR
testgo build, go vet, then make coverage (go test ./... -race with the Makefile's coverage scope and 90 % gate), uploads coverage.outevery push and PR
bddgo test ./... -run TestFeatures -vevery push and PR
evals-testsgo test ./internal/adapters/outbound/mcpclient/... -race -run '^TestAgentEval' -vevery push and PR
arch-testgo test ./internal/architecture/... -vevery push and PR
mutation-fastgremlins v0.6.0 over ./internal/domainevery push and PR (blocking)
vulngovulncheck v1.1.4every push and PR
driftdeadcode, go mod tidy -diff, coverage-quality (scripts/coverage-quality.py over coverage plus gremlins output); opens or closes a harness:red issue on scheduled runsschedule and manual dispatch only
helm-lintchart-testing ct lint on charts/warehouse-ops-agentPRs into main only
chart-testscharts/warehouse-ops-agent/tests/render_test.sh (helm v3.16.4): the ConfigMap is mounted with envFrom, config.corsAllowedOrigins renders as CORS_ALLOWED_ORIGINS only when set, config.logLevel=warning passes throughevery push and PR
trivy-scanbuilds the image and scans it; blocks on fixable CRITICAL/HIGHPRs into main only
docker-publishmulti-arch image to GHCR, cosign signature, SPDX SBOM attestationpush to main only
releasenext vX.Y.Z tag, image re-tag, Helm chart push to oci://ghcr.io/iqvo, GitHub releasepush to main only, after docker-publish

On a PR into develop, drift, helm-lint, trivy-scan, docker-publish and release show as skipped by design.

Other workflows: codeql.yml (push and PR to main/develop, weekly), scorecard.yml (push to develop, weekly), ai-review.yml (advisory review on PRs into develop) and docs.yml, which builds this site on every pull request that touches docs/** (build only, nothing is published) and builds and deploys it on push to main or manual dispatch. Run npm run build in docs/ to catch a broken sidebar id, link or MDX before pushing.

Writing a new test​

  • A new decision rule goes in internal/domain/policy with a table test; it raises the mutation baseline, so run make mutation-fast.
  • A new route or tool gets a Gherkin scenario in features/ and steps in the matching steps_*_test.go; wire any new fake in fakes_*_test.go.
  • A new outbound MCP tool must be a read tool, or TestMCPClientsCallOnlyReadTools fails.
  • A new inbound MCP tool must set ReadOnlyHint: true, or TestNoMutatingToolAnnotationInMCPServer fails.