perf:优化识图,缓解重复回复,使用原始插件manifest_id避免不一致情况
This commit is contained in:
@@ -61,3 +61,76 @@ def test_resolve_installed_plugin_path_accepts_manifest_id_case_mismatch(client:
|
||||
|
||||
assert plugin_path is not None
|
||||
assert plugin_path.name == "demo_plugin"
|
||||
|
||||
|
||||
def test_install_plugin_preserves_manifest_declared_id(client: TestClient, monkeypatch):
|
||||
class FakeGitMirrorService:
|
||||
async def clone_repository(self, **kwargs):
|
||||
target_path = kwargs["target_path"]
|
||||
target_path.mkdir(parents=True, exist_ok=True)
|
||||
(target_path / "_manifest.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"id": "author.declared",
|
||||
"name": "Declared Plugin",
|
||||
"version": "1.0.0",
|
||||
"author": {"name": "author"},
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
return {"success": True}
|
||||
|
||||
monkeypatch.setattr(management_module, "get_git_mirror_service", lambda: FakeGitMirrorService())
|
||||
|
||||
response = client.post(
|
||||
"/api/webui/plugins/install",
|
||||
json={
|
||||
"plugin_id": "market.plugin",
|
||||
"repository_url": "https://github.com/author/declared",
|
||||
"branch": "main",
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
plugin_path = support_module.resolve_installed_plugin_path("author.declared")
|
||||
assert plugin_path is not None
|
||||
manifest = json.loads((plugin_path / "_manifest.json").read_text(encoding="utf-8"))
|
||||
assert manifest["id"] == "author.declared"
|
||||
|
||||
|
||||
def test_install_plugin_backfills_missing_manifest_id(client: TestClient, monkeypatch):
|
||||
class FakeGitMirrorService:
|
||||
async def clone_repository(self, **kwargs):
|
||||
target_path = kwargs["target_path"]
|
||||
target_path.mkdir(parents=True, exist_ok=True)
|
||||
(target_path / "_manifest.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"name": "Legacy Plugin",
|
||||
"version": "1.0.0",
|
||||
"author": {"name": "author"},
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
return {"success": True}
|
||||
|
||||
monkeypatch.setattr(management_module, "get_git_mirror_service", lambda: FakeGitMirrorService())
|
||||
|
||||
response = client.post(
|
||||
"/api/webui/plugins/install",
|
||||
json={
|
||||
"plugin_id": "market.legacy",
|
||||
"repository_url": "https://github.com/author/legacy",
|
||||
"branch": "main",
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
plugin_path = support_module.resolve_installed_plugin_path("market.legacy")
|
||||
assert plugin_path is not None
|
||||
manifest = json.loads((plugin_path / "_manifest.json").read_text(encoding="utf-8"))
|
||||
assert manifest["id"] == "market.legacy"
|
||||
|
||||
Reference in New Issue
Block a user