diff options
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/antigravity/test-antigravity-tools.sh | 10 | ||||
| -rwxr-xr-x | tests/antigravity/test-logo.sh | 44 | ||||
| -rwxr-xr-x | tests/antigravity/test-plugin-manifest.sh | 107 | ||||
| -rw-r--r-- | tests/brainstorm-server/lifecycle.test.js | 6 | ||||
| -rw-r--r-- | tests/brainstorm-server/server.test.js | 17 | ||||
| -rwxr-xr-x | tests/claude-code/test-executing-plans-scripts.sh | 27 | ||||
| -rwxr-xr-x | tests/claude-code/test-sdd-workspace.sh | 30 | ||||
| -rwxr-xr-x | tests/codex-plugin-sync/test-sync-to-codex-plugin.sh | 14 | ||||
| -rw-r--r-- | tests/hermes/conftest.py | 4 | ||||
| -rw-r--r-- | tests/hermes/test_plugin.py | 36 | ||||
| -rwxr-xr-x | tests/hooks/test-run-hook-cmd-windows.sh | 223 | ||||
| -rwxr-xr-x | tests/hooks/test-session-start.sh | 100 | ||||
| -rw-r--r-- | tests/version-bump/test-bump-version.sh | 13 | ||||
| -rwxr-xr-x | tests/writing-skills/test-render-graphs.sh | 4 |
14 files changed, 623 insertions, 12 deletions
diff --git a/tests/antigravity/test-antigravity-tools.sh b/tests/antigravity/test-antigravity-tools.sh index e10edd4..ca83065 100755 --- a/tests/antigravity/test-antigravity-tools.sh +++ b/tests/antigravity/test-antigravity-tools.sh @@ -1,10 +1,8 @@ #!/usr/bin/env bash -# Validate the Antigravity (agy) integration. agy installs the existing plugin -# directly (`agy plugin install <repo-url>`): it loads the bundled skills and -# runs the SessionStart hook for bootstrap, so there is no agy-specific scaffold -# to test. What IS agy-specific is the tool mapping — subagent dispatch via -# invoke_subagent (self/research types) and task tracking via a task artifact — -# and SKILL.md pointing at it. +# Validate the Antigravity (agy) tool mapping: subagent dispatch via +# invoke_subagent (self/research types), task tracking via a task artifact, and +# SKILL.md pointing at the mapping. The plugin manifest and layout are checked +# by test-plugin-manifest.sh. # # Mirrors tests/pi/test-pi-extension.mjs's "tools reference documents # harness-specific mappings" check. CI-safe: does not require `agy` installed. diff --git a/tests/antigravity/test-logo.sh b/tests/antigravity/test-logo.sh new file mode 100755 index 0000000..6132e47 --- /dev/null +++ b/tests/antigravity/test-logo.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# Check the Antigravity Marketplace logo: a square RGBA PNG at least 128x128 +# (the Marketplace minimum), at the path the manifest names. When rsvg-convert +# is available, also check the committed PNG matches a fresh render, so the +# asset can't drift from scripts/render-antigravity-logo.sh. +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +LOGO="$REPO_ROOT/assets/antigravity-logo.png" + +fail() { echo "FAIL: $*" >&2; exit 1; } + +echo "test-logo: checking Antigravity logo" + +[ -f "$LOGO" ] || fail "logo missing at $LOGO" + +python3 - "$LOGO" <<'PY' +import struct +import sys + +data = open(sys.argv[1], "rb").read() +if data[:8] != b"\x89PNG\r\n\x1a\n": + raise SystemExit("FAIL: logo is not a PNG") +width, height, bit_depth, color_type = struct.unpack(">IIBB", data[16:26]) +if width != height: + raise SystemExit(f"FAIL: logo is not square ({width}x{height})") +if width < 128: + raise SystemExit(f"FAIL: logo is smaller than 128x128 ({width}x{height})") +if color_type != 6: + raise SystemExit(f"FAIL: logo is not RGBA (PNG color type {color_type})") +PY + +if command -v rsvg-convert >/dev/null 2>&1; then + tmp="$(mktemp -d)" + trap 'rm -f "$tmp/logo.png"; rmdir "$tmp"' EXIT + bash "$REPO_ROOT/scripts/render-antigravity-logo.sh" --output "$tmp/logo.png" >/dev/null + cmp -s "$tmp/logo.png" "$LOGO" \ + || fail "assets/antigravity-logo.png is stale; run scripts/render-antigravity-logo.sh" +else + echo "SKIP: rsvg-convert not on PATH; not checking logo freshness" +fi + +echo "PASS: Antigravity logo valid" diff --git a/tests/antigravity/test-plugin-manifest.sh b/tests/antigravity/test-plugin-manifest.sh new file mode 100755 index 0000000..ca2dad7 --- /dev/null +++ b/tests/antigravity/test-plugin-manifest.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash +# Validate the native Antigravity plugin: the Marketplace manifest, the skill +# description agy relies on to bootstrap using-superpowers, and the repo layout +# agy depends on. CI-safe; when `agy` is on PATH, also runs `agy plugin validate`. +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" + +echo "test-plugin-manifest: checking Antigravity plugin" + +python3 - "$REPO_ROOT" <<'PY' +import json +import re +import struct +import sys +from pathlib import Path + +root = Path(sys.argv[1]) + +def fail(message): + raise SystemExit(f"FAIL: {message}") + +manifest_path = root / ".antigravity-plugin" / "plugin.json" +if not manifest_path.is_file(): + fail(f"manifest missing at {manifest_path}") +manifest = json.loads(manifest_path.read_text(encoding="utf-8")) + +# --- Marketplace-required fields ------------------------------------------- +for field in ["name", "description", "displayName", "logo", + "suggestedPrompts", "version", "author"]: + if not manifest.get(field): + fail(f"manifest field {field!r} is missing or empty") + +if manifest["name"] != "superpowers": + fail(f"name must be 'superpowers', got {manifest['name']!r}") +if not re.fullmatch(r"[a-z0-9]+(-[a-z0-9]+)*", manifest["name"]): + fail("name is not kebab-case") + +description_length = len(manifest["description"]) +# The guide recommends 120-160 characters for Marketplace cards; we use a +# shorter tagline by choice, so enforce only the upper bound. +if description_length > 160: + fail(f"description is {description_length} characters; Marketplace cards fit at most 160") + +prompts = manifest["suggestedPrompts"] +if not isinstance(prompts, list) or not 1 <= len(prompts) <= 3: + fail("suggestedPrompts must be a list of 1-3 prompts") +if not all(isinstance(p, str) and p.strip() for p in prompts): + fail("suggestedPrompts entries must be non-empty strings") + +claude_manifest = json.loads( + (root / ".claude-plugin" / "plugin.json").read_text(encoding="utf-8")) +if manifest["version"] != claude_manifest["version"]: + fail(f"version {manifest['version']!r} != .claude-plugin version " + f"{claude_manifest['version']!r}") +if manifest["author"] != claude_manifest["author"]: + fail("author does not match .claude-plugin/plugin.json") + +# --- Logo ------------------------------------------------------------------ +logo = root / manifest["logo"] +if not logo.is_file(): + fail(f"logo {manifest['logo']!r} does not exist") +header = logo.read_bytes()[:26] +if header[:8] != b"\x89PNG\r\n\x1a\n": + fail("logo is not a PNG") +width, height = struct.unpack(">II", header[16:24]) +if width != height or width < 128: + fail(f"logo must be square and at least 128x128, got {width}x{height}") + +# --- Version bumps --------------------------------------------------------- +version_config = json.loads((root / ".version-bump.json").read_text(encoding="utf-8")) +if not any(entry.get("path") == ".antigravity-plugin/plugin.json" + and entry.get("field") == "version" + for entry in version_config.get("files", [])): + fail(".version-bump.json does not register .antigravity-plugin/plugin.json") + +# --- Bootstrap: agy lists each skill's description, and using-superpowers' +# description is what gets the model to load it at the start of a session. +skill_md = (root / "skills" / "using-superpowers" / "SKILL.md").read_text(encoding="utf-8") +frontmatter = re.match(r"---\n(.*?)\n---\n", skill_md, re.DOTALL) +description = frontmatter and re.search(r"^description:(.*)$", frontmatter.group(1), re.MULTILINE) +if not description or "Use when starting any conversation" not in description.group(1): + fail("using-superpowers description no longer says 'Use when starting any " + "conversation'; Antigravity relies on it to bootstrap") + +# --- Layout agy depends on ------------------------------------------------- +# A root plugin.json would be read instead of .antigravity-plugin/plugin.json, +# a root hooks.json would run on every model call, and Cursor loads any +# rules/*.md shipped in a plugin. +for stray in ["plugin.json", "hooks.json", "rules"]: + if (root / stray).exists(): + fail(f"root {stray} must not exist") +PY + +if command -v agy >/dev/null 2>&1; then + output="$(agy plugin validate "$REPO_ROOT" 2>&1)" \ + || { echo "$output" >&2; echo "FAIL: agy plugin validate failed" >&2; exit 1; } + grep -q '\[ok\]' <<<"$output" \ + || { echo "$output" >&2; echo "FAIL: agy plugin validate did not report [ok]" >&2; exit 1; } + grep -qE 'skills +: [0-9]+ processed' <<<"$output" \ + || { echo "$output" >&2; echo "FAIL: agy found no skills" >&2; exit 1; } +else + echo "SKIP: agy not on PATH; not running agy plugin validate" +fi + +echo "PASS: Antigravity plugin manifest and layout valid" diff --git a/tests/brainstorm-server/lifecycle.test.js b/tests/brainstorm-server/lifecycle.test.js index c43d8c0..83b3193 100644 --- a/tests/brainstorm-server/lifecycle.test.js +++ b/tests/brainstorm-server/lifecycle.test.js @@ -102,16 +102,16 @@ async function waitForStartedOutput(child, timeoutMs = 5000) { } function makeShellTempDir(prefix) { - return execFileSync('bash', ['-lc', `mktemp -d "\${TMPDIR:-/tmp}/${prefix}-XXXXXX"`], { encoding: 'utf8' }).trim(); + return execFileSync('bash', ['-c', `mktemp -d "\${TMPDIR:-/tmp}/${prefix}-XXXXXX"`], { encoding: 'utf8' }).trim(); } function removeShellPath(p) { - execFileSync('bash', ['-lc', 'rm -rf "$1"', 'bash', p], { stdio: 'ignore' }); + execFileSync('bash', ['-c', 'rm -rf "$1"', 'bash', p], { stdio: 'ignore' }); } function newestSessionDir(projectDir) { const sessionDir = execFileSync('bash', [ - '-lc', + '-c', 'find "$1/.superpowers/brainstorm" -mindepth 1 -maxdepth 1 -type d -print | sort | tail -1', 'bash', projectDir diff --git a/tests/brainstorm-server/server.test.js b/tests/brainstorm-server/server.test.js index 5d62323..510ee98 100644 --- a/tests/brainstorm-server/server.test.js +++ b/tests/brainstorm-server/server.test.js @@ -211,6 +211,20 @@ async function runTests() { assert(res.body.includes('data-choice="a"'), 'Fragment interactive elements intact'); }); + await test('preserves literal replacement tokens in content fragments', async () => { + const tokens = ["$'", '$`', '$&', '$$', '$1', '$<name>']; + const fragment = '<h2>Literal tokens</h2><pre>' + tokens.join(' | ') + '</pre>'; + fs.writeFileSync(path.join(CONTENT_DIR, 'literal-tokens.html'), fragment); + await sleep(300); + + const res = await fetch(`http://localhost:${TEST_PORT}/`); + assert.strictEqual(res.status, 200); + assert(res.body.includes(fragment), 'Fragment must be inserted verbatim'); + assert.strictEqual(res.body.split('<div class="header">').length - 1, 1, 'Frame chrome must not be duplicated'); + assert(!res.body.includes('<!-- CONTENT -->'), 'Replacement tokens must not restore the placeholder'); + assert(res.body.includes('WebSocket'), 'Helper must still be injected'); + }); + await test('serves newest file by mtime', async () => { fs.writeFileSync(path.join(CONTENT_DIR, 'older.html'), '<h2>Older</h2>'); await sleep(100); @@ -577,7 +591,8 @@ async function runTests() { // ========== Summary ========== console.log(`\n--- Results: ${passed} passed, ${failed} failed, ${skipped} skipped ---`); - if (failed > 0) process.exit(1); + // exitCode, not exit(): exit() would skip the finally below and orphan the server. + if (failed > 0) process.exitCode = 1; } finally { server.kill(); diff --git a/tests/claude-code/test-executing-plans-scripts.sh b/tests/claude-code/test-executing-plans-scripts.sh index 994733b..e4e3904 100755 --- a/tests/claude-code/test-executing-plans-scripts.sh +++ b/tests/claude-code/test-executing-plans-scripts.sh @@ -33,6 +33,8 @@ main() { git init -q -b main "$TEST_ROOT/repo" local repo repo="$(cd "$TEST_ROOT/repo" && git rev-parse --show-toplevel)" + # Same spelling as the scripts print (pwd), not rev-parse's C:/... on Git Bash. + repo="$(cd "$repo" && pwd)" local git_id=(-c user.email=t@example.com -c user.name=t -c commit.gpgsign=false) cat > "$repo/plan.md" <<'PLAN' @@ -127,6 +129,31 @@ PLAN echo " got: $out" fi + # --- task-done: records a passing task whose test command prints nothing --- + # https://github.com/obra/superpowers/issues/2385 -- under `set -euo + # pipefail`, the ledger's `grep -v '^[[:space:]]*$' log | tail -n 1` + # exits 1 on an empty/blank log, which used to abort the whole script + # (silently, no ledger line) even though the test command itself passed. + ( cd "$repo" && echo y > work2.txt && git add work2.txt && git "${git_id[@]}" commit -qm "task 2" ) + local head2 + head2="$(cd "$repo" && git rev-parse HEAD)" + rc=0 + out="$(cd "$repo" && "$EP_SCRIPTS/task-done" plan.md 2 "$head" -- true 2>&1)" || rc=$? + if [[ "$rc" -eq 0 ]]; then + pass "task-done exits 0 when a passing test command prints nothing" + else + fail "task-done exits 0 when a passing test command prints nothing (got rc=$rc)" + echo " got: $out" + fi + local expected2="Task 2: complete (commits ${head:0:7}..${head2:0:7}, tests: true → (no output))" + if [[ -f "$ledger" ]] && grep -qF "$expected2" "$ledger"; then + pass "task-done records a passing task that printed no output" + else + fail "task-done records a passing task that printed no output" + echo " expected: $expected2" + echo " ledger:"; sed 's/^/ /' "$ledger" 2>/dev/null || echo " (missing)" + fi + echo if [[ "$FAILURES" -eq 0 ]]; then echo "PASS" diff --git a/tests/claude-code/test-sdd-workspace.sh b/tests/claude-code/test-sdd-workspace.sh index 2e8c227..16cf50d 100755 --- a/tests/claude-code/test-sdd-workspace.sh +++ b/tests/claude-code/test-sdd-workspace.sh @@ -17,6 +17,16 @@ fail() { FAILURES=$((FAILURES + 1)) } +# Push a path through the same `cd ... && pwd` normalization that +# sdd-workspace's own printed output goes through, so both sides of a +# string comparison are guaranteed to be spelled identically. On Windows +# Git Bash/MSYS, `git rev-parse --show-toplevel` (Windows-style, +# C:/Users/...) and `cd ... && pwd` (MSYS-style, /c/Users/...) can print +# different spellings of the identical physical directory; on Linux/macOS +# this is a no-op since the two already agree (module the resolved-symlink +# /var -> /private/var case handled by the mktemp comment above). +physical_path() { (cd "$1" && pwd); } + cleanup() { if [[ -n "$TEST_ROOT" && -d "$TEST_ROOT" ]]; then rm -rf "$TEST_ROOT" @@ -35,6 +45,7 @@ main() { git init -q -b main "$TEST_ROOT/repo" local repo repo="$(cd "$TEST_ROOT/repo" && git rev-parse --show-toplevel)" + repo="$(physical_path "$repo")" cat > "$repo/plan-a.md" <<'PLAN' # Plan A @@ -194,6 +205,7 @@ PLAN ( cd "$repo" && git worktree add -q "$wt" -b wt-feature ) local wt_root wt_dir wt_root="$(cd "$wt" && git rev-parse --show-toplevel)" + wt_root="$(physical_path "$wt_root")" wt_dir="$(cd "$wt" && "$SDD_SCRIPTS/sdd-workspace" plan-a.md)" if [[ "$wt_dir" == "$wt_root/.superpowers/sdd/plan-a" && "$wt_dir" != "$dir_a" ]]; then pass "linked worktree resolves its own distinct workspace" @@ -350,6 +362,24 @@ PLAN echo " marker: $(cat "$dir_out/plan-path" 2>/dev/null)" fi + # --- A repo's own committed .superpowers/sdd/.gitignore is left alone --- + git init -q -b main "$TEST_ROOT/own-ignore" + local own own_ignore + own="$(cd "$TEST_ROOT/own-ignore" && git rev-parse --show-toplevel)" + own_ignore=$'*\n!.gitignore\n!*/\n!*/progress.md' + mkdir -p "$own/.superpowers/sdd" + printf '%s\n' "$own_ignore" > "$own/.superpowers/sdd/.gitignore" + printf '# Plan\n\n## Task 1: One\n\nOne.\n' > "$own/plan.md" + (cd "$own" && git add -A && git -c user.name=t -c user.email=t@t commit -qm init) + (cd "$own" && "$SDD_SCRIPTS/sdd-workspace" plan.md >/dev/null) + if [[ "$(cat "$own/.superpowers/sdd/.gitignore")" == "$own_ignore" \ + && -z "$(cd "$own" && git status --porcelain -- .superpowers/sdd/.gitignore)" ]]; then + pass "an existing .superpowers/sdd/.gitignore is not overwritten" + else + fail "an existing .superpowers/sdd/.gitignore is not overwritten" + echo " now: $(cat "$own/.superpowers/sdd/.gitignore")" + 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 265aea1..84282c2 100755 --- a/tests/codex-plugin-sync/test-sync-to-codex-plugin.sh +++ b/tests/codex-plugin-sync/test-sync-to-codex-plugin.sh @@ -174,6 +174,7 @@ write_upstream_fixture() { local with_pure_ignored="${2:-1}" mkdir -p \ + "$repo/.antigravity-plugin" \ "$repo/.codex-plugin" \ "$repo/.kimi-plugin" \ "$repo/.private-journal" \ @@ -241,6 +242,15 @@ EOF } EOF + cat > "$repo/.antigravity-plugin/plugin.json" <<EOF +{ + "name": "superpowers", + "version": "$MANIFEST_VERSION" +} +EOF + + printf 'antigravity png fixture\n' > "$repo/assets/antigravity-logo.png" + cat > "$repo/assets/superpowers-small.svg" <<'EOF' <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1"></svg> EOF @@ -295,11 +305,13 @@ EOF fi git -C "$repo" add \ + .antigravity-plugin/plugin.json \ .codex-plugin/plugin.json \ .kimi-plugin/plugin.json \ .gitignore \ .gitmodules \ .pre-commit-config.yaml \ + assets/antigravity-logo.png \ assets/app-icon.png \ assets/superpowers-small.svg \ evals/drill/README.md \ @@ -657,6 +669,8 @@ main() { assert_not_contains "$preview_output" "Version: $PACKAGE_VERSION" "Preview does not use package.json version" assert_contains "$preview_section" ".codex-plugin/plugin.json" "Preview includes manifest path" assert_not_contains "$preview_section" ".kimi-plugin/plugin.json" "Preview excludes Kimi manifest from Codex sync" + assert_not_contains "$preview_section" ".antigravity-plugin/plugin.json" "Preview excludes Antigravity manifest from Codex sync" + assert_not_contains "$preview_section" "assets/antigravity-logo.png" "Preview excludes Antigravity logo from Codex sync" assert_contains "$preview_section" "assets/superpowers-small.svg" "Preview includes SVG asset" assert_contains "$preview_section" "assets/app-icon.png" "Preview includes PNG asset" assert_contains "$preview_section" "hooks/hooks-codex.json" "Preview includes Codex hook manifest" diff --git a/tests/hermes/conftest.py b/tests/hermes/conftest.py index 561cd8c..ec22bed 100644 --- a/tests/hermes/conftest.py +++ b/tests/hermes/conftest.py @@ -9,11 +9,12 @@ def mock_ctx(): ctx = MagicMock() ctx._hooks = {} ctx._skills = {} + ctx._descriptions = {} def register_hook(event, fn): ctx._hooks[event] = fn - def register_skill(name, path): + def register_skill(name, path, description="", frontmatter=None): # Mimic hermes' real register_skill, which calls path.exists() and # therefore breaks on a str (the bug that silently disabled the whole # plugin, found 2026-07-23). Keeping that fidelity here means a @@ -24,6 +25,7 @@ def mock_ctx(): f"register_skill requires a pathlib.Path, got {type(path).__name__}" ) ctx._skills[name] = path + ctx._descriptions[name] = description ctx.register_hook.side_effect = register_hook ctx.register_skill.side_effect = register_skill diff --git a/tests/hermes/test_plugin.py b/tests/hermes/test_plugin.py index 9c6c4f0..57d619e 100644 --- a/tests/hermes/test_plugin.py +++ b/tests/hermes/test_plugin.py @@ -1,6 +1,7 @@ import importlib import importlib.util import os +import re import shutil import sys from pathlib import Path @@ -140,3 +141,38 @@ class TestLayoutResolution: mod = self._load_from(plugdir) with pytest.raises(RuntimeError, match="cannot find the skills"): mod.register(mock_ctx) + + +class TestSkillDescriptions: + """Hermes builds its skill catalogue from register_skill(description=...), + which defaults to "". Registering the path alone left every stock skill + blank in that catalogue, so the model had nothing to select on.""" + + def test_every_stock_skill_registers_a_description(self, mock_ctx): + plugin = _load_plugin() + plugin.register(mock_ctx) + assert set(mock_ctx._descriptions) == set(mock_ctx._skills) + blank = sorted(n for n, d in mock_ctx._descriptions.items() if not d.strip()) + assert blank == [], f"registered without a description: {blank}" + + def test_descriptions_match_the_skill_frontmatter(self, mock_ctx): + plugin = _load_plugin() + plugin.register(mock_ctx) + skills_dir = Path(plugin._skills_dir()) + for name, description in mock_ctx._descriptions.items(): + text = (skills_dir / name / "SKILL.md").read_text(encoding="utf-8") + declared = re.search(r"^description:\s*(.+)$", text, re.M).group(1) + assert description == declared.strip().strip('"').strip("'") + + @pytest.mark.parametrize( + "block, expected", + [ + ('---\nname: demo\ndescription: "Quoted value."\n---\nbody', "Quoted value."), + ("---\nname: demo\ndescription: Bare value\n---\nbody", "Bare value"), + ("---\nname: demo\n---\nbody", ""), + ("no frontmatter at all", ""), + ], + ) + def test_frontmatter_value_parsing(self, block, expected): + plugin = _load_plugin() + assert plugin._frontmatter_value(block, "description") == expected diff --git a/tests/hooks/test-run-hook-cmd-windows.sh b/tests/hooks/test-run-hook-cmd-windows.sh new file mode 100755 index 0000000..b58c6d1 --- /dev/null +++ b/tests/hooks/test-run-hook-cmd-windows.sh @@ -0,0 +1,223 @@ +#!/usr/bin/env bash +# Tests for the Windows (cmd) half of hooks/run-hook.cmd: how it finds bash +# and whether the hook's exit code survives. Run from Git Bash on Windows; +# skips anywhere cmd.exe isn't available. +# +# Most cases need the fallback branches, which a machine with Git in +# Program Files never reaches. Those cases run a sandbox copy of the wrapper +# whose Program Files paths point at a directory that doesn't exist. +set -euo pipefail + +if ! command -v cmd >/dev/null 2>&1 || ! command -v cygpath >/dev/null 2>&1; then + echo "SKIP: cmd.exe not available (these tests run in Git Bash on Windows)" + exit 0 +fi + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +PF_GIT='C:\Program Files\Git' +# Spelled out: inside Git Bash, cygpath maps its own install dir to "/". +PF_GIT_UNIX='/c/Program Files/Git' + +if [[ ! -e "$PF_GIT_UNIX/bin/bash.exe" ]]; then + echo "SKIP: needs Git for Windows in $PF_GIT to stand in for other installs" + exit 0 +fi + +FAILURES=0 +TEST_ROOT="$(mktemp -d)" +JUNCTIONS=() + +cleanup() { + # Remove junctions with cmd's rmdir first, which never touches the + # target, so nothing below can recurse into the real Git install. + local j left=0 + for j in "${JUNCTIONS[@]}"; do + cmd //c rmdir "$j" >/dev/null 2>&1 || true + if [[ -e "$(cygpath "$j")" ]]; then + echo "WARNING: junction $j still exists; not deleting $TEST_ROOT" >&2 + left=1 + fi + done + [[ "$left" -eq 0 ]] && rm -rf "$TEST_ROOT" +} +trap cleanup EXIT + +pass() { echo " [PASS] $1"; } +fail() { echo " [FAIL] $1"; FAILURES=$((FAILURES + 1)); } + +junction() { + local link="$1" target="$2" + # Keep Git Bash from rewriting /J into a path. + MSYS2_ARG_CONV_EXCL="*" cmd /c mklink /J "$link" "$target" >/dev/null + JUNCTIONS+=("$link") +} + +# A plugin root with probe hooks. $1 = "real" keeps the wrapper as is; +# "sandbox" points its Program Files paths at nothing. +make_plugin() { + local dir="$1" mode="$2" + mkdir -p "$dir/hooks" + if [[ "$mode" == sandbox ]]; then + sed -e 's#C:\\Program Files\\Git\\#C:\\no-such-program-files\\Git\\#g' \ + -e 's#C:\\Program Files (x86)\\Git\\#C:\\no-such-program-files\\Git\\#g' \ + "$REPO_ROOT/hooks/run-hook.cmd" > "$dir/hooks/run-hook.cmd" + if grep -q 'Program Files' "$dir/hooks/run-hook.cmd"; then + echo "sandbox wrapper still mentions Program Files" >&2 + exit 1 + fi + else + cp "$REPO_ROOT/hooks/run-hook.cmd" "$dir/hooks/run-hook.cmd" + fi + printf 'echo probe-ran\n' > "$dir/hooks/probe-ok" + printf 'echo probe-ran\nexit 7\n' > "$dir/hooks/probe-exit" +} + +# run_hook PLUGIN_DIR CWD PROBE [VAR=value...] -> sets OUT and RC +run_hook() { + local plugin="$1" cwd="$2" probe="$3" + shift 3 + RC=0 + # tr drops the NUL bytes the WSL launcher prints (UTF-16 text). + OUT="$(cd "$cwd" && env "$@" cmd //c "$(cygpath -w "$plugin")\\hooks\\run-hook.cmd" "$probe" 2>&1 | tr -d '\000'; exit "${PIPESTATUS[0]}")" || RC=$? +} + +SYS32_PATH="/c/Windows/System32" +GIT_USR_BIN="$PF_GIT_UNIX/usr/bin" +NO_LA='C:\no-such-localappdata' + +echo "run-hook.cmd (Windows) tests" + +# --- exit code of the hook survives the wrapper --- +real="$TEST_ROOT/real" +make_plugin "$real" real +run_hook "$real" "$TEST_ROOT" probe-exit +if [[ "$RC" -eq 7 && "$OUT" == *probe-ran* ]]; then + pass "hook exit code propagates through run-hook.cmd" +else + fail "hook exit code propagates through run-hook.cmd (rc=$RC, out=$OUT)" +fi + +sandbox="$TEST_ROOT/sandbox" +make_plugin "$sandbox" sandbox + +# --- per-user Git install (%LOCALAPPDATA%\Programs\Git) --- +la="$TEST_ROOT/localappdata" +mkdir -p "$la/Programs" +junction "$(cygpath -w "$la/Programs/Git")" "$PF_GIT" +run_hook "$sandbox" "$TEST_ROOT" probe-exit \ + LOCALAPPDATA="$(cygpath -w "$la")" PATH="$SYS32_PATH" +if [[ "$RC" -eq 7 && "$OUT" == *probe-ran* ]]; then + pass "per-user Git install is found and its exit code propagates" +else + fail "per-user Git install is found and its exit code propagates (rc=$RC, out=$OUT)" +fi + +# --- the System32 WSL launcher on PATH is skipped for a real bash --- +run_hook "$sandbox" "$TEST_ROOT" probe-ok \ + LOCALAPPDATA="$NO_LA" PATH="$SYS32_PATH:$GIT_USR_BIN" +if [[ "$RC" -eq 0 && "$OUT" == *probe-ran* ]]; then + pass "System32 bash.exe (WSL launcher) is skipped in favor of Git's bash on PATH" +else + fail "System32 bash.exe (WSL launcher) is skipped in favor of Git's bash on PATH (rc=$RC, out=$OUT)" +fi + +# --- a bash under a WindowsApps directory (the Store WSL stub) is skipped --- +apps_la="$TEST_ROOT/apps-localappdata" +apps="$apps_la/Microsoft/WindowsApps" +mkdir -p "$apps" +apps_marker="$TEST_ROOT/windowsapps-ran" +printf '@echo off\r\necho stub> "%s"\r\n' "$(cygpath -w "$apps_marker")" > "$apps/bash.cmd" +run_hook "$sandbox" "$TEST_ROOT" probe-ok \ + LOCALAPPDATA="$(cygpath -w "$apps_la")" PATH="$apps:$SYS32_PATH:$GIT_USR_BIN" +if [[ ! -e "$apps_marker" && "$OUT" == *probe-ran* ]]; then + pass "bash under WindowsApps (Store WSL stub) is skipped" +else + fail "bash under WindowsApps (Store WSL stub) is skipped (stub ran: $([[ -e $apps_marker ]] && echo yes || echo no), out=$OUT)" +fi + +# --- nothing in the current directory is run: not bash, not where --- +plant="$TEST_ROOT/planted-cwd" +mkdir -p "$plant" +for name in bash.cmd where.bat; do + printf '@echo off\r\necho planted> "%s"\r\n' "$(cygpath -w "$TEST_ROOT/ran-$name")" > "$plant/$name" +done +run_hook "$sandbox" "$plant" probe-ok \ + LOCALAPPDATA="$NO_LA" PATH="$SYS32_PATH:$GIT_USR_BIN" +for name in bash.cmd where.bat; do + if [[ ! -e "$TEST_ROOT/ran-$name" && "$OUT" == *probe-ran* ]]; then + pass "$name in the current directory is not run" + else + fail "$name in the current directory is not run (ran: $([[ -e $TEST_ROOT/ran-$name ]] && echo yes || echo no), out=$OUT)" + fi +done + +# --- PATH entries whose names cmd could misparse still work --- +# fake_bash DIR: a bash.cmd that reports it ran. +fake_bash() { + mkdir -p "$1" + printf '@echo off\r\necho fake-bash-ran\r\n' > "$1/bash.cmd" +} +for dir_name in 'caret^and%OS%percent' $'caf\u00e9-bin' 'extensionless'; do + dir="$TEST_ROOT/$dir_name" + case "$dir_name" in + extensionless) + # An extensionless "bash" first on PATH must be skipped. + mkdir -p "$dir" + printf 'not a program\n' > "$dir/bash" + fake_bash "$TEST_ROOT/after-extensionless" + path="$dir:$TEST_ROOT/after-extensionless:$SYS32_PATH" + ;; + *) + fake_bash "$dir" + path="$dir:$SYS32_PATH" + ;; + esac + run_hook "$sandbox" "$TEST_ROOT" probe-ok LOCALAPPDATA="$NO_LA" PATH="$path" + if [[ "$RC" -eq 0 && "$OUT" == *fake-bash-ran* ]]; then + pass "bash on PATH is found under $dir_name" + else + fail "bash on PATH is found under $dir_name (rc=$RC, out=$OUT)" + fi +done + +# --- unset SystemRoot must not let the WSL launcher through --- +run_hook "$sandbox" "$TEST_ROOT" probe-ok -u SystemRoot \ + LOCALAPPDATA="$NO_LA" PATH="$SYS32_PATH:$GIT_USR_BIN" +if [[ "$RC" -eq 0 && "$OUT" != *Subsystem* ]]; then + pass "unset SystemRoot does not run the WSL launcher" +else + fail "unset SystemRoot does not run the WSL launcher (rc=$RC, out=$OUT)" +fi + +# --- unset LOCALAPPDATA must not probe \Programs\Git on the current drive --- +drive_programs="/c/Programs" +if [[ -e "$drive_programs" ]]; then + echo " [SKIP] unset LOCALAPPDATA: C:\\Programs already exists" +else + mkdir "$drive_programs" + junction 'C:\Programs\Git' "$PF_GIT" + run_hook "$sandbox" "$TEST_ROOT" probe-ok -u LOCALAPPDATA PATH="$SYS32_PATH" + cmd //c rmdir 'C:\Programs\Git' >/dev/null 2>&1 || true + rmdir "$drive_programs" + if [[ "$RC" -eq 0 && "$OUT" != *probe-ran* ]]; then + pass "unset LOCALAPPDATA does not run \\Programs\\Git on the current drive" + else + fail "unset LOCALAPPDATA does not run \\Programs\\Git on the current drive (rc=$RC, out=$OUT)" + fi +fi + +# --- no usable bash: exit 0 quietly, without invoking the WSL launcher --- +run_hook "$sandbox" "$TEST_ROOT" probe-ok \ + LOCALAPPDATA="$NO_LA" PATH="$SYS32_PATH" +if [[ "$RC" -eq 0 && -z "$OUT" ]]; then + pass "no usable bash exits 0 with no output" +else + fail "no usable bash exits 0 with no output (rc=$RC, out=$OUT)" +fi + +if [[ "$FAILURES" -gt 0 ]]; then + echo "STATUS: FAILED ($FAILURES failure(s))" + exit 1 +fi +echo "STATUS: PASSED" diff --git a/tests/hooks/test-session-start.sh b/tests/hooks/test-session-start.sh index c150829..6ddf011 100755 --- a/tests/hooks/test-session-start.sh +++ b/tests/hooks/test-session-start.sh @@ -217,6 +217,106 @@ assert_command_output \ CLAUDE_PLUGIN_ROOT="$REPO_ROOT" \ bash "$HOOK_UNDER_TEST" +# Regression for #2310: Claude Code can spawn SessionStart:startup hooks with +# a broken/empty PATH (anthropics/claude-code#43127). session-start and +# run-hook.cmd's Unix half both shell out to external binaries (dirname, cat) +# that an empty PATH cannot resolve, even though bash itself was invoked by +# absolute path. Every call here should use bash's own builtins/redirection +# instead, so an empty PATH must not change the result. +bash_bin="$(command -v bash)" + +broken_path_home="$(make_home broken-path)" +assert_command_output \ + "session-start with empty PATH still emits nested additionalContext" \ + "nested" \ + "" \ + "" \ + "$broken_path_home" \ + PATH="" \ + CLAUDE_PLUGIN_ROOT="$REPO_ROOT" \ + "$bash_bin" "$HOOK_UNDER_TEST" + +broken_path_wrapper_home="$(make_home broken-path-wrapper)" +assert_command_output \ + "run-hook.cmd with empty PATH still dispatches session-start" \ + "nested" \ + "" \ + "" \ + "$broken_path_wrapper_home" \ + PATH="" \ + CLAUDE_PLUGIN_ROOT="$REPO_ROOT" \ + "$bash_bin" "$WRAPPER_UNDER_TEST" session-start + +# Run by bare filename from inside hooks/ ($0 has no slash), the plugin root +# must still resolve. +bare_name_home="$(make_home bare-name)" +assert_command_output \ + "session-start run by bare filename from hooks/ still emits nested additionalContext" \ + "nested" \ + "" \ + "" \ + "$bare_name_home" \ + CLAUDE_PLUGIN_ROOT="$REPO_ROOT" \ + "$bash_bin" -c 'cd "$1" && exec "$2" session-start' _ "$REPO_ROOT/hooks" "$bash_bin" + +bare_name_wrapper_home="$(make_home bare-name-wrapper)" +assert_command_output \ + "run-hook.cmd run by bare filename from hooks/ still dispatches session-start" \ + "nested" \ + "" \ + "" \ + "$bare_name_wrapper_home" \ + CLAUDE_PLUGIN_ROOT="$REPO_ROOT" \ + "$bash_bin" -c 'cd "$1" && exec "$2" run-hook.cmd session-start' _ "$REPO_ROOT/hooks" "$bash_bin" + +# run-hook.cmd's Windows half starts bash with a backslash path +# (C:\...\hooks\session-start), so $0 can use \ as its separator. The skill +# must still be found. On Windows use the real Windows path; elsewhere build +# a plugin root whose hook is reached through a name containing a backslash. +backslash_home="$(make_home backslash)" +if command -v cygpath >/dev/null 2>&1; then + backslash_cwd="$REPO_ROOT" + backslash_hook="$(cygpath -w "$HOOK_UNDER_TEST")" +else + backslash_cwd="$TEST_ROOT/backslash/root" + mkdir -p "$backslash_cwd" + ln -s "$REPO_ROOT/hooks" "$backslash_cwd/hooks" + ln -s "$REPO_ROOT/skills" "$backslash_cwd/skills" + ln -s "$REPO_ROOT/hooks/session-start" "$backslash_cwd/hooks\\session-start" + backslash_hook='hooks\session-start' +fi +assert_command_output \ + "session-start reached through a backslash path still reads the skill" \ + "nested" \ + "" \ + "Error reading using-superpowers skill" \ + "$backslash_home" \ + CLAUDE_PLUGIN_ROOT="$REPO_ROOT" \ + "$bash_bin" -c 'cd "$1" && exec "$2" "$3"' _ "$backslash_cwd" "$bash_bin" "$backslash_hook" + +# When cat is on PATH, the JSON must still go through it: the pipe absorbs +# EPIPE on Windows + Git Bash (#1612). The stub records that it ran. +cat_stub_dir="$TEST_ROOT/cat-stub/bin" +cat_marker="$TEST_ROOT/cat-stub/used" +mkdir -p "$cat_stub_dir" +printf '#!%s\n: > "%s"\nexec /bin/cat "$@"\n' "$bash_bin" "$cat_marker" > "$cat_stub_dir/cat" +chmod +x "$cat_stub_dir/cat" +cat_stub_home="$(make_home cat-stub)" +assert_command_output \ + "session-start with cat on PATH emits nested additionalContext" \ + "nested" \ + "" \ + "" \ + "$cat_stub_home" \ + PATH="$cat_stub_dir" \ + CLAUDE_PLUGIN_ROOT="$REPO_ROOT" \ + "$bash_bin" "$HOOK_UNDER_TEST" +if [[ -f "$cat_marker" ]]; then + pass "session-start pipes its JSON through cat when cat is on PATH" +else + fail "session-start pipes its JSON through cat when cat is on PATH" +fi + if [[ "$FAILURES" -gt 0 ]]; then echo "STATUS: FAILED ($FAILURES failure(s))" exit 1 diff --git a/tests/version-bump/test-bump-version.sh b/tests/version-bump/test-bump-version.sh index 195d88a..2f77a48 100644 --- a/tests/version-bump/test-bump-version.sh +++ b/tests/version-bump/test-bump-version.sh @@ -73,4 +73,17 @@ cmp -s "$TEST_ROOT/package.before" "$invalid_repo/package.json" \ cmp -s "$TEST_ROOT/plugin.before" "$invalid_repo/.hermes-plugin/plugin.yaml" \ || fail "invalid YAML manifest changed" +audit_repo="$TEST_ROOT/audit-boundaries" +make_fixture "$audit_repo" $'name: superpowers\nversion: 1.2.3' +/bin/bash "$audit_repo/scripts/bump-version.sh" 4.0.0 >/dev/null +printf 'host = "10.4.0.0"\n' >"$audit_repo/server.js" +printf 'pin: superpowers.git#v4.0.0\n' >"$audit_repo/INSTALL.md" +/bin/bash "$audit_repo/scripts/bump-version.sh" --audit >"$TEST_ROOT/audit-boundaries.out" + +grep -q 'INSTALL.md' "$TEST_ROOT/audit-boundaries.out" \ + || fail "audit missed an undeclared #v4.0.0 pin" +if grep -q 'server.js' "$TEST_ROOT/audit-boundaries.out"; then + fail "audit flagged 10.4.0.0 as version 4.0.0" +fi + echo "Version-bump tests passed" diff --git a/tests/writing-skills/test-render-graphs.sh b/tests/writing-skills/test-render-graphs.sh index 349cd47..8bda626 100755 --- a/tests/writing-skills/test-render-graphs.sh +++ b/tests/writing-skills/test-render-graphs.sh @@ -4,7 +4,9 @@ set -u SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" SCRIPT_UNDER_TEST="$REPO_ROOT/skills/writing-skills/render-graphs.js" -NODE_BIN="$(command -v node)" +# Resolve the real binary: version-manager shims (mise, asdf) can't find node +# under the empty PATH used for the missing-Graphviz case. +NODE_BIN="$(node -p 'process.execPath')" PASSES=0 FAILURES=0 |
