summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/claude-code/run-skill-tests.sh1
-rwxr-xr-xtests/claude-code/test-executing-plans-scripts.sh139
-rwxr-xr-xtests/claude-code/test-sdd-workspace.sh161
-rwxr-xr-xtests/codex-plugin-sync/test-sync-to-codex-plugin.sh6
-rwxr-xr-xtests/diagnosing-superpowers/test-skill-structure.sh151
-rwxr-xr-xtests/opencode/run-tests.sh4
-rw-r--r--tests/opencode/test-bootstrap-caching.mjs122
-rw-r--r--tests/opencode/test-session-bootstrap.mjs224
-rwxr-xr-xtests/opencode/test-session-bootstrap.sh4
-rw-r--r--tests/opencode/test-skill-registration.mjs205
-rwxr-xr-xtests/opencode/test-skill-registration.sh22
11 files changed, 1039 insertions, 0 deletions
diff --git a/tests/claude-code/run-skill-tests.sh b/tests/claude-code/run-skill-tests.sh
index 83217cd..97bce6d 100755
--- a/tests/claude-code/run-skill-tests.sh
+++ b/tests/claude-code/run-skill-tests.sh
@@ -76,6 +76,7 @@ done
tests=(
"test-worktree-path-policy.sh"
"test-sdd-workspace.sh"
+ "test-executing-plans-scripts.sh"
"test-subagent-driven-development.sh"
)
diff --git a/tests/claude-code/test-executing-plans-scripts.sh b/tests/claude-code/test-executing-plans-scripts.sh
new file mode 100755
index 0000000..994733b
--- /dev/null
+++ b/tests/claude-code/test-executing-plans-scripts.sh
@@ -0,0 +1,139 @@
+#!/usr/bin/env bash
+# Tests for executing-plans' bookkeeping helpers: scripts/task-start extracts
+# the brief and records BASE in one call; scripts/task-done runs the task's
+# test command, records the result in the ledger, and refuses to record a
+# failing task.
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
+EP_SCRIPTS="$REPO_ROOT/skills/executing-plans/scripts"
+
+FAILURES=0
+TEST_ROOT=""
+
+pass() { echo " [PASS] $1"; }
+fail() {
+ echo " [FAIL] $1"
+ FAILURES=$((FAILURES + 1))
+}
+
+cleanup() {
+ if [[ -n "$TEST_ROOT" && -d "$TEST_ROOT" ]]; then
+ rm -rf "$TEST_ROOT"
+ fi
+}
+
+main() {
+ echo "=== Test: executing-plans scripts ==="
+
+ TEST_ROOT="$(mktemp -d)"
+ trap cleanup EXIT
+
+ git init -q -b main "$TEST_ROOT/repo"
+ local repo
+ repo="$(cd "$TEST_ROOT/repo" && git rev-parse --show-toplevel)"
+ local git_id=(-c user.email=t@example.com -c user.name=t -c commit.gpgsign=false)
+
+ cat > "$repo/plan.md" <<'PLAN'
+# Plan
+
+## Task 1: First thing
+
+Do the first thing.
+
+## Task 2: Second thing
+
+Do the second thing.
+PLAN
+ ( cd "$repo" && git add plan.md && git "${git_id[@]}" commit -qm fixture )
+ local base
+ base="$(cd "$repo" && git rev-parse HEAD)"
+
+ # --- task-start: argument validation ---
+ local rc=0
+ (cd "$repo" && "$EP_SCRIPTS/task-start" plan.md >/dev/null 2>&1) || rc=$?
+ if [[ "$rc" -eq 2 ]]; then
+ pass "task-start without a task number errors with exit 2"
+ else
+ fail "task-start without a task number errors with exit 2 (got $rc)"
+ fi
+
+ # --- task-start: brief path + BASE in one call ---
+ local out
+ out="$(cd "$repo" && "$EP_SCRIPTS/task-start" plan.md 1)"
+ if [[ "$out" == *"brief: $repo/.superpowers/sdd/plan/task-1-brief.md"* ]]; then
+ pass "task-start prints the brief path under the plan's workspace"
+ else
+ fail "task-start prints the brief path under the plan's workspace"
+ echo " got: $out"
+ fi
+ if [[ "$out" == *"base: $base"* ]]; then
+ pass "task-start prints BASE as the current HEAD"
+ else
+ fail "task-start prints BASE as the current HEAD"
+ echo " got: $out"
+ fi
+ if [[ -s "$repo/.superpowers/sdd/plan/task-1-brief.md" ]]; then
+ pass "task-start writes the brief file"
+ else
+ fail "task-start writes the brief file"
+ fi
+
+ # --- task-done: records a passing task ---
+ ( cd "$repo" && echo x > work.txt && git add work.txt && git "${git_id[@]}" commit -qm "task 1" )
+ local head
+ head="$(cd "$repo" && git rev-parse HEAD)"
+ out="$(cd "$repo" && "$EP_SCRIPTS/task-done" plan.md 1 "$base" -- sh -c 'echo "Ran 3 tests"; echo OK')"
+ rc=$?
+ local ledger="$repo/.superpowers/sdd/plan/progress.md"
+ local expected="Task 1: complete (commits ${base:0:7}..${head:0:7}, tests: sh -c 'echo \"Ran 3 tests\"; echo OK' → OK)"
+ if [[ -f "$ledger" ]] && grep -qF "$expected" "$ledger"; then
+ pass "task-done appends the completion line with commit range and test result"
+ else
+ fail "task-done appends the completion line with commit range and test result"
+ echo " expected: $expected"
+ echo " ledger:"; sed 's/^/ /' "$ledger" 2>/dev/null || echo " (missing)"
+ fi
+ if [[ "$out" == *"OK"* ]]; then
+ pass "task-done prints the tail of the test output"
+ else
+ fail "task-done prints the tail of the test output"
+ echo " got: $out"
+ fi
+ if [[ -s "$repo/.superpowers/sdd/plan/task-1-tests.log" ]]; then
+ pass "task-done keeps the full test output in the workspace"
+ else
+ fail "task-done keeps the full test output in the workspace"
+ fi
+
+ # --- task-done: refuses to record a failing task ---
+ rc=0
+ out="$(cd "$repo" && "$EP_SCRIPTS/task-done" plan.md 2 "$head" -- sh -c 'echo "FAILED (errors=1)"; exit 1' 2>&1)" || rc=$?
+ if [[ "$rc" -ne 0 ]]; then
+ pass "task-done exits non-zero when the test command fails"
+ else
+ fail "task-done exits non-zero when the test command fails"
+ fi
+ if ! grep -q "Task 2: complete" "$ledger"; then
+ pass "task-done does not record a failing task as complete"
+ else
+ fail "task-done does not record a failing task as complete"
+ fi
+ if [[ "$out" == *"FAILED"* ]]; then
+ pass "task-done shows the failing output"
+ else
+ fail "task-done shows the failing output"
+ echo " got: $out"
+ fi
+
+ echo
+ if [[ "$FAILURES" -eq 0 ]]; then
+ echo "PASS"
+ else
+ echo "FAIL ($FAILURES)"
+ exit 1
+ fi
+}
+
+main "$@"
diff --git a/tests/claude-code/test-sdd-workspace.sh b/tests/claude-code/test-sdd-workspace.sh
index 8417230..2e8c227 100755
--- a/tests/claude-code/test-sdd-workspace.sh
+++ b/tests/claude-code/test-sdd-workspace.sh
@@ -165,6 +165,30 @@ PLAN
echo " got: $rp_explicit"
fi
+ # --- range guards: BASE must be an ancestor of HEAD, range must be non-empty ---
+ local divergent
+ divergent="$(cd "$repo" && git "${git_id[@]}" commit-tree 'HEAD~1^{tree}' -p 'HEAD~1' -m divergent)"
+ rc=0
+ local guard_err
+ guard_err="$(cd "$repo" && "$SDD_SCRIPTS/review-package" plan-a.md "$divergent" HEAD 2>&1 >/dev/null)" || rc=$?
+ if [[ "$rc" -eq 3 && "$guard_err" == *"not a descendant"* ]]; then
+ pass "review-package rejects a BASE that is not an ancestor of HEAD with exit 3"
+ else
+ fail "review-package rejects a BASE that is not an ancestor of HEAD with exit 3"
+ echo " exit: $rc"
+ echo " stderr: $guard_err"
+ fi
+
+ rc=0
+ guard_err="$(cd "$repo" && "$SDD_SCRIPTS/review-package" plan-a.md HEAD HEAD 2>&1 >/dev/null)" || rc=$?
+ if [[ "$rc" -eq 3 && "$guard_err" == *"empty commit range"* ]]; then
+ pass "review-package rejects an empty BASE..HEAD range with exit 3"
+ else
+ fail "review-package rejects an empty BASE..HEAD range with exit 3"
+ echo " exit: $rc"
+ echo " stderr: $guard_err"
+ fi
+
# --- Worktree isolation: a linked worktree resolves its own workspace ---
local wt="$TEST_ROOT/wt"
( cd "$repo" && git worktree add -q "$wt" -b wt-feature )
@@ -189,6 +213,143 @@ PLAN
echo " status: $wt_status"
fi
+ # --- helpers survive a mode-stripping extractor dropping exec bits (#2040) ---
+ local stripped="$TEST_ROOT/stripped-scripts"
+ mkdir -p "$stripped"
+ cp "$SDD_SCRIPTS/sdd-workspace" "$SDD_SCRIPTS/task-brief" "$SDD_SCRIPTS/review-package" "$stripped/"
+ chmod -x "$stripped"/*
+ local noexec_out noexec_rc=0
+ noexec_out="$(cd "$repo" && bash "$stripped/task-brief" plan-b.md 1 2>&1)" || noexec_rc=$?
+ if [[ "$noexec_rc" -eq 0 && -f "$repo/.superpowers/sdd/plan-b/task-1-brief.md" ]]; then
+ pass "task-brief works with no exec bit on sdd-workspace"
+ else
+ fail "task-brief works with no exec bit on sdd-workspace"
+ echo " rc: $noexec_rc"
+ echo " output: $noexec_out"
+ fi
+
+ # --- Ownership markers: two plans with the same basename (#2045) ---
+ mkdir -p "$repo/docs/alpha" "$repo/docs/beta"
+ cat > "$repo/docs/alpha/plan.md" <<'PLAN'
+# Alpha Plan
+
+## Task 1: Alpha work
+
+Alpha-only requirement text.
+PLAN
+ cat > "$repo/docs/beta/plan.md" <<'PLAN'
+# Beta Plan
+
+## Task 1: Beta work
+
+Beta-only requirement text.
+PLAN
+
+ local dir_alpha dir_beta
+ dir_alpha="$(cd "$repo" && "$SDD_SCRIPTS/sdd-workspace" docs/alpha/plan.md)"
+ dir_beta="$(cd "$repo" && "$SDD_SCRIPTS/sdd-workspace" docs/beta/plan.md)"
+ if [[ "$dir_alpha" != "$dir_beta" ]]; then
+ pass "same-basename plans resolve to distinct workspaces"
+ else
+ fail "same-basename plans resolve to distinct workspaces"
+ echo " alpha: $dir_alpha"
+ echo " beta: $dir_beta"
+ fi
+
+ ( cd "$repo" && "$SDD_SCRIPTS/task-brief" docs/alpha/plan.md 1 >/dev/null )
+ ( cd "$repo" && "$SDD_SCRIPTS/task-brief" docs/beta/plan.md 1 >/dev/null )
+ if grep -q "Alpha-only requirement text." "$dir_alpha/task-1-brief.md" 2>/dev/null \
+ && grep -q "Beta-only requirement text." "$dir_beta/task-1-brief.md" 2>/dev/null; then
+ pass "same-basename plans keep both task briefs intact"
+ else
+ fail "same-basename plans keep both task briefs intact"
+ echo " alpha brief: $(cat "$dir_alpha/task-1-brief.md" 2>/dev/null)"
+ echo " beta brief: $(cat "$dir_beta/task-1-brief.md" 2>/dev/null)"
+ fi
+
+ # --- Legacy adoption: pre-existing workspace without a marker ---
+ printf '# Foo\n\n## Task 1: Foo\n\nFoo.\n' > "$repo/foo.md"
+ mkdir -p "$repo/.superpowers/sdd/foo"
+ printf 'ledger\n' > "$repo/.superpowers/sdd/foo/progress.md"
+ local dir_foo
+ dir_foo="$(cd "$repo" && "$SDD_SCRIPTS/sdd-workspace" foo.md)"
+ if [[ "$dir_foo" == "$repo/.superpowers/sdd/foo" \
+ && -f "$dir_foo/progress.md" \
+ && "$(cat "$dir_foo/plan-path" 2>/dev/null)" == "foo.md" ]]; then
+ pass "legacy markerless workspace is adopted in place and marked"
+ else
+ fail "legacy markerless workspace is adopted in place and marked"
+ echo " dir: $dir_foo"
+ echo " marker: $(cat "$dir_foo/plan-path" 2>/dev/null)"
+ fi
+
+ # --- Ownership conflict: marker names a different plan ---
+ printf '# Bar\n\n## Task 1: Bar\n\nBar.\n' > "$repo/bar.md"
+ mkdir -p "$repo/.superpowers/sdd/bar"
+ printf 'somewhere-else/bar.md\n' > "$repo/.superpowers/sdd/bar/plan-path"
+ printf 'other ledger\n' > "$repo/.superpowers/sdd/bar/progress.md"
+ local dir_bar
+ dir_bar="$(cd "$repo" && "$SDD_SCRIPTS/sdd-workspace" bar.md)"
+ if [[ "$dir_bar" == "$repo/.superpowers/sdd/bar-repo" \
+ && "$(cat "$dir_bar/plan-path" 2>/dev/null)" == "bar.md" ]]; then
+ pass "owned workspace disambiguates with parent-dir suffix"
+ else
+ fail "owned workspace disambiguates with parent-dir suffix"
+ echo " got: $dir_bar"
+ fi
+ if [[ "$(cat "$repo/.superpowers/sdd/bar/plan-path")" == "somewhere-else/bar.md" \
+ && "$(cat "$repo/.superpowers/sdd/bar/progress.md")" == "other ledger" ]]; then
+ pass "conflicting plan leaves the original workspace untouched"
+ else
+ fail "conflicting plan leaves the original workspace untouched"
+ fi
+
+ # --- Counter fallback: parent-suffixed workspace is owned too ---
+ printf '# Baz\n\n## Task 1: Baz\n\nBaz.\n' > "$repo/baz.md"
+ mkdir -p "$repo/.superpowers/sdd/baz" "$repo/.superpowers/sdd/baz-repo"
+ printf 'one/baz.md\n' > "$repo/.superpowers/sdd/baz/plan-path"
+ printf 'two/baz.md\n' > "$repo/.superpowers/sdd/baz-repo/plan-path"
+ local dir_baz
+ dir_baz="$(cd "$repo" && "$SDD_SCRIPTS/sdd-workspace" baz.md)"
+ if [[ "$dir_baz" == "$repo/.superpowers/sdd/baz-repo-2" \
+ && "$(cat "$dir_baz/plan-path" 2>/dev/null)" == "baz.md" ]]; then
+ pass "double conflict falls back to a counter suffix"
+ else
+ fail "double conflict falls back to a counter suffix"
+ echo " got: $dir_baz"
+ fi
+
+ # --- Same plan spelled differently resolves to one workspace ---
+ local dir_rel dir_abs dir_dotdot
+ dir_rel="$(cd "$repo" && "$SDD_SCRIPTS/sdd-workspace" docs/alpha/plan.md)"
+ dir_abs="$(cd "$repo" && "$SDD_SCRIPTS/sdd-workspace" "$repo/docs/alpha/plan.md")"
+ dir_dotdot="$(cd "$repo/docs/beta" && "$SDD_SCRIPTS/sdd-workspace" ../alpha/plan.md)"
+ if [[ "$dir_rel" == "$dir_abs" && "$dir_rel" == "$dir_dotdot" \
+ && "$(cat "$dir_rel/plan-path" 2>/dev/null)" == "docs/alpha/plan.md" ]]; then
+ pass "relative, absolute, and ../ spellings share one workspace and marker"
+ else
+ fail "relative, absolute, and ../ spellings share one workspace and marker"
+ echo " rel: $dir_rel"
+ echo " abs: $dir_abs"
+ echo " dotdot: $dir_dotdot"
+ echo " marker: $(cat "$dir_rel/plan-path" 2>/dev/null)"
+ fi
+
+ # --- Out-of-repo plans keep working, marker holds the absolute path ---
+ mkdir -p "$TEST_ROOT/outside"
+ printf '# Remote\n\n## Task 1: Remote\n\nRemote.\n' > "$TEST_ROOT/outside/remote-plan.md"
+ local outside_abs dir_out
+ outside_abs="$(cd "$TEST_ROOT/outside" && pwd -P)/remote-plan.md"
+ dir_out="$(cd "$repo" && "$SDD_SCRIPTS/sdd-workspace" "$TEST_ROOT/outside/remote-plan.md")"
+ if [[ "$dir_out" == "$repo/.superpowers/sdd/remote-plan" \
+ && "$(cat "$dir_out/plan-path" 2>/dev/null)" == "$outside_abs" ]]; then
+ pass "out-of-repo plan gets a basename slug and an absolute-path marker"
+ else
+ fail "out-of-repo plan gets a basename slug and an absolute-path marker"
+ echo " dir: $dir_out"
+ echo " marker: $(cat "$dir_out/plan-path" 2>/dev/null)"
+ fi
+
echo ""
if [[ "$FAILURES" -ne 0 ]]; then
echo "FAILED: $FAILURES assertion(s)."
diff --git a/tests/codex-plugin-sync/test-sync-to-codex-plugin.sh b/tests/codex-plugin-sync/test-sync-to-codex-plugin.sh
index 01de394..265aea1 100755
--- a/tests/codex-plugin-sync/test-sync-to-codex-plugin.sh
+++ b/tests/codex-plugin-sync/test-sync-to-codex-plugin.sh
@@ -196,6 +196,10 @@ write_upstream_fixture() {
}
EOF
+ cat > "$repo/index.js" <<'EOF'
+export { default } from "./.opencode/plugins/superpowers.js";
+EOF
+
cat > "$repo/.gitignore" <<'EOF'
.private-journal/
EOF
@@ -303,6 +307,7 @@ EOF
hooks/run-hook.cmd \
hooks/session-start \
hooks/session-start-codex \
+ index.js \
package.json \
scripts/sync-to-codex-plugin.sh \
skills/example/SKILL.md
@@ -664,6 +669,7 @@ main() {
assert_not_contains "$preview_section" "evals/" "Preview excludes eval harness"
assert_not_contains "$preview_section" ".gitmodules" "Preview excludes repo submodule metadata"
assert_not_contains "$preview_section" ".pre-commit-config.yaml" "Preview excludes repo pre-commit config"
+ assert_not_contains "$preview_section" "index.js" "Preview excludes OpenCode root entrypoint"
assert_not_contains "$preview_output" "Overlay file (.codex-plugin/plugin.json) will be regenerated" "Preview omits overlay regeneration note"
assert_not_contains "$preview_output" "Assets (superpowers-small.svg, app-icon.png) will be seeded from" "Preview omits assets seeding note"
assert_contains "$preview_section" "skills/example/SKILL.md" "Preview reflects dirty tracked destination file"
diff --git a/tests/diagnosing-superpowers/test-skill-structure.sh b/tests/diagnosing-superpowers/test-skill-structure.sh
new file mode 100755
index 0000000..9c31591
--- /dev/null
+++ b/tests/diagnosing-superpowers/test-skill-structure.sh
@@ -0,0 +1,151 @@
+#!/usr/bin/env bash
+# Structural checks for skills/diagnosing-superpowers. Behavior is tested by
+# scenario evals kept by the maintainer; this script only checks the things a
+# shell can check: frontmatter, referenced files exist, no local paths or
+# names leaked into shipped files, SKILL.md word budget.
+set -u
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
+SKILL_DIR="$REPO_ROOT/skills/diagnosing-superpowers"
+SKILL_MD="$SKILL_DIR/SKILL.md"
+WORD_BUDGET=1000
+
+PASSES=0
+FAILURES=0
+
+pass() { echo " [PASS] $1"; PASSES=$((PASSES + 1)); }
+fail() { echo " [FAIL] $1"; FAILURES=$((FAILURES + 1)); }
+
+echo "diagnosing-superpowers structure"
+
+# --- SKILL.md frontmatter -------------------------------------------------
+if [ -f "$SKILL_MD" ]; then
+ pass "SKILL.md exists"
+ frontmatter="$(awk 'NR==1 && $0!="---"{exit} NR>1 && $0=="---"{exit} NR>1{print}' "$SKILL_MD")"
+ if printf '%s\n' "$frontmatter" | grep -q '^name: diagnosing-superpowers$'; then
+ pass "frontmatter name is diagnosing-superpowers"
+ else
+ fail "frontmatter name is diagnosing-superpowers"
+ fi
+ description="$(printf '%s\n' "$frontmatter" | awk '/^description:/{sub(/^description:[ ]*/,""); print; found=1; next} found && /^[ ]/{print} found && !/^[ ]/{exit}' | tr '\n' ' ')"
+ if printf '%s' "$description" | grep -q '^Use when'; then
+ pass "description starts with 'Use when'"
+ else
+ fail "description starts with 'Use when' (got: ${description:0:60})"
+ fi
+ if [ "${#description}" -le 1024 ]; then
+ pass "description under 1024 characters"
+ else
+ fail "description under 1024 characters (${#description})"
+ fi
+ for banned in "dispatch" "then" "step"; do
+ if printf '%s' "$description" | grep -qiw "$banned"; then
+ fail "description contains workflow word '$banned'"
+ else
+ pass "description avoids workflow word '$banned'"
+ fi
+ done
+
+ # --- word budget --------------------------------------------------------
+ body_words="$(awk 'BEGIN{fm=0} NR==1 && $0=="---"{fm=1; next} fm==1 && $0=="---"{fm=2; next} fm==2{print}' "$SKILL_MD" | wc -w | tr -d ' ')"
+ if [ "$body_words" -le "$WORD_BUDGET" ]; then
+ pass "SKILL.md body within $WORD_BUDGET words ($body_words)"
+ else
+ fail "SKILL.md body within $WORD_BUDGET words ($body_words)"
+ fi
+
+ # --- required sections --------------------------------------------------
+ for heading in "## Hard rules" "## Red Flags"; do
+ if grep -q "^$heading" "$SKILL_MD"; then
+ pass "SKILL.md has section '$heading'"
+ else
+ fail "SKILL.md has section '$heading'"
+ fi
+ done
+
+ # --- every referenced skill file exists --------------------------------
+ while IFS= read -r ref; do
+ if [ -f "$SKILL_DIR/$ref" ]; then
+ pass "referenced file exists: $ref"
+ else
+ fail "referenced file exists: $ref"
+ fi
+ done < <(grep -o '\(references\|prompts\|templates\)/[A-Za-z0-9._-]*\.md' "$SKILL_MD" | sort -u)
+else
+ fail "SKILL.md exists"
+fi
+
+# --- expected files -------------------------------------------------------
+expected_files=(
+ references/redaction-policy.md
+ references/session-discovery.md
+ references/context-safety.md
+ references/github-issues.md
+ prompts/analyst-common.md
+ prompts/skill-timeline.md
+ prompts/plan-adherence.md
+ prompts/repeated-work.md
+ prompts/stumbles.md
+ prompts/quality-evidence.md
+ prompts/request-conflicts.md
+ prompts/cost-and-time.md
+ prompts/scrub.md
+ prompts/scrub-audit.md
+ prompts/similar-session.md
+ templates/case.md
+ templates/report.md
+ templates/bundle-README.md
+ templates/issue.md
+)
+for rel in "${expected_files[@]}"; do
+ if [ -f "$SKILL_DIR/$rel" ]; then
+ pass "expected file present: $rel"
+ else
+ fail "expected file present: $rel"
+ fi
+done
+
+# --- removed harness recipes stay removed --------------------------------
+removed_files=(
+ references/claude-code-sessions.md
+ references/codex-sessions.md
+ references/other-harnesses.md
+)
+for rel in "${removed_files[@]}"; do
+ if [ ! -e "$SKILL_DIR/$rel" ]; then
+ pass "removed reference absent: $rel"
+ else
+ fail "removed reference absent: $rel"
+ fi
+done
+
+removed_reference_hits="$(grep -rn -E 'references/(claude-code-sessions|codex-sessions|other-harnesses)\.md' "$SKILL_DIR" --include='*.md' 2>/dev/null || true)"
+if [ -z "$removed_reference_hits" ]; then
+ pass "active skill prose has no references to removed harness recipes"
+else
+ fail "active skill prose has no references to removed harness recipes"
+ printf '%s\n' "$removed_reference_hits" | head -10 | sed 's/^/ /'
+fi
+
+# --- no local paths or names in shipped files ----------------------------
+leaks="$(grep -rn -E '/Users/|/home/|jesse' "$SKILL_DIR" "$SCRIPT_DIR" --exclude=test-skill-structure.sh 2>/dev/null || true)"
+if [ -z "$leaks" ]; then
+ pass "no machine-specific paths or names in shipped files (skills + tests)"
+else
+ fail "no machine-specific paths or names in shipped files (skills + tests)"
+ printf '%s\n' "$leaks" | head -10 | sed 's/^/ /'
+fi
+
+# --- "the user" never appears in skill prose -----------------------------
+user_hits="$(grep -rn -i 'the user' "$SKILL_DIR" --include='*.md' 2>/dev/null || true)"
+if [ -z "$user_hits" ]; then
+ pass "skill files say 'your human partner', not 'the user'"
+else
+ fail "skill files say 'your human partner', not 'the user'"
+ printf '%s\n' "$user_hits" | head -10 | sed 's/^/ /'
+fi
+
+echo
+echo "Passed: $PASSES Failed: $FAILURES"
+[ "$FAILURES" -eq 0 ]
diff --git a/tests/opencode/run-tests.sh b/tests/opencode/run-tests.sh
index d9b100e..43e1a3a 100755
--- a/tests/opencode/run-tests.sh
+++ b/tests/opencode/run-tests.sh
@@ -45,6 +45,8 @@ while [[ $# -gt 0 ]]; do
echo "Tests:"
echo " test-plugin-loading.sh Verify plugin installation and structure"
echo " test-bootstrap-caching.sh Verify bootstrap content caching"
+ echo " test-session-bootstrap.sh Verify session classification and lookup recovery"
+ echo " test-skill-registration.sh Verify V2 skill registration contract (2.0.4 path field)"
echo " test-tools.sh Test use_skill and find_skills tools (integration)"
echo " test-priority.sh Test skill priority resolution (integration)"
exit 0
@@ -61,6 +63,8 @@ done
tests=(
"test-plugin-loading.sh"
"test-bootstrap-caching.sh"
+ "test-session-bootstrap.sh"
+ "test-skill-registration.sh"
)
# Integration tests (require OpenCode)
diff --git a/tests/opencode/test-bootstrap-caching.mjs b/tests/opencode/test-bootstrap-caching.mjs
index 32149ae..386b7b1 100644
--- a/tests/opencode/test-bootstrap-caching.mjs
+++ b/tests/opencode/test-bootstrap-caching.mjs
@@ -32,6 +32,10 @@ const mod = await import(pathToFileURL(pluginPath).href);
const plugin = await mod.SuperpowersPlugin({ client: {}, directory: '.' });
const transform = plugin['experimental.chat.messages.transform'];
+// Mapping constants are flavor-specific (#opencode-v2): V1 keeps the 1.18.x
+// tool names, V2 teaches the renamed tools. Assert both directly.
+const mappingFailures = assertMappingConstants(mod);
+
const firstOutput = makeOutput(`${scenario} bootstrap first step`);
await transform({}, firstOutput);
const afterFirst = { existsCount, readCount };
@@ -40,6 +44,11 @@ const secondOutput = makeOutput(`${scenario} bootstrap second step`);
await transform({}, secondOutput);
const afterSecond = { existsCount, readCount };
+// Exercise the V2 path (setup() + ctx.session.hook("context")) with a mock
+// ctx so the V2_MAPPING wiring is verified, not just the constant. Run after
+// the V1 count snapshots: setup() reads SKILL.md files during registration.
+const v2Result = await runV2ContextHook(mod);
+
const result = {
scenario,
firstBootstrapParts: countBootstrapParts(firstOutput),
@@ -52,12 +61,24 @@ const result = {
secondReadCount: afterSecond.readCount,
firstExistsCount: afterFirst.existsCount,
secondExistsCount: afterSecond.existsCount,
+ v2BootstrapParts: v2Result.bootstrapParts,
+ mapsV2SubagentTool: v2Result.text.includes('`subagent` with `agent: "general"`'),
+ mapsV2SessionIDContinuation: v2Result.text.includes('`sessionID` to continue a previous subagent'),
+ mapsV2NoTodoTool: v2Result.text.includes('no todo tool'),
+ mapsV2MutationToPatch: v2Result.text.includes('`patch` with `patchText`'),
+ mapsV2Shell: v2Result.text.includes('`shell`'),
+ staleV1ToolsInV2: v2Result.text.includes('`apply_patch`') || v2Result.text.includes('`todowrite`') || v2Result.text.includes('`subagent_type`'),
};
const failures = scenario === 'present'
? assertPresentBootstrap(result)
: assertMissingBootstrap(result);
+if (scenario === 'present') {
+ failures.push(...assertV2Bootstrap(result));
+}
+failures.push(...mappingFailures);
+
if (failures.length > 0) {
console.error(JSON.stringify(result, null, 2));
for (const failure of failures) {
@@ -144,3 +165,104 @@ function assertMissingBootstrap(result) {
}
return failures;
}
+
+function assertMappingConstants(mod) {
+ const failures = [];
+ if (typeof mod.V1_MAPPING !== 'string' || typeof mod.V2_MAPPING !== 'string') {
+ failures.push('expected plugin to export V1_MAPPING and V2_MAPPING string constants');
+ return failures;
+ }
+ for (const needle of ['`todowrite`', '`task` with `subagent_type: "general"`', '`apply_patch`', '`bash`']) {
+ if (!mod.V1_MAPPING.includes(needle)) {
+ failures.push(`expected V1_MAPPING to keep the 1.18.x tool name ${needle}`);
+ }
+ }
+ for (const needle of [
+ '`subagent` with `agent: "general"`',
+ '`sessionID` to continue a previous subagent',
+ 'no todo tool',
+ '`write`',
+ '`edit`',
+ '`patch` with `patchText`',
+ '`shell`',
+ '`read`',
+ '`grep`, `glob`',
+ '`webfetch`',
+ '`websearch`',
+ ]) {
+ if (!mod.V2_MAPPING.includes(needle)) {
+ failures.push(`expected V2_MAPPING to teach the V2 tool ${needle}`);
+ }
+ }
+ for (const stale of ['`todowrite`', '`task` with', '`apply_patch`', '`bash`']) {
+ if (mod.V2_MAPPING.includes(stale)) {
+ failures.push(`expected V2_MAPPING not to teach the V1-only tool name ${stale}`);
+ }
+ }
+ return failures;
+}
+
+// Drive setup() with a mock V2 ctx and fire the captured "context" hook on a
+// top-level (parentID-less) session. Returns the injected-part count and the
+// injected bootstrap text ('' when nothing was injected).
+async function runV2ContextHook(mod) {
+ let contextHook = null;
+ const ctx = {
+ skill: {
+ transform: async (fn) => {
+ fn({ add: () => {} });
+ },
+ },
+ session: {
+ hook: async (name, cb) => {
+ if (name === 'context') contextHook = cb;
+ },
+ get: async ({ sessionID }) => ({ id: sessionID }), // top-level: no parentID
+ },
+ };
+ try {
+ await mod.default.setup(ctx);
+ } catch (err) {
+ console.error('[test] V2 setup() threw:', err);
+ return { bootstrapParts: 0, text: '' };
+ }
+ if (typeof contextHook !== 'function') {
+ return { bootstrapParts: 0, text: '' };
+ }
+ const event = {
+ sessionID: 'sess-v2-top',
+ messages: [{ role: 'user', content: [{ type: 'text', text: 'v2 bootstrap step' }] }],
+ };
+ await contextHook(event);
+ const parts = event.messages[0].content.filter(
+ (part) => part.type === 'text' && part.text.includes('EXTREMELY_IMPORTANT')
+ );
+ return { bootstrapParts: parts.length, text: parts[0]?.text || '' };
+}
+
+function assertV2Bootstrap(result) {
+ const failures = [];
+ if (result.v2BootstrapParts !== 1) {
+ failures.push(`expected V2 context hook to inject one bootstrap part, got ${result.v2BootstrapParts}`);
+ return failures;
+ }
+ if (!result.mapsV2SubagentTool) {
+ failures.push('expected V2 bootstrap to map general-purpose subagents to subagent with agent');
+ }
+ if (!result.mapsV2SessionIDContinuation) {
+ failures.push('expected V2 bootstrap to teach sessionID continuation for subagents');
+ }
+ if (!result.mapsV2NoTodoTool) {
+ failures.push('expected V2 bootstrap to state that V2 has no todo tool');
+ }
+ if (!result.mapsV2MutationToPatch) {
+ failures.push('expected V2 bootstrap to map file mutation to patch with patchText');
+ }
+ if (!result.mapsV2Shell) {
+ failures.push('expected V2 bootstrap to map shell commands to the shell tool');
+ }
+ if (result.staleV1ToolsInV2) {
+ failures.push('expected V2 bootstrap not to teach V1-only tool names (apply_patch/todowrite/subagent_type)');
+ }
+ return failures;
+}
diff --git a/tests/opencode/test-session-bootstrap.mjs b/tests/opencode/test-session-bootstrap.mjs
new file mode 100644
index 0000000..31658d5
--- /dev/null
+++ b/tests/opencode/test-session-bootstrap.mjs
@@ -0,0 +1,224 @@
+import assert from 'node:assert/strict';
+import fs from 'node:fs';
+import { pathToFileURL } from 'node:url';
+
+const [, , inputPath] = process.argv;
+assert.ok(inputPath, 'pass the plugin module path');
+const pluginURL = pathToFileURL(fs.realpathSync(inputPath));
+const marker = '<EXTREMELY_IMPORTANT>\nYou have superpowers.';
+let generation = 0;
+
+function reply(flavor, session) {
+ return flavor === 'v1' ? { data: session } : session;
+}
+
+function makeEvent(flavor, sessionID) {
+ const text = { type: 'text', text: 'Execute the assigned task' };
+ return {
+ sessionID,
+ messages: [flavor === 'v1'
+ ? { info: { role: 'user', sessionID }, parts: [text] }
+ : { role: 'user', content: [text] }],
+ };
+}
+
+function bootstrapCount(event) {
+ return event.messages.flatMap((message) => message.parts ?? message.content ?? []).filter(
+ (part) => part.type === 'text' && part.text.startsWith(marker)
+ ).length;
+}
+
+async function makeHarness(flavor, fetchSession) {
+ const mod = await import(`${pluginURL.href}?session-test=${++generation}`);
+ const lookups = [];
+ const registered = [];
+ const get = async (id) => {
+ lookups.push(id);
+ return fetchSession(id, lookups.length);
+ };
+ let invoke;
+ if (flavor === 'v1') {
+ const hooks = await mod.SuperpowersPlugin({
+ client: { session: { get: ({ path: { id } }) => get(id) } },
+ directory: '.',
+ });
+ invoke = (event) => hooks['experimental.chat.messages.transform']({}, event);
+ } else {
+ await mod.default.setup({
+ skill: { transform: async (transform) => transform({ add: (skill) => registered.push(skill) }) },
+ session: {
+ get: ({ sessionID }) => get(sessionID),
+ hook: async (name, callback) => { if (name === 'context') invoke = callback; },
+ },
+ });
+ }
+ assert.equal(typeof invoke, 'function');
+ return { invoke, lookups, registered };
+}
+
+for (const flavor of ['v1', 'v2']) {
+ for (const [kind, extra, expected] of [
+ ['root', {}, 1],
+ ['child', { parentID: 'parent' }, 0],
+ ['fork', { fork: { sessionID: 'origin' } }, 1],
+ ]) {
+ const id = `${flavor}-${kind}`;
+ const h = await makeHarness(flavor, () => reply(flavor, { id, ...extra }));
+ const event = makeEvent(flavor, id);
+ await h.invoke(event);
+ assert.equal(bootstrapCount(event), expected, `${id}: first request`);
+ await h.invoke(event);
+ assert.equal(bootstrapCount(event), expected, `${id}: repeated event`);
+ const fresh = makeEvent(flavor, id);
+ await h.invoke(fresh);
+ assert.equal(bootstrapCount(fresh), expected, `${id}: fresh request`);
+ assert.deepEqual(h.lookups, [id], `${id}: cache successful classification`);
+ if (flavor === 'v2' && kind === 'child') {
+ assert.ok(h.registered.some((skill) => skill.id === 'brainstorming'));
+ }
+ }
+
+ const failures = [
+ ['throws', () => { throw new Error('temporary lookup failure'); }],
+ ['missing', () => undefined],
+ ['null', () => null],
+ ['empty', () => reply(flavor, {})],
+ ['wrong-id', () => reply(flavor, { id: 'different-session' })],
+ ['invalid-parent', (id) => reply(flavor, { id, parentID: 42 })],
+ ];
+ if (flavor === 'v1') {
+ failures.push(['resolved-http-error', () => ({
+ data: undefined,
+ error: { name: 'UnknownError', data: { message: 'temporary 503' } },
+ response: { ok: false, status: 503 },
+ })]);
+ }
+ for (const [kind, firstResult] of failures) {
+ const id = `${flavor}-${kind}`;
+ const h = await makeHarness(flavor, (sessionID, call) => call === 1
+ ? firstResult(sessionID)
+ : reply(flavor, { id: sessionID, parentID: 'parent' }));
+ const counts = [];
+ for (let step = 0; step < 2; step++) {
+ const event = makeEvent(flavor, id);
+ await h.invoke(event);
+ counts.push(bootstrapCount(event));
+ }
+ assert.deepEqual(counts, [1, 0], `${id}: recover on the next request`);
+ assert.deepEqual(h.lookups, [id, id], `${id}: never cache the failure`);
+ }
+
+ const isolated = await makeHarness(flavor, (id) => reply(flavor,
+ id === 'child-session' ? { id, parentID: 'parent' } : { id }));
+ for (const [id, expected] of [['root-session', 1], ['child-session', 0], ['root-session', 1], ['child-session', 0]]) {
+ const event = makeEvent(flavor, id);
+ await isolated.invoke(event);
+ assert.equal(bootstrapCount(event), expected);
+ }
+ assert.deepEqual(isolated.lookups, ['root-session', 'child-session']);
+
+ const bounded = await makeHarness(flavor, (id) => reply(flavor, { id, parentID: 'parent' }));
+ for (let index = 0; index <= 512; index++) {
+ const event = makeEvent(flavor, `eviction-${index}`);
+ await bounded.invoke(event);
+ assert.equal(bootstrapCount(event), 0);
+ }
+ const evicted = makeEvent(flavor, 'eviction-0');
+ await bounded.invoke(evicted);
+ assert.equal(bootstrapCount(evicted), 0);
+ assert.equal(bounded.lookups.filter((id) => id === 'eviction-0').length, 2);
+
+ const restarted = await makeHarness(flavor, (id) => reply(flavor, { id, parentID: 'parent' }));
+ const afterRestart = makeEvent(flavor, 'eviction-0');
+ await restarted.invoke(afterRestart);
+ assert.equal(bootstrapCount(afterRestart), 0);
+ assert.deepEqual(restarted.lookups, ['eviction-0']);
+
+ const unknown = await makeHarness(flavor, () => { throw new Error('must not look up a missing ID'); });
+ const noID = makeEvent(flavor, undefined);
+ await unknown.invoke(noID);
+ assert.equal(bootstrapCount(noID), 1);
+ assert.deepEqual(unknown.lookups, []);
+}
+
+function compactedEvent(sessionID) {
+ return {
+ sessionID,
+ system: [],
+ messages: [{
+ role: 'assistant',
+ content: [{ type: 'compaction', provider: 'fixture', encrypted: 'opaque-checkpoint' }],
+ }],
+ };
+}
+
+const compactedRoot = await makeHarness('v2', (id) => ({ id }));
+const rootEvent = compactedEvent('compacted-root');
+const checkpoint = structuredClone(rootEvent.messages[0]);
+await compactedRoot.invoke(rootEvent);
+assert.equal(bootstrapCount(rootEvent), 1);
+assert.deepEqual(rootEvent.messages[0], checkpoint);
+assert.equal(rootEvent.messages.length, 2);
+assert.equal(rootEvent.messages[1].role, 'user');
+assert.deepEqual(rootEvent.system, []);
+await compactedRoot.invoke(rootEvent);
+assert.equal(bootstrapCount(rootEvent), 1);
+assert.equal(rootEvent.messages.length, 2);
+const freshRootEvent = compactedEvent('compacted-root');
+await compactedRoot.invoke(freshRootEvent);
+assert.equal(bootstrapCount(freshRootEvent), 1);
+assert.deepEqual(compactedRoot.lookups, ['compacted-root']);
+
+const compactedChild = await makeHarness('v2', (id) => ({ id, parentID: 'parent' }));
+const childEvent = compactedEvent('compacted-child');
+const originalChild = structuredClone(childEvent);
+await compactedChild.invoke(childEvent);
+assert.equal(bootstrapCount(childEvent), 0);
+assert.deepEqual(childEvent, originalChild);
+assert.deepEqual(compactedChild.lookups, ['compacted-child']);
+
+const retryChild = await makeHarness('v2', (id, call) => {
+ if (call === 1) throw new Error('temporary lookup failure');
+ return { id, parentID: 'parent' };
+});
+const unknownChild = compactedEvent('retry-compacted-child');
+await retryChild.invoke(unknownChild);
+assert.equal(bootstrapCount(unknownChild), 1);
+const recoveredChild = compactedEvent('retry-compacted-child');
+await retryChild.invoke(recoveredChild);
+assert.equal(bootstrapCount(recoveredChild), 0);
+assert.equal(recoveredChild.messages.length, 1);
+assert.equal(retryChild.lookups.length, 2);
+
+const newPromptAfterCheckpoint = compactedEvent('new-prompt-after-checkpoint-root');
+newPromptAfterCheckpoint.messages.push({ role: 'user', content: [{ type: 'text', text: 'Continue' }] });
+await compactedRoot.invoke(newPromptAfterCheckpoint);
+assert.equal(bootstrapCount(newPromptAfterCheckpoint), 1);
+assert.equal(newPromptAfterCheckpoint.messages.length, 2);
+assert.equal(newPromptAfterCheckpoint.messages[1].content.length, 2);
+
+const retainedUser = compactedEvent('retained-user-root');
+retainedUser.messages.unshift({ role: 'user', content: [{ type: 'text', text: 'Keep going' }] });
+const retainedCheckpoint = structuredClone(retainedUser.messages[1]);
+await compactedRoot.invoke(retainedUser);
+assert.equal(bootstrapCount(retainedUser), 1);
+assert.equal(retainedUser.messages.length, 2);
+assert.equal(retainedUser.messages[0].content.length, 2);
+assert.ok(retainedUser.messages[0].content[0].text.startsWith(marker));
+assert.equal(retainedUser.messages[0].content[1].text, 'Keep going');
+assert.deepEqual(retainedUser.messages[1], retainedCheckpoint);
+await compactedRoot.invoke(retainedUser);
+assert.equal(bootstrapCount(retainedUser), 1);
+assert.equal(retainedUser.messages.length, 2);
+
+const retainedUserChild = compactedEvent('retained-user-child');
+retainedUserChild.messages.unshift({ role: 'user', content: [{ type: 'text', text: 'Keep going' }] });
+const originalRetainedUserChild = structuredClone(retainedUserChild);
+await compactedChild.invoke(retainedUserChild);
+assert.equal(bootstrapCount(retainedUserChild), 0);
+assert.deepEqual(retainedUserChild, originalRetainedUserChild);
+const empty = { sessionID: 'empty', messages: [] };
+await compactedRoot.invoke(empty);
+assert.deepEqual(empty.messages, []);
+
+console.log('Session classification, recovery and cache lifetime passed');
diff --git a/tests/opencode/test-session-bootstrap.sh b/tests/opencode/test-session-bootstrap.sh
new file mode 100755
index 0000000..accd85b
--- /dev/null
+++ b/tests/opencode/test-session-bootstrap.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+set -euo pipefail
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+node "$SCRIPT_DIR/test-session-bootstrap.mjs" "$SCRIPT_DIR/../../.opencode/plugins/superpowers.js"
diff --git a/tests/opencode/test-skill-registration.mjs b/tests/opencode/test-skill-registration.mjs
new file mode 100644
index 0000000..a31fe4a
--- /dev/null
+++ b/tests/opencode/test-skill-registration.mjs
@@ -0,0 +1,205 @@
+import fs from 'fs';
+import os from 'os';
+import path from 'path';
+import { pathToFileURL } from 'url';
+
+// Verifies the V2 skill registration payload matches OpenCode 2.0.4's
+// Skill.Info contract (packages/schema/src/skill.ts):
+// { id, name, description?, autoinvoke?, path, content }
+// Upstream commit 199aabe9e2 (first released in v2.0.4) renamed the required
+// file field `location` -> `path`. A wrong field name makes draft.add()
+// throw inside the host's transform rebuild, which asynchronously disables
+// the whole plugin ("Plugin disabled after skill.transform failed") and
+// takes the bootstrap hook down with it — see PR #2106 review by 80avin.
+
+const [, , inputPath] = process.argv;
+
+if (!inputPath) {
+ console.error('Usage: node test-skill-registration.mjs PLUGIN_PATH');
+ process.exit(2);
+}
+
+const pluginPath = fs.realpathSync(inputPath);
+const skillsDir = path.resolve(path.dirname(pluginPath), '../../skills');
+const mod = await import(pathToFileURL(pluginPath).href);
+
+const failures = [];
+
+// --- Run 1: passive capture of every draft.add payload -------------------
+const added = [];
+await mod.default.setup(makeCtx({ add: (skill) => added.push(skill) }));
+
+const expectedIds = fs.existsSync(skillsDir)
+ ? fs.readdirSync(skillsDir, { withFileTypes: true })
+ .filter((e) => e.isDirectory() && !e.name.startsWith('.'))
+ .filter((e) => fs.existsSync(path.join(skillsDir, e.name, 'SKILL.md')))
+ .map((e) => e.name)
+ .sort()
+ : [];
+
+if (added.length === 0) {
+ failures.push('expected setup() to register at least one skill via draft.add()');
+}
+if (JSON.stringify(added.map((s) => s.id).sort()) !== JSON.stringify(expectedIds)) {
+ failures.push(`expected draft.add() ids to match skills dir contents, got ${JSON.stringify(added.map((s) => s.id))}`);
+}
+
+for (const skill of added) {
+ if (typeof skill.path !== 'string' || !path.isAbsolute(skill.path)) {
+ failures.push(`skill "${skill.id}": expected required absolute Skill.Info field "path", got ${JSON.stringify(skill.path)}`);
+ } else if (skill.path !== path.join(skillsDir, skill.id, 'SKILL.md')) {
+ failures.push(`skill "${skill.id}": expected path ${path.join(skillsDir, skill.id, 'SKILL.md')}, got ${skill.path}`);
+ } else if (!fs.existsSync(skill.path)) {
+ failures.push(`skill "${skill.id}": path does not exist on disk: ${skill.path}`);
+ }
+ // Stale 2.0.3-era fields must not leak into the payload: the host strips
+ // unknown keys, but keeping them would silently mask a future regression
+ // to a schema that no longer accepts `path`.
+ if ('location' in skill) {
+ failures.push(`skill "${skill.id}": payload still carries the pre-2.0.4 field "location"`);
+ }
+ if ('slash' in skill) {
+ failures.push(`skill "${skill.id}": payload carries "slash", removed from Skill.Info in 2.0.4`);
+ }
+ if (typeof skill.id !== 'string' || skill.id.length === 0) failures.push(`skill payload missing non-empty "id"`);
+ if (typeof skill.name !== 'string' || skill.name.length === 0) failures.push(`skill "${skill.id}" missing non-empty "name"`);
+ if (typeof skill.content !== 'string' || !skill.content.trim()) failures.push(`skill "${skill.id}" missing non-empty "content"`);
+ if ('description' in skill && typeof skill.description !== 'string') {
+ failures.push(`skill "${skill.id}": "description" must be a string when present`);
+ } else if ('description' in skill && /["']$/.test(skill.description)) {
+ failures.push(`skill "${skill.id}": description ends with a dangling quote: ${JSON.stringify(skill.description)}`);
+ }
+ if (typeof skill.content === 'string' && skill.content.startsWith('---')) {
+ failures.push(`skill "${skill.id}": content still starts with the frontmatter delimiter`);
+ }
+}
+
+// --- Run 2: hostile draft.add must not abort the remaining registrations --
+// The real host swallows a throw escaping the transform callback and then
+// hard-disables the plugin asynchronously. Locally we can only observe the
+// synchronous half of that contract: when draft.add() rejects one skill, the
+// plugin must keep registering the rest instead of aborting the loop.
+const hostileId = added.length > 1 ? added[Math.floor(added.length / 2)].id : null;
+const survived = [];
+let setupThrew = null;
+let survivingContextHook;
+try {
+ await mod.default.setup(makeCtx({
+ add: (skill) => {
+ if (skill.id === hostileId) throw new Error('Simulated Skill.Info decode failure');
+ survived.push(skill.id);
+ },
+ onHook: (name, callback) => {
+ if (name === 'context') survivingContextHook = callback;
+ },
+ }));
+} catch (err) {
+ setupThrew = err;
+}
+if (setupThrew) {
+ failures.push(`expected setup() to contain draft.add() failures, but it threw: ${setupThrew.message}`);
+} else if (hostileId) {
+ const expectedSurvivors = added.map((s) => s.id).filter((id) => id !== hostileId);
+ if (JSON.stringify(survived.sort()) !== JSON.stringify(expectedSurvivors.sort())) {
+ failures.push(`expected all non-rejected skills to still register when one draft.add() throws, got ${JSON.stringify(survived)}`);
+ }
+}
+if (typeof survivingContextHook !== 'function') {
+ failures.push('expected bootstrap hook to survive a rejected skill');
+} else {
+ const event = {
+ sessionID: 'registration-survival-root',
+ messages: [{ role: 'user', content: [{ type: 'text', text: 'Continue' }] }],
+ };
+ await survivingContextHook(event);
+ const count = event.messages.flatMap((message) => message.content).filter(
+ (part) => part.type === 'text' && part.text.startsWith('<EXTREMELY_IMPORTANT>\nYou have superpowers.')
+ ).length;
+ if (count !== 1) failures.push(`expected surviving bootstrap once, got ${count}`);
+}
+
+// --- Run 3: quoted and multi-line frontmatter values ---------------------
+// The description is what the host shows in its skill list. A quoted value
+// that wraps onto indented continuation lines must register as one unquoted
+// line, so exercise each layout against a synthetic install: a copy of the
+// plugin next to fixture skills, laid out like a real package root.
+const frontmatterFixtures = {
+ 'multi-line-double': {
+ frontmatter: 'description: "Use when foo happens\n and bar continues\n and baz ends"',
+ expected: 'Use when foo happens and bar continues and baz ends',
+ },
+ 'multi-line-single': {
+ frontmatter: "description: 'Use when foo happens\n and bar continues\n and baz ends'",
+ expected: 'Use when foo happens and bar continues and baz ends',
+ },
+ 'single-line-quoted': {
+ frontmatter: 'description: "Plain quoted"',
+ expected: 'Plain quoted',
+ },
+ 'block-scalar': {
+ frontmatter: 'description: >\n Folded line one\n line two',
+ expected: 'Folded line one line two',
+ },
+};
+const fixtureRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'superpowers-frontmatter-'));
+try {
+ const fixturePlugin = path.join(fixtureRoot, '.opencode', 'plugins', 'superpowers.js');
+ fs.mkdirSync(path.dirname(fixturePlugin), { recursive: true });
+ fs.copyFileSync(pluginPath, fixturePlugin);
+ for (const [id, { frontmatter }] of Object.entries(frontmatterFixtures)) {
+ const skillDir = path.join(fixtureRoot, 'skills', id);
+ fs.mkdirSync(skillDir, { recursive: true });
+ fs.writeFileSync(path.join(skillDir, 'SKILL.md'), `---\nname: ${id}\n${frontmatter}\n---\n# Title\n\nBody.\n`);
+ }
+ const fixtureMod = await import(pathToFileURL(fixturePlugin).href);
+ const fixtureAdded = [];
+ await fixtureMod.default.setup(makeCtx({ add: (skill) => fixtureAdded.push(skill) }));
+ for (const [id, { expected }] of Object.entries(frontmatterFixtures)) {
+ const skill = fixtureAdded.find((s) => s.id === id);
+ if (!skill) {
+ failures.push(`fixture "${id}": expected setup() to register it`);
+ continue;
+ }
+ if (skill.description !== expected) {
+ failures.push(`fixture "${id}": expected description ${JSON.stringify(expected)}, got ${JSON.stringify(skill.description)}`);
+ }
+ if (skill.content.startsWith('---')) {
+ failures.push(`fixture "${id}": content still starts with the frontmatter delimiter`);
+ }
+ }
+} finally {
+ fs.rmSync(fixtureRoot, { recursive: true, force: true });
+}
+
+const result = {
+ registered: added.length,
+ ids: added.map((s) => s.id),
+ allPathsValid: added.every((s) => s.path === path.join(skillsDir, s.id, 'SKILL.md') && fs.existsSync(s.path)),
+ staleLocationField: added.some((s) => 'location' in s),
+ hostileRejectedId: hostileId,
+ survivedHostileAdd: JSON.stringify(survived.sort()) === JSON.stringify(added.map((s) => s.id).filter((id) => id !== hostileId).sort()),
+};
+
+if (failures.length > 0) {
+ console.error(JSON.stringify(result, null, 2));
+ for (const failure of failures) {
+ console.error(`FAIL: ${failure}`);
+ }
+ process.exit(1);
+}
+
+console.log(JSON.stringify(result, null, 2));
+
+function makeCtx({ add, onHook = () => {} }) {
+ return {
+ skill: {
+ transform: async (fn) => {
+ await fn({ list: () => [], get: () => undefined, add, update: () => {}, remove: () => {} });
+ },
+ },
+ session: {
+ hook: async (name, callback) => onHook(name, callback),
+ get: async ({ sessionID }) => ({ id: sessionID }), // top-level: no parentID
+ },
+ };
+}
diff --git a/tests/opencode/test-skill-registration.sh b/tests/opencode/test-skill-registration.sh
new file mode 100755
index 0000000..ac882a4
--- /dev/null
+++ b/tests/opencode/test-skill-registration.sh
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+# Test: V2 Skill Registration Contract (#2106 review)
+# Verifies setup() registers skills matching OpenCode 2.0.4's Skill.Info
+# schema (path field, no stale location/slash) and contains per-skill
+# draft.add() failures instead of aborting registration.
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+
+echo "=== Test: V2 Skill Registration Contract ==="
+
+source "$SCRIPT_DIR/setup.sh"
+trap cleanup_test_env EXIT
+
+node "$SCRIPT_DIR/test-skill-registration.mjs" "$SUPERPOWERS_PLUGIN_FILE"
+node "$SCRIPT_DIR/test-skill-registration.mjs" "$OPENCODE_CONFIG_DIR/plugins/superpowers.js"
+
+echo " [PASS] Skill payloads match the 2.0.4 Skill.Info contract"
+echo " [PASS] A rejected draft.add() skips one skill without aborting the rest"
+echo " [PASS] Quoted and multi-line frontmatter values register unquoted"
+echo ""
+echo "=== All skill registration tests passed ==="