fix(tests): test-created devices and fixture dirs now meet the cleanup contract

Test suites that attach devices to the SHARED admin (testuser, the live
dev account) escaped the harness sweeps whenever their names lacked
"test": createContractDeviceNamed named its devices by surface type
("koreader" — the web progress push adopts the device name as sync
source, so conflict tests drive a second named source without a
separate account), the reinstall regression test uses the web flow's
real "Reinstall Device" label, and opds_test.go's folders test named
its device "OPDS Folders Device". None had self-cleanup either, so
every suite run left 3 more rows on the dev account's device grid —
476 by the time anyone looked. TestDeviceSetup.CreateDevice also never
cleanup-registered, so any CURRENT or future helper-created device was
one rename away from the same leak.

Changes:
- TestDeviceSetup.CreateDevice self-deletes its row at test end
  (t.Cleanup): callers owe nothing to name hygiene any more.
- createContractDeviceNamed self-deletes likewise (contract-% prefix).
- device_test.go: core via cleanupDeviceByIdentifier on every device it
  attaches to the admin ("Reinstall Device" by unique identifier —
  the NAME is user-facing-labeled, sweeps must never torch it).
- Harness setup-time admin-device sweep gains the unambiguous harness
  patterns (dev_contract_* tokens, contract-%/opds-%/repro-reinstall-%
  identifiers) as the drift net; ran once with the rebuilt tests image
  and that sweep alone already purged the existing 476 rows.
- metadata_write_test.go now globs ALL test-metadata-write-* dirs in
  its RemoveAll instead of only its own pid's — killed runs left root-
  owned dirs on the user's uploads bind mount (7 found, deleted).

 audits: collections/saved-filters/libraries/sync_queue are clean;
 the only "test"-named media rows left are scans of the user's own
 on-disk test files (Test/, Bookhoard Test/, embedded " test" in two
 real books' metadata) — content, not suite debris.

Verified: filtered runs (contract/OPDS/reinstall/pairing/metadata)
green, zero device residue after the run, uploads mount clean.
This commit is contained in:
John O'Keefe committed 2026-11-02 17:39:29 -05:00
1 parent 0c31e9b88d
commit 7d88ec5184
5 files changed
+68 -4

No files matched your search

+9
View File
@@ -287,6 +287,15 @@ Test-created data rules (harness cleanup depends on them): users use
`@tests.bookhoard.internal` / `@example.com` emails, libraries and
collections carry "test"-prefixed names, and cleanups delete test
libraries (cascades handle the rest) rather than table-wide deletes.
Devices attach to the per-run regular user when it doesn't matter, or
self-delete via `TestDeviceSetup.CreateDevice` / `createContractDevice`
/ `cleanupDeviceByIdentifier` when they attach to the shared admin —
names lacking "test" (device-type names like "koreader", the
"Reinstall Device" label) escaped the name sweeps for weeks and piled
476 rows onto the live dev account; every suite now cleans its own
rows at test end, with the harness sweep's identifier/token patterns
(`contract-%`, `opds-folders-%`, `repro-reinstall-%`,
`dev_contract_*`) as the drift net.
### Media Fixtures (audio/books)