claude-dev-env 8.116.3 → 8.116.5
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/hooks/blocking/followup_pr_dedupe.py +59 -41
- package/hooks/blocking/pull_request_proof.py +76 -78
- package/hooks/blocking/test_followup_pr_dedupe.py +81 -0
- package/hooks/blocking/test_pr_lifecycle_skill_gate.py +38 -0
- package/hooks/blocking/test_pull_request_proof.py +67 -0
- package/hooks/validators/ruff_integration.py +46 -4
- package/hooks/validators/test_ruff_integration.py +67 -5
- package/package.json +1 -1
|
@@ -192,34 +192,20 @@ def _all_create_argument_lists(command: str) -> Iterator[list[str]]:
|
|
|
192
192
|
|
|
193
193
|
def _arguments_draft(all_arguments: list[str], working_directory: str) -> PullRequestDraft | None:
|
|
194
194
|
body = body_from_arguments(all_arguments, working_directory)
|
|
195
|
+
if body is None or followup_parent_number(body) is None:
|
|
196
|
+
return None
|
|
195
197
|
repository = _repository_from_arguments(all_arguments, working_directory)
|
|
196
|
-
if
|
|
198
|
+
if repository is None:
|
|
197
199
|
return None
|
|
198
200
|
return PullRequestDraft(repository[0], repository[1], body)
|
|
199
201
|
|
|
200
202
|
|
|
201
|
-
def
|
|
203
|
+
def _shell_followup_drafts(command: str, working_directory: str) -> list[PullRequestDraft]:
|
|
202
204
|
all_drafts = (
|
|
203
205
|
_arguments_draft(all_arguments, working_directory)
|
|
204
206
|
for all_arguments in _all_create_argument_lists(command)
|
|
205
207
|
)
|
|
206
|
-
return
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
def _names_a_parent(all_payload_fields: Mapping[str, object]) -> bool:
|
|
210
|
-
create_fields = create_tool_fields(all_payload_fields)
|
|
211
|
-
if create_fields is not None:
|
|
212
|
-
body = create_fields.get("body")
|
|
213
|
-
return isinstance(body, str) and followup_parent_number(body) is not None
|
|
214
|
-
command = shell_command(all_payload_fields)
|
|
215
|
-
if command is None:
|
|
216
|
-
return False
|
|
217
|
-
working_directory = _working_directory(all_payload_fields)
|
|
218
|
-
return any(
|
|
219
|
-
(body := body_from_arguments(all_arguments, working_directory)) is not None
|
|
220
|
-
and followup_parent_number(body) is not None
|
|
221
|
-
for all_arguments in _all_create_argument_lists(command)
|
|
222
|
-
)
|
|
208
|
+
return list(dict.fromkeys(each_draft for each_draft in all_drafts if each_draft is not None))
|
|
223
209
|
|
|
224
210
|
|
|
225
211
|
def shell_command(all_payload_fields: Mapping[str, object]) -> str | None:
|
|
@@ -281,18 +267,50 @@ def create_tool_fields(all_payload_fields: Mapping[str, object]) -> Mapping[str,
|
|
|
281
267
|
return _dispatch_fields(tool_input) if tool_name.endswith(WORKFLOW_DISPATCH_TOOL_SUFFIX) else None
|
|
282
268
|
|
|
283
269
|
|
|
284
|
-
def
|
|
285
|
-
"""Return
|
|
270
|
+
def followup_drafts(all_payload_fields: Mapping[str, object]) -> list[PullRequestDraft]:
|
|
271
|
+
"""Return one draft per distinct repository and body among the creates whose body names a parent.
|
|
272
|
+
|
|
273
|
+
::
|
|
274
|
+
|
|
275
|
+
create on o/r "Follow-up to #7" && create on o/r "Follow-up to #8" -> both drafts
|
|
276
|
+
create_pull_request {owner, repo, body "Follow-up to #7"} -> that one draft
|
|
277
|
+
create whose body names no parent, or any other tool -> []
|
|
278
|
+
|
|
279
|
+
A body that names no parent gives no draft before any repository or
|
|
280
|
+
origin read. A quoted create, which the command parser reads twice,
|
|
281
|
+
gives one draft.
|
|
282
|
+
|
|
283
|
+
Args:
|
|
284
|
+
all_payload_fields: The parsed PreToolUse input.
|
|
285
|
+
|
|
286
|
+
Returns:
|
|
287
|
+
The drafts, in command order.
|
|
288
|
+
"""
|
|
286
289
|
create_fields = create_tool_fields(all_payload_fields)
|
|
287
290
|
if create_fields is not None:
|
|
288
291
|
owner, repo, body = (create_fields.get(each_key) for each_key in ("owner", "repo", "body"))
|
|
289
|
-
if isinstance(
|
|
290
|
-
return
|
|
291
|
-
return
|
|
292
|
+
if not isinstance(body, str) or followup_parent_number(body) is None:
|
|
293
|
+
return []
|
|
294
|
+
return [PullRequestDraft(owner, repo, body)] if isinstance(owner, str) and isinstance(repo, str) else []
|
|
292
295
|
command = shell_command(all_payload_fields)
|
|
293
296
|
if command is None:
|
|
297
|
+
return []
|
|
298
|
+
return _shell_followup_drafts(command, _working_directory(all_payload_fields))
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def _open_pull_requests_once(
|
|
302
|
+
owner: str, repo: str, read_open: OpenPullRequestReader
|
|
303
|
+
) -> list[Mapping[str, object]] | None:
|
|
304
|
+
return answer_once(("open pull requests", owner, repo), lambda: _open_pull_requests_or_none(owner, repo, read_open))
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def _open_pull_requests_or_none(
|
|
308
|
+
owner: str, repo: str, read_open: OpenPullRequestReader
|
|
309
|
+
) -> list[Mapping[str, object]] | None:
|
|
310
|
+
try:
|
|
311
|
+
return read_open(owner, repo)
|
|
312
|
+
except Exception:
|
|
294
313
|
return None
|
|
295
|
-
return _shell_draft(command, _working_directory(all_payload_fields))
|
|
296
314
|
|
|
297
315
|
|
|
298
316
|
def _reason_for_parent(
|
|
@@ -318,25 +336,25 @@ def duplicate_followup_reason(
|
|
|
318
336
|
) -> str | None:
|
|
319
337
|
"""Return a deny reason when an open pull request already follows up the same parent.
|
|
320
338
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
339
|
+
Every create body that names a parent is checked, in command order, and
|
|
340
|
+
the first duplicate denies. A read that fails skips that create. When no
|
|
341
|
+
create body carries a "Follow-up to #N" line, nothing is read, not even
|
|
342
|
+
the origin remote.
|
|
324
343
|
|
|
325
344
|
Args:
|
|
326
345
|
all_payload_fields: The parsed PreToolUse input.
|
|
327
346
|
read_open: Reads the open pull requests of an owner and repository;
|
|
328
347
|
None reads them from the GitHub API.
|
|
329
348
|
"""
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
return _reason_for_parent(parent_number, all_open_pull_requests)
|
|
349
|
+
reader = read_open or read_open_pull_requests
|
|
350
|
+
for each_draft in followup_drafts(all_payload_fields):
|
|
351
|
+
parent_number = followup_parent_number(each_draft.body)
|
|
352
|
+
if parent_number is None:
|
|
353
|
+
continue
|
|
354
|
+
all_open_pull_requests = _open_pull_requests_once(each_draft.owner, each_draft.repo, reader)
|
|
355
|
+
if all_open_pull_requests is None:
|
|
356
|
+
continue
|
|
357
|
+
reason = _reason_for_parent(parent_number, all_open_pull_requests)
|
|
358
|
+
if reason is not None:
|
|
359
|
+
return reason
|
|
360
|
+
return None
|
|
@@ -112,10 +112,17 @@ from hooks_constants.shell_command_wrappers import segment_program_and_arguments
|
|
|
112
112
|
|
|
113
113
|
|
|
114
114
|
class CreateCall(NamedTuple):
|
|
115
|
-
"""The title and
|
|
115
|
+
"""The title, body, head, base and repository one pull request create call passes.
|
|
116
|
+
|
|
117
|
+
None in title or body marks a value this gate cannot read. None in head,
|
|
118
|
+
base or repository marks a value the create does not name.
|
|
119
|
+
"""
|
|
116
120
|
|
|
117
121
|
title: str | None
|
|
118
122
|
body: str | None
|
|
123
|
+
head: str | None
|
|
124
|
+
base: str | None
|
|
125
|
+
repository: str | None
|
|
119
126
|
|
|
120
127
|
|
|
121
128
|
def _heading_level(line: str, heading_pattern: str) -> int | None:
|
|
@@ -235,6 +242,9 @@ def _shell_create_calls(command: str, working_directory: str) -> list[CreateCall
|
|
|
235
242
|
CreateCall(
|
|
236
243
|
title_from_arguments(all_create_arguments),
|
|
237
244
|
body_from_arguments(all_create_arguments, working_directory),
|
|
245
|
+
_flag_value(all_create_arguments, ALL_HEAD_FLAGS, HEAD_FLAG_ASSIGNMENT_PREFIX) or None,
|
|
246
|
+
_flag_value(all_create_arguments, ALL_BASE_FLAGS, BASE_FLAG_ASSIGNMENT_PREFIX) or None,
|
|
247
|
+
_flag_value(all_create_arguments, ALL_REPOSITORY_FLAGS, REPOSITORY_FLAG_ASSIGNMENT_PREFIX) or None,
|
|
238
248
|
)
|
|
239
249
|
for all_create_arguments in _all_create_argument_lists(command)
|
|
240
250
|
]
|
|
@@ -249,59 +259,29 @@ def _flag_value(all_create_arguments: list[str], all_flags: frozenset[str], assi
|
|
|
249
259
|
return None
|
|
250
260
|
|
|
251
261
|
|
|
252
|
-
def
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
command = shell_command(all_payload_fields)
|
|
256
|
-
if command is None:
|
|
257
|
-
return None
|
|
258
|
-
all_flag_values = [
|
|
259
|
-
_flag_value(all_create_arguments, all_flags, assignment_prefix)
|
|
260
|
-
for all_create_arguments in _all_create_argument_lists(command)
|
|
261
|
-
]
|
|
262
|
-
return next((each_value for each_value in all_flag_values if each_value), None)
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
def _named_create_field(
|
|
266
|
-
all_payload_fields: Mapping[str, object], field_name: str, all_flags: frozenset[str], assignment_prefix: str
|
|
267
|
-
) -> str | None:
|
|
268
|
-
create_fields = create_tool_fields(all_payload_fields)
|
|
269
|
-
field_value = None if create_fields is None else create_fields.get(field_name)
|
|
270
|
-
if isinstance(field_value, str) and field_value:
|
|
271
|
-
return field_value
|
|
272
|
-
return _shell_flag_value(all_payload_fields, all_flags, assignment_prefix)
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
def _named_head_branch(all_payload_fields: Mapping[str, object]) -> str | None:
|
|
276
|
-
return _named_create_field(all_payload_fields, "head", ALL_HEAD_FLAGS, HEAD_FLAG_ASSIGNMENT_PREFIX)
|
|
262
|
+
def _named_text(all_create_fields: Mapping[str, object], field_name: str) -> str | None:
|
|
263
|
+
field_value = all_create_fields.get(field_name)
|
|
264
|
+
return field_value if isinstance(field_value, str) and field_value else None
|
|
277
265
|
|
|
278
266
|
|
|
279
|
-
def
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
return _shell_flag_value(all_payload_fields, ALL_REPOSITORY_FLAGS, REPOSITORY_FLAG_ASSIGNMENT_PREFIX)
|
|
267
|
+
def _mcp_create_call(all_create_fields: Mapping[str, object]) -> CreateCall:
|
|
268
|
+
title = all_create_fields.get("title")
|
|
269
|
+
body = all_create_fields.get("body")
|
|
270
|
+
owner = _named_text(all_create_fields, "owner")
|
|
271
|
+
repository_name = _named_text(all_create_fields, "repo")
|
|
272
|
+
return CreateCall(
|
|
273
|
+
title if isinstance(title, str) else None,
|
|
274
|
+
body if isinstance(body, str) else "",
|
|
275
|
+
_named_text(all_create_fields, "head"),
|
|
276
|
+
_named_text(all_create_fields, "base"),
|
|
277
|
+
f"{owner}/{repository_name}" if owner and repository_name else None,
|
|
278
|
+
)
|
|
292
279
|
|
|
293
280
|
|
|
294
281
|
def _create_calls(all_payload_fields: Mapping[str, object]) -> list[CreateCall]:
|
|
295
282
|
create_fields = create_tool_fields(all_payload_fields)
|
|
296
283
|
if create_fields is not None:
|
|
297
|
-
|
|
298
|
-
body = create_fields.get("body")
|
|
299
|
-
return [
|
|
300
|
-
CreateCall(
|
|
301
|
-
title if isinstance(title, str) else None,
|
|
302
|
-
body if isinstance(body, str) else "",
|
|
303
|
-
)
|
|
304
|
-
]
|
|
284
|
+
return [_mcp_create_call(create_fields)]
|
|
305
285
|
command = shell_command(all_payload_fields)
|
|
306
286
|
if command is None:
|
|
307
287
|
return []
|
|
@@ -576,36 +556,38 @@ def missing_proof_reason(all_payload_fields: Mapping[str, object]) -> str | None
|
|
|
576
556
|
the run, and the line uses the word run outside code spans and says workflow
|
|
577
557
|
or GitHub Actions or names a covered workflow file; see
|
|
578
558
|
_first_unwaived_admission. The same covered line is exempt from the merge word.
|
|
559
|
+
The waiver reads the head branch of the create whose body holds the admission.
|
|
579
560
|
|
|
580
561
|
Args:
|
|
581
562
|
all_payload_fields: The parsed PreToolUse input.
|
|
582
563
|
"""
|
|
583
|
-
|
|
584
|
-
|
|
564
|
+
working_directory = str(all_payload_fields.get("cwd") or "")
|
|
565
|
+
for each_call in _create_calls(all_payload_fields):
|
|
566
|
+
if each_call.body is None:
|
|
585
567
|
return MISSING_BODY_REASON
|
|
586
|
-
section = proof_section(
|
|
568
|
+
section = proof_section(each_call.body)
|
|
587
569
|
if not section:
|
|
588
570
|
return MISSING_PROOF_REASON
|
|
589
|
-
section_reason = _proof_section_reason(section,
|
|
571
|
+
section_reason = _proof_section_reason(section, each_call, working_directory)
|
|
590
572
|
if section_reason is not None:
|
|
591
573
|
return section_reason
|
|
592
574
|
return None
|
|
593
575
|
|
|
594
576
|
|
|
595
577
|
def _proof_section_reason(
|
|
596
|
-
section: str,
|
|
578
|
+
section: str, create_call: CreateCall | None = None, working_directory: str = ""
|
|
597
579
|
) -> str | None:
|
|
598
580
|
if COMMAND_MARKER not in section:
|
|
599
581
|
return MISSING_PROOF_REASON
|
|
600
582
|
if _proof_runs_only_tests(section):
|
|
601
583
|
return TEST_ONLY_PROOF_REASON
|
|
602
584
|
all_admissions = unproven_admissions(section)
|
|
603
|
-
if
|
|
585
|
+
if create_call is None or create_call.body is None:
|
|
604
586
|
unwaived_admission = all_admissions[0] if all_admissions else None
|
|
605
587
|
all_covered_names: list[str] = []
|
|
606
588
|
else:
|
|
607
589
|
needs_waiver = bool(all_admissions) or merge_word_line(section) is not None
|
|
608
|
-
all_covered_names = _covered_workflow_names(
|
|
590
|
+
all_covered_names = _covered_workflow_names(create_call, working_directory) if needs_waiver else []
|
|
609
591
|
unwaived_admission = _first_unwaived_admission(all_admissions, all_covered_names)
|
|
610
592
|
if unwaived_admission is not None:
|
|
611
593
|
return UNPROVEN_PROOF_REASON.format(admission=unwaived_admission)
|
|
@@ -992,11 +974,8 @@ def remote_added_workflow_files(
|
|
|
992
974
|
return None
|
|
993
975
|
|
|
994
976
|
|
|
995
|
-
def _added_workflow_files_for_create(
|
|
996
|
-
|
|
997
|
-
head_branch = _named_head_branch(all_payload_fields)
|
|
998
|
-
repository = _named_repository(all_payload_fields)
|
|
999
|
-
base_branch = _named_base_branch(all_payload_fields)
|
|
977
|
+
def _added_workflow_files_for_create(create_call: CreateCall, working_directory: str) -> list[str]:
|
|
978
|
+
repository, base_branch, head_branch = create_call.repository, create_call.base, create_call.head
|
|
1000
979
|
return answer_once(
|
|
1001
980
|
("added workflow files", working_directory, repository, base_branch, head_branch),
|
|
1002
981
|
lambda: _read_added_workflow_files(working_directory, repository, base_branch, head_branch),
|
|
@@ -1067,7 +1046,7 @@ def _admission_is_about_a_first_run(admission: str, all_workflow_names: list[str
|
|
|
1067
1046
|
)
|
|
1068
1047
|
|
|
1069
1048
|
|
|
1070
|
-
def _covered_workflow_names(
|
|
1049
|
+
def _covered_workflow_names(create_call: CreateCall, working_directory: str) -> list[str]:
|
|
1071
1050
|
"""Return the added workflow files whose first run the body plans for after the merge.
|
|
1072
1051
|
|
|
1073
1052
|
::
|
|
@@ -1082,17 +1061,17 @@ def _covered_workflow_names(body: str, all_payload_fields: Mapping[str, object])
|
|
|
1082
1061
|
count as that prose. A sentence with a negation ahead of the verb does not count.
|
|
1083
1062
|
|
|
1084
1063
|
Args:
|
|
1085
|
-
|
|
1086
|
-
|
|
1064
|
+
create_call: The create whose body and head branch are read.
|
|
1065
|
+
working_directory: The session directory the hook payload names.
|
|
1087
1066
|
"""
|
|
1088
|
-
after_merge = _section_text(body, AFTER_MERGE_HEADING_PATTERN)
|
|
1067
|
+
after_merge = _section_text(create_call.body or "", AFTER_MERGE_HEADING_PATTERN)
|
|
1089
1068
|
if not after_merge:
|
|
1090
1069
|
return []
|
|
1091
1070
|
outside_fence_text = _text_outside_fences(after_merge)
|
|
1092
1071
|
if not _prose_names_a_recorder(re.sub(INLINE_CODE_SPAN_PATTERN, "", outside_fence_text)):
|
|
1093
1072
|
return []
|
|
1094
1073
|
all_names = []
|
|
1095
|
-
for each_path in _added_workflow_files_for_create(
|
|
1074
|
+
for each_path in _added_workflow_files_for_create(create_call, working_directory):
|
|
1096
1075
|
each_name = each_path.rsplit("/", 1)[-1]
|
|
1097
1076
|
if f"`{each_path}`" in outside_fence_text or f"`{each_name}`" in outside_fence_text:
|
|
1098
1077
|
all_names.append(each_name)
|
|
@@ -1124,29 +1103,48 @@ def missing_look_reason(all_payload_fields: Mapping[str, object]) -> str | None:
|
|
|
1124
1103
|
git cannot read the branch, compare API lists only .py files -> None
|
|
1125
1104
|
git cannot read the branch, compare API returns 300 .py files -> UNREADABLE_CHANGES_REASON
|
|
1126
1105
|
neither git nor the compare API can read it, no picture -> UNREADABLE_CHANGES_REASON
|
|
1106
|
+
create --head a && create --head b, only b changes page.html -> MISSING_LOOK_REASON
|
|
1127
1107
|
|
|
1128
1108
|
Every body is checked for a picture first. When each one shows a picture,
|
|
1129
|
-
the check passes and reads neither git nor the compare API.
|
|
1109
|
+
the check passes and reads neither git nor the compare API. Each create
|
|
1110
|
+
is checked against its own head, base and repository, in command order,
|
|
1111
|
+
and the first deny wins.
|
|
1130
1112
|
|
|
1131
1113
|
Args:
|
|
1132
1114
|
all_payload_fields: The parsed PreToolUse input.
|
|
1133
1115
|
"""
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1116
|
+
working_directory = str(all_payload_fields.get("cwd") or "")
|
|
1117
|
+
all_calls_without_picture = [
|
|
1118
|
+
each_call
|
|
1119
|
+
for each_call in _create_calls(all_payload_fields)
|
|
1120
|
+
if each_call.body is not None
|
|
1121
|
+
and not re.search(PROOF_IMAGE_PATTERN, proof_section(each_call.body) or "", re.IGNORECASE)
|
|
1138
1122
|
]
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
all_visible_files = remote_visible_changed_files(
|
|
1146
|
-
_named_repository(all_payload_fields), _named_base_branch(all_payload_fields), head_branch
|
|
1147
|
-
)
|
|
1123
|
+
all_reasons = (_look_reason_for_create(each_call, working_directory) for each_call in all_calls_without_picture)
|
|
1124
|
+
return next((each_reason for each_reason in all_reasons if each_reason is not None), None)
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
def _look_reason_for_create(create_call: CreateCall, working_directory: str) -> str | None:
|
|
1128
|
+
all_visible_files = _visible_files_for_create(create_call, working_directory)
|
|
1148
1129
|
if all_visible_files == []:
|
|
1149
1130
|
return None
|
|
1150
1131
|
if all_visible_files is None:
|
|
1151
1132
|
return UNREADABLE_CHANGES_REASON
|
|
1152
1133
|
return MISSING_LOOK_REASON.format(changed_files=CHANGED_FILES_SEPARATOR.join(all_visible_files))
|
|
1134
|
+
|
|
1135
|
+
|
|
1136
|
+
def _visible_files_for_create(create_call: CreateCall, working_directory: str) -> list[str] | None:
|
|
1137
|
+
repository, base_branch, head_branch = create_call.repository, create_call.base, create_call.head
|
|
1138
|
+
return answer_once(
|
|
1139
|
+
("visible changed files", working_directory, repository, base_branch, head_branch),
|
|
1140
|
+
lambda: _read_visible_files(working_directory, repository, base_branch, head_branch),
|
|
1141
|
+
)
|
|
1142
|
+
|
|
1143
|
+
|
|
1144
|
+
def _read_visible_files(
|
|
1145
|
+
working_directory: str, repository: str | None, base_branch: str | None, head_branch: str | None
|
|
1146
|
+
) -> list[str] | None:
|
|
1147
|
+
all_visible_files = visible_changed_files(working_directory, head_branch)
|
|
1148
|
+
if all_visible_files is None:
|
|
1149
|
+
return remote_visible_changed_files(repository, base_branch, head_branch)
|
|
1150
|
+
return all_visible_files
|
|
@@ -16,6 +16,8 @@ if str(HOOKS_DIRECTORY) not in sys.path:
|
|
|
16
16
|
sys.path.insert(0, str(HOOKS_DIRECTORY))
|
|
17
17
|
|
|
18
18
|
from blocking import followup_pr_dedupe as dedupe
|
|
19
|
+
from blocking.gate_run_reads import gate_run
|
|
20
|
+
from hooks_constants.followup_pr_dedupe_constants import DUPLICATE_FOLLOWUP_REASON_TEMPLATE
|
|
19
21
|
|
|
20
22
|
OPEN_FOLLOWUP = {
|
|
21
23
|
"number": 1769,
|
|
@@ -181,3 +183,82 @@ def test_create_tool_fields_should_read_a_pull_request_dispatch_as_a_create() ->
|
|
|
181
183
|
def test_create_tool_fields_should_skip_a_call_that_opens_no_pull_request() -> None:
|
|
182
184
|
assert dedupe.create_tool_fields(_dispatch_payload({"work_order": "wo-1"})) is None
|
|
183
185
|
assert dedupe.create_tool_fields({"tool_name": "Bash", "tool_input": {"command": "gh pr list"}}) is None
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _open_followup(number: int, parent_number: int) -> dict[str, object]:
|
|
189
|
+
return {
|
|
190
|
+
"number": number,
|
|
191
|
+
"html_url": f"https://github.com/o/r/pull/{number}",
|
|
192
|
+
"body": f"Follow-up to #{parent_number}",
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def _duplicate_reason(open_followup: Mapping[str, object], parent_number: int) -> str:
|
|
197
|
+
return DUPLICATE_FOLLOWUP_REASON_TEMPLATE.format(
|
|
198
|
+
open_number=open_followup["number"], parent_number=parent_number, open_url=open_followup["html_url"]
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _keyed_reader(
|
|
203
|
+
all_open_by_repository: Mapping[tuple[str, str], list[Mapping[str, object]] | Exception],
|
|
204
|
+
all_asked_repositories: list[tuple[str, str]],
|
|
205
|
+
) -> dedupe.OpenPullRequestReader:
|
|
206
|
+
def read(owner: str, repo: str) -> list[Mapping[str, object]]:
|
|
207
|
+
all_asked_repositories.append((owner, repo))
|
|
208
|
+
answer = all_open_by_repository[(owner, repo)]
|
|
209
|
+
if isinstance(answer, Exception):
|
|
210
|
+
raise answer
|
|
211
|
+
return answer
|
|
212
|
+
|
|
213
|
+
return read
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _chained_inline_creates(all_repositories_and_bodies: list[tuple[str, str]]) -> dict[str, object]:
|
|
217
|
+
all_creates = [
|
|
218
|
+
f'gh pr create --repo {each_repository} --title "fix: {each_index}" --body "{each_body}"'
|
|
219
|
+
for each_index, (each_repository, each_body) in enumerate(all_repositories_and_bodies)
|
|
220
|
+
]
|
|
221
|
+
return {"tool_name": "Bash", "tool_input": {"command": " && ".join(all_creates)}}
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def test_chained_creates_should_deny_when_only_the_second_body_repeats_an_open_followup() -> None:
|
|
225
|
+
open_followup = _open_followup(9, 7)
|
|
226
|
+
all_asked_repositories: list[tuple[str, str]] = []
|
|
227
|
+
payload = _chained_inline_creates([("o/r", "Adds a hook."), ("o/r", "Follow-up to #7")])
|
|
228
|
+
reason = dedupe.duplicate_followup_reason(
|
|
229
|
+
payload, _keyed_reader({("o", "r"): [open_followup]}, all_asked_repositories)
|
|
230
|
+
)
|
|
231
|
+
assert reason == _duplicate_reason(open_followup, 7)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def test_followup_drafts_should_count_a_quoted_create_once() -> None:
|
|
235
|
+
payload = _chained_inline_creates([("o/r", "Follow-up to #7"), ("o/r", "Follow-up to #8")])
|
|
236
|
+
assert dedupe.followup_drafts(payload) == [
|
|
237
|
+
dedupe.PullRequestDraft("o", "r", "Follow-up to #7"),
|
|
238
|
+
dedupe.PullRequestDraft("o", "r", "Follow-up to #8"),
|
|
239
|
+
]
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def test_chained_followups_should_read_one_open_list_per_repository() -> None:
|
|
243
|
+
open_followup = _open_followup(11, 8)
|
|
244
|
+
all_asked_repositories: list[tuple[str, str]] = []
|
|
245
|
+
payload = _chained_inline_creates([("o/r", "Follow-up to #7"), ("o/r", "Follow-up to #8")])
|
|
246
|
+
with gate_run():
|
|
247
|
+
reason = dedupe.duplicate_followup_reason(
|
|
248
|
+
payload, _keyed_reader({("o", "r"): [open_followup]}, all_asked_repositories)
|
|
249
|
+
)
|
|
250
|
+
assert reason == _duplicate_reason(open_followup, 8)
|
|
251
|
+
assert all_asked_repositories == [("o", "r")]
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def test_followup_read_failure_should_skip_only_that_create() -> None:
|
|
255
|
+
open_followup = _open_followup(9, 7)
|
|
256
|
+
all_asked_repositories: list[tuple[str, str]] = []
|
|
257
|
+
all_open_by_repository: dict[tuple[str, str], list[Mapping[str, object]] | Exception] = {
|
|
258
|
+
("a", "r"): OSError("network down"),
|
|
259
|
+
("b", "r"): [open_followup],
|
|
260
|
+
}
|
|
261
|
+
payload = _chained_inline_creates([("a/r", "Follow-up to #5"), ("b/r", "Follow-up to #7")])
|
|
262
|
+
reason = dedupe.duplicate_followup_reason(payload, _keyed_reader(all_open_by_repository, all_asked_repositories))
|
|
263
|
+
assert reason == _duplicate_reason(open_followup, 7)
|
|
264
|
+
assert all_asked_repositories == [("a", "r"), ("b", "r")]
|
|
@@ -436,6 +436,44 @@ def test_deny_should_add_the_reads_ran_out_sentence_when_the_deadline_cut_a_read
|
|
|
436
436
|
assert decision["hookSpecificOutput"]["permissionDecisionReason"] == UNREADABLE_CHANGES_REASON + READS_RAN_OUT_SENTENCE
|
|
437
437
|
|
|
438
438
|
|
|
439
|
+
class SettableClock:
|
|
440
|
+
"""Reads the seconds it was last set to, starting at zero."""
|
|
441
|
+
|
|
442
|
+
def __init__(self) -> None:
|
|
443
|
+
self.seconds = 0.0
|
|
444
|
+
|
|
445
|
+
def __call__(self) -> float:
|
|
446
|
+
return self.seconds
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
def test_deny_should_add_the_reads_ran_out_sentence_when_the_deadline_cuts_the_second_head(
|
|
450
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
451
|
+
) -> None:
|
|
452
|
+
all_asked_commands = _unstarted_children(monkeypatch)
|
|
453
|
+
clock = SettableClock()
|
|
454
|
+
original_gh_api_lines = gate.proof._gh_api_lines
|
|
455
|
+
|
|
456
|
+
def compare_that_spends_the_slice(endpoint: str, query: str) -> list[str] | None:
|
|
457
|
+
if endpoint.endswith("...x"):
|
|
458
|
+
clock.seconds = PROOF_AND_LOOK_READS_SECONDS + 1.0
|
|
459
|
+
return [json.dumps(["M", "", "tool.py"])]
|
|
460
|
+
return original_gh_api_lines(endpoint, query)
|
|
461
|
+
|
|
462
|
+
monkeypatch.setattr(gate.proof, "_gh_api_lines", compare_that_spends_the_slice)
|
|
463
|
+
body = PROVEN_FOLLOWUP_BODY.replace("Follow-up to #1731", "Adds a guard.")
|
|
464
|
+
(tmp_path / "body.md").write_text(body, encoding="utf-8")
|
|
465
|
+
all_creates = [
|
|
466
|
+
CREATE_WORDS + f' --title "fix: {each_head}" --body-file body.md --repo o/r --base main --head {each_head}'
|
|
467
|
+
for each_head in ("x", "y")
|
|
468
|
+
]
|
|
469
|
+
payload = {"tool_name": "Bash", "tool_input": {"command": " && ".join(all_creates)}, "cwd": str(tmp_path)}
|
|
470
|
+
with read_deadlines_started(clock):
|
|
471
|
+
decision = gate.decision_for(payload)
|
|
472
|
+
assert decision is not None
|
|
473
|
+
assert decision["hookSpecificOutput"]["permissionDecisionReason"] == UNREADABLE_CHANGES_REASON + READS_RAN_OUT_SENTENCE
|
|
474
|
+
assert not any(each_command[:1] == ["gh"] for each_command in all_asked_commands)
|
|
475
|
+
|
|
476
|
+
|
|
439
477
|
def test_deny_should_keep_its_reason_when_every_read_had_time(tmp_path: Path) -> None:
|
|
440
478
|
decision = gate.decision_for(_mcp_create_without_repository(tmp_path))
|
|
441
479
|
assert decision is not None
|
|
@@ -12,6 +12,7 @@ if str(HOOKS_DIRECTORY) not in sys.path:
|
|
|
12
12
|
sys.path.insert(0, str(HOOKS_DIRECTORY))
|
|
13
13
|
|
|
14
14
|
from blocking import pull_request_proof as gate
|
|
15
|
+
from blocking.gate_run_reads import gate_run
|
|
15
16
|
from blocking.pr_lifecycle_skill_gate import decision_for
|
|
16
17
|
from hooks_constants.pull_request_proof_constants import (
|
|
17
18
|
COMPARE_FILE_LIST_LIMIT,
|
|
@@ -21,6 +22,7 @@ from hooks_constants.pull_request_proof_constants import (
|
|
|
21
22
|
MISSING_EVAL_SECTION_REASON,
|
|
22
23
|
MISSING_EXISTING_WORK_REASON,
|
|
23
24
|
MISSING_FLOWCHART_REASON,
|
|
25
|
+
MISSING_LOOK_REASON,
|
|
24
26
|
MISSING_PROOF_REASON,
|
|
25
27
|
TEST_ONLY_PROOF_REASON,
|
|
26
28
|
UNPROVEN_PROOF_REASON,
|
|
@@ -1662,3 +1664,68 @@ def test_create_calls_and_other_tools_should_pass_the_edit_check(tmp_path: Path)
|
|
|
1662
1664
|
unrun_body = "## Proof in practice\nRan `python run.py`.\nNot run: x.\n"
|
|
1663
1665
|
assert gate.edit_proof_reason(_mcp_create(unrun_body)) is None
|
|
1664
1666
|
assert gate.edit_proof_reason(_shell("git push -u origin b", tmp_path)) is None
|
|
1667
|
+
|
|
1668
|
+
|
|
1669
|
+
def _chained_creates(tmp_path: Path, all_flags_and_bodies: list[tuple[str, str]]) -> str:
|
|
1670
|
+
all_creates = []
|
|
1671
|
+
for each_index, (each_flags, each_body) in enumerate(all_flags_and_bodies):
|
|
1672
|
+
body_path = tmp_path / f"body_{each_index}.md"
|
|
1673
|
+
body_path.write_text(each_body, encoding="utf-8")
|
|
1674
|
+
all_creates.append(f'gh pr create --title "fix: {each_index}" --body-file "{body_path}" {each_flags}')
|
|
1675
|
+
return " && ".join(all_creates)
|
|
1676
|
+
|
|
1677
|
+
|
|
1678
|
+
def _clone_with_quiet_branch(tmp_path: Path) -> Path:
|
|
1679
|
+
clone_path = _repository_with_change(tmp_path / "repository", "page.html")
|
|
1680
|
+
subprocess.run(["git", "-C", str(clone_path), "branch", "quiet", "main"], check=True)
|
|
1681
|
+
return clone_path
|
|
1682
|
+
|
|
1683
|
+
|
|
1684
|
+
def test_chained_creates_should_deny_when_only_the_second_branch_changes_a_page(tmp_path: Path) -> None:
|
|
1685
|
+
clone_path = _clone_with_quiet_branch(tmp_path)
|
|
1686
|
+
subprocess.run(["git", "-C", str(clone_path), "checkout", "-q", "main"], check=True)
|
|
1687
|
+
command = _chained_creates(tmp_path, [("--head quiet", PROVEN_BODY), ("--head feature", PROVEN_BODY)])
|
|
1688
|
+
reason = gate.missing_look_reason(_shell(command, clone_path))
|
|
1689
|
+
assert reason == MISSING_LOOK_REASON.format(changed_files="page.html")
|
|
1690
|
+
|
|
1691
|
+
|
|
1692
|
+
def test_chained_create_without_a_head_should_read_its_own_checkout(tmp_path: Path) -> None:
|
|
1693
|
+
clone_path = _clone_with_quiet_branch(tmp_path)
|
|
1694
|
+
picture_body = PROVEN_BODY + "\n"
|
|
1695
|
+
command = _chained_creates(tmp_path, [("", PROVEN_BODY), ("--head quiet", picture_body)])
|
|
1696
|
+
reason = gate.missing_look_reason(_shell(command, clone_path))
|
|
1697
|
+
assert reason == MISSING_LOOK_REASON.format(changed_files="page.html")
|
|
1698
|
+
|
|
1699
|
+
|
|
1700
|
+
def test_chained_creates_should_check_each_waiver_against_its_own_head(
|
|
1701
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
1702
|
+
) -> None:
|
|
1703
|
+
all_endpoints: list[str] = []
|
|
1704
|
+
all_responses = {
|
|
1705
|
+
"repos/o/r/compare/main...x": _workflow_compare_lines(1, ["tool.py"]),
|
|
1706
|
+
"repos/o/r/compare/main...y": _workflow_compare_lines(1, [f"{WORKFLOW_DIRECTORY}/new.yml"]),
|
|
1707
|
+
}
|
|
1708
|
+
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api(all_responses, all_endpoints))
|
|
1709
|
+
shared_flags = "--repo o/r --base main"
|
|
1710
|
+
command = _chained_creates(
|
|
1711
|
+
tmp_path, [(f"--head x {shared_flags}", PROVEN_BODY), (f"--head y {shared_flags}", WAIVER_BODY)]
|
|
1712
|
+
)
|
|
1713
|
+
assert gate.missing_proof_reason(_shell(command, tmp_path)) is None
|
|
1714
|
+
assert all_endpoints == ["repos/o/r/compare/main...y"]
|
|
1715
|
+
|
|
1716
|
+
|
|
1717
|
+
def test_chained_creates_should_read_the_compare_api_once_per_distinct_head(
|
|
1718
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
1719
|
+
) -> None:
|
|
1720
|
+
all_endpoints: list[str] = []
|
|
1721
|
+
python_only = [_compare_line("M", "", "tool.py")]
|
|
1722
|
+
all_responses = {"repos/o/r/compare/main...x": python_only, "repos/o/r/compare/main...y": python_only}
|
|
1723
|
+
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api(all_responses, all_endpoints))
|
|
1724
|
+
shared_flags = "--repo o/r --base main"
|
|
1725
|
+
command = _chained_creates(
|
|
1726
|
+
tmp_path,
|
|
1727
|
+
[(f"--head {each_head} {shared_flags}", PROVEN_BODY) for each_head in ("x", "y", "x")],
|
|
1728
|
+
)
|
|
1729
|
+
with gate_run():
|
|
1730
|
+
assert gate.missing_look_reason(_shell(command, tmp_path)) is None
|
|
1731
|
+
assert all_endpoints == ["repos/o/r/compare/main...x", "repos/o/r/compare/main...y"]
|
|
@@ -12,11 +12,17 @@ _validators_directory = str(Path(__file__).resolve().parent)
|
|
|
12
12
|
_hooks_directory = str(Path(__file__).resolve().parent.parent)
|
|
13
13
|
|
|
14
14
|
try:
|
|
15
|
-
from pyproject_config_discovery import
|
|
15
|
+
from pyproject_config_discovery import (
|
|
16
|
+
ancestor_directories,
|
|
17
|
+
find_pyproject_configuring_tool,
|
|
18
|
+
)
|
|
16
19
|
except ModuleNotFoundError:
|
|
17
20
|
if _validators_directory not in sys.path:
|
|
18
21
|
sys.path.insert(0, _validators_directory)
|
|
19
|
-
from pyproject_config_discovery import
|
|
22
|
+
from pyproject_config_discovery import (
|
|
23
|
+
ancestor_directories,
|
|
24
|
+
find_pyproject_configuring_tool,
|
|
25
|
+
)
|
|
20
26
|
|
|
21
27
|
try:
|
|
22
28
|
from hooks_constants.blocking_check_limits import RUFF_STDIN_ENCODING
|
|
@@ -239,10 +245,45 @@ def _run_staged_ruff_check(
|
|
|
239
245
|
return _staged_ruff_result(resolved_pyproject, stdin_filename, staged_content)
|
|
240
246
|
|
|
241
247
|
|
|
248
|
+
def _native_ruff_working_directory(config_source_path: Path | None) -> str | None:
|
|
249
|
+
"""Return the folder a native ruff run starts in, or None for the caller's folder.
|
|
250
|
+
|
|
251
|
+
::
|
|
252
|
+
|
|
253
|
+
config_source_path .../repo/pkg/module.py, pkg exists -> ".../repo/pkg"
|
|
254
|
+
config_source_path .../repo/new_pkg/module.py, new_pkg missing -> ".../repo"
|
|
255
|
+
config_source_path None -> None (the caller's working folder)
|
|
256
|
+
|
|
257
|
+
Ruff grades a file with no config above it under the config found from its
|
|
258
|
+
working folder. A staged copy has no config above it, so starting ruff
|
|
259
|
+
beside the original target makes that fallback the target's own config.
|
|
260
|
+
|
|
261
|
+
Args:
|
|
262
|
+
config_source_path: The original target path the staged copy stands in
|
|
263
|
+
for, or ``None`` for a run over files checked in place.
|
|
264
|
+
|
|
265
|
+
Returns:
|
|
266
|
+
The nearest existing folder at or above the target, or ``None``.
|
|
267
|
+
"""
|
|
268
|
+
if config_source_path is None:
|
|
269
|
+
return None
|
|
270
|
+
return next(
|
|
271
|
+
(
|
|
272
|
+
str(each_candidate_directory)
|
|
273
|
+
for each_candidate_directory in ancestor_directories(config_source_path)
|
|
274
|
+
if each_candidate_directory.is_dir()
|
|
275
|
+
),
|
|
276
|
+
None,
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
|
|
242
280
|
def _run_native_ruff_check(
|
|
243
281
|
all_python_files: list[str], config_source_path: Path | None
|
|
244
282
|
) -> RuffResult:
|
|
245
|
-
"""Run ruff over *all_python_files* directly, resolving
|
|
283
|
+
"""Run ruff over *all_python_files* directly, resolving config from the path.
|
|
284
|
+
|
|
285
|
+
Ruff starts in the folder ``_native_ruff_working_directory`` picks.
|
|
286
|
+
"""
|
|
246
287
|
config_argument = _ruff_config_argument(config_source_path)
|
|
247
288
|
concise_output_arguments = ["--output-format", "concise"]
|
|
248
289
|
result = subprocess.run(
|
|
@@ -250,6 +291,7 @@ def _run_native_ruff_check(
|
|
|
250
291
|
check=False,
|
|
251
292
|
capture_output=True,
|
|
252
293
|
text=True,
|
|
294
|
+
cwd=_native_ruff_working_directory(config_source_path),
|
|
253
295
|
env=_ruff_subprocess_environment(),
|
|
254
296
|
creationflags=hidden_window_creation_flags(),
|
|
255
297
|
)
|
|
@@ -267,7 +309,7 @@ def run_ruff_check(
|
|
|
267
309
|
|
|
268
310
|
A given ``config_source_path`` grades the single staged copy under the project
|
|
269
311
|
config resolved from the original target, applying its path-scoped
|
|
270
|
-
per-file-ignores.
|
|
312
|
+
per-file-ignores. Otherwise the files are checked natively."""
|
|
271
313
|
if not all_files:
|
|
272
314
|
return RuffResult(passed=True, output="No files to check", fixed_count=0)
|
|
273
315
|
|
|
@@ -5,6 +5,8 @@ import sys
|
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
from unittest.mock import patch
|
|
7
7
|
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
8
10
|
from .ruff_integration import (
|
|
9
11
|
RuffResult,
|
|
10
12
|
_config_relative_stdin_filename,
|
|
@@ -72,23 +74,23 @@ def test_run_ruff_check_returns_passed_for_empty_files() -> None:
|
|
|
72
74
|
|
|
73
75
|
|
|
74
76
|
def test_run_ruff_check_applies_config_resolved_from_config_source_path(
|
|
75
|
-
tmp_path: Path,
|
|
77
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
76
78
|
) -> None:
|
|
77
79
|
"""A given config_source_path resolves the ruff config for a staged copy.
|
|
78
80
|
|
|
79
81
|
A ``[tool.ruff.lint]`` selecting B flags an ``assert False`` (B011) only when
|
|
80
82
|
``config_source_path`` — the original ``.py`` target — resolves it; native
|
|
81
|
-
discovery from the detached staged copy
|
|
83
|
+
discovery from the detached staged copy, started in a folder with no ruff
|
|
84
|
+
config, finds none and passes.
|
|
82
85
|
"""
|
|
86
|
+
monkeypatch.chdir(tmp_path)
|
|
83
87
|
ruff_repo = tmp_path / "ruff_repo"
|
|
84
88
|
ruff_repo.mkdir()
|
|
85
89
|
(ruff_repo / "pyproject.toml").write_text(
|
|
86
90
|
"[tool.ruff.lint]\nselect = ['B']\n", encoding="utf-8"
|
|
87
91
|
)
|
|
88
92
|
original_target = ruff_repo / "asserts.py"
|
|
89
|
-
staged_copy = tmp_path
|
|
90
|
-
staged_copy.parent.mkdir(parents=True)
|
|
91
|
-
staged_copy.write_text("def probe() -> None:\n assert False\n", encoding="utf-8")
|
|
93
|
+
staged_copy = _write_detached_assert_false_copy(tmp_path)
|
|
92
94
|
|
|
93
95
|
without_source = run_ruff_check([staged_copy])
|
|
94
96
|
with_source = run_ruff_check([staged_copy], config_source_path=original_target)
|
|
@@ -97,6 +99,66 @@ def test_run_ruff_check_applies_config_resolved_from_config_source_path(
|
|
|
97
99
|
assert "B011" in with_source.output
|
|
98
100
|
|
|
99
101
|
|
|
102
|
+
def _write_detached_assert_false_copy(tmp_path: Path) -> Path:
|
|
103
|
+
"""Write a staged copy holding ``assert False`` under a folder with no ruff config."""
|
|
104
|
+
staged_copy = tmp_path / "detached" / "asserts.py"
|
|
105
|
+
staged_copy.parent.mkdir(parents=True)
|
|
106
|
+
staged_copy.write_text("def probe() -> None:\n assert False\n", encoding="utf-8")
|
|
107
|
+
return staged_copy
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_run_ruff_check_should_not_grade_a_staged_copy_under_the_working_folder_config(
|
|
111
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
112
|
+
) -> None:
|
|
113
|
+
"""The working folder's ruff config never grades a staged copy of an unconfigured target.
|
|
114
|
+
|
|
115
|
+
The original target sits in a folder with no ruff config, so the staged run
|
|
116
|
+
does not apply and ruff checks the copy natively. The working folder selects
|
|
117
|
+
B; the copy is still graded under ruff's defaults, which omit B011.
|
|
118
|
+
"""
|
|
119
|
+
session_folder = tmp_path / "session_folder"
|
|
120
|
+
session_folder.mkdir()
|
|
121
|
+
(session_folder / "pyproject.toml").write_text(
|
|
122
|
+
"[tool.ruff.lint]\nselect = ['B']\n", encoding="utf-8"
|
|
123
|
+
)
|
|
124
|
+
unconfigured_repo = tmp_path / "unconfigured_repo"
|
|
125
|
+
unconfigured_repo.mkdir()
|
|
126
|
+
staged_copy = _write_detached_assert_false_copy(tmp_path)
|
|
127
|
+
monkeypatch.chdir(session_folder)
|
|
128
|
+
|
|
129
|
+
result = run_ruff_check(
|
|
130
|
+
[staged_copy], config_source_path=unconfigured_repo / "asserts.py"
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
assert "All checks passed" in result.output
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def test_run_ruff_check_should_grade_a_staged_copy_under_a_ruff_toml_beside_the_target(
|
|
137
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
138
|
+
) -> None:
|
|
139
|
+
"""A ``ruff.toml`` above the original target grades its staged copy.
|
|
140
|
+
|
|
141
|
+
The pyproject walk finds no ``[tool.ruff]`` table, so ruff checks the copy
|
|
142
|
+
natively. Started from a folder with no ruff config, it still reads the
|
|
143
|
+
target's ``ruff.toml``, which selects B and reports B011. The target's
|
|
144
|
+
``new_package`` folder does not exist yet, as for a Write that creates it.
|
|
145
|
+
"""
|
|
146
|
+
session_folder = tmp_path / "session_folder"
|
|
147
|
+
session_folder.mkdir()
|
|
148
|
+
ruff_toml_repo = tmp_path / "ruff_toml_repo"
|
|
149
|
+
ruff_toml_repo.mkdir()
|
|
150
|
+
(ruff_toml_repo / "ruff.toml").write_text("[lint]\nselect = ['B']\n", encoding="utf-8")
|
|
151
|
+
staged_copy = _write_detached_assert_false_copy(tmp_path)
|
|
152
|
+
monkeypatch.chdir(session_folder)
|
|
153
|
+
|
|
154
|
+
result = run_ruff_check(
|
|
155
|
+
[staged_copy],
|
|
156
|
+
config_source_path=ruff_toml_repo / "new_package" / "asserts.py",
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
assert "B011" in result.output
|
|
160
|
+
|
|
161
|
+
|
|
100
162
|
def test_run_ruff_check_grades_a_staged_copy_holding_non_ascii_text(
|
|
101
163
|
tmp_path: Path,
|
|
102
164
|
) -> None:
|