Testing
The test pyramid as it exists on develop, the make targets that run each
layer, and the CI jobs that gate a pull request. Every count on this page
was recounted on 2026-10-19 from develop at 3312858 (after the analytics
read side, ADR 0006, and the real-only runtime, ADR 0011).
Source: Makefile, .github/workflows/ci.yml, features/*.feature,
.gremlins.yaml, internal/architecture/*_test.go.
Make targets
| Target | Command | Needs | In check / check-all |
|---|---|---|---|
make test | go test ./... -race | nothing (no database, no broker) | both |
make coverage | go test ./... -race -coverprofile=coverage.out -coverpkg=./internal/domain/...,./internal/application/... plus the 90 % gate | nothing | check-all |
make bdd | go test ./... -run TestFeatures -v | nothing | check-all |
make arch-test | go test ./internal/architecture/... -v | nothing | check-all |
make integration | go test -tags=integration ./... -race -count=1 | Docker only | neither |
make mutation | gremlins unleash on ./internal/domain/slotplan, then ./internal/domain/planning | gremlins v0.6.0 | neither |
make mutation-full | gremlins unleash ./internal/domain --workers 1 --timeout-coefficient 30 | gremlins | neither |
make lint | golangci-lint run ./... (complexity limits in .golangci.yml) | golangci-lint v2.14.0 | both |
make vuln | govulncheck ./... | govulncheck | neither |
make check | fmt-check vet build lint test | the pre-commit gate | |
make check-all | check coverage arch-test bdd | run before pushing | |
make check-fast | fmt-check vet arch-test plus the tests of the Go packages changed vs HEAD | python3 | the agent Stop hook |
lefthook (lefthook.yml) runs fmt-check, vet and lint on commit and
make check on push.
Unit tests
Plain go test, no build tag, no I/O.
| Area | Where | What it pins |
|---|---|---|
| Aggregate | internal/domain/slotplan/{plan,values}_test.go | every invariant of Restore, the Draft -> Approved/Rejected, Approved -> Superseded transitions, the events and their headers |
| Execution (ADR 0010) | internal/domain/slotplan/execution_test.go | ParseMoveRef (<plan_id>:<move_seq>, digits only), NewRelocation required fields, MatchRef / MatchBins per kind and every unmatched reason, Progress (executed moves, summed quantities, latest instant, out-of-range positions ignored) |
| Planner | internal/domain/planning/planner_test.go | candidates, ABC thresholds, hazmat and temperature compatibility, capacity, stickiness, move diffing, determinism |
| Use cases | internal/application/usecases/*_test.go with fakes_test.go | unit-of-work boundaries, version guards, supersede-on-approve, consumer outcomes (applied, duplicate, stale, ignored); record_relocation_test.go: reference first, bins fallback, unmatched is claimed not recorded, CloudEvents-id and relocation-id dedupe, invalid facts touch nothing, transient errors roll back, GetPlan.View progress |
| HTTP | internal/adapters/inbound/http/*_test.go (not _integration) | routes through httptest, problem mapping, readiness |
| Kafka in | internal/adapters/inbound/kafka/*_test.go | dispatch by full type, skip vs retry, backoff sequence, dead-lettering with fake readers and writers; stock_consumer_test.go: inventory-storage's AsyncAPI StockRelocated example decoded byte for byte (testdata/inventory_StockRelocated.golden.json), the move reference, poison dead-lettered at once, unmatched committed, other types skipped, shutdown never dead-letters; TestDomainDLQWriter_TopicComesFromTheMessage |
| HTTP / MCP execution view | internal/adapters/inbound/http/execution_handlers_test.go, internal/adapters/inbound/mcp/execution_tool_test.go | execution on GET /slot-plans/{planId} and get_slot_plan (camelCase vs snake_case, omitted fields) |
| Kafka out, relay | internal/adapters/outbound/{kafka,outbox}/*_test.go | CloudEvents encoding (golden), sink settings, relay batching; the attempt cap over the in-memory store (relay_cap_test.go: TestRelay_MaxAttempts_PoisonRowExcludedThenGoodRowPublishes, TestRelay_NoCap_PoisonRowBlocksLaterRows, TestRelay_MaxAttemptsNegativeIgnoredAndDefaultIsTwenty, TestRelay_SendFailureCarriesTheRow; ADR 0008) |
| In-memory adapters | internal/adapters/outbound/memory/memory_test.go | the shared repository contract in internal/testing/repocontract |
| Analytics read model (ADR 0006) | internal/analytics/report/report_test.go | the three projected kinds, Event.Validate, MilestonesOf, ParseGranularity, ParseRange (defaults, 366-day cap, inverted ranges), DayWindows, ComputeFreshness (no negative lag), Percentile (linear interpolation, the percentile_cont definition), TimingOf |
| Analytics store | internal/adapters/outbound/analyticsstore/contract_test.go | TestMemory_Contract: the shared projection/reader contract over the in-memory twin (the Postgres twin runs it under the integration tag) |
| Analytics stream and projector consumer | internal/adapters/outbound/kafka/analytics_encoder_test.go, internal/adapters/inbound/kafka/analytics_consumer_test.go, analytics_consumer_internal_test.go | the analytics golden wire format; FanoutEncoder: two rows and one id per event, the whole call fails on an unknown event, topic overrides, unique ids across occurrences; the consumer applies valid events, skips what it cannot route, dead-letters deterministic failures at once, retries transient ones without committing, never fails on a skip; the skip sampler; TestAnalyticsKindsCoverExactlyTheThreePublishedTypes |
| Reports HTTP | internal/adapters/inbound/http/reports_handler_test.go | funnel report shape, defaults and validation (invalid-report-range, invalid-report-granularity), freshness, 500 report-store-error, /healthz |
| Projector and reports roots | cmd/slotting-projector/main_test.go, cmd/slotting-reports/main_test.go | loadConfig defaults and overrides, fail-fast without the analytical DSN or brokers, /healthz vs /readyz flip on shutdown, a malformed DSN, LOG_LEVEL mapping |
| Composition root | cmd/api/main_test.go, outbox_relay_config_test.go, logger_level_test.go; cmd/mcp/main_test.go; cmd/api/e2e_integration_test.go | env parsing (the boot refusals of loadRuntime as a table asserting the error names the variable: TestLoadRuntimeRefusesWithAnErrorNamingTheVariable, TestLoadRuntimePermissiveMessageNamesRealKafka, TestNoDatabaseURLIsABootErrorEverywhere; relay interval, OUTBOX_MAX_ATTEMPTS (TestOutboxMaxAttempts, TestDefaultOutboxMaxAttemptsIsTwenty), LOG_LEVEL incl. warning (TestNewLoggerLevels in both binaries), LOOKBACK_DAYS, FORWARD_ZONE_CODES, DEMAND_SITE_ID/DEFAULT_SITE_ID, drain delay, MIGRATIONS_DATABASE_URL), consumers and relay start and stop, a worker that dies (TestWatchWorkersReportsAWorkerThatDied), the readiness dependencies, and TestRunOnRealPostgresAndKafka (integration tag): the real run() on testcontainers Postgres and Kafka driven only through REST and Kafka, including the exit when Kafka goes away. The composition root has no in-memory runtime: unit tests build the doubles directly (cmd/api/testdoubles_test.go) |
| Boot retry, telemetry, ids, clock | their packages |
Integration tests (testcontainers)
Twenty-one files in ten packages carry //go:build integration:
| Package | Files | Backing services and what the suite proves |
|---|---|---|
internal/adapters/outbound/postgres | main_integration_test.go, repositories_integration_test.go | Postgres: the same repocontract suite the memory adapters pass (TestSlotPlanRepoContract, TestDemandLedgerContract, TestProfileDirectoryContract, TestSlotCatalogueContract, TestMoveExecutionLedgerContract), the execution ledger joining the unit of work (TestMoveExecutionLedgerJoinsTheUnitOfWork), one Approved plan per site enforced by the database, the unit of work committing or rolling back plan, outbox and claim together, claim-once, outbox drain order and failure handling |
internal/adapters/outbound/postgres/pgtx | pgtx_integration_test.go (its own TestMain) | Postgres: the transaction bracket every write relies on, through the real repositories and postgres.UnitOfWork. A plan save and its outbox rows commit together (TestPgtx_SaveAndPublishCommitAtomically); an error inside the scope rolls back the plan, the outbox rows and the processed-event claim (TestPgtx_AnErrorInsideTheScopeRollsEverythingBack); a reader on the pool sees nothing before commit (TestPgtx_ReposOutsideTheScopeSeeNothingUntilCommit); a nested Do joins the outer transaction (TestPgtx_NestedUnitOfWorkJoinsTheOuterTransaction); pgtx.With/pgtx.From carry a bare pgx transaction to the repositories (TestPgtx_ExplicitWithFromCarriesTheTransactionToAnyQuerier) |
internal/adapters/outbound/outbox | main_integration_test.go, relay_integration_test.go, relay_cap_integration_test.go, outbox_trace_integration_test.go | Postgres + Kafka: TestRelay_RealPostgresAndKafka_PublishesCloudEventsKeyedByPlanID. The attempt cap over real Postgres (ADR 0008): a poison row is excluded after the cap, logged once at ERROR with id, topic, type and key, and the good row of the same key behind it publishes (TestOutboxRelay_MaxAttempts_PoisonRowExcludedThenGoodRowPublishes); the runbook's re-arm SQL makes it claimable again (TestOutboxRelay_MaxAttempts_ReArmedRowIsClaimedAgain); without a cap the poison row blocks everything (TestOutboxRelay_NoCap_PoisonRowBlocksLaterRows). Trace continuity (ADR 0009): the approve request's traceparent is stored in outbox_events.headers, relayed by a background pass and extracts to the request span (TestOutboxTrace_TraceparentCrossesTheOutboxToKafka); a row without stored headers relays unchanged with none (TestOutboxTrace_RowWithoutTraceHeadersRelaysUnchanged) |
internal/adapters/outbound/kafka | main_integration_test.go, publisher_integration_test.go | Kafka: the production Encoder and RelaySink (the writer settings cmd/api builds) publish the aggregate's three event kinds, then the test reads them back from the broker and asserts the CloudEvents 1.0 envelope (specversion, id, source, the com.warehouse.wms.slotting-optimization.slotplan.<Event> type), the content-type header, the payloads pinned in apis/asyncapi.yaml and a re-sent outbox row carrying the same CloudEvents id (TestKafkaPublisher_RealBrokerPublishesTheCloudEventsContract); every event of one plan carries the plan id as the Kafka key (TestKafkaPublisher_OnePlanSticksToOnePartitionKeysOrdering) |
internal/adapters/inbound/http | main_integration_test.go, helpers_integration_test.go, idempotency_integration_test.go | Postgres: the Idempotency-Key middleware (400 without a key, replay of the original plan, 422 on a different body, different keys make different plans, a rejected request is cached too, concurrent requests with one key create one plan), approve end to end, racing approvals of one site leave one Approved plan |
internal/adapters/inbound/kafka | main_integration_test.go, consumers_integration_test.go, stock_consumer_integration_test.go, analytics_consumer_integration_test.go | Postgres + Kafka: the demand, product and layout consumers end to end; the StockRelocated consumer (ADR 0010, TestStockConsumer_RealKafkaAndPostgres): a relocation with the move reference updates the plan's progress, a redelivery and a replay under a new id count once, an unmatched relocation is committed past, and the poison message is the only one on warehouse.inventory.events.dlq; the projector's consumer over a real analytical database (TestAnalyticsConsumer_RealKafkaAndPostgres) |
internal/adapters/outbound/analyticsstore | postgres_integration_test.go | Postgres: the shared contract over the real store (TestPostgres_Contract), the analytical migrations up and down repeatably, the claim and the effect commit atomically, an integrity violation becomes ErrRejected, the read-only pool cannot write, the SQL day windows equal the Go definition |
cmd/api | e2e_integration_test.go | Postgres + Kafka: TestRunOnRealPostgresAndKafka boots the real run() and drives it only through REST and Kafka, including the exit when Kafka goes away |
cmd/mcp | main_integration_test.go | Postgres: the MCP binary migrates a database itself, reads through every tool what the api's write use cases persisted, and adds no outbox row (TestMCPAgainstPostgres_ReadsWhatTheAPIWroteAndNeverWrites) |
internal/application/usecases | main_integration_test.go, wiring_integration_test.go | Postgres: the write use cases wired like cmd/api (real Postgres repositories, unit of work, CloudEvents encoder and read-model adapters; only the clock is fixed). The local copies are seeded through the real ledger, profile directory and slot catalogue, then generate, approve, a second approval that supersedes the first, regeneration stickiness and a rejection are checked against the persisted state and the read models (TestUsecases_WiringPlanLifecycleEndToEnd). Every outbox row the lifecycle wrote is decoded as a CloudEvents 1.0 envelope with its pinned payload (TestUsecases_WiringPublishedEventsCarryTheCloudEventsContract) |
internal/testing/pgtest starts one postgres:16-alpine container per test
binary and clones a migrated template database per test (pgtest.NewPool(t));
internal/testing/kafkatest starts one confluentinc/confluent-local:7.6.1
broker per test binary and gives each test its own timestamp-suffixed topic
(kafkatest.Topic). Both start their container lazily, on first use. Each
integration package has a TestMain that runs the tests and then calls
pgtest.Shutdown() and/or kafkatest.Shutdown(). Neither helper reads
DATABASE_URL or KAFKA_BROKERS and neither skips, so a missing Docker
daemon fails the run. Two fitness tests keep it that way
(TestPostgresIntegrationTestsUseTestcontainers,
TestKafkaIntegrationTestsUseTestcontainers). They check imports, so a
suite that only goes through the helpers still names the testcontainers
module itself: the Kafka check wants testcontainers-go/modules/kafka in
every Kafka-touching _integration_test.go file (the publisher suite keeps a
tckafka reference for that), and the Postgres check wants
testcontainers-go/modules/postgres somewhere in each package that uses
pgx or database/sql (the usecases and pgtx suites keep a tcpostgres
reference).
make integration and the CI integration job both run
go test -tags=integration ./... -race -count=1, so every package above runs
in CI with no explicit package list to keep in sync.
BDD (godog)
features_test.go (TestFeatures) and features_wave2_test.go drive the
real chi router over HTTP and feed the local copies through the real
consumers' HandleMessage with raw CloudEvents, over the in-memory adapters
wired the way cmd/api wires them, with a fixed clock (2026-10-08 12:00 UTC)
and sequential plan ids. Strict mode: an undefined step fails. The execution
ledger is wired into the unit of work and GetPlan, and the real StockRelocated
consumer runs with a recording metrics port and a dead-letter stub, so the
execution progress of GET /slot-plans/{id} and the relocation outcomes are
reachable from the suite. The *_rules.feature files pin the rules the
context documentation and ADR 0010 state, one rule per scenario with boundaries
as Outline rows; their steps are in steps_rules_test.go.
The runner executes 290 scenarios once every Outline Examples row is
expanded (the N scenarios line of
go test . -run TestFeatures -count=1 -v); the table counts definitions
(^[[:space:]]*Scenario in features/). BDD-only statement coverage over
./internal/... (go test . -run TestFeatures -count=1 -coverpkg=./internal/...)
is 58.0 %.
| Feature file | Scenario / Scenario Outline blocks |
|---|---|
features/generate_plan.feature | 9 |
features/generate_plan_request.feature | 6 |
features/approve_and_reject.feature | 10 |
features/plan_decisions_and_events.feature | 20 |
features/velocity_and_listing.feature | 5 |
features/planning_policy_rules.feature | 16: ABC class edges, ordering, one SKU per slot, capacity fit, hazmat and temperature, stickiness |
features/local_copies_rules.feature | 30: demand window, product and physical versions, layout upserts, invalid payloads |
features/plan_lifecycle_rules.feature | 29: state machine, reasons, list filters and paging, NUL and body-size guards |
features/relocation_execution_rules.feature | 18: move reference, quantities, duplicates, unmatched reasons, poison payloads |
features/relocation_matching_rules.feature | 5: bins per move kind without a reference |
| Total | 148 (34 of them outlines with example tables) |
Mutation testing
.gremlins.yaml: workers: 1, timeout-coefficient: 30, thresholds
efficacy: 99 and mutant-coverage: 99 (gremlins fails at or below the
threshold). Measured on 2026-10-08: internal/domain/slotplan 72 killed / 0
lived, internal/domain/planning 46 killed / 0 lived, both 100 %.
Architecture fitness tests
internal/architecture (make arch-test, CI job arch-test):
| Test | Rule |
|---|---|
TestHexagonalArchitecture | domain imports nothing from application or adapters; ports holds interfaces only; adapters never import each other; internal/analytics/** imports nothing internal but itself, and the OLTP domain and application never import it or analyticsstore (ADR 0006) (arch-go) |
TestRuntimeBinaryHasNoInMemoryAdapters, TestRuntimeBinarySensorBites | no file under cmd/** imports internal/adapters/outbound/memory (ADR 0011) |
TestMCPAdapterDependencyRule | the MCP adapter (internal/adapters/inbound/mcp) depends only on the application and domain layers and nothing imports it |
TestMCPOptionalToolInputsCarryOmitempty, TestMCPOptionalToolInputsSensorFailsOnBadFixtures | an MCP tool input whose jsonschema description calls it optional (optional / omitted) has omitempty in its json tag, or the SDK would mark it required (gap fix D16) |
TestOutboxRelaysPassAttemptCap, TestOutboxRelayCapSensorFailsOnBadFixtures | every non-test file under cmd/ that builds an outbox relay passes WithMaxAttempts (gap fix D12, ADR 0008) |
TestNoAuthMiddlewareReintroduced | no auth middleware on the router (fleet decision) |
TestKafkaConsumerGroupNeverHardcodedInline | group ids come from the environment |
TestKafkaIntegrationTestsUseTestcontainers, TestPostgresIntegrationTestsUseTestcontainers, TestPostgresIntegrationSensorFailsOnBadFixtures | integration tests boot real containers and never skip |
TestNoEventEnvelopeToggleOrFlatEnvelope, TestCloudEventsOnly | CloudEvents 1.0 only, built in one package |
TestReplayConsumersSetCommitInterval | a reader whose GroupID is a per-run unique group must set CommitInterval (no such reader exists here; the five api consumers and the projector use env-provided groups and synchronous commits) |
TestEventCatalogueMatchesContract, TestEventCatalogueDetector | the published types match apis/asyncapi.yaml |
TestKafkaWritersSetRequiredAcks, TestKafkaWriterAcksSensorBites | Every kafka-go Writer composite literal in a non-test file under internal/ or cmd/ sets RequiredAcks (the import alias is resolved per file). kafka-go defaults it to RequireNone (acks=0): the broker never confirms the write, so a broker blip silently drops the message while WriteMessages returns nil. The twin proves the sensor flags a bad fixture under any alias. |
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.) |
Contract and API checks
There is no schemathesis (or other runtime contract) job in this repository.
The contracts are checked statically: the api-lint job runs Spectral on
apis/openapi.yaml (.spectral.yaml) and apis/asyncapi.yaml
(.spectral.asyncapi.yaml) with --fail-severity=warn, and the CloudEvents
golden tests plus TestEventCatalogueMatchesContract tie the encoder to the
AsyncAPI document.
Evals
EVALS.md records the harness evaluations (tools/harness_eval.py,
tools/harness_eval2.py): agent runs against inventory-storage and
fulfillment-execution comparing guided and unguided agents. They are not
tests of this service and do not run in CI.
CI
.github/workflows/ci.yml (on push to main/develop, every pull request
into them, weekly schedule, manual dispatch):
| Job | Runs | On a PR into develop |
|---|---|---|
lint | golangci-lint v2.14.0 | blocking |
guide-lint | scripts/harness/guide_lint.py and test_hook.py | advisory (continue-on-error) |
complexity | golangci-lint with only gocyclo,gocognit,cyclop,funlen,nestif, plus an informational gocyclo report | blocking |
test | go build, go vet, then make coverage (go test ./... -race with the Makefile's coverage scope, domain and application, and the 90 % gate) | blocking |
bdd | go test ./... -run TestFeatures -v | blocking |
integration | go test -tags=integration ./... -race -count=1 (testcontainers on the runner's Docker) | blocking |
mutation-fast | gremlins on slotplan and planning | blocking |
mutation | gremlins on ./internal/domain | skipped (schedule and dispatch only); opens or closes a harness:red issue |
drift | deadcode, go mod tidy -diff, coverage-quality report | skipped (schedule and dispatch only), advisory |
api-lint | Spectral on both specs | blocking |
vuln | govulncheck ./... | blocking |
arch-test | go test ./internal/architecture/... -v | blocking |
helm-lint | ct lint and the Service selector test | pull requests only |
chart-tests | charts/slotting-optimization/tests/render_test.sh (the api Deployment mounts the ConfigMap with envFrom; OUTBOX_MAX_ATTEMPTS defaults to 20 and renders 0; every os.Getenv / getenv literal of the four cmd/*/main.go is rendered into its Deployment; no ConfigMap key is read by no binary; mcp does not mount the ConfigMap; the analytics components render only with analytics.enabled and a DSN source, the projector without a Service and without the api's OLTP env), and test_service_selectors.py (tests/test_kong_config.py exists, but no CI job runs it) | every push and PR; not a required check (branch protection unchanged) |
trivy-scan | builds the image locally and scans it with Trivy (SARIF uploaded; blocking on CRITICAL/HIGH with a fix available) | pull requests only |
docker-publish, release | image, signature, SBOM, Helm chart, GitHub release | skipped (push to main only) |
Other workflows: docs.yml builds this site on every pull request touching
docs/** or apis/** and deploys GitHub Pages from main; selftest.yml
runs the harness template's own checks (hook tests, repo_lint tests,
Python compile, the architecture tests, the migration tool); ai-review.yml
is the automated review workflow.