Skip to main content

Testing

The test pyramid as it is on this branch: a pure domain under a mutation gate, use cases and adapters with unit and httptest tests, a godog suite over the real use cases, testcontainers integration tests against real Postgres and Kafka, architecture fitness tests, and spec linting. Counts come from reading the test files (func Test... per package); many tests are table-driven, so the number of cases is larger. Nothing on this page is a captured run.

LayerCount / thresholdCommand
Unit, domain56 top-level test functions in 4 packages (productview 24, search 20, categoryview 10, shared 2)make test
Unit, application23 in internal/application/usecases (6 files, including concurrency and metrics)make test
Unit and httptest, adapters and binariesinbound/http 19, inbound/kafka 32, inbound/a2a 20, inbound/mcp 21, inbound/requestlog 4, kafka/cloudevents 6, outbound/kafka 4, outbound/memory 1 (the repository contract), outbound/sources 7, outbound/telemetry 11, bootretry 6, cmd/api 16, cmd/a2a 14, cmd/mcp 15, cmd/rebuild 6make test
Coverage gate90 % over ./internal/domain/...,./internal/application/... (COVERAGE_THRESHOLD)make coverage
BDD (godog / Gherkin)8 feature files, 111 scenario definitions (179 executed with the Examples rows expanded); strict modemake bdd
Integration (testcontainers)8 tests behind //go:build integration in 9 files: cmd/api 3, cmd/a2a 1, cmd/mcp 1, cmd/rebuild 1, outbound/postgres 2 (plus one TestMain in each package that boots the shared container)make integration
ContractThe repository contract suite (internal/adapters/outbound/repocontract) runs against the in-memory store and against real Postgres; Spectral lints both specs; no consumer-driven or schemathesis contract testsmake test, make integration, CI api-lint
Architecture fitness44 top-level test functions in internal/architecture (17 files); two skip here on purpose, see belowmake arch-test
Mutation (gremlins)efficacy 99, mutant coverage 99 (.gremlins.yaml); the file records a 100 % / 100 % measurement over every package of internal/domainmake mutation, make mutation-full
Evalsnone: EVALS.md at the repository root is the harness template's note about agent evaluation on another service; it measures nothing in this repositorynone

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 the four binaries
make vetgo vet ./...
make fmt / make fmt-checkgofmt -w . / fail when 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 the godog suite (it is an ordinary Test function); no database needed
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 the repository lint
make arch-testgo test ./internal/architecture/... -v
make bddgo test ./... -run TestFeatures -vthe godog suite, internal/bdd/features_test.go
make integrationgo test -tags=integration ./... -race -count=1needs only Docker; every test boots its own Postgres and Kafka; not part of check / check-all
make mutationgremlins unleash on each directory of ./internal/domain/*/ (productview, categoryview, search, shared)the fast, blocking gate; 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 testwhat the pre-push hook runs (lefthook.yml)
make check-allcheck coverage arch-test bddrun before pushing
make check-fastfmt-check vet arch-test plus go test of the packages changed against HEADthe agent Stop hook
make guide-lint / make harness-testscripts/harness/guide_lint.py / scripts/harness/test_hook.pyagent-guide checks, not product tests

Run one package or one test:

go test ./internal/domain/productview -run TestPurchasable -v
go test ./internal/application/usecases -v

Unit tests​

  • Domain (productview, search, categoryview, shared): pure, standard library only, no fixtures. They pin the fold rules and their per-source guards (listing asOf, content revision, price version), the stub-row behaviour, the PurchasableRule, query validation and the cursor, the price bands, the facet tallies, the trigram similarity and category-name matching, and the category tree checks (duplicate id, unknown parent, cycle, version guard).
  • Use cases (internal/application/usecases): the consumer folds, the three queries and the rebuild run against the in-memory adapters, which are test doubles only: the shipped binaries never import them (runtime_no_memory_fitness_test.go enforces it). concurrency_test.go covers the retry on a serialization failure; queries_metrics_test.go the served / empty / failed counter.
  • HTTP adapter: httptest over the real router (products_test.go, search_test.go, readiness_test.go, telemetry_test.go).
  • A2A adapter: the Agent Card, the skill dispatch table, strict argument decoding and the parity of the skill answers with REST (skills_test.go, card_test.go, cmd/a2a/router_test.go).
  • 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), plus deadletter_test.go, dispatch_test.go, pipeline_test.go, tracing_test.go and topic_not_ready_test.go.
  • Rebuild sources: sources_test.go against httptest servers (paging, retries on 5xx, status handling).
  • Binaries: environment parsing and boot errors (cmd/api/main_test.go, cmd/a2a/bootconfig_test.go, cmd/rebuild/main_test.go), shutdown behaviour, telemetry wiring.

BDD (godog)​

features/*.feature holds eight files: 111 Scenario and Scenario Outline definitions (git grep -c -E "^[[:space:]]*Scenario" -- features), executed as 179 scenarios once the Examples rows are expanded (179 scenarios (179 passed) from go test ./internal/bdd -run TestFeatures -count=1 -v).

FileDefinitions / executedCovers
search.feature8 / 8full-text, typo fallback, category suggestions, AND filters, subtree filter, facets over the whole result, cursor paging, validation failures
folding.feature6 / 6eleven kinds of fact make one purchasable product, facts before the item master stay invisible, a discontinued item, a suppressed listing, the per-listing guard, a redelivered event
folding_wave2.feature5 / 5the removal facts (retired content, withdrawn price, created listing), the bootstrap rebuild, a bad cursor and the platform endpoints
categories.feature4 / 4counts roll up, a rename shows at once, an older tree version is ignored, an empty list before the first tree
fold_rules.feature31 / 60the documented fold rules of item master, listings, price and content (version guards, boundaries, redelivery)
read_rules.feature31 / 54the read side: filters, price bounds, ranking, suggestions, typo fallback, ordering and paging, facets, categories
rest_rules.feature14 / 30the REST contract: limit and cursor errors, unknown-query-parameter, NUL, methods, problem shape, ETag and If-None-Match
rebuild_rules.feature12 / 12RebuildProjections: snapshots never rewind events, skipped rows, paged reads, a failing page and the re-run

The four *_rules.feature files pin rules documented in the Product Discovery documentation, ADR 0002 and the troubleshooting page. The runner is internal/bdd/features_test.go (TestFeatures, godog Paths: ../../features, Strict: true). It wires the real use cases over the in-memory store and reads through the real HTTP router, so the scenarios are fast and need no Docker.

Integration (testcontainers)​

Every file carries //go:build integration and boots its own containers (internal/testing/pgtest, internal/testing/kafkatest); there is no DATABASE_URL or KAFKA_BROKERS gate and no skip.

TestPackageWhat it proves
TestRealWiringFoldsEventsFromThreeTopicsIntoOneSearchableProductcmd/apithe real entry point on real Postgres and Kafka: events from the three topics fold into one searchable, purchasable product read back over REST
TestRealWiringPoisonMessageGoesToTheDeadLetterTopiccmd/apia message that can never be applied lands on <topic>.dlq and the consumer moves on
TestRealWiringReadyzTurns503WhenKafkaStopscmd/api/readyz follows the Kafka broker
TestRealWiringAgentReadsPostgresOverTheWirecmd/a2athe agent boots on real Postgres and answers both skills
TestRebuildSeedsARealDatabaseAndIsRepeatablecmd/rebuildthe rebuild fills the projections from stub snapshot servers, and a second run is harmless
TestPostgresHonoursTheRepositoryContractoutbound/postgresthe shared repository contract (repocontract.Run) passes on Postgres exactly as on the in-memory store
TestMigrationsGoUpDownUpoutbound/postgresthe migration applies, reverts and applies again

make integration and the CI integration job run the same command. Fitness tests fail the build if an integration test gates on environment variables or hard-codes a broker address (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 2026-10-25 measurement of 100 % efficacy and 100 % mutator coverage over productview, categoryview, search and shared. Only the domain is mutated, not use cases or adapters.

CI runs the fast loop on every push and pull request (mutation-fast, blocking) and the exhaustive ./internal/domain run on the weekly schedule and on manual dispatch (mutation); a failing scheduled run opens or refreshes a harness:red issue (scripts/harness/red_issue.py).

Architecture fitness tests​

internal/architecture holds the dependency-direction rules (TestHexagonalArchitecture: domain depends on nothing internal, application only on domain, inbound and outbound adapters never on each other, only cmd wires every layer, ports holds only interfaces) and source-scanning sensors, among them:

TestGuards
TestA2AAdapterDependencyRule, TestA2ASourcesStayReadOnlythe A2A adapter depends inward only and never writes
TestNoAuthMiddlewareReintroducedno auth middleware (fleet decision)
TestCloudEventsOnly, TestNoEventEnvelopeToggleOrFlatEnvelope, TestEventCatalogueMatchesContractCloudEvents 1.0 only; the consumed type catalogue matches apis/asyncapi.yaml
TestKafkaConsumerGroupNeverHardcodedInline, TestReplayConsumersSetCommitInterval, TestKafkaWritersSetRequiredAcks, TestKafkaWriterTopicNotSetTwice, TestDeadLetterCallsGuardCancellationconsumer group from the environment, explicit commits, RequireAll acks, no double topic, cancellation-safe dead letters
TestNoInOrgNetworkRouteoutbound HTTP calls stay within docs/network-ohs-allowlist.yaml
TestRuntimeBinaryHasNoInMemoryAdapters, TestNoGoFilesAtRepoRootbinaries never import the memory adapters; no Go file at the module root
TestPostgresIntegrationTestsUseTestcontainers, TestKafkaIntegrationTestsUseTestcontainersintegration tests start their own containers

Each sensor that scans source also has a test that proves it can fail (...SensorBites, ...SensorFailsOnBadFixtures). Two tests skip on purpose because this service has neither: the MCP optional-input sensor (mcp_optional_inputs_test.go, no internal/adapters/inbound/mcp) and the outbox relay cap (outbox_relay_cap_fitness_test.go, no relay). TestMCPAdapterDependencyRule passes trivially for the same reason.

make arch-test

CI jobs​

.github/workflows/ci.yml runs on push and pull request to main and develop, weekly on Monday 06:00 UTC (mutation only) 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 (gate 15) plus an informational gocyclo reportalways
file-lengththe revive file-length limit (at most 300 lines of code per production Go file, settings in .golangci.yml): blocking for the Go files a pull request into develop adds or touches; an informational report of the whole backlog otherwisealways
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 every ./internal/domain/*/ package; blockingalways
mutationgremlins unleash ./internal/domain --workers 1 --timeout-coefficient 30, harness:red issue handlingschedule 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 (.spectral.yaml) and apis/asyncapi.yaml (.spectral.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 ci/default-values.yaml and ci/all-components-values.yamlpull requests only
chart-testsevery charts/product-discovery/tests/*.sh and test_*.py (render_test.sh, test_service_selectors.py); a test that prints 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-discovery, 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

Other workflows: docs.yml builds this site on pull requests (and deploys to GitHub Pages only on push to main), codeql.yml runs CodeQL, ai-review.yml is an advisory review on pull requests. Jobs that show 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, so regenerate it yourself after any change to apis/openapi.yaml (see below).

Reproducing the docs build​

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

The build fails on a broken link (onBrokenLinks is throw). After a change to apis/openapi.yaml run npm run clean-api-docs and npm run gen-api-docs to refresh docs/docs/api-reference/rest/. Mermaid diagrams are checked with scripts/validate-mermaid.cjs of the warehouse-docs repository, because docusaurus build alone never catches a broken diagram.