diff --git a/.agents/skills/skill-review/SKILL.md b/.agents/skills/skill-review/SKILL.md index e23e5f6f0..2c1d1f1f7 100644 --- a/.agents/skills/skill-review/SKILL.md +++ b/.agents/skills/skill-review/SKILL.md @@ -15,7 +15,7 @@ path) is the only writer of `~/.claude/skills/`. 1. **List** the staged drafts: ```bash - skill-review list # tab-separated: \t + skill-review list # tab-separated: \t\t ``` If "(no staged drafts)", stop and say so. @@ -39,8 +39,8 @@ path) is the only writer of `~/.claude/skills/`. steps lets the agent follow the summary and skip the body. Start with "Use when ...". 3. **Decide per draft** (always show the user the draft and your read before acting): - - Approve -> `skill-review promote ` (moves it into `~/.claude/skills//`; refuses to - overwrite a live skill without `--force`). + - Approve -> `skill-review promote ` (moves it into `~/.claude/skills//`; refuses + digest mismatch or overwriting a live skill without `--force`). - Reject -> `skill-review reject ` (moves it to `_rejected/`, recoverable, never deleted). 4. **Report** what was promoted vs rejected, and any draft you left staged for the user to decide. diff --git a/docs/reference/FEATURES.md b/docs/reference/FEATURES.md index 19db34a47..b98746856 100644 --- a/docs/reference/FEATURES.md +++ b/docs/reference/FEATURES.md @@ -102,7 +102,7 @@ GENERATED , do not hand-edit. Regenerate: `bash lib/registry/feature-registry.sh | `memory-tidy` | `[I]` | Use when auditing, consolidating, or cleaning a repo's .claude/memory store, "dọn memory", "memory tidy", the biweekly memory audit, dupl… | SPEC-208, SPEC-225, SPEC-249 | test-audit-cadence.sh, test-audit-verdict-grammar.sh, test-memory-tidy-contract.sh +1 | | `observe` | `[I]` | Query and render the kit's control plane (fleet runs, spend, debt; backed by lib/bench) from an agent session. NOT for your own Claude Code… | SPEC-033, SPEC-052, SPEC-128 +17 | smoke.sh, test-bin-forwarders.sh, test-kit-contract.sh +4 | | `repo-hygiene` | `[I]` | Use for the whole-repo decay audit, "run the repo-hygiene loop", "what has rotted in this repo", "is anything mis-shelved", "dọn repo", o… | SPEC-256 | test-audit-cadence.sh, test-audit-verdict-grammar.sh, test-repohygiene.sh | -| `skill-review` | `[I]` | Review and promote skill drafts that skill-curator staged from past sessions. Use when the user runs /skill-review, says "review my skill d… | SPEC-218, SPEC-285 | test-async.sh, test-bin-forwarders.sh, test-egress-visible.sh +7 | +| `skill-review` | `[I]` | Review and promote skill drafts that skill-curator staged from past sessions. Use when the user runs /skill-review, says "review my skill d… | SPEC-218, SPEC-285 | test-async.sh, test-bin-forwarders.sh, test-egress-visible.sh +8 | | `stats` | `[I]` | Query or render ledger state and propose backlog rows off anomalies. Use when asked to SEE it -- "show me the ledger state", "my waived gat… | SPEC-001, SPEC-182, SPEC-192 +24 | test-anomalies-advisor.sh, test-bin-forwarders.sh, test-board-brief.sh +39 | | `system-design` | `[I]` | Own the repo's system design document at docs/SYSTEM-DESIGN.md: its format, its updates per feature, and rendering it as a UML drawing set … | SPEC-292, SPEC-426, SPEC-427 | test-doc-figures.sh, test-system-design.sh | | `topology-drift` | `[I]` | Maintainer-only. Use to audit THIS KIT's OWN feature estate against its path map, "run the topology-drift loop", "feature inventory drift".… | SPEC-225, SPEC-235, SPEC-237 | test-audit-cadence.sh, test-audit-scanner-contract.sh, test-audit-verdict-grammar.sh +1 | diff --git a/docs/verification/skill-promote-reviewed-digest.md b/docs/verification/skill-promote-reviewed-digest.md new file mode 100644 index 000000000..c7dd78e97 --- /dev/null +++ b/docs/verification/skill-promote-reviewed-digest.md @@ -0,0 +1,140 @@ +# Verification: skill-promote-reviewed-digest + +Proof of done for digest-pinned skill promotion (atomic private move out of staging, strict entry classification with mode bit and draft-contained relative symlinks, no inherited-temp recursive delete, no post-promote retire step hiding newer drafts) and safe `curate_restore` (slug validation, live-target refusal with no nesting, and guarded `manifest.tsv` row removal). + +## Green runs + +### Fix round 1 on /bin/bash (3.2.57) and bash 5 (5.3.20), temp HOME + +``` +Command: HOME="$H" /bin/bash lib/skill-curator/tests/test-promote-digest.sh && HOME="$H" /opt/homebrew/bin/bash lib/skill-curator/tests/test-promote-digest.sh +Exit: 0 +Output: + [1] list prints 12-hex digest; added file and symlink target change it + ok: 12-hex digests change on added file and symlink target (b5e281e2a95f -> a438b47fd3f0 -> 0924f274b843 -> 50101cd74165) + [2] re-stage between list and promote is refused (rc=4), nothing moves + ok: re-staged draft refused (rc=4), nothing moved + [3] no digest, --force in digest slot, and wrong digest all refuse (rc=4) + ok: missing/wrong digest refused (rc=4), draft untouched + [4] right digest promotes exact reviewed draft including extra files and symlinks + ok: right digest promoted draft with extra file and symlink intact + [5] --force after digest replaces live skill and backs up previous live copy + ok: --force after digest replaced live skill and backed up old copy + [6] re-stage during promotion (PATH stub) publishes reviewed copy, newer draft stays visible + ok: mid-digest re-stage: live got V1, newer V2 stayed staged and listed + [7] late re-stage during promote (mkdir stub, Fault 2) does not hide newer draft + ok: late re-stage: live got V1, newer V2 not hidden by retire step + [8] re-stage during refused promotion preserves BOTH old and new drafts + ok: refusal during re-stage preserved both V2-REF-NEW and V1-REF-OLD + [9] inherited temp variable does not recursively delete unrelated folder (Fault 1) + ok: inherited temp env left canary folder untouched; no recursive rm in promote.sh + [10] auto mode promotes eligible draft from private copy and preserves concurrent newer draft + ok: auto mode published V1 from private copy, kept newer V2 staged, skipped ineligible + [11] curate_restore refuses over a live skill (rc=5), no nesting, manifest unchanged + ok: restore over live skill refused (rc=5), no nesting, manifest unchanged + [12] normal curate_restore moves archive back and removes only its manifest row + ok: normal restore moved skill back and pruned only its exact manifest row + [13] file with newline in name added after list is refused (rc=4), not installed + ok: newline-named file refused (rc=4), nothing installed + [14] fifo added after list is refused (rc=4), not installed + ok: fifo refused (rc=4), nothing installed + [15] chmod +x after list changes digest and is refused (rc=4), not installed + ok: chmod +x refused (rc=4), nothing installed + [16] absolute symlink target swap after list is refused (rc=4), not installed + ok: absolute symlink refused (rc=4), swapped target not installed + [17] curate_restore refuses traversal, slash, empty, and leading-dash slugs + ok: curate_restore refused invalid slugs (rc=2), live skill stayed inside skills/ + test-promote-digest: all 17 passed (identical on /bin/bash 3.2.57 and bash 5.3.20) +Verdict: PASS +``` + +``` +Command: HOME="$H" /bin/bash lib/skill-curator/tests/test-promote.sh && HOME="$H" /bin/bash lib/skill-curator/tests/test-curate.sh && HOME="$H" /opt/homebrew/bin/bash lib/skill-curator/tests/test-promote.sh && HOME="$H" /opt/homebrew/bin/bash lib/skill-curator/tests/test-curate.sh +Exit: 0 +Output: + test-promote: all 11 passed (/bin/bash 3.2.57 and bash 5.3.20) + test-curate: all 11 passed (/bin/bash 3.2.57 and bash 5.3.20) +Verdict: PASS +``` + +``` +Command: HOME="$H" tests/run-all.sh --changed e75b5b2d --time (bash 5.3.20) and --changed origin/master --time (/bin/bash 3.2.57) +Exit: 0 (all 12 lib-skill-curator suites, test-meta-docs-registry 123/123, test-no-personal-paths 3/3, test-no-scattered-ids 9/9, test-skills-root, test-kit-contract, and 51/52 suites pass in run-all on bash 5.3.20; test-flick timed out under host load 385 in run-all and passed standalone 346/346 on both bash 5.3.20 and /bin/bash 3.2.57; test-board-registry-env 13/13 and test-repohygiene 100/100 are pre-existing bash-4+ suites that pass on bash 5.3.20) +Output: + lib-skill-curator-test-async ok + lib-skill-curator-test-curate ok + lib-skill-curator-test-hook-async ok + lib-skill-curator-test-install ok + lib-skill-curator-test-promote-digest ok + lib-skill-curator-test-promote ok + lib-skill-curator-test-reentrancy ok + lib-skill-curator-test-reviewer ok + lib-skill-curator-test-signal-gate ok + lib-skill-curator-test-staging-gate ok + lib-skill-curator-test-surface ok + lib-skill-curator-test-transcript-parse ok + test-meta-docs-registry ok + flick: 346 passed, 0 failed (/bin/bash 3.2.57 and bash 5.3.20) +Verdict: PASS +``` + +## Negative controls + +### Baseline on origin/master (before initial fix) + +``` +Command: bash lib/skill-curator/tests/test-promote-digest.sh +Exit: 1 +Output: + FAIL: digest sensitivity failed: d1='first draft' d2='first draft' d3='first draft' d4='first draft' + FAIL: re-stage not refused cleanly (rc=0, live=beta) + FAIL: bad-digest refusal wrong (none=2 flag=2 wrong=2) + FAIL: --force behavior wrong (noforce=4 force=4) + FAIL: mid-digest re-stage failed (rc=0, list='alpha replacement') + FAIL: late re-stage hid or lost newer draft (rc=0, list='alpha replacement') + FAIL: refusal during re-stage lost a draft (rc=0) + FAIL: auto mode wrong (rc=0) + FAIL: restore over live skill failed (rc=0, nested=live-one + FAIL: normal restore wrong (rc=0, manifest='live-one 2026-01-01T00:00:00+0000 umb + test-promote-digest: 2 passed, 10 FAILED +Verdict: RED +``` + +### Fix round 1 red-first run (before digest-else and curate_restore slug fixes) + +``` +Command: HOME="$H" /bin/bash lib/skill-curator/tests/test-promote-digest.sh && HOME="$H" /opt/homebrew/bin/bash lib/skill-curator/tests/test-promote-digest.sh +Exit: 1 +Output: + FAIL: newline-named file bypassed digest (rc=0) + FAIL: fifo bypassed digest (rc=0) + FAIL: chmod +x bypassed digest (rc=0) + FAIL: absolute symlink bypassed digest (rc=0, dig='cd5d134b11a1') + FAIL: curate_restore accepted an invalid slug or moved live skill out + test-promote-digest: 12 passed, 5 FAILED +Verdict: RED +``` + +### Planted faults on a temp sandbox copy of the fixed code + +| Fault | Mutation | Exit | Failing cases | +|---|---|---|---| +| A | Disable digest comparison in `promote.sh` | 1 | `test-promote-digest: 9 passed, 3 FAILED` (re-stage, wrong digest, refusal re-stage) | +| B | Remove live-exists guard in `curate_restore` | 1 | `test-promote-digest: 10 passed, 2 FAILED` (restore over live skill nested, manifest drift) | +| C | Re-introduce inherited `_PTMP` removal in `promote_one` | 1 | `test-promote-digest: 11 passed, 1 FAILED` (canary folder deleted) | +| D | Re-introduce post-promote retire move of `$staged` | 1 | `test-promote-digest: 10 passed, 2 FAILED` (mid-digest and late re-stage hid newer draft) | + +``` +Command: planted-fault sandbox runs A, B, C, D against lib/skill-curator/tests/test-promote-digest.sh +Exit: 1 +Output: + Fault A: test-promote-digest: 9 passed, 3 FAILED + Fault B: test-promote-digest: 10 passed, 2 FAILED + Fault C: test-promote-digest: 11 passed, 1 FAILED + Fault D: test-promote-digest: 10 passed, 2 FAILED +Verdict: RED +``` + +## Rollback + +Revert the commits on this branch (`git revert `). No data migration, hook change, or live skill mutation occurs; staged drafts remain under `skill-proposals/` and archived skills under `skills/_archive/`. diff --git a/lib/skill-curator/README.md b/lib/skill-curator/README.md index 1b5d71362..5aa25d6c3 100644 --- a/lib/skill-curator/README.md +++ b/lib/skill-curator/README.md @@ -67,16 +67,16 @@ settings.json. After a session stages drafts, inspect status and review them: ```bash -bin/skill-improve status # staged-draft count + reviewer runs + 7-day loop spend -bin/skill-review list # one line per draft: \t -bin/skill-review promote # vet (writing-skills) then move into ~/.claude/skills// -bin/skill-review promote --force # replace an existing live skill (backs old copy to _replaced/) -bin/skill-review reject # move to skill-proposals/_rejected// (recoverable) +bin/skill-improve status # staged-draft count + reviewer runs + 7-day loop spend +bin/skill-review list # one line per draft: \t\t +bin/skill-review promote # vet (writing-skills) then move into ~/.claude/skills// +bin/skill-review promote --force # replace an existing live skill (backs old copy to _replaced/) +bin/skill-review reject # move to skill-proposals/_rejected// (recoverable) ``` Or run `/skill-review` (the skill) for the guided, vet-each-draft flow. -Promote exit codes: `2` no such draft, `3` secret-shaped string found (scrub it first), `4` live skill already exists (re-run with `--force` after reading the live skill), `5` move/mkdir failure. +Promote exit codes: `2` no such draft, `3` secret-shaped string found (scrub it first), `4` missing/mismatched digest or live skill already exists (re-run with `--force` after reading the live skill), `5` move/mkdir failure. **Gotchas:** - `deploy/install.sh` aborts if `settings.json` is invalid JSON, after backing it up to `settings.json.bak-`. The reviewer only fires on a real session end or compaction, so `status` stays empty until a substantial session finishes. diff --git a/lib/skill-curator/bin/skill-review b/lib/skill-curator/bin/skill-review index a3f30c459..55100943e 100755 --- a/lib/skill-curator/bin/skill-review +++ b/lib/skill-curator/bin/skill-review @@ -11,8 +11,8 @@ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" case "${1:-list}" in list) promote_list ;; - promote) promote_one "${2:-}" "${3:-}" ;; + promote) promote_one "${2:-}" "${3:-}" "${4:-}" ;; reject) promote_reject "${2:-}" ;; auto) promote_auto ;; - *) echo "usage: skill-review {list|promote [--force]|reject |auto}" >&2; exit 2 ;; + *) echo "usage: skill-review {list|promote [--force]|reject |auto}" >&2; exit 2 ;; esac diff --git a/lib/skill-curator/lib/curate.sh b/lib/skill-curator/lib/curate.sh index 82e17d597..ea172de62 100755 --- a/lib/skill-curator/lib/curate.sh +++ b/lib/skill-curator/lib/curate.sh @@ -108,12 +108,18 @@ curate_run() { # curate_restore : reverse an archive (git mv back, or mv on a non-git host). curate_restore() { local name="${1:-}"; [ -n "$name" ] || { echo "restore: need a skill name" >&2; return 2; } + case "$name" in .*|-*|*/*) echo "restore: invalid skill name '$name'" >&2; return 2 ;; esac local arc="$SKILL_CURATOR_SKILLS_DIR/_archive/$name" [ -d "$arc" ] || { echo "restore: '$name' is not in _archive/" >&2; return 2; } + local dest="$SKILL_CURATOR_SKILLS_DIR/$name" mf="$SKILL_CURATOR_SKILLS_DIR/_archive/manifest.tsv" kept + [ ! -e "$dest" ] && [ ! -L "$dest" ] || { echo "restore: REFUSED, live skill '$name' already exists" >&2; return 5; } if git -C "$SKILL_CURATOR_SKILLS_DIR" rev-parse --git-dir >/dev/null 2>&1; then git -C "$SKILL_CURATOR_SKILLS_DIR" mv "_archive/$name" "$name" 2>/dev/null || mv "$arc" "$SKILL_CURATOR_SKILLS_DIR/$name" 2>/dev/null || { echo "restore: move failed" >&2; return 5; } else mv "$arc" "$SKILL_CURATOR_SKILLS_DIR/$name" 2>/dev/null || { echo "restore: move failed" >&2; return 5; } fi + if [ -f "$mf" ] && kept="$(NAME="$name" awk -F'\t' '($1 "") != (ENVIRON["NAME"] "")' "$mf" 2>/dev/null)"; then + printf '%s' "${kept:+$kept$'\n'}" > "$mf" + fi echo "restore: '$name' <- _archive/"; si_log "curate: restored '$name' from _archive/" } diff --git a/lib/skill-curator/lib/promote.sh b/lib/skill-curator/lib/promote.sh index 73534f331..334d58e34 100755 --- a/lib/skill-curator/lib/promote.sh +++ b/lib/skill-curator/lib/promote.sh @@ -19,7 +19,7 @@ _is_reserved() { case "$1" in _rejected|_replaced|_archive) return 0;; *) return # A slug names exactly one draft dir: not empty, not reserved, no path separator, not . or .. _valid_slug() { - case "$1" in ""|.|..|*/*) return 1;; esac + case "$1" in ""|.*|*/*) return 1;; esac _is_reserved "$1" && return 1 return 0 } @@ -29,25 +29,55 @@ _desc_of() { # read `description:` from a SKILL.md frontmatter, else "" sed -n 's/^description:[[:space:]]*//p' "$f" | head -1 } +_sha() { if command -v sha256sum >/dev/null 2>&1; then sha256sum; else shasum -a 256; fi | cut -c1-64; } +_draft_digest() { + [ -d "$1" ] || return 1 + ( cd "$1" || exit 1; local p h + LC_ALL=C find . -mindepth 1 | LC_ALL=C sort | while IFS= read -r p; do + case "$p" in ./*) ;; *) exit 1;; esac + if [ -L "$p" ]; then h="$(readlink "$p")"; case "$h" in /*|*..*) exit 1;; esac; printf 'L\t%s\t%s\n' "$p" "$h" + elif [ -f "$p" ]; then h="$(_sha < "$p")" && [ "${#h}" -eq 64 ] || exit 1; [ -x "$p" ] && h="x$h"; printf 'F\t%s\t%s\n' "$p" "$h" + elif [ -d "$p" ]; then printf 'D\t%s\n' "$p"; else exit 1; fi + done ) | _sha | cut -c1-12 +} +_put_back() { + local priv="$1" src="$2" hold="$3" slug="$4" base alt n=1 + if [ ! -e "$src" ] && [ ! -L "$src" ]; then mv "$priv" "$src" 2>/dev/null || true + else base="$SKILL_CURATOR_PROPOSALS_DIR/${slug}-prior-$(date +%Y%m%d-%H%M%S)"; alt="$base" + while [ -e "$alt" ] || [ -L "$alt" ]; do alt="${base}-$((n++))"; done; mv "$priv" "$alt" 2>/dev/null || true; fi + rmdir "$hold" 2>/dev/null || true +} + promote_list() { [ -d "$SKILL_CURATOR_PROPOSALS_DIR" ] || { echo "(no staged drafts)"; return 0; } local found=0 d slug for d in "$SKILL_CURATOR_PROPOSALS_DIR"/*/; do - [ -d "$d" ] || continue + d="${d%/}"; [ ! -L "$d" ] && [ -d "$d" ] || continue slug="$(basename "$d")"; _is_reserved "$slug" && continue [ -f "$d/SKILL.md" ] || continue found=1 - printf '%s\t%s\n' "$slug" "$(_desc_of "$d/SKILL.md")" + printf '%s\t%s\t%s\n' "$slug" "$(_draft_digest "$d" || echo unreadable)" "$(_desc_of "$d/SKILL.md")" done [ "$found" = 1 ] || echo "(no staged drafts)" } promote_one() { - local slug="${1:-}" force=0; [ "${2:-}" = "--force" ] && force=1 + local slug="${1:-}" want="${2:-}" force=0 rc=0; [ "${3:-}" = "--force" ] && force=1 [ -n "$slug" ] || { echo "promote: need a slug" >&2; return 2; } _valid_slug "$slug" || { echo "promote: invalid slug '$slug'" >&2; return 2; } - local src="$SKILL_CURATOR_PROPOSALS_DIR/$slug" dest="$SKILL_CURATOR_SKILLS_DIR/$slug" - [ -d "$src" ] && [ -f "$src/SKILL.md" ] || { echo "promote: no draft '$slug'" >&2; return 2; } + case "$want" in ""|--force|*[!0-9a-f]*) echo "promote: REFUSED '$slug', digest required" >&2; return 4 ;; esac + local staged="$SKILL_CURATOR_PROPOSALS_DIR/$slug" dest="$SKILL_CURATOR_SKILLS_DIR/$slug" hold="" src="" + [ ! -L "$staged" ] && [ -d "$staged" ] && [ -f "$staged/SKILL.md" ] || { echo "promote: no draft '$slug'" >&2; return 2; } + hold="$(mktemp -d "$SKILL_CURATOR_PROPOSALS_DIR/.promote.XXXXXX" 2>/dev/null)" || { echo "promote: move failed" >&2; return 5; } + src="$hold/$slug"; mv "$staged" "$src" 2>/dev/null || { rmdir "$hold" 2>/dev/null || true; echo "promote: move failed" >&2; return 5; } + _promote_checked "$slug" "$want" "$force" "$src" "$dest" || rc=$? + if [ "$rc" -ne 0 ] && [ -d "$src" ]; then _put_back "$src" "$staged" "$hold" "$slug"; else rmdir "$hold" 2>/dev/null || true; fi + return "$rc" +} +_promote_checked() { + local slug="$1" want="$2" force="$3" src="$4" dest="$5" got="" + got="$(_draft_digest "$src")" || got="" + if [ "${#want}" -ne 12 ] || [ "$got" != "$want" ]; then echo "promote: REFUSED '$slug', digest mismatch" >&2; return 4; fi if contains_secret "$(cat "$src/SKILL.md" 2>/dev/null)"; then echo "promote: REFUSED '$slug' , SKILL.md contains a secret-shaped string; scrub it first" >&2 @@ -92,14 +122,14 @@ promote_reject() { # SKILL.md-body edit. 02's reviewer does not emit this yet; the predicate is the safe gate for when # it does. auto_promote_eligible() { - local slug="${1:-}" f="$SKILL_CURATOR_PROPOSALS_DIR/${1:-}/SKILL.md" + local slug="${1:-}" f="${2:-$SKILL_CURATOR_PROPOSALS_DIR/${1:-}}/SKILL.md" [ -f "$f" ] || return 1 local kind umb path kind="$(sed -n 's/^cc-si-kind:[[:space:]]*//p' "$f" | head -1)" umb="$(sed -n 's/^cc-si-umbrella:[[:space:]]*//p' "$f" | head -1)" path="$(sed -n 's/^cc-si-path:[[:space:]]*//p' "$f" | head -1)" [ "$kind" = "references-add" ] || return 1 - [ -n "$umb" ] && [ -d "$SKILL_CURATOR_SKILLS_DIR/$umb" ] || return 1 # umbrella must already exist + _valid_slug "$umb" && [ -d "$SKILL_CURATOR_SKILLS_DIR/$umb" ] || return 1 # umbrella must already exist case "$path" in references/*.md) : ;; *) return 1;; esac # references-only, no traversal case "$path" in *..*) return 1;; esac contains_secret "$(cat "$f" 2>/dev/null)" && return 1 @@ -108,16 +138,21 @@ auto_promote_eligible() { promote_auto() { [ "$(cfg auto_promote false)" = "true" ] || { echo "auto-promote: disabled (auto_promote=false)"; return 0; } - local d slug umb path n=0 - for d in "$SKILL_CURATOR_PROPOSALS_DIR"/*/; do - [ -d "$d" ] || continue; slug="$(basename "$d")"; _is_reserved "$slug" && continue - auto_promote_eligible "$slug" || continue + local staged d slug umb path hold="" dig="" n=0 + for staged in "$SKILL_CURATOR_PROPOSALS_DIR"/*/; do + staged="${staged%/}"; [ ! -L "$staged" ] && [ -d "$staged" ] && [ -f "$staged/SKILL.md" ] || continue + slug="$(basename "$staged")"; _is_reserved "$slug" && continue + hold="$(mktemp -d "$SKILL_CURATOR_PROPOSALS_DIR/.promote.XXXXXX" 2>/dev/null)" || continue + d="$hold/$slug"; mv "$staged" "$d" 2>/dev/null || { rmdir "$hold" 2>/dev/null || true; continue; } + if ! auto_promote_eligible "$slug" "$d" || ! dig="$(_draft_digest "$d")"; then _put_back "$d" "$staged" "$hold" "$slug"; continue; fi umb="$(sed -n 's/^cc-si-umbrella:[[:space:]]*//p' "$d/SKILL.md" | head -1)" path="$(sed -n 's/^cc-si-path:[[:space:]]*//p' "$d/SKILL.md" | head -1)" - mkdir -p "$SKILL_CURATOR_SKILLS_DIR/$umb/$(dirname "$path")" 2>/dev/null || continue - cp "$d/SKILL.md" "$SKILL_CURATOR_SKILLS_DIR/$umb/$path" 2>/dev/null && { - promote_reject "$slug" >/dev/null # clear the draft once absorbed - echo "auto-promote: $slug -> skills/$umb/$path"; si_log "auto-promote: $slug -> $umb/$path"; n=$((n+1)); } + mkdir -p "$SKILL_CURATOR_SKILLS_DIR/$umb/$(dirname "$path")" 2>/dev/null || { _put_back "$d" "$staged" "$hold" "$slug"; continue; } + if cp "$d/SKILL.md" "$SKILL_CURATOR_SKILLS_DIR/$umb/$path" 2>/dev/null; then + mkdir -p "$SKILL_CURATOR_PROPOSALS_DIR/_rejected" 2>/dev/null || true + mv "$d" "$SKILL_CURATOR_PROPOSALS_DIR/_rejected/${slug}-$(date +%Y%m%d-%H%M%S)-$$" 2>/dev/null || true; rmdir "$hold" 2>/dev/null || true + echo "auto-promote: $slug -> skills/$umb/$path"; si_log "auto-promote: $slug ($dig) -> $umb/$path"; n=$((n+1)) + else _put_back "$d" "$staged" "$hold" "$slug"; fi done echo "auto-promote: $n promoted" } diff --git a/lib/skill-curator/tests/test-promote-digest.sh b/lib/skill-curator/tests/test-promote-digest.sh new file mode 100755 index 000000000..7da889fa3 --- /dev/null +++ b/lib/skill-curator/tests/test-promote-digest.sh @@ -0,0 +1,352 @@ +#!/usr/bin/env bash +# D18: digest-pinned promote (atomic private move, no inherited-temp rm -rf, +# no retire step hiding newer drafts) and safe curate_restore (no nesting, +# manifest cleanup). Runs entirely in a temp HOME sandbox. +set -uo pipefail +DIR="$(cd "$(dirname "$0")/.." && pwd)" +CLI="$DIR/bin/skill-review" +IMPROVE="$DIR/bin/skill-improve" +TMP="$(mktemp -d "${TMPDIR:-/tmp}/kit.XXXXXX")" || exit 1 +trap 'rm -rf "$TMP"' EXIT + +export HOME="$TMP/home" +mkdir -p "$HOME/.claude/skills" +export SKILL_CURATOR_STATE_DIR="$TMP/state" +export SKILL_CURATOR_PROPOSALS_DIR="$TMP/proposals" +export SKILL_CURATOR_SKILLS_DIR="$TMP/skills" + +pass=0; fail=0 +ok() { echo " ok: $*"; pass=$((pass + 1)); } +no() { echo " FAIL: $*" >&2; fail=$((fail + 1)); } + +mkdraft() { + mkdir -p "$SKILL_CURATOR_PROPOSALS_DIR/$1" + printf '%s\n' "$2" > "$SKILL_CURATOR_PROPOSALS_DIR/$1/SKILL.md" +} +dig_of() { + "$CLI" list | awk -F'\t' -v s="$1" '$1 == s { print $2; exit }' +} +is_hex12() { + [[ "$1" =~ ^[0-9a-f]{12}$ ]] +} + +REAL_SHASUM="$(command -v shasum 2>/dev/null || true)" +REAL_SHA256="$(command -v sha256sum 2>/dev/null || true)" +REAL_MKDIR="$(command -v mkdir)" + +echo "[1] list prints 12-hex digest; added file and symlink target change it" +mkdraft alpha "$(printf -- '---\nname: alpha\ndescription: first draft\n---\n# alpha v1')" +d1="$(dig_of alpha)" +mkdir -p "$SKILL_CURATOR_PROPOSALS_DIR/alpha/references" +printf 'extra bytes\n' > "$SKILL_CURATOR_PROPOSALS_DIR/alpha/references/extra.md" +d2="$(dig_of alpha)" +ln -s target-a "$SKILL_CURATOR_PROPOSALS_DIR/alpha/ref-link" +d3="$(dig_of alpha)" +ln -sfn target-b "$SKILL_CURATOR_PROPOSALS_DIR/alpha/ref-link" +d4="$(dig_of alpha)" +if is_hex12 "$d1" && is_hex12 "$d2" && is_hex12 "$d3" && is_hex12 "$d4" \ + && [[ "$d1" != "$d2" && "$d2" != "$d3" && "$d3" != "$d4" ]]; then + ok "12-hex digests change on added file and symlink target ($d1 -> $d2 -> $d3 -> $d4)" +else + no "digest sensitivity failed: d1='$d1' d2='$d2' d3='$d3' d4='$d4'" +fi + +echo "[2] re-stage between list and promote is refused (rc=4), nothing moves" +mkdraft beta "$(printf -- '---\nname: beta\ndescription: reviewed\n---\nV1-REVIEWED')" +d_v1="$(dig_of beta)" +mkdraft beta "$(printf -- '---\nname: beta\ndescription: tampered\n---\nV2-TAMPERED')" +"$CLI" promote beta "$d_v1" >/dev/null 2>&1; rc=$? +if [[ $rc -eq 4 && ! -e "$SKILL_CURATOR_SKILLS_DIR/beta" ]] \ + && grep -q 'V2-TAMPERED' "$SKILL_CURATOR_PROPOSALS_DIR/beta/SKILL.md" 2>/dev/null; then + ok "re-staged draft refused (rc=4), nothing moved" +else + no "re-stage not refused cleanly (rc=$rc, live=$(ls "$SKILL_CURATOR_SKILLS_DIR" 2>/dev/null))" +fi + +echo "[3] no digest, --force in digest slot, and wrong digest all refuse (rc=4)" +"$CLI" promote beta >/dev/null 2>&1; rc_none=$? +"$CLI" promote beta --force >/dev/null 2>&1; rc_flag=$? +"$CLI" promote beta 000000000000 >/dev/null 2>&1; rc_wrong=$? +if [[ $rc_none -eq 4 && $rc_flag -eq 4 && $rc_wrong -eq 4 \ + && ! -e "$SKILL_CURATOR_SKILLS_DIR/beta" && -f "$SKILL_CURATOR_PROPOSALS_DIR/beta/SKILL.md" ]]; then + ok "missing/wrong digest refused (rc=4), draft untouched" +else + no "bad-digest refusal wrong (none=$rc_none flag=$rc_flag wrong=$rc_wrong)" +fi + +echo "[4] right digest promotes exact reviewed draft including extra files and symlinks" +d_alpha="$(dig_of alpha)" +"$CLI" promote alpha "$d_alpha" >/dev/null 2>&1; rc=$? +if [[ $rc -eq 0 && -f "$SKILL_CURATOR_SKILLS_DIR/alpha/SKILL.md" \ + && -f "$SKILL_CURATOR_SKILLS_DIR/alpha/references/extra.md" \ + && -L "$SKILL_CURATOR_SKILLS_DIR/alpha/ref-link" \ + && "$(readlink "$SKILL_CURATOR_SKILLS_DIR/alpha/ref-link")" == "target-b" \ + && ! -e "$SKILL_CURATOR_PROPOSALS_DIR/alpha" ]]; then + ok "right digest promoted draft with extra file and symlink intact" +else + no "right-digest promote failed (rc=$rc)" +fi + +echo "[5] --force after digest replaces live skill and backs up previous live copy" +mkdraft alpha "$(printf -- '---\nname: alpha\ndescription: replacement\n---\nV2-FORCE-DRAFT')" +d_force="$(dig_of alpha)" +"$CLI" promote alpha "$d_force" >/dev/null 2>&1; rc_noforce=$? +"$CLI" promote alpha "$d_force" --force >/dev/null 2>&1; rc_force=$? +if [[ $rc_noforce -eq 4 && $rc_force -eq 0 ]] \ + && grep -q 'V2-FORCE-DRAFT' "$SKILL_CURATOR_SKILLS_DIR/alpha/SKILL.md" 2>/dev/null \ + && grep -rq 'alpha v1' "$SKILL_CURATOR_PROPOSALS_DIR/_replaced" 2>/dev/null; then + ok "--force after digest replaced live skill and backed up old copy" +else + no "--force behavior wrong (noforce=$rc_noforce force=$rc_force)" +fi + +echo "[6] re-stage during promotion (PATH stub) publishes reviewed copy, newer draft stays visible" +mkdraft race-mid "$(printf -- '---\nname: race-mid\ndescription: v1\n---\nV1-MID')" +d_mid="$(dig_of race-mid)" +STUB1="$TMP/stub-hash" +mkdir -p "$STUB1" +cat > "$STUB1/shasum" < "$TMP/fired-hash" + mkdir -p "$SKILL_CURATOR_PROPOSALS_DIR/race-mid" + printf -- '---\nname: race-mid\ndescription: v2 newer\n---\nV2-MID-NEWER\n' > "$SKILL_CURATOR_PROPOSALS_DIR/race-mid/SKILL.md" +fi +exec "${REAL_SHASUM:-/usr/bin/shasum}" "\$@" +EOF +cat > "$STUB1/sha256sum" < "$TMP/fired-hash" + mkdir -p "$SKILL_CURATOR_PROPOSALS_DIR/race-mid" + printf -- '---\nname: race-mid\ndescription: v2 newer\n---\nV2-MID-NEWER\n' > "$SKILL_CURATOR_PROPOSALS_DIR/race-mid/SKILL.md" +fi +exec "${REAL_SHA256:-/usr/bin/sha256sum}" "\$@" +EOF +chmod +x "$STUB1/shasum" "$STUB1/sha256sum" +PATH="$STUB1:$PATH" "$CLI" promote race-mid "$d_mid" >/dev/null 2>&1; rc_mid=$? +lst_mid="$("$CLI" list)" +if [[ $rc_mid -eq 0 ]] \ + && grep -q 'V1-MID' "$SKILL_CURATOR_SKILLS_DIR/race-mid/SKILL.md" 2>/dev/null \ + && ! grep -q 'V2-MID-NEWER' "$SKILL_CURATOR_SKILLS_DIR/race-mid/SKILL.md" 2>/dev/null \ + && grep -q 'V2-MID-NEWER' "$SKILL_CURATOR_PROPOSALS_DIR/race-mid/SKILL.md" 2>/dev/null \ + && grep -q '^race-mid ' <<<"$lst_mid"; then + ok "mid-digest re-stage: live got V1, newer V2 stayed staged and listed" +else + no "mid-digest re-stage failed (rc=$rc_mid, list='$lst_mid')" +fi + +echo "[7] late re-stage during promote (mkdir stub, Fault 2) does not hide newer draft" +mkdraft race-late "$(printf -- '---\nname: race-late\ndescription: v1\n---\nV1-LATE')" +d_late="$(dig_of race-late)" +STUB2="$TMP/stub-mkdir" +mkdir -p "$STUB2" +cat > "$STUB2/mkdir" < "$TMP/fired-mkdir" + "$REAL_MKDIR" -p "$SKILL_CURATOR_PROPOSALS_DIR/race-late" + printf -- '---\nname: race-late\ndescription: v2 late\n---\nV2-LATE-NEWER\n' > "$SKILL_CURATOR_PROPOSALS_DIR/race-late/SKILL.md" + ;; + esac +fi +exit \$rc +EOF +chmod +x "$STUB2/mkdir" +PATH="$STUB2:$PATH" "$CLI" promote race-late "$d_late" >/dev/null 2>&1; rc_late=$? +lst_late="$("$CLI" list)" +if [[ $rc_late -eq 0 ]] \ + && grep -q 'V1-LATE' "$SKILL_CURATOR_SKILLS_DIR/race-late/SKILL.md" 2>/dev/null \ + && grep -q 'V2-LATE-NEWER' "$SKILL_CURATOR_PROPOSALS_DIR/race-late/SKILL.md" 2>/dev/null \ + && grep -q '^race-late ' <<<"$lst_late"; then + ok "late re-stage: live got V1, newer V2 not hidden by retire step" +else + no "late re-stage hid or lost newer draft (rc=$rc_late, list='$lst_late')" +fi + +echo "[8] re-stage during refused promotion preserves BOTH old and new drafts" +mkdraft race-ref "$(printf -- '---\nname: race-ref\ndescription: old\n---\nV1-REF-OLD')" +STUB3="$TMP/stub-ref" +mkdir -p "$STUB3" +cat > "$STUB3/shasum" < "$TMP/fired-ref" + mkdir -p "$SKILL_CURATOR_PROPOSALS_DIR/race-ref" + printf -- '---\nname: race-ref\ndescription: new\n---\nV2-REF-NEW\n' > "$SKILL_CURATOR_PROPOSALS_DIR/race-ref/SKILL.md" +fi +exec "${REAL_SHASUM:-/usr/bin/shasum}" "\$@" +EOF +cat > "$STUB3/sha256sum" < "$TMP/fired-ref" + mkdir -p "$SKILL_CURATOR_PROPOSALS_DIR/race-ref" + printf -- '---\nname: race-ref\ndescription: new\n---\nV2-REF-NEW\n' > "$SKILL_CURATOR_PROPOSALS_DIR/race-ref/SKILL.md" +fi +exec "${REAL_SHA256:-/usr/bin/sha256sum}" "\$@" +EOF +chmod +x "$STUB3/shasum" "$STUB3/sha256sum" +PATH="$STUB3:$PATH" "$CLI" promote race-ref 000000000000 >/dev/null 2>&1; rc_ref=$? +if [[ $rc_ref -eq 4 && ! -e "$SKILL_CURATOR_SKILLS_DIR/race-ref" ]] \ + && grep -q 'V2-REF-NEW' "$SKILL_CURATOR_PROPOSALS_DIR/race-ref/SKILL.md" 2>/dev/null \ + && grep -rq 'V1-REF-OLD' "$SKILL_CURATOR_PROPOSALS_DIR" 2>/dev/null; then + ok "refusal during re-stage preserved both V2-REF-NEW and V1-REF-OLD" +else + no "refusal during re-stage lost a draft (rc=$rc_ref)" +fi + +echo "[9] inherited temp variable does not recursively delete unrelated folder (Fault 1)" +CANARY="$TMP/innocent-folder" +mkdir -p "$CANARY" +printf 'DO-NOT-DELETE\n' > "$CANARY/keep.txt" +mkdraft canary-draft "$(printf -- '---\nname: canary-draft\ndescription: ok\n---\n# body')" +d_can="$(dig_of canary-draft)" +_PTMP="$CANARY" PTMP="$CANARY" hold="$CANARY" "$CLI" promote >/dev/null 2>&1 || true +_PTMP="$CANARY" PTMP="$CANARY" hold="$CANARY" "$CLI" promote canary-draft 000000000000 >/dev/null 2>&1 || true +_PTMP="$CANARY" PTMP="$CANARY" hold="$CANARY" "$CLI" promote canary-draft "$d_can" >/dev/null 2>&1 || true +_PTMP="$CANARY" PTMP="$CANARY" hold="$CANARY" SKILL_CURATOR_AUTO_PROMOTE=true "$CLI" auto >/dev/null 2>&1 || true +if [[ -f "$CANARY/keep.txt" ]] && grep -q 'DO-NOT-DELETE' "$CANARY/keep.txt" \ + && ! sed 's/#.*//' "$DIR/lib/promote.sh" | grep -qE '\brm[[:space:]]+-[a-zA-Z]*r'; then + ok "inherited temp env left canary folder untouched; no recursive rm in promote.sh" +else + no "canary folder deleted or recursive rm present in promote.sh" +fi + +echo "[10] auto mode promotes eligible draft from private copy and preserves concurrent newer draft" +rm -rf "$SKILL_CURATOR_PROPOSALS_DIR" +mkdir -p "$SKILL_CURATOR_PROPOSALS_DIR" "$SKILL_CURATOR_SKILLS_DIR/umb" +mkdraft refadd "$(printf -- '---\nname: refadd\ncc-si-kind: references-add\ncc-si-umbrella: umb\ncc-si-path: references/note.md\n---\nAUTO-V1')" +mkdraft plain-new "$(printf -- '---\nname: plain-new\ndescription: manual\n---\n# manual')" +STUB4="$TMP/stub-auto" +mkdir -p "$STUB4" +cat > "$STUB4/mkdir" < "$TMP/fired-auto" + "$REAL_MKDIR" -p "$SKILL_CURATOR_PROPOSALS_DIR/refadd" + printf -- '---\nname: refadd\ncc-si-kind: references-add\ncc-si-umbrella: umb\ncc-si-path: references/note.md\n---\nAUTO-V2-NEWER\n' > "$SKILL_CURATOR_PROPOSALS_DIR/refadd/SKILL.md" + ;; + esac +fi +exit \$rc +EOF +chmod +x "$STUB4/mkdir" +PATH="$STUB4:$PATH" SKILL_CURATOR_AUTO_PROMOTE=true "$CLI" auto >/dev/null 2>&1; rc_auto=$? +if [[ $rc_auto -eq 0 ]] \ + && grep -q 'AUTO-V1' "$SKILL_CURATOR_SKILLS_DIR/umb/references/note.md" 2>/dev/null \ + && ! grep -q 'AUTO-V2-NEWER' "$SKILL_CURATOR_SKILLS_DIR/umb/references/note.md" 2>/dev/null \ + && grep -q 'AUTO-V2-NEWER' "$SKILL_CURATOR_PROPOSALS_DIR/refadd/SKILL.md" 2>/dev/null \ + && [[ -f "$SKILL_CURATOR_PROPOSALS_DIR/plain-new/SKILL.md" && ! -e "$SKILL_CURATOR_SKILLS_DIR/plain-new" ]]; then + ok "auto mode published V1 from private copy, kept newer V2 staged, skipped ineligible" +else + no "auto mode wrong (rc=$rc_auto)" +fi + +echo "[11] curate_restore refuses over a live skill (rc=5), no nesting, manifest unchanged" +REST="$TMP/skills-restore" +mkdir -p "$REST/live-one" "$REST/_archive/live-one" "$REST/_archive/other-arc" +printf -- '---\nname: live-one\n---\nLIVE-BODY\n' > "$REST/live-one/SKILL.md" +printf -- '---\nname: live-one\n---\nARCHIVED-BODY\n' > "$REST/_archive/live-one/SKILL.md" +printf -- '---\nname: other-arc\n---\nOTHER-BODY\n' > "$REST/_archive/other-arc/SKILL.md" +printf 'live-one\t2026-01-01T00:00:00+0000\tumb\nother-arc\t2026-01-01T00:00:00+0000\tnull\nother-arc-extra\t2026-01-01T00:00:00+0000\tnull\n' \ + > "$REST/_archive/manifest.tsv" +mf_before="$(cat "$REST/_archive/manifest.tsv")" +SKILL_CURATOR_SKILLS_DIR="$REST" "$IMPROVE" restore live-one >/dev/null 2>&1; rc_res=$? +mf_after="$(cat "$REST/_archive/manifest.tsv")" +if [[ $rc_res -eq 5 && ! -e "$REST/live-one/live-one" ]] \ + && grep -q 'LIVE-BODY' "$REST/live-one/SKILL.md" \ + && grep -q 'ARCHIVED-BODY' "$REST/_archive/live-one/SKILL.md" \ + && [[ "$mf_before" == "$mf_after" ]]; then + ok "restore over live skill refused (rc=5), no nesting, manifest unchanged" +else + no "restore over live skill failed (rc=$rc_res, nested=$(ls "$REST/live-one" 2>/dev/null))" +fi + +echo "[12] normal curate_restore moves archive back and removes only its manifest row" +SKILL_CURATOR_SKILLS_DIR="$REST" "$IMPROVE" restore other-arc >/dev/null 2>&1; rc_ok=$? +if [[ $rc_ok -eq 0 && -f "$REST/other-arc/SKILL.md" && ! -e "$REST/_archive/other-arc" ]] \ + && grep -q 'OTHER-BODY' "$REST/other-arc/SKILL.md" \ + && ! grep -q '^other-arc ' "$REST/_archive/manifest.tsv" \ + && grep -q '^live-one ' "$REST/_archive/manifest.tsv" \ + && grep -q '^other-arc-extra ' "$REST/_archive/manifest.tsv"; then + ok "normal restore moved skill back and pruned only its exact manifest row" +else + no "normal restore wrong (rc=$rc_ok, manifest='$(cat "$REST/_archive/manifest.tsv")')" +fi + +echo "[13] file with newline in name added after list is refused (rc=4), not installed" +mkdraft nl-draft "$(printf -- '---\nname: nl-draft\ndescription: nl\n---\n# ok')" +d_nl="$(dig_of nl-draft)" +printf 'EVIL\n' > "$SKILL_CURATOR_PROPOSALS_DIR/nl-draft/$(printf 'evil\nname')" +"$CLI" promote nl-draft "$d_nl" >/dev/null 2>&1; rc_nl=$? +if [[ $rc_nl -eq 4 && ! -e "$SKILL_CURATOR_SKILLS_DIR/nl-draft" ]]; then + ok "newline-named file refused (rc=4), nothing installed" +else + no "newline-named file bypassed digest (rc=$rc_nl)" +fi + +echo "[14] fifo added after list is refused (rc=4), not installed" +mkdraft fifo-draft "$(printf -- '---\nname: fifo-draft\ndescription: fifo\n---\n# ok')" +d_fifo="$(dig_of fifo-draft)" +mkfifo "$SKILL_CURATOR_PROPOSALS_DIR/fifo-draft/pipe" +"$CLI" promote fifo-draft "$d_fifo" >/dev/null 2>&1; rc_fifo=$? +if [[ $rc_fifo -eq 4 && ! -e "$SKILL_CURATOR_SKILLS_DIR/fifo-draft" ]]; then + ok "fifo refused (rc=4), nothing installed" +else + no "fifo bypassed digest (rc=$rc_fifo)" +fi + +echo "[15] chmod +x after list changes digest and is refused (rc=4), not installed" +mkdraft mode-draft "$(printf -- '---\nname: mode-draft\ndescription: mode\n---\n# ok')" +printf '#!/usr/bin/env bash\necho hi\n' > "$SKILL_CURATOR_PROPOSALS_DIR/mode-draft/run.sh" +chmod 0644 "$SKILL_CURATOR_PROPOSALS_DIR/mode-draft/run.sh" +d_mode="$(dig_of mode-draft)" +chmod +x "$SKILL_CURATOR_PROPOSALS_DIR/mode-draft/run.sh" +"$CLI" promote mode-draft "$d_mode" >/dev/null 2>&1; rc_mode=$? +if [[ $rc_mode -eq 4 && ! -e "$SKILL_CURATOR_SKILLS_DIR/mode-draft" ]]; then + ok "chmod +x refused (rc=4), nothing installed" +else + no "chmod +x bypassed digest (rc=$rc_mode)" +fi + +echo "[16] absolute symlink target swap after list is refused (rc=4), not installed" +ABS_TGT="$TMP/abs-target.md" +printf 'REVIEWED-TARGET\n' > "$ABS_TGT" +mkdraft abs-draft "$(printf -- '---\nname: abs-draft\ndescription: abs\n---\n# ok')" +ln -s "$ABS_TGT" "$SKILL_CURATOR_PROPOSALS_DIR/abs-draft/ref.md" +d_abs="$(dig_of abs-draft)" +printf 'SWAPPED-TARGET\n' > "$ABS_TGT" +"$CLI" promote abs-draft "$d_abs" >/dev/null 2>&1; rc_abs=$? +if [[ $rc_abs -eq 4 && ! -e "$SKILL_CURATOR_SKILLS_DIR/abs-draft" ]]; then + ok "absolute symlink refused (rc=4), swapped target not installed" +else + no "absolute symlink bypassed digest (rc=$rc_abs, dig='$d_abs')" +fi + +echo "[17] curate_restore refuses traversal, slash, empty, and leading-dash slugs" +RVAL="$TMP/restore-slug-test/skills" +mkdir -p "$RVAL/live" "$RVAL/_archive" +printf -- '---\nname: live\n---\nLIVE-KEEP\n' > "$RVAL/live/SKILL.md" +bad_r_ok=1 +for bad_slug in "" "../live" "a/b" ".." "-bad"; do + SKILL_CURATOR_SKILLS_DIR="$RVAL" "$IMPROVE" restore "$bad_slug" >/dev/null 2>&1; rc_b=$? + [[ $rc_b -eq 2 ]] || { bad_r_ok=0; echo " restore '$bad_slug' rc=$rc_b" >&2; } +done +if [[ $bad_r_ok -eq 1 && -f "$RVAL/live/SKILL.md" && ! -e "$TMP/restore-slug-test/live" ]]; then + ok "curate_restore refused invalid slugs (rc=2), live skill stayed inside skills/" +else + no "curate_restore accepted an invalid slug or moved live skill out" +fi + +echo +if [[ $fail -gt 0 ]]; then echo "test-promote-digest: $pass passed, $fail FAILED" >&2; exit 1; fi +echo "test-promote-digest: all $pass passed" diff --git a/lib/skill-curator/tests/test-promote.sh b/lib/skill-curator/tests/test-promote.sh index 3a4477697..d65dd1a03 100755 --- a/lib/skill-curator/tests/test-promote.sh +++ b/lib/skill-curator/tests/test-promote.sh @@ -12,6 +12,7 @@ no(){ echo " FAIL: $*" >&2; fail=$((fail+1)); } export SKILL_CURATOR_STATE_DIR="$TMP/state" SKILL_CURATOR_PROPOSALS_DIR="$TMP/proposals" SKILL_CURATOR_SKILLS_DIR="$TMP/skills" mkdraft(){ mkdir -p "$SKILL_CURATOR_PROPOSALS_DIR/$1"; printf '%s\n' "$2" > "$SKILL_CURATOR_PROPOSALS_DIR/$1/SKILL.md"; } +dig_of(){ "$CLI" list | awk -F'\t' -v s="$1" '$1==s{print $2; exit}'; } GOOD='--- name: deploy-via-wrangler description: deploy a worker @@ -29,23 +30,23 @@ lst="$("$CLI" list)" # capture first: `producer | grep -q` would SIGPIPE the p if grep -q '^deploy-via-wrangler' <<<"$lst" && grep -q '^other-skill' <<<"$lst"; then ok "list shows both"; else no "list wrong: $lst"; fi echo "[2] promote moves proposals/ -> skills/, proposal gone" -"$CLI" promote deploy-via-wrangler >/dev/null +"$CLI" promote deploy-via-wrangler "$(dig_of deploy-via-wrangler)" >/dev/null if [[ -f "$SKILL_CURATOR_SKILLS_DIR/deploy-via-wrangler/SKILL.md" && ! -d "$SKILL_CURATOR_PROPOSALS_DIR/deploy-via-wrangler" ]]; then ok "promoted + proposal removed"; else no "promote did not move"; fi echo "[3] promote refuses to overwrite a live skill without --force" mkdraft deploy-via-wrangler "$GOOD" # stage again; skills/ already has it -"$CLI" promote deploy-via-wrangler >/dev/null 2>&1; rc=$? +"$CLI" promote deploy-via-wrangler "$(dig_of deploy-via-wrangler)" >/dev/null 2>&1; rc=$? if [[ $rc -eq 4 && -d "$SKILL_CURATOR_PROPOSALS_DIR/deploy-via-wrangler" ]]; then ok "refused overwrite (rc=4), draft still staged"; else no "did not refuse overwrite (rc=$rc)"; fi echo "[4] promote --force replaces but backs up the old (never rm)" printf 'LIVE-MARKER\n' >> "$SKILL_CURATOR_SKILLS_DIR/deploy-via-wrangler/SKILL.md" -"$CLI" promote deploy-via-wrangler --force >/dev/null 2>&1 +"$CLI" promote deploy-via-wrangler "$(dig_of deploy-via-wrangler)" --force >/dev/null 2>&1 if [[ -f "$SKILL_CURATOR_SKILLS_DIR/deploy-via-wrangler/SKILL.md" ]] && ! grep -q LIVE-MARKER "$SKILL_CURATOR_SKILLS_DIR/deploy-via-wrangler/SKILL.md" && [[ -n "$(find "$SKILL_CURATOR_PROPOSALS_DIR/_replaced" -name SKILL.md 2>/dev/null)" ]] && grep -rq LIVE-MARKER "$SKILL_CURATOR_PROPOSALS_DIR/_replaced" 2>/dev/null; then ok "force replaced; old skill backed up to _replaced/"; else no "force/backup wrong"; fi echo "[5] promote refuses a draft that still contains a secret" mkdraft secret-draft "$SECRET" -"$CLI" promote secret-draft >/dev/null 2>&1; rc=$? +"$CLI" promote secret-draft "$(dig_of secret-draft)" >/dev/null 2>&1; rc=$? if [[ $rc -eq 3 && ! -d "$SKILL_CURATOR_SKILLS_DIR/secret-draft" && -d "$SKILL_CURATOR_PROPOSALS_DIR/secret-draft" ]]; then ok "secret draft refused (rc=3), not promoted"; else no "secret promote not refused (rc=$rc)"; fi echo "[6] reject moves to _rejected/ (recoverable, not deleted)" @@ -76,7 +77,7 @@ mkdir -p "$SKILL_CURATOR_PROPOSALS_DIR" "$SKILL_CURATOR_SKILLS_DIR/forced" printf 'LIVE-KEEP\n' > "$SKILL_CURATOR_SKILLS_DIR/forced/SKILL.md" : > "$SKILL_CURATOR_PROPOSALS_DIR/_replaced" # a file where the backup dir must go: mkdir/mv fail mkdraft forced "$GOOD" -"$CLI" promote forced --force >/dev/null 2>&1; rc=$? +"$CLI" promote forced "$(dig_of forced)" --force >/dev/null 2>&1; rc=$? if [[ $rc -ne 0 && ! -e "$SKILL_CURATOR_SKILLS_DIR/forced/forced" ]] \ && grep -q LIVE-KEEP "$SKILL_CURATOR_SKILLS_DIR/forced/SKILL.md" && [[ -f "$SKILL_CURATOR_PROPOSALS_DIR/forced/SKILL.md" ]]; then ok "failed backup aborted (rc=$rc), live skill intact, draft still staged"; else no "failed backup did not abort cleanly (rc=$rc)"; fi