Repository navigation
Expand file tree
/
Copy pathtest_agentify.py
More file actions
119 lines (112 loc) · 3.88 KB
/
Copy pathtest_agentify.py
File metadata and controls
119 lines (112 loc) · 3.88 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
import re
import tempfile
from pathlib import Path
from types import SimpleNamespace
from unittest import mock
import pytest
from diffpy.apps.app_agentify import agentify, ensure_setup
pytestmark = pytest.mark.skipif(
not ensure_setup(),
reason="Internet connection or git unavailable. Skipping agentify tests.",
allow_module_level=True,
)
@pytest.mark.parametrize(
"args, expected_scope, expected_skill_dir",
[
# C1: diffpy.apps agentify
# Deploys workspace claude skill.
# Expect skill folder is created in the current working directory.
(
SimpleNamespace(
agent="claude",
system=False,
update=False,
),
"cwd",
".claude/skills/diffpy-playbook",
),
# C2: diffpy.apps agentify --system
# Deploys system claude skill.
# Expect skill folder is created in the user's home directory.
(
SimpleNamespace(
agent="claude",
system=True,
update=False,
),
"home",
".claude/skills/diffpy-playbook",
),
# C3: diffpy.apps agentify --agent codex
# Deploys workspace codex skill.
# Expect skill folder is created in the current working directory.
(
SimpleNamespace(
agent="codex",
system=False,
update=False,
),
"cwd",
".codex/skills/diffpy-playbook",
),
# C4: diffpy.apps agentify --agent codex --system
# Deploys system codex skill.
# Expect skill folder is created in the user's home directory.
(
SimpleNamespace(
agent="codex",
system=True,
update=False,
),
"home",
".codex/skills/diffpy-playbook",
),
],
)
def test_agentify(args, expected_scope, expected_skill_dir):
with tempfile.TemporaryDirectory() as tmp:
with (
mock.patch.object(Path, "home", return_value=Path(tmp) / "home"),
mock.patch.object(Path, "cwd", return_value=Path(tmp) / "cwd"),
):
agentify(args)
expected_path = Path(tmp) / expected_scope / expected_skill_dir
assert expected_path.exists()
def test_agentify_update():
with tempfile.TemporaryDirectory() as tmp:
with (
mock.patch.object(Path, "home", return_value=Path(tmp) / "home"),
mock.patch.object(Path, "cwd", return_value=Path(tmp) / "cwd"),
):
# C1: Deploy again without --update flag when skill already exists.
# Expect FileExistsError to be raised, and the error message
# matches.
args = SimpleNamespace(
agent="claude",
system=False,
update=False,
)
agentify(args)
skill_path = (
Path(tmp) / "cwd" / ".claude" / "skills" / "diffpy-playbook"
)
assert skill_path.exists()
args.update = True
agentify(args)
pytest.raises(
FileExistsError,
match=re.escape(
"Agentic skill diffpy-playbook already exists at "
f"{skill_path}. "
"To overwrite, pass '--update' flag to update the skill"
),
)
# C2: Deploy again with --update flag when skill already exists
# with a dummy file in the skill directory.
# Expect no error to be raised, and the skill is updated.
dummy_file = skill_path / "dummy.txt"
dummy_file.touch()
assert dummy_file.exists()
args.update = True
agentify(args)
assert not dummy_file.exists()