Repository navigation
Expand file tree
/
Copy pathtest_opencode_env_aliases.py
More file actions
76 lines (56 loc) · 2.9 KB
/
Copy pathtest_opencode_env_aliases.py
File metadata and controls
76 lines (56 loc) · 2.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
"""OpenCode environment aliases keep the new names first and the old names usable."""
from __future__ import annotations
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "scripts"))
import google_auth # noqa: E402
import runtime # noqa: E402
import url_safety # noqa: E402
def test_opencode_google_auth_wins(monkeypatch) -> None:
monkeypatch.setenv("OPENCODE_SEO_GOOGLE_AUTH", "adc")
monkeypatch.setenv("CLAUDE_SEO_GOOGLE_AUTH", "service-account")
assert google_auth._prefers_gcloud() is True
def test_legacy_google_auth_still_works(monkeypatch) -> None:
monkeypatch.delenv("OPENCODE_SEO_GOOGLE_AUTH", raising=False)
monkeypatch.setenv("CLAUDE_SEO_GOOGLE_AUTH", "adc")
assert google_auth._prefers_gcloud() is True
def test_opencode_local_targets_wins(monkeypatch) -> None:
monkeypatch.setenv("OPENCODE_SEO_LOCAL_TARGETS", "example.com:8080")
monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", "legacy.example:9090")
assert ("example.com", 8080) in url_safety._local_targets()
def test_legacy_local_targets_still_works(monkeypatch) -> None:
monkeypatch.delenv("OPENCODE_SEO_LOCAL_TARGETS", raising=False)
monkeypatch.setenv("CLAUDE_SEO_LOCAL_TARGETS", "legacy.example:9090")
assert ("legacy.example", 9090) in url_safety._local_targets()
def test_opencode_data_dir_wins(monkeypatch, tmp_path) -> None:
root = tmp_path / "root"
root.mkdir()
monkeypatch.setenv("OPENCODE_SEO_DATA_DIR", str(tmp_path / "new-data"))
monkeypatch.setenv("CLAUDE_SEO_DATA_DIR", str(tmp_path / "old-data"))
data_dir, mode = runtime._data_dir(root)
assert mode == "override"
assert data_dir == (tmp_path / "new-data").resolve()
def test_legacy_data_dir_still_works(monkeypatch, tmp_path) -> None:
root = tmp_path / "root"
root.mkdir()
monkeypatch.delenv("OPENCODE_SEO_DATA_DIR", raising=False)
monkeypatch.setenv("CLAUDE_SEO_DATA_DIR", str(tmp_path / "old-data"))
data_dir, mode = runtime._data_dir(root)
assert mode == "override"
assert data_dir == (tmp_path / "old-data").resolve()
def test_opencode_root_uses_opencode_product_name(monkeypatch, tmp_path) -> None:
monkeypatch.setenv("OPENCODE_SEO_ROOT", str(tmp_path))
assert runtime._product() == "OpenCode SEO"
assert runtime._python_env_name() == "OPENCODE_SEO_PYTHON"
def test_opencode_root_marker_selects_plugin_mode(monkeypatch, tmp_path) -> None:
root = tmp_path / "root"
root.mkdir()
(root / ".opencode-seo-root").write_text("marker\n", encoding="utf-8")
monkeypatch.delenv("OPENCODE_SEO_DATA_DIR", raising=False)
monkeypatch.delenv("CLAUDE_SEO_DATA_DIR", raising=False)
monkeypatch.delenv("CLAUDE_PLUGIN_DATA", raising=False)
monkeypatch.delenv("OPENCODE_SEO_ROOT", raising=False)
monkeypatch.delenv("CLAUDE_PLUGIN_ROOT", raising=False)
_, mode = runtime._data_dir(root)
assert mode == "plugin-fallback"