Files
msd-core/tests/bug-2334-quick-gsd-sdk-preflight.test.cjs
Tom Boucher 7c6f8005f3 test: destroy 9 config-schema.cjs/core.cjs source-grep tests, replace with behavioral config-set (#2696)
* test: destroy 9 config-schema.cjs/core.cjs source-grep tests, add behavioral config-set tests (#2691, #2693)

Replace source-grep theater with config-set behavioral tests:
- execute-phase-wave: config-set workflow.use_worktrees replaces VALID_CONFIG_KEYS grep
- inline-plan-threshold: delete redundant source-grep (behavioral test at L36 already covered it)
- plan-bounce: config-set for plan_bounce / plan_bounce_script / plan_bounce_passes replaces 3 key-presence greps
- code-review: config-set for code_review / code_review_depth replaces 2 greps; removes CONFIG_PATH constant
- thinking-partner: config-set features.thinking_partner replaces two greps (config-schema.cjs AND core.cjs)

Behavioral tests survive refactors (no path constants, no file reads). The config-schema.cjs →
core.cjs migration commit 990c3e64 happened because these tests groped source paths.

Add allow-test-rule: source-text-is-the-product annotations to legitimate product-content tests:
autonomous-allowed-tools, agent-frontmatter, agent-skills-awareness, bug-2334, bug-2346,
execute-phase-wave (MD reads), plan-bounce (workflow reads). Annotations explain WHY text
inspection is the right level of testing for AI instruction files.

Closes #2691
Closes #2693

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test: address CodeRabbit findings on #2696

- agent-frontmatter.test.cjs: move allow-test-rule annotation from block comment
  to standalone // line comment so rule scanners can detect it
- thinking-partner.test.cjs: strengthen config-set test with config-get read-back
  assertion to verify the value was persisted, not just accepted (exit 0)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test: tighten thinking_partner config assertion per CodeRabbit (#2696)

Replace config-get output substring check (includes('true') false-positive
risk) with a direct JSON read of .planning/config.json, asserting the
exact persisted value via strictEqual. This also validates the config file
was created, catching silent key-acceptance without persistence.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 10:50:54 -04:00

66 lines
3.0 KiB
JavaScript

/**
* Regression test for bug #2334
*
* /gsd-quick crashed with `command not found: gsd-sdk` (exit code 127) when
* the gsd-sdk binary was not installed or not in PATH. The workflow's Step 2
* called `gsd-sdk query init.quick` directly with no pre-flight check and no
* fallback, so missing gsd-sdk caused an immediate abort with no helpful message.
*
* Fix: Step 2 must check for gsd-sdk in PATH before invoking it. If absent,
* emit a human-readable error pointing users to the install command.
*/
'use strict';
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const WORKFLOW_PATH = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'quick.md');
// allow-test-rule: source-text-is-the-product
// quick.md is the AI instruction workflow — the `command -v gsd-sdk` guard IS the fix.
// There is no behavioral equivalent: the check runs inside the AI agent, not in gsd-tools.
describe('bug #2334: quick workflow gsd-sdk pre-flight check', () => {
let content;
test('workflow file exists', () => {
assert.ok(fs.existsSync(WORKFLOW_PATH), 'workflows/quick.md should exist');
content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
});
test('Step 2 checks for gsd-sdk before invoking it', () => {
content = content || fs.readFileSync(WORKFLOW_PATH, 'utf-8');
// The check must appear before the first gsd-sdk invocation in Step 2
const step2Start = content.indexOf('**Step 2:');
assert.ok(step2Start !== -1, 'Step 2 must exist in quick workflow');
const firstSdkCall = content.indexOf('gsd-sdk query init.quick', step2Start);
assert.ok(firstSdkCall !== -1, 'gsd-sdk query init.quick must be present in Step 2');
// Find any gsd-sdk availability check between the Step 2 heading and the first call
const step2Section = content.slice(step2Start, firstSdkCall);
const hasCommandCheck = step2Section.includes('command -v gsd-sdk') || step2Section.includes('which gsd-sdk');
assert.ok(
hasCommandCheck,
'Step 2 must check for gsd-sdk in PATH (via `command -v gsd-sdk` or `which gsd-sdk`) ' +
'before calling `gsd-sdk query init.quick`. Without this guard, the workflow crashes ' +
'with exit code 127 when gsd-sdk is not installed (root cause of #2334).'
);
});
test('pre-flight error message references the install command', () => {
content = content || fs.readFileSync(WORKFLOW_PATH, 'utf-8');
const step2Start = content.indexOf('**Step 2:');
const firstSdkCall = content.indexOf('gsd-sdk query init.quick', step2Start);
const step2Section = content.slice(step2Start, firstSdkCall);
const hasInstallHint = step2Section.includes('@gsd-build/sdk') || step2Section.includes('gsd-update') || step2Section.includes('/gsd-update');
assert.ok(
hasInstallHint,
'Pre-flight error must include a hint on how to install gsd-sdk (npm install -g @gsd-build/sdk or /gsd-update)'
);
});
});