refactor(consolidation): delete dead packages/handlers + unscoped magic footguns (bookshelf-9snmz.1.3) #1255
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "bd-bookshelf-9snmz.1.3"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Deletes four clusters of dead code (scoped to avoid overlap with sibling PR #1254 which already removed hardcoversync.SyncUserBooks/pushBooks and shelves.ListBooks):
internal/versionpackage (~37 LOC deleted) — self-admitted placeholder;main.versionvia-ldflagsis the real version source. Removed fromUNIT_PKGSandcheck-coverage.sh.Dead admin-users list handler (~66 LOC deleted) —
GET /admin/usersis a 301 redirect in production;adminUsersListHandler/parseListParams/buildUserListRows/adminUsersPageDataand related constants are dead.AdminUserListRowpreserved (used bysettings/shell_handler.go). Updatedexport_test.goto omit the dead route.Dead
startupHooksmachinery ininternal/app(~15 LOC deleted) — field declared and slice allocated, but no hook was ever appended; the loop iterated an empty slice on every startup. Pure dead weight.Unscoped shelf/magic query paths (~108 LOC deleted) — security footguns — production wires only the
*Scopedvariants; the unscoped paths bypass per-user library scoping:magic.CountBooks+buildMagicShelfCountQuery(unscoped;CountBooksScopedis sole prod caller)magic.ListBooksForMagicShelf+buildMagicShelfQuery(unscoped;ListBooksForMagicShelfScopedis sole prod caller)magic.EncodeAdvSearch(no production callers;DecodeAdvSearchis live)magic.ValidOperator(no production callers;ValidFieldOperatoris live)All companion tests deleted with their symbols. Added tests for branches previously covered by deleted
books_test.go(clampBooksLimitbounds,tr.Joins,afterID > 0,rows.Err()).Test plan
make coveragepasses (100% gate, zero uncovered statement blocks)make lintclean for changed packagesgo build ./...succeedsCloses bead bookshelf-9snmz.1.3 on merge.
Code Review: PR #1255 (Deletion PR Safety)
Summary
This PR safely removes 4 unscoped magic-shelf query functions (CountBooks, ListBooksForMagicShelf, EncodeAdvSearch, ValidOperator), a dead admin users list handler, the internal/version package, and the startupHooks machinery. It adds 6 new coverage tests covering branches in the surviving Scoped variants.
Verification Results
Deleted Symbol Caller Analysis — ALL ZERO PRODUCTION CALLERS ✓
CountBooksScoped(ContentRestrictions). No prod callers. ✓Preserved Symbols — CORRECTLY RETAINED ✓
internal/settings/shell_handler.gofor admin users enriched with permission counts. ✓Coverage Exclusions — CORRECT ✓
./internal/version/...removed from UNIT_PKGS line. ✓./internal/version/...removed from coverage unit-test list. ✓New Coverage Tests — LEGIT (NOT PADDING) ✓
All 6 new tests in
list_books_for_magic_shelf_scoped_test.gocover real branches previously untested:defaultBooksLimitbranch.maxBooksLimitcap.All tests use black-box testing (invoke
ListBooksForMagicShelfScopedvia public interface, inspect captured SQL). Each asserts real behavior, not just line coverage.Test File Organization — CLEAN ✓
books_test.gofully deleted (tested unscoped functions). ✓operators_test.gofully deleted (tested ValidOperator). ✓EncodeAdvSearchtests deleted fromadvsearch_test.go. ✓admin_handler_test.gofully deleted (tested adminUsersListHandler). ✓version_suite_test.go+ 22-lineversion_test.gofully deleted. ✓list_books_for_magic_shelf_scoped_test.go. ✓Test Exports — ACCURATE ✓
mux.Handle("GET /admin/users", ...)route fromExportRegisterAdminHandlersForTest. Docstring updated to reflect that the list is now a 301 redirect in the Settings shell. ✓REVIEW VERDICT: 0 blocker, 0 major, 0 minor
The PR is safe for merge. All deletions have zero production callers, the coverage tests are legitimate and cover real branches, and the exclusion updates are correct and complete.
Security re-review — PR #1251 (concurrent-accept TOCTOU MAJOR)
Verified
git diff origin/main...origin/bd-bookshelf-t582g.7.The concurrent-accept clobbering MAJOR is CLOSED. Finalize now uses a non-clobbering
os.Link(failsEEXISTwhen the dest name already exists —os.Linkdoes not follow a symlink at the target and never write-through-clobbers) with a bounded re-uniquify retry (finalizeWithRetry, review_service.go:695-740). Two concurrent accepts of same-base-named proposals can no longer both land on the same path: the link is the atomic exclusive claim; the race loser getsEEXISTand advances to the next(N)suffix. Confirmed viainternal/app/build_extended_deps.go:1806wiringLinkFile: os.Linkand the EEXIST-retry test (review_service_test.go:2051-2110).Checklist against the four points:
os.Link+EEXIST is the mutual-exclusion primitive; the winner's file is never overwritten.os.CreateTemp(destDir,...)inside the confineddestDir; every link candidate isfilepath.Join(destDir, base+"(N)"+ext)off afilepath.Base'd name with a numeric suffix. No separators, no.., no follow-through.[MAJOR] internal/bookdrop/review_service.go:998 — DB records the pre-finalize filename; EEXIST-retry path leaves a dangling book_file reference
The TX records
FileName: safeFileName/FileSubPath: fileSubPath(review_service.go:955-957), computed byuniquifyDestPathBEFORE the TX (line 876).finalizeWithRetryruns AFTER the commit (line 998) and, onEEXIST, advances the on-disk path to a different suffix (e.g. DB saysnovel.epubbut the file links tonovel (2).epub— exactly the path the EEXIST-retry test asserts, review_service_test.go:2106-2107). Result in the concurrent-race path: the committedbook_filerow points at a path that does not exist, and the actual file is orphaned on disk (a rescan may re-import it as a duplicate). This is the security fix trading a clobber for a dangling reference — the winner's data is safe (so no security escalation), but it is a real data-integrity regression on the very race this PR fixes. Fix: capture the final linked path/name returned fromfinalizeWithRetryand reconcile thebook_filerow (updatefile_name/file_sub_path) after finalize, or move the link before the TX and record the actually-claimed name. The existing test masks this by stubbingupsertBookFileas a no-op — add an assertion that the storedFileNameequals the finally-linked name in the EEXIST-retry case.[MINOR] internal/bookdrop/review_service.go:997 —
LinkFilehas no nil-default despite the doc claiming oneThe doc comment (review_service.go:272) says "Defaults to os.Link when nil," but
linkFn := p.LinkFileis passed straight intofinalizeWithRetrywith noif linkFn == nil { linkFn = os.Link }guard (contrastStatFile/MkdirAll, which are defaulted). Production wiring passesos.Linkso this is not exploitable, but a nil would panic and the code/doc disagree. Add the nil-default to match the contract.REVIEW VERDICT: 0 blocker, 1 major, 1 minor
Security Review — PR #1255 (bd-bookshelf-9snmz.1.3)
Dead-code deletion:
internal/version, dead admin-users list handler,startupHooks, and 4 unscoped magic-shelf query paths. Reviewedgit diff origin/main...origin/bd-bookshelf-9snmz.1.3. This deletion is security-positive — it removes per-user-scoping footguns. All three focus questions check out.Verification summary:
CountBooks,ListBooksForMagicShelf,buildMagicShelfCountQuery,buildMagicShelfQuery,EncodeAdvSearch,ValidOperatorare all deleted. No qualified (magic.CountBooks() or in-package call remains. Production wiring ininternal/shelves/magic/wire.gouses only the scoped variants:ListBooksForMagicShelfScoped(line 54) andCountBooksScoped(line 55). The handlerDeps.CountBooksfield is a different symbol (a struct field bound toCountBooksScoped), not the deleted package func — no collision. No unscoped footgun path survives. Surviving*Scopedfuncs remain tested;go build ./internal/shelves/magic/...passes.GET /admin/usersis not dropped —routes.go:70now serves anadminRequired-wrapped 301 redirect to/settings/users. The write routes remainadminRequired-wrapped.AdminUserListRow+ListUsersPermissionsare preserved and consumed by the live Settings Users tab (internal/settings/shell_handler.go:616). No permission gate lost.go buildofinternal/{shelves/magic,users,settings,app}all pass.internal/versionfully removed fromMakefileUNIT_PKGS andscripts/check-coverage.sh.startupHooksfield + Run() loop removed cleanly with no remaining appender.Findings
[MINOR] internal/users/admin_handler.go:30 (+ internal/users/wire.go:187) — dead
AdminDeps.ListUsersfieldThe
ListUsersfield's only consumer (adminUsersListHandler) was deleted, but the field remains in the struct and is still populated inwire.go:187. It compiles (field assignment, not a call), so no build break and no footgun (the live Settings list path uses settings' ownListAdminUsers). Remove the now-unusedAdminDeps.ListUsersfield and its wire.go assignment to finish the cleanup.[MINOR] templates/pages/admin_users.html — orphaned template
Its only production reference was the deleted
adminUsersListHandler(remaining grep hit is a test file). The live users list now renders via the Settings shell template. Delete the orphaned template.[MINOR] internal/shelves/magic/operators.go:142 — stale doc-comment reference to deleted
ValidOperatorValidFieldOperator's comment says "Unlike ValidOperator it consults…" butValidOperatorno longer exists. Reword to drop the dangling reference.[MINOR] internal/app/app.go:779 — stale comment referencing deleted
CountBooksComment reads "…guard produces 1=0 and CountBooks returns 0" but the unscoped
CountBooksis deleted; the code path usesCountBooksScoped. Update the comment.REVIEW VERDICT: 0 blocker, 0 major, 4 minor
6a1f14e7866be16b0d9a