Skip to content

fix(market): include plugin_dependencies in build_market_plugin_payload - #3

Open
fuilyha56-wq wants to merge 1 commit into
MoFox-Studio:masterfrom
fuilyha56-wq:fix/market-plugin-dependencies-payload
Open

fuilyha56-wq wants to merge 1 commit into
MoFox-Studio:masterfrom
fuilyha56-wq:fix/market-plugin-dependencies-payload

Conversation

@fuilyha56-wq

@fuilyha56-wq fuilyha56-wq commented Aug 10, 2026

Copy link
Copy Markdown

问题

mpdt market publish 发布插件后,市场公开端点 /api/v1/plugins/{plugin_id}/dependencies 一直为空,作者必须在首次发布后手动 PUT /api/v1/plugins/{plugin_id} 提交 plugin_dependencies 才能让详情页显示依赖约束。

已确认根因:ManifestManager.build_market_plugin_payload() 构建的注册 payload 没有包含 manifest.dependencies.plugins,尽管:

  • 同类已有 get_plugin_dependencies() 辅助方法;
  • 市场 API PluginCreate schema 明确接受 plugin_dependencies: array[string] 字段;
  • PluginUpdate 也接受 plugin_dependencies
  • 公开端点 /api/v1/plugins/{plugin_id}/dependencies 读取该字段。

影响版本:0.6.5 及当前 master(0.6.6)均存在。

修复

build_market_plugin_payload() 的返回字典中新增 plugin_dependencies,复用已有的 get_plugin_dependencies() 读取 manifest.dependencies.plugins。缺失时返回空列表,与 OpenAPI schema 默认值一致。

plugin_dependencies = list(self.get_plugin_dependencies())

return {
    ...
    "maintainers": maintainer_list,
    "plugin_dependencies": plugin_dependencies,
    "readme_markdown": readme_markdown,
}

测试

新增两条单测覆盖:

  • test_build_market_plugin_payload_includes_plugin_dependencies:manifest 声明 dependencies.plugins 时 payload 正确透传(含版本约束 >=1.0.13)。
  • test_build_market_plugin_payload_defaults_dependencies_to_empty:manifest 无 dependencies 时 payload 中 plugin_dependencies == []
tests\test_manifest_manager.py ...                                       [100%]
============================== 3 passed in 0.73s ==============================

ruff check tests/test_manifest_manager.py 通过;manifest_manager.py 的既有 W292 报错与本次改动无关(均为模板字典/文档字符串,master 上已存在)。

兼容性

  • 纯增量字段,不改变既有字段语义;
  • 后端 PluginCreate 已接受该字段,注册请求无需额外变更;
  • 已注册插件升级到新版本 mpdt 后,下次 package-update 仍走版本提交路径;若需同步已有条目的依赖,可继续用 PUTmpdt market 后续命令补充(本次不改动 package-update 路径,避免扩大改动面)。

Summary by Sourcery

Include plugin dependency metadata in market plugin registration payload and add tests to cover the new behavior.

Bug Fixes:

  • Populate plugin_dependencies in the market plugin registration payload so published plugins expose their dependency constraints via the API.

Tests:

  • Add tests verifying plugin_dependencies are propagated from manifest dependencies.plugins and default to an empty list when unspecified.

ManifestManager.build_market_plugin_payload() did not map
manifest.dependencies.plugins to the PluginCreate.plugin_dependencies
field of the market register API. As a result, plugins published via
'mpdt market publish' registered with an empty dependencies endpoint
(/api/v1/plugins/{id}/dependencies), and authors had to PUT the
dependencies manually after every first publish.

Reuse the existing get_plugin_dependencies() helper so the dependency
specs (e.g. 'onebot_expand>=1.0.13') are forwarded during registration.
Defaults to an empty list when dependencies.plugins is absent, matching
the OpenAPI schema default.

Add unit tests covering both the populated and empty-dependency cases.
@sourcery-ai

