Skip to main content

Testing

The test pyramid as it is on this branch: a small pure domain under a mutation gate, use cases and adapters with unit and httptest tests, a godog BDD suite over the real use cases and router, testcontainers integration tests against real Postgres and Kafka, a repository contract suite shared by the in-memory and Postgres adapters, golden CloudEvents bytes, architecture fitness tests and spec linting.

LayerCount / thresholdCommand
Unit, domain55 top-level test functions in 3 packages (shared 5, content 28, category 22)make test
Unit, application33 in internal/application/{usecases,outbox,readmodel} (usecases 31, outbox 1, readmodel 1)make test
Unit and httptest, adapters and binariesinbound/http 20, inbound/kafka 33, inbound/a2a 13, inbound/mcp 20, inbound/requestlog 4, outbound/kafka 16, outbound/outbox 5, outbound/telemetry 11, outbound/postgres 3 (outbox trace unit tests), kafka/cloudevents 6, cmd/api 16, cmd/a2a 9, cmd/mcp 12, bootretry 6make test
Coverage gate90% over ./internal/domain/...,./internal/application/... (COVERAGE_THRESHOLD in the Makefile)make coverage
BDD (godog / Gherkin)8 feature files, 101 scenario definitions (123 executed with the Examples rows expanded), run by internal/bdd/features_test.go with Strict: truemake bdd
Repository contractone suite, six sub-suites (contents, tree, items, inbox, unitofwork, idempotency), run against the in-memory store and against Postgresmake test (memory), make integration (Postgres)
Integration (testcontainers)9 top-level tests (not counting TestMain) behind //go:build integration in 10 files: cmd/api 2, cmd/mcp 1, cmd/a2a 1, inbound/http 2, outbound/postgres 3make integration
Golden bytesone *.golden.json per published event type in internal/adapters/outbound/kafka/testdata (3 files), compared byte for bytemake test
Architecture fitness40 top-level test functions in internal/architecturemake arch-test
Mutation (gremlins)efficacy 99, mutant coverage 99 (.gremlins.yaml); measured 100% / 100% on the three domain packagesmake mutation, make mutation-full
Spec linting (Spectral)OpenAPI and AsyncAPI, --fail-severity=warnCI api-lint
Helm chart testscharts/product-content/tests/render_test.sh, test_service_selectors.pyCI chart-tests
Contract against a running service (schemathesis)none: no schemathesis configuration and no CI jobnone

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

Make targets​

