@jesdi/skills 0.0.63 → 0.0.64
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 +15 -0
- package/package.json +2 -2
- package/skills/babysit-pr/SKILL.md +54 -0
- package/skills/babysit-pr/babysit.py +998 -0
- package/skills/babysit-pr/fixtures/gh +310 -0
- package/skills/babysit-pr/hooks/post-pr-create.sh +56 -0
- package/skills/babysit-pr/hooks.json +10 -0
- package/skills/babysit-pr/judge-prompt.md +10 -0
- package/skills/babysit-pr/test_babysit.py +242 -0
- package/skills/babysit-pr/test_babysit_judge.py +286 -0
- package/skills/babysit-pr/test_babysit_judge_diff.py +25 -0
- package/skills/babysit-pr/test_babysit_judge_isolation.py +61 -0
- package/skills/babysit-pr/test_checks_regressions.py +210 -0
- package/skills/babysit-pr/test_comment_fidelity.py +88 -0
- package/skills/babysit-pr/test_comment_identity.py +70 -0
- package/skills/babysit-pr/test_e2e_setup.py +74 -0
- package/skills/babysit-pr/test_handoff_takeover.py +141 -0
- package/skills/babysit-pr/test_handoff_terminal.py +29 -0
- package/skills/babysit-pr/test_hook_quoting.py +25 -0
- package/skills/babysit-pr/test_hooks.py +62 -0
- package/skills/babysit-pr/test_lease_regressions.py +198 -0
- package/skills/babysit-pr/test_merge_and_handoff.py +260 -0
- package/skills/babysit-pr/test_merge_base_pin.py +10 -0
- package/skills/babysit-pr/test_merge_gate.py +124 -0
- package/skills/babysit-pr/test_merge_session_safety.py +117 -0
- package/skills/babysit-pr/test_merged_pr_labels.py +144 -0
- package/skills/babysit-pr/test_owner_comment_edits.py +26 -0
- package/skills/babysit-pr/test_owner_comments.py +316 -0
- package/skills/babysit-pr/test_retry_and_stall_hardening.py +143 -0
- package/skills/babysit-pr/test_rounds_and_checks.py +305 -0
- package/skills/babysit-pr/test_terminal_label_regressions.py +117 -0
- package/skills/babysit-pr/test_trusted_merge_risk.py +184 -0
- package/skills/babysit-pr/test_update_plan.py +157 -0
- package/skills/implement-spec/README.md +1 -1
- package/skills/implement-spec/SKILL.md +1 -1
- package/skills/implement-spec/driver_final.py +49 -10
- package/skills/implement-spec/prompts/pr-writer.md +3 -2
- package/skills/implement-spec/tests/test_final.py +112 -1
- package/skills/implement-spec/tests/test_tidy.py +2 -2
- package/skills/implement-spec/tests/test_walk.py +2 -2
- package/skills/pr-risk/SKILL.md +33 -0
- package/skills/pr-risk/hooks/pre-pr-create.sh +274 -0
- package/skills/pr-risk/hooks.json +10 -0
- package/skills/pr-risk/merge_policy.py +81 -0
- package/skills/pr-risk/merge_risk.py +314 -0
- package/skills/pr-risk/test_hook_commands.py +47 -0
- package/skills/pr-risk/test_hook_heredoc.py +16 -0
- package/skills/pr-risk/test_hook_substitution.py +40 -0
- package/skills/pr-risk/test_hooks.py +175 -0
- package/skills/pr-risk/test_merge_risk.py +97 -0
- package/skills/pr-risk/test_merge_risk_gate.py +217 -0
- package/skills/pr-risk/test_merge_risk_regressions.py +37 -0
- package/skills/pr-risk/test_merge_risk_structure.py +101 -0
- package/skills-manifest.json +15 -3
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Regression coverage for handoffs whose mutable heading was removed."""
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from test_babysit import MIN, T, World, iso
|
|
7
|
+
from test_owner_comments import HANDOFF_BODY, comment, read
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@pytest.mark.parametrize("editor", ["alice", "jesdi"])
|
|
11
|
+
def test_removing_handoff_heading_does_not_reactivate_approval(tmp_path, editor):
|
|
12
|
+
w = World(tmp_path, comments=[
|
|
13
|
+
comment(1001, "jesdi", "@babysitter merge a1b2c3d", at=T - 20 * MIN),
|
|
14
|
+
comment(1002, "jesdi", HANDOFF_BODY, at=T - 10 * MIN)])
|
|
15
|
+
state = w.github()
|
|
16
|
+
state["commits"] = [{"sha": "a1b2c3d", "date": iso(T - 30 * MIN)}]
|
|
17
|
+
w.state.write_text(json.dumps(state))
|
|
18
|
+
assert read(w) == {"handoff": None, "instructions": []}
|
|
19
|
+
|
|
20
|
+
# The final editor can also be the owner after another account's earlier edit.
|
|
21
|
+
state["comments"][1] = comment(1002, "jesdi", "please continue",
|
|
22
|
+
at=T - 10 * MIN, editor=editor)
|
|
23
|
+
w.state.write_text(json.dumps(state))
|
|
24
|
+
out = read(w)
|
|
25
|
+
assert out["handoff"] == "handoff comment edited, boundary unverifiable"
|
|
26
|
+
assert out["instructions"] == []
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"""Acceptance tests for `babysit.py owner-comments --repo R --pr N`.
|
|
2
|
+
|
|
3
|
+
Interface under test:
|
|
4
|
+
babysit.py owner-comments --repo <owner/name> --pr <number>
|
|
5
|
+
Exit 0; stdout is one JSON object:
|
|
6
|
+
{"handoff": <reason string or null>,
|
|
7
|
+
"instructions": [{"id": <comment id>, "text": <comment body>, "approved_sha": <sha or null>}]}
|
|
8
|
+
`handoff` is set when a review, or a comment that is not a trusted owner comment, needs a human.
|
|
9
|
+
An instruction is a comment that starts with `@babysitter`, whose author login is the owner (the
|
|
10
|
+
login of `gh api user`), that no other account edited, and that was created after the last
|
|
11
|
+
handoff comment (`## 🧑 Needs human: ...`). `approved_sha` is set for `@babysitter merge`: the
|
|
12
|
+
commit SHA the comment names, given as a hex prefix that must resolve to exactly one of the PR's
|
|
13
|
+
commits (otherwise null, with a handoff); it is never inferred from commit dates.
|
|
14
|
+
|
|
15
|
+
`gh` is the fake in fixtures/gh (REST and GraphQL `editor` / `lastEditedAt`).
|
|
16
|
+
"""
|
|
17
|
+
import json
|
|
18
|
+
import subprocess
|
|
19
|
+
import sys
|
|
20
|
+
from datetime import timedelta
|
|
21
|
+
|
|
22
|
+
from test_babysit import SCRIPT, MIN, T, World, iso
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def comment(cid, login, body, at=T, editor=None):
|
|
26
|
+
c = {"id": cid, "user": {"login": login}, "body": body,
|
|
27
|
+
"created_at": iso(at), "updated_at": iso(at)}
|
|
28
|
+
if editor:
|
|
29
|
+
c.update(editor={"login": editor}, last_edited_at=iso(at + MIN))
|
|
30
|
+
return c
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def read(w):
|
|
34
|
+
p = subprocess.run([sys.executable, str(SCRIPT), "owner-comments", "--repo", "jesdi/demo",
|
|
35
|
+
"--pr", "58"], cwd=w.project, env=w.env, text=True, capture_output=True)
|
|
36
|
+
assert p.returncode == 0, p.stdout + p.stderr
|
|
37
|
+
assert w.unsupported() == []
|
|
38
|
+
assert w.writes() == []
|
|
39
|
+
return json.loads(p.stdout)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_review_comment_from_another_login_hands_off(tmp_path):
|
|
43
|
+
w = World(tmp_path, comments=[comment(1001, "alice", "why this change?")])
|
|
44
|
+
out = read(w)
|
|
45
|
+
assert out["handoff"] == "review comment from alice"
|
|
46
|
+
assert out["instructions"] == []
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_changes_requested_without_a_comment_hands_off(tmp_path):
|
|
50
|
+
w = World(tmp_path)
|
|
51
|
+
st = w.github()
|
|
52
|
+
st["reviews"] = [{"id": 5, "user": {"login": "alice"}, "state": "CHANGES_REQUESTED",
|
|
53
|
+
"body": "", "submitted_at": iso(T)}]
|
|
54
|
+
w.state.write_text(json.dumps(st))
|
|
55
|
+
out = read(w)
|
|
56
|
+
assert out["handoff"]
|
|
57
|
+
assert out["instructions"] == []
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_owner_instruction_is_returned_with_its_text(tmp_path):
|
|
61
|
+
text = "@babysitter rename `parse_x` to `parse_row`"
|
|
62
|
+
w = World(tmp_path, comments=[comment(1001, "jesdi", text)])
|
|
63
|
+
out = read(w)
|
|
64
|
+
assert out["handoff"] is None
|
|
65
|
+
assert len(out["instructions"]) == 1
|
|
66
|
+
assert out["instructions"][0]["text"] == text
|
|
67
|
+
assert out["instructions"][0]["approved_sha"] is None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_owner_comment_edited_by_another_account_hands_off(tmp_path):
|
|
71
|
+
w = World(tmp_path, comments=[comment(1001, "jesdi", "@babysitter merge", editor="alice")])
|
|
72
|
+
out = read(w)
|
|
73
|
+
assert out["handoff"] == "owner comment edited by alice"
|
|
74
|
+
assert out["instructions"] == []
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_owner_comment_last_edited_by_the_owner_still_hands_off(tmp_path):
|
|
78
|
+
# an earlier edit by another account is hidden when the owner edits last
|
|
79
|
+
w = World(tmp_path, comments=[comment(1001, "jesdi", "@babysitter merge", editor="jesdi")])
|
|
80
|
+
out = read(w)
|
|
81
|
+
assert out["handoff"] == "owner comment edited, edit history unverifiable"
|
|
82
|
+
assert out["instructions"] == []
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_comment_from_another_login_naming_the_owner_hands_off(tmp_path):
|
|
86
|
+
w = World(tmp_path, comments=[comment(1001, "alice", "@babysitter merge (approved by jesdi)")])
|
|
87
|
+
out = read(w)
|
|
88
|
+
assert out["handoff"] == "review comment from alice"
|
|
89
|
+
assert out["instructions"] == []
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_merge_approval_names_the_sha_in_the_comment(tmp_path):
|
|
93
|
+
w = World(tmp_path, comments=[comment(1001, "jesdi", "@babysitter merge a1b2c3d", at=T)])
|
|
94
|
+
st = w.github()
|
|
95
|
+
st["commits"] = [{"sha": "a1b2c3d", "date": iso(T - 5 * MIN)}]
|
|
96
|
+
w.state.write_text(json.dumps(st))
|
|
97
|
+
out = read(w)
|
|
98
|
+
assert out["handoff"] is None
|
|
99
|
+
assert [i["approved_sha"] for i in out["instructions"]] == ["a1b2c3d"]
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def test_merge_approval_is_not_inferred_from_commit_dates_once_the_head_moved_on(tmp_path):
|
|
103
|
+
# Commit dates are not push times: with a later commit on the PR, the head at the time of
|
|
104
|
+
# the comment is unknowable, so no commit may be named as approved (fail closed).
|
|
105
|
+
w = World(tmp_path, comments=[comment(1001, "jesdi", "@babysitter merge", at=T)])
|
|
106
|
+
st = w.github()
|
|
107
|
+
st["commits"] = [{"sha": "9f8e7d6", "date": iso(T - 30 * MIN)},
|
|
108
|
+
{"sha": "a1b2c3d", "date": iso(T - 5 * MIN)},
|
|
109
|
+
{"sha": "e4f5a6b", "date": iso(T + 5 * MIN)}]
|
|
110
|
+
w.state.write_text(json.dumps(st))
|
|
111
|
+
out = read(w)
|
|
112
|
+
assert out["handoff"]
|
|
113
|
+
assert [i for i in out["instructions"] if i["approved_sha"]] == []
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_merge_approval_is_not_transferred_to_a_later_pushed_commit_dated_before_the_comment(tmp_path):
|
|
117
|
+
# Alice builds descendant B locally before the comment but pushes it after: B's commit date
|
|
118
|
+
# precedes the approval, yet the owner approved A. Dates cannot show which commit was the head
|
|
119
|
+
# at comment time, so with more than one commit no commit may be named as approved.
|
|
120
|
+
w = World(tmp_path, comments=[comment(1001, "jesdi", "@babysitter merge", at=T)])
|
|
121
|
+
st = w.github()
|
|
122
|
+
st["commits"] = [{"sha": "a1b2c3d", "date": iso(T - 10 * MIN)},
|
|
123
|
+
{"sha": "e4f5a6b", "date": iso(T - 2 * MIN)}]
|
|
124
|
+
w.state.write_text(json.dumps(st))
|
|
125
|
+
out = read(w)
|
|
126
|
+
assert out["handoff"]
|
|
127
|
+
assert [i for i in out["instructions"] if i["approved_sha"]] == []
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def test_only_owner_comments_after_the_last_handoff_are_instructions(tmp_path):
|
|
131
|
+
lease = "<!-- babysit-pr lease: s1 mac 2020-01-01T11:00:00Z -->\nrounds: 0\n@babysitter merge"
|
|
132
|
+
old_handoff = "## 🧑 Needs human: door one-way\n\nnext: reply `@babysitter merge`\n"
|
|
133
|
+
last_handoff = "## 🧑 Needs human: 5 fix rounds\n\nnext: reply\n@babysitter merge\n"
|
|
134
|
+
w = World(tmp_path, comments=[
|
|
135
|
+
comment(1001, "jesdi", "@babysitter old one", at=T - 60 * MIN),
|
|
136
|
+
comment(1002, "jesdi", old_handoff, at=T - 50 * MIN),
|
|
137
|
+
comment(1003, "jesdi", "@babysitter before the last handoff", at=T - 40 * MIN),
|
|
138
|
+
comment(1004, "jesdi", last_handoff, at=T - 30 * MIN),
|
|
139
|
+
comment(1005, "jesdi", lease, at=T - 20 * MIN, editor="jesdi"), # acquisition PATCHes the lease to confirm its claim
|
|
140
|
+
comment(1006, "jesdi", "@babysitter add a test for the empty case", at=T - 10 * MIN)])
|
|
141
|
+
out = read(w)
|
|
142
|
+
assert out["handoff"] is None
|
|
143
|
+
assert [i["id"] for i in out["instructions"]] == [1006]
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def test_unresolved_review_thread_hands_off(tmp_path):
|
|
147
|
+
w = World(tmp_path)
|
|
148
|
+
st = w.github()
|
|
149
|
+
st["threads"] = [{"user": {"login": "alice"}, "resolved": False}]
|
|
150
|
+
w.state.write_text(json.dumps(st))
|
|
151
|
+
out = read(w)
|
|
152
|
+
assert out["handoff"] == "review comment from alice"
|
|
153
|
+
assert out["instructions"] == []
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def test_merge_approval_is_not_given_to_a_sole_commit_dated_after_the_comment(tmp_path):
|
|
157
|
+
# A sole commit created after the approval cannot have been the head the owner approved.
|
|
158
|
+
w = World(tmp_path, comments=[comment(1001, "jesdi", "@babysitter merge", at=T)])
|
|
159
|
+
st = w.github()
|
|
160
|
+
st["commits"] = [{"sha": "e4f5a6b", "date": iso(T + 5 * MIN)}]
|
|
161
|
+
w.state.write_text(json.dumps(st))
|
|
162
|
+
out = read(w)
|
|
163
|
+
assert out["handoff"]
|
|
164
|
+
assert [i for i in out["instructions"] if i["approved_sha"]] == []
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def test_resolved_review_thread_older_than_the_last_handoff_does_not_hand_off(tmp_path):
|
|
168
|
+
handoff = "## 🧑 Needs human: 5 fix rounds\n\nnext: reply\n"
|
|
169
|
+
w = World(tmp_path, comments=[comment(1001, "jesdi", handoff, at=T)])
|
|
170
|
+
st = w.github()
|
|
171
|
+
st["threads"] = [{"user": {"login": "alice"}, "resolved": True, "created_at": iso(T - 10 * MIN)}]
|
|
172
|
+
w.state.write_text(json.dumps(st))
|
|
173
|
+
assert read(w)["handoff"] is None
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def test_resolved_review_thread_newer_than_the_last_handoff_hands_off(tmp_path):
|
|
177
|
+
handoff = "## 🧑 Needs human: 5 fix rounds\n\nnext: reply\n"
|
|
178
|
+
w = World(tmp_path, comments=[comment(1001, "jesdi", handoff, at=T)])
|
|
179
|
+
st = w.github()
|
|
180
|
+
st["threads"] = [{"user": {"login": "alice"}, "resolved": True, "created_at": iso(T + 10 * MIN)}]
|
|
181
|
+
w.state.write_text(json.dumps(st))
|
|
182
|
+
assert read(w)["handoff"] == "review comment from alice"
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def test_unread_comments_of_a_review_thread_hand_off(tmp_path):
|
|
186
|
+
# a resolved thread whose comments run past the page read: the unread ones may be alice's
|
|
187
|
+
w = World(tmp_path)
|
|
188
|
+
st = w.github()
|
|
189
|
+
st["threads"] = [{"user": {"login": "jesdi"}, "resolved": True, "more_comments": True}]
|
|
190
|
+
w.state.write_text(json.dumps(st))
|
|
191
|
+
out = read(w)
|
|
192
|
+
assert out["handoff"]
|
|
193
|
+
assert out["instructions"] == []
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def test_a_review_comment_on_a_later_page_suppresses_instructions(tmp_path):
|
|
197
|
+
w = World(tmp_path, comments=[comment(1001, "jesdi", "@babysitter rename it"),
|
|
198
|
+
comment(1002, "alice", "why this change?")])
|
|
199
|
+
st = w.github()
|
|
200
|
+
st["page_size"] = 1
|
|
201
|
+
w.state.write_text(json.dumps(st))
|
|
202
|
+
out = read(w)
|
|
203
|
+
assert out["handoff"] == "review comment from alice"
|
|
204
|
+
assert out["instructions"] == []
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def test_merge_approval_does_not_transfer_to_a_replacement_sole_commit(tmp_path):
|
|
208
|
+
# The owner approved a1b2c3d. A force-push then leaves b7c8d9e, dated before the comment, as
|
|
209
|
+
# the sole commit: a1b2c3d is no commit of the PR any more, so the comment approves nothing.
|
|
210
|
+
w = World(tmp_path, comments=[comment(1001, "jesdi", "@babysitter merge a1b2c3d", at=T)])
|
|
211
|
+
st = w.github()
|
|
212
|
+
st["commits"] = [{"sha": "b7c8d9e", "date": iso(T - 3 * MIN)}]
|
|
213
|
+
w.state.write_text(json.dumps(st))
|
|
214
|
+
out = read(w)
|
|
215
|
+
assert out["handoff"] == "merge approval must name a commit: @babysitter merge <sha>"
|
|
216
|
+
assert [i for i in out["instructions"] if i["approved_sha"]] == []
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
MERGE_HANDOFF = "merge approval must name a commit: @babysitter merge <sha>"
|
|
220
|
+
A = "a1b2c3d" + "0" * 33
|
|
221
|
+
B = "a1b2c3d" + "1" * 33
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def merge_read(tmp_path, body, shas):
|
|
225
|
+
w = World(tmp_path, comments=[comment(1001, "jesdi", body, at=T)])
|
|
226
|
+
st = w.github()
|
|
227
|
+
st["commits"] = [{"sha": s, "date": iso(T - (10 - i) * MIN)} for i, s in enumerate(shas)]
|
|
228
|
+
w.state.write_text(json.dumps(st))
|
|
229
|
+
return read(w)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def test_merge_approval_by_a_unique_prefix_names_the_full_sha(tmp_path):
|
|
233
|
+
out = merge_read(tmp_path, "@babysitter merge a1b2c3d", [A, "b7c8d9e" + "2" * 33])
|
|
234
|
+
assert out["handoff"] is None
|
|
235
|
+
assert [i["approved_sha"] for i in out["instructions"]] == [A]
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def test_merge_approval_by_the_full_sha_names_it(tmp_path):
|
|
239
|
+
out = merge_read(tmp_path, f"@babysitter merge {A}", [A, B])
|
|
240
|
+
assert out["handoff"] is None
|
|
241
|
+
assert [i["approved_sha"] for i in out["instructions"]] == [A]
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def test_merge_approval_by_an_ambiguous_prefix_hands_off(tmp_path):
|
|
245
|
+
out = merge_read(tmp_path, "@babysitter merge a1b2c3d", [A, B])
|
|
246
|
+
assert out["handoff"] == MERGE_HANDOFF
|
|
247
|
+
assert out["instructions"] == []
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def test_merge_approval_by_a_too_short_prefix_hands_off(tmp_path):
|
|
251
|
+
out = merge_read(tmp_path, "@babysitter merge a1b2c3", [A])
|
|
252
|
+
assert out["handoff"] == MERGE_HANDOFF
|
|
253
|
+
assert out["instructions"] == []
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def test_merge_approval_by_a_non_hex_token_hands_off(tmp_path):
|
|
257
|
+
out = merge_read(tmp_path, "@babysitter merge zz12345", ["zz12345" + "0" * 33])
|
|
258
|
+
assert out["handoff"] == MERGE_HANDOFF
|
|
259
|
+
assert out["instructions"] == []
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def test_merge_approval_without_a_sha_hands_off(tmp_path):
|
|
263
|
+
out = merge_read(tmp_path, "@babysitter merge", [A])
|
|
264
|
+
assert out["handoff"] == MERGE_HANDOFF
|
|
265
|
+
assert out["instructions"] == []
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def test_explicit_approval_stays_valid_when_a_later_commit_becomes_the_head(tmp_path):
|
|
269
|
+
out = merge_read(tmp_path, "@babysitter merge a1b2c3d", [A, "e4f5a6b" + "3" * 33])
|
|
270
|
+
assert out["handoff"] is None
|
|
271
|
+
assert [i["approved_sha"] for i in out["instructions"]] == [A]
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
HANDOFF_BODY = "## 🧑 Needs human: 5 fix rounds\n\nnext: reply\n"
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def test_handoff_comment_edited_by_another_account_hands_off_and_hides_earlier_instructions(tmp_path):
|
|
278
|
+
w = World(tmp_path, comments=[
|
|
279
|
+
comment(1001, "jesdi", "@babysitter old one", at=T - 20 * MIN),
|
|
280
|
+
comment(1002, "jesdi", HANDOFF_BODY, at=T - 10 * MIN, editor="alice")])
|
|
281
|
+
out = read(w)
|
|
282
|
+
assert out["handoff"]
|
|
283
|
+
assert out["instructions"] == []
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def test_review_comment_submitted_exactly_at_the_handoff_hands_off(tmp_path):
|
|
287
|
+
w = World(tmp_path, comments=[comment(1001, "jesdi", HANDOFF_BODY, at=T)])
|
|
288
|
+
st = w.github()
|
|
289
|
+
st["reviews"] = [{"id": 5, "user": {"login": "alice"}, "state": "COMMENTED",
|
|
290
|
+
"body": "why this change?", "submitted_at": iso(T)}]
|
|
291
|
+
w.state.write_text(json.dumps(st))
|
|
292
|
+
assert read(w)["handoff"] == "review comment from alice"
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def test_resolved_review_thread_created_exactly_at_the_handoff_hands_off(tmp_path):
|
|
296
|
+
w = World(tmp_path, comments=[comment(1001, "jesdi", HANDOFF_BODY, at=T)])
|
|
297
|
+
st = w.github()
|
|
298
|
+
st["threads"] = [{"user": {"login": "alice"}, "resolved": True, "created_at": iso(T)}]
|
|
299
|
+
w.state.write_text(json.dumps(st))
|
|
300
|
+
assert read(w)["handoff"] == "review comment from alice"
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def test_instruction_after_a_lease_acquired_and_renewed_through_the_cli_is_returned(tmp_path):
|
|
304
|
+
w = World(tmp_path)
|
|
305
|
+
assert w.run("acquire", "s1").returncode == 0
|
|
306
|
+
w.set_now(T + 10 * MIN)
|
|
307
|
+
assert w.run("renew", "s1").returncode == 0
|
|
308
|
+
st = w.github()
|
|
309
|
+
for c in st["comments"]: # GitHub records an editor on every body edit; the fake gh does not
|
|
310
|
+
c["editor"] = {"login": "jesdi"}; c["last_edited_at"] = c["updated_at"]
|
|
311
|
+
st["comments"].append(comment(st["next_id"], "jesdi", "@babysitter add a test", at=T + 11 * MIN))
|
|
312
|
+
w.state.write_text(json.dumps(st))
|
|
313
|
+
w.log.write_text("")
|
|
314
|
+
out = read(w)
|
|
315
|
+
assert out["handoff"] is None
|
|
316
|
+
assert [i["id"] for i in out["instructions"]] == [st["next_id"]]
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"""Acceptance tests for ticket 18: a retried failure record counts once, and the CI stall timer
|
|
2
|
+
keeps the earliest pending time it has seen.
|
|
3
|
+
|
|
4
|
+
Interface under test (same helpers as test_rounds_and_checks.py):
|
|
5
|
+
babysit.py round record-failure --repo R --pr N --session S --host H --check C --error E --op O
|
|
6
|
+
--op is required and names the round the failure belongs to; a retry with the same --op
|
|
7
|
+
records nothing new.
|
|
8
|
+
babysit.py checks --repo R --pr N --wait-minutes M
|
|
9
|
+
"""
|
|
10
|
+
from test_rounds_and_checks import Ci, MIN, T, ci_world, iso, run_ci
|
|
11
|
+
|
|
12
|
+
ERR = "test_empty AssertionError"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def record(w, op, error=ERR, session="s1"):
|
|
16
|
+
return w.round("record-failure", session, "--check", "test", "--error", error, "--op", op)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_record_failure_without_op_is_refused_naming_op_and_writes_nothing(tmp_path):
|
|
20
|
+
w = Ci(tmp_path)
|
|
21
|
+
assert w.acquire("s1").returncode == 0
|
|
22
|
+
assert w.round("start", "s1", "--op", "a").returncode == 0
|
|
23
|
+
before = w.github()
|
|
24
|
+
p = w.round("record-failure", "s1", "--check", "test", "--error", ERR)
|
|
25
|
+
assert p.returncode != 0, p.output
|
|
26
|
+
assert "--op" in p.output
|
|
27
|
+
assert w.github() == before
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_a_lost_response_retry_after_the_next_round_start_records_the_failure_once(tmp_path):
|
|
31
|
+
w = Ci(tmp_path)
|
|
32
|
+
assert w.acquire("s1").returncode == 0
|
|
33
|
+
assert w.round("start", "s1", "--op", "f1").returncode == 0
|
|
34
|
+
assert record(w, "f1").returncode == 0 # the response of this call is lost
|
|
35
|
+
assert w.round("start", "s1", "--op", "b").returncode == 0
|
|
36
|
+
body_before = w.comment(1001)["body"]
|
|
37
|
+
retry = record(w, "f1")
|
|
38
|
+
assert retry.returncode == 0, retry.output
|
|
39
|
+
assert w.comment(1001)["body"] == body_before
|
|
40
|
+
assert body_before.count("signature:") == 1
|
|
41
|
+
assert "signature: r1 " in body_before
|
|
42
|
+
p = w.round("start", "s1", "--op", "c")
|
|
43
|
+
assert p.returncode == 0, p.output
|
|
44
|
+
assert p.stdout.strip().split()[-1] == "3"
|
|
45
|
+
assert not any("Needs human" in c["body"] for c in w.github()["comments"])
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_the_same_failure_recorded_with_two_different_ops_is_same_failure_twice(tmp_path):
|
|
49
|
+
w = Ci(tmp_path)
|
|
50
|
+
assert w.acquire("s1").returncode == 0
|
|
51
|
+
assert w.round("start", "s1", "--op", "f1").returncode == 0
|
|
52
|
+
assert record(w, "f1").returncode == 0
|
|
53
|
+
assert w.round("start", "s1", "--op", "f2").returncode == 0
|
|
54
|
+
p = record(w, "f2")
|
|
55
|
+
assert p.returncode != 0
|
|
56
|
+
assert "same failure twice" in p.output
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_a_check_that_publishes_pending_again_keeps_its_first_pending_time(tmp_path):
|
|
60
|
+
w = ci_world(tmp_path, [dict(run_ci("e2e", "queued"), id=1, created_at=iso(T))])
|
|
61
|
+
# published pending at minute 0, but `checks` only runs for the first time at minute 30
|
|
62
|
+
w.set_now(T + 30 * MIN)
|
|
63
|
+
assert w.checks(wait=60).stdout.strip() == "pending"
|
|
64
|
+
w.set_now(T + 60 * MIN)
|
|
65
|
+
w.seed(check_runs={"head1": [dict(run_ci("e2e", "queued"), id=1,
|
|
66
|
+
created_at=iso(T + 60 * MIN))]})
|
|
67
|
+
assert w.checks(wait=60).stdout.strip() == "CI stalled"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_a_run_with_both_timestamps_counts_pending_from_the_earlier_created_at(tmp_path):
|
|
71
|
+
run = dict(run_ci("e2e", "in_progress"), id=1, created_at=iso(T), started_at=iso(T + 20 * MIN))
|
|
72
|
+
w = ci_world(tmp_path, [run])
|
|
73
|
+
w.set_now(T + 30 * MIN)
|
|
74
|
+
assert w.checks(wait=60).stdout.strip() == "pending"
|
|
75
|
+
w.set_now(T + 60 * MIN)
|
|
76
|
+
assert w.checks(wait=60).stdout.strip() == "CI stalled"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_a_rerun_after_the_check_completed_starts_a_new_timer(tmp_path):
|
|
80
|
+
w = ci_world(tmp_path, [dict(run_ci("e2e", "queued"), id=1, created_at=iso(T))])
|
|
81
|
+
assert w.checks(wait=60).stdout.strip() == "pending"
|
|
82
|
+
w.set_now(T + 30 * MIN)
|
|
83
|
+
w.seed(check_runs={"head1": [dict(run_ci("e2e", "completed", "success"), id=1,
|
|
84
|
+
created_at=iso(T))]})
|
|
85
|
+
assert w.checks(wait=60).stdout.strip() == "green"
|
|
86
|
+
w.set_now(T + 120 * MIN)
|
|
87
|
+
w.seed(check_runs={"head1": [dict(run_ci("e2e", "queued"), id=2,
|
|
88
|
+
created_at=iso(T + 120 * MIN))]})
|
|
89
|
+
assert w.checks(wait=60).stdout.strip() == "pending"
|
|
90
|
+
w.set_now(T + 179 * MIN)
|
|
91
|
+
assert w.checks(wait=60).stdout.strip() == "pending"
|
|
92
|
+
w.set_now(T + 180 * MIN)
|
|
93
|
+
assert w.checks(wait=60).stdout.strip() == "CI stalled"
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def pending_status(sid, at):
|
|
97
|
+
return {"id": sid, "context": "ci/e2e", "state": "pending", "created_at": iso(at)}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_a_commit_status_published_pending_again_keeps_its_first_pending_time(tmp_path):
|
|
101
|
+
w = ci_world(tmp_path, [])
|
|
102
|
+
w.seed(statuses={"head1": [pending_status(1, T)]})
|
|
103
|
+
w.set_now(T + 30 * MIN)
|
|
104
|
+
assert w.checks(wait=60).stdout.strip() == "pending"
|
|
105
|
+
w.set_now(T + 60 * MIN)
|
|
106
|
+
w.seed(statuses={"head1": [pending_status(2, T + 60 * MIN), pending_status(1, T)]})
|
|
107
|
+
assert w.checks(wait=60).stdout.strip() == "CI stalled"
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_a_commit_status_that_completed_and_goes_pending_again_starts_a_new_timer(tmp_path):
|
|
111
|
+
w = ci_world(tmp_path, [])
|
|
112
|
+
w.seed(statuses={"head1": [pending_status(1, T)]})
|
|
113
|
+
assert w.checks(wait=60).stdout.strip() == "pending"
|
|
114
|
+
w.set_now(T + 30 * MIN)
|
|
115
|
+
w.seed(statuses={"head1": [{"id": 2, "context": "ci/e2e", "state": "success",
|
|
116
|
+
"created_at": iso(T + 30 * MIN)}, pending_status(1, T)]})
|
|
117
|
+
assert w.checks(wait=60).stdout.strip() == "green"
|
|
118
|
+
w.set_now(T + 120 * MIN)
|
|
119
|
+
w.seed(statuses={"head1": [pending_status(3, T + 120 * MIN)]})
|
|
120
|
+
assert w.checks(wait=60).stdout.strip() == "pending"
|
|
121
|
+
w.set_now(T + 179 * MIN)
|
|
122
|
+
assert w.checks(wait=60).stdout.strip() == "pending"
|
|
123
|
+
w.set_now(T + 180 * MIN)
|
|
124
|
+
assert w.checks(wait=60).stdout.strip() == "CI stalled"
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def test_an_earlier_created_at_learned_after_the_timer_was_persisted_moves_it_back(tmp_path):
|
|
128
|
+
w = ci_world(tmp_path, [dict(run_ci("e2e", "queued"), id=1)]) # no created_at yet
|
|
129
|
+
w.set_now(T + 30 * MIN)
|
|
130
|
+
assert w.checks(wait=60).stdout.strip() == "pending" # persists minute 30
|
|
131
|
+
w.set_now(T + 60 * MIN)
|
|
132
|
+
w.seed(check_runs={"head1": [dict(run_ci("e2e", "queued"), id=1, created_at=iso(T))]})
|
|
133
|
+
assert w.checks(wait=60).stdout.strip() == "CI stalled"
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def test_an_earlier_status_created_at_learned_after_the_timer_was_persisted_moves_it_back(tmp_path):
|
|
137
|
+
w = ci_world(tmp_path, [])
|
|
138
|
+
w.seed(statuses={"head1": [pending_status(1, T + 30 * MIN)]})
|
|
139
|
+
w.set_now(T + 30 * MIN)
|
|
140
|
+
assert w.checks(wait=60).stdout.strip() == "pending" # persists minute 30
|
|
141
|
+
w.set_now(T + 60 * MIN)
|
|
142
|
+
w.seed(statuses={"head1": [pending_status(1, T)]})
|
|
143
|
+
assert w.checks(wait=60).stdout.strip() == "CI stalled"
|