Skip to main content

Testing and CI

The test pyramid as it is in this repo on develop, the make targets that run each layer, and what every CI job in .github/workflows/ci.yml does.

Layers at a glance​

LayerWhereHow manyRun withNeeds
Unit (domain, use cases, adapters with fakes, httptest)internal/**/*_test.go, cmd/netfulfil/*_test.go68 test files without a build tag (not counting the BDD and architecture files below)make testGo only
BDD / acceptance (godog)features/*.feature, step code in features_*_test.go at the repo root20 feature files, 192 Scenario/Scenario Outline blocks that expand to 279 executed scenarios, 2292 steps; no scenario is tagged @known-bug any moremake bddGo only
Integration (testcontainers)files with //go:build integration20 filesmake integrationDocker
Architecture fitnessinternal/architecture/11 files, 25 Test* functionsmake arch-testGo only
Mutationgremlins on ./internal/domain/networkorderthresholds in .gremlins.yamlmake mutationgremlins v0.6.0
API contract lintapis/openapi.yamlSpectral, .spectral.yamlCI api-lint onlyNode 20
Chart testscharts/network-fulfillment/tests/*.py2 scriptsCI helm-lint onlyHelm, Python, PyYAML
Frontendweb/src/**/*.test.ts(x)2 test files (vitest)npm test in web/Node; no CI job

There is no contract test against a running server (no schemathesis), no consumer-driven contract test, and no eval suite in this repo.

Unit tests​

