* test(#2974): migrate 8 test files to typed-IR assertions Replaces raw stdout/stderr substring matching with structured-field assertions per CONTRIBUTING.md "Prohibited: Raw Text Matching on Test Outputs". Adds shared infrastructure for typed error emission so this pattern is the easy path going forward. Shared infrastructure: - core.cjs: ERROR_REASON frozen enum + setJsonErrorMode/getJsonErrorMode - gsd-tools.cjs: --json-errors CLI flag, parsed before subcommand dispatch - config.cjs: typed reasons at all 7 error sites - graphify.cjs: GRAPHIFY_REASON enum + reason/timeout_ms in execGraphify result - bin/install.js: pure buildSdkFailFastReport() IR builder + renderer - hooks/gsd-session-state.sh, gsd-phase-boundary.sh: emit Claude Code hookSpecificOutput JSON envelope with typed state_present/config_mode/ planning_modified/file_path fields (no-op when hooks.community is off) Test migrations (all pass, 171 tests across the 8 files): - bug-2649-sdk-fail-fast: assert on ir.reason / ir.context / ir.fix_command - bug-2687-config-read-warning-parity: assert.equal stderr === '' - bug-2796-arg-parsing-regression: assert on result.json.updated/.phase - bug-2838-summary-rescue: parse rescue footer, assert mtime invariant - bug-2943-config-get-context-window: parse JSON, assert ERROR_REASON.CONFIG_KEY_NOT_FOUND - graphify: assert reason === GRAPHIFY_REASON.ENOENT/TIMEOUT - hooks-opt-in: parse hookSpecificOutput, assert typed fields - security-scan: reclassified as source-text-is-the-product (scan label output and CI workflow YAML ARE the deployed contract) Verification: lint-no-source-grep clean (0 violations), full suite 6741/6741 pass. Closes #2974 * test(#2974): address CR feedback — typed code field, robust idempotency Two CodeRabbit findings on #3016 addressed: 1. tests/hooks-opt-in.test.cjs:355 (Minor, inline) — parsed.reason.includes('Conventional Commits') was still substring matching after the typed-IR migration. Fixed at the source: the gsd-validate-commit hook now emits a typed `code` field ('CONVENTIONAL_COMMITS_VIOLATION', 'COMMIT_SUBJECT_TOO_LONG') alongside the human-readable `reason`. Test asserts strictEqual on the code; the prose copy is no longer part of the test contract. 2. tests/bug-2838-summary-rescue-gitignored-planning.test.cjs:224-250 (Outside-diff) — mtimeMs alone can stay unchanged on coarse-grained filesystems (HFS+, FAT) when two rewrites land within the same timestamp tick, falsely passing the idempotency assertion. Replaced with a full snapshot (mtimeMs, ctimeMs, size, ino, sha256 of contents) compared via assert.deepStrictEqual — the hash catches any rewrite the timestamp would miss. Verification: 30/30 pass on the two affected files; lint-no-source-grep clean (0 violations across 368 test files).
This commit is contained in:
@@ -14,21 +14,46 @@ else
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo '## Project State Reminder'
|
||||
echo ''
|
||||
|
||||
# Build the additionalContext text and emit it as a structured JSON
|
||||
# envelope per the Claude Code SessionStart hook protocol (#2974). Tests
|
||||
# parse the JSON and assert on typed fields (state_present: bool,
|
||||
# config_mode: string, etc) rather than substring-matching free-form text.
|
||||
STATE_PRESENT="false"
|
||||
STATE_HEAD=""
|
||||
if [ -f .planning/STATE.md ]; then
|
||||
echo 'STATE.md exists - check for blockers and current phase.'
|
||||
head -20 .planning/STATE.md
|
||||
else
|
||||
echo 'No .planning/ found - suggest /gsd-new-project if starting new work.'
|
||||
STATE_PRESENT="true"
|
||||
STATE_HEAD=$(head -20 .planning/STATE.md)
|
||||
fi
|
||||
|
||||
echo ''
|
||||
|
||||
CONFIG_MODE="unknown"
|
||||
if [ -f .planning/config.json ]; then
|
||||
MODE=$(grep -o '"mode"[[:space:]]*:[[:space:]]*"[^"]*"' .planning/config.json 2>/dev/null || echo '"mode": "unknown"')
|
||||
echo "Config: $MODE"
|
||||
CONFIG_MODE=$(node -e "try{const c=require('./.planning/config.json');process.stdout.write(String(c.mode||'unknown'))}catch{process.stdout.write('unknown')}" 2>/dev/null)
|
||||
fi
|
||||
|
||||
# Use Node for JSON encoding so embedded newlines/quotes are escaped correctly.
|
||||
# additionalContext is the text Claude Code injects at session start; the
|
||||
# typed fields (state_present, config_mode) let tests assert on the
|
||||
# structured contract without grepping the prose.
|
||||
node -e '
|
||||
const [statePresent, stateHead, configMode] = process.argv.slice(1);
|
||||
const headerLines = ["## Project State Reminder", ""];
|
||||
if (statePresent === "true") {
|
||||
headerLines.push("STATE.md exists - check for blockers and current phase.");
|
||||
if (stateHead) headerLines.push(stateHead);
|
||||
} else {
|
||||
headerLines.push("No .planning/ found - suggest /gsd-new-project if starting new work.");
|
||||
}
|
||||
headerLines.push("");
|
||||
headerLines.push("Config: \"mode\": \"" + configMode + "\"");
|
||||
const additionalContext = headerLines.join("\n");
|
||||
process.stdout.write(JSON.stringify({
|
||||
hookSpecificOutput: {
|
||||
hookEventName: "SessionStart",
|
||||
additionalContext,
|
||||
state_present: statePresent === "true",
|
||||
config_mode: configMode,
|
||||
},
|
||||
}));
|
||||
' "$STATE_PRESENT" "$STATE_HEAD" "$CONFIG_MODE"
|
||||
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user