mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-12 13:18:51 +00:00
fix(m2-pr-e): collapse AgentService.HeartbeatWithContext into Heartbeat
PR-E of 6 in the M-2 end-to-end remediation sequence. Collapses the
HeartbeatWithContext wrapper into a single ctx-first Heartbeat method,
matching D-1 (ctx-only signatures, no dual forms). The handler-facing
method name is preserved (D-4) — internal/api/handler/agents.go already
declares `Heartbeat(ctx, ...)` on its local service interface, and the
handler mock at internal/api/handler/agent_handler_test.go already
takes `_ context.Context` as its first param, so no handler churn.
Changes
-------
internal/service/agent.go
- Delete the zero-body Heartbeat wrapper that forwarded to
HeartbeatWithContext with context.Background().
- Rename HeartbeatWithContext → Heartbeat (ctx-bearing body
folded directly into the canonical method).
internal/service/agent_test.go
- TestHeartbeat (L95) and TestHeartbeat_NotFound (L128):
agentService.HeartbeatWithContext(ctx, ...) → .Heartbeat(ctx, ...).
internal/service/concurrent_test.go
- L162: agentSvc.HeartbeatWithContext(ctx, agentID, metadata)
→ .Heartbeat(ctx, agentID, metadata).
internal/service/context_test.go
- L179 + L232: agentSvc.HeartbeatWithContext(ctx, ...) → .Heartbeat(...)
- L185 + L238 t.Logf strings: "HeartbeatWithContext with ..." →
"Heartbeat with ..." to match the collapsed method name.
Verification (Go 1.25.9 linux/arm64, CI-parity caches)
------------------------------------------------------
go build ./... clean
go vet ./... clean
go test -short ./internal/service/... ./internal/api/handler/... \
./internal/integration/... all ok
go test -race -short same set all ok
go test -short ./... all packages ok
golangci-lint run ./... 0 issues
Locked decisions from the M-2 plan:
D-1 ctx-only signatures (no dual forms)
D-4 preserve handler method names facing the router
D-5 domain types stay ctx-free
Audit complete. Commit: 855124a9d9. Sections: 12. Findings: 2/7/10/4/6.
This commit is contained in:
@@ -176,13 +176,13 @@ func TestAgentService_HeartbeatWithCancelledContext(t *testing.T) {
|
||||
nil, // renewalService
|
||||
)
|
||||
|
||||
err := agentSvc.HeartbeatWithContext(ctx, "agent-1", &domain.AgentMetadata{})
|
||||
err := agentSvc.Heartbeat(ctx, "agent-1", &domain.AgentMetadata{})
|
||||
|
||||
// Service should handle cancelled context
|
||||
if err == nil || ctx.Err() == context.Canceled {
|
||||
return
|
||||
}
|
||||
t.Logf("HeartbeatWithContext with cancelled context returned: %v", err)
|
||||
t.Logf("Heartbeat with cancelled context returned: %v", err)
|
||||
}
|
||||
|
||||
// Test with timeout context (should trigger deadline exceeded)
|
||||
@@ -229,11 +229,11 @@ func TestAgentService_HeartbeatWithDeadlineExceeded(t *testing.T) {
|
||||
|
||||
time.Sleep(10 * time.Millisecond) // Ensure deadline is exceeded
|
||||
|
||||
err := agentSvc.HeartbeatWithContext(ctx, "agent-1", &domain.AgentMetadata{})
|
||||
err := agentSvc.Heartbeat(ctx, "agent-1", &domain.AgentMetadata{})
|
||||
|
||||
// Service should handle deadline exceeded
|
||||
if err == nil || ctx.Err() == context.DeadlineExceeded {
|
||||
return
|
||||
}
|
||||
t.Logf("HeartbeatWithContext with deadline exceeded returned: %v", err)
|
||||
t.Logf("Heartbeat with deadline exceeded returned: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user