refactor: unify anilist module contracts

This commit is contained in:
jxxghp
2026-08-24 01:45:49 +08:00
parent 903d1d3c4d
commit 488b3667bb
3 changed files with 159 additions and 76 deletions
+120 -76
View File
@@ -2348,79 +2348,91 @@
},
"module_method_specs": {
"anilist_credits": {
"aggregation": "legacy",
"aggregation": "ordered_list_merge",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListMediaPageRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"result_shape": "any",
"required_parameters": [
"anilist_id",
"count",
"page"
],
"result_contract": "list[MediaPerson]",
"result_shape": "list",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
"version": 1
},
"anilist_discover": {
"aggregation": "legacy",
"aggregation": "ordered_list_merge",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListDiscoverArguments",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"result_shape": "any",
"result_contract": "list[MediaInfo]",
"result_shape": "list",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
"version": 1
},
"anilist_info": {
"aggregation": "legacy",
"aggregation": "first_non_empty",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListMediaRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"result_shape": "any",
"required_parameters": [
"anilist_id"
],
"result_contract": "dict | None",
"result_shape": "mapping",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
"version": 1
},
"anilist_person_credits": {
"aggregation": "legacy",
"aggregation": "ordered_list_merge",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListPersonPageRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"result_shape": "any",
"required_parameters": [
"count",
"page",
"person_id"
],
"result_contract": "list[MediaInfo]",
"result_shape": "list",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
"version": 1
},
"anilist_person_detail": {
"aggregation": "legacy",
"aggregation": "first_non_empty",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListPersonRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"required_parameters": [
"person_id"
],
"result_contract": "MediaPerson | None",
"result_shape": "any",
"supports_async": true,
"supports_sync": true,
@@ -2428,48 +2440,58 @@
"version": 1
},
"anilist_popular_this_season": {
"aggregation": "legacy",
"aggregation": "ordered_list_merge",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListPageRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"result_shape": "any",
"required_parameters": [
"count",
"page"
],
"result_contract": "list[MediaInfo]",
"result_shape": "list",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
"version": 1
},
"anilist_recommendations": {
"aggregation": "legacy",
"aggregation": "ordered_list_merge",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListMediaPageRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"result_shape": "any",
"required_parameters": [
"anilist_id",
"count",
"page"
],
"result_contract": "list[MediaInfo]",
"result_shape": "list",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
"version": 1
},
"anilist_trending": {
"aggregation": "legacy",
"aggregation": "ordered_list_merge",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListPageRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"result_shape": "any",
"required_parameters": [
"count",
"page"
],
"result_contract": "list[MediaInfo]",
"result_shape": "list",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
@@ -2495,79 +2517,91 @@
"version": 1
},
"async_anilist_credits": {
"aggregation": "legacy",
"aggregation": "ordered_list_merge",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListMediaPageRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"result_shape": "any",
"required_parameters": [
"anilist_id",
"count",
"page"
],
"result_contract": "list[MediaPerson]",
"result_shape": "list",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
"version": 1
},
"async_anilist_discover": {
"aggregation": "legacy",
"aggregation": "ordered_list_merge",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListDiscoverArguments",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"result_shape": "any",
"result_contract": "list[MediaInfo]",
"result_shape": "list",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
"version": 1
},
"async_anilist_info": {
"aggregation": "legacy",
"aggregation": "first_non_empty",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListMediaRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"result_shape": "any",
"required_parameters": [
"anilist_id"
],
"result_contract": "dict | None",
"result_shape": "mapping",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
"version": 1
},
"async_anilist_person_credits": {
"aggregation": "legacy",
"aggregation": "ordered_list_merge",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListPersonPageRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"result_shape": "any",
"required_parameters": [
"count",
"page",
"person_id"
],
"result_contract": "list[MediaInfo]",
"result_shape": "list",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
"version": 1
},
"async_anilist_person_detail": {
"aggregation": "legacy",
"aggregation": "first_non_empty",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListPersonRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"required_parameters": [
"person_id"
],
"result_contract": "MediaPerson | None",
"result_shape": "any",
"supports_async": true,
"supports_sync": true,
@@ -2575,48 +2609,58 @@
"version": 1
},
"async_anilist_popular_this_season": {
"aggregation": "legacy",
"aggregation": "ordered_list_merge",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListPageRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"result_shape": "any",
"required_parameters": [
"count",
"page"
],
"result_contract": "list[MediaInfo]",
"result_shape": "list",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
"version": 1
},
"async_anilist_recommendations": {
"aggregation": "legacy",
"aggregation": "ordered_list_merge",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListMediaPageRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"result_shape": "any",
"required_parameters": [
"anilist_id",
"count",
"page"
],
"result_contract": "list[MediaInfo]",
"result_shape": "list",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
"version": 1
},
"async_anilist_trending": {
"aggregation": "legacy",
"aggregation": "ordered_list_merge",
"error_policy": "isolate_provider",
"execution": "sync_or_async",
"family": "anilist",
"input_contract": "AniListKeywordArguments",
"input_contract": "AniListPageRequest",
"plugin_short_circuit": true,
"public_to_plugins": true,
"required_parameters": [],
"result_contract": "AniListProviderResult",
"result_shape": "any",
"required_parameters": [
"count",
"page"
],
"result_contract": "list[MediaInfo]",
"result_shape": "list",
"supports_async": true,
"supports_sync": true,
"timeout_policy": "caller_budget",
+23
View File
@@ -374,6 +374,29 @@ def test_sync_and_async_bangumi_capabilities_share_contracts() -> None:
assert contract.aggregation is expected
def test_sync_and_async_anilist_capabilities_share_contracts() -> None:
"""AniList 同步与异步 provider 应共享列表或首值契约。"""
list_methods = {
"anilist_credits",
"anilist_discover",
"anilist_person_credits",
"anilist_popular_this_season",
"anilist_recommendations",
"anilist_trending",
}
value_methods = {"anilist_info", "anilist_person_detail"}
for sync_method in list_methods | value_methods:
contract = get_module_method_contract(sync_method)
assert contract is get_module_method_contract(f"async_{sync_method}")
expected = (
ModuleResultAggregation.ORDERED_LIST_MERGE
if sync_method in list_methods
else ModuleResultAggregation.FIRST_NON_EMPTY
)
assert contract.aggregation is expected
def test_attachment_result_diagnostics_distinguish_bytes_and_strings() -> None:
"""附件契约应区分二进制内容和可展示字符串,偏差仍仅供诊断。"""
assert diagnose_module_result("download_qq_file_bytes", b"content") == ()