mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-12-02 00:46:27 +08:00
Merge pull request #7414 from gi29734401/agent/moviepilot/dfe0f538fb50ccf0
fix(transfer): 智能助手识别成功但文件仍无法整理
This commit is contained in:
@@ -6130,7 +6130,7 @@
|
||||
"title": "Episode"
|
||||
},
|
||||
"media_id": {
|
||||
"description": "经媒体查询核实的来源原生 ID",
|
||||
"description": "经媒体查询核实并与 media_source 原样配对的来源原生 ID,重新规划时直接按该身份识别",
|
||||
"minLength": 1,
|
||||
"title": "Media Id",
|
||||
"type": "string"
|
||||
@@ -6140,7 +6140,7 @@
|
||||
"description": "元数据来源标识,保留与 media_id 一同返回的精确值。"
|
||||
},
|
||||
"media_type": {
|
||||
"description": "经核实的电影或电视剧类型",
|
||||
"description": "经核实的电影或电视剧类型,须与该来源原生 ID 对应",
|
||||
"enum": [
|
||||
"movie",
|
||||
"tv"
|
||||
|
||||
@@ -314,9 +314,20 @@ if TYPE_CHECKING:
|
||||
episode_group: Optional[str] = None,
|
||||
obtain_images: bool = False,
|
||||
music_type: Optional[str] = None,
|
||||
*,
|
||||
media_id: Optional[str] = None,
|
||||
) -> Optional[MediaInfo]:
|
||||
"""
|
||||
同步识别元数据并在需要时回退插件。
|
||||
|
||||
:param metainfo: 保留季集信息的标题解析结果
|
||||
:param mtype: 上游已核实的媒体类型
|
||||
:param media_source: 请求级识别来源
|
||||
:param episode_group: 需要保留的剧集组
|
||||
:param obtain_images: 是否补充媒体图片
|
||||
:param music_type: 音乐实体类型约束
|
||||
:param media_id: 已核实的来源原生标识,提供时直接按身份识别
|
||||
:return: 符合身份与类型约束的媒体信息,未命中时返回 None
|
||||
"""
|
||||
...
|
||||
|
||||
@@ -328,9 +339,20 @@ if TYPE_CHECKING:
|
||||
episode_group: Optional[str] = None,
|
||||
obtain_images: bool = False,
|
||||
music_type: Optional[str] = None,
|
||||
*,
|
||||
media_id: Optional[str] = None,
|
||||
) -> Optional[MediaInfo]:
|
||||
"""
|
||||
异步识别元数据并在需要时回退插件。
|
||||
|
||||
:param metainfo: 保留季集信息的标题解析结果
|
||||
:param mtype: 上游已核实的媒体类型
|
||||
:param media_source: 请求级识别来源
|
||||
:param episode_group: 需要保留的剧集组
|
||||
:param obtain_images: 是否补充媒体图片
|
||||
:param music_type: 音乐实体类型约束
|
||||
:param media_id: 已核实的来源原生标识,提供时直接按身份识别
|
||||
:return: 符合身份与类型约束的媒体信息,未命中时返回 None
|
||||
"""
|
||||
...
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ from app.domain.meta.metabase import MetaBase
|
||||
from app.domain.meta.metamusic import MetaMusic
|
||||
from app.runtime.cache import async_fresh, fresh
|
||||
from app.runtime.log import logger
|
||||
from app.schemas.media import resolve_media_identity
|
||||
from app.schemas.types import (
|
||||
MUSIC_ENTITY_RECORDING,
|
||||
ChainEventType,
|
||||
@@ -86,6 +87,7 @@ class _MetaRecognitionRequest:
|
||||
:param share_meta: 供共享识别与插件使用的元数据副本
|
||||
:param mtype: 调用方指定的媒体类型,None 时由元数据和来源决定
|
||||
:param media_source: 显式指定的媒体来源,None 时选择默认来源
|
||||
:param media_id: 已核实的来源原生标识,None 时允许按标题和插件优先级识别
|
||||
:param episode_group: 电视剧识别使用的剧集组标识,None 表示未指定
|
||||
:param music_type: 音乐实体类型,None 时由元数据或默认规则选择
|
||||
:param is_music: 是否按音乐识别协议处理本次请求
|
||||
@@ -96,6 +98,7 @@ class _MetaRecognitionRequest:
|
||||
share_meta: MetaBase
|
||||
mtype: Optional[MediaType]
|
||||
media_source: Optional[MediaSource]
|
||||
media_id: Optional[str]
|
||||
episode_group: Optional[str]
|
||||
music_type: Optional[str]
|
||||
is_music: bool
|
||||
@@ -240,11 +243,20 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
*,
|
||||
mtype: Optional[MediaType],
|
||||
media_source: Optional[MediaSource],
|
||||
media_id: Optional[str],
|
||||
episode_group: Optional[str],
|
||||
music_type: Optional[str],
|
||||
) -> _MetaRecognitionRequest:
|
||||
"""
|
||||
为同步与异步标题识别冻结相同的元数据副本和来源语义。
|
||||
|
||||
:param metainfo: 保留原始季集信息的标题解析结果
|
||||
:param mtype: 上游已核实的媒体类型
|
||||
:param media_source: 请求级身份来源,须与显式 media_id 配对
|
||||
:param media_id: 已核实的来源原生标识,None 时执行标题识别
|
||||
:param episode_group: 需要保留的剧集组
|
||||
:param music_type: 显式音乐实体类型
|
||||
:return: 本次识别共享的冻结请求及原始元数据副本
|
||||
"""
|
||||
return _MetaRecognitionRequest(
|
||||
title=metainfo.title or "",
|
||||
@@ -252,6 +264,7 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
share_meta=deepcopy(metainfo),
|
||||
mtype=mtype,
|
||||
media_source=media_source,
|
||||
media_id=media_id,
|
||||
episode_group=episode_group,
|
||||
music_type=music_type,
|
||||
is_music=mtype == MediaType.MUSIC or isinstance(metainfo, MetaMusic),
|
||||
@@ -278,9 +291,24 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
) -> Optional[MediaInfo]:
|
||||
"""
|
||||
统一识别结果的空值判定与成功日志,图片补充留给各 I/O 外壳。
|
||||
|
||||
显式指定身份时,插件补充结果也必须与已核实的来源、标识及媒体类型一致。
|
||||
|
||||
:param request: 包含已核实身份与类型约束的识别请求
|
||||
:param mediainfo: 原生识别或辅助识别返回的候选
|
||||
:return: 符合请求约束的媒体信息,无结果或身份冲突时返回 None
|
||||
"""
|
||||
if not mediainfo:
|
||||
return None
|
||||
if request.media_id is not None:
|
||||
expected_identity = resolve_media_identity(
|
||||
media_source=request.media_source, media_id=request.media_id,
|
||||
)
|
||||
identity_matches = all(expected_identity) and resolve_media_identity(media=mediainfo) == expected_identity
|
||||
type_matches = request.mtype is None or mediainfo.type == request.mtype
|
||||
if not (identity_matches and type_matches):
|
||||
logger.warning(f"{request.title} 识别结果与已核实的媒体身份或类型不一致")
|
||||
return None
|
||||
logger.info(
|
||||
f"{request.title} 识别到媒体信息:"
|
||||
f"{(mediainfo.type or MediaType.UNKNOWN).value} {mediainfo.title_year}"
|
||||
@@ -295,6 +323,8 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
obtain_images: bool = False,
|
||||
mtype: Optional[MediaType] = None,
|
||||
music_type: Optional[str] = None,
|
||||
*,
|
||||
media_id: Optional[str] = None,
|
||||
) -> Optional[MediaInfo]:
|
||||
"""
|
||||
根据主副标题识别媒体信息
|
||||
@@ -305,11 +335,14 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
:param obtain_images: 是否补充图片
|
||||
:param mtype: 上游已确定的媒体类型
|
||||
:param music_type: 音乐实体类型,用于约束显式音乐身份及插件结果
|
||||
:param media_id: 已核实的来源原生标识,须与 media_source 配对,提供时直接按身份识别
|
||||
:return: 符合身份与类型约束的媒体信息,未命中时返回 None
|
||||
"""
|
||||
mediainfo = self._recognize_with_fallback_by_meta(
|
||||
metainfo=metainfo,
|
||||
mtype=mtype,
|
||||
media_source=media_source,
|
||||
media_id=media_id,
|
||||
episode_group=episode_group,
|
||||
obtain_images=obtain_images,
|
||||
music_type=music_type,
|
||||
@@ -326,6 +359,8 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
episode_group: Optional[str] = None,
|
||||
obtain_images: bool = False,
|
||||
music_type: Optional[str] = None,
|
||||
*,
|
||||
media_id: Optional[str] = None,
|
||||
) -> Optional[MediaInfo]:
|
||||
"""
|
||||
根据标题识别媒体信息,必要时回退到辅助识别。
|
||||
@@ -336,6 +371,7 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
:param episode_group: 剧集组
|
||||
:param obtain_images: 是否补充图片
|
||||
:param music_type: 音乐实体类型,用于约束显式音乐身份及插件结果
|
||||
:param media_id: 已核实的来源原生标识,提供时由原生识别校验身份并跳过标题辅助识别
|
||||
:return: 统一媒体信息
|
||||
"""
|
||||
if not metainfo:
|
||||
@@ -344,6 +380,7 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
metainfo,
|
||||
mtype=mtype,
|
||||
media_source=media_source,
|
||||
media_id=media_id,
|
||||
episode_group=episode_group,
|
||||
music_type=music_type,
|
||||
)
|
||||
@@ -356,6 +393,7 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
meta=request.metainfo,
|
||||
mtype=request.mtype,
|
||||
media_source=request.media_source,
|
||||
media_id=request.media_id,
|
||||
share_meta=request.share_meta,
|
||||
episode_group=request.episode_group,
|
||||
music_type=request.music_type,
|
||||
@@ -376,19 +414,22 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
music_type=request.music_type,
|
||||
)
|
||||
|
||||
# 按 config 中设置的识别顺序识别,影视与音乐共用同一选择流程
|
||||
mediainfo = self.select_recognize_source(
|
||||
log_name=request.title,
|
||||
log_context=request.title,
|
||||
native_fn=native_recognize,
|
||||
plugin_fn=plugin_recognize,
|
||||
is_recognized=(
|
||||
MediaRecognitionOwner._music_recognition_is_terminal
|
||||
if request.is_music
|
||||
else None
|
||||
),
|
||||
plugin_event=request.plugin_event,
|
||||
)
|
||||
# 已核实身份直接查询,防止标题辅助识别覆盖来源、标识或季集。
|
||||
if request.media_id is not None:
|
||||
mediainfo = native_recognize()
|
||||
else:
|
||||
mediainfo = self.select_recognize_source(
|
||||
log_name=request.title,
|
||||
log_context=request.title,
|
||||
native_fn=native_recognize,
|
||||
plugin_fn=plugin_recognize,
|
||||
is_recognized=(
|
||||
MediaRecognitionOwner._music_recognition_is_terminal
|
||||
if request.is_music
|
||||
else None
|
||||
),
|
||||
plugin_event=request.plugin_event,
|
||||
)
|
||||
mediainfo = MediaRecognitionOwner._accepted_recognition(request, mediainfo)
|
||||
if mediainfo is None:
|
||||
return None
|
||||
@@ -407,6 +448,8 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
obtain_images: bool = False,
|
||||
mtype: Optional[MediaType] = None,
|
||||
music_type: Optional[str] = None,
|
||||
*,
|
||||
media_id: Optional[str] = None,
|
||||
) -> Optional[MediaInfo]:
|
||||
"""
|
||||
根据主副标题识别媒体信息(异步版本)
|
||||
@@ -417,12 +460,14 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
:param obtain_images: 是否补充图片
|
||||
:param mtype: 上游已确定的媒体类型
|
||||
:param music_type: 音乐实体类型,用于约束显式音乐身份及插件结果
|
||||
:param media_id: 已核实的来源原生标识,须与 media_source 配对,提供时直接按身份识别
|
||||
:return: 统一媒体信息
|
||||
"""
|
||||
mediainfo = await self._async_recognize_with_fallback_by_meta(
|
||||
metainfo=metainfo,
|
||||
mtype=mtype,
|
||||
media_source=media_source,
|
||||
media_id=media_id,
|
||||
episode_group=episode_group,
|
||||
obtain_images=obtain_images,
|
||||
music_type=music_type,
|
||||
@@ -439,6 +484,8 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
episode_group: Optional[str] = None,
|
||||
obtain_images: bool = False,
|
||||
music_type: Optional[str] = None,
|
||||
*,
|
||||
media_id: Optional[str] = None,
|
||||
) -> Optional[MediaInfo]:
|
||||
"""
|
||||
异步根据标题识别媒体信息,必要时回退到辅助识别。
|
||||
@@ -449,6 +496,7 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
:param episode_group: 剧集组
|
||||
:param obtain_images: 是否补充图片
|
||||
:param music_type: 音乐实体类型,用于约束显式音乐身份及插件结果
|
||||
:param media_id: 已核实的来源原生标识,提供时由原生识别校验身份并跳过标题辅助识别
|
||||
:return: 统一媒体信息
|
||||
"""
|
||||
if not metainfo:
|
||||
@@ -457,6 +505,7 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
metainfo,
|
||||
mtype=mtype,
|
||||
media_source=media_source,
|
||||
media_id=media_id,
|
||||
episode_group=episode_group,
|
||||
music_type=music_type,
|
||||
)
|
||||
@@ -469,6 +518,7 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
meta=request.metainfo,
|
||||
mtype=request.mtype,
|
||||
media_source=request.media_source,
|
||||
media_id=request.media_id,
|
||||
share_meta=request.share_meta,
|
||||
episode_group=request.episode_group,
|
||||
music_type=request.music_type,
|
||||
@@ -489,19 +539,22 @@ class MediaRecognitionOwner(_MediaOwnerBase):
|
||||
music_type=request.music_type,
|
||||
)
|
||||
|
||||
# 按 config 中设置的识别顺序识别,影视与音乐共用同一选择流程
|
||||
mediainfo = await self.async_select_recognize_source(
|
||||
log_name=request.title,
|
||||
log_context=request.title,
|
||||
native_fn=native_recognize,
|
||||
plugin_fn=plugin_recognize,
|
||||
is_recognized=(
|
||||
MediaRecognitionOwner._music_recognition_is_terminal
|
||||
if request.is_music
|
||||
else None
|
||||
),
|
||||
plugin_event=request.plugin_event,
|
||||
)
|
||||
# 显式身份与同步入口保持相同的直查和失败语义。
|
||||
if request.media_id is not None:
|
||||
mediainfo = await native_recognize()
|
||||
else:
|
||||
mediainfo = await self.async_select_recognize_source(
|
||||
log_name=request.title,
|
||||
log_context=request.title,
|
||||
native_fn=native_recognize,
|
||||
plugin_fn=plugin_recognize,
|
||||
is_recognized=(
|
||||
MediaRecognitionOwner._music_recognition_is_terminal
|
||||
if request.is_music
|
||||
else None
|
||||
),
|
||||
plugin_event=request.plugin_event,
|
||||
)
|
||||
mediainfo = MediaRecognitionOwner._accepted_recognition(request, mediainfo)
|
||||
if mediainfo is None:
|
||||
return None
|
||||
|
||||
@@ -505,6 +505,10 @@ class TransferExecutionOwner(_TransferOwnerBase):
|
||||
options: dict[str, Any] = {"obtain_images": True}
|
||||
if task.media_source:
|
||||
options["media_source"] = task.media_source
|
||||
# 已核实的来源原生标识必须随识别下传,否则只能按标题搜索,
|
||||
# 拼音或错名文件会在重新规划后再次识别失败。
|
||||
if task.media_source and task.media_id:
|
||||
options["media_id"] = task.media_id
|
||||
if task.mtype:
|
||||
options["mtype"] = task.mtype
|
||||
info = MediaChain().recognize_by_meta(task.meta, **options)
|
||||
|
||||
@@ -230,8 +230,11 @@ class TransferHistoryReplanRequest(RequiredMediaIdentityMixin, BaseModel):
|
||||
task_id: str = Field(min_length=1, description="接管上下文中的原始持久任务标识,必须与历史绑定一致")
|
||||
settlement_revision: int = Field(ge=1, description="接管上下文中的原始结算版本,拒绝分析期间已变化的任务")
|
||||
media_source: MediaSource = Field(description="经媒体查询核实的身份来源")
|
||||
media_id: str = Field(min_length=1, description="经媒体查询核实的来源原生 ID")
|
||||
media_type: Literal["movie", "tv"] = Field(description="经核实的电影或电视剧类型")
|
||||
media_id: str = Field(
|
||||
min_length=1,
|
||||
description="经媒体查询核实并与 media_source 原样配对的来源原生 ID,重新规划时直接按该身份识别",
|
||||
)
|
||||
media_type: Literal["movie", "tv"] = Field(description="经核实的电影或电视剧类型,须与该来源原生 ID 对应")
|
||||
season: Optional[int] = Field(default=None, ge=0, description="修正后的季号,0 为特别篇;为空时保留原值")
|
||||
episode: Optional[int] = Field(default=None, ge=1, description="修正后的单集集号;为空时保留原集数范围")
|
||||
|
||||
|
||||
@@ -851,7 +851,7 @@ flowchart LR
|
||||
| 指标 | 当前值 |
|
||||
|---|---:|
|
||||
| Python 模块 | 1166 |
|
||||
| 内部导入边 | 10,168 |
|
||||
| 内部导入边 | 10,169 |
|
||||
| 非平凡 SCC | 1(29 个模块的 TMDB vendor 精确 containment) |
|
||||
| Application / Chain 具体 Adapter 直连 | 0 / 0 |
|
||||
| Direct egress | 51(精确 policy 准入,Application / Chain 均为 0) |
|
||||
|
||||
@@ -285,6 +285,8 @@ JSON 使用十进制字符串避免浏览器数字精度丢失,客户端应原
|
||||
整理失败的 AI 接管应先读取 `transfer.history` 并核实媒体身份;对持久化任务使用
|
||||
`transfer.history.replan` 提交 `history_id`、接管时的 `task_id`/`settlement_revision`、`media_source`、`media_id`、`media_type`
|
||||
以及可选的 `season`/`episode`。该操作只接受没有文件副作用的识别拒绝,保留原任务、失败证据、结算回执和重试预算;排队受理不代表文件已经整理完成。
|
||||
`history_id` 放入 `path_params`,其余修正字段放入 `body`。预览与重新规划必须保留
|
||||
同一组已核实的来源、原生标识、媒体类型及季集,重新识别会直接查询该身份。
|
||||
|
||||
认证补充:
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ if str(PROJECT_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(PROJECT_ROOT))
|
||||
|
||||
# 与对应 SKILL.md 同步维护,重新生成不能回退用户同步所需的版本。
|
||||
MOVIEPILOT_API_SKILL_VERSION = "73"
|
||||
MOVIEPILOT_API_SKILL_VERSION = "74"
|
||||
DATABASE_OPERATION_SKILL_VERSION = "18"
|
||||
|
||||
|
||||
@@ -305,6 +305,13 @@ _MEDIA_TYPE_FIELD_VALUES: dict[tuple[str, str, str], str] = {
|
||||
# OpenAPI 无法表达的操作级 Agent 指引,在生成时追加到操作参数组之后,
|
||||
# 保证运行中的 Skill 包含这些指引,无需手动修改生成的 api/*.md。
|
||||
_OPERATION_NOTES: dict[str, list[str]] = {
|
||||
"transfer.history.replan": [
|
||||
"- `path_params.history_id` 使用本次失败历史 ID,`body.task_id` 和 `body.settlement_revision` "
|
||||
"原样保留接管上下文中的任务与结算版本。",
|
||||
"- `body.media_source`、`body.media_id`、`body.media_type` 必须来自同一次核实的媒体身份。"
|
||||
"重新规划会清空旧识别结果,再按该身份直接查询,预览与提交使用同一身份及季集。",
|
||||
"- 受理后通过 `transfer.history` 核实整理结果,受理或排队仅表示任务等待执行。",
|
||||
],
|
||||
"transfer.history.register": [
|
||||
"- **Completed external work only:** Register a completed copy, native local hard link, or move; "
|
||||
"this operation only writes history and never moves files, scrapes metadata, or changes downloads.",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: moviepilot-api
|
||||
version: 73
|
||||
version: 74
|
||||
description: >-
|
||||
Use this skill for MoviePilot product operations such as media search, torrent
|
||||
search, downloads, subscriptions, library checks, sites, storage, workflows,
|
||||
|
||||
@@ -130,7 +130,10 @@ Purpose: 为没有文件副作用的识别失败历史提交已核实的电影
|
||||
Identity scope: `admin`; required role: `system_admin`.
|
||||
- `path_params`: `history_id*` (integer): 历史查询操作返回的持久化整理或订阅历史标识。
|
||||
- `query`: none
|
||||
- `body`: `episode` (integer|null): 修正后的单集集号;为空时保留原集数范围; `media_id*` (string; minimum length `1`): 经媒体查询核实的来源原生 ID; `media_source*` (MediaSource): 元数据来源标识,保留与 media_id 一同返回的精确值。; `media_type*` (string(movie,tv)): 经核实的电影或电视剧类型; `season` (integer|null): 修正后的季号,0 为特别篇;为空时保留原值; `settlement_revision*` (integer; minimum `1.0`): 接管上下文中的原始结算版本,拒绝分析期间已变化的任务; `task_id*` (string; minimum length `1`): 接管上下文中的原始持久任务标识,必须与历史绑定一致
|
||||
- `body`: `episode` (integer|null): 修正后的单集集号;为空时保留原集数范围; `media_id*` (string; minimum length `1`): 经媒体查询核实并与 media_source 原样配对的来源原生 ID,重新规划时直接按该身份识别; `media_source*` (MediaSource): 元数据来源标识,保留与 media_id 一同返回的精确值。; `media_type*` (string(movie,tv)): 经核实的电影或电视剧类型,须与该来源原生 ID 对应; `season` (integer|null): 修正后的季号,0 为特别篇;为空时保留原值; `settlement_revision*` (integer; minimum `1.0`): 接管上下文中的原始结算版本,拒绝分析期间已变化的任务; `task_id*` (string; minimum length `1`): 接管上下文中的原始持久任务标识,必须与历史绑定一致
|
||||
- `path_params.history_id` 使用本次失败历史 ID,`body.task_id` 和 `body.settlement_revision` 原样保留接管上下文中的任务与结算版本。
|
||||
- `body.media_source`、`body.media_id`、`body.media_type` 必须来自同一次核实的媒体身份。重新规划会清空旧识别结果,再按该身份直接查询,预览与提交使用同一身份及季集。
|
||||
- 受理后通过 `transfer.history` 核实整理结果,受理或排队仅表示任务等待执行。
|
||||
|
||||
### `transfer.manual_history`
|
||||
`POST /api/v1/transfer/manual/history`; policy effect: `safe_read`.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: transfer-failed-retry
|
||||
version: 6
|
||||
version: 7
|
||||
description: >-
|
||||
Analyze failed MoviePilot transfers, verify media identity and season/episode,
|
||||
and safely replan durable recognition rejections while preserving task identity,
|
||||
@@ -49,3 +49,29 @@ Use structured `moviepilot_api` operations only; discover their current schemas.
|
||||
8. Report verified corrections, accepted/queued replans, confirmed transfer
|
||||
successes, and remaining blockers accurately. A queued replan is not a
|
||||
completed transfer. Never reset or remove failure/retry evidence.
|
||||
|
||||
## 重新规划输入
|
||||
|
||||
将失败历史 ID 放在 `path_params.history_id`,将原任务与结算版本放在 `body`。
|
||||
`media_source`、`media_id` 和 `media_type` 必须使用同一次媒体查询核实的值,
|
||||
预览与重新规划保留相同的身份及季集。`media_type` 使用 `movie` 或 `tv`。
|
||||
重新规划会清空旧识别结果并按提交的来源原生标识直接查询。
|
||||
收到受理结果后,用 `transfer.history` 核实该条历史的最终状态。
|
||||
|
||||
以下示例的历史 ID、任务标识、结算版本和媒体身份均须替换为本次查询的实际值。
|
||||
|
||||
```json
|
||||
{
|
||||
"operation_id": "transfer.history.replan",
|
||||
"path_params": {"history_id": 123},
|
||||
"body": {
|
||||
"task_id": "task-from-analysis-context",
|
||||
"settlement_revision": 1,
|
||||
"media_source": "themoviedb",
|
||||
"media_id": "117061",
|
||||
"media_type": "tv",
|
||||
"season": 2,
|
||||
"episode": 3
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -963,8 +963,8 @@
|
||||
"runtime_only": true
|
||||
}
|
||||
},
|
||||
"edge_count": 10168,
|
||||
"edge_sha256": "0d18e0059a0e92f3505b0fe57704f69f4c67a2571b70e64ed36ab89840dd386e",
|
||||
"edge_count": 10169,
|
||||
"edge_sha256": "cc3ba1dd8781800999f526a56f051b8241bca9d4f0284e1deca7686464fc2bd7",
|
||||
"edges": [
|
||||
"app -> app.foundation",
|
||||
"app -> app.foundation.environment",
|
||||
@@ -5162,6 +5162,7 @@
|
||||
"app.chain.media.recognition -> app.runtime.cache",
|
||||
"app.chain.media.recognition -> app.runtime.log",
|
||||
"app.chain.media.recognition -> app.schemas",
|
||||
"app.chain.media.recognition -> app.schemas.media",
|
||||
"app.chain.media.recognition -> app.schemas.types",
|
||||
"app.chain.media.search -> app.chain",
|
||||
"app.chain.media.search -> app.chain.media",
|
||||
|
||||
@@ -130,10 +130,10 @@ def test_modified_builtin_skills_have_incremented_versions() -> None:
|
||||
"database-operation": "18",
|
||||
"feedback-issue": "12",
|
||||
"anysearch": "3",
|
||||
"moviepilot-api": "73",
|
||||
"moviepilot-api": "74",
|
||||
"moviepilot-update": "7",
|
||||
"organize-files": "6",
|
||||
"transfer-failed-retry": "6",
|
||||
"transfer-failed-retry": "7",
|
||||
"generate-identifiers": "4",
|
||||
"create-moviepilot-plugin": "7",
|
||||
"create-moviepilot-skill": "3",
|
||||
|
||||
@@ -27,7 +27,8 @@ from app.application.transfer.workflow import (
|
||||
TransferPlanCheckpoint,
|
||||
TransferPlanningInput,
|
||||
)
|
||||
from app.chain.transfer.execution import _DurableTransferStepRunner
|
||||
from app.chain.media import MediaChain
|
||||
from app.chain.transfer.execution import TransferExecutionOwner, _DurableTransferStepRunner
|
||||
from app.chain.transfer.facade import TransferChain
|
||||
from app.db.adapters.chain import TransactionalChainDurableEventWriter
|
||||
from app.db.adapters.transfer.admission import TransactionalTransferAdmissionRepository
|
||||
@@ -36,6 +37,7 @@ from app.db.models.transferexecutionstep import TransferExecutionStep
|
||||
from app.db.models.transferhistory import TransferHistory
|
||||
from app.db.models.transferpending import TransferPending
|
||||
from app.db.models.transfersettlementreceipt import TransferSettlementReceipt
|
||||
from app.domain.context import MediaInfo
|
||||
from app.domain.meta.metavideo import MetaVideo
|
||||
from app.schemas.file import FileItem
|
||||
from app.schemas.history import TransferHistoryReplanRequest
|
||||
@@ -126,7 +128,7 @@ def _correct(executions, history_id, task_id):
|
||||
)
|
||||
|
||||
|
||||
def test_replan_preserves_identity_evidence_budget_and_replays_correct_season(replan_store, tmp_path):
|
||||
def test_replan_preserves_identity_evidence_budget_and_replays_correct_season(replan_store, tmp_path, monkeypatch):
|
||||
"""
|
||||
修正重启后仍使用同一任务与预算,并从 accepted 输入恢复正确身份和 S02E03。
|
||||
"""
|
||||
@@ -176,6 +178,18 @@ def test_replan_preserves_identity_evidence_budget_and_replays_correct_season(re
|
||||
assert task.meta.begin_season == 2 and task.meta.begin_episode == 3
|
||||
assert task.target_path.as_posix() == planning.target_path
|
||||
assert task.transfer_type == 'copy'
|
||||
# 从真实修正、进程恢复和入队结果继续识别,覆盖原生标识完整下传。
|
||||
media_chain = MediaChain()
|
||||
expected = MediaInfo(media_source=MediaSource.TMDB, media_id='117061', type=MediaType.TV)
|
||||
native_recognize = Mock(return_value=expected)
|
||||
monkeypatch.setattr(media_chain, 'recognize_media', native_recognize)
|
||||
monkeypatch.setattr(media_chain, 'obtain_images', Mock())
|
||||
assert TransferExecutionOwner._recognize_task_meta(task, restore_history=False) is expected
|
||||
assert native_recognize.call_args.kwargs['media_source'] is MediaSource.TMDB
|
||||
assert native_recognize.call_args.kwargs['media_id'] == '117061'
|
||||
assert native_recognize.call_args.kwargs['mtype'] is MediaType.TV
|
||||
recognized_meta = native_recognize.call_args.kwargs['meta']
|
||||
assert recognized_meta.begin_season == 2 and recognized_meta.begin_episode == 3
|
||||
admissions.release_claim(task_id=claimed.task_id, lease_token=replay.lease_token)
|
||||
|
||||
|
||||
|
||||
237
tests/test_transfer_replan_recognition_identity.py
Normal file
237
tests/test_transfer_replan_recognition_identity.py
Normal file
@@ -0,0 +1,237 @@
|
||||
"""
|
||||
验证整理重新识别时下传已核实的来源原生标识。
|
||||
|
||||
智能助手核实媒体身份与季集后,重新规划会写入 media_source/media_id 并清空旧识别结果。
|
||||
若重新识别只按标题搜索,拼音文件名或错名文件会再次识别失败,重新规划等于白做。
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
|
||||
import pytest
|
||||
|
||||
from app.agent.api.arguments import canonical_api_arguments
|
||||
from app.agent.tools.impl.api import MoviePilotApiTool
|
||||
from app.chain.media import MediaChain
|
||||
from app.chain.media import plugin as media_plugin
|
||||
from app.chain.transfer import execution as transfer_execution
|
||||
from app.chain.transfer.execution import TransferExecutionOwner
|
||||
from app.domain.context import MediaInfo
|
||||
from app.domain.meta.metavideo import MetaVideo
|
||||
from app.schemas.types import MediaSource, MediaType
|
||||
|
||||
|
||||
def _capture_recognition(monkeypatch) -> dict:
|
||||
"""
|
||||
替换媒体链,记录重新识别实际收到的参数。
|
||||
"""
|
||||
captured = {}
|
||||
|
||||
class _FakeMediaChain:
|
||||
"""
|
||||
记录识别调用的伪媒体链。
|
||||
"""
|
||||
|
||||
def recognize_by_meta(self, meta, **options):
|
||||
"""
|
||||
保存元数据与识别选项,不返回媒体信息。
|
||||
"""
|
||||
captured["meta"] = meta
|
||||
captured["options"] = options
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(transfer_execution, "MediaChain", _FakeMediaChain)
|
||||
return captured
|
||||
|
||||
|
||||
def _task(**overrides) -> SimpleNamespace:
|
||||
"""
|
||||
构造只带识别所需字段的整理任务。
|
||||
"""
|
||||
task = SimpleNamespace(
|
||||
meta=SimpleNamespace(name="yongzhe de mingzi S02E03"),
|
||||
media_source=MediaSource.TMDB,
|
||||
media_id="117061",
|
||||
mtype=MediaType.TV,
|
||||
download_history=None,
|
||||
preview=True,
|
||||
)
|
||||
task.__dict__.update(overrides)
|
||||
return task
|
||||
|
||||
|
||||
def test_replan_recognition_passes_verified_media_id(monkeypatch) -> None:
|
||||
"""
|
||||
已核实的来源与原生标识必须成对下传,重新识别才能按身份而不是按标题进行。
|
||||
"""
|
||||
captured = _capture_recognition(monkeypatch)
|
||||
|
||||
TransferExecutionOwner._recognize_task_meta(_task())
|
||||
|
||||
assert captured["options"]["media_source"] is MediaSource.TMDB
|
||||
assert captured["options"]["media_id"] == "117061"
|
||||
assert captured["options"]["mtype"] is MediaType.TV
|
||||
|
||||
|
||||
def test_recognition_without_source_does_not_send_bare_media_id(monkeypatch) -> None:
|
||||
"""
|
||||
来源缺失时不能下传孤立标识,否则识别会按成对校验直接失败。
|
||||
"""
|
||||
captured = _capture_recognition(monkeypatch)
|
||||
|
||||
TransferExecutionOwner._recognize_task_meta(_task(media_source=None))
|
||||
|
||||
assert "media_id" not in captured["options"]
|
||||
|
||||
|
||||
def test_recognition_without_media_id_keeps_title_search(monkeypatch) -> None:
|
||||
"""
|
||||
未核实原生标识时保持按标题识别的既有行为。
|
||||
"""
|
||||
captured = _capture_recognition(monkeypatch)
|
||||
|
||||
TransferExecutionOwner._recognize_task_meta(_task(media_id=None))
|
||||
|
||||
assert "media_id" not in captured["options"]
|
||||
assert captured["options"]["media_source"] is MediaSource.TMDB
|
||||
|
||||
|
||||
@pytest.mark.parametrize("asynchronous", [False, True], ids=["sync", "async"])
|
||||
@pytest.mark.parametrize("plugin_first", [False, True], ids=["native-first", "plugin-first"])
|
||||
@pytest.mark.parametrize("outcome", ["matched", "missing", "other-source", "other-id", "other-type"])
|
||||
def test_verified_identity_controls_recognition(
|
||||
monkeypatch, asynchronous: bool, plugin_first: bool, outcome: str,
|
||||
) -> None:
|
||||
"""
|
||||
显式身份在两种识别顺序下都直查,查无结果或身份及类型不符时拒绝继续整理。
|
||||
"""
|
||||
meta = MetaVideo("yongzhe de mingzi S02E03")
|
||||
expected = MediaInfo(
|
||||
media_source=MediaSource.Douban if outcome == "other-source" else MediaSource.TMDB,
|
||||
media_id="999999" if outcome == "other-id" else "117061",
|
||||
type=MediaType.MOVIE if outcome == "other-type" else MediaType.TV,
|
||||
title="已核实剧集",
|
||||
)
|
||||
candidate = None if outcome == "missing" else expected
|
||||
chain = MediaChain()
|
||||
native = AsyncMock(return_value=candidate) if asynchronous else Mock(return_value=candidate)
|
||||
plugin = AsyncMock(return_value=expected) if asynchronous else Mock(return_value=expected)
|
||||
native_name = "async_recognize_media" if asynchronous else "recognize_media"
|
||||
plugin_name = "async_recognize_help" if asynchronous else "recognize_help"
|
||||
monkeypatch.setattr(chain, native_name, native)
|
||||
monkeypatch.setattr(chain, plugin_name, plugin)
|
||||
monkeypatch.setattr(chain.eventmanager, "check", Mock(return_value=True))
|
||||
monkeypatch.setattr(media_plugin, "get_chain_runtime_config_snapshot", Mock(
|
||||
return_value=SimpleNamespace(recognize_plugin_first=plugin_first),
|
||||
))
|
||||
images = AsyncMock() if asynchronous else Mock()
|
||||
monkeypatch.setattr(chain, "async_obtain_images" if asynchronous else "obtain_images", images)
|
||||
finalizer = Mock(return_value=candidate)
|
||||
monkeypatch.setattr(chain, "_finalize_recognition_result", finalizer)
|
||||
options = dict(media_source=MediaSource.TMDB, media_id="117061", mtype=MediaType.TV, obtain_images=True)
|
||||
|
||||
if asynchronous:
|
||||
result = asyncio.run(chain.async_recognize_by_meta(meta, **options))
|
||||
else:
|
||||
result = chain.recognize_by_meta(meta, **options)
|
||||
|
||||
assert native.call_count == 1
|
||||
assert native.call_args.kwargs["media_source"] is MediaSource.TMDB
|
||||
assert native.call_args.kwargs["media_id"] == "117061"
|
||||
assert native.call_args.kwargs["mtype"] is MediaType.TV
|
||||
assert meta.begin_season == 2 and meta.begin_episode == 3
|
||||
plugin.assert_not_called()
|
||||
if outcome == "matched":
|
||||
assert result is expected
|
||||
assert images.call_count == 1
|
||||
else:
|
||||
assert result is None
|
||||
finalizer.assert_not_called()
|
||||
images.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("asynchronous", [False, True], ids=["sync", "async"])
|
||||
def test_recognition_keeps_existing_positional_arguments(monkeypatch, asynchronous: bool) -> None:
|
||||
"""
|
||||
旧调用中的剧集组、图片选项、媒体类型和音乐类型保留原有位置含义。
|
||||
"""
|
||||
chain = MediaChain()
|
||||
fallback = AsyncMock(return_value=None) if asynchronous else Mock(return_value=None)
|
||||
method = "_async_recognize_with_fallback_by_meta" if asynchronous else "_recognize_with_fallback_by_meta"
|
||||
monkeypatch.setattr(chain, method, fallback)
|
||||
meta = MetaVideo("已核实剧集 S02E03")
|
||||
args = (meta, MediaSource.TMDB, "episode-group", True, MediaType.TV, None)
|
||||
|
||||
if asynchronous:
|
||||
asyncio.run(chain.async_recognize_by_meta(*args))
|
||||
else:
|
||||
chain.recognize_by_meta(*args)
|
||||
|
||||
assert fallback.call_args.kwargs == dict(
|
||||
metainfo=meta, media_source=MediaSource.TMDB, media_id=None,
|
||||
episode_group="episode-group", obtain_images=True, mtype=MediaType.TV, music_type=None,
|
||||
)
|
||||
|
||||
|
||||
def test_replan_skill_example_matches_runtime_input_contract() -> None:
|
||||
"""
|
||||
失败重试技能的结构化示例必须符合实际 MCP Schema,并保留已核实身份与类型。
|
||||
"""
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
skill = (root / "skills/transfer-failed-retry/SKILL.md").read_text(encoding="utf-8")
|
||||
examples = re.findall(r"```json\n(.*?)\n```", skill, re.DOTALL)
|
||||
assert len(examples) == 1
|
||||
payload = json.loads(examples[0])
|
||||
schema = MoviePilotApiTool(session_id="replan-contract", user_id="1").get_mcp_input_schema()
|
||||
assert canonical_api_arguments(payload, schema) == {**payload, "query": {}}
|
||||
model = schema["$defs"]["TransferHistoryReplanRequest"]
|
||||
assert set(model["required"]) == {"task_id", "settlement_revision", "media_source", "media_id", "media_type"}
|
||||
assert "直接" in model["properties"]["media_id"]["description"]
|
||||
assert payload["body"]["media_type"] == "tv"
|
||||
assert payload["body"]["season"] == 2 and payload["body"]["episode"] == 3
|
||||
|
||||
|
||||
@pytest.mark.parametrize("asynchronous", [False, True], ids=["sync", "async"])
|
||||
def test_bare_identity_cannot_fall_back_to_plugin(monkeypatch, asynchronous: bool) -> None:
|
||||
"""
|
||||
缺少来源的显式标识由原生入口拒绝,插件优先也不能将其改成标题识别。
|
||||
"""
|
||||
chain = MediaChain()
|
||||
plugin = AsyncMock() if asynchronous else Mock()
|
||||
runner = AsyncMock() if asynchronous else Mock()
|
||||
monkeypatch.setattr(chain, "async_recognize_help" if asynchronous else "recognize_help", plugin)
|
||||
monkeypatch.setattr(chain, "_async_run_recognition_steps" if asynchronous else "_run_recognition_steps", runner)
|
||||
monkeypatch.setattr(chain.eventmanager, "check", Mock(return_value=True))
|
||||
monkeypatch.setattr(media_plugin, "get_chain_runtime_config_snapshot", Mock(
|
||||
return_value=SimpleNamespace(recognize_plugin_first=True),
|
||||
))
|
||||
meta = MetaVideo("yongzhe de mingzi S02E03")
|
||||
|
||||
if asynchronous:
|
||||
result = asyncio.run(chain.async_recognize_by_meta(meta, media_id="117061"))
|
||||
else:
|
||||
result = chain.recognize_by_meta(meta, media_id="117061")
|
||||
|
||||
assert result is None
|
||||
runner.assert_not_called()
|
||||
plugin.assert_not_called()
|
||||
|
||||
|
||||
def test_replan_generated_schema_and_skill_stay_in_sync() -> None:
|
||||
"""
|
||||
重新生成后仍保留重规划输入的直查约束,发布的 Schema 与技能内容使用同一定义。
|
||||
"""
|
||||
from scripts.generate_agent_api_mcp_schema import generate_schema
|
||||
from scripts.generate_agent_skill_docs import _render_api_docs
|
||||
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
stored_schema = json.loads((root / "app/agent/policy/resources/api_mcp_schema.json").read_text(encoding="utf-8"))
|
||||
assert stored_schema["$defs"]["TransferHistoryReplanRequest"] == generate_schema()["$defs"]["TransferHistoryReplanRequest"]
|
||||
heading = "### `transfer.history.replan`"
|
||||
generated_operation = heading + _render_api_docs().split(heading, 1)[1].split("\n### `", 1)[0]
|
||||
skill = (root / "skills/moviepilot-api/api/transfer.md").read_text(encoding="utf-8")
|
||||
assert generated_operation.strip() in skill
|
||||
Reference in New Issue
Block a user