tenseleyflow/documentlanguagemodel / fe9c820

Browse files

Pre-commit hook: refuse new sprint/audit IDs in src/dlm/

Diff-based, fires on staged additions. Pregate already runs a similar pre-push check; this hook is the earlier guard so the rule fires before each commit instead of waiting for the push.
Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
fe9c82028b3de03f68b0cb08905a40c6e25e6490
Parents
1f790be
Tree
6a035e3

2 changed files

StatusFile+-
M .pre-commit-config.yaml 6 0
A scripts/check-no-sprint-references.sh 46 0
.pre-commit-config.yamlmodified
@@ -32,6 +32,12 @@ repos:
3232
 
3333
   - repo: local
3434
     hooks:
35
+      - id: no-sprint-references
36
+        name: refuse new sprint/audit IDs in src/dlm/
37
+        entry: ./scripts/check-no-sprint-references.sh --staged
38
+        language: system
39
+        pass_filenames: false
40
+        stages: [pre-commit]
3541
       - id: pytest-unit
3642
         name: pytest (unit + non-slow integration)
3743
         entry: uv run pytest -m "not slow and not gpu and not online"
scripts/check-no-sprint-references.shadded
@@ -0,0 +1,46 @@
1
+#!/usr/bin/env bash
2
+# Refuse new "Sprint N" / "audit-N" references in src/dlm/.
3
+#
4
+# Sprint IDs and audit IDs belong in `.docs/sprints/` and
5
+# `.docs/audits/`, not in source code. Code that mentions a sprint by
6
+# number rots the moment that sprint's scope shifts. We caught and
7
+# swept this multiple times across audits 09 / 11 / 12 — this hook
8
+# enforces the norm so the next sweep doesn't have to be mechanical.
9
+#
10
+# Runs against the staged diff (pre-commit) — only NEW additions are
11
+# checked. Existing lines are tolerated (the sweep already cleaned
12
+# them up; future sweeps catch any drift the diff misses).
13
+#
14
+# To run manually:
15
+#     ./scripts/check-no-sprint-references.sh
16
+# To check only what's staged:
17
+#     ./scripts/check-no-sprint-references.sh --staged
18
+
19
+set -euo pipefail
20
+
21
+PATTERN='([Ss]print[[:space:]]+[0-9]+|[Aa]udit[[:space:]]*-?[[:space:]]*[0-9]+)'
22
+
23
+if [[ "${1:-}" == "--staged" ]]; then
24
+    diff="$(git diff --cached --no-color --unified=0 -- 'src/dlm/*.py')"
25
+    # Only inspect added lines (start with '+', not '+++ ').
26
+    hits="$(printf '%s\n' "$diff" \
27
+        | grep -E '^\+[^+]' \
28
+        | grep -E "$PATTERN" || true)"
29
+    if [[ -n "$hits" ]]; then
30
+        echo "Refusing commit: new sprint/audit references in src/dlm/." >&2
31
+        echo "Move them into .docs/sprints/ or .docs/audits/." >&2
32
+        echo >&2
33
+        printf '%s\n' "$hits" >&2
34
+        exit 1
35
+    fi
36
+    exit 0
37
+fi
38
+
39
+# Full-tree audit (use this in CI / on demand).
40
+hits="$(git grep -nE "$PATTERN" -- 'src/dlm/*.py' || true)"
41
+if [[ -n "$hits" ]]; then
42
+    echo "Sprint/audit references found in src/dlm/:" >&2
43
+    printf '%s\n' "$hits" >&2
44
+    exit 1
45
+fi
46
+echo "src/dlm/ clean — no sprint/audit references."