Skip to main content
neutral

Phase 16 — Test Coverage Expansion to 80%+

Systematically expands test coverage across all 22 internal packages to ≥80%, using mock clients (sqlmock, httptest, Temporal testsuite) so no live services are required. All new test code passes SonarQube quality gates — no code smells, no cognitive complexity issues, meaningful assertions.

Status: Completed (2026-02-09) Depends on: Phases 1-14 complete Migrations: None (tests only — no schema changes) Branch: dev


Sub-Phases

Sub-PhaseNamePackagesPromptsDepends On
16AFoundation & Small Packagesblackboard, observability, temporal, mcp, config, health, agenttest3
16BQuota, Registry & LLMquota, registry, llm316A
16CMemory & Embeddingmemory, embedding, vectorstore316A
16DAudit, Security & Tenantaudit, security, tenant316A
16EAgent Part 1: Activities & Helpersagent (activities, helpers, stores)416B
16FAgent Part 2: Workflow & Signalsagent (workflow, queries, signals)216E
16GSupervisor & Graphsupervisor, graph316F
16HToolstools316B, 16C
16IAPI Coverage Expansionapi, api/middleware, api/routes316B–16H
16JCoverage Verification & CIall216A–16I

Total: 10 sub-phases, 29 prompts, 21 documentation files

Dependency Graph

16A (Foundation) ──┬──→ 16B (Quota/Registry/LLM) ──→ 16E (Agent Pt1) ──→ 16F (Agent Pt2) ──→ 16G (Super/Graph)
├──→ 16C (Memory/Embedding) ────→ 16H (Tools) ←── 16B
├──→ 16D (Audit/Security/Tenant)

│ 16B-16H ────────────────────→ 16I (API)
└─────────────────────────────────→ 16J (Verification)

Parallelizable: 16B, 16C, 16D can all run simultaneously after 16A completes. 16H runs after both 16B and 16C.

Coverage Gap Analysis

PackageCurrentTargetGapPriority Files
blackboard0%80%80%postgres_store.go, store.go
observability0%80%80%logger.go
temporal0%80%80%client.go
supervisor17.6%80%62%workflow.go, activities.go, capability.go, delegation_chain.go
registry21.1%80%59%store.go
api/routes29.2%80%51%18 route files (edge cases, error paths)
health30.1%80%50%checker.go edge cases
quota31.1%80%49%policy.go, limiter.go, middleware.go
llm33.7%80%46%client.go, openrouter.go, azure.go, model_store.go
memory34.7%80%45%policy.go, postgres_store.go, redis_store.go, embedding.go
audit36.1%80%44%logger.go, export_hipaa.go, export_soc2.go
agent40.3%80%40%workflow.go, activities.go, stores, helpers
mcp43.1%80%37%client.go
vectorstore43.6%80%36%composite.go, metrics.go
graph44.3%80%36%conditions.go, dsl.go, workflow.go
api/middleware49.8%80%30%auth.go, ratelimit.go edge cases
config50.3%80%30%edge cases in env parsing
tools56.8%80%23%8 individual tool files
agenttest58.2%80%22%playground.go, chaos edge cases
security59.5%80%21%sanitizer.go, sandbox edge cases
tenant60.4%80%20%middleware.go, config.go
embedding73.8%80%6%ollama.go, google.go

Testing Strategy

Mock Infrastructure

No live services required. All tests use mock clients:

DependencyMock Strategy
PostgreSQLDATA-DOG/go-sqlmock for store-level tests
Temporalgo.temporal.io/sdk/testsuite for workflow/activity tests
HTTP APIs (LLM, MCP, Qdrant)net/http/httptest for provider client tests
Redis / Dragonflyalicebob/miniredis or interface mocks
Huma API routesdanielgtaylor/huma/v2/humatest for route-level tests
Vector storesInterface mocks (function-field pattern from api/testutil/mocks.go)

Existing Test Infrastructure

PatternLocationUsed By
Temporal test harnessinternal/agenttest/suite.goAgent workflow tests (DeterministicJSON, StepDecider, MockTool)
Mock store patterninternal/api/testutil/mocks.goAPI route tests (MockTemporalClient, MockRegistryStore, etc.)
In-memory storeinternal/memory/inmemory_store.goMemory tests (already used as test double)
Test helper utilitiesinternal/api/routes/test_helpers_test.goAPI route test setup

Test Conventions

All new test code follows these conventions:

  • Naming: Test<Function>_<Scenario> (e.g., TestNewClient_TLSEnabled)
  • Table-driven: Use subtests with t.Run() to reduce duplication
  • Assertions: github.com/stretchr/testify — use meaningful messages (not bare assert.True)
  • Setup: Extract shared setup into helper functions; no duplicate setup blocks
  • Cognitive complexity: Keep test functions ≤ 15 per SonarQube threshold
  • Build tags: Integration tests use //go:build integration tag
  • No secrets: No hardcoded credentials — use placeholder values

