refactor: type downloader action contracts

This commit is contained in:
jxxghp
2026-08-24 01:11:47 +08:00
parent f37407d0f3
commit 14e70208a2
4 changed files with 107 additions and 30 deletions
+61 -29
View File
@@ -3740,15 +3740,23 @@
"version": 1
},
"download": {
"aggregation": "legacy",
"aggregation": "first_non_empty",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "downloader",
"input_contract": "DownloaderKeywordArguments",
"input_contract": "DownloadTaskRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "DownloaderProviderResult",
"required_parameters": [
"category",
"content",
"cookie",
"download_dir",
"downloader",
"episodes",
"label"
],
"result_contract": "DownloadTaskResult | None",
"result_shape": "any",
"supports_async": true,
"supports_sync": true,
@@ -5014,16 +5022,20 @@
"version": 1
},
"remove_torrents": {
"aggregation": "legacy",
"aggregation": "first_non_empty",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "downloader",
"input_contract": "DownloaderKeywordArguments",
"input_contract": "TorrentRemoveRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "DownloaderProviderResult",
"result_shape": "any",
"required_parameters": [
"delete_file",
"downloader",
"hashs"
],
"result_contract": "bool | None",
"result_shape": "boolean",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
@@ -5228,16 +5240,20 @@
"version": 1
},
"set_torrents_tag": {
"aggregation": "legacy",
"aggregation": "first_non_empty",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "downloader",
"input_contract": "DownloaderKeywordArguments",
"input_contract": "TorrentTagRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "DownloaderProviderResult",
"result_shape": "any",
"required_parameters": [
"downloader",
"hashs",
"tags"
],
"result_contract": "bool | None",
"result_shape": "boolean",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
@@ -5282,32 +5298,38 @@
"version": 1
},
"start_torrents": {
"aggregation": "legacy",
"aggregation": "first_non_empty",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "downloader",
"input_contract": "DownloaderKeywordArguments",
"input_contract": "TorrentControlRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "DownloaderProviderResult",
"result_shape": "any",
"required_parameters": [
"downloader",
"hashs"
],
"result_contract": "bool | None",
"result_shape": "boolean",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
"version": 1
},
"stop_torrents": {
"aggregation": "legacy",
"aggregation": "first_non_empty",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "downloader",
"input_contract": "DownloaderKeywordArguments",
"input_contract": "TorrentControlRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "DownloaderProviderResult",
"result_shape": "any",
"required_parameters": [
"downloader",
"hashs"
],
"result_contract": "bool | None",
"result_shape": "boolean",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
@@ -5784,16 +5806,26 @@
"version": 1
},
"update_torrent": {
"aggregation": "legacy",
"aggregation": "first_non_empty",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "downloader",
"input_contract": "DownloaderKeywordArguments",
"input_contract": "TorrentUpdateRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "DownloaderProviderResult",
"result_shape": "any",
"required_parameters": [
"category",
"download_limit",
"downloader",
"hash_string",
"ratio_limit",
"save_path",
"seeding_time_limit",
"tracker_list",
"upload_limit"
],
"result_contract": "dict[str, bool] | None",
"result_shape": "mapping",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
+36
View File
@@ -178,6 +178,42 @@ def test_torrent_tracker_contract_merges_downloader_mappings() -> None:
assert contract.result_shape is ModuleResultShape.MAPPING
def test_downloader_action_contracts_freeze_shared_provider_signatures() -> None:
"""三种宿主下载器的目标选择动作应使用一致的首个非空契约。"""
expected_parameters = {
"download": (
"content",
"download_dir",
"cookie",
"episodes",
"category",
"label",
"downloader",
),
"remove_torrents": ("hashs", "delete_file", "downloader"),
"set_torrents_tag": ("hashs", "tags", "downloader"),
"start_torrents": ("hashs", "downloader"),
"stop_torrents": ("hashs", "downloader"),
"update_torrent": (
"hash_string",
"downloader",
"download_limit",
"upload_limit",
"tracker_list",
"save_path",
"category",
"ratio_limit",
"seeding_time_limit",
),
}
for method, parameters in expected_parameters.items():
contract = get_module_method_contract(method)
assert contract.family == "downloader"
assert contract.aggregation is ModuleResultAggregation.FIRST_NON_EMPTY
assert contract.required_parameters == parameters
def test_attachment_result_diagnostics_distinguish_bytes_and_strings() -> None:
"""附件契约应区分二进制内容和可展示字符串,偏差仍仅供诊断。"""
assert diagnose_module_result("download_qq_file_bytes", b"content") == ()