Repository navigation
test(importer): cover remove on import for qBittorrent and Transmission (#2046) - #2943
Conversation
…on (#2046) The removal code shipped in #2713 was never executed by a test. These drive it against fake qBittorrent and Transmission daemons and pin the contract: one removal per import, keyed on the info hash, never asking the client to delete the payload, sent only after the row is imported, and skipped when the toggle is off, the import failed, or the row still holds a legacy Transmission number. A refused removal is logged and leaves the import alone. Both qBittorrent "already in library" shortcuts are covered as well as the normal import. The db tests round trip remove_on_import through Create, Update and every getter, rebuild the pre 090 schema to show an existing client upgrades with the toggle off, and check an unreadable value is an error. No behaviour change and no bug found. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016fJcCVbNnKsmj2MAAMwWj9 Signed-off-by: vavallee <vavallee@protonmail.com>
There was a problem hiding this comment.
Test-only, no behaviour change — looks solid overall.
One gap vs. the PR description: TestDownloadClientRepo_UnreadableRemoveOnImportIsAnError tests four read paths (List, ListEnabled, GetEnabledByProtocol, GetByID) but skips GetFirstEnabled and GetFirstEnabledByProtocol. Both scan remove_on_import as int (download_clients.go:219, download_clients.go:245), so a text value in that column would error there too. The PR description says "a scan error in every read path, not a silent false" — the claim slightly overstates coverage. Two extra assertions at the bottom of that test would close it.
Everything else checks out: mutexes on both fake daemons, t.Cleanup restoring the global logger, migration 090_download_client_remove_on_import.sql confirmed present, all referenced helpers and production functions exist, and the legacy-numeric-id guard matches RemoveTransmissionTorrent's strconv.ParseInt check at adapter.go:356.
— 🤖 Bindery triage bot (automated). Reply to correct me; a human will see it.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
Remove torrent after import (#2046, shipped in #2713) had no test that actually ran the removal. This adds them. Test only, no behaviour change, no bug found.
importer (
internal/importer/scanner_remove_on_import_test.go), against fake qBittorrent and Transmission daemons:checkQbittorrentDownloads: exactly one/torrents/deletefor the hash withdeleteFiles=false. The fake reads the DB when the delete arrives and sees the row alreadyimportedwith the file in the library. Default import mode (auto, so hardlink here) leaves the source file in place.importedwith no error message, the library file stays, and acleanup failedwarning names the hash and the 500.importFailed, no delete.torrent-removewithids: [<info hash>]and nodelete-local-data(the client only sends that key when it is true), sent after the import committed. Toggle off: none.RemoveTransmissionTorrentrefuses the number, the daemon never sees atorrent-remove, and the refusal is logged.importFailed, no removal.db (
internal/db/download_clients_remove_on_import_test.go):RemoveOnImporttrue and false through Create, Update (flipped both ways), GetByID, List, ListEnabled, GetEnabledByProtocol, GetFirstEnabled and GetFirstEnabledByProtocol.remove_on_importis a scan error in every read path, not a silent false.Fail before checks, run locally and reverted: flipping
deleteFilesto true in both cleanups fails 4 subtests, and moving the shortcut cleanup ahead of theimportedwrite fails both shortcut subtests.No changelog fragment: nothing in
.github/workflowschecks for one, and these are tests only.Covered lines
go test ./internal/importer/ ./internal/db/ -coverprofile, before is origin/main at d34e906. The db baseline was taken without the new db test file. Counts are set mode, so 0 means never run and 1 means run.Package totals: importer 85.0% to 85.3%, db 72.0% to 72.4%.
Test plan
go build ./...go vet ./...go test ./internal/importer/... ./internal/db/... ./internal/downloader/... -count=1go test -race ./internal/importer/ ./internal/db/ -run RemoveOnImport -count=1🤖 Generated with Claude Code
https://claude.ai/code/session_016fJcCVbNnKsmj2MAAMwWj9