claude-dev-env 8.117.1 → 8.117.2
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/docs/references/working-style.md +3 -0
- package/docs/rule-guides/question-presentation.md +8 -0
- package/hooks/blocking/final_reply_gate.py +20 -7
- package/hooks/blocking/open_tasks_stop_gate.py +133 -7
- package/hooks/blocking/open_tasks_transcript.py +77 -9
- package/hooks/blocking/test_final_reply_gate.py +14 -0
- package/hooks/blocking/test_open_tasks_stop_gate.py +204 -1
- package/hooks/blocking/test_open_tasks_transcript.py +123 -0
- package/hooks/blocking/test_user_step_wording.py +481 -0
- package/hooks/blocking/user_step_wording.py +384 -0
- package/hooks/features/conduct-gates.md +1 -1
- package/hooks/hooks_constants/final_reply_gate_constants.py +1 -1
- package/hooks/hooks_constants/open_tasks_stop_gate_constants.py +58 -5
- package/hooks/hooks_constants/user_step_wording_constants.py +79 -0
- package/package.json +1 -1
- package/rules/question-presentation.md +1 -1
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
import string
|
|
2
|
+
import time
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
import user_step_wording
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@pytest.mark.parametrize(
|
|
11
|
+
("shown_text", "expected_phrase"),
|
|
12
|
+
[
|
|
13
|
+
("The key is set. Two items need you.", "need you"),
|
|
14
|
+
("## What needs you\n\nThe vault key goes into each environment.", "needs you"),
|
|
15
|
+
("The docs pull request is green and needs your merge.", "needs your"),
|
|
16
|
+
("Here is what I need from you today.", "need from you"),
|
|
17
|
+
("The release is waiting on you.", "waiting on you"),
|
|
18
|
+
("The deploy waits for your approval.", "waits for your"),
|
|
19
|
+
("The rollout is blocked on you.", "blocked on you"),
|
|
20
|
+
("You still need to add the key.", "You still need to"),
|
|
21
|
+
("You'll need to sign in first.", "You'll need to"),
|
|
22
|
+
("The pull request is ready for you to merge.", "for you to merge"),
|
|
23
|
+
("Two demo sessions are running, so say when they may be archived.", "say when"),
|
|
24
|
+
("Let me know when the key is in place.", "Let me know when"),
|
|
25
|
+
("Action required: rotate the deploy key.", "Action required"),
|
|
26
|
+
("The build is not merged; it needs you to approve it.", "needs you"),
|
|
27
|
+
("It isn't merged yet and needs your approval.", "needs your"),
|
|
28
|
+
("The pull request is not merged and needs your review.", "needs your"),
|
|
29
|
+
("The pull request with no failing checks needs your approval.", "needs your"),
|
|
30
|
+
("Pull request 12 (not urgent) needs your approval.", "needs your"),
|
|
31
|
+
("- Say when the demo sessions may be archived.", "Say when"),
|
|
32
|
+
("- Nothing is blocked on the runner\n- Pull request 12 needs your approval", "needs your"),
|
|
33
|
+
("Action required: NO_PROXY must list the new host before the rerun.", "Action required"),
|
|
34
|
+
("Needs you: Noël has to sign the access form.", "Needs you"),
|
|
35
|
+
("Action required: No-reply inbox needs a DNS record.", "Action required"),
|
|
36
|
+
("Action required: **No-reply** inbox needs a DNS record.", "Action required"),
|
|
37
|
+
("Action required: no later than Friday, rotate the key.", "Action required"),
|
|
38
|
+
("Needs you: no later than Friday.", "Needs you"),
|
|
39
|
+
("Let me know when none of the old sessions are still open.", "Let me know when"),
|
|
40
|
+
("Tell me when nothing else is running, and I will archive them.", "Tell me when"),
|
|
41
|
+
("**Action required:** None of these can wait, so approve item 12 today.", "Action required"),
|
|
42
|
+
("The release is blocked on you - nothing else is holding it.", "blocked on you"),
|
|
43
|
+
("Action required: no, approve item 12 first.", "Action required"),
|
|
44
|
+
("Action required: no) approve", "Action required"),
|
|
45
|
+
("Action required: No. 12 is ready to merge.", "Action required"),
|
|
46
|
+
("Waiting on you: No. 4 and No. 7.", "Waiting on you"),
|
|
47
|
+
("Action required: no", "Action required"),
|
|
48
|
+
("SKIP_NONE needs your value.", "needs your"),
|
|
49
|
+
("The status__none filter needs your review.", "needs your"),
|
|
50
|
+
("Nothing*needs you.", "needs you"),
|
|
51
|
+
("No**needs your approval**.", "needs your"),
|
|
52
|
+
("It does not*need you*.", "need you"),
|
|
53
|
+
("This isn't**needs you**", "needs you"),
|
|
54
|
+
("Nothing changed--and the deploy needs your approval.", "needs your"),
|
|
55
|
+
("Nothing on this list\rneeds you.", "needs you"),
|
|
56
|
+
("Action\rrequired: none.", "Action\nrequired"),
|
|
57
|
+
("Action required:\rnone.", "Action required"),
|
|
58
|
+
("(Nothing here needs you.)", "needs you"),
|
|
59
|
+
("|No item needs you|", "needs you"),
|
|
60
|
+
("-No item needs you.", "needs you"),
|
|
61
|
+
("Done.Nothing here needs you.", "needs you"),
|
|
62
|
+
("Done. No" + " " * 238 + "needs you.", "needs you"),
|
|
63
|
+
("The do-nothing job " + "x " * 114 + "needs your approval.", "needs your"),
|
|
64
|
+
("A minor" + " x" * 118 + " needs your approval.", "needs your"),
|
|
65
|
+
("y " * 150 + "and no" + " " * 235 + "needs you.", "needs you"),
|
|
66
|
+
("1) Nothing failed\n2) PR 12 needs your merge.", "needs your"),
|
|
67
|
+
("## Nothing failed in CI\nPR 12 needs your merge.", "needs your"),
|
|
68
|
+
("Nothing on this list\nneeds you.", "needs you"),
|
|
69
|
+
("Action required: none... except one: merge PR 12.", "Action required"),
|
|
70
|
+
("Needs you: nothing...merge PR 12 first.", "Needs you"),
|
|
71
|
+
("Action required: none. Merge item 12 first.", "Action required"),
|
|
72
|
+
("Needs you:\nnothing except the merge of PR 12", "Needs you"),
|
|
73
|
+
("Please just say when the demo sessions may be archived.", "say when"),
|
|
74
|
+
("The fix_never flag needs your review.", "needs your"),
|
|
75
|
+
("The do-nothing cron job needs your approval to delete.", "needs your"),
|
|
76
|
+
("The now-or-never deadline needs your approval.", "needs your"),
|
|
77
|
+
("## What needs you\n\nNothing.", "needs you"),
|
|
78
|
+
("- [ ] Say when the demo sessions may be archived.", "Say when"),
|
|
79
|
+
("_Say when_ the demo sessions may be archived.", "Say when"),
|
|
80
|
+
("(Say when the demo sessions may be archived.)", "Say when"),
|
|
81
|
+
("Update the minor " + "z" * 235 + " needs your approval.", "needs your"),
|
|
82
|
+
("Tie the knot " + "z" * 76 + " " + "y" * 76 + " " + "x" * 81 + " needs your approval.", "needs your"),
|
|
83
|
+
("No-reply inbox needs your DNS record.", "needs your"),
|
|
84
|
+
("**No**-reply inbox needs your DNS record.", "needs your"),
|
|
85
|
+
("The do-**nothing** job needs your approval.", "needs your"),
|
|
86
|
+
("The **nothing**-burger job needs your approval.", "needs your"),
|
|
87
|
+
("The yes-and-no question needs your answer.", "needs your"),
|
|
88
|
+
("The yes-**but**-no reply needs your review.", "needs your"),
|
|
89
|
+
("Action\nrequired: none.", "Action\nrequired"),
|
|
90
|
+
("NO_PROXY needs your value before the rerun.", "needs your"),
|
|
91
|
+
("The docs pull request _needs your_ merge.", "needs your"),
|
|
92
|
+
("__Action required__: rotate the deploy key.", "Action required"),
|
|
93
|
+
("Nothing on this list\u2028needs you.", "needs you"),
|
|
94
|
+
("Action\u2028required: none.", "Action\u2028required"),
|
|
95
|
+
("Done.\u2028> Two items need you.", "need you"),
|
|
96
|
+
("Status\u2028~~~\u2028Item 12 needs your merge.\u2028~~~", "needs your"),
|
|
97
|
+
("Status\x0b<div>\x0bItem 12 needs your merge.", "needs your"),
|
|
98
|
+
("Action required: none.\u2028Merge item 12 first.", "Action required"),
|
|
99
|
+
("Action required:\x0cnone.", "Action required"),
|
|
100
|
+
("Item 5 is ready\x85no later than Friday it needs your merge.", "needs your"),
|
|
101
|
+
("The deploy did not start because api`/`web needs your token.", "needs your"),
|
|
102
|
+
("It is not a`x`b c that needs your merge.", "needs your"),
|
|
103
|
+
("It isn't a`x`b c that needs your merge.", "needs your"),
|
|
104
|
+
("Action required: none. `run merge 12`", "Action required"),
|
|
105
|
+
("**Action required:** none `run merge 12`", "Action required"),
|
|
106
|
+
("Action required: none.\ufffc", "Action required"),
|
|
107
|
+
("Action required `now`: none.", "Action required"),
|
|
108
|
+
("No`-reply` inbox needs your record.", "needs your"),
|
|
109
|
+
("Plea\u017fe say when the demo sessions may be archived.", "say when"),
|
|
110
|
+
("Ju\u017ft say when the demo sessions may be archived.", "say when"),
|
|
111
|
+
("\ufeffSay when the demo sessions may be archived.", "Say when"),
|
|
112
|
+
("\u2022 Say when the demo sessions may be archived.", "Say when"),
|
|
113
|
+
("(Please say when the demo sessions may be archived.)", "say when"),
|
|
114
|
+
("**Please** say when the demo sessions may be archived.", "say when"),
|
|
115
|
+
("Not`-`e PR 5 needs your merge.", "needs your"),
|
|
116
|
+
("Item 5 needs `the merge command` your run.", "needs your"),
|
|
117
|
+
],
|
|
118
|
+
)
|
|
119
|
+
def test_should_find_the_phrase_that_says_something_waits_on_the_user(
|
|
120
|
+
shown_text: str, expected_phrase: str
|
|
121
|
+
) -> None:
|
|
122
|
+
assert user_step_wording.waiting_phrase(shown_text) == expected_phrase
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
@pytest.mark.parametrize(
|
|
126
|
+
"shown_text",
|
|
127
|
+
[
|
|
128
|
+
"Both builds passed.",
|
|
129
|
+
"Nothing here needs you.",
|
|
130
|
+
"Nothing else is waiting on you.",
|
|
131
|
+
"None of these need you.",
|
|
132
|
+
"This change does not need you.",
|
|
133
|
+
"No action needed.",
|
|
134
|
+
"The label reads `needs you`.",
|
|
135
|
+
"> What needs you?",
|
|
136
|
+
"```\necho 'this needs you'\n```",
|
|
137
|
+
"None of the open items needs you.",
|
|
138
|
+
"**Nothing** here needs you.",
|
|
139
|
+
"_Nothing_ here needs you.",
|
|
140
|
+
"_No open item_ needs you.",
|
|
141
|
+
"- [ ] No open item needs you.",
|
|
142
|
+
"| No item needs you |",
|
|
143
|
+
"It has never been blocked on you.",
|
|
144
|
+
"This is not something that's waiting on you.",
|
|
145
|
+
"y " * 150 + "and no" + " " * 234 + "needs you.",
|
|
146
|
+
"alpha nothing " + "x" * 231 + " needs you.",
|
|
147
|
+
"No" + " " * 238 + "needs you.",
|
|
148
|
+
"Action required: none.",
|
|
149
|
+
"The docs say when the token expires.",
|
|
150
|
+
"There are no items that need you.",
|
|
151
|
+
"I have not found anything that needs you.",
|
|
152
|
+
"No step on this long list of six open items is waiting on you.",
|
|
153
|
+
"**Action required:** none.",
|
|
154
|
+
"**Action required**: nothing",
|
|
155
|
+
"Needs you: **none**",
|
|
156
|
+
"Needs you — _n/a_",
|
|
157
|
+
"Action required: no action.",
|
|
158
|
+
"Needs you: nothing.\nBoth builds passed.",
|
|
159
|
+
"- [x] Say when the demo sessions may be archived.",
|
|
160
|
+
"Action required: no action needed.",
|
|
161
|
+
"Action required: none at this time.",
|
|
162
|
+
"Needs you - nothing right now!",
|
|
163
|
+
"- No open item needs you.",
|
|
164
|
+
"## No step needs you",
|
|
165
|
+
"# No action needed",
|
|
166
|
+
"2) No item needs your review.",
|
|
167
|
+
"**No** item needs you.",
|
|
168
|
+
"- There are no items that need you.",
|
|
169
|
+
"Action required: no actions.",
|
|
170
|
+
"This change does **not** need you.",
|
|
171
|
+
"Item 12 is merged **and** no other item needs you.",
|
|
172
|
+
"__Action required__: none.",
|
|
173
|
+
"There were no items that need you.",
|
|
174
|
+
"Neither build needs you.",
|
|
175
|
+
"The runner no longer needs you.",
|
|
176
|
+
"Nothing here needs **you**.",
|
|
177
|
+
"Action **required**: none.",
|
|
178
|
+
"No item is waiting on [you](https://example.com/you).",
|
|
179
|
+
"**1)** No reviewer needs your approval.",
|
|
180
|
+
"Nothing in `deploy.yml` needs you.",
|
|
181
|
+
"This change does not `yet` need you.",
|
|
182
|
+
],
|
|
183
|
+
)
|
|
184
|
+
def test_should_find_no_phrase_in_text_that_hands_the_user_nothing(shown_text: str) -> None:
|
|
185
|
+
assert user_step_wording.waiting_phrase(shown_text) is None
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
@pytest.mark.parametrize(
|
|
189
|
+
("shown_text", "expected_phrase"),
|
|
190
|
+
[
|
|
191
|
+
("Pull request 12 needs **your** approval.", "needs **your"),
|
|
192
|
+
("Pull request 12 needs *your* approval.", "needs *your"),
|
|
193
|
+
("Pull request 12 **needs** your approval.", "needs** your"),
|
|
194
|
+
("Three items are waiting on **you**.", "waiting on **you"),
|
|
195
|
+
("The rollout is blocked on _you_.", "blocked on _you"),
|
|
196
|
+
("You **still** need to merge pull request 12.", "You **still** need to"),
|
|
197
|
+
("Let me know **when** the key is set.", "Let me know **when"),
|
|
198
|
+
("Action **required**: merge pull request 12.", "Action **required"),
|
|
199
|
+
("Pull request 12 needs [your approval](https://example.com/12).", "needs [your"),
|
|
200
|
+
("The release is waiting on [you](https://example.com/you).", "waiting on [you"),
|
|
201
|
+
("It does not a b c needs **you need to merge it.", "you need to"),
|
|
202
|
+
],
|
|
203
|
+
)
|
|
204
|
+
def test_should_find_a_phrase_with_emphasis_or_a_link_bracket_between_its_words(
|
|
205
|
+
shown_text: str, expected_phrase: str
|
|
206
|
+
) -> None:
|
|
207
|
+
assert user_step_wording.waiting_phrase(shown_text) == expected_phrase
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
@pytest.mark.parametrize(
|
|
211
|
+
("shown_text", "expected_phrase"),
|
|
212
|
+
[
|
|
213
|
+
(
|
|
214
|
+
"Pull request 12 [needs](https://example.com/12) your approval.",
|
|
215
|
+
"needs](https://example.com/12) your",
|
|
216
|
+
),
|
|
217
|
+
(
|
|
218
|
+
"[You](https://example.com/you) need to merge pull request 12.",
|
|
219
|
+
"You](https://example.com/you) need to",
|
|
220
|
+
),
|
|
221
|
+
(
|
|
222
|
+
"This is for [you](https://example.com/12) to approve.",
|
|
223
|
+
"for [you](https://example.com/12) to approve",
|
|
224
|
+
),
|
|
225
|
+
(
|
|
226
|
+
"Let me [know](https://example.com/form) when the key is set.",
|
|
227
|
+
"Let me [know](https://example.com/form) when",
|
|
228
|
+
),
|
|
229
|
+
("Pull request 12 [**needs**](https://example.com/12) your approval.", "needs**](https://example.com/12) your"),
|
|
230
|
+
("Pull request 12 **[needs](https://example.com/12)** your approval.", "needs](https://example.com/12)** your"),
|
|
231
|
+
("Pull request 12 [needs][1] your approval.", "needs][1] your"),
|
|
232
|
+
("Pull request 12 [needs][] your approval.", "needs][] your"),
|
|
233
|
+
("Pull request 12 [needs] your approval.", "needs] your"),
|
|
234
|
+
("The docs **say** when the token expires.", "say** when"),
|
|
235
|
+
("The docs [say](https://example.com/docs) when the token expires.", "say](https://example.com/docs) when"),
|
|
236
|
+
("- [x] [Say](https://example.com/form) when the demo may be archived.", "Say](https://example.com/form) when"),
|
|
237
|
+
("Pull request 12 [needs](" + "a" * 256 + ") your approval.", "needs](" + "a" * 256 + ") your"),
|
|
238
|
+
("Pull request 12 [needs][" + "a" * 256 + "] your approval.", "needs][" + "a" * 256 + "] your"),
|
|
239
|
+
],
|
|
240
|
+
)
|
|
241
|
+
def test_should_find_a_phrase_with_a_link_around_one_of_its_words(
|
|
242
|
+
shown_text: str, expected_phrase: str
|
|
243
|
+
) -> None:
|
|
244
|
+
assert user_step_wording.waiting_phrase(shown_text) == expected_phrase
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
@pytest.mark.parametrize(
|
|
248
|
+
"shown_text",
|
|
249
|
+
[
|
|
250
|
+
'Pull request 12 [needs](https://example.com/12 "the page") your approval.',
|
|
251
|
+
"Pull request 12 [needs](" + "a" * 257 + ") your approval.",
|
|
252
|
+
"Pull request 12 [needs][" + "a" * 257 + "] your approval.",
|
|
253
|
+
"Pull request 12 [needs][the page] your approval.",
|
|
254
|
+
"Pull request 12 [needs](https://example.com/A_(b)) your approval.",
|
|
255
|
+
"Pull request 12 [needs][a[b]] your approval.",
|
|
256
|
+
"Pull request 12 needs](https://example.com/12)your approval.",
|
|
257
|
+
],
|
|
258
|
+
)
|
|
259
|
+
def test_should_find_no_phrase_across_a_link_target_or_label_outside_its_stated_form(
|
|
260
|
+
shown_text: str,
|
|
261
|
+
) -> None:
|
|
262
|
+
assert user_step_wording.waiting_phrase(shown_text) is None
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
@pytest.mark.parametrize(
|
|
266
|
+
"shown_text",
|
|
267
|
+
[
|
|
268
|
+
"Done.`x`a No item needs you.",
|
|
269
|
+
"Done:`x`a No item needs you.",
|
|
270
|
+
"Done,`x`a No item needs you.",
|
|
271
|
+
"Done and`x`a No item needs you.",
|
|
272
|
+
"Done.ab`x`a No item needs you.",
|
|
273
|
+
"Done.abc`x`a No item needs you.",
|
|
274
|
+
],
|
|
275
|
+
)
|
|
276
|
+
def test_should_hold_a_match_when_a_clause_break_cuts_a_word_that_holds_a_code_span(
|
|
277
|
+
shown_text: str,
|
|
278
|
+
) -> None:
|
|
279
|
+
assert user_step_wording.waiting_phrase(shown_text) == "needs you"
|
|
280
|
+
assert user_step_wording.waiting_phrase(shown_text.replace("`x`a", "")) is None
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def test_should_hold_a_match_that_a_word_with_a_code_span_touches() -> None:
|
|
284
|
+
assert user_step_wording.waiting_phrase("It isn't a b c d`x`needs you.") == "needs you"
|
|
285
|
+
assert user_step_wording.waiting_phrase("It isn't a b c `x`needs you.") is None
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def test_should_skip_a_negated_match_when_only_emphasis_marks_join_a_code_span() -> None:
|
|
289
|
+
assert user_step_wording.waiting_phrase("No **`x`** item needs you.") is None
|
|
290
|
+
assert user_step_wording.waiting_phrase("No **`x`**a item needs you.") == "needs you"
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def test_should_read_the_label_form_before_a_joined_code_span() -> None:
|
|
294
|
+
assert user_step_wording.waiting_phrase("a`x`b Action required: none.") is None
|
|
295
|
+
assert user_step_wording.waiting_phrase("a`x`b Nothing here is an action required.") == "action required"
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def test_should_read_joined_code_spans_only_in_the_text_a_match_looks_back_over() -> None:
|
|
299
|
+
negated_tail = " nothing here needs you."
|
|
300
|
+
assert user_step_wording.waiting_phrase("y" * 300 + "`x`" + "z" * 20 + negated_tail) == "needs you"
|
|
301
|
+
assert user_step_wording.waiting_phrase("y" * 20 + "`x`" + "z" * 300 + negated_tail) is None
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def test_should_skip_a_match_only_when_a_negating_word_leads_it_in_the_same_clause() -> None:
|
|
305
|
+
assert (
|
|
306
|
+
user_step_wording.waiting_phrase_in_prose("Nothing is open. One item needs you.")
|
|
307
|
+
== "needs you"
|
|
308
|
+
)
|
|
309
|
+
assert user_step_wording.waiting_phrase_in_prose("No step here needs you.") is None
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def test_should_hold_a_negating_word_with_any_other_character_joined_to_it() -> None:
|
|
313
|
+
all_sentence_frames = {
|
|
314
|
+
"nothing": "{word} here needs you.",
|
|
315
|
+
"none": "{word} of these needs you.",
|
|
316
|
+
"nobody": "{word} here needs you.",
|
|
317
|
+
"no": "{word} open item needs you.",
|
|
318
|
+
"neither": "{word} build needs you.",
|
|
319
|
+
"nor": "{word} this build needs you.",
|
|
320
|
+
"not": "It does {word} need you.",
|
|
321
|
+
"never": "It is {word} blocked on you.",
|
|
322
|
+
"without": "It runs {word} waiting on you.",
|
|
323
|
+
}
|
|
324
|
+
all_joined_characters = [each_character for each_character in string.punctuation + "a0" if each_character not in "*_"]
|
|
325
|
+
all_plain_texts = [each_frame.format(word=each_negator) for each_negator, each_frame in all_sentence_frames.items()]
|
|
326
|
+
assert [user_step_wording.waiting_phrase_in_prose(each_text) for each_text in all_plain_texts] == [None] * len(
|
|
327
|
+
all_plain_texts
|
|
328
|
+
)
|
|
329
|
+
all_joined_texts = [
|
|
330
|
+
each_frame.format(word=each_joined_word)
|
|
331
|
+
for each_negator, each_frame in all_sentence_frames.items()
|
|
332
|
+
for each_character in all_joined_characters
|
|
333
|
+
for each_joined_word in (each_character + each_negator, each_negator + each_character)
|
|
334
|
+
]
|
|
335
|
+
all_skipped_texts = [
|
|
336
|
+
each_text for each_text in all_joined_texts if user_step_wording.waiting_phrase_in_prose(each_text) is None
|
|
337
|
+
]
|
|
338
|
+
assert len(all_joined_texts) > len(all_plain_texts) * len(all_joined_characters)
|
|
339
|
+
assert all_skipped_texts == []
|
|
340
|
+
assert user_step_wording.waiting_phrase_in_prose("It isn't waiting on you.") is None
|
|
341
|
+
assert user_step_wording.waiting_phrase_in_prose("It isn't- waiting on you.") == "waiting on you"
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
@pytest.mark.parametrize("line_end", ["\x0b", "\x0c", "\x1c", "\x1d", "\x1e", "\x85", "\u2028", "\u2029"])
|
|
345
|
+
def test_should_hold_every_match_in_a_paragraph_with_an_odd_line_end(line_end: str) -> None:
|
|
346
|
+
assert "a\nb".splitlines() == ("a" + line_end + "b").splitlines()
|
|
347
|
+
all_negated_texts = [
|
|
348
|
+
"Nothing on this list" + line_end + "needs you.",
|
|
349
|
+
"Nothing here needs you." + line_end,
|
|
350
|
+
line_end + "No open item needs you.",
|
|
351
|
+
"Action required: none." + line_end + "Merge item 12 first.",
|
|
352
|
+
"Action required:" + line_end + "none.",
|
|
353
|
+
"The docs" + line_end + "say when the token expires.",
|
|
354
|
+
]
|
|
355
|
+
all_skipped_texts = [
|
|
356
|
+
each_text for each_text in all_negated_texts if user_step_wording.waiting_phrase_in_prose(each_text) is None
|
|
357
|
+
]
|
|
358
|
+
assert all_skipped_texts == []
|
|
359
|
+
assert user_step_wording.waiting_phrase("Nothing here needs you.\n\nBoth builds passed." + line_end) is None
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def test_should_read_a_long_text_of_negated_phrases_in_linear_time() -> None:
|
|
363
|
+
long_text = "No action needed.\n" * 60000
|
|
364
|
+
started_at = time.perf_counter()
|
|
365
|
+
assert user_step_wording.waiting_phrase_in_prose(long_text) is None
|
|
366
|
+
assert time.perf_counter() - started_at < 5
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def test_should_read_a_last_line_of_tildes_with_no_line_end_in_linear_time() -> None:
|
|
370
|
+
started_at = time.perf_counter()
|
|
371
|
+
assert user_step_wording.waiting_phrase("Both builds passed.\n" + "~" * 200000) is None
|
|
372
|
+
assert time.perf_counter() - started_at < 5
|
|
373
|
+
assert user_step_wording.waiting_phrase("~~~~\nTwo items need you.\n~~~~\nBoth builds passed.") is None
|
|
374
|
+
assert user_step_wording.waiting_phrase("~~~ text\nlog line\n~~~\nTwo items need you.") == "need you"
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
def test_should_leave_code_quotes_and_unclosed_script_openers_out_of_an_html_page() -> None:
|
|
378
|
+
page_markup = "<p>Status</p><code>needs you</code><pre>waiting on you</pre><blockquote>say when</blockquote>"
|
|
379
|
+
assert user_step_wording.html_visible_text(page_markup).split() == ["Status"]
|
|
380
|
+
started_at = time.perf_counter()
|
|
381
|
+
user_step_wording.html_visible_text("<script " * 30000)
|
|
382
|
+
assert time.perf_counter() - started_at < 5
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
@pytest.mark.parametrize(
|
|
386
|
+
("page_markup", "expected_phrase"),
|
|
387
|
+
[
|
|
388
|
+
("<p>Nothing in <code>x</code> needs you.</p>", None),
|
|
389
|
+
("<p>No item on the <abbr>PR</abbr> list <br>needs you.</p>", "needs you"),
|
|
390
|
+
("<p>None of the open items\n needs you.</p>", None),
|
|
391
|
+
("<p>Nothing failed<br>PR 12 needs your merge</p>", "needs your"),
|
|
392
|
+
("<title>What needs you</title><template>Two items need you.</template><p>Both builds passed.</p>", None),
|
|
393
|
+
("<ul><li>Nothing is blocked</li><li>Pull request 12 needs your approval</li></ul>", "needs your"),
|
|
394
|
+
("<p>Both builds passed.</p></code><p>Two items need you.</p>", "need you"),
|
|
395
|
+
("<h2>What it needs</h2><p>You can skip this section.</p>", None),
|
|
396
|
+
("<h2>Action required</h2><p>None of the items below can ship until you approve item 12.</p>", "Action required"),
|
|
397
|
+
("<table><tr><td>Needs you</td><td>none</td></tr></table>", "Needs you"),
|
|
398
|
+
("<p>Action required: <b>none</b>.</p>", None),
|
|
399
|
+
("<p>No<code>-reply</code> inbox needs your record.</p>", "needs your"),
|
|
400
|
+
("<p>Action required: none.<code>run merge 12</code></p>", "Action required"),
|
|
401
|
+
("<p>Action required: none.
Merge item 12 first.</p>", "Action required"),
|
|
402
|
+
("<p>Item 5 is ready
no later than Friday it needs your merge.</p>", "needs your"),
|
|
403
|
+
("<p>Item 5 needs <code>the merge command</code> your run.</p>", "needs your"),
|
|
404
|
+
("<p>Pull request 12 need<code></code>s your approval.</p>", "needs your"),
|
|
405
|
+
("<p>Three items ne<code>x</code>ed you.</p>", "need you"),
|
|
406
|
+
("<p>A<code>x</code>ction required: none.\ufffc</p>", "Action required"),
|
|
407
|
+
],
|
|
408
|
+
)
|
|
409
|
+
def test_should_find_the_phrase_in_each_block_of_a_sent_html_page(
|
|
410
|
+
tmp_path: Path, page_markup: str, expected_phrase: str | None
|
|
411
|
+
) -> None:
|
|
412
|
+
page_path = tmp_path / "status.html"
|
|
413
|
+
page_path.write_text(page_markup, encoding="utf-8")
|
|
414
|
+
assert user_step_wording.file_waiting_phrase(str(page_path), None) == expected_phrase
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def test_should_read_a_sent_file_at_the_size_limit_and_skip_one_byte_past_it(tmp_path: Path) -> None:
|
|
418
|
+
phrase_bytes = b"Two items need you."
|
|
419
|
+
size_limit = user_step_wording.MAXIMUM_SENT_FILE_BYTES
|
|
420
|
+
(tmp_path / "at-limit.txt").write_bytes(b" " * (size_limit - len(phrase_bytes)) + phrase_bytes)
|
|
421
|
+
(tmp_path / "past-limit.txt").write_bytes(b" " * (size_limit + 1 - len(phrase_bytes)) + phrase_bytes)
|
|
422
|
+
assert user_step_wording.file_waiting_phrase(str(tmp_path / "at-limit.txt"), None) == "need you"
|
|
423
|
+
assert user_step_wording.file_waiting_phrase(str(tmp_path / "past-limit.txt"), None) is None
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def test_should_read_an_html_page_as_its_visible_text() -> None:
|
|
427
|
+
page_markup = "<style>.a{color:red}</style><h2>What needs you</h2><script>var needsYou = 1</script><p>Merge it.</p>"
|
|
428
|
+
visible_text = user_step_wording.html_visible_text(page_markup)
|
|
429
|
+
assert "What needs you" in visible_text
|
|
430
|
+
assert "Merge\xa0it." in visible_text
|
|
431
|
+
assert user_step_wording.html_visible_text("<p>Nothing <b>here</b> needs you.</p>").strip() == "Nothing here needs you."
|
|
432
|
+
assert "color:red" not in visible_text
|
|
433
|
+
assert "needsYou" not in visible_text
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
@pytest.mark.parametrize(
|
|
437
|
+
("file_name", "file_text"),
|
|
438
|
+
[
|
|
439
|
+
("status.md", "## What needs you\n\nAdd the key."),
|
|
440
|
+
("status.txt", "What needs you: add the key."),
|
|
441
|
+
("status.html", "<h2>What needs you</h2><p>Add the key.</p>"),
|
|
442
|
+
],
|
|
443
|
+
)
|
|
444
|
+
def test_should_find_the_phrase_in_a_sent_text_file(tmp_path: Path, file_name: str, file_text: str) -> None:
|
|
445
|
+
(tmp_path / file_name).write_text(file_text, encoding="utf-8")
|
|
446
|
+
assert user_step_wording.file_waiting_phrase(str(tmp_path / file_name), None) == "needs you"
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
def test_should_leave_a_markdown_html_block_out_and_read_the_same_markup_in_an_html_file(tmp_path: Path) -> None:
|
|
450
|
+
page_markup = "<div>\nWhat needs you\n</div>"
|
|
451
|
+
(tmp_path / "status.md").write_text(page_markup, encoding="utf-8")
|
|
452
|
+
(tmp_path / "status.html").write_text(page_markup, encoding="utf-8")
|
|
453
|
+
assert user_step_wording.file_waiting_phrase(str(tmp_path / "status.md"), None) is None
|
|
454
|
+
assert user_step_wording.file_waiting_phrase(str(tmp_path / "status.html"), None) == "needs you"
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def test_should_read_a_relative_sent_file_from_the_working_directory(tmp_path: Path) -> None:
|
|
458
|
+
(tmp_path / "status.md").write_text("Two items need you.", encoding="utf-8")
|
|
459
|
+
assert user_step_wording.file_waiting_phrase("status.md", str(tmp_path)) == "need you"
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
def test_should_skip_a_sent_file_that_is_no_text_file_is_too_large_or_is_missing(
|
|
463
|
+
tmp_path: Path,
|
|
464
|
+
) -> None:
|
|
465
|
+
(tmp_path / "status.png").write_text("Two items need you.", encoding="utf-8")
|
|
466
|
+
(tmp_path / "large.md").write_text("Two items need you. " * 20000, encoding="utf-8")
|
|
467
|
+
assert user_step_wording.file_waiting_phrase(str(tmp_path / "status.png"), None) is None
|
|
468
|
+
assert user_step_wording.file_waiting_phrase(str(tmp_path / "large.md"), None) is None
|
|
469
|
+
assert user_step_wording.file_waiting_phrase(str(tmp_path / "missing.md"), None) is None
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
def test_should_never_open_a_sent_path_that_is_no_regular_file_or_cannot_be_a_path(
|
|
473
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
474
|
+
) -> None:
|
|
475
|
+
folder_path = tmp_path / "folder.md"
|
|
476
|
+
folder_path.mkdir()
|
|
477
|
+
all_opened_paths: list[Path] = []
|
|
478
|
+
monkeypatch.setattr(Path, "open", lambda opened_path, *all_arguments, **all_options: all_opened_paths.append(opened_path))
|
|
479
|
+
assert user_step_wording.file_waiting_phrase(str(folder_path), None) is None
|
|
480
|
+
assert user_step_wording.file_waiting_phrase("status\x00.md", str(tmp_path)) is None
|
|
481
|
+
assert all_opened_paths == []
|