From 9d7959f98fead95a84e79b855e57202c365774ff Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Sat, 3 Oct 2026 05:00:27 +0100 Subject: [PATCH] fix(lint): clear the staticcheck findings Drop the RealIP middleware: the worker listens on 127.0.0.1 only, and RealIP is deprecated because a client can set its own address. Log the restart error directly, since Restart only returns on failure. Remove an unused slice in a test and pass a real context instead of nil. staticcheck now reports nothing. --- internal/db/gorm/observation_store_test.go | 4 +--- internal/worker/handlers_update.go | 10 ++++------ internal/worker/sdk/dedup_test.go | 5 +++-- internal/worker/service.go | 1 - 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/internal/db/gorm/observation_store_test.go b/internal/db/gorm/observation_store_test.go index c2cf9ec..00db5d4 100644 --- a/internal/db/gorm/observation_store_test.go +++ b/internal/db/gorm/observation_store_test.go @@ -500,15 +500,13 @@ func TestObservationStore_CleanupOldObservations(t *testing.T) { // Store observations beyond the limit WITHOUT async cleanup // We disable async cleanup by not setting cleanupFunc - var allIDs []int64 for i := 0; i < 105; i++ { observation := &models.ParsedObservation{ Type: models.ObsTypeDiscovery, Title: "Observation", } - id, _, err := observationStore.StoreObservation(ctx, "claude-1", "test-project", observation, i, 10) + _, _, err := observationStore.StoreObservation(ctx, "claude-1", "test-project", observation, i, 10) require.NoError(t, err) - allIDs = append(allIDs, id) time.Sleep(2 * time.Millisecond) // Ensure different timestamps } diff --git a/internal/worker/handlers_update.go b/internal/worker/handlers_update.go index 454287a..1c79f23 100644 --- a/internal/worker/handlers_update.go +++ b/internal/worker/handlers_update.go @@ -218,9 +218,8 @@ func (s *Service) handleUpdateRestart(w http.ResponseWriter, r *http.Request) { // Restart in background after response is sent go func() { - if err := s.updater.Restart(); err != nil { - log.Error().Err(err).Msg("Failed to restart worker") - } + // Restart only returns when the new worker failed to start. + log.Error().Err(s.updater.Restart()).Msg("Failed to restart worker") }() } @@ -244,8 +243,7 @@ func (s *Service) handleRestart(w http.ResponseWriter, r *http.Request) { go func() { // Small delay to ensure response is sent time.Sleep(100 * time.Millisecond) - if err := s.updater.Restart(); err != nil { - log.Error().Err(err).Msg("Failed to restart worker") - } + // Restart only returns when the new worker failed to start. + log.Error().Err(s.updater.Restart()).Msg("Failed to restart worker") }() } diff --git a/internal/worker/sdk/dedup_test.go b/internal/worker/sdk/dedup_test.go index f494a40..59edb06 100644 --- a/internal/worker/sdk/dedup_test.go +++ b/internal/worker/sdk/dedup_test.go @@ -1,6 +1,7 @@ package sdk import ( + "context" "testing" "github.com/lukaszraczylo/claude-mnemonic/internal/vector/sqlitevec" @@ -121,7 +122,7 @@ func TestCheckVectorDeduplication_NilClient(t *testing.T) { Narrative: "Some narrative text", } - result := p.checkVectorDeduplication(nil, obs, "test-project") + result := p.checkVectorDeduplication(context.Background(), obs, "test-project") if result.Action != "insert" { t.Errorf("expected Action='insert' when vectorClient is nil, got %q", result.Action) } @@ -136,7 +137,7 @@ func TestCheckVectorDeduplication_EmptySearchText(t *testing.T) { // All empty fields } - result := p.checkVectorDeduplication(nil, obs, "test-project") + result := p.checkVectorDeduplication(context.Background(), obs, "test-project") if result.Action != "insert" { t.Errorf("expected Action='insert' for empty observation, got %q", result.Action) } diff --git a/internal/worker/service.go b/internal/worker/service.go index a9a11ee..2d6627b 100644 --- a/internal/worker/service.go +++ b/internal/worker/service.go @@ -1213,7 +1213,6 @@ func (s *Service) setupMiddleware() { s.router.Use(middleware.Logger) s.router.Use(middleware.Recoverer) - s.router.Use(middleware.RealIP) // Add security headers (X-Frame-Options, X-Content-Type-Options, CSP, etc.) s.router.Use(SecurityHeaders)