blob: c9fa2f1807e3ffa6db72776aca5faa83c2c25d8f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#!/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
|