@elvis1513/auto-coding-skill 5.1.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/cli/assets/managed-install.json +5 -5
- package/cli/assets/skill/SKILL.md +13 -38
- package/cli/assets/skill/data/templates/PROJECT.md +10 -29
- package/cli/assets/skill/data/templates/bridges/AGENTS.md +26 -97
- package/cli/assets/skill/references/parallel-development.md +37 -59
- package/cli/src/check-package.js +3 -2
- package/cli/src/diagnostics.js +121 -0
- package/cli/src/index.js +29 -5
- package/package.json +4 -2
- package/src/git-workflow/guard.py +451 -0
- package/src/git-workflow/test_guard.py +341 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
"""Hermetic Git fixtures only: no product builds, network or target services."""
|
|
2
|
+
import json
|
|
3
|
+
import importlib.util
|
|
4
|
+
import os
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
import tempfile
|
|
9
|
+
import unittest
|
|
10
|
+
from unittest.mock import patch
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
GUARD = Path(__file__).with_name("guard.py").resolve()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class VersionGateReached(Exception):
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class VersionGateTests(unittest.TestCase):
|
|
21
|
+
def setUp(self):
|
|
22
|
+
spec = importlib.util.spec_from_file_location("guard_version_fixture", GUARD)
|
|
23
|
+
self.guard = importlib.util.module_from_spec(spec)
|
|
24
|
+
spec.loader.exec_module(self.guard)
|
|
25
|
+
|
|
26
|
+
def test_supported_git_version_variants_reach_the_installation_boundary(self):
|
|
27
|
+
for text in ("git version 2.38.0", "git version 2.50.1.windows.1", "git version 2.39.5 (Apple Git-154)", "git version 2.51.0-rc0", "git version 10.0.GIT"):
|
|
28
|
+
with self.subTest(text=text), patch.object(self.guard, "value", return_value=text), patch.object(self.guard, "state_dir", side_effect=VersionGateReached):
|
|
29
|
+
with self.assertRaises(VersionGateReached):
|
|
30
|
+
self.guard.install()
|
|
31
|
+
|
|
32
|
+
def test_unsupported_or_malformed_versions_never_reach_installation(self):
|
|
33
|
+
for text in ("git version 2.37.9", "", "unrelated 2.50", "9" * 50000, "git version " + "9" * 50000):
|
|
34
|
+
with self.subTest(text=text[:40]), patch.object(self.guard, "value", return_value=text), patch.object(self.guard, "state_dir") as stage:
|
|
35
|
+
with self.assertRaises(self.guard.Rejected):
|
|
36
|
+
self.guard.install()
|
|
37
|
+
stage.assert_not_called()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class GuardTest(unittest.TestCase):
|
|
41
|
+
def setUp(self):
|
|
42
|
+
scratch = GUARD.parents[2] / ".local" / "git-workflow-guard-tests"
|
|
43
|
+
scratch.mkdir(parents=True, exist_ok=True)
|
|
44
|
+
self.temp = tempfile.TemporaryDirectory(prefix="fixture-", dir=scratch)
|
|
45
|
+
self.addCleanup(self.temp.cleanup)
|
|
46
|
+
self.root = Path(self.temp.name)
|
|
47
|
+
self.main = self.root / "main"
|
|
48
|
+
self.remote = self.root / "remote.git"
|
|
49
|
+
self.env = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")}
|
|
50
|
+
self.env.update(GIT_CONFIG_GLOBAL=os.devnull, GIT_CONFIG_NOSYSTEM="1",
|
|
51
|
+
GIT_TERMINAL_PROMPT="0", PYTHONDONTWRITEBYTECODE="1")
|
|
52
|
+
self.run_git(self.root, "init", "--bare", str(self.remote))
|
|
53
|
+
self.run_git(self.root, "init", "-b", "dev", str(self.main))
|
|
54
|
+
self.run_git(self.main, "config", "user.name", "Guard Fixture")
|
|
55
|
+
self.run_git(self.main, "config", "user.email", "guard-fixture@example.invalid")
|
|
56
|
+
self.run_git(self.main, "config", "commit.gpgsign", "false")
|
|
57
|
+
self.run_git(self.main, "remote", "add", "origin", str(self.remote))
|
|
58
|
+
self.commit(self.main, "seed")
|
|
59
|
+
self.run_git(self.main, "push", "-u", "origin", "dev")
|
|
60
|
+
self.base = self.run_git(self.main, "rev-parse", "HEAD").stdout.strip()
|
|
61
|
+
|
|
62
|
+
def run_cmd(self, cwd, *args, ok=True, input=None):
|
|
63
|
+
result = subprocess.run(args, cwd=cwd, env=self.env, text=True,
|
|
64
|
+
input=input, capture_output=True)
|
|
65
|
+
if ok:
|
|
66
|
+
self.assertEqual(result.returncode, 0, result.stderr)
|
|
67
|
+
else:
|
|
68
|
+
self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr)
|
|
69
|
+
return result
|
|
70
|
+
|
|
71
|
+
def run_git(self, cwd, *args, **kwargs):
|
|
72
|
+
return self.run_cmd(cwd, "git", *args, **kwargs)
|
|
73
|
+
|
|
74
|
+
def install(self):
|
|
75
|
+
return self.run_cmd(self.main, sys.executable, str(GUARD), "install")
|
|
76
|
+
|
|
77
|
+
def task(self, name="task"):
|
|
78
|
+
path = self.root / name
|
|
79
|
+
self.run_git(self.main, "worktree", "add", "-b", "codex/" + name,
|
|
80
|
+
str(path), "origin/dev")
|
|
81
|
+
return path
|
|
82
|
+
|
|
83
|
+
def commit(self, cwd, name, *options, ok=True):
|
|
84
|
+
(cwd / (name + ".txt")).write_text(name + "\n")
|
|
85
|
+
self.run_git(cwd, "add", "--", name + ".txt")
|
|
86
|
+
return self.run_git(cwd, "commit", *options, "-m", name, ok=ok)
|
|
87
|
+
|
|
88
|
+
def test_dev_commit_blocked_and_index_preserved(self):
|
|
89
|
+
self.install()
|
|
90
|
+
result = self.commit(self.main, "blocked", ok=False)
|
|
91
|
+
self.assertIn("independent", result.stderr)
|
|
92
|
+
self.assertEqual(self.run_git(self.main, "rev-parse", "HEAD").stdout.strip(), self.base)
|
|
93
|
+
self.assertIn("blocked.txt", self.run_git(self.main, "diff", "--cached", "--name-only").stdout)
|
|
94
|
+
|
|
95
|
+
def test_dev_no_verify_still_blocked_by_reference_transaction(self):
|
|
96
|
+
self.install()
|
|
97
|
+
result = self.commit(self.main, "blocked", "--no-verify", ok=False)
|
|
98
|
+
self.assertIn("Direct development on dev", result.stderr)
|
|
99
|
+
self.assertEqual(self.run_git(self.main, "rev-parse", "HEAD").stdout.strip(), self.base)
|
|
100
|
+
|
|
101
|
+
def test_codex_branch_in_primary_checkout_is_not_isolation(self):
|
|
102
|
+
self.install()
|
|
103
|
+
self.run_git(self.main, "switch", "-c", "codex/fake")
|
|
104
|
+
self.commit(self.main, "blocked", ok=False)
|
|
105
|
+
self.commit(self.main, "blocked", "--no-verify", ok=False)
|
|
106
|
+
|
|
107
|
+
def test_linked_non_codex_and_detached_commits_blocked(self):
|
|
108
|
+
self.install()
|
|
109
|
+
path = self.root / "other"
|
|
110
|
+
self.run_git(self.main, "worktree", "add", "-b", "feature/other", str(path), "origin/dev")
|
|
111
|
+
self.commit(path, "blocked", ok=False)
|
|
112
|
+
self.run_git(path, "restore", "--staged", "blocked.txt")
|
|
113
|
+
self.run_git(path, "switch", "--detach", "HEAD")
|
|
114
|
+
self.commit(path, "blocked", ok=False)
|
|
115
|
+
|
|
116
|
+
def test_codex_worktree_commit_and_push_to_dev(self):
|
|
117
|
+
self.install()
|
|
118
|
+
path = self.task()
|
|
119
|
+
self.commit(path, "allowed")
|
|
120
|
+
self.run_git(path, "push", "origin", "HEAD:refs/heads/dev")
|
|
121
|
+
self.run_git(self.main, "merge", "--ff-only", "origin/dev")
|
|
122
|
+
self.assertTrue((self.main / "allowed.txt").is_file())
|
|
123
|
+
|
|
124
|
+
def test_primary_fast_forward_then_push(self):
|
|
125
|
+
self.install()
|
|
126
|
+
path = self.task()
|
|
127
|
+
self.commit(path, "allowed")
|
|
128
|
+
self.run_git(self.main, "merge", "--ff-only", "codex/task")
|
|
129
|
+
self.run_git(self.main, "push", "origin", "dev")
|
|
130
|
+
|
|
131
|
+
def test_pure_no_ff_integration_allowed(self):
|
|
132
|
+
self.install()
|
|
133
|
+
path = self.task()
|
|
134
|
+
self.commit(path, "allowed")
|
|
135
|
+
self.run_git(self.main, "merge", "--no-ff", "codex/task", "-m", "integrate task")
|
|
136
|
+
self.run_git(self.main, "push", "origin", "dev")
|
|
137
|
+
|
|
138
|
+
def test_extra_content_in_dev_merge_is_blocked(self):
|
|
139
|
+
self.install()
|
|
140
|
+
path = self.task()
|
|
141
|
+
self.commit(path, "allowed")
|
|
142
|
+
self.run_git(self.main, "merge", "--no-ff", "--no-commit", "codex/task")
|
|
143
|
+
self.commit(self.main, "unrelated", ok=False)
|
|
144
|
+
self.commit(self.main, "unrelated", "--no-verify", ok=False)
|
|
145
|
+
|
|
146
|
+
def test_preexisting_isolated_task_is_preserved(self):
|
|
147
|
+
path = self.task()
|
|
148
|
+
self.commit(path, "already-working")
|
|
149
|
+
before = self.run_git(path, "rev-parse", "HEAD").stdout
|
|
150
|
+
self.install()
|
|
151
|
+
self.assertEqual(before, self.run_git(path, "rev-parse", "HEAD").stdout)
|
|
152
|
+
self.run_git(path, "push", "origin", "HEAD:dev")
|
|
153
|
+
|
|
154
|
+
def test_preexisting_primary_dev_commit_is_not_grandfathered(self):
|
|
155
|
+
self.commit(self.main, "direct-dev")
|
|
156
|
+
self.install()
|
|
157
|
+
self.run_git(self.main, "push", "origin", "dev", ok=False)
|
|
158
|
+
|
|
159
|
+
def test_dev_delete_and_rewrite_blocked(self):
|
|
160
|
+
self.install()
|
|
161
|
+
path = self.task()
|
|
162
|
+
self.commit(path, "allowed")
|
|
163
|
+
self.run_git(self.main, "merge", "--ff-only", "codex/task")
|
|
164
|
+
self.run_git(self.main, "update-ref", "refs/heads/dev", self.base, ok=False)
|
|
165
|
+
self.run_git(self.main, "update-ref", "-d", "refs/heads/dev", ok=False)
|
|
166
|
+
self.run_git(path, "push", "origin", ":dev", ok=False)
|
|
167
|
+
|
|
168
|
+
def test_amend_and_rebase_keep_provenance(self):
|
|
169
|
+
self.install()
|
|
170
|
+
path = self.task()
|
|
171
|
+
self.commit(path, "one")
|
|
172
|
+
self.commit(path, "two", "--amend")
|
|
173
|
+
other = self.task("other")
|
|
174
|
+
self.commit(other, "remote-change")
|
|
175
|
+
self.run_git(other, "push", "origin", "HEAD:dev")
|
|
176
|
+
self.run_git(path, "rebase", "origin/dev")
|
|
177
|
+
self.run_git(path, "push", "origin", "HEAD:dev")
|
|
178
|
+
|
|
179
|
+
def test_merge_latest_dev_into_task(self):
|
|
180
|
+
self.install()
|
|
181
|
+
path, other = self.task(), self.task("other")
|
|
182
|
+
self.commit(path, "one")
|
|
183
|
+
self.commit(other, "other")
|
|
184
|
+
self.run_git(other, "push", "origin", "HEAD:dev")
|
|
185
|
+
self.run_git(path, "merge", "--no-edit", "origin/dev")
|
|
186
|
+
self.run_git(path, "push", "origin", "HEAD:dev")
|
|
187
|
+
|
|
188
|
+
def test_stale_push_requires_reconciliation(self):
|
|
189
|
+
self.install()
|
|
190
|
+
path, other = self.task(), self.task("other")
|
|
191
|
+
self.commit(path, "one")
|
|
192
|
+
self.commit(other, "other")
|
|
193
|
+
self.run_git(other, "push", "origin", "HEAD:dev")
|
|
194
|
+
self.run_git(path, "push", "--force", "origin", "HEAD:dev", ok=False)
|
|
195
|
+
|
|
196
|
+
def test_existing_hook_runs_and_can_reject(self):
|
|
197
|
+
hook_dir = self.main / "config" / "hooks"
|
|
198
|
+
hook_dir.mkdir(parents=True)
|
|
199
|
+
(hook_dir / "pre-commit").write_text("#!/bin/sh\necho original-hook >&2\nexit 19\n")
|
|
200
|
+
(hook_dir / "pre-commit").chmod(0o755)
|
|
201
|
+
self.run_git(self.main, "add", "config/hooks/pre-commit")
|
|
202
|
+
self.run_git(self.main, "commit", "-m", "original hook")
|
|
203
|
+
self.run_git(self.main, "push", "origin", "dev")
|
|
204
|
+
self.run_git(self.main, "config", "core.hooksPath", "config/hooks")
|
|
205
|
+
self.install()
|
|
206
|
+
path = self.task()
|
|
207
|
+
result = self.commit(path, "blocked-by-original", ok=False)
|
|
208
|
+
self.assertIn("original-hook", result.stderr)
|
|
209
|
+
self.run_cmd(self.main, sys.executable, str(GUARD), "uninstall")
|
|
210
|
+
self.assertEqual(self.run_git(self.main, "config", "core.hooksPath").stdout.strip(), "config/hooks")
|
|
211
|
+
self.assertTrue((hook_dir / "pre-commit").is_file())
|
|
212
|
+
|
|
213
|
+
def test_install_preserves_other_worktree_dirty_files(self):
|
|
214
|
+
path = self.task()
|
|
215
|
+
(path / "unfinished.txt").write_text("owned by another conversation\n")
|
|
216
|
+
self.run_git(path, "add", "unfinished.txt")
|
|
217
|
+
before = self.run_git(path, "status", "--porcelain").stdout
|
|
218
|
+
self.install()
|
|
219
|
+
self.assertEqual(before, self.run_git(path, "status", "--porcelain").stdout)
|
|
220
|
+
self.assertEqual((path / "unfinished.txt").read_text(), "owned by another conversation\n")
|
|
221
|
+
|
|
222
|
+
def test_existing_pre_push_receives_original_stdin(self):
|
|
223
|
+
hook = self.main / ".git/hooks/pre-push"
|
|
224
|
+
hook.write_text("#!/bin/sh\nread local_ref local_sha remote_ref remote_sha\n"
|
|
225
|
+
'[ "$remote_ref" = refs/heads/dev ] || exit 31\n'
|
|
226
|
+
"echo chained-pre-push >&2\n")
|
|
227
|
+
hook.chmod(0o755)
|
|
228
|
+
self.install()
|
|
229
|
+
path = self.task()
|
|
230
|
+
self.commit(path, "allowed")
|
|
231
|
+
result = self.run_git(path, "push", "origin", "HEAD:dev")
|
|
232
|
+
self.assertIn("chained-pre-push", result.stderr)
|
|
233
|
+
|
|
234
|
+
def test_fast_forward_from_another_clone_is_allowed(self):
|
|
235
|
+
self.install()
|
|
236
|
+
clone = self.root / "remote-developer"
|
|
237
|
+
self.run_git(self.root, "clone", "--branch", "dev", str(self.remote), str(clone))
|
|
238
|
+
self.run_git(clone, "config", "user.name", "Other Fixture")
|
|
239
|
+
self.run_git(clone, "config", "user.email", "other@example.invalid")
|
|
240
|
+
self.commit(clone, "remote-only")
|
|
241
|
+
self.run_git(clone, "push", "origin", "dev")
|
|
242
|
+
self.run_git(self.main, "fetch", "origin", "dev")
|
|
243
|
+
self.run_git(self.main, "merge", "--ff-only", "origin/dev")
|
|
244
|
+
|
|
245
|
+
def test_idempotent_install_status_and_uninstall(self):
|
|
246
|
+
self.install()
|
|
247
|
+
first = self.run_git(self.main, "config", "core.hooksPath").stdout
|
|
248
|
+
self.install()
|
|
249
|
+
self.assertEqual(first, self.run_git(self.main, "config", "core.hooksPath").stdout)
|
|
250
|
+
status = self.run_cmd(self.main, sys.executable, str(GUARD), "status")
|
|
251
|
+
self.assertTrue(json.loads(status.stdout)["ok"])
|
|
252
|
+
self.run_cmd(self.main, sys.executable, str(GUARD), "uninstall")
|
|
253
|
+
self.assertEqual(self.run_git(self.main, "config", "--get", "core.hooksPath", ok=False).returncode, 1)
|
|
254
|
+
|
|
255
|
+
def test_new_task_push_inherits_already_accepted_remote_dev(self):
|
|
256
|
+
self.install()
|
|
257
|
+
clone = self.root / "remote-maintenance"
|
|
258
|
+
self.run_git(self.root, "clone", "--branch", "dev", str(self.remote), str(clone))
|
|
259
|
+
self.run_git(clone, "config", "user.name", "Remote Fixture")
|
|
260
|
+
self.run_git(clone, "config", "user.email", "remote@example.invalid")
|
|
261
|
+
self.commit(clone, "remote-maintenance")
|
|
262
|
+
self.run_git(clone, "push", "origin", "dev")
|
|
263
|
+
self.run_git(self.main, "fetch", "origin", "dev")
|
|
264
|
+
path = self.task()
|
|
265
|
+
self.commit(path, "isolated-feature")
|
|
266
|
+
self.run_git(path, "push", "origin", "HEAD:refs/heads/codex/task")
|
|
267
|
+
other = self.root / "other.git"
|
|
268
|
+
self.run_git(self.root, "init", "--bare", str(other))
|
|
269
|
+
self.run_git(self.main, "remote", "add", "other", str(other))
|
|
270
|
+
rejected = self.run_git(path, "push", "other", "HEAD:refs/heads/codex/task", ok=False)
|
|
271
|
+
self.assertIn("Unverified commit origin", rejected.stderr)
|
|
272
|
+
|
|
273
|
+
def test_new_task_push_still_rejects_unverified_new_commits(self):
|
|
274
|
+
self.install()
|
|
275
|
+
path = self.task()
|
|
276
|
+
self.commit(path, "isolated-feature")
|
|
277
|
+
tree = self.run_git(path, "write-tree").stdout.strip()
|
|
278
|
+
parent = self.run_git(path, "rev-parse", "HEAD").stdout.strip()
|
|
279
|
+
unverified = self.run_git(path, "commit-tree", tree, "-p", parent,
|
|
280
|
+
"-m", "uncertified fixture").stdout.strip()
|
|
281
|
+
self.run_git(path, "update-ref", "refs/heads/codex/task", unverified)
|
|
282
|
+
result = self.run_git(path, "push", "origin", "HEAD:refs/heads/codex/task", ok=False)
|
|
283
|
+
self.assertIn("Unverified commit origin", result.stderr)
|
|
284
|
+
|
|
285
|
+
def test_pack_refs_and_maintenance_leave_exact_live_heads(self):
|
|
286
|
+
self.install()
|
|
287
|
+
path = self.task()
|
|
288
|
+
self.commit(path, "isolated")
|
|
289
|
+
before = self.run_git(self.main, "show-ref", "--heads").stdout
|
|
290
|
+
self.run_git(self.main, "pack-refs", "--all")
|
|
291
|
+
self.assertFalse((self.main / ".git/refs/heads/dev").exists())
|
|
292
|
+
self.run_git(self.main, "maintenance", "run", "--task=pack-refs")
|
|
293
|
+
self.assertEqual(self.run_git(self.main, "show-ref", "--heads").stdout, before)
|
|
294
|
+
self.commit(path, "second")
|
|
295
|
+
updated = self.run_git(path, "rev-parse", "HEAD").stdout
|
|
296
|
+
self.run_git(self.main, "pack-refs", "--all")
|
|
297
|
+
self.assertEqual(self.run_git(path, "rev-parse", "HEAD").stdout, updated)
|
|
298
|
+
|
|
299
|
+
def test_protect_dev_deletion_with_loose_packed_and_both(self):
|
|
300
|
+
self.install()
|
|
301
|
+
for mode in ("loose", "both", "packed"):
|
|
302
|
+
if mode != "loose":
|
|
303
|
+
self.run_git(self.main, "pack-refs", "--all", *(["--no-prune"] if mode == "both" else []))
|
|
304
|
+
for old in ([], [self.base]):
|
|
305
|
+
with self.subTest(mode=mode, old=bool(old)):
|
|
306
|
+
result = self.run_git(self.main, "update-ref", "-d", "refs/heads/dev", *old, ok=False)
|
|
307
|
+
self.assertIn("blocked", result.stderr)
|
|
308
|
+
self.assertEqual(self.run_git(self.main, "rev-parse", "dev").stdout.strip(), self.base)
|
|
309
|
+
|
|
310
|
+
def test_new_clone_does_not_inherit_local_installation(self):
|
|
311
|
+
self.install()
|
|
312
|
+
clone = self.root / "ci-clone"
|
|
313
|
+
self.run_git(self.root, "clone", "--branch", "dev", str(self.remote), str(clone))
|
|
314
|
+
self.run_git(clone, "config", "--get", "core.hooksPath", ok=False)
|
|
315
|
+
self.assertFalse((clone / ".git/codex-workflow-guard").exists())
|
|
316
|
+
|
|
317
|
+
def test_upgrade_preserves_receipts_prior_hooks_and_dirty_task(self):
|
|
318
|
+
self.install()
|
|
319
|
+
task = self.task()
|
|
320
|
+
self.commit(task, "receipt")
|
|
321
|
+
(task / "pending").write_text("still editing")
|
|
322
|
+
root = self.main / ".git/codex-workflow-guard"
|
|
323
|
+
statefile = root / "state.json"
|
|
324
|
+
old = json.loads(statefile.read_text())
|
|
325
|
+
receipts = {p.name: p.read_bytes() for p in (root / "commits").iterdir()}
|
|
326
|
+
statefile.write_text(json.dumps({**old, "version": 1}))
|
|
327
|
+
self.install()
|
|
328
|
+
state = json.loads(statefile.read_text())
|
|
329
|
+
self.assertEqual(state["version"], 2)
|
|
330
|
+
for key in ("baseline", "previous_hooks", "previous_local"):
|
|
331
|
+
self.assertEqual(old[key], state[key])
|
|
332
|
+
self.assertEqual(receipts, {p.name: p.read_bytes() for p in (root / "commits").iterdir()})
|
|
333
|
+
self.assertEqual((task / "pending").read_text(), "still editing")
|
|
334
|
+
hook = Path(state["hooks_path"]) / "pre-commit"
|
|
335
|
+
hook.write_text("#!/bin/sh\nexit 0\n")
|
|
336
|
+
report = self.run_cmd(self.main, sys.executable, str(GUARD), "status", ok=False)
|
|
337
|
+
self.assertFalse(json.loads(report.stdout)["hooks_match"])
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
if __name__ == "__main__":
|
|
341
|
+
unittest.main()
|