Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions .github/workflows/validate-skills.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ jobs:
run: bash scripts/seeded-gates.test.sh
- name: Seeded gate-time budget, record, check, hook and ratchet guards
run: bash scripts/gate-budget.test.sh
- name: Seeded gate wrapper path-word tests
run: bash scripts/gate-baselined-paths.test.sh

seeded-gate-ci-tests:
name: Seeded gate tests, day-one and CI templates
Expand Down Expand Up @@ -655,6 +657,8 @@ jobs:
run: bash scripts/harness-merge.test.sh
- name: Harness refresh superseded-file tests
run: bash scripts/harness-refresh-stale-guard.test.sh
- name: Harness refresh manifest key tests
run: bash scripts/harness-refresh-keys.test.sh

refresh-adopt-route-tests:
name: Refresh adopt-route tests
Expand Down Expand Up @@ -811,11 +815,23 @@ jobs:
fetch-tags: true
- name: Migrate gate baseline tests
run: bash scripts/migrate-baseline.test.sh
- name: Adopted docs baseline tests
run: bash scripts/adopt-docs-baseline.test.sh
- name: Pristine hashes are current
run: bash skills/migrate/general/gen-pristine-hashes.sh --check

adopt-docs-baseline-tests:
name: Adopted docs baseline tests
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
fetch-tags: true
- name: Adopted docs baseline tests
run: bash scripts/adopt-docs-baseline.test.sh

lint-negative-tests:
name: Lint check negative tests
runs-on: ubuntu-24.04
Expand Down Expand Up @@ -960,6 +976,7 @@ jobs:
- sonar-parity-tests
- defect-report-tests
- migrate-baseline-tests
- adopt-docs-baseline-tests
- lint-negative-tests
- fence-snapshot-frozen
- line-budget-frozen
Expand Down
1 change: 1 addition & 0 deletions changelog.d/minors-batch-2.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Several smaller gaps in the seeded harness and its tests are closed: the gate-time budget hook never waits on a stdin that does not close, and its test now reaps every process it starts and fails if one survives; `scripts/set-coverage-floor.sh` reads a jest section in `package.json` and `jest.config.json` honestly, names the real limit in its messages, and ignores comment text when it looks for the insertion line; `harness-refresh.sh` stops on a repeated or non-plain `stack` key; the docs gate refuses a linked or empty baseline wrapper; the gate wrapper refuses control characters in a path word; the live harness check asks a jest `test:ci` line for a floor in `jest.config.*`; and the CI=none branch lint covers every form of a second early exit.
19 changes: 19 additions & 0 deletions scripts/check-docs.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,25 @@ printf '[a](docs\\real.md) [b](C:\\x)\n' > "$d/README.md"
run_check "$d"
check 0 "$EC" "backslash_targets: not checked ($OUT)"

# a baseline file with no usable wrapper stops the gate (exit 2) instead of running unjudged; a usable wrapper routes through
d="$T/clean-nestjs"
printf '# templatecentral gate baseline v2\ndocs\tREADME.md:1: x\n' > "$d/.claude/gate-baseline.txt"
for wrapper in missing linked empty; do
rm -rf "$T/wrap-$wrapper"
cp -R "$d" "$T/wrap-$wrapper"
rm -f "$T/wrap-$wrapper/scripts/gate-baselined.sh"
case "$wrapper" in
linked) ln -s ../../clean-nestjs/scripts/gate-baseline.sh "$T/wrap-$wrapper/scripts/gate-baselined.sh" ;;
empty) : > "$T/wrap-$wrapper/scripts/gate-baselined.sh" ;;
esac
run_check "$T/wrap-$wrapper"
check 2 "$EC" "baseline_wrapper[$wrapper]: exits 2 ($OUT)"
check 1 "$(printf '%s\n' "$OUT" | grep -c 'is missing, linked or empty')" "baseline_wrapper[$wrapper]: names the cause ($OUT)"
done
run_check "$d"
check 0 "$(printf '%s\n' "$OUT" | grep -c 'is missing, linked or empty')" "baseline_wrapper[control]: a real wrapper is not refused for being unusable ($OUT)"
rm -f "$d/.claude/gate-baseline.txt"

