@christang/keel 5.221.0 → 5.223.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/.claude-plugin/plugin.json +1 -1
- package/README.md +16 -7
- package/README.zh-CN.md +12 -6
- package/assets/bootstrap/AGENTS.md +1 -1
- package/bin/keel.js +16 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/plugins/keel/.claude-plugin/plugin.json +1 -1
- package/plugins/keel/.codex-plugin/plugin.json +1 -1
- package/plugins/keel/commands/feedback.md +38 -0
- package/plugins/keel/scripts/pretooluse-guard.js +63 -13
- package/scripts/validation/common.py +2 -2
- package/scripts/validation/docs.py +2 -2
- package/scripts/validation/feedback.py +324 -0
- package/scripts/validation/guard.py +177 -0
- package/scripts/validation/hosts.py +1 -1
- package/scripts/validation/registry.py +11 -0
- package/src/core/config.js +23 -2
- package/src/core/feedback.js +286 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"""Issue #505: `keel feedback` drafts, redacts, searches and (under a declaration or a confirmation) creates."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
import shutil
|
|
8
|
+
import subprocess
|
|
9
|
+
import tempfile
|
|
10
|
+
from contextlib import contextmanager
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from validation.common import ROOT, report, run_keel, write_authorize_config, write_text
|
|
14
|
+
|
|
15
|
+
KEEL_REPO = "TanglmChris/keel"
|
|
16
|
+
CREATED_URL = f"https://github.com/{KEEL_REPO}/issues/999"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def version() -> str:
|
|
20
|
+
return json.loads((ROOT / "package.json").read_text(encoding="utf-8"))["version"]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def secret(*parts: str) -> str:
|
|
24
|
+
"""Join pieces so this file holds no literal that looks like a credential."""
|
|
25
|
+
return "".join(parts)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@contextmanager
|
|
29
|
+
def feedback_world(prefix: str, *, with_gh: bool = True):
|
|
30
|
+
"""A scratch git project that is not Keel, a stub `gh`, and an environment that finds both.
|
|
31
|
+
|
|
32
|
+
Yields `(project, env, log, bin_dir)`. The stub logs its arguments, prints
|
|
33
|
+
`list.json` for `issue list` and a fixed URL for `issue create`, and with a
|
|
34
|
+
`fail` file beside it prints `gh: not logged in` and exits 1.
|
|
35
|
+
"""
|
|
36
|
+
with tempfile.TemporaryDirectory(prefix=prefix) as raw:
|
|
37
|
+
base = Path(raw).resolve()
|
|
38
|
+
project = base / "secret-project-name"
|
|
39
|
+
project.mkdir()
|
|
40
|
+
for args in (["init", "-q", "-b", "main"], ["config", "user.email", "t@example.invalid"], ["config", "user.name", "t"]):
|
|
41
|
+
subprocess.run(["git", *args], cwd=project, check=True, capture_output=True)
|
|
42
|
+
home = base / "home"
|
|
43
|
+
home.mkdir()
|
|
44
|
+
bin_dir = base / "stub-bin"
|
|
45
|
+
bin_dir.mkdir()
|
|
46
|
+
for tool in ("node", "git", "cat"):
|
|
47
|
+
found = shutil.which(tool)
|
|
48
|
+
(bin_dir / tool).symlink_to(found)
|
|
49
|
+
log = base / "gh.log"
|
|
50
|
+
if with_gh:
|
|
51
|
+
script = bin_dir / "gh"
|
|
52
|
+
script.write_text(
|
|
53
|
+
"#!/bin/sh\n"
|
|
54
|
+
f'echo "$*" >> "{log}"\n'
|
|
55
|
+
'case "$1 $2" in\n'
|
|
56
|
+
f' "issue list"|"issue create") if [ -f "{bin_dir}/fail" ]; then echo "gh: not logged in" >&2; exit 1; fi ;;\n'
|
|
57
|
+
"esac\n"
|
|
58
|
+
'case "$1 $2" in\n'
|
|
59
|
+
f' "issue list") cat "{bin_dir}/list.json" ;;\n'
|
|
60
|
+
f' "issue create") echo "{CREATED_URL}" ;;\n'
|
|
61
|
+
"esac\n",
|
|
62
|
+
encoding="utf-8",
|
|
63
|
+
)
|
|
64
|
+
script.chmod(0o755)
|
|
65
|
+
write_text(bin_dir / "list.json", "[]")
|
|
66
|
+
env = {k: v for k, v in os.environ.items() if not k.startswith(("CLAUDE", "KEEL_"))}
|
|
67
|
+
env["PATH"] = str(bin_dir)
|
|
68
|
+
env["HOME"] = str(home)
|
|
69
|
+
yield project, env, log, bin_dir
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def gh_log(log: Path) -> str:
|
|
73
|
+
return log.read_text(encoding="utf-8") if log.exists() else ""
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def saved_file(stdout: str) -> Path | None:
|
|
77
|
+
match = re.search(r"^Saved: (\S+)$", stdout, re.MULTILINE)
|
|
78
|
+
return Path(match.group(1)) if match else None
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def validate_feedback_draft_scenario() -> int:
|
|
82
|
+
"""Issue #505: a draft carries the version, the command and its output, and creates nothing."""
|
|
83
|
+
label = "feedback-draft:"
|
|
84
|
+
with feedback_world("keel-feedback-draft-") as (project, env, log, _bin):
|
|
85
|
+
write_text(project / "out.txt", "keel gate: FAILED no task 1.1 in the change\n")
|
|
86
|
+
result = run_keel(
|
|
87
|
+
project, "feedback", "gate refuses a valid task",
|
|
88
|
+
"--command", "keel gate task-start", "--output-file", "out.txt",
|
|
89
|
+
"--expected", "the gate passes", "--repro", "run it in the project", "--impact", "blocks the work",
|
|
90
|
+
env=env,
|
|
91
|
+
)
|
|
92
|
+
if result.returncode != 0:
|
|
93
|
+
report(f"{label} exit {result.returncode}: {result.stdout}{result.stderr}")
|
|
94
|
+
return 1
|
|
95
|
+
out = result.stdout
|
|
96
|
+
needles = (
|
|
97
|
+
version(), "keel gate task-start", "no task 1.1 in the change", "gate refuses a valid task",
|
|
98
|
+
"现象", "期望", "复现", "证据", "影响", "环境", "the gate passes", "blocks the work",
|
|
99
|
+
)
|
|
100
|
+
missing = [n for n in needles if n not in out]
|
|
101
|
+
if missing:
|
|
102
|
+
report(f"{label} the draft lacks {missing!r}: {out}")
|
|
103
|
+
return 1
|
|
104
|
+
saved = saved_file(out)
|
|
105
|
+
if saved is None:
|
|
106
|
+
report(f"{label} the draft does not name the file it saved: {out}")
|
|
107
|
+
return 1
|
|
108
|
+
if not saved.exists():
|
|
109
|
+
report(f"{label} the file {saved} the draft names does not exist.")
|
|
110
|
+
return 1
|
|
111
|
+
if "no task 1.1 in the change" not in saved.read_text(encoding="utf-8"):
|
|
112
|
+
report(f"{label} the saved file does not hold the output: {saved}")
|
|
113
|
+
return 1
|
|
114
|
+
if "issue create" in gh_log(log):
|
|
115
|
+
report(f"{label} a draft without --create asked gh to create an issue: {gh_log(log)}")
|
|
116
|
+
return 1
|
|
117
|
+
for private in ("secret-project-name", "origin"):
|
|
118
|
+
if private in out:
|
|
119
|
+
report(f"{label} the draft holds {private!r}, project content nobody asked to publish: {out}")
|
|
120
|
+
return 1
|
|
121
|
+
report("feedback-draft scenario passed.")
|
|
122
|
+
return 0
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def validate_feedback_redacts_scenario() -> int:
|
|
126
|
+
"""Issue #505: tokens, Slack IDs, e-mail, credentials and local paths never reach the draft."""
|
|
127
|
+
label = "feedback-redacts:"
|
|
128
|
+
with feedback_world("keel-feedback-redact-") as (project, env, log, _bin):
|
|
129
|
+
home = Path(env["HOME"])
|
|
130
|
+
secrets = {
|
|
131
|
+
"a GitHub token": secret("gh", "p_", "a1B2c3D4e5F6g7H8i9J0k1L2m3N4o5P6q7R8"),
|
|
132
|
+
"a Slack bot token": secret("xo", "xb-", "1234567890-abcdefghijklmnop"),
|
|
133
|
+
"a Slack user ID": secret("U", "01ABC", "DE23F"),
|
|
134
|
+
"a bearer credential": secret("Bearer ", "abcdef0123456789zz"),
|
|
135
|
+
"a key=value secret": secret("hunt", "er2"),
|
|
136
|
+
"an e-mail address": secret("someone", "@", "example.org"),
|
|
137
|
+
"a URL password": secret("pa", "ssw0rd9"),
|
|
138
|
+
}
|
|
139
|
+
lines = [
|
|
140
|
+
f"token was {secrets['a GitHub token']} and {secrets['a Slack bot token']}",
|
|
141
|
+
f"posted as {secrets['a Slack user ID']} to the channel",
|
|
142
|
+
f"Authorization: {secrets['a bearer credential']}",
|
|
143
|
+
f"API_KEY={secrets['a key=value secret']}",
|
|
144
|
+
f"contact {secrets['an e-mail address']}",
|
|
145
|
+
f"clone https://deploy:{secrets['a URL password']}@git.example.org/x.git",
|
|
146
|
+
f"read {home}/notes/private.txt and {project}/src/a.js",
|
|
147
|
+
"The Gate refused TASK 12 at line 4 with UNREADABLE input",
|
|
148
|
+
]
|
|
149
|
+
write_text(project / "out.txt", "\n".join(lines) + "\n")
|
|
150
|
+
result = run_keel(project, "feedback", "output leaks", "--output-file", "out.txt", env=env)
|
|
151
|
+
if result.returncode != 0:
|
|
152
|
+
report(f"{label} exit {result.returncode}: {result.stdout}{result.stderr}")
|
|
153
|
+
return 1
|
|
154
|
+
saved = saved_file(result.stdout)
|
|
155
|
+
if saved is None or not saved.exists():
|
|
156
|
+
report(f"{label} no saved file: {result.stdout}")
|
|
157
|
+
return 1
|
|
158
|
+
shown = result.stdout + saved.read_text(encoding="utf-8")
|
|
159
|
+
for what, value in secrets.items():
|
|
160
|
+
if value in shown:
|
|
161
|
+
report(f"{label} {what} reached the draft or the saved file: {value!r}")
|
|
162
|
+
return 1
|
|
163
|
+
if not re.search(r"[Rr]edacted \d+", result.stdout):
|
|
164
|
+
report(f"{label} the draft does not report how many values it redacted: {result.stdout}")
|
|
165
|
+
return 1
|
|
166
|
+
for expected in ("~/notes/private.txt", "<project>/src/a.js"):
|
|
167
|
+
if expected not in shown:
|
|
168
|
+
report(f"{label} the draft lacks the shortened path {expected!r}: {shown}")
|
|
169
|
+
return 1
|
|
170
|
+
if "The Gate refused TASK 12 at line 4 with UNREADABLE input" not in shown:
|
|
171
|
+
report(f"{label} ordinary prose was changed by the redaction: {shown}")
|
|
172
|
+
return 1
|
|
173
|
+
report("feedback-redacts scenario passed.")
|
|
174
|
+
return 0
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def validate_feedback_duplicates_scenario() -> int:
|
|
178
|
+
"""Issue #505: near-duplicates are listed first, and Keel runs no comment."""
|
|
179
|
+
label = "feedback-duplicates:"
|
|
180
|
+
with feedback_world("keel-feedback-dup-") as (project, env, log, bin_dir):
|
|
181
|
+
write_text(bin_dir / "list.json", json.dumps([
|
|
182
|
+
{"number": 12, "title": "the push guard refuses a tag", "state": "OPEN", "url": f"https://github.com/{KEEL_REPO}/issues/12"},
|
|
183
|
+
]))
|
|
184
|
+
result = run_keel(project, "feedback", "push guard refuses tag pushes", env=env)
|
|
185
|
+
if result.returncode != 0:
|
|
186
|
+
report(f"{label} exit {result.returncode}: {result.stdout}{result.stderr}")
|
|
187
|
+
return 1
|
|
188
|
+
for needle in ("#12", "the push guard refuses a tag", f"https://github.com/{KEEL_REPO}/issues/12", "gh issue comment 12"):
|
|
189
|
+
if needle not in result.stdout:
|
|
190
|
+
report(f"{label} the draft lacks {needle!r}: {result.stdout}")
|
|
191
|
+
return 1
|
|
192
|
+
recorded = gh_log(log)
|
|
193
|
+
if f"issue list --repo {KEEL_REPO}" not in recorded:
|
|
194
|
+
report(f"{label} the duplicate search was not run against {KEEL_REPO}: {recorded!r}")
|
|
195
|
+
return 1
|
|
196
|
+
if "issue comment" in recorded:
|
|
197
|
+
report(f"{label} Keel ran a comment: {recorded!r}")
|
|
198
|
+
return 1
|
|
199
|
+
report("feedback-duplicates scenario passed.")
|
|
200
|
+
return 0
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def creations(log: Path) -> list[str]:
|
|
204
|
+
return [line for line in gh_log(log).splitlines() if line.startswith("issue create")]
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def validate_feedback_create_scenario() -> int:
|
|
208
|
+
"""Issue #505: --create needs the declaration or a confirmation, and adds no label."""
|
|
209
|
+
label = "feedback-create:"
|
|
210
|
+
with feedback_world("keel-feedback-create-") as (project, env, log, _bin):
|
|
211
|
+
refused = run_keel(project, "feedback", "gate refuses a valid task", "--create", env=env)
|
|
212
|
+
if refused.returncode != 3:
|
|
213
|
+
report(f"{label} --create with no declaration and no --confirmed exited {refused.returncode}, not 3: {refused.stdout}{refused.stderr}")
|
|
214
|
+
return 1
|
|
215
|
+
if "Title:" not in refused.stdout:
|
|
216
|
+
report(f"{label} the refusal did not print the draft: {refused.stdout}")
|
|
217
|
+
return 1
|
|
218
|
+
if creations(log):
|
|
219
|
+
report(f"{label} a refused --create still ran gh: {gh_log(log)!r}")
|
|
220
|
+
return 1
|
|
221
|
+
confirmed = run_keel(project, "feedback", "gate refuses a valid task", "--create", "--confirmed", env=env)
|
|
222
|
+
if confirmed.returncode != 0:
|
|
223
|
+
report(f"{label} --create --confirmed exited {confirmed.returncode}: {confirmed.stdout}{confirmed.stderr}")
|
|
224
|
+
return 1
|
|
225
|
+
if CREATED_URL not in confirmed.stdout:
|
|
226
|
+
report(f"{label} the new issue's URL was not printed: {confirmed.stdout}")
|
|
227
|
+
return 1
|
|
228
|
+
made = creations(log)
|
|
229
|
+
if len(made) != 1:
|
|
230
|
+
report(f"{label} --confirmed ran {len(made)} creations: {gh_log(log)!r}")
|
|
231
|
+
return 1
|
|
232
|
+
for needle in (f"--repo {KEEL_REPO}", "--title", "--body-file"):
|
|
233
|
+
if needle not in made[0]:
|
|
234
|
+
report(f"{label} the creation lacks {needle!r}: {made[0]!r}")
|
|
235
|
+
return 1
|
|
236
|
+
for forbidden in ("--label", "--assignee", "--milestone"):
|
|
237
|
+
if forbidden in made[0]:
|
|
238
|
+
report(f"{label} the creation carries {forbidden}: {made[0]!r}")
|
|
239
|
+
return 1
|
|
240
|
+
write_authorize_config(project, "authorize:\n - issue:acme/widgets\n")
|
|
241
|
+
elsewhere = run_keel(project, "feedback", "gate refuses a valid task", "--create", env=env)
|
|
242
|
+
if elsewhere.returncode != 3:
|
|
243
|
+
report(f"{label} a declaration for another repository exited {elsewhere.returncode}, not 3: {elsewhere.stdout}")
|
|
244
|
+
return 1
|
|
245
|
+
write_authorize_config(project, f"authorize:\n - issue:{KEEL_REPO}\n")
|
|
246
|
+
declared = run_keel(project, "feedback", "gate refuses a valid task", "--create", env=env)
|
|
247
|
+
if declared.returncode != 0:
|
|
248
|
+
report(f"{label} the declared project was refused ({declared.returncode}): {declared.stdout}{declared.stderr}")
|
|
249
|
+
return 1
|
|
250
|
+
if len(creations(log)) != 2:
|
|
251
|
+
report(f"{label} the declared project did not create exactly one more issue: {gh_log(log)!r}")
|
|
252
|
+
return 1
|
|
253
|
+
report("feedback-create scenario passed.")
|
|
254
|
+
return 0
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def validate_feedback_gh_missing_scenario() -> int:
|
|
258
|
+
"""Issue #505: no usable gh loses nothing."""
|
|
259
|
+
label = "feedback-gh-missing:"
|
|
260
|
+
attempts = (("no gh on PATH", False, None), ("a gh that is not logged in", True, "fail"))
|
|
261
|
+
for what, with_gh, marker in attempts:
|
|
262
|
+
with feedback_world("keel-feedback-nogh-", with_gh=with_gh) as (project, env, log, bin_dir):
|
|
263
|
+
if marker:
|
|
264
|
+
write_text(bin_dir / marker, "")
|
|
265
|
+
draft = run_keel(project, "feedback", "gate refuses a valid task", env=env)
|
|
266
|
+
if draft.returncode != 0:
|
|
267
|
+
report(f"{label} with {what} the draft exited {draft.returncode}: {draft.stdout}{draft.stderr}")
|
|
268
|
+
return 1
|
|
269
|
+
if "not searched" not in draft.stdout:
|
|
270
|
+
report(f"{label} with {what} the draft does not say the search was not run: {draft.stdout}")
|
|
271
|
+
return 1
|
|
272
|
+
created = run_keel(project, "feedback", "gate refuses a valid task", "--create", "--confirmed", env=env)
|
|
273
|
+
if created.returncode != 4:
|
|
274
|
+
report(f"{label} with {what} --create --confirmed exited {created.returncode}, not 4: {created.stdout}{created.stderr}")
|
|
275
|
+
return 1
|
|
276
|
+
saved = saved_file(created.stdout)
|
|
277
|
+
if saved is None or not saved.exists():
|
|
278
|
+
report(f"{label} with {what} the draft was lost: {created.stdout}")
|
|
279
|
+
return 1
|
|
280
|
+
if f"gh issue create --repo {KEEL_REPO}" not in created.stdout:
|
|
281
|
+
report(f"{label} with {what} no command to run was printed: {created.stdout}")
|
|
282
|
+
return 1
|
|
283
|
+
report("feedback-gh-missing scenario passed.")
|
|
284
|
+
return 0
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def validate_feedback_command_surface_scenario() -> int:
|
|
288
|
+
"""Issue #505: the slash command orders the steps, and the docs list it."""
|
|
289
|
+
label = "feedback-command-surface:"
|
|
290
|
+
command = ROOT / "plugins/keel/commands/feedback.md"
|
|
291
|
+
if not command.exists():
|
|
292
|
+
report(f"{label} {command.relative_to(ROOT)} does not exist.")
|
|
293
|
+
return 1
|
|
294
|
+
text = command.read_text(encoding="utf-8")
|
|
295
|
+
if not text.startswith("---\n"):
|
|
296
|
+
report(f"{label} the command file has no front matter.")
|
|
297
|
+
return 1
|
|
298
|
+
front = text.split("---", 2)[1]
|
|
299
|
+
for key in ("description:", "argument-hint:"):
|
|
300
|
+
if key not in front:
|
|
301
|
+
report(f"{label} the command file's front matter lacks {key}")
|
|
302
|
+
return 1
|
|
303
|
+
for needle in ("keel feedback", "--create", "--confirmed", "$ARGUMENTS", "no label", "comment"):
|
|
304
|
+
if needle not in text:
|
|
305
|
+
report(f"{label} the command file lacks {needle!r}.")
|
|
306
|
+
return 1
|
|
307
|
+
for answer in ("new issue", "add to", "cancel"):
|
|
308
|
+
if answer not in text.lower():
|
|
309
|
+
report(f"{label} the command file does not offer the answer {answer!r}.")
|
|
310
|
+
return 1
|
|
311
|
+
for doc, count in (("docs/commands.md", "six"), ("docs/commands.zh-CN.md", "六个")):
|
|
312
|
+
body = (ROOT / doc).read_text(encoding="utf-8")
|
|
313
|
+
if "/keel:feedback" not in body:
|
|
314
|
+
report(f"{label} {doc} does not list /keel:feedback.")
|
|
315
|
+
return 1
|
|
316
|
+
if count not in body:
|
|
317
|
+
report(f"{label} {doc} does not say {count!r} commands.")
|
|
318
|
+
return 1
|
|
319
|
+
for readme in ("README.md", "README.zh-CN.md"):
|
|
320
|
+
if "keel feedback" not in (ROOT / readme).read_text(encoding="utf-8"):
|
|
321
|
+
report(f"{label} {readme} does not name `keel feedback`.")
|
|
322
|
+
return 1
|
|
323
|
+
report("feedback-command-surface scenario passed.")
|
|
324
|
+
return 0
|
|
@@ -1129,6 +1129,58 @@ def validate_push_protected_declaration_scenario() -> int:
|
|
|
1129
1129
|
return 0
|
|
1130
1130
|
|
|
1131
1131
|
|
|
1132
|
+
def validate_push_tag_declaration_scenario() -> int:
|
|
1133
|
+
"""Issue #499: `push-tag:<glob>[@<role>]` is accepted, reported and enforced by name."""
|
|
1134
|
+
label = "push-tag-declaration:"
|
|
1135
|
+
with tempfile.TemporaryDirectory(prefix="keel-push-tag-decl-") as raw_tmp:
|
|
1136
|
+
root = Path(raw_tmp)
|
|
1137
|
+
|
|
1138
|
+
def fixture(name: str, entries: list[str]) -> Path:
|
|
1139
|
+
repo = root / name
|
|
1140
|
+
repo.mkdir()
|
|
1141
|
+
write_authorize_config(repo, "authorize:\n" + "".join(f" - {e}\n" for e in entries))
|
|
1142
|
+
return repo
|
|
1143
|
+
|
|
1144
|
+
doctor = run_keel(fixture("good", ["push-tag:v*", "push-tag:cbb-parked-*@kaiwu-pm-cbb"]), "--doctor")
|
|
1145
|
+
if doctor.returncode != 0:
|
|
1146
|
+
report(f"{label} doctor failed on a valid declaration: {doctor.stdout}{doctor.stderr}")
|
|
1147
|
+
return 1
|
|
1148
|
+
line = next((l for l in doctor.stdout.splitlines() if l.strip().startswith("push-tag:")), "")
|
|
1149
|
+
for needle in ("authorized", "v*"):
|
|
1150
|
+
if needle not in line:
|
|
1151
|
+
report(f"{label} doctor's push-tag line lacks {needle!r}: {line!r}")
|
|
1152
|
+
report(doctor.stdout)
|
|
1153
|
+
return 1
|
|
1154
|
+
if "push-tag:cbb-parked-*@kaiwu-pm-cbb" not in doctor.stdout:
|
|
1155
|
+
report(f"{label} doctor does not name the role-limited entry: {doctor.stdout}")
|
|
1156
|
+
return 1
|
|
1157
|
+
tag_line = next((l for l in doctor.stdout.splitlines() if l.strip().startswith("tag push:")), "")
|
|
1158
|
+
if "write guard enforces" not in tag_line:
|
|
1159
|
+
report(f"{label} doctor's tag push line does not say the guard enforces it: {tag_line!r}")
|
|
1160
|
+
return 1
|
|
1161
|
+
if "does not enforce" in doctor.stdout:
|
|
1162
|
+
report(f"{label} doctor calls the tag scope carried and not enforced: {doctor.stdout}")
|
|
1163
|
+
return 1
|
|
1164
|
+
beside = run_keel(fixture("beside-push", ["push", "push-tag:v*"]), "--doctor")
|
|
1165
|
+
if beside.returncode != 0:
|
|
1166
|
+
report(f"{label} a bare push beside push-tag:v* was refused: {beside.stdout}{beside.stderr}")
|
|
1167
|
+
return 1
|
|
1168
|
+
for name, entries in (
|
|
1169
|
+
("bare", ["push-tag"]),
|
|
1170
|
+
("bad-glob", ["push-tag:v$"]),
|
|
1171
|
+
("bad-role", ["push-tag:v*@Not"]),
|
|
1172
|
+
):
|
|
1173
|
+
refused = run_keel(fixture(name, entries), "--doctor")
|
|
1174
|
+
if refused.returncode == 0:
|
|
1175
|
+
report(f"{label} {entries!r} was accepted.")
|
|
1176
|
+
return 1
|
|
1177
|
+
if "push-tag:<tag glob>" not in refused.stdout + refused.stderr:
|
|
1178
|
+
report(f"{label} {entries!r} was refused without naming the form: {refused.stdout}")
|
|
1179
|
+
return 1
|
|
1180
|
+
report("push-tag-declaration scenario passed.")
|
|
1181
|
+
return 0
|
|
1182
|
+
|
|
1183
|
+
|
|
1132
1184
|
def validate_authorize_push_close_cleanup_scenario() -> int:
|
|
1133
1185
|
"""Issue #257: `push:<glob>`, `issue-close:<owner>/<repo>`, `cleanup:scratch`.
|
|
1134
1186
|
|
|
@@ -4263,6 +4315,131 @@ def validate_push_guard_follow_tags_scenario() -> int:
|
|
|
4263
4315
|
return 0
|
|
4264
4316
|
|
|
4265
4317
|
|
|
4318
|
+
@contextlib.contextmanager
|
|
4319
|
+
def push_tag_session(prefix: str):
|
|
4320
|
+
"""Issue #499: two worktrees bound to roles, and the real hook run against them.
|
|
4321
|
+
|
|
4322
|
+
Yields `(pm, rtl, declare, expect)`. `pm` is bound to `kaiwu-pm-cbb` and `rtl`
|
|
4323
|
+
to `rtl`; `declare` writes an `authorize:` block into both; `expect` runs the
|
|
4324
|
+
real PreToolUse hook and checks the verdict and the words it names.
|
|
4325
|
+
"""
|
|
4326
|
+
with tempfile.TemporaryDirectory(prefix=prefix) as raw:
|
|
4327
|
+
base = Path(raw)
|
|
4328
|
+
repo = mailbox_repository(base / "repo")
|
|
4329
|
+
pm = chat_worktree(repo, base / "pm")
|
|
4330
|
+
rtl = chat_worktree(repo, base / "rtl")
|
|
4331
|
+
env = chat_environment()
|
|
4332
|
+
run_keel(pm, "chat", "role", "--set", "kaiwu-pm-cbb", env=env)
|
|
4333
|
+
run_keel(rtl, "chat", "role", "--set", "rtl", env=env)
|
|
4334
|
+
hook_env = {
|
|
4335
|
+
k: v for k, v in os.environ.items()
|
|
4336
|
+
if k not in ("KEEL_CHAT_ROLE", "KEEL_MAIL_ROLE") and not k.startswith("GIT_CONFIG")
|
|
4337
|
+
}
|
|
4338
|
+
hook_env["CLAUDE_PLUGIN_ROOT"] = str(ROOT / PLUGIN_ROOT)
|
|
4339
|
+
|
|
4340
|
+
def declare(entries: list[str]) -> None:
|
|
4341
|
+
for cwd in (pm, rtl):
|
|
4342
|
+
write_authorize_config(cwd, "authorize:\n" + "".join(f" - {e}\n" for e in entries))
|
|
4343
|
+
|
|
4344
|
+
def expect(label: str, what: str, cwd: Path, command: str, want: str, needles: tuple[str, ...] = ()) -> bool:
|
|
4345
|
+
event = {"tool_name": "Bash", "tool_input": {"command": command}, "cwd": str(cwd), "permission_mode": "default"}
|
|
4346
|
+
result = subprocess.run(
|
|
4347
|
+
["node", str(ROOT / PLUGIN_ROOT / "scripts/pretooluse-guard.js")],
|
|
4348
|
+
cwd=cwd, env=hook_env, input=json.dumps(event), text=True, capture_output=True, check=False,
|
|
4349
|
+
)
|
|
4350
|
+
decision = pretooluse_decision(result) or {"permissionDecision": "pass"}
|
|
4351
|
+
if decision.get("permissionDecision") != want:
|
|
4352
|
+
verdict = "allowed" if decision.get("permissionDecision") == "pass" else decision.get("permissionDecision")
|
|
4353
|
+
report(f"{label} {what} was {verdict}, not {want} ({command!r}): {decision!r}")
|
|
4354
|
+
return False
|
|
4355
|
+
reason = decision.get("permissionDecisionReason", "")
|
|
4356
|
+
for needle in needles:
|
|
4357
|
+
if needle not in reason:
|
|
4358
|
+
report(f"{label} {what} does not name {needle!r}: {reason!r}")
|
|
4359
|
+
return False
|
|
4360
|
+
return True
|
|
4361
|
+
|
|
4362
|
+
yield pm, rtl, declare, expect
|
|
4363
|
+
|
|
4364
|
+
|
|
4365
|
+
def validate_push_tag_grant_scenario() -> int:
|
|
4366
|
+
"""Issue #499: a granted role pushes a granted tag; nobody else pushes it."""
|
|
4367
|
+
label = "push-tag-grant:"
|
|
4368
|
+
with push_tag_session("keel-push-tag-grant-") as (pm, rtl, declare, expect):
|
|
4369
|
+
declare(["push-tag:cbb-parked-*@kaiwu-pm-cbb"])
|
|
4370
|
+
granted = (
|
|
4371
|
+
("an explicit refs/tags refspec", "git push origin refs/tags/cbb-parked-1101-design"),
|
|
4372
|
+
("the `tag <name>` form", "git push origin tag cbb-parked-1101-design"),
|
|
4373
|
+
("HEAD to a new tag", "git push origin HEAD:refs/tags/cbb-parked-1101-verify"),
|
|
4374
|
+
("a tag to the same tag", "git push origin refs/tags/cbb-parked-1101-design:refs/tags/cbb-parked-1101-design"),
|
|
4375
|
+
)
|
|
4376
|
+
for what, command in granted:
|
|
4377
|
+
if not expect(label, f"the granted role's push of {what}", pm, command, "pass"):
|
|
4378
|
+
return 1
|
|
4379
|
+
if not expect(label, "another role's push of a granted tag", rtl,
|
|
4380
|
+
"git push origin refs/tags/cbb-parked-1101-design", "deny", ("kaiwu-pm-cbb",)):
|
|
4381
|
+
return 1
|
|
4382
|
+
if not expect(label, "the granted role's push of a tag outside the glob", pm,
|
|
4383
|
+
"git push origin refs/tags/other-1", "deny", ("push-tag:",)):
|
|
4384
|
+
return 1
|
|
4385
|
+
report("push-tag-grant scenario passed.")
|
|
4386
|
+
return 0
|
|
4387
|
+
|
|
4388
|
+
|
|
4389
|
+
def validate_push_tag_branches_scenario() -> int:
|
|
4390
|
+
"""Issue #499: a tag beside a branch is judged by its own rule, and a tag-only
|
|
4391
|
+
declaration leaves branch pushes alone."""
|
|
4392
|
+
label = "push-tag-branches:"
|
|
4393
|
+
with push_tag_session("keel-push-tag-branches-") as (pm, rtl, declare, expect):
|
|
4394
|
+
declare(["push:claude/*", "push-tag:v*"])
|
|
4395
|
+
if not expect(label, "a granted branch and a granted tag together", rtl,
|
|
4396
|
+
"git push origin claude/x refs/tags/v1", "pass"):
|
|
4397
|
+
return 1
|
|
4398
|
+
if not expect(label, "an ungranted branch beside a granted tag", rtl,
|
|
4399
|
+
"git push origin main refs/tags/v1", "deny", ("`main`",)):
|
|
4400
|
+
return 1
|
|
4401
|
+
if not expect(label, "a granted branch beside an ungranted tag", rtl,
|
|
4402
|
+
"git push origin claude/x refs/tags/w1", "deny", ("push-tag:",)):
|
|
4403
|
+
return 1
|
|
4404
|
+
declare(["push-tag:v*"])
|
|
4405
|
+
if not expect(label, "a branch push when only tags are declared", rtl, "git push origin feature-1", "pass"):
|
|
4406
|
+
return 1
|
|
4407
|
+
if not expect(label, "a granted tag when only tags are declared", rtl, "git push origin refs/tags/v1", "pass"):
|
|
4408
|
+
return 1
|
|
4409
|
+
if not expect(label, "an ungranted tag when only tags are declared", rtl,
|
|
4410
|
+
"git push origin refs/tags/w1", "deny", ("push-tag:",)):
|
|
4411
|
+
return 1
|
|
4412
|
+
declare(["push-protected:main", "push-tag:v*"])
|
|
4413
|
+
if not expect(label, "a protected branch with a granted tag", rtl, "git push origin main refs/tags/v1", "ask",
|
|
4414
|
+
("`main`",)):
|
|
4415
|
+
return 1
|
|
4416
|
+
report("push-tag-branches scenario passed.")
|
|
4417
|
+
return 0
|
|
4418
|
+
|
|
4419
|
+
|
|
4420
|
+
def validate_push_tag_keeps_verdicts_scenario() -> int:
|
|
4421
|
+
"""Issue #499: the tag grant changes nothing about bulk tag pushes, deletions
|
|
4422
|
+
or a repository without the grant."""
|
|
4423
|
+
label = "push-tag-keeps-verdicts:"
|
|
4424
|
+
with push_tag_session("keel-push-tag-verdicts-") as (pm, rtl, declare, expect):
|
|
4425
|
+
declare(["push:claude/*", "push-tag:cbb-parked-*"])
|
|
4426
|
+
for what, command, needles in (
|
|
4427
|
+
("--tags", "git push --tags origin", ("--tags",)),
|
|
4428
|
+
("--mirror", "git push --mirror origin", ("--mirror",)),
|
|
4429
|
+
("--follow-tags to an unprotected branch", "git push --follow-tags origin claude/x", ("--no-follow-tags",)),
|
|
4430
|
+
("--delete of a granted tag", "git push origin --delete refs/tags/cbb-parked-1101-design", ("is not a branch",)),
|
|
4431
|
+
("a colon refspec deleting a granted tag", "git push origin :refs/tags/cbb-parked-1101-design", ("is not a branch",)),
|
|
4432
|
+
):
|
|
4433
|
+
if not expect(label, f"a push with {what}", rtl, command, "deny", needles):
|
|
4434
|
+
return 1
|
|
4435
|
+
declare(["push:claude/*"])
|
|
4436
|
+
if not expect(label, "an explicit tag with no tag grant declared", rtl,
|
|
4437
|
+
"git push origin refs/tags/v1", "deny", ("is not a branch",)):
|
|
4438
|
+
return 1
|
|
4439
|
+
report("push-tag-keeps-verdicts scenario passed.")
|
|
4440
|
+
return 0
|
|
4441
|
+
|
|
4442
|
+
|
|
4266
4443
|
def validate_touch_write_guard_scenario() -> int:
|
|
4267
4444
|
with tempfile.TemporaryDirectory(
|
|
4268
4445
|
prefix="keel-touch-guard-", ignore_cleanup_errors=True
|
|
@@ -872,7 +872,7 @@ def validate_slash_menu_ships_scenario() -> int:
|
|
|
872
872
|
# The four everyday flows a person runs, each naming the keel command it orders.
|
|
873
873
|
commands_root = ROOT / PLUGIN_ROOT / "commands"
|
|
874
874
|
commands = sorted(path.stem for path in commands_root.glob("*.md"))
|
|
875
|
-
expected = {"context": "keel context", "start": "keel gate task-start", "done": "keel gate task-complete", "chat": "keel chat unread"}
|
|
875
|
+
expected = {"context": "keel context", "start": "keel gate task-start", "done": "keel gate task-complete", "chat": "keel chat unread", "feedback": "keel feedback"}
|
|
876
876
|
if commands != sorted([*expected, "shift"]):
|
|
877
877
|
report(f"{label} the plugin's commands are {commands!r}, not {sorted([*expected, 'shift'])!r}.")
|
|
878
878
|
return 1
|
|
@@ -8,6 +8,7 @@ from validation import shift
|
|
|
8
8
|
from validation import docs
|
|
9
9
|
from validation import selfcheck
|
|
10
10
|
from validation import export
|
|
11
|
+
from validation import feedback
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
|
|
@@ -228,6 +229,7 @@ SCENARIOS: tuple = (
|
|
|
228
229
|
),
|
|
229
230
|
("authorize-push-close-cleanup", guard.validate_authorize_push_close_cleanup_scenario),
|
|
230
231
|
("push-protected-declaration", guard.validate_push_protected_declaration_scenario),
|
|
232
|
+
("push-tag-declaration", guard.validate_push_tag_declaration_scenario),
|
|
231
233
|
("authorize-block-reads-every-line", guard.validate_authorize_block_reads_every_line_scenario),
|
|
232
234
|
(
|
|
233
235
|
"standing-authorization-sync-confusion",
|
|
@@ -531,6 +533,15 @@ SCENARIOS: tuple = (
|
|
|
531
533
|
("push-guard-cd-before-push", guard.validate_push_guard_cd_before_push_scenario),
|
|
532
534
|
("push-guard-redirects", guard.validate_push_guard_redirects_scenario),
|
|
533
535
|
("push-guard-follow-tags", guard.validate_push_guard_follow_tags_scenario),
|
|
536
|
+
("push-tag-grant", guard.validate_push_tag_grant_scenario),
|
|
537
|
+
("push-tag-branches", guard.validate_push_tag_branches_scenario),
|
|
538
|
+
("push-tag-keeps-verdicts", guard.validate_push_tag_keeps_verdicts_scenario),
|
|
539
|
+
("feedback-draft", feedback.validate_feedback_draft_scenario),
|
|
540
|
+
("feedback-redacts", feedback.validate_feedback_redacts_scenario),
|
|
541
|
+
("feedback-duplicates", feedback.validate_feedback_duplicates_scenario),
|
|
542
|
+
("feedback-create", feedback.validate_feedback_create_scenario),
|
|
543
|
+
("feedback-gh-missing", feedback.validate_feedback_gh_missing_scenario),
|
|
544
|
+
("feedback-command-surface", feedback.validate_feedback_command_surface_scenario),
|
|
534
545
|
("push-protected-guard", guard.validate_push_protected_guard_scenario),
|
|
535
546
|
("authorize-role-scoped", guard.validate_authorize_role_scoped_scenario),
|
|
536
547
|
("touch-guard-record-layer", guard.validate_touch_guard_record_layer_scenario),
|
package/src/core/config.js
CHANGED
|
@@ -44,6 +44,11 @@ const STANDING_AUTHORIZATION_ACTIONS = [
|
|
|
44
44
|
// through `keel branches prune` (#469). Its one scope, `merged`, says which
|
|
45
45
|
// branches it reaches; each deletion is recorded with its sha first.
|
|
46
46
|
"delete-branch",
|
|
47
|
+
// Pushing an explicit tag whose name matches the glob, which the Claude
|
|
48
|
+
// write guard otherwise refuses as not a branch (#499); `@<role>` limits who
|
|
49
|
+
// may. It grants no bulk tag push and no tag deletion, and it widens no
|
|
50
|
+
// branch, so a bare `push` beside it is not a mixed declaration.
|
|
51
|
+
"push-tag",
|
|
47
52
|
];
|
|
48
53
|
|
|
49
54
|
// The actions whose credential reaches further than the checkout the
|
|
@@ -53,7 +58,7 @@ const STANDING_AUTHORIZATION_ACTIONS = [
|
|
|
53
58
|
// actions are declared with the resource they may reach and refused bare —
|
|
54
59
|
// accepting the bare form as a convenience would make the narrow form optional
|
|
55
60
|
// and the wide one the default, which is the decision inverted.
|
|
56
|
-
const SCOPED_AUTHORIZATION_ACTIONS = new Set(["issue", "chat-reply", "issue-close", "cleanup", "push-protected", "delete-branch"]);
|
|
61
|
+
const SCOPED_AUTHORIZATION_ACTIONS = new Set(["issue", "chat-reply", "issue-close", "cleanup", "push-protected", "delete-branch", "push-tag"]);
|
|
57
62
|
|
|
58
63
|
// Actions whose scope narrows them but is not required (#257). A bare `push`
|
|
59
64
|
// keeps the meaning it always had; `push:<branch glob>` limits it to matching
|
|
@@ -79,6 +84,8 @@ const AUTHORIZATION_SCOPES = {
|
|
|
79
84
|
// `**` across them, as Touch globs do.
|
|
80
85
|
push: { form: "<branch glob>", pattern: /^[A-Za-z0-9._/*-]+$/ },
|
|
81
86
|
"push-protected": { form: "<branch glob>", pattern: /^[A-Za-z0-9._/*-]+$/ },
|
|
87
|
+
// Tag-name characters and `*`, which matches within one `/` segment.
|
|
88
|
+
"push-tag": { form: "<tag glob>", pattern: /^[A-Za-z0-9._/*-]+$/ },
|
|
82
89
|
};
|
|
83
90
|
|
|
84
91
|
// `@<role pattern>` after any scope (#378): chat-role characters and `*`,
|
|
@@ -359,6 +366,14 @@ function standingAuthorizationUnknownMessage(unknown, problems = []) {
|
|
|
359
366
|
);
|
|
360
367
|
continue;
|
|
361
368
|
}
|
|
369
|
+
if (problem.action === "push-tag") {
|
|
370
|
+
notes.push(
|
|
371
|
+
`\`${problem.entry}\` is not \`push-tag:<tag glob>\` or \`push-tag:<tag glob>@<role>\` — `
|
|
372
|
+
+ "a glob of letters, digits, `.`, `_`, `-`, `/`, and `*`, and a chat role of lowercase "
|
|
373
|
+
+ "letters, digits, and hyphens. It takes a tag glob because a tag push is granted by name."
|
|
374
|
+
);
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
362
377
|
if (problem.action === "push") {
|
|
363
378
|
notes.push(
|
|
364
379
|
`\`${problem.entry}\` does not name a branch glob as \`push:<branch glob>\` — `
|
|
@@ -446,6 +461,7 @@ function readStandingAuthorization(repo, options = {}) {
|
|
|
446
461
|
// author believes they granted the typo too.
|
|
447
462
|
const pushGlobs = [];
|
|
448
463
|
const protectedPushes = [];
|
|
464
|
+
const pushTags = [];
|
|
449
465
|
for (const entry of declared) {
|
|
450
466
|
const classified = classifyAuthorizationEntry(entry);
|
|
451
467
|
if (classified.action === "push" && classified.scope !== null && !pushGlobs.includes(classified.scope)) {
|
|
@@ -454,6 +470,9 @@ function readStandingAuthorization(repo, options = {}) {
|
|
|
454
470
|
if (classified.action === "push-protected" && !protectedPushes.includes(classified.scope)) {
|
|
455
471
|
protectedPushes.push(classified.scope);
|
|
456
472
|
}
|
|
473
|
+
if (classified.action === "push-tag" && !pushTags.includes(classified.scope)) {
|
|
474
|
+
pushTags.push(classified.scope);
|
|
475
|
+
}
|
|
457
476
|
}
|
|
458
477
|
const anyScopedPush = entries.some((e) => (e.action === "push" && e.scope !== null) || e.action === "push-protected");
|
|
459
478
|
if (anyScopedPush && declared.includes("push")) {
|
|
@@ -470,6 +489,7 @@ function readStandingAuthorization(repo, options = {}) {
|
|
|
470
489
|
chatReplyGroups: [],
|
|
471
490
|
pushGlobs: [],
|
|
472
491
|
protectedPushes: [],
|
|
492
|
+
pushTags: [],
|
|
473
493
|
otherRoles: [],
|
|
474
494
|
entries: [],
|
|
475
495
|
role,
|
|
@@ -480,7 +500,8 @@ function readStandingAuthorization(repo, options = {}) {
|
|
|
480
500
|
if (chatReplyGroups.length) scopes.set("chat-reply", chatReplyGroups.join(", "));
|
|
481
501
|
if (pushGlobs.length) scopes.set("push", pushGlobs.join(", "));
|
|
482
502
|
if (protectedPushes.length) scopes.set("push-protected", protectedPushes.join(", "));
|
|
483
|
-
|
|
503
|
+
if (pushTags.length) scopes.set("push-tag", pushTags.join(", "));
|
|
504
|
+
return { declared, scopes, chatReplyGroups, pushGlobs, protectedPushes, pushTags, otherRoles, entries, role, unknown, message: null };
|
|
484
505
|
}
|
|
485
506
|
|
|
486
507
|
// `full_mode_paths:` — the paths whose change always routes Full, whatever the
|