sourcery-ai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds propagation of manifest-declared plugin dependencies into the market plugin registration payload and covers it with tests to ensure correct transmission and default behavior when dependencies are absent.

Sequence diagram for including plugin_dependencies in market plugin payload

sequenceDiagram
    actor User
    participant MpdtCLI
    participant ManifestManager
    participant MarketAPI

    User->>MpdtCLI: mpdt_market_publish
    MpdtCLI->>ManifestManager: build_market_plugin_payload
    ManifestManager->>ManifestManager: get_plugin_dependencies
    ManifestManager-->>MpdtCLI: payload_with_plugin_dependencies
    MpdtCLI->>MarketAPI: POST_api_v1_plugins(payload_with_plugin_dependencies)
    MarketAPI-->>MpdtCLI: PluginCreate_response
    Note over MarketAPI: plugin_dependencies stored

    User->>MarketAPI: GET_api_v1_plugins_plugin_id_dependencies
    MarketAPI-->>User: plugin_dependencies_list
Loading

File-Level Changes

Change Details Files
Include plugin dependency information from the manifest in the market plugin registration payload.
  • Call existing get_plugin_dependencies() inside build_market_plugin_payload() to read manifest.dependencies.plugins.
  • Convert the returned dependencies to a list and assign it to a local plugin_dependencies variable, defaulting to an empty list when dependencies are missing.
  • Add plugin_dependencies field into the returned payload dictionary so it is sent to the market API and exposed via downstream endpoints.
mpdt/utils/managers/manifest_manager.py
Add unit tests ensuring plugin_dependencies are correctly populated in the payload and default to an empty list.
  • Add test that creates a manifest with dependencies.plugins and asserts payload.plugin_dependencies contains the specified values including version constraints.
  • Add test that creates a manifest without dependencies and asserts payload.plugin_dependencies is an empty list.
  • Preserve and slightly refactor the existing README-related test to keep full coverage of build_market_version_payload().
tests/test_manifest_manager.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/test_manifest_manager.py" line_range="55-64" />
<code_context>
+    )
+
+    manager = ManifestManager(plugin_dir)
+    payload = manager.build_market_plugin_payload(
+        repository_url="https://github.com/test/deps_plugin"
+    )
+
+    assert payload["plugin_dependencies"] == [
+        "onebot_expand>=1.0.13",
+        "neo_fatum_chatter",
+    ]
+
+
+def test_build_market_plugin_payload_defaults_dependencies_to_empty(tmp_path) -> None:
+    plugin_dir = tmp_path / "no_deps_plugin"
+    plugin_dir.mkdir()
+    (plugin_dir / "manifest.json").write_text(
+        json.dumps(
+            {
+                "name": "no_deps_plugin",
+                "version": "1.0.0",
+                "description": "plugin without deps",
+                "author": "tester",
+            }
+        ),
+        encoding="utf-8",
+    )
+
+    manager = ManifestManager(plugin_dir)
+    payload = manager.build_market_plugin_payload(
+        repository_url="https://github.com/test/no_deps_plugin"
+    )
+
</code_context>
<issue_to_address>
**issue (testing):** Add an assertion to verify `plugin_dependencies` defaults to an empty list

This test constructs the payload but never checks `plugin_dependencies`. Please add an assertion that it defaults to an empty list so the regression is explicitly covered, e.g.:

```python
assert payload["plugin_dependencies"] == []
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +55 to +64
payload = manager.build_market_plugin_payload(
repository_url="https://github.com/test/deps_plugin"
)

assert payload["plugin_dependencies"] == [
"onebot_expand>=1.0.13",
"neo_fatum_chatter",
]


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (testing): Add an assertion to verify plugin_dependencies defaults to an empty list

This test constructs the payload but never checks plugin_dependencies. Please add an assertion that it defaults to an empty list so the regression is explicitly covered, e.g.:

assert payload["plugin_dependencies"] == []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant