mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-11-29 23:45:03 +08:00
Merge pull request #7050 from DDSRem-Dev/codex-comment-migration
docs: 统一全项目中文注释和结构化契约说明
This commit is contained in:
@@ -185,12 +185,14 @@ Python 内核继承宿主部署环境(含数据库配置与连接凭据),
|
||||
|
||||
这四个工具都要求管理员级 MCP 集成身份;`tools/list` 的可见性不等于绕过业务权限或写操作确认。下载器和媒体服务器工具会在一次调用内自动选择默认/唯一实例;实例不明确时,错误结果会列出可复用的精确实例名。数据库工具不接受任意连接串或凭据,脚本从 MoviePilot 运行时配置读取数据库连接。
|
||||
|
||||
`app/agent/policy/resources/api_mcp_schema.json` 是 `moviepilot_api` 的生成制品,不是设置项或 API 参数的手工事实源。`scripts/generate_agent_api_mcp_schema.py` 从当前 FastAPI OpenAPI、固定 operation 路由和 Agent 专用英文参数说明生成该文件;运行时直接读取它响应外部 MCP `tools/list`,测试会校验生成结果没有漂移。修改 API、请求模型或 operation 后应重新生成并提交该文件,不应直接编辑 JSON。
|
||||
`app/agent/policy/resources/api_mcp_schema.json` 是 `moviepilot_api` 的生成制品,不是设置项或 API 参数的手工事实源。`scripts/generate_agent_api_mcp_schema.py` 从当前 FastAPI OpenAPI、固定 operation 路由和 Agent 专用中文参数说明生成该文件;运行时直接读取它响应外部 MCP `tools/list`,测试会校验生成结果没有漂移。修改 API、请求模型或 operation 后应重新生成并提交该文件,不应直接编辑 JSON。生成器保留端点已有的中文字段契约,缺少中文说明时使用已登记的中文兜底;紧凑投影同步改写中文分支引用,并兼容旧英文元数据输入。
|
||||
|
||||
HTTP 接口的摘要、分页参数、数量响应头及认证请求字段使用中文说明;生成的 Skill 分类契约同步引用这些说明,操作标识、类型、默认值和权限规则保持各自原有含义。
|
||||
|
||||
当前完整 FastAPI OpenAPI 包含 421 个 HTTP 操作,其中 231 个稳定业务操作进入
|
||||
`moviepilot_api`,使用 229 个固定路由模板:228 条 OpenAPI 路由直接匹配,另有 1 条只允许
|
||||
`tmdb`、`douban`、`bangumi`、`anilist` 四个来源的受限人物作品动态路由。每个 operation
|
||||
均同时具备固定 method/path、角色权限、副作用等级、确认与恢复策略、结果敏感性、英文用途说明,
|
||||
均同时具备固定 method/path、角色权限、副作用等级、确认与恢复策略、结果敏感性、中文用途说明,
|
||||
以及可直接提交的 path/query/body JSON Schema;Skill front matter、正文 operation 章节、运行时
|
||||
注册表和 MCP `tools/list` 的 231 个 `oneOf` 分支必须完全一致。
|
||||
|
||||
|
||||
@@ -2438,7 +2438,7 @@
|
||||
"owner": "host-runtime",
|
||||
"path": "/api/v1/anthropic/v1/messages",
|
||||
"reason": "Authentication, protocol compatibility, conversation transport, callback, or account lifecycle endpoint; never recursively exposed as an Agent business action.",
|
||||
"summary": "Anthropic compatible messages",
|
||||
"summary": "Anthropic 兼容消息生成",
|
||||
"tags": [
|
||||
"anthropic"
|
||||
]
|
||||
@@ -4449,7 +4449,7 @@
|
||||
"owner": "host-runtime",
|
||||
"path": "/api/v1/openai/v1/chat/completions",
|
||||
"reason": "Authentication, protocol compatibility, conversation transport, callback, or account lifecycle endpoint; never recursively exposed as an Agent business action.",
|
||||
"summary": "OpenAI compatible chat completions",
|
||||
"summary": "OpenAI 兼容聊天补全",
|
||||
"tags": [
|
||||
"openai"
|
||||
]
|
||||
@@ -4461,7 +4461,7 @@
|
||||
"owner": "host-runtime",
|
||||
"path": "/api/v1/openai/v1/models",
|
||||
"reason": "Authentication, protocol compatibility, conversation transport, callback, or account lifecycle endpoint; never recursively exposed as an Agent business action.",
|
||||
"summary": "OpenAI compatible models",
|
||||
"summary": "OpenAI 兼容模型列表",
|
||||
"tags": [
|
||||
"openai"
|
||||
]
|
||||
@@ -4473,7 +4473,7 @@
|
||||
"owner": "host-runtime",
|
||||
"path": "/api/v1/openai/v1/responses",
|
||||
"reason": "Authentication, protocol compatibility, conversation transport, callback, or account lifecycle endpoint; never recursively exposed as an Agent business action.",
|
||||
"summary": "OpenAI compatible responses",
|
||||
"summary": "OpenAI 兼容响应生成",
|
||||
"tags": [
|
||||
"openai"
|
||||
]
|
||||
@@ -7098,7 +7098,7 @@
|
||||
"owner": "moviepilot-api",
|
||||
"path": "/api/v1/system/settings",
|
||||
"reason": "Executable through moviepilot_api; exact inputs are generated into MCP tools/list and SKILL.md.",
|
||||
"summary": "Discover or read registered system settings",
|
||||
"summary": "发现或读取已登记的系统设置",
|
||||
"tags": [
|
||||
"system"
|
||||
]
|
||||
@@ -7112,7 +7112,7 @@
|
||||
"owner": "moviepilot-api",
|
||||
"path": "/api/v1/system/settings",
|
||||
"reason": "Executable through moviepilot_api; exact inputs are generated into MCP tools/list and SKILL.md.",
|
||||
"summary": "Update one registered system setting",
|
||||
"summary": "更新单项已登记系统设置",
|
||||
"tags": [
|
||||
"system"
|
||||
]
|
||||
@@ -7126,7 +7126,7 @@
|
||||
"owner": "moviepilot-api",
|
||||
"path": "/api/v1/system/settings/catalog",
|
||||
"reason": "Executable through moviepilot_api; exact inputs are generated into MCP tools/list and SKILL.md.",
|
||||
"summary": "List system setting contracts",
|
||||
"summary": "列出系统设置契约",
|
||||
"tags": [
|
||||
"system"
|
||||
]
|
||||
@@ -7140,7 +7140,7 @@
|
||||
"owner": "moviepilot-api",
|
||||
"path": "/api/v1/system/settings/describe/{setting_key}",
|
||||
"reason": "Executable through moviepilot_api; exact inputs are generated into MCP tools/list and SKILL.md.",
|
||||
"summary": "Describe one system setting contract",
|
||||
"summary": "查询单项系统设置契约",
|
||||
"tags": [
|
||||
"system"
|
||||
]
|
||||
|
||||
@@ -286,7 +286,7 @@ Plugin ratings include this installation's own rating and require the same admin
|
||||
| `GET` | `/api/v1/anilist/recommend/{anilist_id}` | anilist | `consolidated` | moviepilot-api | 查询 AniList 相关推荐 |
|
||||
| `GET` | `/api/v1/anilist/trending` | anilist | `consolidated` | moviepilot-api | 查询 AniList 当前趋势榜 |
|
||||
| `GET` | `/api/v1/anilist/{anilist_id}` | anilist | `consolidated` | moviepilot-api | 查询 AniList 动画详情 |
|
||||
| `POST` | `/api/v1/anthropic/v1/messages` | anthropic | `transport_or_identity` | host-runtime | Anthropic compatible messages |
|
||||
| `POST` | `/api/v1/anthropic/v1/messages` | anthropic | `transport_or_identity` | host-runtime | Anthropic 兼容消息生成 |
|
||||
| `POST` | `/api/v1/auth/exchange` | auth | `transport_or_identity` | host-runtime | 兑换插件认证登录票据 |
|
||||
| `GET` | `/api/v1/auth/providers` | auth | `transport_or_identity` | host-runtime | 查询登录认证提供方 |
|
||||
| `GET` | `/api/v1/bangumi/credits/{bangumiid}` | bangumi | `consolidated` | moviepilot-api | 查询Bangumi演职员表 |
|
||||
@@ -444,9 +444,9 @@ Plugin ratings include this installation's own rating and require the same admin
|
||||
| `POST` | `/api/v1/music/recognize` | music | `gateway` | music.recognize | 识别音乐元数据详情 |
|
||||
| `POST` | `/api/v1/notification/config` | notification | `transport_or_identity` | host-runtime | 保存通知渠道并同步登录缓存 |
|
||||
| `POST` | `/api/v1/notification/manage` | notification | `transport_or_identity` | host-runtime | 通知渠道统一管理 |
|
||||
| `POST` | `/api/v1/openai/v1/chat/completions` | openai | `transport_or_identity` | host-runtime | OpenAI compatible chat completions |
|
||||
| `GET` | `/api/v1/openai/v1/models` | openai | `transport_or_identity` | host-runtime | OpenAI compatible models |
|
||||
| `POST` | `/api/v1/openai/v1/responses` | openai | `transport_or_identity` | host-runtime | OpenAI compatible responses |
|
||||
| `POST` | `/api/v1/openai/v1/chat/completions` | openai | `transport_or_identity` | host-runtime | OpenAI 兼容聊天补全 |
|
||||
| `GET` | `/api/v1/openai/v1/models` | openai | `transport_or_identity` | host-runtime | OpenAI 兼容模型列表 |
|
||||
| `POST` | `/api/v1/openai/v1/responses` | openai | `transport_or_identity` | host-runtime | OpenAI 兼容响应生成 |
|
||||
| `GET` | `/api/v1/plugin/` | plugin | `gateway` | plugin.installed, plugin.market | 所有插件 |
|
||||
| `GET` | `/api/v1/plugin/agent_pets` | plugin | `ui_presentation` | host-ui | 获取插件 Agent 助手形象 |
|
||||
| `POST` | `/api/v1/plugin/clone/{plugin_id}` | plugin | `gateway` | plugin.clone | 创建插件分身 |
|
||||
@@ -640,10 +640,10 @@ Plugin ratings include this installation's own rating and require the same admin
|
||||
| `GET` | `/api/v1/system/setting/public/{key}` | system | `gateway` | config.public.get | 查询公开系统设置 |
|
||||
| `GET` | `/api/v1/system/setting/{key}` | system | `consolidated` | config.system.get | 查询系统设置 |
|
||||
| `POST` | `/api/v1/system/setting/{key}` | system | `consolidated` | config.system.update | 更新系统设置 |
|
||||
| `GET` | `/api/v1/system/settings` | system | `gateway` | config.system.get | Discover or read registered system settings |
|
||||
| `POST` | `/api/v1/system/settings` | system | `gateway` | config.system.update | Update one registered system setting |
|
||||
| `GET` | `/api/v1/system/settings/catalog` | system | `gateway` | config.system.list | List system setting contracts |
|
||||
| `GET` | `/api/v1/system/settings/describe/{setting_key}` | system | `gateway` | config.system.describe | Describe one system setting contract |
|
||||
| `GET` | `/api/v1/system/settings` | system | `gateway` | config.system.get | 发现或读取已登记的系统设置 |
|
||||
| `POST` | `/api/v1/system/settings` | system | `gateway` | config.system.update | 更新单项已登记系统设置 |
|
||||
| `GET` | `/api/v1/system/settings/catalog` | system | `gateway` | config.system.list | 列出系统设置契约 |
|
||||
| `GET` | `/api/v1/system/settings/describe/{setting_key}` | system | `gateway` | config.system.describe | 查询单项系统设置契约 |
|
||||
| `POST` | `/api/v1/system/update/check` | system | `gateway` | system.update.check | 立即检查系统更新 |
|
||||
| `POST` | `/api/v1/system/update/download` | system | `gateway` | system.update.download | 后台下载系统更新 |
|
||||
| `POST` | `/api/v1/system/update/install` | system | `gateway` | system.update.install | 确认重启安装系统更新 |
|
||||
|
||||
@@ -108,12 +108,14 @@ ARCH-201 至 ARCH-204 均达到实现、验证、提交、推送和远端门禁
|
||||
| Event Contract | 53 | 均已有 payload model,但当前全部是 diagnostic enforcement |
|
||||
| Python 源码量 | 373,625 行 | 本次重新扫描物理行数,排除 `app/plugins/**`;74 个文件超过 1,000 行,12 个超过 2,000 行;源码尺寸仅作观察 |
|
||||
| 长方法 | 309 个超过 80 行 | 本次 AST 扫描排除 `app/plugins/**`;61 个超过 150 行,17 个超过 250 行;新增函数仍受 C901/嵌套深度门禁约束 |
|
||||
| 全量 mypy 历史债务 | 4,448 / 252 文件 | 本轮在消息、站点、诊断、备份、用户配置、订阅、AcoustID、TMDB、仪表板和命令生命周期边界补齐类型,历史债务再减少 53 项;TMDB v3 API 显式导出并保留集合 parts 的列表合同,逐文件逐错误码无增长;此前工作流筛选、动态插件路由和 stdio 流补齐边界类型,历史债务减少 3 项;Bitpt 与 CookieCloud 补齐边界类型,历史债务减少 16 项;知行站点解析器补齐数值属性与基类合同,历史债务减少 18 项;通知排版补齐 Slack 消息块类型,历史债务减少 2 项;工作流资源过滤改用领域对象调用过滤链,恢复的节点输出在消费前归一化,并收紧可空资源列表的类型低水位;消息媒体交互类型债务已清零,canonical Facade 与 endpoint 类型边界已补齐,低水位只允许继续下降;微信 ClawBot 入站 item_list 媒体解析改为按子项键名分派后,类型错误减少 4 项;站点解析器分享率改用浮点初值,类型错误减少 20 项;本次下载与文件安全修复再减少 3 项;Transmission 进度回退值归一化再减少 2 项;本批清理 Servarr、认证、存储、订阅策略和搜索/规则/通知 Schema 的 18 项类型错误,并修复系统配置中的 Python 2 异常语法;本批再清理订阅元数据、订阅写入、交互宿主、整理路径、删除统计和工作流动作的 14 项类型错误,逐文件逐错误码无增长;本批补齐 OCR 请求参数、工具 Schema 摘要和宿主模块配置快照的 5 项边界类型,逐文件逐错误码无增长;本批为 Rousi 用户消息分页解析补齐返回类型与数据结构兜底,减少 2 项类型错误;本批优先处理 TMDB v3 电影与电视剧对象模型,补齐 98 个同步/异步方法注解并减少 122 项历史类型错误;随后补齐剧集、季度、人物、搜索和趋势对象的 142 个方法注解,再减少 142 项类型错误;绿联 API 响应边界补齐具体泛型与运行时字典收窄,减少 31 项类型错误;运行时限流器补齐状态方法、装饰器边界和时间队列类型,减少 31 项类型错误;QQ Bot API 响应边界补齐具体泛型与 JSON 形状校验,减少 17 项类型错误;rTorrent 客户端清理 182 项错误,调用端同步明确字典合同,累计再减少 190 项错误;豆瓣 API、中心服务接口及订阅消费端补齐返回边界和参数收窄,结合 Context 方法签名与缓存代理类型清理,累计再减少 455 项错误;共享 HTTP 客户端清理 110 项错误,TMDB API 清理 84 项错误,索引器爬虫清理 87 项错误,并补充 U115、AliPan、OpenList 对可空流响应的防守;U115 其余存储基类契约债务暂留待测试完备后处理;缓存同步/异步继承冲突保留为设计债务,未纳入严格门禁;本批并行清理消息模板与队列、TMDB 模块和飞牛媒体客户端,累计减少 177 项类型错误,新增严格门禁文件 3 个 |
|
||||
| 全量 mypy 历史债务 | 4,445 / 252 文件 | 本分支为 Pydantic 字段补充描述并保留默认值,减少 3 项 assignment 错误;本轮在消息、站点、诊断、备份、用户配置、订阅、AcoustID、TMDB、仪表板和命令生命周期边界补齐类型,历史债务再减少 53 项;TMDB v3 API 显式导出并保留集合 parts 的列表合同,逐文件逐错误码无增长;此前工作流筛选、动态插件路由和 stdio 流补齐边界类型,历史债务减少 3 项;Bitpt 与 CookieCloud 补齐边界类型,历史债务减少 16 项;知行站点解析器补齐数值属性与基类合同,历史债务减少 18 项;通知排版补齐 Slack 消息块类型,历史债务减少 2 项;工作流资源过滤改用领域对象调用过滤链,恢复的节点输出在消费前归一化,并收紧可空资源列表的类型低水位;消息媒体交互类型债务已清零,canonical Facade 与 endpoint 类型边界已补齐,低水位只允许继续下降;微信 ClawBot 入站 item_list 媒体解析改为按子项键名分派后,类型错误减少 4 项;站点解析器分享率改用浮点初值,类型错误减少 20 项;本次下载与文件安全修复再减少 3 项;Transmission 进度回退值归一化再减少 2 项;本批清理 Servarr、认证、存储、订阅策略和搜索/规则/通知 Schema 的 18 项类型错误,并修复系统配置中的 Python 2 异常语法;本批再清理订阅元数据、订阅写入、交互宿主、整理路径、删除统计和工作流动作的 14 项类型错误,逐文件逐错误码无增长;本批补齐 OCR 请求参数、工具 Schema 摘要和宿主模块配置快照的 5 项边界类型,逐文件逐错误码无增长;本批为 Rousi 用户消息分页解析补齐返回类型与数据结构兜底,减少 2 项类型错误;本批优先处理 TMDB v3 电影与电视剧对象模型,补齐 98 个同步/异步方法注解并减少 122 项历史类型错误;随后补齐剧集、季度、人物、搜索和趋势对象的 142 个方法注解,再减少 142 项类型错误;绿联 API 响应边界补齐具体泛型与运行时字典收窄,减少 31 项类型错误;运行时限流器补齐状态方法、装饰器边界和时间队列类型,减少 31 项类型错误;QQ Bot API 响应边界补齐具体泛型与 JSON 形状校验,减少 17 项类型错误;rTorrent 客户端清理 182 项错误,调用端同步明确字典合同,累计再减少 190 项错误;豆瓣 API、中心服务接口及订阅消费端补齐返回边界和参数收窄,结合 Context 方法签名与缓存代理类型清理,累计再减少 455 项错误;共享 HTTP 客户端清理 110 项错误,TMDB API 清理 84 项错误,索引器爬虫清理 87 项错误,并补充 U115、AliPan、OpenList 对可空流响应的防守;U115 其余存储基类契约债务暂留待测试完备后处理;缓存同步/异步继承冲突保留为设计债务,未纳入严格门禁 |
|
||||
| Ruff 历史诊断 | 73 | 低水位门禁通过,但规则集只覆盖 `E4/E7/E9/F/I` |
|
||||
| 覆盖率逐文件低水位 | 全 app(排除 app/plugins)当前聚合 77.68% | 存量文件低水位只增不减,新文件至少 80% |
|
||||
| 覆盖率逐文件低水位 | 全 app(排除 app/plugins)当前聚合 77.68% | 存量文件比例不降;语句减少且未覆盖行数不增时允许比例变化,新文件至少 80% |
|
||||
|
||||
外部 MCP schema 紧凑投影由纯函数模块 `app.agent.tools.projection` 拥有,仅在请求头显式 opt-in 后应用;新增 1 个模块和 1 条合法端点依赖边,未新增 SCC。`list_exposed_tools` 返回类型注解使端点类型债务减少 5 项。
|
||||
|
||||
本批并行清理消息模板与队列、TMDB 模块和飞牛媒体客户端,累计减少 177 项类型错误,新增严格门禁文件 3 个。
|
||||
|
||||
### 3.3 热点文件
|
||||
|
||||
| 文件 | 行数 | 主要职责混合 |
|
||||
|
||||
@@ -7,10 +7,10 @@ This document is the project command reference, not an exhaustive shell allowlis
|
||||
## Development Environment Setup
|
||||
|
||||
```bash
|
||||
# Create the locked development/test environment (standalone checkout)
|
||||
# 在独立检出目录中创建与锁文件一致的开发和测试环境
|
||||
uv sync --locked
|
||||
|
||||
# Create a runtime-only environment
|
||||
# 创建仅包含运行依赖的环境
|
||||
uv sync --locked --no-dev --no-install-project
|
||||
```
|
||||
|
||||
@@ -21,13 +21,13 @@ Shared workspaces may map the environment to an explicit absolute path as docume
|
||||
## Dependency Management
|
||||
|
||||
```bash
|
||||
# Verify that project metadata and lock agree
|
||||
# 检查项目依赖声明与锁文件是否一致
|
||||
uv lock --check
|
||||
|
||||
# Update the lock after editing pyproject.toml
|
||||
# 修改 pyproject.toml 后更新锁文件
|
||||
uv lock
|
||||
|
||||
# Verify the installed environment against the locked project
|
||||
# 按锁文件检查当前环境中已安装的依赖
|
||||
uv sync --locked --offline --inexact --no-dev --check
|
||||
```
|
||||
|
||||
@@ -43,16 +43,16 @@ uv sync --locked --offline --inexact --no-dev --check
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
# Run a specific test file
|
||||
# 运行指定测试文件
|
||||
uv run --locked --no-sync pytest tests/test_xxx.py
|
||||
|
||||
# Run all tests
|
||||
# 运行全部测试
|
||||
uv run --locked --no-sync pytest
|
||||
|
||||
# Run tests with verbose output
|
||||
# 运行测试并显示详细结果
|
||||
uv run --locked --no-sync pytest -v tests/test_xxx.py
|
||||
|
||||
# Run a specific test function
|
||||
# 运行指定测试函数
|
||||
uv run --locked --no-sync pytest tests/test_xxx.py::test_function_name
|
||||
```
|
||||
|
||||
@@ -65,10 +65,10 @@ uv run --locked --no-sync pytest tests/test_xxx.py::test_function_name
|
||||
## Static Analysis
|
||||
|
||||
```bash
|
||||
# Run pylint on the application package
|
||||
# 检查整个应用包的代码质量
|
||||
uv run --locked --no-sync pylint app/
|
||||
|
||||
# Run pylint on a specific module
|
||||
# 检查指定模块的代码质量
|
||||
uv run --locked --no-sync pylint app/chain/download.py
|
||||
```
|
||||
|
||||
@@ -128,36 +128,36 @@ moviepilot logs --stdio --follow
|
||||
## Local CLI — Installation and Setup
|
||||
|
||||
```bash
|
||||
# One-line bootstrap installer
|
||||
# 下载并运行本地安装引导脚本
|
||||
curl -fsSL https://raw.githubusercontent.com/jxxghp/MoviePilot/v3/scripts/bootstrap-local.sh | bash
|
||||
|
||||
# Install backend dependencies
|
||||
# 安装后端依赖
|
||||
moviepilot install deps
|
||||
moviepilot install deps --python python3.12
|
||||
moviepilot install deps --venv /path/to/venv
|
||||
moviepilot install deps --recreate
|
||||
|
||||
# Install frontend release
|
||||
# 安装前端发布包
|
||||
moviepilot install frontend
|
||||
moviepilot install frontend --version latest
|
||||
moviepilot install frontend --version v3.0.0
|
||||
|
||||
# Install resource files
|
||||
# 安装运行所需的资源文件
|
||||
moviepilot install resources
|
||||
|
||||
# Initialize local config
|
||||
# 初始化本地配置
|
||||
moviepilot init
|
||||
moviepilot init --wizard
|
||||
moviepilot init --force-token
|
||||
moviepilot init --superuser admin --superuser-password 'ChangeMe123!'
|
||||
|
||||
# All-in-one setup
|
||||
# 完成依赖、资源和配置的一体化安装
|
||||
moviepilot setup
|
||||
moviepilot setup --wizard
|
||||
moviepilot setup --recreate
|
||||
moviepilot setup --superuser admin --superuser-password 'ChangeMe123!'
|
||||
|
||||
# Uninstall
|
||||
# 卸载本地安装
|
||||
moviepilot uninstall
|
||||
```
|
||||
|
||||
@@ -213,21 +213,21 @@ moviepilot config describe API_TOKEN --show-secrets
|
||||
## Local CLI — Tools and Scheduler
|
||||
|
||||
```bash
|
||||
# List all MCP tools
|
||||
# 列出全部 MCP 工具
|
||||
moviepilot tool list
|
||||
|
||||
# Show tool parameters
|
||||
# 查看工具参数
|
||||
moviepilot tool show moviepilot_api
|
||||
moviepilot tool show agent_task
|
||||
|
||||
# Run a tool directly
|
||||
# 直接调用工具
|
||||
moviepilot tool run moviepilot_api operation_id=scheduler.list
|
||||
moviepilot tool run moviepilot_api operation_id=media.search 'query={"title":"流浪地球","type":"media"}'
|
||||
|
||||
# List scheduled tasks
|
||||
# 列出定时任务
|
||||
moviepilot scheduler list
|
||||
|
||||
# Immediately run a scheduled task
|
||||
# 立即执行指定定时任务
|
||||
moviepilot scheduler run subscribe_refresh
|
||||
```
|
||||
|
||||
@@ -286,7 +286,7 @@ moviepilot help scheduler
|
||||
## Site Adapter Capture — macOS / Linux
|
||||
|
||||
```bash
|
||||
# Run from the independent MoviePilot-Site-Collector checkout and reuse its virtual environment
|
||||
# 在独立的 MoviePilot-Site-Collector 检出目录中运行,复用其虚拟环境
|
||||
cd /path/to/MoviePilot-Site-Collector
|
||||
bash scripts/collect-site-adapter.sh
|
||||
```
|
||||
@@ -303,7 +303,7 @@ bash scripts/collect-site-adapter.sh
|
||||
## Plugin Market Release Default
|
||||
|
||||
```bash
|
||||
# Run after activating the project virtual environment
|
||||
# 激活项目虚拟环境后运行
|
||||
python -m scripts.generate_plugin_market_default \
|
||||
--wiki-file /path/to/MoviePilot-Wiki/plugin.md \
|
||||
--config-file app/runtime/config.py
|
||||
|
||||
@@ -18,36 +18,72 @@ This document defines the structural patterns used across this codebase. When im
|
||||
|
||||
```python
|
||||
class ExampleModule(_ModuleBase, _DownloaderBase):
|
||||
"""
|
||||
展示下载器模块的注册、配置开关与生命周期接口。
|
||||
"""
|
||||
|
||||
def init_module(self) -> None:
|
||||
"""模块初始化"""
|
||||
"""
|
||||
初始化本模块管理的下载器服务。
|
||||
"""
|
||||
super().init_service(service_name=..., service_type=...)
|
||||
|
||||
def init_setting(self) -> Tuple[str, Union[str, bool]]:
|
||||
"""返回控制此模块开关的配置项名称和匹配值"""
|
||||
"""
|
||||
声明启用本下载器模块所需的配置匹配条件。
|
||||
|
||||
:return: 配置项 DOWNLOADER 及其启用值 example
|
||||
"""
|
||||
return "DOWNLOADER", "example"
|
||||
|
||||
@staticmethod
|
||||
def get_name() -> str:
|
||||
"""
|
||||
提供模块的展示名称。
|
||||
|
||||
:return: 示例下载器的名称
|
||||
"""
|
||||
return "Example"
|
||||
|
||||
@staticmethod
|
||||
def get_type() -> ModuleType:
|
||||
"""
|
||||
声明模块所属的能力分类。
|
||||
|
||||
:return: 下载器模块分类
|
||||
"""
|
||||
return ModuleType.Downloader
|
||||
|
||||
@staticmethod
|
||||
def get_subtype() -> DownloaderType:
|
||||
"""
|
||||
声明下载器的具体类型。
|
||||
|
||||
:return: 示例下载器对应的类型枚举
|
||||
"""
|
||||
return DownloaderType.Example
|
||||
|
||||
@staticmethod
|
||||
def get_priority() -> int:
|
||||
"""
|
||||
提供模块调度的排序优先级。
|
||||
|
||||
:return: 示例优先级 1,数值越小越先调用
|
||||
"""
|
||||
return 1
|
||||
|
||||
def test(self) -> Optional[Tuple[bool, str]]:
|
||||
"""测试模块连通性"""
|
||||
"""
|
||||
检查已配置下载器的连接状态。
|
||||
|
||||
:return: 检测结果与说明组成的二元组;未启用检测时返回 None
|
||||
"""
|
||||
...
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
结束模块生命周期;本示例没有需要释放的资源。
|
||||
"""
|
||||
pass
|
||||
```
|
||||
|
||||
@@ -66,12 +102,11 @@ class ExampleModule(_ModuleBase, _DownloaderBase):
|
||||
**Calling modules from a chain:**
|
||||
|
||||
```python
|
||||
# Preferred: call via run_module / async_run_module
|
||||
# 通过模块调度接口调用,避免链直接依赖具体模块实例
|
||||
result = self.run_module("method_name", kwarg1=val1, kwarg2=val2)
|
||||
result = await self.async_run_module("method_name", kwarg1=val1)
|
||||
|
||||
# Only use ModuleManager directly when you need to enumerate modules,
|
||||
# inspect instances, or run health checks.
|
||||
# 仅在枚举模块、查看实例或检查健康状态时直接使用 ModuleManager
|
||||
```
|
||||
|
||||
**Chain-to-chain calls:** A chain may call another chain to reuse stable domain logic. Avoid introducing new circular dependencies between chains.
|
||||
@@ -94,6 +129,11 @@ from app.schemas.types import EventType
|
||||
|
||||
@eventmanager.register(EventType.TransferComplete)
|
||||
def on_transfer_complete(self, event: Event):
|
||||
"""
|
||||
接收整理完成事件并读取本次整理结果。
|
||||
|
||||
:param event: 事件对象,event_data 保存整理完成后的业务数据
|
||||
"""
|
||||
event_data = event.event_data
|
||||
...
|
||||
```
|
||||
@@ -133,6 +173,14 @@ command. Oper methods only query, stage, or flush in that caller-owned Session.
|
||||
from app.application.subscription.write import SubscribeWriter
|
||||
|
||||
def create_subscription(writer: SubscribeWriter, identity: dict, payload: dict):
|
||||
"""
|
||||
通过应用写入服务创建订阅。
|
||||
|
||||
:param writer: 已完成依赖注入的订阅写入服务
|
||||
:param identity: 订阅媒体身份,用于确定订阅对象
|
||||
:param payload: 本次提交的订阅配置
|
||||
:return: 写入服务返回的创建结果,保留其成功或失败信息
|
||||
"""
|
||||
return writer.add(identity=identity, payload=payload)
|
||||
```
|
||||
|
||||
@@ -168,10 +216,18 @@ must not copy that form.
|
||||
|
||||
```python
|
||||
class MyChain(ChainBase, ConfigReloadMixin):
|
||||
"""
|
||||
在下载器配置变化后重新初始化模块。
|
||||
|
||||
:cvar CONFIG_WATCH: 触发重新初始化的下载器类型、地址和端口配置项
|
||||
"""
|
||||
|
||||
CONFIG_WATCH = {"DOWNLOADER", "QB_HOST", "QB_PORT"}
|
||||
|
||||
def on_config_changed(self):
|
||||
"""
|
||||
在受监控的配置项变化后刷新模块实例。
|
||||
"""
|
||||
self.init_module()
|
||||
```
|
||||
|
||||
@@ -189,6 +245,9 @@ class MyChain(ChainBase, ConfigReloadMixin):
|
||||
from app.foundation.singleton import Singleton
|
||||
|
||||
class MyManager(metaclass=Singleton):
|
||||
"""
|
||||
展示进程内共享同一管理器实例的声明方式。
|
||||
"""
|
||||
...
|
||||
```
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ are forbidden.
|
||||
- Retry logic
|
||||
|
||||
```python
|
||||
# Adapter implementation example; Application/Chain consume an injected Port instead.
|
||||
# 此处展示适配器实现;应用服务和业务链通过注入的接口访问网络能力
|
||||
from app.adapters.network.http import RequestUtils
|
||||
|
||||
res = RequestUtils(
|
||||
@@ -46,15 +46,15 @@ All REST API responses use Pydantic schema models from `app/schemas/`. Do not re
|
||||
### Standard Response Patterns
|
||||
|
||||
```python
|
||||
# Success with data
|
||||
# 成功响应携带业务结果
|
||||
from app.schemas.response import Response
|
||||
|
||||
return Response(success=True, message="", data=result)
|
||||
|
||||
# Success without data
|
||||
# 无业务结果时只返回成功状态和说明
|
||||
return Response(success=True, message="操作成功")
|
||||
|
||||
# Error
|
||||
# 失败响应保留可向调用方展示的原因
|
||||
return Response(success=False, message="错误原因描述")
|
||||
```
|
||||
|
||||
@@ -86,9 +86,12 @@ Do not raise `HTTPException` in chain or module code. Chains and modules return
|
||||
| Endpoint | Translate `None` or failure result into a `Response(success=False, ...)` or `HTTPException` |
|
||||
|
||||
```python
|
||||
# Module layer
|
||||
def test(self) -> Optional[Tuple[bool, str]]:
|
||||
"""测试模块连通性"""
|
||||
"""
|
||||
在模块层检查客户端连通性并归一化失败结果。
|
||||
|
||||
:return: 连接状态与说明组成的二元组;客户端异常会记录日志并转换为失败结果
|
||||
"""
|
||||
try:
|
||||
ok = self.client.ping()
|
||||
return (True, "连接成功") if ok else (False, "连接失败")
|
||||
|
||||
@@ -35,10 +35,10 @@ Models are SQLAlchemy declarative classes. Each model maps to one database table
|
||||
**Generating a migration:**
|
||||
|
||||
```bash
|
||||
# Auto-generate from model diff
|
||||
# 根据模型与数据库的差异生成迁移脚本
|
||||
alembic revision --autogenerate -m "describe the change"
|
||||
|
||||
# Create a blank migration for manual SQL
|
||||
# 创建空迁移脚本,以便填写需要手工控制的 SQL
|
||||
alembic revision -m "describe the change"
|
||||
```
|
||||
|
||||
@@ -252,9 +252,10 @@ with `--write-host`; never refresh it to accept newly introduced debt.
|
||||
```python
|
||||
with SessionFactory() as session:
|
||||
oper = SubscribeOper(session)
|
||||
subscribe = oper.get(sid=1) # Query in caller-owned Session
|
||||
subscribes = oper.list() # List in caller-owned Session
|
||||
oper.stage_add(Subscribe(...)) # Stage only; caller-owned UoW commits
|
||||
# 查询复用调用方的会话,新增操作只暂存,由调用方的工作单元提交
|
||||
subscribe = oper.get(sid=1)
|
||||
subscribes = oper.list()
|
||||
oper.stage_add(Subscribe(...))
|
||||
```
|
||||
|
||||
The following no-Session form is legacy plugin ABI only and must not be copied
|
||||
@@ -262,11 +263,11 @@ into host code:
|
||||
|
||||
```python
|
||||
oper = SubscribeOper()
|
||||
subscribe = oper.get(sid=1) # Get by primary key or filter
|
||||
subscribes = oper.list() # List all
|
||||
oper.add(Subscribe(...)) # Insert
|
||||
oper.update(sid=1, name="New Name") # Update by key
|
||||
oper.delete(sid=1) # Delete by key
|
||||
subscribe = oper.get(sid=1)
|
||||
subscribes = oper.list()
|
||||
oper.add(Subscribe(...))
|
||||
oper.update(sid=1, name="New Name")
|
||||
oper.delete(sid=1)
|
||||
```
|
||||
|
||||
---
|
||||
@@ -366,10 +367,8 @@ from app.schemas.types import SystemConfigKey
|
||||
|
||||
configuration = get_configured_system_config()
|
||||
|
||||
# Read
|
||||
rss_urls = configuration.get(SystemConfigKey.RssUrls)
|
||||
|
||||
# Write
|
||||
configuration.set(SystemConfigKey.RssUrls, ["https://example.com/rss"])
|
||||
```
|
||||
|
||||
@@ -449,6 +448,12 @@ cache = FileCache(cache_name="tmdb", ttl=3600)
|
||||
|
||||
@fresh(cache=cache, key_func=lambda tmdb_id: f"movie_{tmdb_id}")
|
||||
def get_movie_detail(tmdb_id: int) -> dict:
|
||||
"""
|
||||
查询电影详情,并由装饰器复用一小时内的文件缓存。
|
||||
|
||||
:param tmdb_id: 电影在 TMDB 中的原生标识,同时用于区分缓存项
|
||||
:return: 缓存命中时返回已缓存的详情,否则返回客户端查询结果
|
||||
"""
|
||||
return self._tmdb_client.get_movie(tmdb_id)
|
||||
```
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ Verification preparation below is the contributor default. Confirmed maintainers
|
||||
### What to Run
|
||||
|
||||
```bash
|
||||
# Minimum: run tests directly related to the change
|
||||
# 至少运行与本次改动直接相关的测试
|
||||
uv run --locked --no-sync pytest tests/test_<domain>.py
|
||||
|
||||
# If the change affects common modules, startup flow, CLI, or agent runtime
|
||||
# 改动影响公共模块、启动流程、CLI 或智能体运行行为时扩大测试范围
|
||||
uv run --locked --no-sync pytest
|
||||
```
|
||||
|
||||
@@ -44,7 +44,7 @@ Use the following as likely shared-impact boundaries. Run the full test suite wh
|
||||
## Static Analysis
|
||||
|
||||
```bash
|
||||
# Full application report; use the AGENTS.md selector for changed-file checks
|
||||
# 生成全应用检查报告;改动文件检查按 AGENTS.md 规定选择路径
|
||||
uv run --locked --no-sync pylint app/
|
||||
```
|
||||
|
||||
|
||||
@@ -131,8 +131,10 @@ When updating a dependency:
|
||||
The `moviepilot` CLI is the local-mode entrypoint. Its update path is:
|
||||
|
||||
```bash
|
||||
moviepilot update all # updates backend + frontend + resources
|
||||
moviepilot update backend # git pull + reinstall deps
|
||||
# 同时更新后端、前端和资源
|
||||
moviepilot update all
|
||||
# 拉取后端代码并重新安装依赖
|
||||
moviepilot update backend
|
||||
moviepilot update frontend
|
||||
```
|
||||
|
||||
|
||||
@@ -7,12 +7,18 @@
|
||||
pytest 是唯一运行入口。`tests/conftest.py` 在收集前完成隔离引导,因此任何方式启动 pytest 都会自动隔离。
|
||||
|
||||
```bash
|
||||
uv run --locked --no-sync pytest tests # 串行全量
|
||||
uv run --locked --no-sync pytest tests/test_xxx.py # 单文件
|
||||
uv run --locked --no-sync pytest tests/test_xxx.py::SomeTest::test_y # 单用例
|
||||
uv run --locked --no-sync python tests/run.py # 默认按文件预计耗时均衡为 4 片并行跑全量
|
||||
uv run --locked --no-sync python tests/run.py --serial # 串行全量,便于调试或生成覆盖率
|
||||
uv run --locked --no-sync python tests/run.py --shard 1/4 # 只跑指定分片,供 CI 复用
|
||||
# 串行全量
|
||||
uv run --locked --no-sync pytest tests
|
||||
# 单文件
|
||||
uv run --locked --no-sync pytest tests/test_xxx.py
|
||||
# 单用例
|
||||
uv run --locked --no-sync pytest tests/test_xxx.py::SomeTest::test_y
|
||||
# 默认按文件预计耗时均衡为 4 片并行跑全量
|
||||
uv run --locked --no-sync python tests/run.py
|
||||
# 串行全量,便于调试或生成覆盖率
|
||||
uv run --locked --no-sync python tests/run.py --serial
|
||||
# 只跑指定分片,供 CI 复用
|
||||
uv run --locked --no-sync python tests/run.py --shard 1/4
|
||||
```
|
||||
|
||||
`tests/run.py` 的 runner 参数只有 `--serial`、`--shard N/TOTAL` 和 `--exclude-architecture-gate`;其余参数保持原顺序
|
||||
@@ -199,11 +205,20 @@ from app.schemas.types import MediaSource
|
||||
|
||||
@pytest.fixture
|
||||
def sample_meta():
|
||||
"""构造一条可复用的识别元数据。"""
|
||||
"""
|
||||
构造一条可复用的识别元数据。
|
||||
|
||||
:return: 包含示例标题和年份的媒体识别输入
|
||||
"""
|
||||
return MetaInfo(title="示例 (2020)")
|
||||
|
||||
def test_recognize_prefers_explicit_identity(sample_meta, monkeypatch):
|
||||
"""显式媒体来源与原生 ID 时应优先精确识别,而非回退标题搜索。"""
|
||||
"""
|
||||
验证指定媒体来源与原生标识时优先精确识别。
|
||||
|
||||
:param sample_meta: 待识别的示例媒体输入
|
||||
:param monkeypatch: 隔离外部查询并在用例结束后恢复的测试夹具
|
||||
"""
|
||||
monkeypatch.setattr(SomeClient, "fetch", lambda *a, **k: FAKE_MOVIE)
|
||||
result = recognize(
|
||||
sample_meta,
|
||||
@@ -257,6 +272,16 @@ def test_recognize_prefers_explicit_identity(sample_meta, monkeypatch):
|
||||
_orig = socket.getaddrinfo
|
||||
hits = []
|
||||
def _spy(host, *a, **k):
|
||||
"""
|
||||
记录非本地主机的地址解析请求。
|
||||
|
||||
此探针只记录请求,仍调用真实解析函数;运行用例前须完成外部依赖隔离。
|
||||
|
||||
:param host: 待解析的主机名或地址
|
||||
:param a: 原样传给地址解析函数的位置参数
|
||||
:param k: 原样传给地址解析函数的关键字参数
|
||||
:return: 原始地址解析函数的返回值
|
||||
"""
|
||||
if host not in ("127.0.0.1", "localhost", "::1"):
|
||||
hits.append(str(host))
|
||||
return _orig(host, *a, **k)
|
||||
@@ -276,5 +301,5 @@ def test_recognize_prefers_explicit_identity(sample_meta, monkeypatch):
|
||||
- **跨仓观察**:`.github/workflows/architecture-observe.yml` 每周或手工检出官方插件仓最新 `main`,使用 `--check-plugins` 比较公开导入、Hook 和动态 API 契约。它只上传 `official-plugin-architecture-report.json`,不会自动刷新 fixture;语义变化必须人工审查后显式执行 `--write-plugins`。
|
||||
- **静态检查**:`.github/workflows/pylint.yml` 对指向 `v3` 的 PR、推送和手工触发运行 Pylint。PR/推送改动到的 Python 文件是硬门禁;`app/` 全量扫描保留为建议性 JSON 构建工件,存量告警不会掩盖或阻塞本次增量治理。
|
||||
- **PR 本地验证**:按上文「验证范围与维护者安排」选择 contributor 默认检查或已记录的维护者安排,统一处理证据复用与失败归属;需要断点、输出顺序或测试污染诊断时使用 `--serial`。确认受影响路径与零真实出站,准确标注验证范围;本地执行安排不改变 CI 的全量验证与复用合同。
|
||||
- **覆盖率门禁**:`Unit Tests with Coverage` jobs 会在 `v3` 的 PR、push 和手工触发中通过 `tests/run.py --exclude-architecture-gate --shard N/6` 并行采集覆盖率数据,`Coverage Report` 再合并全部分片并只读检查除 `app/plugins` 外全部 `app` Python 文件的逐文件低水位;已有文件覆盖率只能保持或提升,新文件必须达到至少 80%,同时上传 JSON / XML 工件。macOS 本地报告只用于诊断,不直接作为可提交基线。
|
||||
- **覆盖率门禁**:`Unit Tests with Coverage` jobs 会在 `v3` 的 PR、push 和手工触发中通过 `tests/run.py --exclude-architecture-gate --shard N/6` 并行采集覆盖率数据,`Coverage Report` 再合并全部分片并只读检查除 `app/plugins` 外全部 `app` Python 文件的逐文件低水位;已有文件覆盖率只能保持或提升,若可执行语句数减少且未覆盖行数不增加,也允许由此产生的比例下降;未覆盖行数增加仍判为回退。单独一行的 `...` 与 `pass` 一样属于无操作占位,不计入覆盖率,其他包含 `...` 的真实语句仍需覆盖。新文件必须达到至少 80%,同时上传 JSON / XML 工件。macOS 本地报告只用于诊断,不直接作为可提交基线。
|
||||
- 复现 CI 使用 `uv sync --locked`;主程序运行依赖位于 `[project].dependencies`,pytest 与覆盖率工具位于默认 `dev` 依赖组。
|
||||
|
||||
Reference in New Issue
Block a user