Repository navigation
Expand file tree
/
Copy pathtest_opencode_package_install.py
More file actions
78 lines (60 loc) · 3.34 KB
/
Copy pathtest_opencode_package_install.py
File metadata and controls
78 lines (60 loc) · 3.34 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
"""Contract tests for the top-level OpenCode package installer."""
from __future__ import annotations
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "scripts"))
import install_opencode_package as installer # noqa: E402
def test_install_package_copies_generated_target(tmp_path) -> None:
counts = installer.install_package(tmp_path, setup=False)
assert counts == {"skills": 26, "agents": 19, "commands": 35, "plugins": 1}
assert (tmp_path / "plugins" / "opencode-seo" / "index.ts").is_file()
assert (tmp_path / "plugins" / "opencode-seo" / "package.json").is_file()
assert (tmp_path / "opencode-seo" / ".opencode-seo-root").is_file()
assert (tmp_path / "opencode-seo" / "scripts" / "runtime.py").is_file()
assert (tmp_path / "opencode-seo" / "hooks" / "validate-schema.py").is_file()
assert (tmp_path / "opencode-seo" / "package.json").is_file()
assert (tmp_path / "commands" / "seo.md").is_file()
assert (tmp_path / "commands" / "seo" / "audit.md").is_file()
assert len(list((tmp_path / "skills").glob("*/SKILL.md"))) == 26
assert len(list((tmp_path / "agents").glob("*.md"))) == 19
def test_install_package_skips_claude_only_payload(tmp_path) -> None:
installer.install_package(tmp_path, setup=False)
runtime = tmp_path / "opencode-seo"
# AGENTS.md is read from a project or config root, never from a nested
# runtime directory, so shipping it only confuses the payload.
assert not (runtime / "AGENTS.md").exists()
# The Claude hook manifest and its Node bridge are unused by the plugin.
assert not (runtime / "hooks" / "hooks.json").exists()
assert not (runtime / "hooks" / "run-python-hook.js").exists()
# The plugin calls runtime.py directly; launchers stay in the repository.
assert not (runtime / "scripts" / "claude-seo").exists()
assert not (runtime / "scripts" / "opencode-seo").exists()
assert not (runtime / "scripts" / "opencode-seo.ps1").exists()
assert not list(runtime.rglob("__pycache__"))
assert not list(runtime.rglob("*.pyc"))
def test_install_package_forwards_render_flags(tmp_path, monkeypatch) -> None:
seen: list[list[str]] = []
def fake_run(command, cwd=None, check=False):
seen.append(command)
return subprocess.CompletedProcess(command, 0)
monkeypatch.setattr(installer.subprocess, "run", fake_run)
installer.install_package(tmp_path, with_playwright=True)
assert seen[-1][-1] == "--playwright"
installer.install_package(tmp_path)
assert seen[-1][-1] == "--skip-browser"
installer.install_package(tmp_path, with_browser=True)
assert seen[-1][-1] == "setup"
def test_install_package_does_not_remove_user_skills(tmp_path) -> None:
user_skill = tmp_path / "skills" / "my-skill" / "SKILL.md"
user_skill.parent.mkdir(parents=True)
user_skill.write_text("---\nname: my-skill\ndescription: Mine\n---\n", encoding="utf-8")
installer.install_package(tmp_path, setup=False)
assert user_skill.is_file()
installer.uninstall_package(tmp_path)
assert user_skill.is_file()
assert not (tmp_path / "skills" / "seo" / "SKILL.md").exists()
assert not (tmp_path / "agents" / "seo-technical.md").exists()
assert not (tmp_path / "plugins" / "opencode-seo").exists()
assert not (tmp_path / "opencode-seo").exists()