make test runs go test ./... -race. No database, broker or network is needed: unit and BDD tests use the in-memory repositories (test doubles, not a runtime mode), the stub gateway and fake ports. Notable suites:

  • internal/domain/networkorder and internal/domain/capabilityoffer: every lifecycle transition and invariant, plus ParseState/ParseBasis. For the hold (ADR 0024): network_order_hold_test.go (RecordHold, SettleHold, HoldOrphaned at every state and at the grace boundary) and network_order_committed_test.go (CommittedLocalOrderId).
  • internal/application/usecases: each use case, including failure_paths_test.go (planner, gateway and repository failures), cycle_time_eligibility_test.go (ADR 0017) and events_test.go. For ADR 0024: sweep_orphaned_holds_test.go (every order-management answer, the grace, the outcome never marked done on a failure, one event per hold) and hold_recording_test.go (the hold is recorded at raise; freeHold records CANCELLED with the rejection).
  • internal/adapters/outbound/ordermanagement/cancel_answers_test.go: the cancel's 404 and 409/422 become the two contract sentinels, and the breaker counts them as answers, not failures.
  • internal/adapters/inbound/{http,mcp}/hold_exposure_test.go: localOrderId stays absent for a NEW or REJECTED order even though the hold is recorded.
  • cmd/netfulfil/orphan_hold_config_test.go: ORPHAN_HOLD_SWEEP_ENABLED (on by default, a typo keeps it on) and ORPHAN_HOLD_GRACE (0 valid, negative or malformed uses 1h).
  • internal/adapters/outbound/telemetry/orphan_hold_metrics_test.go: the network_fulfillment.orphaned_holds.swept counter and its outcome attribute.
  • The node profile (ADR 0027 part 1): internal/application/usecases/declare_node_profiles_test.go (what the caches support, the skips and their logged reasons, ceilings never lowered, a fingerprint that follows content and not order, one site's failure never stops the others); internal/adapters/outbound/retailnetwork/profile_request_test.go and contract_test.go (the body against the vendored OpenAPI, which is byte-identical to vendor-connectivity's apis/openapi.yaml); gateway_live_profile_test.go (the revision, restart, retry, stale-revision recovery and race paths against a stateful fake Vendor API that judges a revision as node-topology does); pgstore_profile_integration_test.go (integration tag: the guarded monotonic write, 16 racing writers, migration 0010 up/down/up with data, and a fresh database migrated through every migration, down one step and up again); processpathcache/schedule_test.go; telemetry/node_profile_metrics_test.go; cmd/netfulfil/profile_test.go (NETWORK_PROFILE_INTERVAL, the wiring and the worker's start and stop); and the chart's render_test.sh and test_env_parity.py.
  • The inventory feed (ADR 0027 part 2): internal/application/usecases/feed_inventory_test.go (the pass, the complete flag and its edge cases, the 5000 split, the fingerprint, unlisted SKUs said once, one site's failure never stopping the others); internal/adapters/outbound/producttranslation/site_test.go (the optional site and the inverse lookup per site); retailnetwork/gateway_live_inventory_test.go (the feed against a stateful fake Vendor API: ledger, key, restart, the hourly repeat, a refused listing left out, ErrFeedAlreadyApplied); pgstore_inventory_integration_test.go and pgstore_profile_integration_test.go (integration tag: the feed state and the refused listings on a real Postgres, the ledger accepting INVENTORY, and migration 0011 up, down and up with data, plus a fresh database migrated through every migration, down one step and up again); cmd/netfulfil/inventory_feed_test.go (NETWORK_INVENTORY_INTERVAL, the wiring and the worker's start and stop); cmd/netfulfil/demand_inventory_live_integration_test.go (integration tag: the real entry point against a real Postgres and Kafka and the fake Vendor API, which judges a feed as the network does: one run declares the profile and feeds the offers of a pass, an unchanged feed is not re-sent while the hour has not passed, not even after a restart, a changed one is sent at once, and a listing the network refuses as not on the node is left out of the next feeds, also after a restart); and the chart's render_test.sh and test_env_parity.py.
  • internal/adapters/outbound/kafka/wire_golden_test.go: the CloudEvents wire shape of every event against testdata/wire/{events,analytics}/*.json.
  • internal/adapters/outbound/events/testdata/log_publisher.golden: the log publisher's output.
  • internal/adapters/inbound/http/otel_metrics_test.go: the otelhttp instruments the REST handler emits.
  • cmd/netfulfil/retry_test.go, wiring_test.go: the boot retry, the mandatory DATABASE_URL/KAFKA_BROKERS boot errors, and the MIGRATIONS_DATABASE_URL split.
  • cmd/netfulfil/outbox_relay_config_test.go: OUTBOX_MAX_ATTEMPTS parsing (TestOutboxMaxAttempts, TestDefaultOutboxMaxAttemptsIsTwenty) and that the relay the composition root builds carries it (TestWireEventPublisher_OutboxRelayIsCapped).
  • internal/adapters/outbound/postgres/outbox_trace_headers_test.go: the trace-header injection (TestTraceHeaders_NoSpanAddsNothing, TestTraceHeaders_SpanInjectsTraceparent) and the merge in which an encoder-set header wins (TestWithTraceHeaders_EncoderKeyWinsAndInputUntouched).
  • cmd/*/log_level_test.go (all four binaries): LOG_LEVEL=warning means warn (TestNewLoggerAcceptsWarning, TestNewLoggerLevels).

Coverage gate: make coverage (and the CI test job) measure coverage of ./internal/domain/... and ./internal/application/... only, and fail below 90 %.

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, so the local and the PR gate cannot drift; harness repo_lint rule R11 (coverage-scope) forbids a workflow passing -coverpkg itself. Change the scope or the threshold in the Makefile only.

BDD acceptance suite (ADR 0018)​

features_test.go (TestFeatures) runs every features/*.feature with godog in strict mode against the real routers: the OLTP Server.Routes() and the reports chi router, wired over the in-memory adapters. Orders are created the way production creates them: by seeding the real StubGateway and running the real poller.

Feature fileScenarios (blocks)
acknowledgement_lifecycle.feature9
acknowledgement_report.feature15
capability_offers.feature14
inbound_receipt_return.feature4
inbound_shipment_intake.feature4
inbound_status.feature6
integration_events.feature5
network_order_intake.feature10
network_order_queries.feature7
operations.feature6
orphaned_holds.feature7 (ADR 0024: cancel after the window and grace, a 404 is done, a 409 is not an orphan and not retried, a failing cancel is retried and never marked done, SUBMITTED is never swept, RejectOverdueOrders frees a recorded hold first)
request_hardening.feature3
shipment_confirmation.feature6

Seven further files, named *_rules.feature, pin rules the documentation states (business context, use cases, aggregate canvas, troubleshooting and the ADRs they cite), one rule per scenario title, with concrete values; their step code is steps_rules_test.go, steps_shipment_test.go and steps_supply_test.go:

Feature fileScenarios (blocks)Rules
capability_offer_rules.feature10the walk to the next feasible cutoff stops at exactly 7 days; a full cutoff is skipped for the next one with room (ADR 0033); capacity matched on the exact cutoff instant; zero cycle time stays eligible; an over-committed path never gives a negative offer; one SKU advertised once
hold_policy_rules.feature18the deadline sweep, RejectOverdueOrders and SweepOrphanedHolds act only once their window has strictly closed; a failed cancel leaves the order NEW and is retried; 409/422 is ALREADY_RELEASED, an unclassified answer is retried; the hold id is shown only for an order we committed to
inventory_feed_rules.feature13ADR 0027 part 2: complete feed sorted by SKU, stale offers and unlisted SKUs left out, split at 5000 lines, site skips, fingerprint
node_profile_rules.feature17ADR 0027 part 1 and ADR 0017: what is declared and when, handling time rounded up, longest gap of the week, merged cutoffs, ceilings never lowered
order_intake_rules.feature7resume only while the window is open, untranslatable demand recorded lineless, a refused order whose cancel failed is retried, one malformed unit never stops the poll
reconciliation_rules.feature10pending submission settled later and released once, the documented residual hold of ADR 0024, one failure never stops the pass, only SUBMITTED orders looked at, event payloads
shipment_event_rules.feature21ShipmentConfirmed by event: package count, redelivery, deferral until acknowledged, operator route and event never confirm twice, contract breaks

A scenario tagged @known-bug states the correct behaviour for a defect the suite found and is excluded until it is fixed. None is tagged today: the order that failed during an order-management outage is now answered on a later pass, and an empty networkRef on the shipment confirmation is a 422. The test-only variable BDD_TAGS overrides the default filter ~@known-bug (BDD_TAGS=@known-bug go test . -run TestFeatures -v would run only tagged scenarios, and there are none).

Output of go test . -run TestFeatures -count=1 -v on this branch:

279 scenarios (279 passed)
2292 steps (2292 passed)
--- PASS: TestFeatures (11.12s)

Integration tests​

make integration runs go test -tags=integration ./... -race -count=1 -timeout 15m: the live tests of cmd/netfulfil boot the whole service, and that package alone takes about ten minutes, which is go test's default ceiling. Every test starts its own Postgres or Kafka with testcontainers (testcontainers-go v0.44.0, modules postgres and kafka); there is no DATABASE_URL service container and no skip gate. Two fitness tests enforce that (TestPostgresIntegrationTestsUseTestcontainers, TestKafkaIntegrationTestsUseTestcontainers).

FileCovers
internal/adapters/outbound/postgres/integration_test.goshared fixtures, migrations against a real Postgres
.../postgres/network_order_repo_integration_test.gothe order repository
.../postgres/hold_integration_test.gothe hold (ADR 0024): TestNetworkOrderRepo_SavesEveryStateTheAggregateCanReach (a REJECTED order that keeps its id is saved, which the dropped CHECK used to refuse), TestNetworkOrderRepo_HoldOutcomeRoundTrips, TestNetworkOrderRepo_SettlingAnOpenHoldIsPersisted, TestNetworkOrderRepo_ListOpenHoldsReturnsOnlyOpenHoldsOfDecidedOrOverdueCandidates
.../postgres/pending_shipment_integration_test.gothe pending shipment (ADR 0014 addendum D7, migration 0015): TestNetworkOrderRepo_PendingShipmentRoundTripsAndIsHeldByTheSchema (the three columns round-trip and are cleared by the confirmation, a stale writer still gets ErrVersionConflict, the CHECKs refuse a half-written shipment), TestNetworkOrderRepo_ListPendingShipments (order, limit)
.../postgres/migration_0005_integration_test.goTestMigration0005_UpDownUp: migration 0005 up, down (clears the ids the restored CHECK would refuse, SUBMITTED data survives) and up again, on a bare Postgres
.../postgres/capability_offer_repo_integration_test.gothe offer repository
.../postgres/outbox_integration_test.gooutbox write and relay
.../postgres/outbox_trace_integration_test.gotrace context across the outbox (ADR 0022), real Postgres and Kafka: TestOutboxTrace_TraceparentCrossesTheOutboxToKafka (rows written in a span store its traceparent; a relay pass on a background context sends it to both topics; it extracts to the producing span) and TestOutboxTrace_RowWithoutTraceHeadersRelaysUnchanged
.../postgres/outbox_relay_cap_integration_test.gorelay attempt cap (ADR 0021): TestOutboxRelay_MaxAttempts_PoisonRowExcludedThenGoodRowPublishes (a poison row, then a good row with the same key, which publishes once the poison row hits the cap and is logged at ERROR), TestOutboxRelay_MaxAttempts_ReArmedRowIsClaimedAgain (the runbook's re-arm SQL), TestOutboxRelay_NoCap_PoisonRowBlocksLaterRows (0 = unlimited)
.../postgres/pool_limits_integration_test.goMaxConns and statement_timeout really applied
.../postgres/rehydrate_validation_integration_test.gocorrupt stored state is refused on load
internal/adapters/outbound/analyticsstore/postgres_integration_test.goprojection and report store
.../analyticsstore/unit_of_work_integration_test.goanalytics UnitOfWork (ADR 0023): TestUnitOfWork_ClaimAndProjectionRollBackTogether (the consumer claim, the projection claim and the rollup row roll back together), TestUnitOfWork_CommitsClaimAndProjectionAndJoinsNestedScope
internal/adapters/inbound/kafka/analytics_atomic_claim_integration_test.goclaim and apply in one transaction (ADR 0023), real Kafka and Postgres: TestAnalyticsConsumer_CrashBetweenClaimAndApply_RedeliveryAppliesExactlyOnce (the projector stops after the claim and before the apply commits: no claim is left, and the redelivery in the same group applies the event exactly once)
internal/adapters/outbound/kafka/publisher_integration_test.goboth publishers against a real broker
internal/adapters/inbound/kafka/analytics_projector_integration_test.goconsumer to projection, end to end
internal/adapters/inbound/kafka/analytics_dlq_integration_test.goretry and dead-letter path
internal/adapters/inbound/http/rest_api_integration_test.gothe real REST handler chain over Postgres, the outbox and a real poller: poll, persist, read back, and the shipment-confirmation 204 / 409 / 404 paths
internal/adapters/inbound/mcp/streamable_http_integration_test.gothe MCP wire contract over Streamable HTTP with the SDK client and Postgres: initialize, tools/list (every tool readOnlyHint: true), tools/call, resources/read
internal/application/usecases/usecases_wiring_integration_test.gothe write use cases over Postgres, the unit of work and the outbox fan-out, with the real order-management HTTP planner against a stub

The make help text still says integration "needs a running Postgres"; the Makefile comment and the tests themselves only need Docker.

Architecture fitness tests​

make arch-test runs go test ./internal/architecture/... -v:

TestGuards
TestHexagonalArchitecturearch-go rules: domain depends on nothing, application on domain, adapters on both
TestMCPAdapterDependencyRulethe MCP adapter depends only on application and domain, and nothing but cmd/mcp imports it
TestMCPOptionalToolInputsCarryOmitempty, TestMCPOptionalToolInputsSensorFailsOnBadFixturesan MCP tool input field whose jsonschema description says "optional" carries omitempty, or the SDK marks it required (gap fix D16)
TestOutboxRelaysPassAttemptCap, TestOutboxRelayCapSensorFailsOnBadFixturesevery non-test NewOutboxRelay call under cmd/ passes WithMaxAttempts (gap fix D12, ADR 0021)
TestKafkaWritersSetRequiredAcks, TestKafkaWriterAcksSensorBites (kafka_writer_acks_fitness_test.go)every kafka-go Writer literal in a non-test file under internal/ or cmd/ sets RequiredAcks (the DLQ writer and both event publishers use kafkago.RequireAll, synchronous): kafka-go defaults to RequireNone (acks=0), which silently drops a write on a broker blip while WriteMessages returns nil (fleet rollout 2026-10-13)
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.)
TestMCPAdapterStaysReadOnly, TestMCPReadOnlySensorFailsOnBadFixturesthe MCP adapter calls no state-changing method (Save, Publish, Execute, Exec, Insert, Update, Upsert, Delete) and sets no ReadOnlyHint: false, so the "Read-only access" server instructions stay true (gap fix D17)
TestNoAuthMiddlewareReintroducedno auth middleware on REST or MCP (fleet rule)
TestKafkaConsumerGroupNeverHardcodedInlineno reader's GroupID is an inline string literal; it must come from a named constant, variable or function
TestKafkaIntegrationTestsUseTestcontainers, TestPostgresIntegrationTestsUseTestcontainers, TestPostgresIntegrationSensorFailsOnBadFixturesintegration tests start real containers
TestDomainHasNoSerialisationTags, TestDomainTagSensorFailsOnBadFixturesno JSON tags in internal/domain (wire shape lives in eventwire)
TestCloudEventsOnlyevery producer and consumer goes through internal/adapters/kafka/cloudevents
TestReplayConsumersSetCommitIntervalFirstOffset replay readers set a CommitInterval
TestEventCatalogueMatchesContract, TestEventCatalogueDetectorevery CloudEvents type this service declares for itself in apis/asyncapi.yaml also appears in an ADR under docs/adr/ (the type catalogue); the detector test checks the checker
violation_test.gonot a test: the shared archViolation helper that turns a failed rule into a what/why/fix message (managed by the harness template)

Mutation testing​

make mutation runs gremlins unleash ./internal/domain/networkorder with .gremlins.yaml: one worker, timeout-coefficient 30, thresholds efficacy: 99 and mutant-coverage: 92. gremlins fails when the measured value is at or below a threshold. The file records the measurement the thresholds came from: 14 killed, 0 lived, 1 not covered (the AcknowledgementWindow constant), so 100 % efficacy and 93.33 % mutant coverage. That measurement predates internal/domain/capabilityoffer; re-measure before widening the fast subset. make mutation-full runs the whole ./internal/domain tree; no CI job runs it.

Make targets​

TargetRuns
make check-fastfmt-check, vet, arch-test, then go test on the packages changed vs HEAD
make checkfmt-check, vet, build, lint (golangci-lint v2.14.0), test
make check-allcheck plus coverage (90 % gate), arch-test, bdd
make test / bdd / integration / arch-testthe layers above
make coveragerace tests with -coverpkg on domain and application, then the gate
make mutation / mutation-fullgremlins, fast subset / whole domain
make vulngovulncheck ./...
make lintgolangci-lint run ./...
make guide-lint / harness-testscripts/harness/guide_lint.py / test_hook.py

Git hooks (lefthook.yml, after lefthook install): pre-commit runs fmt-check, vet, lint; pre-push runs make check.

CI​

.github/workflows/ci.yml runs on push to main and develop, on pull requests into them, weekly (cron: 0 6 * * 1) and on manual dispatch.

JobRunsWhen
lintgolangci-lint v2.14.0every run
guide-lintguide_lint.py, repo_lint.py, test_hook.py, test_repo_lint.pyevery run
complexitygolangci-lint with only gocyclo, gocognit, cyclop, funlen, nestif, plus an informational gocyclo >10 reportevery run
testgo build, go vet, then make coverage (race unit tests with the Makefile's coverage scope and 90 % gate), uploads coverage.out (generated by make coverage, gitignored, never tracked)every run
bddgo test ./... -run TestFeatures -vevery run
integrationbuild and vet with -tags=integration, then the integration suiteevery run
api-lintSpectral on apis/openapi.yaml (--fail-severity=warn)every run
mutation-fastgremlins unleash ./internal/domain/networkorderevery run
vulngovulncheck ./...every run
helm-linthelm lint charts/network-fulfillment and the two chart wiring scriptsevery run
arch-testgo test ./internal/architecture/... -vevery run
trivy-scanbuilds the image, fails on fixable CRITICAL/HIGHPRs into main only
docker-publishpush, cosign sign, SBOM attest (needs lint, complexity, test, bdd)push to main
releasesemver tag, chart push, GitHub Release (needs docker-publish)push to main

A separate .github/workflows/ai-review.yml exists alongside ci.yml.

Not present, compared with the harness template: a scheduled exhaustive mutation job (the weekly cron re-runs the jobs above instead; .gremlins.yaml still mentions it), drift, docs-api-drift (there is no docs site) and a web job.

develop requires lint, test, mutation-fast, vuln, arch-test, helm-lint, integration and api-lint (strict). See the runbook.