claude-dev-env 8.111.0 → 8.111.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/hooks/blocking/test_chat_reply_gate.py +22 -18
- package/hooks/blocking/test_reply_length_gate.py +45 -35
- package/hooks/hooks_constants/reply_length_gate_constants.py +3 -3
- package/hooks/hooks_constants/test_reply_length_gate_constants.py +2 -2
- package/package.json +1 -1
- package/scripts/dev_env_scripts_constants/review_closure_constants.py +4 -2
- package/scripts/test_durable_post_lint.py +10 -8
- package/scripts/tests/test_review_closure_model.py +3 -0
|
@@ -5,8 +5,14 @@ from pathlib import Path
|
|
|
5
5
|
import pytest
|
|
6
6
|
|
|
7
7
|
import chat_reply_gate
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
from hooks_constants.reply_length_gate_constants import MAXIMUM_SENTENCE_COUNT
|
|
9
|
+
|
|
10
|
+
OVER_LIMIT_SENTENCES = [
|
|
11
|
+
f"Status line {each_number} is ready." for each_number in range(MAXIMUM_SENTENCE_COUNT + 1)
|
|
12
|
+
]
|
|
13
|
+
OVER_LIMIT_REPLY = " ".join(OVER_LIMIT_SENTENCES)
|
|
14
|
+
FIRST_HELD_BATCH = " ".join(OVER_LIMIT_SENTENCES[: len(OVER_LIMIT_SENTENCES) // 2])
|
|
15
|
+
LAST_HELD_BATCH = " ".join(OVER_LIMIT_SENTENCES[len(OVER_LIMIT_SENTENCES) // 2 :])
|
|
10
16
|
THREE_SENTENCE_REPLY = "PR one merged. PR two is queued. Nothing else is open."
|
|
11
17
|
PASSING_DRAFT = "PR one merged. Two others wait."
|
|
12
18
|
|
|
@@ -46,7 +52,7 @@ def test_should_show_a_passing_draft_in_place_of_a_long_reply(
|
|
|
46
52
|
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
47
53
|
) -> None:
|
|
48
54
|
monkeypatch.setattr(chat_reply_gate, "ask_drafter", lambda *_args: PASSING_DRAFT)
|
|
49
|
-
exit_code, hook_output = run_hook(monkeypatch, capsys, display_input(
|
|
55
|
+
exit_code, hook_output = run_hook(monkeypatch, capsys, display_input(OVER_LIMIT_REPLY))
|
|
50
56
|
assert exit_code == 0
|
|
51
57
|
assert hook_output == {"hookEventName": "MessageDisplay", "displayContent": PASSING_DRAFT}
|
|
52
58
|
|
|
@@ -70,16 +76,14 @@ def test_should_hold_batches_until_the_last_one_arrives(
|
|
|
70
76
|
lambda reply_text, _violation: all_requests.append(reply_text) or PASSING_DRAFT,
|
|
71
77
|
)
|
|
72
78
|
_, first_output = run_hook(
|
|
73
|
-
monkeypatch, capsys, display_input(
|
|
79
|
+
monkeypatch, capsys, display_input(FIRST_HELD_BATCH + "\n", False)
|
|
74
80
|
)
|
|
75
81
|
_, last_output = run_hook(
|
|
76
|
-
monkeypatch, capsys, display_input(
|
|
82
|
+
monkeypatch, capsys, display_input(LAST_HELD_BATCH)
|
|
77
83
|
)
|
|
78
84
|
assert first_output == {"hookEventName": "MessageDisplay", "displayContent": ""}
|
|
79
85
|
assert last_output == {"hookEventName": "MessageDisplay", "displayContent": PASSING_DRAFT}
|
|
80
|
-
assert all_requests == [
|
|
81
|
-
"PR one merged. PR two is queued.\nPR three needs a fix. Nothing else is open."
|
|
82
|
-
]
|
|
86
|
+
assert all_requests == [FIRST_HELD_BATCH + "\n" + LAST_HELD_BATCH]
|
|
83
87
|
|
|
84
88
|
|
|
85
89
|
def test_should_show_the_whole_held_message_when_it_passes(
|
|
@@ -100,9 +104,9 @@ def test_should_show_the_original_when_no_draft_passes(
|
|
|
100
104
|
monkeypatch.setattr(
|
|
101
105
|
chat_reply_gate,
|
|
102
106
|
"ask_drafter",
|
|
103
|
-
lambda reply_text, _violation: all_calls.append(reply_text) or
|
|
107
|
+
lambda reply_text, _violation: all_calls.append(reply_text) or OVER_LIMIT_REPLY,
|
|
104
108
|
)
|
|
105
|
-
_, hook_output = run_hook(monkeypatch, capsys, display_input(
|
|
109
|
+
_, hook_output = run_hook(monkeypatch, capsys, display_input(OVER_LIMIT_REPLY))
|
|
106
110
|
assert hook_output is None
|
|
107
111
|
assert len(all_calls) == 2
|
|
108
112
|
|
|
@@ -111,7 +115,7 @@ def test_should_tell_the_agent_which_draft_the_user_saw(
|
|
|
111
115
|
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
112
116
|
) -> None:
|
|
113
117
|
monkeypatch.setattr(chat_reply_gate, "ask_drafter", lambda *_args: PASSING_DRAFT)
|
|
114
|
-
run_hook(monkeypatch, capsys, display_input(
|
|
118
|
+
run_hook(monkeypatch, capsys, display_input(OVER_LIMIT_REPLY))
|
|
115
119
|
prompt_input = {"hook_event_name": "UserPromptSubmit", "session_id": "abc"}
|
|
116
120
|
_, first_output = run_hook(monkeypatch, capsys, prompt_input)
|
|
117
121
|
_, second_output = run_hook(monkeypatch, capsys, prompt_input)
|
|
@@ -124,7 +128,7 @@ def test_should_delete_the_shown_draft_at_session_end(
|
|
|
124
128
|
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
125
129
|
) -> None:
|
|
126
130
|
monkeypatch.setattr(chat_reply_gate, "ask_drafter", lambda *_args: PASSING_DRAFT)
|
|
127
|
-
run_hook(monkeypatch, capsys, display_input(
|
|
131
|
+
run_hook(monkeypatch, capsys, display_input(OVER_LIMIT_REPLY))
|
|
128
132
|
shown_draft_path = chat_reply_gate.state_file_path("claude-chat-reply-shown-", "abc")
|
|
129
133
|
assert shown_draft_path.exists()
|
|
130
134
|
exit_code, hook_output = run_hook(
|
|
@@ -144,14 +148,14 @@ def test_should_add_the_reply_limit_on_each_user_prompt(
|
|
|
144
148
|
assert exit_code == 0
|
|
145
149
|
assert hook_output is not None
|
|
146
150
|
assert hook_output["hookEventName"] == "UserPromptSubmit"
|
|
147
|
-
assert "
|
|
151
|
+
assert f"{MAXIMUM_SENTENCE_COUNT} sentences or fewer" in str(hook_output["additionalContext"])
|
|
148
152
|
|
|
149
153
|
|
|
150
154
|
def test_should_do_nothing_inside_the_drafter_process(
|
|
151
155
|
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
152
156
|
) -> None:
|
|
153
157
|
monkeypatch.setenv("CHAT_REPLY_DRAFTER_ACTIVE", "1")
|
|
154
|
-
exit_code, hook_output = run_hook(monkeypatch, capsys, display_input(
|
|
158
|
+
exit_code, hook_output = run_hook(monkeypatch, capsys, display_input(OVER_LIMIT_REPLY))
|
|
155
159
|
assert exit_code == 0
|
|
156
160
|
assert hook_output is None
|
|
157
161
|
|
|
@@ -162,7 +166,7 @@ def test_should_ignore_the_stop_event(
|
|
|
162
166
|
exit_code, hook_output = run_hook(
|
|
163
167
|
monkeypatch,
|
|
164
168
|
capsys,
|
|
165
|
-
{"hook_event_name": "Stop", "last_assistant_message":
|
|
169
|
+
{"hook_event_name": "Stop", "last_assistant_message": OVER_LIMIT_REPLY},
|
|
166
170
|
)
|
|
167
171
|
assert exit_code == 0
|
|
168
172
|
assert hook_output is None
|
|
@@ -179,7 +183,7 @@ def test_ask_drafter_should_read_the_result_field(monkeypatch: pytest.MonkeyPatc
|
|
|
179
183
|
"run",
|
|
180
184
|
lambda command, **_kwargs: all_commands.append(command) or CompletedDrafter(),
|
|
181
185
|
)
|
|
182
|
-
assert chat_reply_gate.ask_drafter(
|
|
186
|
+
assert chat_reply_gate.ask_drafter(OVER_LIMIT_REPLY, "too long") == PASSING_DRAFT
|
|
183
187
|
assert all_commands[0][:4] == ["C:/npm/claude.cmd", "-p", "--model", "haiku"]
|
|
184
188
|
|
|
185
189
|
|
|
@@ -188,14 +192,14 @@ def test_ask_drafter_should_return_none_for_an_error_result(monkeypatch: pytest.
|
|
|
188
192
|
stdout = json.dumps({"is_error": True, "result": "Credit balance is too low"})
|
|
189
193
|
|
|
190
194
|
monkeypatch.setattr(chat_reply_gate.subprocess, "run", lambda *_args, **_kwargs: FailedDrafter())
|
|
191
|
-
assert chat_reply_gate.ask_drafter(
|
|
195
|
+
assert chat_reply_gate.ask_drafter(OVER_LIMIT_REPLY, "too long") is None
|
|
192
196
|
|
|
193
197
|
|
|
194
198
|
def test_should_forget_the_shown_draft_when_a_later_reply_passes(
|
|
195
199
|
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
196
200
|
) -> None:
|
|
197
201
|
monkeypatch.setattr(chat_reply_gate, "ask_drafter", lambda *_args: PASSING_DRAFT)
|
|
198
|
-
run_hook(monkeypatch, capsys, display_input(
|
|
202
|
+
run_hook(monkeypatch, capsys, display_input(OVER_LIMIT_REPLY))
|
|
199
203
|
run_hook(monkeypatch, capsys, {**display_input(THREE_SENTENCE_REPLY), "message_id": "m2"})
|
|
200
204
|
_, hook_output = run_hook(monkeypatch, capsys, {"hook_event_name": "UserPromptSubmit", "session_id": "abc"})
|
|
201
205
|
assert hook_output is not None
|
|
@@ -5,15 +5,25 @@ from pathlib import Path
|
|
|
5
5
|
import pytest
|
|
6
6
|
|
|
7
7
|
import reply_length_gate
|
|
8
|
+
from hooks_constants.reply_length_gate_constants import (
|
|
9
|
+
MAXIMUM_SENTENCE_COUNT,
|
|
10
|
+
MAXIMUM_WORDS_PER_SENTENCE,
|
|
11
|
+
)
|
|
8
12
|
|
|
9
13
|
REPLY_TOOL_NAME = "mcp__hearthbot__reply"
|
|
10
14
|
POST_TOOL_NAME = "mcp__hearthbot__post_message"
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
15
|
+
OVER_SENTENCE_LIMIT_TEXT = " ".join(
|
|
16
|
+
f"Status line {each_number} is ready." for each_number in range(MAXIMUM_SENTENCE_COUNT + 1)
|
|
17
|
+
)
|
|
18
|
+
OVER_WORD_LIMIT_SENTENCE = (
|
|
19
|
+
"One two three "
|
|
20
|
+
+ " ".join(f"word{each_number}" for each_number in range(3, MAXIMUM_WORDS_PER_SENTENCE + 1))
|
|
21
|
+
+ "."
|
|
14
22
|
)
|
|
15
|
-
|
|
16
|
-
"One two three
|
|
23
|
+
AT_WORD_LIMIT_SENTENCE = (
|
|
24
|
+
"One two three "
|
|
25
|
+
+ " ".join(f"word{each_number}" for each_number in range(3, MAXIMUM_WORDS_PER_SENTENCE))
|
|
26
|
+
+ "."
|
|
17
27
|
)
|
|
18
28
|
|
|
19
29
|
|
|
@@ -59,43 +69,43 @@ def test_should_allow_three_short_sentences(
|
|
|
59
69
|
assert (exit_code, stderr_text) == (0, "")
|
|
60
70
|
|
|
61
71
|
|
|
62
|
-
def
|
|
72
|
+
def test_should_allow_a_sentence_at_the_word_limit(
|
|
63
73
|
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
64
74
|
) -> None:
|
|
65
|
-
exit_code, _ = run_gate(monkeypatch, capsys, REPLY_TOOL_NAME, {"text":
|
|
75
|
+
exit_code, _ = run_gate(monkeypatch, capsys, REPLY_TOOL_NAME, {"text": AT_WORD_LIMIT_SENTENCE})
|
|
66
76
|
assert exit_code == 0
|
|
67
77
|
|
|
68
78
|
|
|
69
|
-
def
|
|
79
|
+
def test_should_deny_too_many_sentences_and_name_the_count(
|
|
70
80
|
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
71
81
|
) -> None:
|
|
72
82
|
exit_code, stderr_text = run_gate(
|
|
73
83
|
monkeypatch,
|
|
74
84
|
capsys,
|
|
75
85
|
REPLY_TOOL_NAME,
|
|
76
|
-
{"text":
|
|
86
|
+
{"text": OVER_SENTENCE_LIMIT_TEXT},
|
|
77
87
|
)
|
|
78
88
|
assert exit_code == 2
|
|
79
|
-
assert "
|
|
80
|
-
assert "
|
|
89
|
+
assert f"{MAXIMUM_SENTENCE_COUNT + 1} sentences" in stderr_text
|
|
90
|
+
assert f"limit {MAXIMUM_SENTENCE_COUNT}" in stderr_text
|
|
81
91
|
|
|
82
92
|
|
|
83
|
-
def
|
|
93
|
+
def test_should_deny_a_sentence_over_the_word_limit_and_name_it(
|
|
84
94
|
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
85
95
|
) -> None:
|
|
86
96
|
exit_code, stderr_text = run_gate(
|
|
87
|
-
monkeypatch, capsys, REPLY_TOOL_NAME, {"text":
|
|
97
|
+
monkeypatch, capsys, REPLY_TOOL_NAME, {"text": OVER_WORD_LIMIT_SENTENCE}
|
|
88
98
|
)
|
|
89
99
|
assert exit_code == 2
|
|
90
|
-
assert "
|
|
91
|
-
assert "
|
|
100
|
+
assert f"{MAXIMUM_WORDS_PER_SENTENCE + 1} words" in stderr_text
|
|
101
|
+
assert f"limit {MAXIMUM_WORDS_PER_SENTENCE}" in stderr_text
|
|
92
102
|
assert "One two three" in stderr_text
|
|
93
103
|
|
|
94
104
|
|
|
95
105
|
def test_should_check_the_project_chat_post_tool(
|
|
96
106
|
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
97
107
|
) -> None:
|
|
98
|
-
exit_code, _ = run_gate(monkeypatch, capsys, POST_TOOL_NAME, {"text":
|
|
108
|
+
exit_code, _ = run_gate(monkeypatch, capsys, POST_TOOL_NAME, {"text": OVER_SENTENCE_LIMIT_TEXT})
|
|
99
109
|
assert exit_code == 2
|
|
100
110
|
|
|
101
111
|
|
|
@@ -106,10 +116,10 @@ def test_should_count_each_line_of_a_list_as_a_sentence(
|
|
|
106
116
|
monkeypatch,
|
|
107
117
|
capsys,
|
|
108
118
|
REPLY_TOOL_NAME,
|
|
109
|
-
{"text": "
|
|
119
|
+
{"text": "\n".join(f"- item {each_number}" for each_number in range(MAXIMUM_SENTENCE_COUNT + 1))},
|
|
110
120
|
)
|
|
111
121
|
assert exit_code == 2
|
|
112
|
-
assert "
|
|
122
|
+
assert f"{MAXIMUM_SENTENCE_COUNT + 1} sentences" in stderr_text
|
|
113
123
|
|
|
114
124
|
|
|
115
125
|
def test_should_not_count_urls_as_words(
|
|
@@ -156,7 +166,7 @@ def test_should_not_count_backticked_spans_as_words(
|
|
|
156
166
|
def test_should_not_count_fenced_blocks(
|
|
157
167
|
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
158
168
|
) -> None:
|
|
159
|
-
fenced_block = "```\nOne.\nTwo.\nThree.\nFour.\n" +
|
|
169
|
+
fenced_block = "```\nOne.\nTwo.\nThree.\nFour.\n" + OVER_WORD_LIMIT_SENTENCE + "\n```"
|
|
160
170
|
exit_code, _ = run_gate(
|
|
161
171
|
monkeypatch,
|
|
162
172
|
capsys,
|
|
@@ -369,14 +379,14 @@ def short_card(**all_overrides: object) -> dict[str, object]:
|
|
|
369
379
|
return card
|
|
370
380
|
|
|
371
381
|
|
|
372
|
-
def
|
|
382
|
+
def test_should_allow_a_card_context_of_two_sentences_at_the_word_limit(
|
|
373
383
|
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
374
384
|
) -> None:
|
|
375
385
|
exit_code, stderr_text = run_gate(
|
|
376
386
|
monkeypatch,
|
|
377
387
|
capsys,
|
|
378
388
|
DECISION_TOOL_NAME,
|
|
379
|
-
short_card(context=" ".join([
|
|
389
|
+
short_card(context=" ".join([AT_WORD_LIMIT_SENTENCE] * 2)),
|
|
380
390
|
)
|
|
381
391
|
assert (exit_code, stderr_text) == (0, "")
|
|
382
392
|
|
|
@@ -439,13 +449,13 @@ def test_should_deny_a_long_card_consequence(
|
|
|
439
449
|
DECISION_TOOL_NAME,
|
|
440
450
|
short_card(
|
|
441
451
|
options=[
|
|
442
|
-
{"label": "Exclude it", "consequence":
|
|
452
|
+
{"label": "Exclude it", "consequence": OVER_WORD_LIMIT_SENTENCE},
|
|
443
453
|
{"label": "Leave it", "consequence": "Seven themes keep a warning."},
|
|
444
454
|
]
|
|
445
455
|
),
|
|
446
456
|
)
|
|
447
457
|
assert exit_code == 2
|
|
448
|
-
assert "Sentence too long:
|
|
458
|
+
assert f"Sentence too long: {MAXIMUM_WORDS_PER_SENTENCE + 1} words, limit {MAXIMUM_WORDS_PER_SENTENCE}" in stderr_text
|
|
449
459
|
|
|
450
460
|
|
|
451
461
|
@pytest.mark.parametrize("card_field_name", ["question", "reason"])
|
|
@@ -456,10 +466,10 @@ def test_should_deny_a_long_sentence_in_the_card_question_and_reason(
|
|
|
456
466
|
monkeypatch,
|
|
457
467
|
capsys,
|
|
458
468
|
DECISION_TOOL_NAME,
|
|
459
|
-
short_card(**{card_field_name:
|
|
469
|
+
short_card(**{card_field_name: OVER_WORD_LIMIT_SENTENCE}),
|
|
460
470
|
)
|
|
461
471
|
assert exit_code == 2
|
|
462
|
-
assert "Sentence too long:
|
|
472
|
+
assert f"Sentence too long: {MAXIMUM_WORDS_PER_SENTENCE + 1} words" in stderr_text
|
|
463
473
|
|
|
464
474
|
|
|
465
475
|
@pytest.mark.parametrize(
|
|
@@ -760,7 +770,7 @@ def test_should_keep_the_length_check_when_the_mode_is_off(
|
|
|
760
770
|
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
761
771
|
) -> None:
|
|
762
772
|
turn_mode_off(tmp_path)
|
|
763
|
-
exit_code, _ = run_gate(monkeypatch, capsys, REPLY_TOOL_NAME, {"text":
|
|
773
|
+
exit_code, _ = run_gate(monkeypatch, capsys, REPLY_TOOL_NAME, {"text": OVER_SENTENCE_LIMIT_TEXT})
|
|
764
774
|
assert exit_code == 2
|
|
765
775
|
|
|
766
776
|
|
|
@@ -1025,7 +1035,7 @@ def test_should_split_prose_sentences_outside_fenced_blocks() -> None:
|
|
|
1025
1035
|
|
|
1026
1036
|
|
|
1027
1037
|
LONG_GITHUB_COMMENT = " ".join(
|
|
1028
|
-
"Sentence number one of a long comment that keeps going." for _ in range(
|
|
1038
|
+
"Sentence number one of a long comment that keeps going." for _ in range(MAXIMUM_SENTENCE_COUNT + 1)
|
|
1029
1039
|
)
|
|
1030
1040
|
SHORT_GITHUB_COMMENT = "Fixed the cap check. The test now covers it. Checks pass."
|
|
1031
1041
|
|
|
@@ -1037,7 +1047,7 @@ def test_should_deny_long_github_comment(
|
|
|
1037
1047
|
monkeypatch, capsys, "mcp__github__add_issue_comment", {"body": LONG_GITHUB_COMMENT}
|
|
1038
1048
|
)
|
|
1039
1049
|
assert exit_code == 2
|
|
1040
|
-
assert "
|
|
1050
|
+
assert f"{MAXIMUM_SENTENCE_COUNT + 1} sentences, limit {MAXIMUM_SENTENCE_COUNT}" in error_text
|
|
1041
1051
|
|
|
1042
1052
|
|
|
1043
1053
|
def test_should_allow_short_github_comment_with_code_and_details(
|
|
@@ -1124,13 +1134,13 @@ def test_should_name_every_broken_rule_in_one_refusal(
|
|
|
1124
1134
|
monkeypatch,
|
|
1125
1135
|
capsys,
|
|
1126
1136
|
POST_TOOL_NAME,
|
|
1127
|
-
{"text": f"See PR 7452 and PR 7460.\n{
|
|
1137
|
+
{"text": f"See PR 7452 and PR 7460.\n{OVER_WORD_LIMIT_SENTENCE}\nIt failed — again."},
|
|
1128
1138
|
)
|
|
1129
1139
|
|
|
1130
1140
|
assert exit_code == reply_length_gate.BLOCK_EXIT_CODE
|
|
1131
1141
|
assert "PR 7452" in error_text
|
|
1132
1142
|
assert "PR 7460" in error_text
|
|
1133
|
-
assert "
|
|
1143
|
+
assert f"{MAXIMUM_WORDS_PER_SENTENCE + 1} words" in error_text
|
|
1134
1144
|
assert reply_length_gate.EM_DASH_MESSAGE in error_text
|
|
1135
1145
|
assert error_text.endswith(reply_length_gate.FIX_EVERY_ITEM_INSTRUCTION)
|
|
1136
1146
|
|
|
@@ -1142,16 +1152,16 @@ def test_should_number_nested_violations_once_in_one_refusal(
|
|
|
1142
1152
|
monkeypatch,
|
|
1143
1153
|
capsys,
|
|
1144
1154
|
POST_TOOL_NAME,
|
|
1145
|
-
{"text": f"
|
|
1155
|
+
{"text": f"{OVER_SENTENCE_LIMIT_TEXT}\n{OVER_WORD_LIMIT_SENTENCE}\n{OVER_WORD_LIMIT_SENTENCE}\nIt failed — again."},
|
|
1146
1156
|
)
|
|
1147
1157
|
|
|
1148
1158
|
assert exit_code == reply_length_gate.BLOCK_EXIT_CODE
|
|
1149
1159
|
all_numbered_lines = [each_line for each_line in error_text.splitlines() if each_line[:1].isdigit()]
|
|
1150
|
-
assert [each_line.split(". ", 1)[0] for each_line in all_numbered_lines] == ["1", "2", "3", "4"]
|
|
1160
|
+
assert [each_line.split(". ", 1)[0] for each_line in all_numbered_lines] == ["1", "2", "3", "4", "5"]
|
|
1151
1161
|
assert not any(each_line.split(". ", 1)[1][:1].isdigit() for each_line in all_numbered_lines)
|
|
1152
|
-
assert "Reply too long:
|
|
1153
|
-
assert all_numbered_lines[1].count("
|
|
1154
|
-
assert all_numbered_lines[2].count("
|
|
1162
|
+
assert f"Reply too long: {MAXIMUM_SENTENCE_COUNT + 4} sentences" in all_numbered_lines[0]
|
|
1163
|
+
assert all_numbered_lines[1].count(f"{MAXIMUM_WORDS_PER_SENTENCE + 1} words") == 1
|
|
1164
|
+
assert all_numbered_lines[2].count(f"{MAXIMUM_WORDS_PER_SENTENCE + 1} words") == 1
|
|
1155
1165
|
assert reply_length_gate.EM_DASH_MESSAGE in all_numbered_lines[3]
|
|
1156
1166
|
|
|
1157
1167
|
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import re
|
|
4
4
|
|
|
5
|
-
MAXIMUM_SENTENCE_COUNT =
|
|
6
|
-
MAXIMUM_WORDS_PER_SENTENCE =
|
|
5
|
+
MAXIMUM_SENTENCE_COUNT = 50
|
|
6
|
+
MAXIMUM_WORDS_PER_SENTENCE = 35
|
|
7
7
|
ALL_CHECKED_TOOL_NAMES = frozenset(
|
|
8
8
|
{"mcp__hearthbot__reply", "mcp__hearthbot__post_message", "mcp__hearthbot__update_message"}
|
|
9
9
|
)
|
|
@@ -182,6 +182,6 @@ ALL_GH_BODY_FLAGS = frozenset({"--body", "-b"})
|
|
|
182
182
|
GH_BODY_FLAG_PREFIX = "--body="
|
|
183
183
|
DETAILS_BLOCK_PATTERN = re.compile(r"<details\b.*?</details>", re.IGNORECASE | re.DOTALL)
|
|
184
184
|
COMMENT_RETRY_INSTRUCTION = (
|
|
185
|
-
" A comment on GitHub holds at most
|
|
185
|
+
f" A comment on GitHub holds at most {MAXIMUM_SENTENCE_COUNT} short sentences."
|
|
186
186
|
" Put detail in the pull request body, a code block, or a collapsed <details> block, then post again."
|
|
187
187
|
)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
from hooks_constants import reply_length_gate_constants as constants
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
def
|
|
5
|
-
assert (constants.MAXIMUM_SENTENCE_COUNT, constants.MAXIMUM_WORDS_PER_SENTENCE) == (
|
|
4
|
+
def test_gate_limits_replies_to_fifty_sentences_of_thirty_five_words() -> None:
|
|
5
|
+
assert (constants.MAXIMUM_SENTENCE_COUNT, constants.MAXIMUM_WORDS_PER_SENTENCE) == (50, 35)
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
def test_gate_checks_the_three_chat_tools_that_post_to_the_user() -> None:
|
package/package.json
CHANGED
|
@@ -149,11 +149,13 @@ ALL_NOTICE_COMMENT_MARKERS: tuple[str, ...] = (
|
|
|
149
149
|
"<h3>PR Summary by Qodo</h3>",
|
|
150
150
|
"<h3>Qodo is busy working</h3>",
|
|
151
151
|
"<h3>Great, no issues found!</h3>",
|
|
152
|
+
"<!-- This is an auto-generated comment: skip review by coderabbit.ai -->",
|
|
152
153
|
)
|
|
153
154
|
"""Text a bot notice carries: a Qodo skip note, a Qodo pointer to its updated
|
|
154
155
|
summary, a Graphite verdict mirror whose findings arrive as review threads, a
|
|
155
|
-
Qodo description of the change, a Qodo placeholder posted while it reviews,
|
|
156
|
-
|
|
156
|
+
Qodo description of the change, a Qodo placeholder posted while it reviews, a
|
|
157
|
+
Qodo review that found nothing, and a CodeRabbit skip note for a bot-authored
|
|
158
|
+
pull request."""
|
|
157
159
|
|
|
158
160
|
CODEX_REVIEW_BOT_LOGIN = "chatgpt-codex-connector[bot]"
|
|
159
161
|
ALL_REVIEW_REQUEST_COMMANDS = ("@codex review", "@codex security review")
|
|
@@ -10,6 +10,10 @@ from pathlib import Path
|
|
|
10
10
|
import pytest
|
|
11
11
|
|
|
12
12
|
import durable_post_lint
|
|
13
|
+
from hooks_constants.reply_length_gate_constants import (
|
|
14
|
+
MAXIMUM_SENTENCE_COUNT,
|
|
15
|
+
MAXIMUM_WORDS_PER_SENTENCE,
|
|
16
|
+
)
|
|
13
17
|
from dev_env_scripts_constants.private_term_constants import PrivateTermDigest
|
|
14
18
|
from hooks_constants.pull_request_proof_constants import (
|
|
15
19
|
MISSING_EVAL_SECTION_REASON,
|
|
@@ -62,9 +66,8 @@ Ran `python scripts/durable_post_lint.py --action pr-create --body-file body.md`
|
|
|
62
66
|
"""
|
|
63
67
|
OVER_LONG_REPLY_BODY = (
|
|
64
68
|
"Fixed in `abc1234`.\n\n"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"---\nPosted by the review agent."
|
|
69
|
+
+ " ".join(f"Status line {each_number} is ready." for each_number in range(MAXIMUM_SENTENCE_COUNT + 1))
|
|
70
|
+
+ "\n\n---\nPosted by the review agent."
|
|
68
71
|
)
|
|
69
72
|
MINIMAL_PR_BODY = """## Why
|
|
70
73
|
|
|
@@ -444,7 +447,7 @@ def should_exit_with_findings_for_a_create_body_with_no_existing_work_section(
|
|
|
444
447
|
assert completed_process.stderr == f"{MISSING_EXISTING_WORK_REASON}\n"
|
|
445
448
|
|
|
446
449
|
|
|
447
|
-
def
|
|
450
|
+
def should_report_a_review_reply_over_the_sentence_limit() -> None:
|
|
448
451
|
all_findings = durable_post_lint.lint_durable_post(
|
|
449
452
|
action="github-mcp-comment",
|
|
450
453
|
title=None,
|
|
@@ -455,13 +458,12 @@ def should_report_a_review_reply_over_three_sentences() -> None:
|
|
|
455
458
|
]
|
|
456
459
|
|
|
457
460
|
|
|
458
|
-
def
|
|
461
|
+
def should_report_a_review_reply_sentence_over_the_word_limit() -> None:
|
|
459
462
|
all_findings = durable_post_lint.lint_durable_post(
|
|
460
463
|
action="github-mcp-comment",
|
|
461
464
|
title=None,
|
|
462
465
|
body_text=(
|
|
463
|
-
"
|
|
464
|
-
" caller on the same import path."
|
|
466
|
+
" ".join(f"word{each_number}" for each_number in range(MAXIMUM_WORDS_PER_SENTENCE + 1)) + "."
|
|
465
467
|
),
|
|
466
468
|
)
|
|
467
469
|
assert [each_finding.code for each_finding in all_findings] == [
|
|
@@ -495,7 +497,7 @@ def should_exit_with_findings_for_an_over_long_review_reply(tmp_path: Path) -> N
|
|
|
495
497
|
text=True,
|
|
496
498
|
)
|
|
497
499
|
assert completed_process.returncode == 1
|
|
498
|
-
assert "at most
|
|
500
|
+
assert f"at most {MAXIMUM_SENTENCE_COUNT} short sentences" in completed_process.stderr
|
|
499
501
|
|
|
500
502
|
|
|
501
503
|
def should_exit_clean_for_a_short_review_reply(tmp_path: Path) -> None:
|
|
@@ -469,6 +469,9 @@ def should_close_a_bot_notice_posted_after_the_driver_time() -> None:
|
|
|
469
469
|
"\n<h3>Qodo is busy working</h3>\n\nCheck back in a few minutes.",
|
|
470
470
|
"\n<h3>Code Review by Qodo</h3>\n<code>\U0001f41e Bugs (0)</code>\n\n"
|
|
471
471
|
"<h3>Great, no issues found!</h3>\nQodo reviewed your code",
|
|
472
|
+
"<!-- coderabbit-ai-generated:v1 -->\n\n"
|
|
473
|
+
"<!-- This is an auto-generated comment: skip review by coderabbit.ai -->\n"
|
|
474
|
+
"> [!IMPORTANT]\n> ## Review skipped\n>\n> Bot user detected.",
|
|
472
475
|
],
|
|
473
476
|
)
|
|
474
477
|
def should_read_a_bot_notice_as_a_notice(body: str) -> None:
|