mirror of
https://github.com/addyosmani/agent-skills.git
synced 2026-10-26 23:15:04 +00:00
#474 changed session-start.sh to the host-required hookSpecificOutput.hookEventName/additionalContext shape. The regression test still expected the old {priority, message} payload, so `bash hooks/session-start-test.sh` fails on current main. Sabotage: the pre-change test errors with "expected IMPORTANT priority, got undefined". After this change both the jq and jq-missing paths pass. Co-Authored-By: Paperclip <noreply@paperclip.ing>
48 lines
1.4 KiB
Bash
Executable File
48 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# session-start-test.sh - Tests for the SessionStart hook JSON payload
|
|
|
|
set -euo pipefail
|
|
|
|
tmp_payload="$(mktemp)"
|
|
trap 'rm -f "$tmp_payload"' EXIT
|
|
|
|
has_jq=0
|
|
if command -v jq >/dev/null 2>&1; then
|
|
has_jq=1
|
|
fi
|
|
|
|
payload="$(bash hooks/session-start.sh)"
|
|
printf '%s' "$payload" > "$tmp_payload"
|
|
|
|
HAS_JQ="$has_jq" PAYLOAD_PATH="$tmp_payload" node <<'NODE'
|
|
const fs = require('fs');
|
|
|
|
const payload = JSON.parse(fs.readFileSync(process.env.PAYLOAD_PATH, 'utf8'));
|
|
const hasJq = process.env.HAS_JQ === '1';
|
|
const out = payload.hookSpecificOutput;
|
|
|
|
if (!out || typeof out !== 'object') {
|
|
throw new Error('payload is missing hookSpecificOutput (hosts reject other shapes)');
|
|
}
|
|
if (out.hookEventName !== 'SessionStart') {
|
|
throw new Error(`expected hookEventName SessionStart, got ${out.hookEventName}`);
|
|
}
|
|
if (typeof out.additionalContext !== 'string' || !out.additionalContext.trim()) {
|
|
throw new Error('additionalContext must be a non-empty string');
|
|
}
|
|
|
|
const ctx = out.additionalContext;
|
|
if (hasJq) {
|
|
if (!ctx.includes('agent-skills loaded.')) {
|
|
throw new Error('additionalContext is missing startup preface');
|
|
}
|
|
if (!ctx.includes('# Using Agent Skills')) {
|
|
throw new Error('additionalContext is missing using-agent-skills content');
|
|
}
|
|
} else if (!ctx.includes('jq is required')) {
|
|
throw new Error('additionalContext is missing jq fallback guidance');
|
|
}
|
|
|
|
console.log('session-start JSON payload OK');
|
|
NODE
|