# the retired gate and its opt-in appear nowhere in the seeded layer or the kit
old=$(grep -rnE 'readme-coupling|readme-freshness|skip-readme-check|ci-gates\.sh readme|richReadme|TC_RICH_README|README freshness' \
"$REPO_ROOT/skills/scaffold" "$REPO_ROOT/skills/add" "$REPO_ROOT/skills/cleanup" "$REPO_ROOT/skills/review" "$REPO_ROOT/skills/standards" 2>/dev/null)
Expand Down
47 changes: 47 additions & 0 deletions scripts/gate-baselined-paths.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# scripts/gate-baselined-paths.test.sh — gate-baselined.sh refuses a path word that holds a control character (tab, carriage return, newline), as well as the shell operators, and still runs a plain path.
# The probe is paired with a guard: with the control-character test removed from the real script, the probe fails.
# Usage: bash scripts/gate-baselined-paths.test.sh
set -uo pipefail

REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
SRC="$REPO_ROOT/skills/scaffold/shared/template/scripts/gate-baselined.sh"

PASS=0
FAIL=0
check() { if [[ "$1" == "$2" ]]; then PASS=$((PASS + 1)); else FAIL=$((FAIL + 1)); echo "FAIL: $3 — expected [$1], got [$2]"; fi; }

T=$(mktemp -d "${TMPDIR:-/tmp}/gbp.XXXXXX") || exit 2
trap 'rm -rf "$T"' EXIT
mkdir -p "$T/scripts" "$T/.claude"
printf '#!/usr/bin/env bash\necho ran\n' > "$T/scripts/check-docs.sh"

# gate <script> <path word>: runs the docs gate with one path word in a project with no baseline; sets OUT and RC.
gate() {
OUT=$(cd "$T" && bash "$1" docs -- bash scripts/check-docs.sh --raw "$2" 2>&1)
RC=$?
}

cp "$SRC" "$T/scripts/gate-baselined.sh"
gate "$T/scripts/gate-baselined.sh" "docs/plain.md"
check 0 "$RC" "plain path: runs ($OUT)"
for name in tab cr lf; do
case "$name" in
tab) w=$(printf 'a\tb') ;;
cr) w=$(printf 'a\rb') ;;
lf) w=$(printf 'a\nb') ;;
esac
gate "$T/scripts/gate-baselined.sh" "$w"
check 2 "$RC" "control char [$name]: refused with exit 2 ($OUT)"
check 1 "$(printf '%s' "$OUT" | grep -c 'not a plain path')" "control char [$name]: names the cause"
done

# guard: without the control-character test, tab and carriage return get through
sed 's/|\*\[\[:cntrl:\]\]\*) return 1/) return 1/' "$SRC" > "$T/scripts/gate-baselined.sh"
if cmp -s "$SRC" "$T/scripts/gate-baselined.sh"; then same=0; else same=1; fi
check 1 "$same" "guard: the mutation changed the script"
gate "$T/scripts/gate-baselined.sh" "$(printf 'a\tb')"
check 0 "$RC" "guard: tab path runs when the test is removed ($OUT)"

