Repository navigation
Expand file tree
/
Copy pathtest_opencode_extension_install.py
More file actions
117 lines (92 loc) · 4.31 KB
/
Copy pathtest_opencode_extension_install.py
File metadata and controls
117 lines (92 loc) · 4.31 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
"""Contract tests for the native OpenCode extension installer."""
from __future__ import annotations
import argparse
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "scripts"))
import install_opencode_extension as installer # noqa: E402
def args_for(extension: str, **overrides) -> argparse.Namespace:
values = {
"extension": extension,
"username": "user@example.com",
"password": "secret",
"key": "test-key",
"url": None,
"site_id": None,
"env": None,
"dry_run": False,
}
values.update(overrides)
return argparse.Namespace(**values)
def test_strip_jsonc_keeps_strings_and_removes_comments() -> None:
text = """{
// comment
"url": "https://example.com/a//b",
"items": [1, 2,],
/* block */
}"""
parsed = json.loads(installer.strip_jsonc(text))
assert parsed["url"] == "https://example.com/a//b"
assert parsed["items"] == [1, 2]
def test_dataforseo_installs_skill_agent_and_mcp(tmp_path, monkeypatch) -> None:
monkeypatch.setenv("OPENCODE_CONFIG_DIR", str(tmp_path))
installer.build_extension("dataforseo", args_for("dataforseo"))
skill = tmp_path / "skills" / "seo-dataforseo" / "SKILL.md"
agent = tmp_path / "agents" / "seo-dataforseo.md"
assert skill.is_file()
assert agent.is_file()
skill_text = skill.read_text(encoding="utf-8")
assert "${CLAUDE_PLUGIN_ROOT}" not in skill_text
assert 'seo({"action": "run"' in skill_text
assert "user-invocable" not in skill_text
agent_text = agent.read_text(encoding="utf-8")
assert "mode: subagent" in agent_text
assert 'action: "seo"' in agent_text
assert "maxTurns" not in agent_text
config = json.loads((tmp_path / "opencode.json").read_text(encoding="utf-8"))
server = config["mcp"]["servers"]["dataforseo"]
assert server["type"] == "local"
assert server["codemode"] is False
assert server["environment"]["DATAFORSEO_USERNAME"] == "user@example.com"
assert Path(server["environment"]["FIELD_CONFIG_PATH"]).is_file()
def test_banana_transforms_extension_runner_and_references(tmp_path, monkeypatch) -> None:
monkeypatch.setenv("OPENCODE_CONFIG_DIR", str(tmp_path))
installer.build_extension("banana", args_for("banana"))
skill = tmp_path / "skills" / "seo-image-gen" / "SKILL.md"
text = skill.read_text(encoding="utf-8")
assert '"extension": "banana"' in text
assert "CLAUDE_SKILL_DIR" not in text
assert (tmp_path / "skills" / "seo-image-gen" / "references" / "prompt-engineering.md").is_file()
assert (tmp_path / "opencode-seo" / "extensions" / "banana" / "scripts" / "generate.py").is_file()
config = json.loads((tmp_path / "opencode.json").read_text(encoding="utf-8"))
assert "nanobanana-mcp" in config["mcp"]["servers"]
def test_matomo_writes_to_the_opencode_config_location(tmp_path, monkeypatch) -> None:
monkeypatch.setenv("OPENCODE_CONFIG_DIR", str(tmp_path / "opencode"))
monkeypatch.delenv("OPENCODE_SEO_CONFIG_DIR", raising=False)
monkeypatch.delenv("CLAUDE_SEO_CONFIG_DIR", raising=False)
installer.build_extension(
"matomo",
args_for("matomo", url="https://analytics.example.com", site_id="1"),
)
saved = tmp_path / "opencode-seo" / "matomo.json"
assert saved.is_file()
payload = json.loads(saved.read_text(encoding="utf-8"))
assert payload["matomo_url"] == "https://analytics.example.com"
assert payload["matomo_token"] == "test-key"
assert not (tmp_path / "opencode" / "opencode.json").exists(), (
"Matomo is a REST API and must not be registered as an MCP server"
)
def test_jsonc_config_is_merged_without_losing_keys(tmp_path, monkeypatch) -> None:
monkeypatch.setenv("OPENCODE_CONFIG_DIR", str(tmp_path))
config_path = tmp_path / "opencode.jsonc"
config_path.write_text(
'{\n // keep this value\n "model": "deepseek/deepseek-flash",\n "permissions": [],\n}\n',
encoding="utf-8",
)
installer.build_extension("firecrawl", args_for("firecrawl"))
document = json.loads((tmp_path / "opencode.jsonc").read_text(encoding="utf-8"))
assert document["model"] == "deepseek/deepseek-flash"
assert "firecrawl" in document["mcp"]["servers"]
assert (tmp_path / "opencode.jsonc.bak").is_file()