MEMO-093: 4-Week Test Coverage Improvement Plan
Executive Summary
Comprehensive plan to increase test coverage across the Prism codebase from current baseline to target levels over 4 weeks. Focus on Core SDK (85%), Drivers (80-85%), and Patterns (80-85%).
Current Coverage Baseline (2025-11-18)
Core SDK Packages
- ✅ pkg/config: 90.3% (exceeds target)
- ❌ pkg/plugin: 3.6% (needs 85%) - 78 untested functions
- ❌ pkg/authz: 35.4% (needs 85%)
Driver Packages
- ✅ pkg/drivers/memstore: 98.9% (excellent)
- ⚠️ pkg/drivers/nats: 67.0% (needs 85%)
- ❌ pkg/drivers/redis: 30.7% (needs 85%)
- ❌ pkg/drivers/sqlite: 0.0% (needs 85%)
Coverage Targets (from CLAUDE.md)
- Core SDK: 85%
- Plugins/Drivers: 80-85%
- Utilities: 90%
4-Week Implementation Plan
Week 1: Core SDK - Critical Gaps
Day 1-2: pkg/plugin (3.6% → 85%)
Priority: CRITICAL - Core SDK with only 3.6% coverage
Untested Components (78 functions total):
- config_parser.go
- config.go
- backend.go
- dataplane.go
- controlplane.go
- observability.go
- serve.go
- pattern_control_plane_client.go
- proxy_control_plane_server.go (most functions 0%)
Test Files to Create:
pkg/plugin/
├── config_parser_test.go (NEW)
├── config_test.go (NEW)
├── backend_test.go (NEW)
├── dataplane_test.go (NEW)
├── controlplane_test.go (NEW)
├── observability_test.go (NEW)
├── serve_test.go (NEW)
├── pattern_control_plane_client_test.go (NEW)
└── proxy_control_plane_server_test.go (NEW)
Test Coverage Strategy:
- Unit tests for all exported functions
- Integration tests for gRPC server lifecycle
- Mock backends for testing control plane interactions
- Table-driven tests for configuration parsing
Estimated Effort: 16 hours (2 days)
Day 3-4: pkg/authz (35.4% → 85%)
Priority: HIGH - Core SDK authentication/authorization
Components Needing Tests:
- Token validation edge cases
- Vault client error handling
- Session management lifecycle
- Credential renewal/revocation paths
- Service identity validation
Gaps to Address:
- Error paths in VaultClient
- SessionManager edge cases
- TokenValidator failure modes
- RenewalManager concurrent sessions
- RevocationManager batch operations
Test Files to Enhance:
pkg/authz/
├── vault_client_test.go (ENHANCE - add error paths)
├── session_manager_test.go (NEW)
├── token_validator_test.go (ENHANCE - edge cases)
├── renewal_manager_test.go (ENHANCE - concurrency)
├── revocation_manager_test.go (ENHANCE - batch ops)
└── types_test.go (NEW - struct validation)
Estimated Effort: 16 hours (2 days)
Day 5: pkg/drivers/nats (67% → 85%)
Priority: MEDIUM - Close to target, needs 18% increase
Components Needing Tests:
- Connection error handling
- Reconnection logic
- Message serialization edge cases
- Concurrent publish/subscribe
- Stream context management
Test Files to Enhance:
pkg/drivers/nats/
├── nats_test.go (ENHANCE - add error paths)
├── connection_test.go (NEW - reconnection logic)
└── integration_test.go (ENHANCE - edge cases)
Estimated Effort: 8 hours (1 day)
Week 1 Deliverable: Core SDK packages at 85%+ coverage
Week 2: Driver Packages
Day 1-2: pkg/drivers/sqlite (0% → 85%)
Priority: CRITICAL - No test coverage at all
Components to Test:
- Database initialization
- Connection management
- Query execution (CRUD operations)
- Transaction handling
- Error conditions
- Schema migrations (if any)
- Concurrent access
Test Files to Create:
pkg/drivers/sqlite/
├── sqlite_test.go (NEW - core functionality)
├── connection_test.go (NEW - connection lifecycle)
├── transaction_test.go (NEW - transaction handling)
├── error_handling_test.go (NEW - error paths)
└── integration_test.go (NEW - E2E scenarios)
Test Strategy:
- Use in-memory SQLite (:memory:) for fast tests
- Test file-based SQLite for persistence scenarios
- Concurrent access tests with goroutines
- Error injection tests
Estimated Effort: 16 hours (2 days)
Day 3-5: pkg/drivers/redis (30.7% → 85%)
Priority: HIGH - Significant gap to close (54.3%)
Components Needing Tests:
- Connection pooling
- Pipeline operations
- Pub/Sub functionality
- Error handling and retries
- Key expiration
- Cluster mode (if supported)
- Transactions (MULTI/EXEC)
Test Files to Create/Enhance:
pkg/drivers/redis/
├── redis_test.go (ENHANCE - comprehensive CRUD)
├── connection_pool_test.go (NEW)
├── pipeline_test.go (NEW)
├── pubsub_test.go (NEW)
├── transaction_test.go (NEW)
├── error_handling_test.go (NEW)
└── integration_test.go (ENHANCE - testcontainers)
Test Strategy:
- Use testcontainers for real Redis instance
- Unit tests with mock Redis client
- Concurrent operation tests
- Network failure simulation
Estimated Effort: 24 hours (3 days)
Week 2 Deliverable: All driver packages at 80-85%+ coverage
Week 3: Pattern Packages
Baseline Assessment Needed
First, measure current coverage for pattern packages:
cd patterns/keyvalue && go test -cover ./...
cd patterns/consumer && go test -cover ./...
cd patterns/producer && go test -cover ./...
cd patterns/mailbox && go test -cover ./...
Expected Work
KeyValue Pattern:
- Pattern initialization
- Slot binding (memstore, redis, sqlite)
- Request routing
- Error handling
- Session integration
Consumer Pattern:
- Message consumption lifecycle
- Offset management
- Consumer group coordination
- Error handling and retries
- Backpressure handling
Producer Pattern:
- Message production
- Batching logic
- Acknowledgment handling
- Error handling and retries
Mailbox Pattern:
- FIFO queue operations
- Message routing
- State management
- Concurrent access
Test Files (per pattern):
patterns/<pattern>/
├── <pattern>_test.go (ENHANCE - core logic)
├── slot_binding_test.go (NEW - backend integration)
├── error_handling_test.go (NEW - error paths)
└── integration_test.go (NEW - E2E with runners)
Estimated Effort: 40 hours (5 days)
Week 3 Deliverable: All pattern packages at 80-85%+ coverage
Week 4: Integration Tests & Edge Cases
Integration Test Suite Enhancement
tests/testing/ improvements:
- Expand
vault_integration_test.go(currently 8 tests passing) - Expand
auth_integration_test.go(Dex configuration complete) - Create
composable_patterns_integration_test.go - Add end-to-end workflow tests
New Integration Test Files:
tests/testing/
├── multi_backend_integration_test.go (NEW)
├── failover_integration_test.go (NEW)
├── performance_integration_test.go (NEW)
└── security_integration_test.go (NEW)
Edge Case Testing
Focus Areas:
- Concurrency: Race conditions, deadlocks
- Error Recovery: Transient failures, network partitions
- Resource Limits: Memory pressure, connection exhaustion
- Security: Invalid tokens, permission escalation
- Performance: High throughput, large payloads
Test Strategy:
- Use
go test -racefor race detection - Chaos engineering tests (network failures, slow responses)
- Load tests with
testing.Bbenchmarks - Fuzzing for input validation
Estimated Effort: 40 hours (5 days)
Week 4 Deliverable: Comprehensive test suite with 85%+ coverage across all Core SDK and drivers
Testing Best Practices
Table-Driven Tests
func TestConfigParser(t *testing.T) {
tests := []struct {
name string
input string
want *Config
wantErr bool
}{
{
name: "valid config",
input: `{"backend": "redis"}`,
want: &Config{Backend: "redis"},
},
{
name: "invalid json",
input: `{invalid}`,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ParseConfig(tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("ParseConfig() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr && !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseConfig() = %v, want %v", got, tt.want)
}
})
}
}
Mock Interfaces
type MockVaultClient struct {
mock.Mock
}
func (m *MockVaultClient) AuthenticateWithJWT(ctx context.Context, token string) (string, time.Duration, error) {
args := m.Called(ctx, token)
return args.String(0), args.Get(1).(time.Duration), args.Error(2)
}
func TestSessionManagerWithMockVault(t *testing.T) {
mockVault := new(MockVaultClient)
mockVault.On("AuthenticateWithJWT", mock.Anything, "valid-token").
Return("vault-token-123", 1*time.Hour, nil)
sm := NewSessionManager(mockVault)
// ... test logic
}
Testcontainers for Integration Tests
func TestRedisIntegration(t *testing.T) {
ctx := context.Background()
redisContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "redis:7-alpine",
ExposedPorts: []string{"6379/tcp"},
},
Started: true,
})
require.NoError(t, err)
defer redisContainer.Terminate(ctx)
// Get mapped port
port, err := redisContainer.MappedPort(ctx, "6379")
require.NoError(t, err)
// Create client
client := redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("localhost:%s", port.Port()),
})
// Run tests...
}
Error Path Testing
func TestErrorPaths(t *testing.T) {
tests := []struct {
name string
setupError error
expectedError string
}{
{
name: "connection timeout",
setupError: context.DeadlineExceeded,
expectedError: "connection timeout",
},
{
name: "authentication failed",
setupError: ErrInvalidCredentials,
expectedError: "authentication failed",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Inject error
// Verify error handling
// Verify cleanup
})
}
}
Coverage Verification
Generate Coverage Reports
# Per-package coverage
cd pkg/plugin && go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
# Aggregate coverage
go test -coverprofile=coverage.out ./pkg/...
go tool cover -func=coverage.out | grep total
Coverage Gates
Add to CI/CD pipeline:
- name: Verify Coverage
run: |
COVERAGE=$(go test -coverprofile=coverage.out ./pkg/... | grep total | awk '{print $3}')
THRESHOLD=85
if [ ${COVERAGE%\%} -lt $THRESHOLD ]; then
echo "Coverage $COVERAGE is below threshold $THRESHOLD%"
exit 1
fi
Progress Tracking
Daily Checklist
- Identify untested functions
- Write tests for high-priority functions
- Run
go test -coverto verify improvement - Run
go test -raceto check for race conditions - Generate coverage report
- Commit tests with descriptive messages
Weekly Goals
- Week 1: Core SDK at 85%+ (pkg/plugin, pkg/authz, pkg/drivers/nats)
- Week 2: All drivers at 80-85%+ (sqlite, redis)
- Week 3: All patterns at 80-85%+
- Week 4: Integration tests complete, all targets met
Success Criteria
- Core SDK packages (pkg/plugin, pkg/authz, pkg/config): ≥85% coverage
- Driver packages (memstore, redis, nats, sqlite): ≥80% coverage
- Pattern packages (keyvalue, consumer, producer, mailbox): ≥80% coverage
- Integration tests: Comprehensive E2E scenarios
- No race conditions: All tests pass with
-raceflag - CI/CD integration: Coverage gates enforced
Related Documents
- TDD Best Practices (see /tdd-guide command)
- CLAUDE.md Coverage Requirements (see TDD section)
- MEMO-041: Auth Integration Testing
Revision History
- 2025-11-18: Initial 4-week test coverage improvement plan