echo "gate-baselined-paths: $PASS passed, $FAIL failed"
[ "$FAIL" -eq 0 ]
82 changes: 72 additions & 10 deletions scripts/gate-budget.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,38 @@ check() { if [[ "$1" == "$2" ]]; then ok; else bad "$3: expected [$1], got [$2]"
has() { if [[ "$2" == *"$1"* ]]; then ok; else bad "$3: [$1] not in [$2]"; fi; }

T=$(mktemp -d "${TMPDIR:-/tmp}/gbt.XXXXXX") || exit 2
trap 'rm -rf "$T"' EXIT
# Every process the test starts in the background is listed in $T/tracked.pids (one pid per line, a group leader's pid for a launched group). The exit trap reaps whatever is left, children first, then removes the folder.
TRACKED="$T/tracked.pids"
: > "$TRACKED"
track() { echo "$1" >> "$TRACKED"; }
# kill_tree <pid>: kills every descendant of a process (children first, found before anything dies), the process itself, and its group when it leads one.
kill_tree() {
local c
for c in $(pgrep -P "$1" 2>/dev/null); do kill_tree "$c"; done
kill -9 -- "-$1" 2>/dev/null
kill -9 "$1" 2>/dev/null
return 0
}
# survivors: prints the tracked pids that are still alive.
survivors() {
local pid
while IFS= read -r pid; do
case "$pid" in '' | *[!0-9]*) continue ;; esac
if kill -0 "$pid" 2>/dev/null; then echo "$pid"; fi
done < "$TRACKED"
}
reap_all() {
local pid f
exec 7>&- 2>/dev/null
for f in "$T"/p*/wpid "$T"/p*/pids/gate "$T"/p*/pids/gc; do
[ -f "$f" ] && track "$(cat "$f" 2>/dev/null)"
done
while IFS= read -r pid; do
case "$pid" in '' | *[!0-9]*) continue ;; esac
kill_tree "$pid"
done < "$TRACKED"
}
trap 'reap_all; rm -rf "$T"' EXIT

N=0
# newproj: a project folder P with the budget files and the runner.
Expand Down Expand Up @@ -121,15 +152,41 @@ probe_session_multiline() { rec deps 700; hookrun $'{\n"session_id"\n:"m1",\n"se
probe_hook_error_throttled() { conf total_budget_seconds=abc per_gate_budget_seconds=180 regression_percent=25 runs_kept=20; rec_ok; local a b c; a=$(hookrun '{"session_id":"e-1"}'); local ra=$?; b=$(hookrun '{"session_id":"e-1"}'); c=$(hookrun '{"session_id":"e-2"}'); [ "$ra" = 0 ] && [[ "$a" == *"whole number"* ]] && [ -z "$b" ] && [[ "$c" == *"whole number"* ]]; }
probe_hook_broken_exit() { conf total_budget_seconds=abc per_gate_budget_seconds=180 regression_percent=25 runs_kept=20; rec_ok; (cd "$P" && echo '{}' | bash .claude/gate-budget.sh hook >/dev/null 2>&1); local a=$?; (cd "$P" && echo '{}' | CLAUDE_PROJECT_DIR="$P" bash .claude/session-context.sh >/dev/null 2>&1); local b=$?; [ "$a" = 0 ] && [ "$b" = 0 ]; }
probe_seen_dir() { rec deps 700; mkdir "$P/.claude/gate-budget.seen"; local a; a=$(hookrun '{"session_id":"d-1"}'); [[ "$a" == *"directory or symlink"* ]] && [[ "$a" == *"over budget"* ]] && [ -z "$(find "$P/.claude/gate-budget.seen" -type f)" ]; }
# hook_bg <ceiling-steps> <stdin-spec>...: runs the hook as the process itself (exec), so the tracked pid is the hook, with the given redirections; waits in 0.2 second steps for it to end by itself. Returns 1 when it is still alive (and reaps it with its children). Sets HRC.
hook_bg() {
local steps=$1 pid i=0 out="$P/hook.out"
shift
(cd "$P" && eval "exec bash .claude/gate-budget.sh hook $* > \"\$out\" 2>&1") & pid=$!
track "$pid"
while kill -0 "$pid" 2>/dev/null && [ "$i" -lt "$steps" ]; do sleep 0.2; i=$((i + 1)); done
if kill -0 "$pid" 2>/dev/null; then kill_tree "$pid"; wait "$pid" 2>/dev/null; return 1; fi
wait "$pid"; HRC=$?
return 0
}
# A closed stdin must neither hang nor fail: the hook runs in the background and is killed after about 3 seconds if it is still there.
probe_closed_stdin() {
rec deps 700
local pid i=0 out="$P/hook.out"
(cd "$P" && bash .claude/gate-budget.sh hook <&- > "$out" 2>&1) & pid=$!
while kill -0 "$pid" 2>/dev/null && [ "$i" -lt 15 ]; do sleep 0.2; i=$((i + 1)); done
if kill -0 "$pid" 2>/dev/null; then kill -9 "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; return 1; fi
wait "$pid"; local rc=$?
[ "$rc" = 0 ] && grep -q "over budget" "$out"
hook_bg 15 '<&-' || return 1
[ "$HRC" = 0 ] && grep -q "over budget" "$P/hook.out"
}
# A stdin that never closes must not keep the hook alive: it gives up on the input after its bounded wait and still prints the note.
probe_open_stdin() {
rec deps 700
mkfifo "$P/in" || return 1
exec 7<>"$P/in"
hook_bg 40 "<\"$P/in\""; local r=$?
exec 7>&-
[ "$r" = 0 ] && [ "$HRC" = 0 ] && grep -q "over budget" "$P/hook.out"
}
# The detector for a leftover child: a process started and tracked is seen as a survivor, then reaped.
probe_survivor_detected() {
local before after pid
sleep 30 >/dev/null 2>&1 & pid=$!
track "$pid"
before=$(survivors | grep -c "^$pid$")
kill_tree "$pid"; wait "$pid" 2>/dev/null
after=$(survivors | grep -c "^$pid$")
[ "$before" = 1 ] && [ "$after" = 0 ]
}
probe_conf_symlink() { printf '%s\n' total_budget_seconds=600 per_gate_budget_seconds=180 regression_percent=25 runs_kept=20 > "$P/real.conf"; rm -f "$P/.claude/gate-budget.conf"; ln -s ../real.conf "$P/.claude/gate-budget.conf"; rec_ok; chk; [ "$RC" = 2 ] && [[ "$OUT" == *"not a regular file"* ]]; }
probe_conf_zero() { conf total_budget_seconds=0600 per_gate_budget_seconds=180 regression_percent=25 runs_kept=20; rec_ok; chk; [ "$RC" = 2 ] && [[ "$OUT" == *"whole number"* ]]; }
Expand Down Expand Up @@ -280,7 +337,7 @@ probe_hook_signal_exit() {
rm -rf "$P/status" "$P/wpid"
# A copy of the script that writes a marker once its traps are set, so the signal never lands early.
rm -f "$P/ready"
awk '/^ input=/ { print " echo up > ready" } { print }' "$P/.claude/gate-budget.sh" > "$P/.claude/gate-budget-ready.sh"
awk '/^ IFS= read -r -t 5 / { print " echo up > ready" } { print }' "$P/.claude/gate-budget.sh" > "$P/.claude/gate-budget-ready.sh"
if ! grep -q 'echo up > ready' "$P/.claude/gate-budget-ready.sh"; then note "could not add the ready marker"; return 1; fi
LSTDIN=1 perl "$T/launch.pl" "$P" bash .claude/gate-budget-ready.sh hook >/dev/null 2>&1 </dev/null &
await "$P/wpid" || return 1
Expand Down Expand Up @@ -407,7 +464,7 @@ for p in probe_clean probe_over_total probe_over_gate probe_regression probe_wit
probe_symlink_record probe_dir_record probe_conf_text probe_conf_negative probe_conf_huge probe_conf_unknown probe_conf_missing_key probe_conf_missing_file probe_conf_duplicate \
probe_once_per_session probe_hook_quiet probe_note_short probe_session_hook probe_runner_status probe_runner_list \
probe_unlisted_row probe_unlisted_dropped probe_gates_missing probe_session_first probe_session_long probe_session_multiline probe_hook_error_throttled probe_hook_broken_exit probe_seen_dir \
probe_closed_stdin probe_conf_symlink probe_conf_zero probe_conf_crlf probe_runner_missing_budget probe_runner_record_fails probe_runner_codes probe_sig_matrix probe_unreadable_record probe_name_len probe_hook_script_missing probe_hook_script_crash probe_hook_signal_exit probe_ignore_patterns; do
probe_closed_stdin probe_open_stdin probe_survivor_detected probe_conf_symlink probe_conf_zero probe_conf_crlf probe_runner_missing_budget probe_runner_record_fails probe_runner_codes probe_sig_matrix probe_unreadable_record probe_name_len probe_hook_script_missing probe_hook_script_crash probe_hook_signal_exit probe_ignore_patterns; do
plain newproj "$p"
done
for p in probe_ratchet_raise probe_ratchet_delete probe_ratchet_lower probe_ratchet_gate_removed probe_ratchet_script probe_ratchet_raise_per probe_ratchet_raise_pct probe_protect_conf probe_protect_script; do
Expand Down Expand Up @@ -443,7 +500,8 @@ guard newproj probe_hook_broken_exit .claude/gate-budget.sh 's/^ exit 0$/ exit
guard newproj probe_session_multiline .claude/gate-budget.sh "s/tr '[^']*' '[^']*' | //" "session id reads one line"
guard newproj probe_hook_error_throttled .claude/gate-budget.sh "s/hook_print err \"[\$]sid\" \"[\$]out\" ;;/echo \"${D}out\" ;;/" "broken-config error shown once per session"
guard newproj probe_seen_dir .claude/gate-budget.sh 's/if \[ -d "[$]seen" \] || \[ -L "[$]seen" \]; then/if false; then/' "marker directory reported"
guard newproj probe_closed_stdin .claude/gate-budget.sh '/-p \/dev\/stdin/d' "closed stdin does not hang the hook"
guard newproj probe_closed_stdin .claude/gate-budget.sh "s/^ IFS= read -r -t 5 -d '' input.*$/ input=${D}(cat)/" "closed stdin does not hang the hook"
guard newproj probe_open_stdin .claude/gate-budget.sh "s/^ IFS= read -r -t 5 -d '' input.*$/ input=${D}(cat)/" "an open stdin does not hold the hook"
guard newproj probe_conf_symlink .claude/gate-budget.sh 's/if \[ -L "[$]conf" \] || /if /' "symlinked config rejected"
guard newproj probe_conf_zero .claude/gate-budget.sh 's/ | 0?\*)/)/' "leading zero rejected"
guard newproj probe_conf_crlf .claude/gate-budget.sh 's/ | \*\[!0-9\]\*//' "non-digit config value rejected"
Expand All @@ -466,5 +524,9 @@ fi
pguard probe_protect_script 's/\.claude\/gate-budget\.sh|\*\/\.claude\/gate-budget\.sh|//' "protect-files asks about the budget script"
guard newproj probe_ignore_patterns .gitignore '/gate-budget\.??????/d' "temp files git-ignored"

# No child may outlive the probes: everything the test started and tracked has ended by itself or was reaped by its probe.
left=$(survivors | tr '\n' ' ')
check "" "$left" "tracked processes still alive after the probes"

echo "gate-budget.test.sh: $PASS passed, $FAIL failed"
[ "$FAIL" -eq 0 ]
18 changes: 17 additions & 1 deletion scripts/harness-live.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ seed "$T/sv-dep"; tpl_pkg vite-react "$T/sv-dep"; set_pkg "$T/sv-dep" drop-dep
out=$(run "$T/sv-dep"); check "vitest coverage without the provider: exits 1" 1 $?
contains "missing provider: names the install" "FAIL coverage provider: test:ci runs vitest --coverage but @vitest/coverage-v8 is not declared in dependencies, devDependencies or optionalDependencies, so the first push stops. Fix: pnpm add -D @vitest/coverage-v8" "$out"
seed "$T/sv-jest"; tpl_pkg vite-react "$T/sv-jest"; set_pkg "$T/sv-jest" test:ci 'jest --coverage'; set_pkg "$T/sv-jest" drop-dep
printf 'module.exports = { coverageThreshold: { global: { lines: 80 } } };\n' >"$T/sv-jest/jest.config.js"
mkdir -p "$T/sv-jest/node_modules/.bin"; printf '#!/bin/sh\nexit 0\n' >"$T/sv-jest/node_modules/.bin/prettier"; chmod +x "$T/sv-jest/node_modules/.bin/prettier"; cx_stub "$T/sv-jest" ts
out=$(run "$T/sv-jest"); check "control, jest with --coverage needs no provider: exits 0" 0 $?
seed "$T/sv-bad"; printf '{ not json' >"$T/sv-bad/package.json"
Expand Down Expand Up @@ -698,7 +699,22 @@ svx_refused 'test:ci mocha as the primary runner' test:ci 'mocha' 'chain the pro
svx_refused 'test:ci node --test as the primary runner' test:ci 'node --test' 'chain the project runner as test:ci:project'
svx_refused "test:ci \$X" test:ci "vitest --run --coverage \$X"
svx vite-react; : >"$T/svx/vitest.config.ts"; set_pkg "$T/svx" test:ci 'vitest --run --coverage --reporter=dot --config vitest.config.ts'; svx_accepted 'control, vitest --config an existing vitest.config.ts' test:ci
svx vite-react; set_pkg "$T/svx" test:ci 'jest --ci --coverage'; set_pkg "$T/svx" drop-dep; svx_accepted 'control, a jest --coverage line' test:ci
svx vite-react; set_pkg "$T/svx" test:ci 'jest --ci --coverage'; set_pkg "$T/svx" drop-dep; printf 'module.exports = { coverageThreshold: { global: { lines: 80 } } };\n' >"$T/svx/jest.config.js"; svx_accepted 'control, a jest --coverage line with a floor in jest.config.js' test:ci
# a jest test:ci line needs a floor the ratchet can read: jest.config.* with coverageThreshold; none, a config without it and a jest key in package.json all fail
svx vite-react; set_pkg "$T/svx" test:ci 'jest --ci --coverage'; set_pkg "$T/svx" drop-dep
out=$(run "$T/svx"); check "jest without any jest.config.*: exits 1" 1 $?
contains "jest without any jest.config.*: names the floor" "FAIL jest coverage floor: test:ci runs jest --coverage but no jest.config.* file at the project root sets coverageThreshold" "$out"
printf 'module.exports = { testEnvironment: "node" };\n' >"$T/svx/jest.config.js"
out=$(run "$T/svx"); check "jest.config.js without coverageThreshold: exits 1" 1 $?
contains "jest.config.js without coverageThreshold: names the floor" "FAIL jest coverage floor" "$out"
printf 'module.exports = { coverageThreshold: { global: { lines: 80 } } };\n' >"$T/svx/jest.config.js"
out=$(run "$T/svx"); check "jest.config.js with coverageThreshold: exits 0" 0 $?
rm -f "$T/svx/jest.config.js"
node -e 'const f=process.argv[1],p=JSON.parse(require("fs").readFileSync(f,"utf8"));p.jest={coverageThreshold:{global:{lines:80}}};require("fs").writeFileSync(f,JSON.stringify(p))' "$T/svx/package.json"
out=$(run "$T/svx"); check "floor only in a jest key of package.json: exits 1" 1 $?
contains "floor only in a jest key of package.json: names the floor" "FAIL jest coverage floor" "$out"
svx vite-react; set_pkg "$T/svx" test:ci 'vitest --run --coverage --reporter=dot'
out=$(run "$T/svx"); case "$out" in *"jest coverage floor"*) echo "FAIL a vitest line is asked for a jest floor"; fail=1 ;; *) echo "ok a vitest line is not asked for a jest floor" ;; esac
# --config only for the names the ratchet's coverage-threshold reader parses (gate-ratchet.sh kind_of and shadow_reason), at the project root
for cfgname in vitest.ci.config.ts vitest.coverage.config.mts jest.config.js jest.config.ts vitest.config.yaml vitest.config.tsx vitest.workspace.ts custom.config.ts; do
svx_refused "test:ci --config $cfgname (a name the ratchet does not read)" test:ci "vitest --run --coverage --reporter=dot --config $cfgname" "not equal in strength"
Expand Down
Loading