diff --git a/app/chain/transfer/settlement.py b/app/chain/transfer/settlement.py index 7967f01ae..18bdbaa9e 100644 --- a/app/chain/transfer/settlement.py +++ b/app/chain/transfer/settlement.py @@ -744,7 +744,8 @@ class TransferSettlementOwner(_TransferOwnerBase): ) -> bool: """确认种子下载完成;查询失败或缺失时记录原因,不把未知状态当作完成。""" try: - torrents = self.list_torrents(hashs=download_hash, downloader=downloader) + # Hash 已唯一定位任务;工作流自定义标签或调整 TORRENT_TAG 后的任务也要能回写。 + torrents = self.list_torrents(hashs=download_hash, downloader=downloader, include_all_tags=True) if not torrents: logger.warning( f"下载器 {downloader} 中未查询到种子 {download_hash},无法回写已整理标签,请检查种子是否已移除或历史关联是否正确" diff --git a/tests/test_transfer_mark_torrent_completed.py b/tests/test_transfer_mark_torrent_completed.py index eae4c50bf..7c3b2b70c 100644 --- a/tests/test_transfer_mark_torrent_completed.py +++ b/tests/test_transfer_mark_torrent_completed.py @@ -141,6 +141,23 @@ def test_mark_tags_when_torrent_completed(): assert completed == [{"hashs": "hash1", "downloader": "qbittorrent"}] +def test_mark_queries_torrent_by_hash_regardless_of_builtin_tag(): + """按 Hash 回写时不得受 TORRENT_TAG 过滤,否则工作流自定义标签的任务永远无法打上已整理标签。""" + chain = _make_chain() + completed = [] + queries = [] + chain.transfer_completed = lambda **kwargs: completed.append(kwargs) + chain.list_torrents = lambda **kwargs: queries.append(kwargs) or ( + [SimpleNamespace(progress=100)] if kwargs.get("include_all_tags") else [] + ) + _finish_task(chain, _make_task(1, "hash1", "qbittorrent")) + + _mark(chain, "hash1", "qbittorrent") + + assert queries == [{"hashs": "hash1", "downloader": "qbittorrent", "include_all_tags": True}] + assert completed == [{"hashs": "hash1", "downloader": "qbittorrent"}] + + def test_mark_short_circuits_downloader_query_when_jobview_not_done(): """作业视图还有未结束任务时,不应产生任何下载器查询。""" chain = _make_chain()