File Structure

No new production files — only test files and CI configuration:

internal/
blackboard/
postgres_store_test.go # 16A
observability/
logger_test.go # 16A
temporal/
client_test.go # 16A
mcp/
client_test.go # 16A
config/
config_test.go # 16A (extend existing)
health/
checker_test.go # 16A (extend existing)
agenttest/
suite_test.go # 16A (extend existing)
playground_test.go # 16A (extend existing)
quota/
policy_test.go # 16B
limiter_test.go # 16B
middleware_test.go # 16B
registry/
store_test.go # 16B
llm/
client_test.go # 16B
openrouter_test.go # 16B
azure_test.go # 16B
model_store_test.go # 16B
memory/
postgres_store_test.go # 16C
redis_store_test.go # 16C
policy_test.go # 16C
embedding_test.go # 16C
embedding/
ollama_test.go # 16C
google_test.go # 16C
vectorstore/
composite_test.go # 16C (extend existing)
metrics_test.go # 16C
audit/
logger_test.go # 16D
export_hipaa_test.go # 16D
export_soc2_test.go # 16D
security/
sanitizer_test.go # 16D
sandbox_test.go # 16D (extend existing)
tenant/
middleware_test.go # 16D
config_test.go # 16D
agent/
activities_test.go # 16E
cost_test.go # 16E
state_test.go # 16E
hash_test.go # 16E
trace_test.go # 16E
retry_store_test.go # 16E
version_store_test.go # 16E
trace_store_test.go # 16E
logging_test.go # 16E
speculative_test.go # 16E
agent/
workflow_test.go # 16F
queries_test.go # 16F
signals_test.go # 16F
supervisor/
workflow_test.go # 16G
activities_test.go # 16G
capability_test.go # 16G
delegation_chain_test.go # 16G
graph/
conditions_test.go # 16G
dsl_test.go # 16G
workflow_test.go # 16G (extend existing)
tools/
http_get_test.go # 16H
kv_store_test.go # 16H
cost_summary_test.go # 16H
model_list_test.go # 16H
model_prefs_test.go # 16H
memory_read_test.go # 16H
memory_write_test.go # 16H
simulated_test.go # 16H
api/
middleware/
middleware_test.go # 16I (extend existing)
routes/
*_test.go # 16I (extend existing — 18 files)
.github/workflows/
coverage.yml # 16J (CI enforcement)

SonarQube Quality Requirements

All new test code must satisfy:

RuleRequirement
Cognitive complexity≤ 15 per function
Assertion qualityMeaningful messages on all assertions
DuplicationExtract shared setup into helpers; no copy-paste blocks
CredentialsNo hardcoded secrets — use placeholder values
Error handlingNo ignored errors; check all err returns
Test namingTest<Function>_<Scenario> convention
Table-drivenUse t.Run() subtests where ≥ 3 similar cases exist

Prompt Files

Each sub-phase has a companion -PROMPT.md file containing implementation prompts designed for LLM-assisted coding. Prompts are ordered by dependency within each sub-phase. Load the listed context files before executing each prompt.

  • PHASE16A-PROMPT.md — 3 prompts (blackboard/observability/temporal → mcp/config/health → agenttest)
  • PHASE16B-PROMPT.md — 3 prompts (quota → registry/llm providers → llm model store/failover)
  • PHASE16C-PROMPT.md — 3 prompts (memory stores → embedding providers → vectorstore)
  • PHASE16D-PROMPT.md — 3 prompts (audit → security → tenant)
  • PHASE16E-PROMPT.md — 4 prompts (activities → helpers/state → stores → cost/logging)
  • PHASE16F-PROMPT.md — 2 prompts (workflow → queries/signals)
  • PHASE16G-PROMPT.md — 3 prompts (supervisor workflow/activities → supervisor capability/delegation → graph)
  • PHASE16H-PROMPT.md — 3 prompts (execution tools → data tools → bridge/simulated tools)
  • PHASE16I-PROMPT.md — 3 prompts (middleware edge cases → route error paths → integration test gaps)
  • PHASE16J-PROMPT.md — 2 prompts (coverage verification script → CI pipeline enforcement)

Verification

After all sub-phases are complete:

  1. go test -coverprofile=coverage.out ./internal/... — all packages ≥ 80%
  2. go test -count=1 ./... — all tests pass, no regressions
  3. go tool cover -func=coverage.out | grep total — verify aggregate ≥ 80%
  4. No tests require live external services (Postgres, Temporal, Redis, LLM APIs)
  5. SonarQube scan passes with no new issues
  6. CI pipeline enforces per-package coverage thresholds
  7. go test -race ./internal/... — no data races detected