nnb9: black-box internal/library tests (bookshelf-nnb9.13) #1439
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "bd-bookshelf-nnb9.13"
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?
Removes internal/library/export_test.go (the package library re-export
shim) and re-covers every unexported branch it exposed by driving the
public HTTP surface (buildMux + RegisterRoutes) instead of exported
wrapper funcs.
saveLibraryNamingPatternHandler, previewLibraryNamingPatternHandler,
and libraryMatchWeightsDeps' CheckLibraryExists are now exercised via
real requests through buildMux(deps).
exercised via GET/PUT /libraries/{id}/metadata-field-priority.
to fold genuinely-unreachable switch-fallback branches into the last
case as
default(n is always 1-4; key is always one of the fixedlibraryFieldDefs keys), removing dead code instead of white-box
testing it.
scripts/test_policy_check/allowlist.txt.
Scope: internal/library only. internal/library/scan
(batch_seed_internal_test.go) is a separate bead (bookshelf-nnb9.14),
not touched here.
Test plan:
wire.go, which is already excluded from the coverage gate)
Closes bead bookshelf-nnb9.13 on merge.
Removes internal/library/export_test.go (the package library re-export shim) and re-covers every unexported branch it exposed by driving the public HTTP surface (buildMux + RegisterRoutes) instead: - healthHandler, getLibraryNamingPatternHandler, saveLibraryNamingPatternHandler, previewLibraryNamingPatternHandler, and libraryMatchWeightsDeps' CheckLibraryExists are now exercised via real requests through buildMux(deps) rather than exported wrapper funcs. - buildLibraryFieldPriorityMatrix and applyLibraryMatrixUpdate are now exercised via GET/PUT /libraries/{id}/metadata-field-priority. Also simplifies fpSlotStr/getSettingsFieldProvider/getSettingsEnabledField to fold their genuinely-unreachable switch-fallback branches (n is always 1-4; key is always one of the fixed libraryFieldDefs keys) into the last case as `default`, removing dead code instead of white-box-testing it. Deletes the internal/library/export_test.go line from scripts/test_policy_check/allowlist.txt. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016tRKybTpfjQ4SxmNdVFLHiAdversarial security review — PR #1439 (bookshelf-nnb9.13)
Reviewed the full diff (
origin/main...origin/bd-bookshelf-nnb9.13). Confirmed this is genuinely a test-only refactor:internal/library/export_test.godeleted; all remaining test files ininternal/librarydeclarepackage library_test(black-box only) — no white-box test files remain, consistent with the allowlist line removal inscripts/test_policy_check/allowlist.txt.internal/library/field_priority.go. The change is a behavior-preserving cleanup: threeswitchstatements (getSettingsFieldProvider,getSettingsEnabledField,fpSlotStr) had their final explicitcasereplaced withdefault:plus a comment explaining the switch is exhaustive over the call sites (libraryFieldDefsfixed keys / literal slot ints 1-4, never user-supplied). Verified callers (buildLibraryFieldRows) only ever pass keys from the fixedlibraryFieldDefstable and literal1..4— key/n are never request-supplied, so removing the unreachablereturn nil/return ""fallthrough does not change behavior or introduce a reachable different code path. No scoping, ownership, DISK_TYPE, or path-validation logic was touched.Keyand anunknown tokenvalidation error string).No findings.
REVIEW VERDICT: 0 blocker, 0 major, 0 minor
Adversarial review of PR #1439 (bookshelf-nnb9.13) — internal/library white-box→black-box conversion.
Verified (anti-gaming checks per dispatch instructions):
No new exported symbols:
export_test.go(90 lines) deleted outright; noExport*shim functions or type aliases were added anywhere else in the diff.library.Depsfields used by the new tests (CheckHealth,GetUserLibraryIDs,GetLibraryNamingPattern,UpdateLibraryNamingPattern,ValidateNamingTemplate,PreviewNamingPattern,LoadGlobalFieldPriority,LoadLibraryFieldPriority) were already public pre-PR (confirmed no new exported identifiers ininternal/library/*.goproduction files).Re-covering tests are real, not self-validating:
health_handler_test.go,naming_pattern_handler_test.go,field_priority_test.go,handler_test.go(match-weights block) all now route throughbuildMux(deps)+ realhttptest.Server, exercising the actual registered HTTP routes end-to-end instead of calling an exported handler-constructor directly.field_priority_test.go's new PUT tests (savedOv/savedID) are captured inside the stubbedUpdateLibraryFieldPrioritydep, which is only invoked by the real production handler — not set by the test itself. Genuine production-path exercise.FpSlotStr/GetSettingsFieldProvider/GetSettingsEnabledField"unknown key" tests correspond to unexported branches that were legitimately deleted as dead code (see #5 below), so removing their now-unreachable-branch tests is correct, not a coverage loss.All
internal/library/*_test.go(non-scan) files arepackage library_test. Confirmed viagit showon every test file in the branch — no leftoverpackage library.internal/library/scan/batch_seed_internal_test.go(package scan) is untouched, correctly out of scope for this bead.scripts/test_policy_check/allowlist.txtdiff removes exactly one line,internal/library/export_test.go; theinternal/library/scan/batch_seed_internal_test.goline is untouched/intact.Production-code changes are limited to
internal/library/field_priority.go:getSettingsFieldProvider,getSettingsEnabledField, andfpSlotStreach had their explicitcase "rating"/case 4converted todefault, removing the trailing unreachablereturn nil/return "". Verified this is safe:getSettingsFieldProvider/getSettingsEnabledFieldhave exactly two call sites, both inbuildLibraryFieldRows, driven only bydef.keyfrom the fixedlibraryFieldDefsslice (never external/request input) — confirmed via grep, only 2 call sites total.fpSlotStrcall sites are the 4 literalfpSlotStr(fp, 1..4)calls. The separate, PUT-facingsetSettingsFieldProvider/setSettingsEnabledField(which DO take externalkeyvalues from the request body and must no-op on unknown keys) were NOT touched by this PR — their existing implicit no-op default is unchanged, and the new "body with all field keys ... plus an unrecognized key" test infield_priority_test.gocorrectly exercises that unchanged no-op path. No behavior change for any reachable caller.Minor observations (do not block):
[MINOR] internal/library/handler_test.go:2041-2043 — the converted "GET /libraries/{id}/match-weights"
It("calls the Get dep and returns 200 when library exists", ...)has two separateExpectcalls (Expect(getCalled).To(BeTrue())andExpect(resp.StatusCode).To(Equal(http.StatusOK))) instead of one. Fold into a singleExpect(getCalled, resp.StatusCode).To(...)-style compound assertion or split into twoIts per project convention (project-conventions.md → Test structure: "exactly ONE Expect per It").REVIEW VERDICT: 0 blocker, 0 major, 1 minor
Adversarial security review of PR #1435 (bookshelf-v3bi0).
Scope:
static/js/controllers/bookdrop_file_editor_controller.js+ its Vitest spec only — thebookdrop:metadatacopiedCustomEvent now dispatches on save success instead of optimistically.Findings:
[MINOR] static/js/controllers/bookdrop_file_editor_controller.js:433 —
_pendingDispatchCopyis a per-controller instance flag, not per-fieldWhen a copy-triggered save collides with an in-flight save and a second
_doSavecall queues behind it (_savePendingAfterInflight),_pendingDispatchCopyis OR'd across whichever calls queued in that window (ctrl._pendingDispatchCopy || !!dispatchCopyEvent). This is a UI-correctness nit (the review row could auto-check slightly earlier/later than the exact field that succeeded), not a security issue — no cross-user or cross-proposal leak, sinceproposalIdValueon the dispatched event is scoped to the mounted controller's own row. No fix required before merge; flag only if the review-row auto-check behavior is later found flaky under rapid-copy usage.Security assessment:
innerHTMLtouched; the eventdetail.proposalIdis echoed from an already-renderedproposalIdValueback into a same-page CustomEvent, never re-inserted into markup.REVIEW VERDICT: 0 blocker, 0 major, 1 minor