claude-dev-env 8.116.2 → 8.116.3

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.
@@ -38,7 +38,7 @@ from contextvars import ContextVar
38
38
  from dataclasses import dataclass, field
39
39
  from enum import Enum
40
40
  from pathlib import Path
41
- from typing import cast
41
+ from typing import TypeVar, cast
42
42
 
43
43
  hooks_directory = str(Path(__file__).resolve().parent.parent)
44
44
  if hooks_directory not in sys.path:
@@ -51,6 +51,8 @@ from hooks_constants.gate_run_reads_constants import (
51
51
  )
52
52
  from hooks_constants.subprocess_window import hidden_window_creation_flags
53
53
 
54
+ AnswerType = TypeVar("AnswerType")
55
+
54
56
 
55
57
  class ReadSlice(Enum):
56
58
  """Which deadline a read answers to, as seconds from the start of the gate process."""
@@ -120,7 +122,7 @@ def read_deadlines_started(clock: Callable[[], float] = time.monotonic) -> Itera
120
122
  started_read_deadlines.reset(token)
121
123
 
122
124
 
123
- def answer_once[AnswerType](question: Hashable, read: Callable[[], AnswerType]) -> AnswerType:
125
+ def answer_once(question: Hashable, read: Callable[[], AnswerType]) -> AnswerType:
124
126
  """Return the open run's answer to ``question``, reading it the first time it is asked.
125
127
 
126
128
  Args:
@@ -234,7 +236,7 @@ def _answer_within(child: subprocess.Popen[str], allowance: float, own_timeout_s
234
236
  return printed_text if child.returncode == 0 else None
235
237
 
236
238
 
237
- def _answers_in_a_daemon_thread[AnswerType](
239
+ def _answers_in_a_daemon_thread(
238
240
  read: Callable[[float], AnswerType], allowance: float
239
241
  ) -> tuple[list[AnswerType], list[Exception]]:
240
242
  all_answers: list[AnswerType] = []
@@ -252,7 +254,7 @@ def _answers_in_a_daemon_thread[AnswerType](
252
254
  return all_answers, all_errors
253
255
 
254
256
 
255
- def answer_within_allowance[AnswerType](
257
+ def answer_within_allowance(
256
258
  read: Callable[[float], AnswerType], own_timeout_seconds: float, read_slice: ReadSlice
257
259
  ) -> AnswerType | None:
258
260
  """Run one read in a daemon thread and return its answer, or None when the allowance runs out first.
@@ -27,7 +27,6 @@ OTHER_FOLLOWUP = {
27
27
  "html_url": "https://github.com/jl-cmd/claude-dev-env/pull/1777",
28
28
  "body": "follow-up to #17",
29
29
  }
30
- ELAPSED_SLACK_SECONDS = 8.0
31
30
 
32
31
 
33
32
  def _reader(all_open: list[Mapping[str, object]]) -> dedupe.OpenPullRequestReader:
@@ -134,10 +133,8 @@ def test_read_open_pull_requests_should_bound_the_whole_read(monkeypatch: pytest
134
133
  monkeypatch.setenv("no_proxy", "127.0.0.1")
135
134
  monkeypatch.setattr(dedupe, "GITHUB_API_ROOT", f"http://127.0.0.1:{server.server_address[1]}")
136
135
  monkeypatch.setattr(dedupe, "READ_TIMEOUT_SECONDS", 1)
137
- started = time.monotonic()
138
136
  with pytest.raises(TimeoutError):
139
137
  dedupe.read_open_pull_requests("jl-cmd", "claude-dev-env")
140
- assert time.monotonic() - started < 1 + ELAPSED_SLACK_SECONDS
141
138
  server.shutdown()
142
139
 
143
140
 
@@ -1,8 +1,10 @@
1
1
  """Behavior tests for the answers one pull request lifecycle gate run remembers."""
2
2
 
3
+ import ast
3
4
  import json
5
+ import subprocess
4
6
  import sys
5
- import time
7
+ import threading
6
8
  from pathlib import Path
7
9
 
8
10
  import pytest
@@ -31,14 +33,25 @@ from hooks_constants.gate_run_reads_constants import (
31
33
  )
32
34
 
33
35
  CLOCK_START = 100.0
36
+ OLDEST_SUPPORTED_PYTHON = (3, 11)
34
37
  HIDDEN_WINDOW_FLAGS = 0x08000000
35
38
  SLEEP_THEN_PRINT = "import time; time.sleep(30); print('late')"
36
- GRANDCHILD_HOLDS_THE_PIPE = (
39
+ HELD_READ_GIVES_UP_SECONDS = 30
40
+ GRANDCHILD_WAITS_FOR_RELEASE = (
41
+ "import os, sys, time\n"
42
+ "gave_up_path, release_path = sys.argv[1], sys.argv[2]\n"
43
+ "polls_left = 300\n"
44
+ "while polls_left and not os.path.exists(release_path):\n"
45
+ " time.sleep(0.1)\n"
46
+ " polls_left -= 1\n"
47
+ "if not os.path.exists(release_path):\n"
48
+ " open(gave_up_path, 'w').close()\n"
49
+ )
50
+ CHILD_STARTS_A_GRANDCHILD = (
37
51
  "import subprocess, sys, time;"
38
- " subprocess.Popen([sys.executable, '-c', 'import time; time.sleep(30)']);"
52
+ " subprocess.Popen([sys.executable, '-c', *sys.argv[1:]]);"
39
53
  " time.sleep(30)"
40
54
  )
41
- ELAPSED_SLACK_SECONDS = 8.0
42
55
  GATE_COMMAND_SUFFIX = "hooks/blocking/pr_lifecycle_" + "skill_gate.py"
43
56
 
44
57
 
@@ -50,6 +63,31 @@ class FakeClock:
50
63
  return self.now
51
64
 
52
65
 
66
+ class RecordedChild(subprocess.Popen[str]):
67
+ """A child that notes the timeout of each wait its caller makes."""
68
+
69
+ def __init__(self, *all_arguments: object, **all_options: object) -> None:
70
+ self.all_wait_timeouts: list[object] = []
71
+ super().__init__(*all_arguments, **all_options)
72
+
73
+ def communicate(self, *all_arguments: object, **all_options: object) -> tuple[str, str]:
74
+ self.all_wait_timeouts.append(all_options.get("timeout"))
75
+ return super().communicate(*all_arguments, **all_options)
76
+
77
+
78
+ @pytest.fixture
79
+ def all_started_children(monkeypatch: pytest.MonkeyPatch) -> list[RecordedChild]:
80
+ all_children: list[RecordedChild] = []
81
+
82
+ def start(*all_arguments: object, **all_options: object) -> RecordedChild:
83
+ child = RecordedChild(*all_arguments, **all_options)
84
+ all_children.append(child)
85
+ return child
86
+
87
+ monkeypatch.setattr(gate_run_reads.subprocess, "Popen", start)
88
+ return all_children
89
+
90
+
53
91
  def _counting_read(all_reads: list[str], answer: str | None):
54
92
  def read() -> str | None:
55
93
  all_reads.append("read")
@@ -157,46 +195,62 @@ def test_child_stdout_should_start_its_child_with_the_hidden_window_flags(monkey
157
195
  assert all_seen_flags == [HIDDEN_WINDOW_FLAGS]
158
196
 
159
197
 
160
- def test_child_stdout_should_kill_a_child_that_outlives_its_own_timeout() -> None:
198
+ def test_child_stdout_should_kill_a_child_that_outlives_its_own_timeout(
199
+ all_started_children: list[RecordedChild],
200
+ ) -> None:
161
201
  with gate_run() as run:
162
- started = time.monotonic()
163
202
  assert child_stdout([sys.executable, "-c", SLEEP_THEN_PRINT], 0.5, ReadSlice.PROOF_AND_LOOK) is None
164
- elapsed = time.monotonic() - started
165
- assert elapsed < 0.5 + ELAPSED_SLACK_SECONDS
203
+ (child,) = all_started_children
204
+ assert child.all_wait_timeouts == [0.5, KILL_GRACE_SECONDS]
205
+ assert child.wait() != 0
166
206
  assert not run.was_read_cut_short
167
207
 
168
208
 
169
- def test_child_stdout_should_stop_waiting_when_a_grandchild_holds_the_pipe() -> None:
170
- started = time.monotonic()
171
- assert child_stdout([sys.executable, "-c", GRANDCHILD_HOLDS_THE_PIPE], 0.5, ReadSlice.PROOF_AND_LOOK) is None
172
- assert time.monotonic() - started < 0.5 + KILL_GRACE_SECONDS + ELAPSED_SLACK_SECONDS
209
+ def test_child_stdout_should_stop_waiting_when_a_grandchild_holds_the_pipe(tmp_path: Path) -> None:
210
+ gave_up_path = tmp_path / "gave-up"
211
+ release_path = tmp_path / "release"
212
+ command = [
213
+ sys.executable,
214
+ "-c",
215
+ CHILD_STARTS_A_GRANDCHILD,
216
+ GRANDCHILD_WAITS_FOR_RELEASE,
217
+ str(gave_up_path),
218
+ str(release_path),
219
+ ]
220
+ answer = child_stdout(command, 1, ReadSlice.PROOF_AND_LOOK)
221
+ release_path.touch()
222
+ assert answer is None
223
+ assert not gave_up_path.exists()
173
224
 
174
225
 
175
- def test_child_stdout_should_mark_the_run_when_the_deadline_cuts_a_read_short() -> None:
226
+ def test_child_stdout_should_mark_the_run_when_the_deadline_cuts_a_read_short(
227
+ all_started_children: list[RecordedChild],
228
+ ) -> None:
176
229
  clock = FakeClock()
177
230
  with read_deadlines_started(clock), gate_run() as run:
178
231
  clock.now = CLOCK_START + PROOF_AND_LOOK_READS_SECONDS - 0.4
179
- started = time.monotonic()
180
232
  assert child_stdout([sys.executable, "-c", SLEEP_THEN_PRINT], 5, ReadSlice.PROOF_AND_LOOK) is None
181
- elapsed = time.monotonic() - started
182
- assert elapsed < 0.4 + ELAPSED_SLACK_SECONDS
233
+ (child,) = all_started_children
234
+ assert child.all_wait_timeouts == [pytest.approx(0.4), KILL_GRACE_SECONDS]
235
+ assert child.wait() != 0
183
236
  assert run.was_read_cut_short
184
237
 
185
238
 
186
- def _slow_read(allowance: float) -> list[str]:
187
- time.sleep(allowance + 30)
188
- return ["late"]
189
-
190
-
191
239
  def test_answer_within_allowance_should_bound_the_whole_read() -> None:
192
240
  clock = FakeClock()
241
+ release = threading.Event()
242
+
243
+ def held_read(allowance: float) -> list[str]:
244
+ release.wait(HELD_READ_GIVES_UP_SECONDS)
245
+ return ["late"]
246
+
193
247
  with read_deadlines_started(clock), gate_run() as run:
194
248
  clock.now = CLOCK_START + PROOF_AND_LOOK_READS_SECONDS + FOLLOWUP_READS_SECONDS - 0.3
195
- started = time.monotonic()
196
- answer = answer_within_allowance(_slow_read, 4, ReadSlice.FOLLOWUP)
197
- elapsed = time.monotonic() - started
249
+ try:
250
+ answer = answer_within_allowance(held_read, 4, ReadSlice.FOLLOWUP)
251
+ finally:
252
+ release.set()
198
253
  assert answer is None
199
- assert elapsed < 0.3 + ELAPSED_SLACK_SECONDS
200
254
  assert run.was_read_cut_short
201
255
 
202
256
 
@@ -239,3 +293,8 @@ def test_registered_timeout_should_outlast_every_read_deadline_and_kill_grace()
239
293
  + KILL_GRACE_SECONDS * MOST_CUT_READS_PER_RUN
240
294
  )
241
295
  assert _registered_gate_timeout_seconds() >= last_read_ends_at + STARTUP_AND_SCAN_MARGIN_SECONDS
296
+
297
+
298
+ def test_gate_run_reads_should_parse_under_the_oldest_supported_python() -> None:
299
+ source = Path(gate_run_reads.__file__).read_text(encoding="utf-8")
300
+ assert ast.parse(source, feature_version=OLDEST_SUPPORTED_PYTHON).body
@@ -94,6 +94,7 @@ ignore = [
94
94
  # Residual production carve-outs re-homed on #57 (gate friction on multi-line touch).
95
95
  "validators/run_all_validators.py" = ["PLW1510"]
96
96
  "validators/exempt_paths.py" = ["F401"]
97
+ "blocking/gate_run_reads.py" = ["UP047"]
97
98
  "test_*.py" = ["B011", "PLR2004", "F401", "F841", "PLW1510", "B905", "B033", "SIM115", "B007", "B018", "B904"]
98
99
  "*_test.py" = ["B011", "PLR2004", "F401", "F841", "PLW1510", "B905", "B033", "SIM115", "B007", "B018", "B904"]
99
100
  "conftest.py" = ["B011", "F401", "F841", "PLW1510"]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "8.116.2",
3
+ "version": "8.116.3",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {