Skip to main content

Testing

Source: Makefile, .github/workflows/ci.yml, .gremlins.yaml, features/, internal/architecture/, internal/**/*_test.go, contracts/. Counts below are func Test... declarations and Gherkin scenarios counted in the tree on develop, not coverage claims.

The pyramid as it is​

LayerWhereCountNeedsNotes
Domain unitinternal/domain/{outboundload,shippingpackage,billoflading,shared}70 test functionsnothingInvariants, transitions, rehydration validation, short-ship validity. Pure Go, no I/O.
Use-case unitinternal/application/usecases/*_test.go43nothingThe consumer policies and REST commands over the in-memory doubles (internal/adapters/outbound/memory): expect, scan, load commands, on-departure, edges, projector, queries.
Adapter unitinternal/adapters/kafka/cloudevents, internal/adapters/outbound/kafka8nothingCloudEvents build and decode, writer settings.
BDD (godog)features/ship_confirm_on_departure.feature, runner features/features_test.go (TestFeatures)1 feature file, 6 scenariosnothingDrives the same use cases cmd/api wires, over the in-memory doubles, with an outbox recorder standing in for the relay. Strict mode.
Contractinternal/adapters/inbound/kafka/producer_contract_test.go, contracts/2nothingSee below.
Integrationinternal/adapters/outbound/postgres/service_integration_test.go (//go:build integration)3 (one is TestMain)DockerReal Postgres through testcontainers (internal/testing/pgtest): TestExpectPackagePlansExactlyOneLoadUnderConcurrency (the one-open-load race backstop) and TestServicePathOverPostgres (a full path through the real adapters).
Fitness (architecture)internal/architecture/12 files, 37 test functionsnothingSee below.
Mutation.gremlins.yamln/agremlins v0.6.0See below.

There are no handler tests for the REST adapter (internal/adapters/inbound/http) and none for the MCP adapter (internal/adapters/inbound/mcp); both are covered only indirectly (architecture sensors, the BDD feature through the use cases). The Kafka consumers' decode paths are likewise exercised mostly through the use-case tests and the yard contract test. There is no end-to-end test of the Kafka consumers against a live broker in this repository (internal/testing/kafkatest exists as a helper; no test in the tree uses it).

The BDD scenarios​

All six are in features/ship_confirm_on_departure.feature: manifest, stage, load, close and depart with one bill of lading; a departure while LOADING that never confirms and flags what missed; a departure that arrives before the load closes (handled, never confirmed, and a re-delivery changes nothing); a departure delivered twice confirms once; a diverted package short-ships and the load still closes; the missed-load sweep flags once even when it runs twice.

Contract test: the yard-management pin​

contracts/yard-management.asyncapi.yaml is a copy of yard-management's apis/asyncapi.yaml on develop, listed in contracts/pinned.json. TestConsumedYardTypesMatchTheProducersIntegrationContract proves each consumed yard type (TrailerDocked, DoorWorkCompleted, TrailerDeparted) is declared on the producer's integration channel and that the producer's example decodes into the struct this service reads, with every field it acts on present; TestOnIntegrationChannelRejectsAnalyticsOnlyTypes proves the detector can fail. The CI job pinned-contracts (scripts/harness/pinned_contract_gate.py) fails when the pinned copy differs from the producer's develop (ADR 0006). The dock-scheduling contract is not pinned the same way: its payload is mirrored by hand in internal/adapters/inbound/kafka/dock_yard_consumers.go.

Fitness tests (internal/architecture)​

TestGuards
TestHexagonalArchitecturedependency direction between domain, application and adapters (arch-go).
TestMCPAdapterDependencyRulethe MCP adapter depends inward on the application layer only.
TestNoAuthMiddlewareReintroducedno auth middleware in the REST or MCP routers.
TestRuntimeBinaryHasNoInMemoryAdapters (+ TestRuntimeBinarySensorBites)cmd/ never imports the memory adapters.
TestNoGoFilesAtRepoRoot (+ two sensor tests)no .go file at the repository root.
TestKafkaConsumerGroupNeverHardcodedInlinegroup ids come from the environment.
TestKafkaWritersSetRequiredAcks, TestKafkaWriterTopicNotSetTwice (+ ...SensorBites)every writer sets RequiredAcks; no Topic on both Writer and Message.
TestDeadLetterCallsGuardCancellation (+ ...SensorBites)a dead-letter call checks for context cancellation first (shutdown is never a dead letter).
TestReplayConsumersSetCommitInterval, TestCloudEventsOnly, TestNoEventEnvelopeToggleOrFlatEnvelopeCloudEvents 1.0 only, no envelope toggle.
TestEventCatalogueMatchesContract (+ detector)every type apis/asyncapi.yaml declares for this service is listed in ADR 0005.
TestOutboxRelaysPassAttemptCap (+ two sensor tests)the relay is built with WithMaxAttempts.
TestMCPOptionalToolInputsCarryOmitempty (+ sensor test)optional MCP inputs are not published as required.
TestEveryMCPToolDeclaresAuthority, TestMCPWriteToolsAreAtLeastL3, TestA2ASkillsDeclareAuthority, TestMCPServerOffersResourceAndPrompt (+ five sensor tests)agent surface rules: every MCP tool declares an authority level, write tools are L3 or above, the server offers a resource and a prompt.
TestGovernance_ToolSetIsPinnedAndHasNoWriteVerb, TestGovernance_EveryToolIsReadOnlyIdempotentClosedWorldL1 (+ TestGovernance_WriteVerbDetectorBites), in internal/adapters/inbound/mcp/governance_test.go (a unit test of the adapter, not of internal/architecture)the real tools/list is exactly loads_at_risk and missed_loads, no tool name carries a write verb, and each tool is read-only, idempotent, closed-world, non-destructive and authority L1.
TestKafkaIntegrationTestsUseTestcontainers, TestPostgresIntegrationTestsUseTestcontainers (+ sensor test)integration tests boot their own containers and never read DATABASE_URL.

Mutation testing​

.gremlins.yaml sets one worker, a timeout coefficient of 30 and thresholds efficacy: 90 and mutant-coverage: 90. The fast gate (make mutation, CI mutation-fast) runs gremlins on each domain package in turn: shared, outboundload, shippingpackage, billoflading. The exhaustive run (make mutation-full, CI mutation) runs ./internal/domain and is scheduled weekly (Monday 06:00 UTC), opening a harness:red issue when it fails.

Coverage gate​

make coverage runs go test ./... -race with -coverpkg=./internal/domain/...,./internal/application/... and fails below 89 % (the Makefile notes 89.3 % measured). Adapters are outside that scope.

Make targets​

TargetDoesNeeds
make helplist targets
make build, make vet, make fmt, make fmt-checkbuild, vet, format, format check
make lintgolangci-lint run ./... (pinned v2.14.0)golangci-lint
make testgo test ./... -race (unit, godog, fitness; no integration)
make coveragetests plus the 89 % gate
make bddgo test ./... -run TestFeatures -v
make arch-testgo test ./internal/architecture/... -v
make integrationgo test -tags=integration ./... -race -count=1Docker
make mutation / make mutation-fullgremlins, fast per-package / exhaustivegremlins
make vulngovulncheck ./...govulncheck
make checkfmt-check vet build lint test: the pre-commit loop
make check-allcheck plus coverage arch-test bdd: run before pushing
make check-fast, make guide-lint, make harness-testagent harness: fast gate, guide lint, hook testspython3

make check is not enough to run the integration suite; integration is deliberately outside both check and check-all. lefthook runs fmt-check, vet and lint on commit and make check on push.

CI jobs (.github/workflows/ci.yml)​

Triggers: push and PR on main and develop, a weekly schedule (mutation), manual dispatch.

JobRuns
lintgolangci-lint
guide-lintthe harness guide lint and hook tests
pinned-contractspinned-contract gate tests; pins equal the producers' develop
complexitygocyclo report (gate 15)
file-lengthfile length of the Go files a PR touches (blocking), backlog (informational)
testbuild, vet, make coverage
bddgo test ./... -run TestFeatures -v
integrationgo test -tags=integration ./... -race -count=1
mutation-fastgremlins on every domain package
mutationexhaustive gremlins (schedule)
driftdead code, go mod tidy -diff, coverage-quality (schedule)
api-lintspectral over apis/openapi.yaml and apis/asyncapi.yaml
vulngovulncheck
chart-testscharts/outbound-shipping/tests/*.sh and test_*.py (render_test.sh, test_service_selectors.py; a test printing SKIP fails the job)
arch-testgo test ./internal/architecture/... -v
docker-publishimage build, push, signing, SBOM: only on a push to main, after the jobs above
releaseversion, tag, chart package, GitHub release: only after docker-publish

The documentation site is built by a separate workflow, .github/workflows/docs.yml (build on pull request, deploy on push to main).