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-Phase | Name | Packages | Prompts | Depends On |
|---|---|---|---|---|
| 16A | Foundation & Small Packages | blackboard, observability, temporal, mcp, config, health, agenttest | 3 | — |
| 16B | Quota, Registry & LLM | quota, registry, llm | 3 | 16A |
| 16C | Memory & Embedding | memory, embedding, vectorstore | 3 | 16A |
| 16D | Audit, Security & Tenant | audit, security, tenant | 3 | 16A |
| 16E | Agent Part 1: Activities & Helpers | agent (activities, helpers, stores) | 4 | 16B |
| 16F | Agent Part 2: Workflow & Signals | agent (workflow, queries, signals) | 2 | 16E |
| 16G | Supervisor & Graph | supervisor, graph | 3 | 16F |
| 16H | Tools | tools | 3 | 16B, 16C |
| 16I | API Coverage Expansion | api, api/middleware, api/routes | 3 | 16B–16H |
| 16J | Coverage Verification & CI | all | 2 | 16A–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
| Package | Current | Target | Gap | Priority Files |
|---|---|---|---|---|
| blackboard | 0% | 80% | 80% | postgres_store.go, store.go |
| observability | 0% | 80% | 80% | logger.go |
| temporal | 0% | 80% | 80% | client.go |
| supervisor | 17.6% | 80% | 62% | workflow.go, activities.go, capability.go, delegation_chain.go |
| registry | 21.1% | 80% | 59% | store.go |
| api/routes | 29.2% | 80% | 51% | 18 route files (edge cases, error paths) |
| health | 30.1% | 80% | 50% | checker.go edge cases |
| quota | 31.1% | 80% | 49% | policy.go, limiter.go, middleware.go |
| llm | 33.7% | 80% | 46% | client.go, openrouter.go, azure.go, model_store.go |
| memory | 34.7% | 80% | 45% | policy.go, postgres_store.go, redis_store.go, embedding.go |
| audit | 36.1% | 80% | 44% | logger.go, export_hipaa.go, export_soc2.go |
| agent | 40.3% | 80% | 40% | workflow.go, activities.go, stores, helpers |
| mcp | 43.1% | 80% | 37% | client.go |
| vectorstore | 43.6% | 80% | 36% | composite.go, metrics.go |
| graph | 44.3% | 80% | 36% | conditions.go, dsl.go, workflow.go |
| api/middleware | 49.8% | 80% | 30% | auth.go, ratelimit.go edge cases |
| config | 50.3% | 80% | 30% | edge cases in env parsing |
| tools | 56.8% | 80% | 23% | 8 individual tool files |
| agenttest | 58.2% | 80% | 22% | playground.go, chaos edge cases |
| security | 59.5% | 80% | 21% | sanitizer.go, sandbox edge cases |
| tenant | 60.4% | 80% | 20% | middleware.go, config.go |
| embedding | 73.8% | 80% | 6% | ollama.go, google.go |
Testing Strategy
Mock Infrastructure
No live services required. All tests use mock clients:
| Dependency | Mock Strategy |
|---|---|
| PostgreSQL | DATA-DOG/go-sqlmock for store-level tests |
| Temporal | go.temporal.io/sdk/testsuite for workflow/activity tests |
| HTTP APIs (LLM, MCP, Qdrant) | net/http/httptest for provider client tests |
| Redis / Dragonfly | alicebob/miniredis or interface mocks |
| Huma API routes | danielgtaylor/huma/v2/humatest for route-level tests |
| Vector stores | Interface mocks (function-field pattern from api/testutil/mocks.go) |
Existing Test Infrastructure
| Pattern | Location | Used By |
|---|---|---|
| Temporal test harness | internal/agenttest/suite.go | Agent workflow tests (DeterministicJSON, StepDecider, MockTool) |
| Mock store pattern | internal/api/testutil/mocks.go | API route tests (MockTemporalClient, MockRegistryStore, etc.) |
| In-memory store | internal/memory/inmemory_store.go | Memory tests (already used as test double) |
| Test helper utilities | internal/api/routes/test_helpers_test.go | API 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 bareassert.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 integrationtag - 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:
| Rule | Requirement |
|---|---|
| Cognitive complexity | ≤ 15 per function |
| Assertion quality | Meaningful messages on all assertions |
| Duplication | Extract shared setup into helpers; no copy-paste blocks |
| Credentials | No hardcoded secrets — use placeholder values |
| Error handling | No ignored errors; check all err returns |
| Test naming | Test<Function>_<Scenario> convention |
| Table-driven | Use 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:
go test -coverprofile=coverage.out ./internal/...— all packages ≥ 80%go test -count=1 ./...— all tests pass, no regressionsgo tool cover -func=coverage.out | grep total— verify aggregate ≥ 80%- No tests require live external services (Postgres, Temporal, Redis, LLM APIs)
- SonarQube scan passes with no new issues
- CI pipeline enforces per-package coverage thresholds
go test -race ./internal/...— no data races detected