From efef46b15a4f5050d599000e78ffb467846406a1 Mon Sep 17 00:00:00 2001 From: Evan Jarrett Date: Sun, 4 Jan 2026 22:02:01 -0600 Subject: [PATCH] various linting fixes --- cmd/credential-helper/main.go | 4 +-- pkg/appview/db/device_store.go | 6 +++-- pkg/appview/db/device_store_test.go | 14 +++------- pkg/appview/db/oauth_store.go | 14 +++++----- pkg/appview/db/oauth_store_test.go | 4 +-- pkg/appview/db/session_store_test.go | 4 +-- pkg/appview/holdhealth/worker_test.go | 13 --------- pkg/appview/jetstream/processor_test.go | 2 +- pkg/appview/jetstream/worker.go | 3 +-- pkg/appview/middleware/auth_test.go | 4 +-- pkg/appview/middleware/registry.go | 2 +- pkg/appview/ogcard/card.go | 27 ++++++++++--------- pkg/appview/readme/fetcher.go | 1 + pkg/appview/readme/fetcher_test.go | 2 +- pkg/appview/storage/manifest_store.go | 2 +- pkg/appview/storage/profile_test.go | 2 +- pkg/appview/storage/proxy_blob_store.go | 11 ++++---- pkg/appview/storage/proxy_blob_store_test.go | 2 +- pkg/appview/storage/routing_repository.go | 6 ++++- .../storage/routing_repository_test.go | 10 +++---- pkg/atproto/directory_test.go | 4 +-- pkg/auth/cache.go | 2 +- pkg/auth/hold_remote_test.go | 11 -------- pkg/auth/oauth/client_test.go | 3 ++- pkg/auth/oauth/server_test.go | 3 ++- pkg/auth/token/claims.go | 1 + pkg/hold/pds/events_test.go | 2 +- pkg/hold/pds/layer_test.go | 6 ++--- pkg/hold/pds/records_test.go | 6 ++--- pkg/hold/pds/server.go | 3 +-- pkg/hold/pds/status_test.go | 2 +- pkg/hold/pds/xrpc_test.go | 8 +++--- pkg/hold/quota/config.go | 1 + pkg/logging/logger_test.go | 4 +-- 34 files changed, 83 insertions(+), 106 deletions(-) delete mode 100644 pkg/appview/holdhealth/worker_test.go diff --git a/cmd/credential-helper/main.go b/cmd/credential-helper/main.go index 9d0e030..91c6559 100644 --- a/cmd/credential-helper/main.go +++ b/cmd/credential-helper/main.go @@ -180,7 +180,7 @@ func handleGet() { // Wait for user to complete OAuth flow, then retry fmt.Fprintf(os.Stderr, "Waiting for authentication") - for i := 0; i < 60; i++ { // Wait up to 2 minutes + for range 60 { // Wait up to 2 minutes time.Sleep(2 * time.Second) fmt.Fprintf(os.Stderr, ".") @@ -765,7 +765,7 @@ func isNewerVersion(newVersion, currentVersion string) bool { curParts := strings.Split(curV, ".") // Compare each part - for i := 0; i < len(newParts) && i < len(curParts); i++ { + for i := range min(len(newParts), len(curParts)) { newNum := 0 curNum := 0 fmt.Sscanf(newParts[i], "%d", &newNum) diff --git a/pkg/appview/db/device_store.go b/pkg/appview/db/device_store.go index 87cf4d4..c06671a 100644 --- a/pkg/appview/db/device_store.go +++ b/pkg/appview/db/device_store.go @@ -365,14 +365,16 @@ func (s *DeviceStore) RevokeDevice(did, deviceID string) error { } // UpdateLastUsed updates the last used timestamp -func (s *DeviceStore) UpdateLastUsed(secretHash string) error { +func (s *DeviceStore) UpdateLastUsed(secretHash string) { _, err := s.db.Exec(` UPDATE devices SET last_used = ? WHERE secret_hash = ? `, time.Now(), secretHash) - return err + if err != nil { + slog.Warn("Failed to update device last used timestamp", "component", "device_store", "error", err) + } } // CleanupExpired removes expired pending authorizations diff --git a/pkg/appview/db/device_store_test.go b/pkg/appview/db/device_store_test.go index c3b3ee2..cdd5242 100644 --- a/pkg/appview/db/device_store_test.go +++ b/pkg/appview/db/device_store_test.go @@ -56,7 +56,7 @@ func TestDevice_Struct(t *testing.T) { func TestGenerateUserCode(t *testing.T) { // Generate multiple codes to test codes := make(map[string]bool) - for i := 0; i < 100; i++ { + for range 100 { code := generateUserCode() // Test format: XXXX-XXXX @@ -372,9 +372,6 @@ func TestDeviceStore_ValidateDeviceSecret(t *testing.T) { return } if !tt.wantErr { - if device == nil { - t.Error("Expected device, got nil") - } if device.DID != "did:plc:alice123" { t.Errorf("DID = %v, want did:plc:alice123", device.DID) } @@ -399,7 +396,7 @@ func TestDeviceStore_ListDevices(t *testing.T) { } // Create 3 devices - for i := 0; i < 3; i++ { + for i := range 3 { pending, err := store.CreatePendingAuth("Device "+string(rune('A'+i)), "192.168.1.1", "Agent") if err != nil { t.Fatalf("CreatePendingAuth() error = %v", err) @@ -417,7 +414,7 @@ func TestDeviceStore_ListDevices(t *testing.T) { } // Verify they're sorted by created_at DESC (newest first) - for i := 0; i < len(devices)-1; i++ { + for i := range len(devices) - 1 { if devices[i].CreatedAt.Before(devices[i+1].CreatedAt) { t.Error("Devices should be sorted by created_at DESC") } @@ -521,10 +518,7 @@ func TestDeviceStore_UpdateLastUsed(t *testing.T) { time.Sleep(10 * time.Millisecond) // Update last used - err = store.UpdateLastUsed(device.SecretHash) - if err != nil { - t.Errorf("UpdateLastUsed() error = %v", err) - } + store.UpdateLastUsed(device.SecretHash) // Verify it was updated device2, err := store.ValidateDeviceSecret(secret) diff --git a/pkg/appview/db/oauth_store.go b/pkg/appview/db/oauth_store.go index d46d9fd..19c9b7a 100644 --- a/pkg/appview/db/oauth_store.go +++ b/pkg/appview/db/oauth_store.go @@ -213,7 +213,7 @@ func (s *OAuthStore) GetLatestSessionForDID(ctx context.Context, did string) (*o } // CleanupOldSessions removes sessions older than the specified duration -func (s *OAuthStore) CleanupOldSessions(ctx context.Context, olderThan time.Duration) error { +func (s *OAuthStore) CleanupOldSessions(ctx context.Context, olderThan time.Duration) { cutoff := time.Now().Add(-olderThan) result, err := s.db.ExecContext(ctx, ` @@ -222,19 +222,18 @@ func (s *OAuthStore) CleanupOldSessions(ctx context.Context, olderThan time.Dura `, cutoff) if err != nil { - return fmt.Errorf("failed to cleanup old sessions: %w", err) + slog.Warn("Failed to cleanup old OAuth sessions", "component", "oauth_store", "error", err) + return } deleted, _ := result.RowsAffected() if deleted > 0 { slog.Info("Cleaned up old OAuth sessions", "count", deleted, "older_than", olderThan) } - - return nil } // CleanupExpiredAuthRequests removes auth requests older than 10 minutes -func (s *OAuthStore) CleanupExpiredAuthRequests(ctx context.Context) error { +func (s *OAuthStore) CleanupExpiredAuthRequests(ctx context.Context) { cutoff := time.Now().Add(-10 * time.Minute) result, err := s.db.ExecContext(ctx, ` @@ -243,15 +242,14 @@ func (s *OAuthStore) CleanupExpiredAuthRequests(ctx context.Context) error { `, cutoff) if err != nil { - return fmt.Errorf("failed to cleanup auth requests: %w", err) + slog.Warn("Failed to cleanup expired auth requests", "component", "oauth_store", "error", err) + return } deleted, _ := result.RowsAffected() if deleted > 0 { slog.Info("Cleaned up expired auth requests", "count", deleted) } - - return nil } // InvalidateSessionsWithMismatchedScopes removes all sessions whose scopes don't match the desired scopes diff --git a/pkg/appview/db/oauth_store_test.go b/pkg/appview/db/oauth_store_test.go index 5ec2501..9cb6b37 100644 --- a/pkg/appview/db/oauth_store_test.go +++ b/pkg/appview/db/oauth_store_test.go @@ -353,9 +353,7 @@ func TestCleanupOldSessions(t *testing.T) { } // Run cleanup (remove sessions older than 30 days) - if err := store.CleanupOldSessions(ctx, 30*24*time.Hour); err != nil { - t.Fatalf("Failed to cleanup old sessions: %v", err) - } + store.CleanupOldSessions(ctx, 30*24*time.Hour) // Verify old session was deleted _, err = store.GetSession(ctx, did1, "old_session") diff --git a/pkg/appview/db/session_store_test.go b/pkg/appview/db/session_store_test.go index 2d2ba89..41c6d40 100644 --- a/pkg/appview/db/session_store_test.go +++ b/pkg/appview/db/session_store_test.go @@ -252,7 +252,7 @@ func TestSessionStore_DeleteByDID(t *testing.T) { // Create multiple sessions for alice sessionIDs := make([]string, 3) - for i := 0; i < 3; i++ { + for i := range 3 { id, err := store.Create(did, "alice.bsky.social", "https://pds.example.com", 1*time.Hour) if err != nil { t.Fatalf("Create() error = %v", err) @@ -516,7 +516,7 @@ func TestSessionStore_SessionIDUniqueness(t *testing.T) { // Generate multiple session IDs ids := make(map[string]bool) - for i := 0; i < 100; i++ { + for range 100 { id, err := store.Create("did:plc:alice123", "alice.bsky.social", "https://pds.example.com", 1*time.Hour) if err != nil { t.Fatalf("Create() error = %v", err) diff --git a/pkg/appview/holdhealth/worker_test.go b/pkg/appview/holdhealth/worker_test.go deleted file mode 100644 index 8a462a3..0000000 --- a/pkg/appview/holdhealth/worker_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package holdhealth - -import "testing" - -func TestWorker_Struct(t *testing.T) { - // Simple struct test - worker := &Worker{} - if worker == nil { - t.Error("Expected non-nil worker") - } -} - -// TODO: Add background health check tests diff --git a/pkg/appview/jetstream/processor_test.go b/pkg/appview/jetstream/processor_test.go index cb2fcd9..6475afc 100644 --- a/pkg/appview/jetstream/processor_test.go +++ b/pkg/appview/jetstream/processor_test.go @@ -675,7 +675,7 @@ func TestProcessAccount(t *testing.T) { } // Test 5: Process multiple deactivation events (idempotent) - for i := 0; i < 3; i++ { + for i := range 3 { err = processor.ProcessAccount(context.Background(), testDID, false, "deactivated") if err != nil { t.Logf("Expected cache invalidation error on iteration %d: %v", i, err) diff --git a/pkg/appview/jetstream/worker.go b/pkg/appview/jetstream/worker.go index 00647b1..0d7067d 100644 --- a/pkg/appview/jetstream/worker.go +++ b/pkg/appview/jetstream/worker.go @@ -128,8 +128,7 @@ func (w *Worker) Start(ctx context.Context) error { // Reset read deadline - we know connection is alive // Allow 90 seconds for next pong (3x ping interval) - conn.SetReadDeadline(time.Now().Add(90 * time.Second)) - return nil + return conn.SetReadDeadline(time.Now().Add(90 * time.Second)) }) // Set initial read deadline diff --git a/pkg/appview/middleware/auth_test.go b/pkg/appview/middleware/auth_test.go index 09a6802..c85a54e 100644 --- a/pkg/appview/middleware/auth_test.go +++ b/pkg/appview/middleware/auth_test.go @@ -318,7 +318,7 @@ func TestMiddleware_ConcurrentAccess(t *testing.T) { // Pre-create all users and sessions before concurrent access // This ensures database is fully initialized before goroutines start sessionIDs := make([]string, 10) - for i := 0; i < 10; i++ { + for i := range 10 { did := fmt.Sprintf("did:plc:user%d", i) handle := fmt.Sprintf("user%d.bsky.social", i) @@ -358,7 +358,7 @@ func TestMiddleware_ConcurrentAccess(t *testing.T) { var wg sync.WaitGroup var mu sync.Mutex // Protect results map - for i := 0; i < 10; i++ { + for i := range 10 { wg.Add(1) go func(index int, sessionID string) { defer wg.Done() diff --git a/pkg/appview/middleware/registry.go b/pkg/appview/middleware/registry.go index 4590b5d..a4d3ba1 100644 --- a/pkg/appview/middleware/registry.go +++ b/pkg/appview/middleware/registry.go @@ -555,7 +555,7 @@ func ExtractAuthMethod(next http.Handler) http.Handler { // Store HTTP method in context for routing decisions // This is used by routing_repository.go to distinguish pull (GET/HEAD) from push (PUT/POST) - ctx = context.WithValue(ctx, "http.request.method", r.Method) + ctx = context.WithValue(ctx, storage.HTTPRequestMethod, r.Method) // Extract Authorization header authHeader := r.Header.Get("Authorization") diff --git a/pkg/appview/ogcard/card.go b/pkg/appview/ogcard/card.go index b9020a4..dfc81f0 100644 --- a/pkg/appview/ogcard/card.go +++ b/pkg/appview/ogcard/card.go @@ -143,9 +143,10 @@ func (c *Card) DrawText(text string, x, y float64, size float64, col color.Color defer face.Close() textWidth := font.MeasureString(face, text).Round() - if align == AlignCenter { + switch align { + case AlignCenter: x -= float64(textWidth) / 2 - } else if align == AlignRight { + case AlignRight: x -= float64(textWidth) } } @@ -292,21 +293,21 @@ func (c *Card) DrawPlaceholderCircle(x, y, diameter int, bgColor, textColor colo // DrawRoundedRect draws a filled rounded rectangle func (c *Card) DrawRoundedRect(x, y, w, h, radius int, col color.Color) { // Draw main rectangle (without corners) - for dy := radius; dy < h-radius; dy++ { - for dx := 0; dx < w; dx++ { - c.img.Set(x+dx, y+dy, col) + for dy := range h - 2*radius { + for dx := range w { + c.img.Set(x+dx, y+radius+dy, col) } } // Draw top and bottom strips (without corners) - for dy := 0; dy < radius; dy++ { - for dx := radius; dx < w-radius; dx++ { - c.img.Set(x+dx, y+dy, col) - c.img.Set(x+dx, y+h-1-dy, col) + for dy := range radius { + for dx := range w - 2*radius { + c.img.Set(x+radius+dx, y+dy, col) + c.img.Set(x+radius+dx, y+h-1-dy, col) } } // Draw rounded corners - for dy := 0; dy < radius; dy++ { - for dx := 0; dx < radius; dx++ { + for dy := range radius { + for dx := range radius { // Check if point is within circle cx := radius - dx - 1 cy := radius - dy - 1 @@ -388,8 +389,8 @@ func createCircleMask(diameter int) *image.Alpha { centerX := radius centerY := radius - for y := 0; y < diameter; y++ { - for x := 0; x < diameter; x++ { + for y := range diameter { + for x := range diameter { dx := x - centerX dy := y - centerY if dx*dx+dy*dy <= radius*radius { diff --git a/pkg/appview/readme/fetcher.go b/pkg/appview/readme/fetcher.go index fa621d3..671f0b7 100644 --- a/pkg/appview/readme/fetcher.go +++ b/pkg/appview/readme/fetcher.go @@ -1,3 +1,4 @@ +// Package readme provides fetching and rendering of README files from Git hosting platforms. package readme import ( diff --git a/pkg/appview/readme/fetcher_test.go b/pkg/appview/readme/fetcher_test.go index c968252..f9d3ef2 100644 --- a/pkg/appview/readme/fetcher_test.go +++ b/pkg/appview/readme/fetcher_test.go @@ -301,7 +301,7 @@ func containsSubstring(s, substr string) bool { } func containsSubstringHelper(s, substr string) bool { - for i := 0; i <= len(s)-len(substr); i++ { + for i := range len(s) - len(substr) + 1 { if s[i:i+len(substr)] == substr { return true } diff --git a/pkg/appview/storage/manifest_store.go b/pkg/appview/storage/manifest_store.go index 4df2e80..dcff9f8 100644 --- a/pkg/appview/storage/manifest_store.go +++ b/pkg/appview/storage/manifest_store.go @@ -76,7 +76,7 @@ func (s *ManifestStore) Get(ctx context.Context, dgst digest.Digest, options ... // Notify hold about manifest pull (for stats tracking) // Only count GET requests (actual downloads), not HEAD requests (existence checks) // Check HTTP method from context (distribution library stores it as "http.request.method") - if method, ok := ctx.Value("http.request.method").(string); ok && method == "GET" { + if method, ok := ctx.Value(HTTPRequestMethod).(string); ok && method == "GET" { // Do this asynchronously to avoid blocking the response if s.ctx.ServiceToken != "" && s.ctx.Handle != "" { go func() { diff --git a/pkg/appview/storage/profile_test.go b/pkg/appview/storage/profile_test.go index 548c6c3..8c68db5 100644 --- a/pkg/appview/storage/profile_test.go +++ b/pkg/appview/storage/profile_test.go @@ -340,7 +340,7 @@ func TestGetProfile_MigrationLocking(t *testing.T) { // Make 5 concurrent GetProfile calls var wg sync.WaitGroup - for i := 0; i < 5; i++ { + for range 5 { wg.Add(1) go func() { defer wg.Done() diff --git a/pkg/appview/storage/proxy_blob_store.go b/pkg/appview/storage/proxy_blob_store.go index ce6099b..e85441a 100644 --- a/pkg/appview/storage/proxy_blob_store.go +++ b/pkg/appview/storage/proxy_blob_store.go @@ -552,7 +552,7 @@ func (p *ProxyBlobStore) completeMultipartUpload(ctx context.Context, digest, up } // abortMultipartUpload aborts a multipart upload via XRPC abortUpload endpoint -func (p *ProxyBlobStore) abortMultipartUpload(ctx context.Context, digest, uploadID string) error { +func (p *ProxyBlobStore) abortMultipartUpload(ctx context.Context, uploadID string) error { reqBody := map[string]any{ "uploadId": uploadID, } @@ -760,8 +760,10 @@ func (w *ProxyBlobWriter) Commit(ctx context.Context, desc distribution.Descript slog.Debug("Flushing final buffer", "component", "proxy_blob_store/Commit", "bytes", w.buffer.Len()) if err := w.flushPart(); err != nil { // Try to abort multipart on error - tempDigest := fmt.Sprintf("uploads/temp-%s", w.id) - w.store.abortMultipartUpload(ctx, tempDigest, w.uploadID) + if err := w.store.abortMultipartUpload(ctx, w.uploadID); err != nil { + slog.Warn("Failed to abort multipart upload", "component", "proxy_blob_store/Cancel", "error", err) + // Continue anyway - we want to mark upload as cancelled + } return distribution.Descriptor{}, fmt.Errorf("failed to flush final part: %w", err) } } @@ -794,8 +796,7 @@ func (w *ProxyBlobWriter) Cancel(ctx context.Context) error { globalUploadsMu.Unlock() // Abort multipart upload - tempDigest := fmt.Sprintf("uploads/temp-%s", w.id) - if err := w.store.abortMultipartUpload(ctx, tempDigest, w.uploadID); err != nil { + if err := w.store.abortMultipartUpload(ctx, w.uploadID); err != nil { slog.Warn("Failed to abort multipart upload", "component", "proxy_blob_store/Cancel", "error", err) // Continue anyway - we want to mark upload as cancelled } diff --git a/pkg/appview/storage/proxy_blob_store_test.go b/pkg/appview/storage/proxy_blob_store_test.go index f162e9d..8b5cc3b 100644 --- a/pkg/appview/storage/proxy_blob_store_test.go +++ b/pkg/appview/storage/proxy_blob_store_test.go @@ -563,7 +563,7 @@ func TestMultipartEndpoints_CorrectURLs(t *testing.T) { { name: "abortMultipartUpload", testFunc: func(store *ProxyBlobStore) error { - return store.abortMultipartUpload(context.Background(), "sha256:test", "upload-123") + return store.abortMultipartUpload(context.Background(), "upload-123") }, expectedPath: atproto.HoldAbortUpload, }, diff --git a/pkg/appview/storage/routing_repository.go b/pkg/appview/storage/routing_repository.go index dc51be4..deba6b3 100644 --- a/pkg/appview/storage/routing_repository.go +++ b/pkg/appview/storage/routing_repository.go @@ -11,6 +11,10 @@ import ( "github.com/distribution/distribution/v3" ) +type contextKey string + +const HTTPRequestMethod contextKey = "http.request.method" + // RoutingRepository routes manifests to ATProto and blobs to external hold service // The registry (AppView) is stateless and NEVER stores blobs locally // NOTE: A fresh instance is created per-request (see middleware/registry.go) @@ -55,7 +59,7 @@ func (r *RoutingRepository) Blobs(ctx context.Context) distribution.BlobStore { // Push operations use the discovery-based hold DID from user's profile/default // This allows users to change their default hold and have new pushes go there isPull := false - if method, ok := ctx.Value("http.request.method").(string); ok { + if method, ok := ctx.Value(HTTPRequestMethod).(string); ok { isPull = method == "GET" || method == "HEAD" } diff --git a/pkg/appview/storage/routing_repository_test.go b/pkg/appview/storage/routing_repository_test.go index a32e8cb..9206062 100644 --- a/pkg/appview/storage/routing_repository_test.go +++ b/pkg/appview/storage/routing_repository_test.go @@ -126,7 +126,7 @@ func TestRoutingRepository_Blobs_PullUsesDatabase(t *testing.T) { } repo := NewRoutingRepository(nil, ctx) - pullCtx := context.WithValue(context.Background(), "http.request.method", method) + pullCtx := context.WithValue(context.Background(), HTTPRequestMethod, method) blobStore := repo.Blobs(pullCtx) assert.NotNil(t, blobStore) @@ -164,7 +164,7 @@ func TestRoutingRepository_Blobs_PushUsesDiscovery(t *testing.T) { repo := NewRoutingRepository(nil, ctx) // Create context with push method - pushCtx := context.WithValue(context.Background(), "http.request.method", tc.method) + pushCtx := context.WithValue(context.Background(), HTTPRequestMethod, tc.method) blobStore := repo.Blobs(pushCtx) assert.NotNil(t, blobStore) @@ -330,7 +330,7 @@ func TestRoutingRepository_ConcurrentAccess(t *testing.T) { wg.Wait() // Verify all stores are non-nil (due to race conditions, they may not all be the same instance) - for i := 0; i < numGoroutines; i++ { + for i := range numGoroutines { assert.NotNil(t, manifestStores[i], "manifest store should not be nil") } @@ -351,7 +351,7 @@ func TestRoutingRepository_ConcurrentAccess(t *testing.T) { wg.Wait() // Verify all stores are non-nil (due to race conditions, they may not all be the same instance) - for i := 0; i < numGoroutines; i++ { + for i := range numGoroutines { assert.NotNil(t, blobStores[i], "blob store should not be nil") } @@ -376,7 +376,7 @@ func TestRoutingRepository_Blobs_PullPriority(t *testing.T) { repo := NewRoutingRepository(nil, ctx) // For pull (GET), database should take priority - pullCtx := context.WithValue(context.Background(), "http.request.method", "GET") + pullCtx := context.WithValue(context.Background(), HTTPRequestMethod, "GET") blobStore := repo.Blobs(pullCtx) assert.NotNil(t, blobStore) diff --git a/pkg/atproto/directory_test.go b/pkg/atproto/directory_test.go index d0a35cf..96d6bdb 100644 --- a/pkg/atproto/directory_test.go +++ b/pkg/atproto/directory_test.go @@ -35,7 +35,7 @@ func TestGetDirectoryConcurrency(t *testing.T) { instances := make(chan any, numGoroutines) // Launch many goroutines concurrently accessing GetDirectory - for i := 0; i < numGoroutines; i++ { + for range numGoroutines { go func() { defer wg.Done() dir := GetDirectory() @@ -73,7 +73,7 @@ func TestGetDirectorySequential(t *testing.T) { t.Run("multiple calls in sequence", func(t *testing.T) { // Get directory multiple times in sequence dirs := make([]any, 10) - for i := 0; i < 10; i++ { + for i := range 10 { dirs[i] = GetDirectory() } diff --git a/pkg/auth/cache.go b/pkg/auth/cache.go index 58c67f2..f865a57 100644 --- a/pkg/auth/cache.go +++ b/pkg/auth/cache.go @@ -1,4 +1,4 @@ -// Package token provides service token caching and management for AppView. +// Package auth provides service token caching and management for AppView. // Service tokens are JWTs issued by a user's PDS to authorize AppView to // act on their behalf when communicating with hold services. Tokens are // cached with automatic expiry parsing and 10-second safety margins. diff --git a/pkg/auth/hold_remote_test.go b/pkg/auth/hold_remote_test.go index c49bb1b..602e59e 100644 --- a/pkg/auth/hold_remote_test.go +++ b/pkg/auth/hold_remote_test.go @@ -14,17 +14,6 @@ import ( "atcr.io/pkg/atproto" ) -func TestNewRemoteHoldAuthorizer(t *testing.T) { - // Test with nil database (should still work) - authorizer := NewRemoteHoldAuthorizer(nil, false) - if authorizer == nil { - t.Fatal("Expected non-nil authorizer") - } - - // Verify it implements the HoldAuthorizer interface - var _ HoldAuthorizer = authorizer -} - func TestNewRemoteHoldAuthorizer_TestMode(t *testing.T) { // Test with testMode enabled authorizer := NewRemoteHoldAuthorizer(nil, true) diff --git a/pkg/auth/oauth/client_test.go b/pkg/auth/oauth/client_test.go index e860d4c..2587cf8 100644 --- a/pkg/auth/oauth/client_test.go +++ b/pkg/auth/oauth/client_test.go @@ -1,8 +1,9 @@ package oauth import ( - "github.com/bluesky-social/indigo/atproto/auth/oauth" "testing" + + "github.com/bluesky-social/indigo/atproto/auth/oauth" ) func TestNewClientApp(t *testing.T) { diff --git a/pkg/auth/oauth/server_test.go b/pkg/auth/oauth/server_test.go index 6e7bcac..f7a0f0d 100644 --- a/pkg/auth/oauth/server_test.go +++ b/pkg/auth/oauth/server_test.go @@ -2,12 +2,13 @@ package oauth import ( "context" - "github.com/bluesky-social/indigo/atproto/auth/oauth" "net/http" "net/http/httptest" "strings" "testing" "time" + + "github.com/bluesky-social/indigo/atproto/auth/oauth" ) func TestNewServer(t *testing.T) { diff --git a/pkg/auth/token/claims.go b/pkg/auth/token/claims.go index 3838345..ef227b2 100644 --- a/pkg/auth/token/claims.go +++ b/pkg/auth/token/claims.go @@ -1,3 +1,4 @@ +// Package token provides JWT claims and token handling for registry authentication. package token import ( diff --git a/pkg/hold/pds/events_test.go b/pkg/hold/pds/events_test.go index 9634d5e..9e37ddc 100644 --- a/pkg/hold/pds/events_test.go +++ b/pkg/hold/pds/events_test.go @@ -150,7 +150,7 @@ func TestAddToHistory_RingBuffer(t *testing.T) { testCID, _ := cid.Decode("bafyreib2rxk3rkhh5ylyxj3x3gathxt3s32qvwj2lf3qg4kmzr6b7teqke") // Broadcast 5 events (exceeds maxHistory of 3) - for i := 0; i < 5; i++ { + for range 5 { event := &RepoEvent{ NewRoot: testCID, Rev: "test-rev", diff --git a/pkg/hold/pds/layer_test.go b/pkg/hold/pds/layer_test.go index 959616b..a6f7acf 100644 --- a/pkg/hold/pds/layer_test.go +++ b/pkg/hold/pds/layer_test.go @@ -377,7 +377,7 @@ defaults: } // Create layer records for owner - for i := 0; i < 3; i++ { + for i := range 3 { record := atproto.NewLayerRecord( "sha256:owner"+string(rune('a'+i)), 1024*1024*100, // 100MB each @@ -454,7 +454,7 @@ defaults: addCrewMemberWithBerth(t, pds, crewDID, "writer", []string{"blob:write"}, "") // Create layer records for crew member - for i := 0; i < 2; i++ { + for i := range 2 { record := atproto.NewLayerRecord( "sha256:crew"+string(rune('a'+i)), 1024*1024*50, // 50MB each @@ -685,7 +685,7 @@ defaults: // Create multiple layer records with same digest (should be deduplicated) digest := "sha256:duplicatelayer" - for i := 0; i < 5; i++ { + for i := range 5 { record := atproto.NewLayerRecord( digest, 1024*1024*100, // 100MB diff --git a/pkg/hold/pds/records_test.go b/pkg/hold/pds/records_test.go index db1e4ac..619aabc 100644 --- a/pkg/hold/pds/records_test.go +++ b/pkg/hold/pds/records_test.go @@ -322,7 +322,7 @@ func TestRecordsIndex_ListRecords_Limit(t *testing.T) { defer ri.Close() // Add 5 records - for i := 0; i < 5; i++ { + for i := range 5 { rkey := string(rune('a' + i)) if err := ri.IndexRecord("io.atcr.hold.crew", rkey, "cid-"+rkey); err != nil { t.Fatalf("IndexRecord() error = %v", err) @@ -473,10 +473,10 @@ func TestRecordsIndex_Count(t *testing.T) { defer ri.Close() // Add records to two collections - for i := 0; i < 3; i++ { + for i := range 3 { ri.IndexRecord("io.atcr.hold.crew", string(rune('a'+i)), "cid1") } - for i := 0; i < 5; i++ { + for i := range 5 { ri.IndexRecord("io.atcr.hold.captain", string(rune('a'+i)), "cid2") } diff --git a/pkg/hold/pds/server.go b/pkg/hold/pds/server.go index 1541de4..19f54e8 100644 --- a/pkg/hold/pds/server.go +++ b/pkg/hold/pds/server.go @@ -103,8 +103,7 @@ func NewHoldPDS(ctx context.Context, did, publicURL, dbPath, keyPath string, ena // Uses same database as carstore for simplicity var recordsIndex *RecordsIndex if dbPath != ":memory:" { - recordsDbPath := dbPath + "/db.sqlite3" - recordsIndex, err = NewRecordsIndex(recordsDbPath) + recordsIndex, err = NewRecordsIndex(dbPath + "/db.sqlite3") if err != nil { return nil, fmt.Errorf("failed to create records index: %w", err) } diff --git a/pkg/hold/pds/status_test.go b/pkg/hold/pds/status_test.go index 1227096..c58a07a 100644 --- a/pkg/hold/pds/status_test.go +++ b/pkg/hold/pds/status_test.go @@ -232,7 +232,7 @@ func contains(s, substr string) bool { } func findSubstring(s, substr string) bool { - for i := 0; i <= len(s)-len(substr); i++ { + for i := range len(s) - len(substr) + 1 { if s[i:i+len(substr)] == substr { return true } diff --git a/pkg/hold/pds/xrpc_test.go b/pkg/hold/pds/xrpc_test.go index a5724b0..64152df 100644 --- a/pkg/hold/pds/xrpc_test.go +++ b/pkg/hold/pds/xrpc_test.go @@ -609,7 +609,7 @@ func TestHandleListRecords_Pagination(t *testing.T) { // Note: Bootstrap already added 1 crew member // Add 4 more for a total of 5 - for i := 0; i < 4; i++ { + for i := range 4 { _, err := handler.pds.AddCrewMember(ctx, "did:plc:member"+string(rune(i+'0')), "reader", []string{"blob:read"}) if err != nil { t.Fatalf("Failed to add crew member: %v", err) @@ -673,7 +673,7 @@ func TestHandleListRecords_Reverse(t *testing.T) { holdDID := "did:web:hold.example.com" // Add crew members - for i := 0; i < 3; i++ { + for i := range 3 { _, err := handler.pds.AddCrewMember(ctx, "did:plc:member"+string(rune(i+'0')), "reader", []string{"blob:read"}) if err != nil { t.Fatalf("Failed to add crew member: %v", err) @@ -888,7 +888,7 @@ func TestHandleListRecords_Indexed_Pagination(t *testing.T) { holdDID := "did:web:hold.example.com" // Add 4 more crew members for total of 5 - for i := 0; i < 4; i++ { + for i := range 4 { _, err := handler.pds.AddCrewMember(ctx, fmt.Sprintf("did:plc:member%d", i), "reader", []string{"blob:read"}) if err != nil { t.Fatalf("Failed to add crew member: %v", err) @@ -968,7 +968,7 @@ func TestHandleListRecords_Indexed_Reverse(t *testing.T) { holdDID := "did:web:hold.example.com" // Add crew members - for i := 0; i < 3; i++ { + for i := range 3 { _, err := handler.pds.AddCrewMember(ctx, fmt.Sprintf("did:plc:member%d", i), "reader", []string{"blob:read"}) if err != nil { t.Fatalf("Failed to add crew member: %v", err) diff --git a/pkg/hold/quota/config.go b/pkg/hold/quota/config.go index 528068e..3a10e41 100644 --- a/pkg/hold/quota/config.go +++ b/pkg/hold/quota/config.go @@ -1,3 +1,4 @@ +// Package quota provides storage quota management for hold services. package quota import ( diff --git a/pkg/logging/logger_test.go b/pkg/logging/logger_test.go index 03b4e3f..ea9c69e 100644 --- a/pkg/logging/logger_test.go +++ b/pkg/logging/logger_test.go @@ -366,7 +366,7 @@ func BenchmarkInitLogger(b *testing.B) { defer slog.SetDefault(originalLogger) b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { InitLogger("info") } } @@ -376,7 +376,7 @@ func BenchmarkSetupTestLogger(b *testing.B) { defer slog.SetDefault(originalLogger) b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { cleanup := SetupTestLogger() cleanup() }