-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_command_classification_git.py
More file actions
198 lines (156 loc) · 6.97 KB
/
Copy pathtest_command_classification_git.py
File metadata and controls
198 lines (156 loc) · 6.97 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
"""Tests for git command classification primitives in _command_classification."""
from __future__ import annotations
import pytest
from autoskillit.hooks._command_classification import (
extract_git_subcommand_and_flags,
is_allowed_protected_path_metadata_command,
is_git_command,
)
pytestmark = [pytest.mark.layer("hooks"), pytest.mark.small]
class TestIsGitCommand:
def test_git_commit(self):
assert is_git_command(["git", "commit", "-m", "msg"]) is True
def test_gh_is_not_git(self):
assert is_git_command(["gh", "pr", "create"]) is False
def test_echo_is_not_git(self):
assert is_git_command(["echo", "git"]) is False
def test_full_path_git(self):
assert is_git_command(["/usr/bin/git", "status"]) is True
def test_full_path_local_git(self):
assert is_git_command(["/usr/local/bin/git", "push"]) is True
def test_empty_segment(self):
assert is_git_command([]) is False
def test_gitignore_is_not_git(self):
assert is_git_command(["gitignore", "status"]) is False
class TestExtractGitSubcommandAndFlags:
def test_simple_commit_amend(self):
result = extract_git_subcommand_and_flags(["git", "commit", "--amend"])
assert result == ("commit", ["--amend"])
def test_global_flag_with_value(self):
result = extract_git_subcommand_and_flags(
["git", "-C", "/path", "commit", "--amend", "--no-edit"]
)
assert result == ("commit", ["--amend", "--no-edit"])
def test_push_force_with_lease(self):
result = extract_git_subcommand_and_flags(["git", "push", "--force-with-lease"])
assert result == ("push", ["--force-with-lease"])
def test_add_flag(self):
result = extract_git_subcommand_and_flags(["git", "add", "-u"])
assert result == ("add", ["-u"])
def test_full_path_git_reset_hard(self):
result = extract_git_subcommand_and_flags(["/usr/bin/git", "reset", "--hard"])
assert result == ("reset", ["--hard"])
def test_no_pager_global_flag(self):
result = extract_git_subcommand_and_flags(["git", "--no-pager", "log"])
assert result == ("log", [])
def test_no_subcommand_returns_none(self):
result = extract_git_subcommand_and_flags(["git"])
assert result is None
def test_not_git_returns_none(self):
result = extract_git_subcommand_and_flags(["gh", "pr", "create"])
assert result is None
def test_git_c_flag_skips_value(self):
result = extract_git_subcommand_and_flags(["git", "-C", "/repo", "status"])
assert result == ("status", [])
def test_git_work_tree_skips_value(self):
result = extract_git_subcommand_and_flags(["git", "--work-tree", "/work", "checkout", "."])
assert result == ("checkout", ["."])
def test_git_bare_flag(self):
result = extract_git_subcommand_and_flags(["git", "--bare", "log"])
assert result == ("log", [])
class TestCheckIgnoreMetadataClassification:
"""Guard-compatibility fixture for the dry-walkthrough prescribed check-ignore form.
Binds `git check-ignore -v {path}` (SKILL.md:152) to
is_allowed_protected_path_metadata_command so the guard classifier and the
skill's committability contract cannot silently drift apart again.
"""
def test_prescribed_dry_walkthrough_form(self):
segment = ["git", "check-ignore", "-v", "src/autoskillit/recipes/remediation.yaml"]
assert is_allowed_protected_path_metadata_command(segment) is True
def test_verbose_long_flag(self):
segment = ["git", "check-ignore", "--verbose", "src/autoskillit/recipes/remediation.yaml"]
assert is_allowed_protected_path_metadata_command(segment) is True
def test_no_index_flag(self):
segment = [
"git",
"check-ignore",
"-v",
"--no-index",
"src/autoskillit/recipes/remediation.yaml",
]
assert is_allowed_protected_path_metadata_command(segment) is True
def test_double_dash_separator(self):
segment = ["git", "check-ignore", "-v", "--", "src/autoskillit/recipes/remediation.yaml"]
assert is_allowed_protected_path_metadata_command(segment) is True
def test_multiple_literal_paths(self):
segment = [
"git",
"check-ignore",
"-v",
"src/autoskillit/recipes/remediation.yaml",
"src/autoskillit/agents/explorer.md",
]
assert is_allowed_protected_path_metadata_command(segment) is True
def test_no_paths_is_denied(self):
assert is_allowed_protected_path_metadata_command(["git", "check-ignore", "-v"]) is False
def test_stdin_flag_denied(self):
segment = ["git", "check-ignore", "-v", "--stdin"]
assert is_allowed_protected_path_metadata_command(segment) is False
def test_quiet_flag_denied(self):
segment = ["git", "check-ignore", "-q", "src/autoskillit/recipes/remediation.yaml"]
assert is_allowed_protected_path_metadata_command(segment) is False
def test_global_c_flag_before_subcommand_denied(self):
segment = [
"git",
"-c",
"core.excludesFile=src/autoskillit/recipes/remediation.yaml",
"check-ignore",
"-v",
"src/autoskillit/recipes/remediation.yaml",
]
assert is_allowed_protected_path_metadata_command(segment) is False
def test_global_git_dir_flag_denied(self):
segment = [
"git",
"--git-dir",
"/tmp/.git",
"check-ignore",
"-v",
"src/autoskillit/recipes/remediation.yaml",
]
assert is_allowed_protected_path_metadata_command(segment) is False
def test_global_work_tree_flag_denied(self):
segment = [
"git",
"--work-tree",
"/tmp",
"check-ignore",
"-v",
"src/autoskillit/recipes/remediation.yaml",
]
assert is_allowed_protected_path_metadata_command(segment) is False
def test_bare_flag_denied(self):
segment = [
"git",
"--bare",
"check-ignore",
"-v",
"src/autoskillit/recipes/remediation.yaml",
]
assert is_allowed_protected_path_metadata_command(segment) is False
def test_redirect_target_denied(self):
segment = [
"git",
"check-ignore",
"-v",
"src/autoskillit/recipes/remediation.yaml",
">",
"/tmp/out",
]
assert is_allowed_protected_path_metadata_command(segment) is False
def test_shell_variable_path_denied(self):
segment = ["git", "check-ignore", "-v", "$VAR"]
assert is_allowed_protected_path_metadata_command(segment) is False
def test_content_bearing_subcommand_still_denied(self):
segment = ["git", "show", "HEAD:src/autoskillit/recipes/remediation.yaml"]
assert is_allowed_protected_path_metadata_command(segment) is False