-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathtest_update_versions.py
More file actions
158 lines (126 loc) · 5.9 KB
/
test_update_versions.py
File metadata and controls
158 lines (126 loc) · 5.9 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from __future__ import annotations
import importlib.util
import json
from pathlib import Path
import pytest
MODULE_PATH = Path(__file__).resolve().parents[1] / "scripts" / "update_versions.py"
SPEC = importlib.util.spec_from_file_location("update_versions", MODULE_PATH)
assert SPEC is not None
assert SPEC.loader is not None
update_versions = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(update_versions)
@pytest.mark.parametrize(
("version", "expected"),
[
("0.21.3", "0.21.3"),
("0.21.3b1", "0.21.3-beta.1"),
("0.21.3rc1", "0.21.3-rc.1"),
],
)
def test_npm_package_version_maps_python_prereleases(version: str, expected: str) -> None:
assert update_versions.npm_package_version(version) == expected
def test_parse_version_preserves_python_prerelease_for_non_npm_manifests() -> None:
assert update_versions.parse_version("v0.21.3b1") == "0.21.3b1"
def test_update_versions_writes_npm_semver_prerelease(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
) -> None:
def write(path: str, content: str) -> None:
target = tmp_path / path
target.parent.mkdir(parents=True, exist_ok=True)
target.write_text(content)
package_manifest = {"version": "0.0.0"}
marketplace_manifest = {
"metadata": {"version": "0.0.0"},
"plugins": [{"name": "basic-memory", "version": "0.0.0"}],
}
monkeypatch.setattr(update_versions, "ROOT", tmp_path)
write("src/basic_memory/__init__.py", '__version__ = "0.0.0"\n')
write(
"server.json",
json.dumps(
{
"version": "0.0.0",
"packages": [{"identifier": "basic-memory", "version": "0.0.0"}],
}
)
+ "\n",
)
write(".claude-plugin/marketplace.json", json.dumps(marketplace_manifest) + "\n")
write("plugins/claude-code/.claude-plugin/plugin.json", json.dumps(package_manifest) + "\n")
write(
"plugins/claude-code/.claude-plugin/marketplace.json",
json.dumps(marketplace_manifest) + "\n",
)
write("integrations/hermes/plugin.yaml", "version: 0.0.0\n")
write("integrations/hermes/__init__.py", '__version__ = "0.0.0"\n')
write("integrations/openclaw/package.json", json.dumps(package_manifest) + "\n")
write("plugins/codex/.codex-plugin/plugin.json", json.dumps(package_manifest) + "\n")
update_versions.update_versions("v0.21.3b1", dry_run=False)
assert (tmp_path / "src/basic_memory/__init__.py").read_text() == ('__version__ = "0.21.3b1"\n')
assert (tmp_path / "integrations/hermes/__init__.py").read_text() == (
'__version__ = "0.21.3b1"\n'
)
openclaw_package = json.loads((tmp_path / "integrations/openclaw/package.json").read_text())
assert openclaw_package["version"] == "0.21.3-beta.1"
codex_plugin = json.loads((tmp_path / "plugins/codex/.codex-plugin/plugin.json").read_text())
assert codex_plugin["version"] == "0.21.3-beta.1"
def _seed_repo(tmp_path: Path) -> None:
"""Write all version-bearing manifests at 0.0.0 under a fake repo root."""
def write(path: str, content: str) -> None:
target = tmp_path / path
target.parent.mkdir(parents=True, exist_ok=True)
target.write_text(content)
package_manifest = {"version": "0.0.0"}
marketplace_manifest = {
"metadata": {"version": "0.0.0"},
"plugins": [{"name": "basic-memory", "version": "0.0.0"}],
}
write("src/basic_memory/__init__.py", '__version__ = "0.0.0"\n')
write(
"server.json",
json.dumps(
{"version": "0.0.0", "packages": [{"identifier": "basic-memory", "version": "0.0.0"}]}
)
+ "\n",
)
write(".claude-plugin/marketplace.json", json.dumps(marketplace_manifest) + "\n")
write("plugins/claude-code/.claude-plugin/plugin.json", json.dumps(package_manifest) + "\n")
write(
"plugins/claude-code/.claude-plugin/marketplace.json",
json.dumps(marketplace_manifest) + "\n",
)
write("integrations/hermes/plugin.yaml", "version: 0.0.0\n")
write("integrations/hermes/__init__.py", '__version__ = "0.0.0"\n')
write("integrations/openclaw/package.json", json.dumps(package_manifest) + "\n")
write("plugins/codex/.codex-plugin/plugin.json", json.dumps(package_manifest) + "\n")
def _plugin_version(tmp_path: Path) -> str:
path = tmp_path / "plugins/claude-code/.claude-plugin/plugin.json"
return json.loads(path.read_text())["version"]
def _codex_plugin_version(tmp_path: Path) -> str:
path = tmp_path / "plugins/codex/.codex-plugin/plugin.json"
return json.loads(path.read_text())["version"]
def test_scope_packages_leaves_core_untouched(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
monkeypatch.setattr(update_versions, "ROOT", tmp_path)
_seed_repo(tmp_path)
update_versions.update_versions("v0.21.6", scope="packages", dry_run=False)
# Core stays put; only the agent/plugin artifacts move.
assert (tmp_path / "src/basic_memory/__init__.py").read_text() == '__version__ = "0.0.0"\n'
assert json.loads((tmp_path / "server.json").read_text())["version"] == "0.0.0"
assert _plugin_version(tmp_path) == "0.21.6"
assert _codex_plugin_version(tmp_path) == "0.21.6"
def test_scope_core_leaves_packages_untouched(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
monkeypatch.setattr(update_versions, "ROOT", tmp_path)
_seed_repo(tmp_path)
update_versions.update_versions("v0.21.6", scope="core", dry_run=False)
assert (tmp_path / "src/basic_memory/__init__.py").read_text() == '__version__ = "0.21.6"\n'
assert _plugin_version(tmp_path) == "0.0.0"
assert _codex_plugin_version(tmp_path) == "0.0.0"
def test_invalid_scope_raises(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
monkeypatch.setattr(update_versions, "ROOT", tmp_path)
with pytest.raises(SystemExit):
update_versions.update_versions("v0.21.6", scope="nonsense", dry_run=True)