mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-07 00:16:57 +08:00
fix(ci): isolate plugin market snapshot generator
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
import ast
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from app.adapters.external.market import extract_plugin_market_repos_from_wiki
|
||||
from scripts.generate_plugin_market_default import (
|
||||
OFFICIAL_PLUGIN_MARKET,
|
||||
_extract_plugin_market_repos_from_wiki,
|
||||
_generate_plugin_market_default,
|
||||
)
|
||||
|
||||
|
||||
ROOT_DIR = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def _read_plugin_market_default(config_file: Path) -> str:
|
||||
tree = ast.parse(config_file.read_text(encoding="utf-8"))
|
||||
for node in tree.body:
|
||||
@@ -37,9 +42,7 @@ def test_extract_plugin_market_repos_uses_marked_section_and_deduplicates() -> N
|
||||
- https://github.com/outside/ignored-again
|
||||
"""
|
||||
|
||||
assert extract_plugin_market_repos_from_wiki(
|
||||
markdown, require_markers=True
|
||||
) == [
|
||||
assert _extract_plugin_market_repos_from_wiki(markdown) == [
|
||||
OFFICIAL_PLUGIN_MARKET,
|
||||
"https://github.com/demo/Market",
|
||||
]
|
||||
@@ -50,9 +53,7 @@ def test_extract_plugin_market_repos_requires_unique_markers_for_build() -> None
|
||||
构建模式拒绝缺失或重复边界标记的 Wiki 文档。
|
||||
"""
|
||||
with pytest.raises(ValueError, match="唯一且有序的开始和结束标记"):
|
||||
extract_plugin_market_repos_from_wiki(
|
||||
f"- {OFFICIAL_PLUGIN_MARKET}", require_markers=True
|
||||
)
|
||||
_extract_plugin_market_repos_from_wiki(f"- {OFFICIAL_PLUGIN_MARKET}")
|
||||
|
||||
markdown = f"""
|
||||
<!-- plugin-market-repos:start -->
|
||||
@@ -61,7 +62,7 @@ def test_extract_plugin_market_repos_requires_unique_markers_for_build() -> None
|
||||
<!-- plugin-market-repos:end -->
|
||||
"""
|
||||
with pytest.raises(ValueError, match="唯一且有序的开始和结束标记"):
|
||||
extract_plugin_market_repos_from_wiki(markdown, require_markers=True)
|
||||
_extract_plugin_market_repos_from_wiki(markdown)
|
||||
|
||||
|
||||
def test_generate_plugin_market_default_updates_assignment_idempotently(
|
||||
@@ -127,3 +128,60 @@ def test_generate_plugin_market_default_requires_official_repo(
|
||||
|
||||
with pytest.raises(ValueError, match="缺少 MoviePilot 官方插件仓库"):
|
||||
_generate_plugin_market_default(wiki_file, config_file)
|
||||
|
||||
|
||||
def test_generate_plugin_market_default_runs_without_project_dependencies(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""发版脚本在禁用 site-packages 时仍应能独立生成默认配置。"""
|
||||
wiki_file = tmp_path / "plugin.md"
|
||||
wiki_file.write_text(
|
||||
f"""
|
||||
<!-- plugin-market-repos:start -->
|
||||
- {OFFICIAL_PLUGIN_MARKET}
|
||||
<!-- plugin-market-repos:end -->
|
||||
""",
|
||||
encoding="utf-8",
|
||||
)
|
||||
config_file = tmp_path / "config.py"
|
||||
config_file.write_text(
|
||||
'class ConfigModel:\n PLUGIN_MARKET: str = "old"\n',
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
result = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-S",
|
||||
"-m",
|
||||
"scripts.generate_plugin_market_default",
|
||||
"--wiki-file",
|
||||
str(wiki_file),
|
||||
"--config-file",
|
||||
str(config_file),
|
||||
],
|
||||
cwd=ROOT_DIR,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=30,
|
||||
check=False,
|
||||
)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert _read_plugin_market_default(config_file) == OFFICIAL_PLUGIN_MARKET
|
||||
|
||||
|
||||
def test_release_workflows_use_canonical_config_path() -> None:
|
||||
"""正式版和 Beta 发版流程必须修改并暂存 canonical 配置文件。"""
|
||||
build_workflow = (
|
||||
ROOT_DIR / ".github" / "workflows" / "build-v3.yml"
|
||||
).read_text(encoding="utf-8")
|
||||
beta_workflow = (
|
||||
ROOT_DIR / ".github" / "workflows" / "beta.yml"
|
||||
).read_text(encoding="utf-8")
|
||||
|
||||
assert "--config-file app/runtime/config.py" in build_workflow
|
||||
assert "git add app/runtime/config.py" in build_workflow
|
||||
assert "--config-file app/runtime/config.py" in beta_workflow
|
||||
assert "app/core/config.py" not in build_workflow
|
||||
assert "app/core/config.py" not in beta_workflow
|
||||
|
||||
Reference in New Issue
Block a user