-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathtest_extensions_ref.py
More file actions
91 lines (77 loc) · 2.8 KB
/
test_extensions_ref.py
File metadata and controls
91 lines (77 loc) · 2.8 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
"""Tests for EXTENSIONS_REF environment variable support.
These tests use subprocess to run each test in an isolated Python process,
avoiding module state pollution that would affect other tests.
"""
import subprocess
import sys
def _run_in_subprocess(test_code: str, env_extra: dict | None = None) -> None:
"""Run test code in a subprocess with the given environment variables."""
import os
env = os.environ.copy()
if env_extra:
env.update(env_extra)
result = subprocess.run(
[sys.executable, "-c", test_code],
env=env,
capture_output=True,
text=True,
)
if result.returncode != 0:
raise AssertionError(
f"Subprocess test failed:\nstdout: {result.stdout}\nstderr: {result.stderr}"
)
def test_extensions_ref_default():
"""PUBLIC_SKILLS_BRANCH should default to 'main' when EXTENSIONS_REF is not set."""
code = """
import os
if "EXTENSIONS_REF" in os.environ:
del os.environ["EXTENSIONS_REF"]
from openhands.sdk.context.skills.skill import PUBLIC_SKILLS_BRANCH
assert PUBLIC_SKILLS_BRANCH == "main", (
f"Expected 'main' but got '{PUBLIC_SKILLS_BRANCH}'"
)
"""
_run_in_subprocess(code)
def test_extensions_ref_custom_branch():
"""PUBLIC_SKILLS_BRANCH should use EXTENSIONS_REF when set."""
code = """
from openhands.sdk.context.skills.skill import PUBLIC_SKILLS_BRANCH
assert PUBLIC_SKILLS_BRANCH == "feature-branch", (
f"Expected 'feature-branch' but got '{PUBLIC_SKILLS_BRANCH}'"
)
"""
_run_in_subprocess(code, {"EXTENSIONS_REF": "feature-branch"})
def test_extensions_ref_with_load_public_skills():
"""load_public_skills should respect EXTENSIONS_REF environment variable."""
code = """
from unittest import mock
from openhands.sdk.context.skills.skill import (
PUBLIC_SKILLS_BRANCH,
load_public_skills,
)
assert PUBLIC_SKILLS_BRANCH == "test-branch", (
f"Expected 'test-branch' but got '{PUBLIC_SKILLS_BRANCH}'"
)
with mock.patch(
"openhands.sdk.context.skills.skill.update_skills_repository"
) as mock_update:
mock_update.return_value = None
load_public_skills()
mock_update.assert_called_once()
call_args = mock_update.call_args
# branch is 2nd positional arg: (repo_url, branch, cache_dir)
assert call_args[0][1] == "test-branch", (
f"Expected branch='test-branch' but got {call_args[0][1]}"
)
"""
_run_in_subprocess(code, {"EXTENSIONS_REF": "test-branch"})
def test_extensions_ref_empty_string():
"""Empty EXTENSIONS_REF should fall back to 'main'."""
code = """
from openhands.sdk.context.skills.skill import PUBLIC_SKILLS_BRANCH
# Empty string returns empty string per os.environ.get behavior
assert PUBLIC_SKILLS_BRANCH == "", (
f"Expected '' but got '{PUBLIC_SKILLS_BRANCH}'"
)
"""
_run_in_subprocess(code, {"EXTENSIONS_REF": ""})