From cf5de2bd87d39386cca21b3a183800d3975fe825 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Mon, 10 Aug 2026 07:45:58 +0000 Subject: [PATCH] fix(lint): fail loudly on a nonexistent REPO_ROOT in check-vale-style-sync.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A bad or stale REPO_ROOT argument fell through to the "neither copy present" no-op guard and exited 0 — the exact "clean result can mean nothing was checked" anti-pattern this PR spent multiple review rounds eliminating elsewhere. That guard exists for a repo that legitimately has no kyberforge plugin installed, not for a typo'd path. Only the documented manual-invocation mode was affected: the shipped pre-push hook always calls this script with zero args, which resolves via `git rev-parse --show-toplevel` and is always valid inside a repo. Added a regression test asserting a nonexistent REPO_ROOT exits non-zero. Refs: #85 --- scripts/check-vale-style-sync.sh | 12 +++++++++--- tests/test-check-vale-style-sync.sh | 13 +++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/scripts/check-vale-style-sync.sh b/scripts/check-vale-style-sync.sh index cd4a0d6..a547604 100755 --- a/scripts/check-vale-style-sync.sh +++ b/scripts/check-vale-style-sync.sh @@ -10,11 +10,17 @@ set -euo pipefail # only one of the two. Run from repo root or pass REPO_ROOT as arg. REPO_ROOT="${1:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}" +# A nonexistent REPO_ROOT must fail loudly, not fall through to the "neither +# copy present" no-op below — that guard exists for a repo that legitimately +# has no kyberforge plugin installed, not for a typo'd or stale path, and a +# clean exit 0 here would read as "checked, in sync" when nothing ran at all. +if [[ ! -d "$REPO_ROOT" ]]; then + echo "Vale style sync check failed: REPO_ROOT '$REPO_ROOT' is not a directory." >&2 + exit 1 +fi # Absolutized because the glob probe below `cd`s into a scratch tree, where a # relative --config path would stop resolving. -if [[ -d "$REPO_ROOT" ]]; then - REPO_ROOT="$(cd "$REPO_ROOT" && pwd)" -fi +REPO_ROOT="$(cd "$REPO_ROOT" && pwd)" FAIL=0 err() { echo " FAIL: $1" >&2; FAIL=$((FAIL + 1)); } diff --git a/tests/test-check-vale-style-sync.sh b/tests/test-check-vale-style-sync.sh index c4f88bb..965e3e2 100755 --- a/tests/test-check-vale-style-sync.sh +++ b/tests/test-check-vale-style-sync.sh @@ -123,6 +123,19 @@ else fail "exited non-zero when skill-audit/agent-audit are simply absent" fi +# --- 5b. Exits 1 when REPO_ROOT does not exist --- +# A nonexistent path used to fall through to the "neither copy present" no-op +# (test 5 above) and exit 0 — indistinguishable from a real, verified in-sync +# result. That guard is for a repo legitimately missing kyberforge, not a +# typo'd or stale path. +echo "" +echo "--- exits 1 when REPO_ROOT does not exist ---" +if bash "$SCRIPT" "/nonexistent/path/$(date +%s)-$$" > /dev/null 2>&1; then + fail "exited 0 for a nonexistent REPO_ROOT — expected exit 1" +else + pass "exits non-zero for a nonexistent REPO_ROOT" +fi + # --- 6. Exits 1 when only one of the two copies is present --- # The no-op guard used `||`, so a single missing copy also exited 0 — a deleted # or renamed copy passed the sync check silently.