Skip to content

Commit 841f0f3

Browse files
chore(hooks): scope pre-edit-impact to cqs's own src/ and tests/ (#1068)
The hook was matching any path containing `/src/`, which included vendored Rust subtrees like `cuvs-fork-push/rust/cuvs/src/`. When an Edit fired against a cuvs file, the hook tried to invoke `python3 .claude/hooks/pre-edit-impact.py` with cwd=cuvs-fork-push, where that path doesn't exist — silently blocking the Edit with a 'No such file' error. Hit during today's rebase of rapidsai/cuvs#2019 to resolve a merge conflict; had to work around by writing the file via a Python script in Bash. Tighten the path predicate: derive cqs root from the script's own location, then accept only files under `<cqs_root>/src/` or `<cqs_root>/tests/`. cuvs-fork-push, evals/, samples/, and any future vendored Rust subtree all silently bail. Verified with four smoke cases: - cuvs path → exit 0, no `cqs impact` invocation - cqs/src path → exit 0, runs `cqs impact` (no output for hypothetical fns) - cqs/tests path → exit 0, runs `cqs impact` - cqs/evals/*.rs → exit 0, no invocation (not under src/ or tests/) Co-authored-by: jamie8johnson <jamie8johnson@users.noreply.github.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d290f23 commit 841f0f3

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

.claude/hooks/pre-edit-impact.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
Only fires when `old_string` contains a `fn foo` / `pub fn foo` declaration.
55
Non-fn edits (schema, comments, match arms, string literals) produce no output,
66
keeping context injection focused on risky function-targeted changes.
7+
8+
Scope: ONLY fires for cqs's own `src/` and `tests/` trees. Vendored Rust
9+
subtrees (`cuvs-fork-push/rust/`, future bundled deps) are deliberately
10+
skipped — `cqs impact` runs against cqs's index, which doesn't contain
11+
foreign Cargo workspaces, so the lookup would be empty/wrong. Earlier
12+
versions of this script matched any path containing `/src/`, which fired
13+
on cuvs-fork-push edits and blocked them with a missing-file error
14+
during conflict resolution.
715
"""
816
import json
917
import os
@@ -15,8 +23,19 @@
1523
file_path = inp.get("tool_input", {}).get("file_path", "")
1624
old_string = inp.get("tool_input", {}).get("old_string", "")
1725

18-
# Only analyse Rust source files in src/
19-
if not file_path.endswith(".rs") or "/src/" not in file_path:
26+
if not file_path.endswith(".rs"):
27+
sys.exit(0)
28+
29+
# Derive cqs project root from the script's own location:
30+
# <cqs_root>/.claude/hooks/pre-edit-impact.py → ../../ = <cqs_root>
31+
CQS_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", ".."))
32+
33+
abs_path = os.path.realpath(file_path)
34+
allowed_roots = (
35+
os.path.join(CQS_ROOT, "src") + os.sep,
36+
os.path.join(CQS_ROOT, "tests") + os.sep,
37+
)
38+
if not abs_path.startswith(allowed_roots):
2039
sys.exit(0)
2140

2241
# Look for a fn / pub fn / pub async fn / pub(crate) fn declaration in old_string.

0 commit comments

Comments
 (0)