claude-dev-env 8.116.4 → 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.
@@ -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 find_pyproject_configuring_tool
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 find_pyproject_configuring_tool
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 ``--config`` from the path."""
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. Without it, the files are checked natively."""
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 finds no ruff config and passes.
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 / "detached" / "asserts.py"
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:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "8.116.4",
3
+ "version": "8.116.5",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {