fix(effort): five residual LOW on lib/effort-pins.sh

INT/TERM trap removes the mktemp sibling and exits 130 (traps restored,
never EXIT); re-read message honest and reached by a stubbed test; rejected
map line printed through printf %q; suite guards mktemp -d and skips the
read-only case under root. Cases T13b, T15, T15b, T16.
This commit is contained in:
bastien
2026-09-29 16:45:57 +02:00
parent 5f39f01159
commit 0c135a0ab7
5 changed files with 105 additions and 15 deletions
+16 -6
View File
@@ -38,13 +38,22 @@ _effort_pin_closed() {
awk 'NR==1&&/^---$/{p=1;next} p&&/^---$/{f=1;exit} END{exit !f}' "$1"
}
# _effort_pin_traps_restore <saved> — drop the INT/TERM handlers set for the
# write and re-install the caller's saved ones. No exit-time handler here.
_effort_pin_traps_restore() {
trap - INT TERM
[ -z "$1" ] || eval "$1"
}
# _effort_pin_write <skill-file> <name> <level> — replace the frontmatter
# `effort:` line, or insert one after `name: <name>` (before the closing
# `---` when the frontmatter has no name line). Body lines never change.
# Writes a mktemp sibling then renames; any failure leaves no temp behind.
_effort_pin_write() {
local file="$1" name="$2" level="$3" tmp
local file="$1" name="$2" level="$3" tmp prev rc
tmp="$(mktemp "$file.XXXXXX")" || return 1
prev="$(trap -p INT TERM)"
trap 'rm -f "$tmp"; exit 130' INT TERM
cp -p "$file" "$tmp" && awk -v n="$name" -v lvl="$level" '
NR==1 && /^---$/ { fm=1; print; next }
fm && /^---$/ {
@@ -54,9 +63,10 @@ _effort_pin_write() {
fm && /^effort: / { if (!done) { print "effort: " lvl; done=1 }; next }
fm && $0 == "name: " n { print; if (!done) { print "effort: " lvl; done=1 }; next }
{ print }
' "$file" > "$tmp" && mv "$tmp" "$file" && return 0
rm -f "$tmp"
return 1
' "$file" > "$tmp" && mv "$tmp" "$file"; rc=$?
[ "$rc" -eq 0 ] || rm -f "$tmp"
_effort_pin_traps_restore "$prev"
return "$rc"
}
# _effort_pin_apply_one <file> <name> <level> → rc 0 applied, 2 already at
@@ -71,7 +81,7 @@ _effort_pin_apply_one() {
err "effort-pins: $file: write failed"; return 1
fi
if [ "$(_effort_pin_current "$file")" != "$level" ]; then
err "effort-pins: $file: level not applied (CRLF or malformed frontmatter?)"
err "effort-pins: $file: level not applied after write"
return 1
fi
return 0
@@ -87,7 +97,7 @@ apply_effort_pins() {
case "$name" in ''|'#'*) continue ;; esac
if [ -n "$rest" ] || ! [[ "$name" =~ $EFFORT_PIN_NAME_RE ]] \
|| ! [[ "$level" =~ $EFFORT_PIN_LEVEL_RE ]]; then
err "effort-pins: rejected map line '$name $level $rest'"
err "effort-pins: rejected map line $(printf '%q' "$name $level $rest")"
rejected=$((rejected + 1)); continue
fi
file="$repo/skills-external/$name/SKILL.md"