Every target mirrors 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, cmd/mcp and cmd/a2a
make vetgo vet ./...
make fmt / make fmt-checkgofmt -w . / fail if gofmt -l . is non-empty
make lintgolangci-lint run --allow-parallel-runners ./...pinned v2.14.0, config .golangci.yml
make testgo test ./... -raceunit, httptest and BDD (the godog 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
make arch-testgo test ./internal/architecture/... -v
make bddgo test ./... -run TestFeatures -vthe godog suite in internal/bdd, reading ../../features
make integrationgo test -tags=integration ./... -race -count=1needs only Docker; each test boots its own Postgres and Kafka; deliberately outside check and check-all
make mutationgremlins unleash on every package matched by ./internal/domain/*/ (shared, content, category), one at a timethe fast, blocking subset; a new domain package is gated as soon as it exists
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 (lefthook.yml) runs this
make check-allcheck coverage arch-test bddrun before pushing
make check-fastfmt-check vet arch-test, then 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

lefthook.yml also runs fmt-check, vet and lint on every commit. Hooks are not tracked: run lefthook install once per clone.

Unit tests​

  • Domain (internal/domain/{shared,content,category}): pure Go, no fixtures. They pin the content state machine (DRAFT to PUBLISHED to RETIRED), the publication gate (description, exactly one PRIMARY medium, a category of the live tree), revision numbering, the four-level category depth limit, cycle prevention on MoveCategory, restore-from-storage and the ordered domain events.
  • Use cases (internal/application/usecases): run against the in-memory adapters (internal/adapters/outbound/memory), which are test doubles only. The shipped binaries never link them (TestRuntimeBinaryHasNoInMemoryAdapters). content_metrics_test.go checks the content.products.published counter.
  • HTTP adapter (internal/adapters/inbound/http): httptest over the real router, split into content_routes_test.go, category_routes_test.go, platform_test.go (health, idempotency, problem details), readiness_test.go and telemetry_test.go.
  • Kafka consumer (internal/adapters/inbound/kafka): a fake reader drives the run loop (consume_loop_test.go: retry, backoff, dead-letter, commit only after success), deadletter_test.go, dispatch_test.go (which event types change the read model), topic_not_ready_test.go and tracing_test.go.
  • A2A (internal/adapters/inbound/a2a, cmd/a2a): the Agent Card, every skill mapping, the JSON-RPC router and the boot configuration.
  • MCP (internal/adapters/inbound/mcp, cmd/mcp): an in-memory MCP client over the real server and the real read use cases seeded through the write use cases (tools_test.go, surface_test.go for the resource and the prompt), the governance gate (governance_test.go: exact tool set, budget, read-only annotations, no write verb, no write seam), the pinned registry (testdata/tool_registry.golden.json, refresh with go test ./internal/adapters/inbound/mcp -run TestToolRegistryGolden -update), raw POSTs for the stateless handler (stateless_test.go) and the router, telemetry and boot tests of cmd/mcp.
  • Outbox relay and encoder: relay ordering and attempt cap with a fake store, and the CloudEvents encoder checked against golden files. Refresh them deliberately with go test ./internal/adapters/outbound/kafka -update.
  • cmd/api: boot configuration and defaults (main_test.go) and the telemetry bootstrap (telemetry_test.go).

Run one package or one test:

go test ./internal/domain/content -run TestPublish -v
go test ./internal/application/usecases -v

BDD (godog)​

features/ holds eight files: 101 Scenario and Scenario Outline definitions (git grep -c -E "^[[:space:]]*Scenario" -- features), which the runner expands to 123 executed scenarios (123 scenarios (123 passed) from go test ./internal/bdd -run TestFeatures -count=1 -v).

FileDefinitions / executedCovers
content_lifecycle.feature4 / 4complete draft published with one event, incomplete draft refused (incomplete-content), discarded draft, content of an unknown item (unknown-catalog-item)
catalogue_events.feature4 / 4CatalogItemDiscontinued retires published content (event raised) and drafts (no event), redelivery changes nothing, content for a discontinued item is refused (item-discontinued)
categories_and_api.feature6 / 6nested categories and CategoryTreePublished count, duplicate-sibling-name, idempotency-key-required, replay, idempotency-key-reused
revision_and_reads.feature9 / 9revise and republish, retired content never changes, reads and paging, category list and move, content limits, platform endpoints
content_rules.feature32 / 51the documented state transitions of ProductContent: ReviseDraft, ReviseContent, publish, retire, discard, the illegal edges, completeness
category_rules.feature21 / 21the category tree: four levels, moves, sibling names, name limits, tree versions
catalogue_policy_rules.feature14 / 17the catalogue facts and RetireOnDiscontinue: creation first, no revival, redelivery on the CloudEvents id, poison ids
api_rules.feature11 / 11Idempotency-Key (128 accepted, 129 malformed, reuse across resources, released retryable refusals, replays) and the list paging rules

The four *_rules.feature files pin rules documented in the Product Content documentation and in the troubleshooting slug table.

The runner internal/bdd/features_test.go (TestFeatures, step files steps_http_test.go, steps_assertions_test.go, steps_wave2_test.go and steps_rules_test.go) wires the real router and use cases over the in-memory store with a frozen clock, so the suite is fast and needs no Docker. Strict: true fails the run on an undefined or pending step. The module root holds no .go file (TestNoGoFilesAtRepoRoot).

Integration (testcontainers)​

All files carry //go:build integration and boot their own containers through internal/testing/pgtest and internal/testing/kafkatest; TestMain in cmd/api, outbound/outbox and outbound/postgres shuts them down. A missing Docker is a failure, never a skip.

SuitePackageWhat it proves
Real wiringcmd/api (2)with real Postgres and a real Kafka, a CatalogItemCreated event produced on the offer-availability topic makes content creatable, and after publish ProductContentPublished appears on the content topic keyed by the item id; a CatalogItemDiscontinued event retires the content with reason DISCONTINUED
A2A over Postgrescmd/a2a (1)the A2A agent reads real Postgres data and writes nothing
MCP over Postgrescmd/mcp (1)the real boot path (buildDeps) behind the real router: /healthz, tools/list returns exactly the two L1 read-only tools, a call reads what the write use cases persisted, an unknown item is a tool error, and the outbox row counts do not move
Repositoriesoutbound/postgres (1)TestPostgresHonoursTheRepositoryContract runs the whole repocontract suite against Postgres
Migrationsoutbound/postgres (1)TestMigrationsGoUpDownUp: up, down, up on an empty database
Outbox traceoutbound/postgres (1)the active traceparent is stored with the outbox row

make integration and the CI integration job run the same command, go test -tags=integration ./... -race -count=1. Two fitness tests fail the build if an integration test gates on DATABASE_URL or KAFKA_BROKERS or skips (TestPostgresIntegrationTestsUseTestcontainers, TestKafkaIntegrationTestsUseTestcontainers).

Mutation testing​

.gremlins.yaml sets workers: 1, timeout-coefficient: 30 and the thresholds efficacy: 99 and mutant-coverage: 99. 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-11-15: shared 31 mutants, category 47, content 76, each at 100% efficacy and 100% mutant coverage. 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; 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 rule (TestHexagonalArchitecture) and source-scanning sensors. Notable ones:

TestRule
TestHexagonalArchitecturesix arch-go rules: domain depends on no internal package except domain; application only on domain and application; inbound and outbound adapters never import each other; nothing under internal/ imports cmd/; internal/application/ports holds only interfaces
TestA2AAdapterDependencyRule, TestA2AAgentIsReadOnlyWithNoOutboundClientthe A2A adapter is additive and read-only, with no outbound client (ADR 0006)
TestMCPAdapterDependencyRule, TestMCPOptionalToolInputsCarryOmitemptythe MCP adapter depends only on application and domain, nothing else imports it, and every optional tool input carries omitempty (ADR 0008)
TestEveryMCPToolDeclaresAuthority, TestMCPWriteToolsAreAtLeastL3, TestA2ASkillsDeclareAuthority, TestMCPServerOffersResourceAndPromptevery MCP tool and A2A skill declares one authority level, a tool not provably read-only is L3 or above, and the MCP server offers a resource and a prompt (Agentic Standard v2)
TestRuntimeBinaryHasNoInMemoryAdapterscmd/* never imports outbound/memory
TestEventCatalogueMatchesContractevery full CloudEvents type string that apis/asyncapi.yaml declares for this service also appears in a *cloudevents*.md ADR (the type catalogue, ADR 0004)
TestCloudEventsOnly, TestNoEventEnvelopeToggleOrFlatEnvelopeevery Kafka message is a structured-mode CloudEvent built through the cloudevents package
TestKafkaWritersSetRequiredAcks, TestKafkaWriterTopicNotSetTwicewriter settings
TestDeadLetterCallsGuardCancellation, TestReplayConsumersSetCommitIntervalconsumer shutdown and commit behaviour
TestOutboxRelaysPassAttemptCapevery relay is built with an attempt cap
TestNoAuthMiddlewareReintroducedthe fleet removed REST and MCP bearer auth; it must not come back
TestNoGoFilesAtRepoRootthe module root stays free of Go files

Each source-scanning sensor has a companion that proves it can fail (...SensorBites, ...SensorFailsOnBadFixtures).

make arch-test

CI jobs​

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

JobRunsWhen
lintgolangci-lint v2.14.0, --timeout=5malways
guide-lintscripts/harness/guide_lint.py and test_hook.py; advisory (continue-on-error)always
complexitygolangci-lint with only gocyclo,gocognit,cyclop,funlen,nestif 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=1always
mutation-fastgremlins v0.6.0 on each package under internal/domain/*/always; blocking
mutationgremlins unleash ./internal/domain --workers 1 --timeout-coefficient 30; harness:red issue on failureschedule and dispatch only
driftdeadcode -test ./..., go mod tidy -diff and scripts/coverage-quality.py (high-coverage functions with a surviving mutant) written to the job summary; harness:red issue on a scheduled failureschedule and dispatch only
api-lintSpectral on apis/openapi.yaml and apis/asyncapi.yaml, --fail-severity=warnalways
vulngovulncheck ./...always
docs-api-driftnpm ci, npm run clean-api-docs and npm run gen-api-docs in docs/, then fails when docs/docs/api-reference/rest differs from what is committedalways
helm-lintct lint and helm lint with each charts/product-content/ci/*.yaml values filepull requests only
chart-testsevery charts/product-content/tests/*.sh and test_*.py; a printed SKIP fails the jobalways
arch-testgo test ./internal/architecture/... -valways
trivy-scanbuilds the image locally (not pushed), uploads a Trivy SARIF report (CRITICAL/HIGH/MEDIUM) and fails on a CRITICAL or HIGH OS/library finding that has a fixpull requests only
docker-publishbuild and push ghcr.io/iqvo/product-content, cosign signature, SBOM attestation; needs the jobs abovepush to main only
releasetags the next patch version, retags the image, pushes the Helm chart, creates the GitHub releasepush to main, 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. codeql.yml runs code scanning and ai-review.yml is an advisory architecture review.

Jobs shown as skipping on a pull request into develop (mutation, docker-publish, release) are gated by their if: conditions; that is expected.

ci.yml has no job that regenerates the REST reference and fails on a diff: after any change to apis/openapi.yaml, regenerate it yourself with npm run gen-api-docs in docs/.

Reproducing the docs build​

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

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