refactor: remove dead code across server, templ pages, and client modules

Deadcode-verified removals (RTA reachability from main, cross-checked
with -test and textual xrefs):

Go server:
- whole files: middleware/transaction.go, middleware/error_handler.go,
  middleware/password_validator.go (live registration machinery kept),
  handlers/sync.go, sync/offline.go
- unrouted endpoints: auth UpdateUsername/UpdateEmail, timezone
  settings handler, OPDS RegisterOPDS, Kobo LibrarySync handler,
  ReaderHandler.ShowReader, JSON-data twins on collections/library
- duplicate book-matching handlers (book_matching.go Handler twins,
  matching.go MatchingHandler twins), superseded helpers
  (router.parseUUID, handlers.ValidateDeviceToken, normalizePath,
  userExists, generateLockID)

Templ/client:
- never-routed pages: api_explorer.templ, queue.templ and their
  client modules api-explorer.ts, api-explorer-docs.ts, queue.ts
- fully orphaned wrapper modules events.ts, dom.ts
- broken clearSyncQueue (called a nonexistent endpoint) and the
  hidden, never-populated sync-queue section on the devices page
- 166+ unused exports demoted to private (knip-verified); ~85 truly
  dead declarations removed via tsc noUnusedLocals fixpoint
- stale 'interactive API Explorer' claims dropped from docs

The docs drift-gate package (internal/docs), templ-bound modules
(dashboard, stats, header, index, login, profile*, bookshelf,
collections, toast-error), sqlc-generated code, and web/static are
intentionally untouched.
This commit is contained in:
John O'Keefe committed 2026-10-25 11:06:08 -04:00
1 parent 8733e83f1f
commit 8631aa00bf
107 files changed
+689 -3443

No files matched your search

-102
View File
@@ -1,89 +1,20 @@
package main
import (
"bookhoard/internal/database"
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
"sync"
"testing"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// Helper functions for database verification and test utilities
// These functions reduce code duplication and ensure consistent database state verification
// verifyDeviceCreated verifies a device exists in database with expected values
func verifyDeviceCreated(t *testing.T, db *database.Queries, deviceID uuid.UUID, expectedName, expectedType, expectedIdentifier string) {
pgDeviceID := pgtype.UUID{Bytes: [16]byte(deviceID), Valid: true}
device, err := db.GetDevice(context.Background(), pgDeviceID)
require.NoError(t, err, "Device should exist in database")
assert.Equal(t, expectedName, device.DeviceName, "Device name should match")
assert.Equal(t, expectedType, device.DeviceType, "Device type should match")
assert.Equal(t, expectedIdentifier, device.DeviceIdentifier, "Device identifier should match")
assert.NotEmpty(t, device.AuthToken, "Device should have auth token")
}
// verifyDeviceDeleted verifies a device does not exist in database
func verifyDeviceDeleted(t *testing.T, db *database.Queries, deviceID uuid.UUID) {
pgDeviceID := pgtype.UUID{Bytes: [16]byte(deviceID), Valid: true}
_, err := db.GetDevice(context.Background(), pgDeviceID)
assert.Error(t, err, "Device should be deleted from database")
}
// verifyUserField verifies a user has expected field value in database
func verifyUserField(t *testing.T, db *database.Queries, userID uuid.UUID, field string, expected interface{}) {
pgUserID := pgtype.UUID{Bytes: [16]byte(userID), Valid: true}
user, err := db.GetUser(context.Background(), pgUserID)
require.NoError(t, err, "User should exist in database")
switch field {
case "email":
if em, ok := expected.(string); ok {
assert.Equal(t, em, user.Email, "Email should match")
}
case "first_name":
if fn, ok := expected.(string); ok {
assert.Equal(t, fn, user.FirstName.String, "First name should match")
}
case "last_name":
if ln, ok := expected.(string); ok {
assert.Equal(t, ln, user.LastName.String, "Last name should match")
}
case "username":
if un, ok := expected.(string); ok {
assert.Equal(t, un, user.Username, "Username should match")
}
case "theme":
if th, ok := expected.(string); ok {
assert.Equal(t, th, user.Theme.String, "Theme should match")
}
}
}
// verifyMediaItemInDB verifies a media item exists in database
func verifyMediaItemInDB(t *testing.T, db *database.Queries, mediaID uuid.UUID) {
pgMediaID := pgtype.UUID{Bytes: [16]byte(mediaID), Valid: true}
_, err := db.GetMediaItem(context.Background(), pgMediaID)
require.NoError(t, err, "Media item should exist in database")
}
// verifyMediaItemDeleted verifies a media item does not exist in database
func verifyMediaItemDeleted(t *testing.T, db *database.Queries, mediaID uuid.UUID) {
pgMediaID := pgtype.UUID{Bytes: [16]byte(mediaID), Valid: true}
_, err := db.GetMediaItem(context.Background(), pgMediaID)
assert.Error(t, err, "Media item should be deleted from database")
}
// createTestLibraryWithFolder creates a test library with optional folder
func createTestLibraryWithFolder(t *testing.T, ts *httptest.Server, token, name string, withFolder bool) string {
libReq := map[string]interface{}{
@@ -141,36 +72,3 @@ func createTestLibraryWithFolder(t *testing.T, ts *httptest.Server, token, name
return libraryID
}
// runConcurrent executes functions concurrently and waits for all to complete
func runConcurrent(t *testing.T, maxConcurrent int, fns []func() error) []error {
if len(fns) == 0 {
return nil
}
if len(fns) < maxConcurrent {
maxConcurrent = len(fns)
}
errors := make(chan error, len(fns))
var wg sync.WaitGroup
for i := 0; i < maxConcurrent; i++ {
wg.Add(1)
go func(idx int) {
defer wg.Done()
if err := fns[idx](); err != nil {
errors <- err
}
}(i)
}
wg.Wait()
close(errors)
var allErrors []error
for err := range errors {
allErrors = append(allErrors, err)
}
return allErrors
}