Files
DarkRoom/.githooks/pre-commit
T
dtourolleandClaude Opus 5 091306f736
🐳 Android image / Build and push (push) Successful in 3s
Build and test / android-image (push) Successful in 3s
Build and test / Desktop (Linux) (push) Failing after 1h16m50s
Build and test / Layer separation (push) Successful in 39s
Traceability / Requirement traces (push) Successful in 50s
Build and test / Android (aarch64) (push) Successful in 22m27s
Gate the gesture vocabulary the way the matrix is gated
Three holes, all found by the gate catching itself out.

**Prose that mentions the tag was read as a tag.** `dr-ui`'s module list
carries a comment saying where the generated table comes from, and it
names `GESTURE:` in passing; the scan extracted that sentence fragment as
a gesture with no place and no way to perform it. A tag must now *open*
its comment. A line that merely mentions it is describing the mechanism,
not declaring a member of it, and position is the only thing that tells
the two apart — which also makes the string-literal guard fall out for
free rather than being a special case.

**Neither artefact was regenerated on commit.** They cite line numbers,
so they go stale on anything that moves a line — the sheet commit made
the document wrong about every gesture in `library.slint` without
touching a single one. The pre-commit hook that already keeps the matrix
in step now keeps these too, and unlike the matrix it *fails* rather than
shrugging when the scan does: a matrix that will not build leaves a stale
one in place, where a malformed gesture block means a user about to be
told the wrong thing.

**CI did not check them at all.** It does now, blocking. The matrix is
read; the gesture table is *shown to somebody using the application*, and
a stale one tells them to perform a gesture that no longer exists — from
which they will conclude the application is broken rather than the page.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-30 00:51:13 +02:00

68 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Keep the generated artefacts in step with the tags in the tree.
#
# Two of them now, from the same scanner: the requirements matrix and the
# gesture vocabulary. Both are generated *from* the tree and cite line numbers
# in it, so both go stale on any commit that moves a line — a `cargo fmt` sweep
# above all, but equally a commit that merely adds a paragraph above a tag.
#
# The gate regenerates the matrix in CI and fails if the result differs from
# what is committed. That is the right check — a matrix that disagrees with the
# tree is worse than none, because it is read as current — but it fails *after*
# a push, on a commit that is otherwise fine, and it has now done so on six
# commits in a row because adding a `TRACES:` tag and regenerating the matrix
# are two actions and only the first is on anyone's mind.
#
# So it happens here instead, where the tags are being changed.
#
# Only when something that can carry a tag is staged: a commit touching
# workflows, packaging or the matrix itself pays nothing.
set -euo pipefail
staged="$(git diff --cached --name-only --diff-filter=ACMR)"
if ! grep -qE '\.(rs|slint|yaml|md)$' <<< "${staged}"; then
exit 0
fi
# The artefacts are generated from the tree, so regenerating them because one
# was itself edited would be circular.
case "$(tr -d '[:space:]' <<< "${staged}")" in
docs/traceability.md | docs/gestures.md | ui/dr-ui/src/gesture_book.rs)
exit 0
;;
esac
repo="$(git rev-parse --show-toplevel)"
cd "${repo}"
# Quiet unless it has something to say. A hook that prints on every commit is
# a hook people start passing --no-verify to.
if ! cargo run -q -p traceability -- report >/dev/null 2>&1; then
echo "pre-commit: could not run the traceability report; leaving the matrix alone" >&2
exit 0
fi
if ! git diff --quiet -- docs/traceability.md; then
git add docs/traceability.md
echo "pre-commit: regenerated docs/traceability.md and staged it"
fi
# The gesture vocabulary, same discipline.
#
# **Failure here is reported and not swallowed**, unlike the matrix above. A
# matrix that will not build leaves the previous one in place, which is merely
# stale; a malformed `GESTURE:` block means a gesture the user is about to be
# told about in the wrong words, or not at all. The gate would catch it in CI
# either way — this is only about catching it a push earlier.
if ! out="$(cargo run -q -p traceability -- gestures 2>&1)"; then
echo "pre-commit: the gesture scan failed — the tags below need fixing" >&2
echo "${out}" >&2
exit 1
fi
for f in docs/gestures.md ui/dr-ui/src/gesture_book.rs; do
if ! git diff --quiet -- "${f}"; then
git add "${f}"
echo "pre-commit: regenerated ${f} and staged it"
fi
done