-
Notifications
You must be signed in to change notification settings - Fork 674
Expand file tree
/
Copy pathtest_v3_dependency_install_gate.py
More file actions
122 lines (98 loc) · 4.17 KB
/
Copy pathtest_v3_dependency_install_gate.py
File metadata and controls
122 lines (98 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""V3 插件依赖真实安装门禁测试。"""
from __future__ import annotations
import importlib.util
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[2]
INSTALL_SCRIPT = REPO_ROOT / "scripts/check_v3_dependency_install.py"
PR_WORKFLOW = REPO_ROOT / ".github/workflows/plugin-gate.yml"
def _load_install_module():
"""按文件路径导入安装门禁脚本。"""
spec = importlib.util.spec_from_file_location(
"check_v3_dependency_install",
INSTALL_SCRIPT,
)
module = importlib.util.module_from_spec(spec)
assert spec and spec.loader
sys.modules[spec.name] = module
spec.loader.exec_module(module)
return module
def test_manifest_discovery_covers_every_v3_pyproject() -> None:
"""门禁必须自动覆盖全部 V3 modern manifest。"""
module = _load_install_module()
expected = sorted((REPO_ROOT / "plugins.v3").glob("*/pyproject.toml"))
assert expected
assert module.discover_manifests() == expected
def test_manifest_platforms_default_to_product_matrix() -> None:
"""未声明窄平台的普通插件必须覆盖 V3 标准五平台。"""
module = _load_install_module()
manifest = REPO_ROOT / "plugins.v3/agentresourceofficer/pyproject.toml"
assert module.manifest_platforms(manifest) == module.SUPPORTED_PLATFORMS
def test_animeupscale_dependency_gate_matches_linux_cuda_contract() -> None:
"""AnimeUpscale 的大体积 CUDA 依赖只在真实支持的 Linux x64 安装。"""
module = _load_install_module()
manifest = REPO_ROOT / "plugins.v3/animeupscale/pyproject.toml"
assert module.manifest_platforms(manifest) == frozenset({"linux-x64"})
def test_installation_uses_fresh_environment_and_host_manifest_semantics(
tmp_path: Path,
) -> None:
"""安装命令必须面向隔离解释器并通过 -r 消费原始 pyproject。"""
module = _load_install_module()
environment = tmp_path / ".venv"
manifest = REPO_ROOT / "plugins.v3/agentresourceofficer/pyproject.toml"
create, install, healthcheck = module.installation_commands(
uv_bin="uv",
python_spec="3.14",
environment=environment,
manifest=manifest,
windows=False,
)
python_bin = environment / "bin/python"
assert create == ["uv", "venv", "--python", "3.14", str(environment)]
assert install == [
"uv",
"pip",
"install",
"--python",
str(python_bin),
"-r",
str(manifest),
]
assert healthcheck == ["uv", "pip", "check", "--python", str(python_bin)]
def test_windows_environment_uses_scripts_python(tmp_path: Path) -> None:
"""Windows runner 必须把依赖安装到目标 venv,而不是 runner 全局环境。"""
module = _load_install_module()
assert module.venv_python(tmp_path / ".venv", windows=True) == (
tmp_path / ".venv/Scripts/python.exe"
)
def test_workflow_runs_scoped_five_platform_install_matrix() -> None:
"""PR 门禁应在相关变更时按平台执行真实安装脚本。"""
workflow = PR_WORKFLOW.read_text(encoding="utf-8")
job_start = workflow.index(" plugin-dependency-install-gate:")
job_end = len(workflow)
install_job = workflow[job_start:job_end]
expected_targets = {
"ubuntu-latest": "linux-x64",
"ubuntu-24.04-arm": "linux-arm64",
"windows-latest": "windows-x64",
"macos-15-intel": "macos-x64",
"macos-15": "macos-arm64",
}
for runner, platform in expected_targets.items():
assert f"os: {runner}" in install_job
assert f"platform: {platform}" in install_job
assert "runs-on: ${{ matrix.os }}" in install_job
assert "fetch-depth: 0" in install_job
assert (
'git diff --quiet "${{ github.event.pull_request.base.sha }}" HEAD'
in install_job
)
for pathspec in (
"plugins.v3/*/pyproject.toml",
"scripts/check_v3_dependency_install.py",
"tests/ci/test_v3_dependency_install_gate.py",
".github/workflows/plugin-gate.yml",
):
assert pathspec in install_job
assert "steps.dependency-scope.outputs.run == 'true'" in install_job
assert "--platform \"${{ matrix.platform }}\"" in install_job