fix: lint cleanup across repo (errcheck, staticcheck, ineffassign, unused)

- daemon.go: real bug — maybeRetryParked resolved fg := d.forgeFor(task)
  (matching markDead's pattern) but called d.Forge.SetStateLabel instead
  of fg.SetStateLabel, silently using the wrong forge client for
  multi-identity/multi-forge task routing. Fixed to use fg throughout.
- telegram.go: updateThreadID existed but was never called anywhere;
  wired it into updateLoggingMiddleware so debug logs include thread_id.
- Two SA9003 empty-branch tests (nell adapter_test.go, tools
  toolentry_test.go) were dead assertions with no body; implemented the
  actual check instead of deleting them.
- memory manager_test.go: mockProvider.lastConfigSchema/lastBackupPaths
  were declared but never recorded; wired GetConfigSchema/BackupPaths to
  populate them and strengthened the aggregation tests to assert on
  per-provider content, not just counts.
- Removed genuinely dead gateway messageevent_test.go helpers (intPtr/
  i64Ptr, marked //go:fix inline, already fully superseded by the new()
  builtin used throughout the file).
- Remaining errcheck findings (defer Close/Flush/Write, os.Setenv, etc.
  in test files) fixed with the existing `_ = ` convention already used
  elsewhere in the codebase.

go build ./..., go test ./... (all packages ok), and
golangci-lint run ./... all clean.
This commit is contained in:
sam committed 2026-07-27 03:49:33 +10:00
1 parent 64352a06f3
commit 6fe1a7d037
19 files changed
+219 -183

No files matched your search

+5 -2
View File
@@ -55,7 +55,7 @@ func (t *HTTPTransport) Send(ctx context.Context, body []byte) ([]byte, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
// Read up to 4 KB of the error body for diagnostics.
@@ -80,7 +80,7 @@ func (t *HTTPTransport) Notify(ctx context.Context, body []byte) error {
}
// Drain and close the response body to return the connection to the pool.
_, _ = io.Copy(io.Discard, resp.Body)
resp.Body.Close()
_ = resp.Body.Close()
return nil
}
@@ -101,3 +101,6 @@ func (t *HTTPTransport) do(ctx context.Context, body []byte) (*http.Response, er
}
return resp, nil
}
// Compile-time interface check.
var _ Transport = (*HTTPTransport)(nil)
+3 -3
View File
@@ -21,7 +21,7 @@ func TestHTTPTransportSendReturnsResponse(t *testing.T) {
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, `{"jsonrpc":"2.0","id":"1","result":{"status":"ok"}}`)
_, _ = fmt.Fprint(w, `{"jsonrpc":"2.0","id":"1","result":{"status":"ok"}}`)
}))
defer srv.Close()
@@ -42,7 +42,7 @@ func TestHTTPTransportSendReturnsResponse(t *testing.T) {
func TestHTTPTransportSendReturnsErrorOnNon200(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, "boom")
_, _ = fmt.Fprint(w, "boom")
}))
defer srv.Close()
@@ -107,7 +107,7 @@ func TestHTTPTransportSendWithCustomHeaders(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
receivedHeader = r.Header.Get("Authorization")
w.Header().Set("Content-Type", "application/json")
fmt.Fprint(w, `{"jsonrpc":"2.0","id":"1","result":{}}`)
_, _ = fmt.Fprint(w, `{"jsonrpc":"2.0","id":"1","result":{}}`)
}))
defer srv.Close()
+6 -10
View File
@@ -66,10 +66,6 @@ type SSETransport struct {
mu sync.Mutex
state TransportState
// sessionID is learned from the endpoint event after the SSE
// connection is established and appended as a query parameter on
// POSTs to the message endpoint.
sessionID string
// messageEndpoint is the actual POST URL the server told us to use,
// discovered from the endpoint event (or the config fallback).
messageEndpoint string
@@ -214,7 +210,7 @@ func (t *SSETransport) connect(ctx context.Context) error {
return err
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
resp.Body.Close()
_ = resp.Body.Close()
err := fmt.Errorf("mcp sse: server returned %d", resp.StatusCode)
_ = t.setError(err)
return err
@@ -228,7 +224,7 @@ func (t *SSETransport) connect(ctx context.Context) error {
reader := bufio.NewReader(resp.Body)
msgURL, err := readEndpointEvent(reader)
if err != nil {
resp.Body.Close()
_ = resp.Body.Close()
_ = t.setError(fmt.Errorf("mcp sse: read endpoint event: %w", err))
return err
}
@@ -252,7 +248,7 @@ func (t *SSETransport) connect(ctx context.Context) error {
// "message" events to the corresponding pending channel.
func (t *SSETransport) runReader(body io.Closer, reader *bufio.Reader) {
defer t.readerWg.Done()
defer body.Close()
defer func() { _ = body.Close() }()
for {
event, data, err := readSSEEvent(reader)
@@ -323,7 +319,7 @@ func (t *SSETransport) reconnect() {
continue
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
resp.Body.Close()
_ = resp.Body.Close()
backoff = nextBackoff(backoff, t.config.effectiveMaxReconnectBackoff())
continue
}
@@ -331,7 +327,7 @@ func (t *SSETransport) reconnect() {
reader := bufio.NewReader(resp.Body)
msgURL, err := readEndpointEvent(reader)
if err != nil {
resp.Body.Close()
_ = resp.Body.Close()
backoff = nextBackoff(backoff, t.config.effectiveMaxReconnectBackoff())
continue
}
@@ -407,7 +403,7 @@ func (t *SSETransport) postJSON(ctx context.Context, body []byte) error {
if err != nil {
return fmt.Errorf("mcp sse: post: %w", err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
msg, _ := io.ReadAll(io.LimitReader(resp.Body, 4096))
+10 -12
View File
@@ -19,11 +19,9 @@ import (
// events onto events to send them back through the SSE stream.
type sseTestServer struct {
*httptest.Server
SessID string
events chan string
incoming chan []byte
mu sync.Mutex
postedIDs []string
SessID string
events chan string
incoming chan []byte
}
func newSSETestServer(t *testing.T) *sseTestServer {
@@ -33,7 +31,7 @@ func newSSETestServer(t *testing.T) *sseTestServer {
incoming: make(chan []byte, 10),
}
s.Server = httptest.NewUnstartedServer(s)
s.Server.Start()
s.Start()
s.SessID = "test-session-id"
return s
}
@@ -51,13 +49,13 @@ func (s *sseTestServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
// Send the endpoint event — tells the client where to POST.
fmt.Fprintf(w, "event: endpoint\ndata: %s/messages?session_id=%s\n\n", s.URL, s.SessID)
_, _ = fmt.Fprintf(w, "event: endpoint\ndata: %s/messages?session_id=%s\n\n", s.URL, s.SessID)
flusher.Flush()
for {
select {
case data := <-s.events:
fmt.Fprintf(w, "event: message\ndata: %s\n\n", data)
_, _ = fmt.Fprintf(w, "event: message\ndata: %s\n\n", data)
flusher.Flush()
case <-r.Context().Done():
return
@@ -66,7 +64,7 @@ func (s *sseTestServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case "/messages":
body, _ := io.ReadAll(r.Body)
r.Body.Close()
_ = r.Body.Close()
s.incoming <- body
w.WriteHeader(http.StatusAccepted)
@@ -86,7 +84,7 @@ func TestSSETransportSendReceivesResponseViaSSE(t *testing.T) {
if err := tr.Start(context.Background()); err != nil {
t.Fatalf("Start: %v", err)
}
defer tr.Stop(context.Background())
defer func() { _ = tr.Stop(context.Background()) }()
time.Sleep(50 * time.Millisecond) // let the SSE connection establish
@@ -121,7 +119,7 @@ func TestSSETransportNotifyFireAndForget(t *testing.T) {
if err := tr.Start(context.Background()); err != nil {
t.Fatalf("Start: %v", err)
}
defer tr.Stop(context.Background())
defer func() { _ = tr.Stop(context.Background()) }()
time.Sleep(50 * time.Millisecond)
@@ -197,7 +195,7 @@ func TestSSETransportConcurrentSendsGetCorrectResponses(t *testing.T) {
if err := tr.Start(context.Background()); err != nil {
t.Fatalf("Start: %v", err)
}
defer tr.Stop(context.Background())
defer func() { _ = tr.Stop(context.Background()) }()
time.Sleep(50 * time.Millisecond)
+11 -11
View File
@@ -103,7 +103,7 @@ func TestRegistryAll(t *testing.T) {
t.Run("returns copy of tools", func(t *testing.T) {
r := NewRegistry()
r.Register(ToolEntry{Name: "x", Handler: noopHandler})
_ = r.Register(ToolEntry{Name: "x", Handler: noopHandler})
all := r.All()
all[0].Name = "mutated"
// Original registry must be unaffected.
@@ -115,10 +115,10 @@ func TestRegistryAll(t *testing.T) {
func TestRegistryByToolset(t *testing.T) {
r := NewRegistry()
r.Register(ToolEntry{Name: "f1", Toolset: "file", Handler: noopHandler})
r.Register(ToolEntry{Name: "f2", Toolset: "file", Handler: noopHandler})
r.Register(ToolEntry{Name: "g1", Toolset: "git", Handler: noopHandler})
r.Register(ToolEntry{Name: "u1", Toolset: "", Handler: noopHandler}) // ungrouped
_ = r.Register(ToolEntry{Name: "f1", Toolset: "file", Handler: noopHandler})
_ = r.Register(ToolEntry{Name: "f2", Toolset: "file", Handler: noopHandler})
_ = r.Register(ToolEntry{Name: "g1", Toolset: "git", Handler: noopHandler})
_ = r.Register(ToolEntry{Name: "u1", Toolset: "", Handler: noopHandler}) // ungrouped
t.Run("filters by toolset", func(t *testing.T) {
file := r.ByToolset("file")
@@ -152,9 +152,9 @@ func TestRegistryByToolset(t *testing.T) {
func TestRegistryAvailable(t *testing.T) {
r := NewRegistry()
r.Register(ToolEntry{Name: "always", Handler: noopHandler})
r.Register(ToolEntry{Name: "offline", Handler: noopHandler, CheckFn: func() bool { return false }})
r.Register(ToolEntry{Name: "conditional", Handler: noopHandler, CheckFn: func() bool { return true }})
_ = r.Register(ToolEntry{Name: "always", Handler: noopHandler})
_ = r.Register(ToolEntry{Name: "offline", Handler: noopHandler, CheckFn: func() bool { return false }})
_ = r.Register(ToolEntry{Name: "conditional", Handler: noopHandler, CheckFn: func() bool { return true }})
t.Run("returns only available tools", func(t *testing.T) {
avail := r.Available()
@@ -175,7 +175,7 @@ func TestRegistryAvailable(t *testing.T) {
t.Run("dynamic availability reflected", func(t *testing.T) {
flag := true
r.Register(ToolEntry{
_ = r.Register(ToolEntry{
Name: "toggle",
Handler: noopHandler,
CheckFn: func() bool { return flag },
@@ -317,10 +317,10 @@ func TestRegistryAvailableReentrySafety(t *testing.T) {
// calling All(), ByToolset(), or even Register() from inside
// CheckFn cannot deadlock.
r := NewRegistry()
r.Register(ToolEntry{Name: "safe", Handler: noopHandler})
_ = r.Register(ToolEntry{Name: "safe", Handler: noopHandler})
called := false
r.Register(ToolEntry{
_ = r.Register(ToolEntry{
Name: "reentrant",
Handler: noopHandler,
CheckFn: func() bool {
+1 -1
View File
@@ -316,7 +316,7 @@ func TestToolEntryZeroValue(t *testing.T) {
t.Error("zero ToolEntry should fail Validate")
}
if !e.Available() {
// nil CheckFn = available -- this is correct even for zero value.
t.Error("zero ToolEntry should be Available (nil CheckFn = available)")
}
if e.ResolvedSchema() != nil {
t.Error("zero ToolEntry should have nil resolved schema")