* test(#443): RED unified effort + fast_mode + resolve-execution All 68 tests failing as expected — no implementation yet. Covers: effort cascade (tier defaults, overrides, invalid fallthrough), fast_mode cascade (boolean-only, tier defaults), resolveEffortForTier escalation, renderEffortForRuntime clamping, resolve-execution CLI, config schema new keys, QA hostile-input matrix. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(#443): unified cross-provider effort + fast_mode knobs and resolve-execution query Adds config-driven effort control (universal ladder: minimal<low<medium<high<xhigh<max) and fast_mode propagation knobs, with per-runtime rendering that clamps the unique tail values (max=Anthropic-only clamps to xhigh on Codex; minimal=Codex-only clamps to low on Claude). Key changes: - config-schema.manifest.json: add effort.default, fast_mode.enabled as validKeys; add 4 dynamicKeyPatterns for effort.routing_tier_defaults, effort.agent_overrides, fast_mode.routing_tier_defaults, fast_mode.agent_overrides; fix stale _comment - config-defaults.manifest.json: add effort and fast_mode blocks with tier defaults - model-catalog.cjs: add EFFORT_RENDERING map, renderEffortForRuntime(), RUNTIMES_WITH_FAST_MODE - model-profiles.cjs: re-export new catalog exports - core.cjs: add resolveEffortInternal, resolveFastModeInternal, resolveEffortForTier, VALID_EFFORTS, EFFORT_SET, nextEffort; pass effort/fast_mode through loadConfig - commands.cjs: replace reasoning_effort in cmdResolveModel with unified effort; add cmdResolveExecution (superset command with effort_rendered, effort_param, effort_propagation, fast_mode, fast_mode_supported) - gsd-tools.cjs: add resolve-execution case with --effort/--fast-mode/--attempt flags - tests/feat-443: 69 tests covering cascade, rendering, escalation, CLI, schema, QA matrix - tests/commands.test.cjs: convert 3 reasoning_effort assertions to unified effort - docs/CONFIGURATION.md: document effort + fast_mode + resolve-execution sections - settings-advanced.md: list new effort/fast_mode keys in confirmation table Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor(#443): remove dead catalog effort lane; unify codex effort through renderEffortForRuntime - Remove resolveReasoningEffortInternal (catalog-driven effort function) from core.cjs and its export; remove from commands.cjs destructure import - Convert tests/issue-2517-runtime-aware-profiles.test.cjs: all 11 effort assertions now use resolveEffortInternal + renderEffortForRuntime; Claude effort is first-class (output_config.effort); unknown runtimes assert param===null - Convert tests/feat-3023-model-phase-types.test.cjs: replace the entire resolveReasoningEffortInternal describe with unified effort assertions; effort derives from AGENT_DEFAULT_TIERS routing tier, not phase-type tier Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * docs(#443): ADR for unified cross-provider effort + fast-mode routing Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * test(#443): architecture-level QA invariants + test-strategy doc Add 48-test integration suite (feat-443-effort-fast-mode.integration.test.cjs) covering 8 architectural invariants: cross-provider validity (never emit a value the real API would 400 on), param/channel contract stability, resolve-execution JSON contract (all 8 keys + correct types), totality across the full 33-agent registry, fast-mode honesty (claude always fast_mode_supported=false), precedence first-valid-wins matrix for both effort and fast_mode cascades, dynamic-routing composition (effort escalation independent of model tier), and config-set round-trip for all new effort/* and fast_mode/* key namespaces. Append test-strategy section with invariant rationale and E2E gap documentation to docs/TESTING-SUITES.md. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * test(#443): add failing install-wiring tests for effort per-runtime injection (RED) TDD RED: 10 failing tests covering: - Claude .md gets effort: injected per tier (planner=xhigh, mapper=low, executor=high) - Gemini .md does NOT get effort: (already passing — Gemini-safe) - Codex .toml gets model_reasoning_effort via unified resolver - Config-driven: effort.agent_overrides drives both Claude .md and Codex .toml - Source purity: agents/*.md have no effort: key (already passing) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(#443): wire effort per-runtime at install (Claude .md frontmatter + Codex .toml unified) - Import AGENT_DEFAULT_TIERS and renderEffortForRuntime from model-catalog.cjs - Add readGsdEffectiveEffortConfig(targetDir): reads merged effort config from .planning/config.json (per-project wins) + ~/.gsd/defaults.json (global fallback), same probe pattern as readGsdRuntimeProfileResolver - Add resolveInstallTimeEffort(effortCfg, agentName): pure function matching resolveEffortInternal() precedence (agent_overrides > routing_tier_defaults > default > 'high') without loadConfig side-effects (no sub-repo detection, no migration writes) - Claude agent copy loop: inject `effort: <value>` into frontmatter ONLY for runtime === 'claude'; all other .md runtimes (Gemini, Qwen, Hermes, etc.) stay effort-free (Gemini-safe source contract preserved in agents/*.md) - generateCodexAgentToml: add effortCfg param; emit model_reasoning_effort from unified resolver (replaces old catalog entry.reasoning_effort); Codex clamps max → xhigh via renderEffortForRuntime('codex', ...) - installCodexConfig: pass readGsdEffectiveEffortConfig(targetDir) to generateCodexAgentToml so per-project config wins for Codex .toml too - Update failing tests to GREEN: 12/12 pass; all 17 install tests pass; 2847/2848 unit tests pass (1 pre-existing failure: policy-shell-pinning) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor(#443): source install effort defaults from manifest (kill drift) + guard test Replace hardcoded _GSD_EFFORT_MANIFEST_TIER_DEFAULTS and the 'high' fallback in resolveInstallTimeEffort with values read from config-defaults.manifest.json at module init, using the same __dirname-relative path install.js already uses for all shared manifests. Add feat-443-effort-defaults-drift.test.cjs to assert equality between install.js's runtime constants and the manifest on every CI run. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(#443): reconcile Codex TOML tests with unified effort design The #443 unified effort resolver makes generateCodexAgentToml always emit model_reasoning_effort (driven by resolveInstallTimeEffort, not model_profile_overrides). The test 'generated TOML omits reasoning_effort when runtime has none' had an obsolete premise — model_profile_overrides.reasoning_effort:'' no longer suppresses unified effort. Convert it to assert the new invariant: Codex TOML always carries a valid model_reasoning_effort from the agent's routing tier (xhigh for gsd-planner, a heavy-tier agent), while model_profile_overrides model override is still respected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(#443): make install.js effort resolution lazy (no load-time side effects breaking launcher-parity) Replace module-load-time IIFE + hard throw (config-defaults.manifest.json read) and top-level require of model-catalog.cjs with a lazy _getGsdEffortCatalog() getter that initialises on first call from resolveInstallTimeEffort / generateCodexAgentToml / Claude .md effort injection. Requiring install.js in unrelated test contexts (e.g. runtime-launcher-parity) no longer triggers manifest IO or throws, eliminating the load-time side effect that changed subprocess exit codes / stderr on the bench. Drift-guard exports (_GSD_EFFORT_MANIFEST_TIER_DEFAULTS / _GSD_EFFORT_MANIFEST_DEFAULT) preserved as lazy getter properties on module.exports so feat-443-effort-defaults-drift still validates them without forcing eager load. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(#443): isolate install-wiring test HOME to stop \$HOME/.claude pollution breaking launcher-parity runGlobalInstall() now redirects HOME to a per-call isolated tmpdir in addition to the existing runtime-specific env-var redirects (CLAUDE_CONFIG_DIR, GEMINI_CONFIG_DIR, CODEX_HOME). This ensures install.js code that uses os.homedir() directly — including the ~/.cache/gsd update-check deletion, ~/.gsd/defaults.json reads, and any HOME-relative npm subprocess writes — never touches the real \$HOME during the test. Without the HOME isolation the install test (which is new to this branch and is now picked up by Docker's raw \`tests/*.test.cjs\` glob) could write or delete files under the real \$HOME, causing runtime-launcher-parity test (D) to fail: (D) asserts a loud non-zero exit when \$RUNTIME_DIR/gsd-tools.cjs is absent and gsd-tools is not on PATH, but the launcher's \$HOME/.claude fallback arm succeeds if \$HOME/.claude/get-shit-done/bin/gsd-tools.cjs exists. Also sets GSD_SKIP_STALE_SDK_CHECK=1 to suppress the \`npm ls -g\` subprocess that the global installer spawns — irrelevant to effort-wiring assertions, slow, and potentially writes to ~/.npm cache. All 12 feat-443 install-wiring assertions preserved. Drift-guard 5/5. Unit suite 2848/2850 (pre-existing policy-shell-pinning.test.cjs failure on next). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore(#443): add changeset fragment for effort + fast-mode routing Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(#443): set GSD_TEST_MODE before requiring install.js in drift-guard test to prevent HOME leak Without GSD_TEST_MODE=1, require('bin/install.js') runs the module's main install block (guarded by !GSD_TEST_MODE), performing a real global Claude install into $HOME/.claude/. On CI ubuntu where node is on standard PATH, the launcher's $HOME/.claude fallback arm then finds gsd-tools.cjs, causing runtime-launcher-parity test (D) to exit zero when it must exit non-zero. Root cause: feat-443-effort-defaults-drift.test.cjs (unit suite) runs alphabetically before runtime-launcher-parity.test.cjs in the same node --test invocation. Each runs in a separate worker process but shares the same HOME. The drift test's install leaks gsd-tools.cjs into that HOME, then the launcher test's bash subprocess finds it via the $HOME/.claude arm. Fix: add process.env.GSD_TEST_MODE = '1' at the top of the drift-guard test, before the require(installPath) call. This matches the pattern used by feat-443-effort-fast-mode.test.cjs and feat-443-effort-install-wiring .install.test.cjs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(#443): deterministic resolve-execution arg parsing + validate install-time effort (Codex adversarial findings) Finding 1: resolve-execution --effort low gsd-planner misrouted 'low' as the agent. Replace find(non-dash) with a proper flag-consuming loop that collects a single positional; validate missing/extra positionals and malformed --attempt values. Finding 2: resolveInstallTimeEffort returned unvalidated effort strings (e.g. "ultra") verbatim. Each precedence layer now checks GSD_EFFORT_SET (imported once from core.cjs) before accepting a value, mirroring resolveEffortInternal exactly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(#443): newline-agnostic effort frontmatter injection (Windows CRLF) + CRLF-safe assertions Extracts injectEffortFrontmatter(content, effortValue) pure helper that detects EOL (LF vs CRLF) from the opening '---' line and inserts 'effort: <value>' before the closing '---' delimiter using the same EOL as the surrounding frontmatter. Regex now uses /^---\r?\n([\s\S]*?)^---\r?$/m instead of the LF-only /^(---\n[\s\S]*?)(---)(\n|$)/ that silently skipped CRLF files on Windows (git core.autocrlf=true checkout). Also adds 7 unit tests covering LF, CRLF, idempotency, no-frontmatter, and complex frontmatter cases. Exports injectEffortFrontmatter from module.exports. Fixes 6 CI failures in tests/feat-443-effort-install-wiring.install.test.cjs on windows-latest runners (lines 138, 145, 152, 261, 345, 356). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: CI Rebase Check <ci@gsd-redux> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2123 lines
83 KiB
JavaScript
2123 lines
83 KiB
JavaScript
// allow-test-rule: source-text-is-the-product
|
||
// Reads .md/.json/.yml product files whose deployed text IS what the
|
||
// runtime loads — testing text content tests the deployed contract.
|
||
|
||
/**
|
||
* GSD Tools Tests - Commands
|
||
*/
|
||
|
||
const { test, describe, beforeEach, afterEach } = require('node:test');
|
||
const assert = require('node:assert/strict');
|
||
const { execSync } = require('node:child_process');
|
||
const fs = require('fs');
|
||
const path = require('path');
|
||
const { runGsdTools, createTempProject, cleanup } = require('./helpers.cjs');
|
||
|
||
describe('history-digest command', () => {
|
||
let tmpDir;
|
||
|
||
beforeEach(() => {
|
||
tmpDir = createTempProject();
|
||
});
|
||
|
||
afterEach(() => {
|
||
cleanup(tmpDir);
|
||
});
|
||
|
||
test('empty phases directory returns valid schema', () => {
|
||
const result = runGsdTools('history-digest', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const digest = JSON.parse(result.output);
|
||
|
||
assert.deepStrictEqual(digest.phases, {}, 'phases should be empty object');
|
||
assert.deepStrictEqual(digest.decisions, [], 'decisions should be empty array');
|
||
assert.deepStrictEqual(digest.tech_stack, [], 'tech_stack should be empty array');
|
||
});
|
||
|
||
test('nested frontmatter fields extracted correctly', () => {
|
||
// Create phase directory with SUMMARY containing nested frontmatter
|
||
const phaseDir = path.join(tmpDir, '.planning', 'phases', '01-foundation');
|
||
fs.mkdirSync(phaseDir, { recursive: true });
|
||
|
||
const summaryContent = `---
|
||
phase: "01"
|
||
name: "Foundation Setup"
|
||
dependency-graph:
|
||
provides:
|
||
- "Database schema"
|
||
- "Auth system"
|
||
affects:
|
||
- "API layer"
|
||
tech-stack:
|
||
added:
|
||
- "prisma"
|
||
- "jose"
|
||
patterns-established:
|
||
- "Repository pattern"
|
||
- "JWT auth flow"
|
||
key-decisions:
|
||
- "Use Prisma over Drizzle"
|
||
- "JWT in httpOnly cookies"
|
||
---
|
||
|
||
# Summary content here
|
||
`;
|
||
|
||
fs.writeFileSync(path.join(phaseDir, '01-01-SUMMARY.md'), summaryContent);
|
||
|
||
const result = runGsdTools('history-digest', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const digest = JSON.parse(result.output);
|
||
|
||
// Check nested dependency-graph.provides
|
||
assert.ok(digest.phases['01'], 'Phase 01 should exist');
|
||
assert.deepStrictEqual(
|
||
digest.phases['01'].provides.sort(),
|
||
['Auth system', 'Database schema'],
|
||
'provides should contain nested values'
|
||
);
|
||
|
||
// Check nested dependency-graph.affects
|
||
assert.deepStrictEqual(
|
||
digest.phases['01'].affects,
|
||
['API layer'],
|
||
'affects should contain nested values'
|
||
);
|
||
|
||
// Check nested tech-stack.added
|
||
assert.deepStrictEqual(
|
||
digest.tech_stack.sort(),
|
||
['jose', 'prisma'],
|
||
'tech_stack should contain nested values'
|
||
);
|
||
|
||
// Check patterns-established (flat array)
|
||
assert.deepStrictEqual(
|
||
digest.phases['01'].patterns.sort(),
|
||
['JWT auth flow', 'Repository pattern'],
|
||
'patterns should be extracted'
|
||
);
|
||
|
||
// Check key-decisions
|
||
assert.strictEqual(digest.decisions.length, 2, 'Should have 2 decisions');
|
||
assert.ok(
|
||
digest.decisions.some(d => d.decision === 'Use Prisma over Drizzle'),
|
||
'Should contain first decision'
|
||
);
|
||
});
|
||
|
||
test('multiple phases merged into single digest', () => {
|
||
// Create phase 01
|
||
const phase01Dir = path.join(tmpDir, '.planning', 'phases', '01-foundation');
|
||
fs.mkdirSync(phase01Dir, { recursive: true });
|
||
fs.writeFileSync(
|
||
path.join(phase01Dir, '01-01-SUMMARY.md'),
|
||
`---
|
||
phase: "01"
|
||
name: "Foundation"
|
||
provides:
|
||
- "Database"
|
||
patterns-established:
|
||
- "Pattern A"
|
||
key-decisions:
|
||
- "Decision 1"
|
||
---
|
||
`
|
||
);
|
||
|
||
// Create phase 02
|
||
const phase02Dir = path.join(tmpDir, '.planning', 'phases', '02-api');
|
||
fs.mkdirSync(phase02Dir, { recursive: true });
|
||
fs.writeFileSync(
|
||
path.join(phase02Dir, '02-01-SUMMARY.md'),
|
||
`---
|
||
phase: "02"
|
||
name: "API"
|
||
provides:
|
||
- "REST endpoints"
|
||
patterns-established:
|
||
- "Pattern B"
|
||
key-decisions:
|
||
- "Decision 2"
|
||
tech-stack:
|
||
added:
|
||
- "zod"
|
||
---
|
||
`
|
||
);
|
||
|
||
const result = runGsdTools('history-digest', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const digest = JSON.parse(result.output);
|
||
|
||
// Both phases present
|
||
assert.ok(digest.phases['01'], 'Phase 01 should exist');
|
||
assert.ok(digest.phases['02'], 'Phase 02 should exist');
|
||
|
||
// Decisions merged
|
||
assert.strictEqual(digest.decisions.length, 2, 'Should have 2 decisions total');
|
||
|
||
// Tech stack merged
|
||
assert.deepStrictEqual(digest.tech_stack, ['zod'], 'tech_stack should have zod');
|
||
});
|
||
|
||
test('malformed SUMMARY.md skipped gracefully', () => {
|
||
const phaseDir = path.join(tmpDir, '.planning', 'phases', '01-test');
|
||
fs.mkdirSync(phaseDir, { recursive: true });
|
||
|
||
// Valid summary
|
||
fs.writeFileSync(
|
||
path.join(phaseDir, '01-01-SUMMARY.md'),
|
||
`---
|
||
phase: "01"
|
||
provides:
|
||
- "Valid feature"
|
||
---
|
||
`
|
||
);
|
||
|
||
// Malformed summary (no frontmatter)
|
||
fs.writeFileSync(
|
||
path.join(phaseDir, '01-02-SUMMARY.md'),
|
||
`# Just a heading
|
||
No frontmatter here
|
||
`
|
||
);
|
||
|
||
// Another malformed summary (broken YAML)
|
||
fs.writeFileSync(
|
||
path.join(phaseDir, '01-03-SUMMARY.md'),
|
||
`---
|
||
broken: [unclosed
|
||
---
|
||
`
|
||
);
|
||
|
||
const result = runGsdTools('history-digest', tmpDir);
|
||
assert.ok(result.success, `Command should succeed despite malformed files: ${result.error}`);
|
||
|
||
const digest = JSON.parse(result.output);
|
||
assert.ok(digest.phases['01'], 'Phase 01 should exist');
|
||
assert.ok(
|
||
digest.phases['01'].provides.includes('Valid feature'),
|
||
'Valid feature should be extracted'
|
||
);
|
||
});
|
||
|
||
test('flat provides field still works (backward compatibility)', () => {
|
||
const phaseDir = path.join(tmpDir, '.planning', 'phases', '01-test');
|
||
fs.mkdirSync(phaseDir, { recursive: true });
|
||
|
||
fs.writeFileSync(
|
||
path.join(phaseDir, '01-01-SUMMARY.md'),
|
||
`---
|
||
phase: "01"
|
||
provides:
|
||
- "Direct provides"
|
||
---
|
||
`
|
||
);
|
||
|
||
const result = runGsdTools('history-digest', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const digest = JSON.parse(result.output);
|
||
assert.deepStrictEqual(
|
||
digest.phases['01'].provides,
|
||
['Direct provides'],
|
||
'Direct provides should work'
|
||
);
|
||
});
|
||
|
||
test('inline array syntax supported', () => {
|
||
const phaseDir = path.join(tmpDir, '.planning', 'phases', '01-test');
|
||
fs.mkdirSync(phaseDir, { recursive: true });
|
||
|
||
fs.writeFileSync(
|
||
path.join(phaseDir, '01-01-SUMMARY.md'),
|
||
`---
|
||
phase: "01"
|
||
provides: [Feature A, Feature B]
|
||
patterns-established: ["Pattern X", "Pattern Y"]
|
||
---
|
||
`
|
||
);
|
||
|
||
const result = runGsdTools('history-digest', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const digest = JSON.parse(result.output);
|
||
assert.deepStrictEqual(
|
||
digest.phases['01'].provides.sort(),
|
||
['Feature A', 'Feature B'],
|
||
'Inline array should work'
|
||
);
|
||
assert.deepStrictEqual(
|
||
digest.phases['01'].patterns.sort(),
|
||
['Pattern X', 'Pattern Y'],
|
||
'Inline quoted array should work'
|
||
);
|
||
});
|
||
});
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
// phases list command
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
|
||
|
||
describe('summary-extract command', () => {
|
||
let tmpDir;
|
||
|
||
beforeEach(() => {
|
||
tmpDir = createTempProject();
|
||
});
|
||
|
||
afterEach(() => {
|
||
cleanup(tmpDir);
|
||
});
|
||
|
||
test('missing file returns error', () => {
|
||
const result = runGsdTools('summary-extract .planning/phases/01-test/01-01-SUMMARY.md', tmpDir);
|
||
assert.ok(result.success, `Command should succeed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.error, 'File not found', 'should report missing file');
|
||
});
|
||
|
||
test('extracts all fields from SUMMARY.md', () => {
|
||
const phaseDir = path.join(tmpDir, '.planning', 'phases', '01-foundation');
|
||
fs.mkdirSync(phaseDir, { recursive: true });
|
||
|
||
fs.writeFileSync(
|
||
path.join(phaseDir, '01-01-SUMMARY.md'),
|
||
`---
|
||
one-liner: Set up Prisma with User and Project models
|
||
key-files:
|
||
- prisma/schema.prisma
|
||
- src/lib/db.ts
|
||
tech-stack:
|
||
added:
|
||
- prisma
|
||
- zod
|
||
patterns-established:
|
||
- Repository pattern
|
||
- Dependency injection
|
||
key-decisions:
|
||
- Use Prisma over Drizzle: Better DX and ecosystem
|
||
- Single database: Start simple, shard later
|
||
requirements-completed:
|
||
- AUTH-01
|
||
- AUTH-02
|
||
---
|
||
|
||
# Summary
|
||
|
||
Full summary content here.
|
||
`
|
||
);
|
||
|
||
const result = runGsdTools('summary-extract .planning/phases/01-foundation/01-01-SUMMARY.md', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.path, '.planning/phases/01-foundation/01-01-SUMMARY.md', 'path correct');
|
||
assert.strictEqual(output.one_liner, 'Set up Prisma with User and Project models', 'one-liner extracted');
|
||
assert.deepStrictEqual(output.key_files, ['prisma/schema.prisma', 'src/lib/db.ts'], 'key files extracted');
|
||
assert.deepStrictEqual(output.tech_added, ['prisma', 'zod'], 'tech added extracted');
|
||
assert.deepStrictEqual(output.patterns, ['Repository pattern', 'Dependency injection'], 'patterns extracted');
|
||
assert.strictEqual(output.decisions.length, 2, 'decisions extracted');
|
||
assert.deepStrictEqual(output.requirements_completed, ['AUTH-01', 'AUTH-02'], 'requirements completed extracted');
|
||
});
|
||
|
||
test('selective extraction with --fields', () => {
|
||
const phaseDir = path.join(tmpDir, '.planning', 'phases', '01-foundation');
|
||
fs.mkdirSync(phaseDir, { recursive: true });
|
||
|
||
fs.writeFileSync(
|
||
path.join(phaseDir, '01-01-SUMMARY.md'),
|
||
`---
|
||
one-liner: Set up database
|
||
key-files:
|
||
- prisma/schema.prisma
|
||
tech-stack:
|
||
added:
|
||
- prisma
|
||
patterns-established:
|
||
- Repository pattern
|
||
key-decisions:
|
||
- Use Prisma: Better DX
|
||
requirements-completed:
|
||
- AUTH-01
|
||
---
|
||
`
|
||
);
|
||
|
||
const result = runGsdTools('summary-extract .planning/phases/01-foundation/01-01-SUMMARY.md --fields one_liner,key_files,requirements_completed', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.one_liner, 'Set up database', 'one_liner included');
|
||
assert.deepStrictEqual(output.key_files, ['prisma/schema.prisma'], 'key_files included');
|
||
assert.deepStrictEqual(output.requirements_completed, ['AUTH-01'], 'requirements_completed included');
|
||
assert.strictEqual(output.tech_added, undefined, 'tech_added excluded');
|
||
assert.strictEqual(output.patterns, undefined, 'patterns excluded');
|
||
assert.strictEqual(output.decisions, undefined, 'decisions excluded');
|
||
});
|
||
|
||
test('extracts one-liner from body when not in frontmatter', () => {
|
||
const phaseDir = path.join(tmpDir, '.planning', 'phases', '01-foundation');
|
||
fs.mkdirSync(phaseDir, { recursive: true });
|
||
|
||
fs.writeFileSync(
|
||
path.join(phaseDir, '01-01-SUMMARY.md'),
|
||
`---
|
||
phase: "01"
|
||
key-files:
|
||
- src/lib/db.ts
|
||
---
|
||
|
||
# Phase 1: Foundation Summary
|
||
|
||
**JWT auth with refresh rotation using jose library**
|
||
|
||
## Performance
|
||
|
||
- **Duration:** 28 min
|
||
- **Tasks:** 5
|
||
`
|
||
);
|
||
|
||
const result = runGsdTools('summary-extract .planning/phases/01-foundation/01-01-SUMMARY.md', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.one_liner, 'JWT auth with refresh rotation using jose library',
|
||
'one-liner should be extracted from body **bold** line');
|
||
});
|
||
|
||
test('handles missing frontmatter fields gracefully', () => {
|
||
const phaseDir = path.join(tmpDir, '.planning', 'phases', '01-foundation');
|
||
fs.mkdirSync(phaseDir, { recursive: true });
|
||
|
||
fs.writeFileSync(
|
||
path.join(phaseDir, '01-01-SUMMARY.md'),
|
||
`---
|
||
one-liner: Minimal summary
|
||
---
|
||
|
||
# Summary
|
||
`
|
||
);
|
||
|
||
const result = runGsdTools('summary-extract .planning/phases/01-foundation/01-01-SUMMARY.md', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.one_liner, 'Minimal summary', 'one-liner extracted');
|
||
assert.deepStrictEqual(output.key_files, [], 'key_files defaults to empty');
|
||
assert.deepStrictEqual(output.tech_added, [], 'tech_added defaults to empty');
|
||
assert.deepStrictEqual(output.patterns, [], 'patterns defaults to empty');
|
||
assert.deepStrictEqual(output.decisions, [], 'decisions defaults to empty');
|
||
assert.deepStrictEqual(output.requirements_completed, [], 'requirements_completed defaults to empty');
|
||
});
|
||
|
||
test('parses key-decisions with rationale', () => {
|
||
const phaseDir = path.join(tmpDir, '.planning', 'phases', '01-foundation');
|
||
fs.mkdirSync(phaseDir, { recursive: true });
|
||
|
||
fs.writeFileSync(
|
||
path.join(phaseDir, '01-01-SUMMARY.md'),
|
||
`---
|
||
key-decisions:
|
||
- Use Prisma: Better DX than alternatives
|
||
- JWT tokens: Stateless auth for scalability
|
||
---
|
||
`
|
||
);
|
||
|
||
const result = runGsdTools('summary-extract .planning/phases/01-foundation/01-01-SUMMARY.md', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.decisions[0].summary, 'Use Prisma', 'decision summary parsed');
|
||
assert.strictEqual(output.decisions[0].rationale, 'Better DX than alternatives', 'decision rationale parsed');
|
||
assert.strictEqual(output.decisions[1].summary, 'JWT tokens', 'second decision summary');
|
||
assert.strictEqual(output.decisions[1].rationale, 'Stateless auth for scalability', 'second decision rationale');
|
||
});
|
||
});
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
// init commands tests
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
|
||
|
||
describe('progress command', () => {
|
||
let tmpDir;
|
||
|
||
beforeEach(() => {
|
||
tmpDir = createTempProject();
|
||
});
|
||
|
||
afterEach(() => {
|
||
cleanup(tmpDir);
|
||
});
|
||
|
||
test('renders JSON progress', () => {
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||
`# Roadmap v1.0 MVP\n`
|
||
);
|
||
const p1 = path.join(tmpDir, '.planning', 'phases', '01-foundation');
|
||
fs.mkdirSync(p1, { recursive: true });
|
||
fs.writeFileSync(path.join(p1, '01-01-PLAN.md'), '# Plan');
|
||
fs.writeFileSync(path.join(p1, '01-01-SUMMARY.md'), '# Done');
|
||
fs.writeFileSync(path.join(p1, '01-02-PLAN.md'), '# Plan 2');
|
||
|
||
const result = runGsdTools('progress json', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.total_plans, 2, '2 total plans');
|
||
assert.strictEqual(output.total_summaries, 1, '1 summary');
|
||
assert.strictEqual(output.percent, 50, '50%');
|
||
assert.strictEqual(output.phases.length, 1, '1 phase');
|
||
assert.strictEqual(output.phases[0].status, 'In Progress', 'phase in progress');
|
||
});
|
||
|
||
test('renders bar format', () => {
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||
`# Roadmap v1.0\n`
|
||
);
|
||
const p1 = path.join(tmpDir, '.planning', 'phases', '01-test');
|
||
fs.mkdirSync(p1, { recursive: true });
|
||
fs.writeFileSync(path.join(p1, '01-01-PLAN.md'), '# Plan');
|
||
fs.writeFileSync(path.join(p1, '01-01-SUMMARY.md'), '# Done');
|
||
|
||
const result = runGsdTools('progress bar --raw', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
assert.ok(result.output.includes('1/1'), 'should include count');
|
||
assert.ok(result.output.includes('100%'), 'should include 100%');
|
||
});
|
||
|
||
test('renders table format', () => {
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||
`# Roadmap v1.0 MVP\n`
|
||
);
|
||
const p1 = path.join(tmpDir, '.planning', 'phases', '01-foundation');
|
||
fs.mkdirSync(p1, { recursive: true });
|
||
fs.writeFileSync(path.join(p1, '01-01-PLAN.md'), '# Plan');
|
||
|
||
const result = runGsdTools('progress table --raw', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
assert.ok(result.output.includes('Phase'), 'should have table header');
|
||
assert.ok(result.output.includes('foundation'), 'should include phase name');
|
||
});
|
||
|
||
test('does not crash when summaries exceed plans (orphaned SUMMARY.md)', () => {
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||
`# Roadmap v1.0 MVP\n`
|
||
);
|
||
const p1 = path.join(tmpDir, '.planning', 'phases', '01-foundation');
|
||
fs.mkdirSync(p1, { recursive: true });
|
||
// 1 plan but 2 summaries (orphaned SUMMARY.md after PLAN.md deletion)
|
||
fs.writeFileSync(path.join(p1, '01-01-PLAN.md'), '# Plan');
|
||
fs.writeFileSync(path.join(p1, '01-01-SUMMARY.md'), '# Done');
|
||
fs.writeFileSync(path.join(p1, '01-02-SUMMARY.md'), '# Orphaned summary');
|
||
|
||
// bar format - should not crash with RangeError
|
||
const barResult = runGsdTools('progress bar --raw', tmpDir);
|
||
assert.ok(barResult.success, `Bar format crashed: ${barResult.error}`);
|
||
assert.ok(barResult.output.includes('100%'), 'percent should be clamped to 100%');
|
||
|
||
// table format - should not crash with RangeError
|
||
const tableResult = runGsdTools('progress table --raw', tmpDir);
|
||
assert.ok(tableResult.success, `Table format crashed: ${tableResult.error}`);
|
||
|
||
// json format - percent should be clamped
|
||
const jsonResult = runGsdTools('progress json', tmpDir);
|
||
assert.ok(jsonResult.success, `JSON format crashed: ${jsonResult.error}`);
|
||
const output = JSON.parse(jsonResult.output);
|
||
assert.ok(output.percent <= 100, `percent should be <= 100 but got ${output.percent}`);
|
||
});
|
||
});
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
// todo complete command
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
|
||
|
||
describe('todo complete command', () => {
|
||
let tmpDir;
|
||
|
||
beforeEach(() => {
|
||
tmpDir = createTempProject();
|
||
});
|
||
|
||
afterEach(() => {
|
||
cleanup(tmpDir);
|
||
});
|
||
|
||
test('moves todo from pending to completed', () => {
|
||
const pendingDir = path.join(tmpDir, '.planning', 'todos', 'pending');
|
||
fs.mkdirSync(pendingDir, { recursive: true });
|
||
fs.writeFileSync(
|
||
path.join(pendingDir, 'add-dark-mode.md'),
|
||
`title: Add dark mode\narea: ui\ncreated: 2025-01-01\n`
|
||
);
|
||
|
||
const result = runGsdTools('todo complete add-dark-mode.md', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.completed, true);
|
||
|
||
// Verify moved
|
||
assert.ok(
|
||
!fs.existsSync(path.join(tmpDir, '.planning', 'todos', 'pending', 'add-dark-mode.md')),
|
||
'should be removed from pending'
|
||
);
|
||
assert.ok(
|
||
fs.existsSync(path.join(tmpDir, '.planning', 'todos', 'completed', 'add-dark-mode.md')),
|
||
'should be in completed'
|
||
);
|
||
|
||
// Verify completion timestamp added
|
||
const content = fs.readFileSync(
|
||
path.join(tmpDir, '.planning', 'todos', 'completed', 'add-dark-mode.md'),
|
||
'utf-8'
|
||
);
|
||
assert.ok(content.startsWith('completed:'), 'should have completed timestamp');
|
||
});
|
||
|
||
test('fails for nonexistent todo', () => {
|
||
const result = runGsdTools('todo complete nonexistent.md', tmpDir);
|
||
assert.ok(!result.success, 'should fail');
|
||
assert.ok(result.error.includes('not found'), 'error mentions not found');
|
||
});
|
||
});
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
// todo match-phase command
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
|
||
describe('todo match-phase command', () => {
|
||
let tmpDir;
|
||
|
||
beforeEach(() => {
|
||
tmpDir = createTempProject();
|
||
});
|
||
afterEach(() => cleanup(tmpDir));
|
||
|
||
test('returns empty matches when no todos exist', () => {
|
||
const result = runGsdTools('todo match-phase 01', tmpDir);
|
||
assert.ok(result.success, 'should succeed');
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.todo_count, 0);
|
||
assert.deepStrictEqual(output.matches, []);
|
||
});
|
||
|
||
test('matches todo by keyword overlap with phase name', () => {
|
||
const pendingDir = path.join(tmpDir, '.planning', 'todos', 'pending');
|
||
fs.mkdirSync(pendingDir, { recursive: true });
|
||
fs.writeFileSync(path.join(pendingDir, 'auth-todo.md'),
|
||
'title: Add OAuth token refresh\narea: auth\ncreated: 2026-03-01\n\nNeed to handle token expiry for OAuth flows.');
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||
'# Roadmap\n\n### Phase 01: Authentication and Session Management\n\n**Goal:** Implement OAuth login and session handling\n');
|
||
|
||
const result = runGsdTools('todo match-phase 01', tmpDir);
|
||
assert.ok(result.success, 'should succeed');
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.todo_count, 1, 'should find 1 todo');
|
||
assert.ok(output.matches.length > 0, 'should have matches');
|
||
assert.strictEqual(output.matches[0].title, 'Add OAuth token refresh');
|
||
assert.ok(output.matches[0].score > 0, 'score should be positive');
|
||
assert.ok(output.matches[0].reasons.length > 0, 'should have reasons');
|
||
});
|
||
|
||
test('does not match unrelated todo', () => {
|
||
const pendingDir = path.join(tmpDir, '.planning', 'todos', 'pending');
|
||
fs.mkdirSync(pendingDir, { recursive: true });
|
||
fs.writeFileSync(path.join(pendingDir, 'auth-todo.md'),
|
||
'title: Add OAuth token refresh\narea: auth\ncreated: 2026-03-01\n\nOAuth token expiry.');
|
||
fs.writeFileSync(path.join(pendingDir, 'unrelated-todo.md'),
|
||
'title: Fix CSS grid layout in dashboard\narea: ui\ncreated: 2026-03-01\n\nGrid columns break on mobile.');
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||
'# Roadmap\n\n### Phase 01: Authentication and Session Management\n\n**Goal:** Implement OAuth login and session handling\n');
|
||
|
||
const result = runGsdTools('todo match-phase 01', tmpDir);
|
||
assert.ok(result.success, 'should succeed');
|
||
const output = JSON.parse(result.output);
|
||
const matchTitles = output.matches.map(m => m.title);
|
||
assert.ok(matchTitles.includes('Add OAuth token refresh'), 'auth todo should match');
|
||
assert.ok(!matchTitles.includes('Fix CSS grid layout in dashboard'), 'unrelated todo should not match');
|
||
});
|
||
|
||
test('matches todo by area overlap', () => {
|
||
const pendingDir = path.join(tmpDir, '.planning', 'todos', 'pending');
|
||
fs.mkdirSync(pendingDir, { recursive: true });
|
||
fs.writeFileSync(path.join(pendingDir, 'auth-todo.md'),
|
||
'title: Add OAuth token refresh\narea: auth\ncreated: 2026-03-01\n\nOAuth token handling.');
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||
'# Roadmap\n\n### Phase 01: Auth System\n\n**Goal:** Build auth module\n');
|
||
|
||
const result = runGsdTools('todo match-phase 01', tmpDir);
|
||
const output = JSON.parse(result.output);
|
||
const authMatch = output.matches.find(m => m.title === 'Add OAuth token refresh');
|
||
assert.ok(authMatch, 'should find auth todo');
|
||
const hasAreaReason = authMatch.reasons.some(r => r.startsWith('area:'));
|
||
assert.ok(hasAreaReason, 'should match on area');
|
||
});
|
||
|
||
test('sorts matches by score descending', () => {
|
||
const pendingDir = path.join(tmpDir, '.planning', 'todos', 'pending');
|
||
fs.mkdirSync(pendingDir, { recursive: true });
|
||
fs.writeFileSync(path.join(pendingDir, 'weak-match.md'),
|
||
'title: Check token format\narea: general\ncreated: 2026-03-01\n\nToken format validation.');
|
||
fs.writeFileSync(path.join(pendingDir, 'strong-match.md'),
|
||
'title: Session management authentication OAuth token handling\narea: auth\ncreated: 2026-03-01\n\nSession auth OAuth tokens.');
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||
'# Roadmap\n\n### Phase 01: Authentication and Session Management\n\n**Goal:** Implement OAuth login, session handling, and token management\n');
|
||
|
||
const result = runGsdTools('todo match-phase 01', tmpDir);
|
||
const output = JSON.parse(result.output);
|
||
assert.ok(output.matches.length >= 2, 'should have multiple matches');
|
||
for (let i = 1; i < output.matches.length; i++) {
|
||
assert.ok(output.matches[i - 1].score >= output.matches[i].score,
|
||
`match ${i-1} score (${output.matches[i-1].score}) should be >= match ${i} score (${output.matches[i].score})`);
|
||
}
|
||
});
|
||
});
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
// scaffold command
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
|
||
|
||
describe('scaffold command', () => {
|
||
let tmpDir;
|
||
|
||
beforeEach(() => {
|
||
tmpDir = createTempProject();
|
||
});
|
||
|
||
afterEach(() => {
|
||
cleanup(tmpDir);
|
||
});
|
||
|
||
test('scaffolds context file', () => {
|
||
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', '03-api'), { recursive: true });
|
||
|
||
const result = runGsdTools('scaffold context --phase 3', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.created, true);
|
||
|
||
// Verify file content
|
||
const content = fs.readFileSync(
|
||
path.join(tmpDir, '.planning', 'phases', '03-api', '03-CONTEXT.md'),
|
||
'utf-8'
|
||
);
|
||
assert.ok(content.includes('Phase 3'), 'should reference phase number');
|
||
assert.ok(content.includes('Decisions'), 'should have decisions section');
|
||
assert.ok(content.includes('Discretion Areas'), 'should have discretion section');
|
||
});
|
||
|
||
test('scaffolds UAT file', () => {
|
||
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', '03-api'), { recursive: true });
|
||
|
||
const result = runGsdTools('scaffold uat --phase 3', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.created, true);
|
||
|
||
const content = fs.readFileSync(
|
||
path.join(tmpDir, '.planning', 'phases', '03-api', '03-UAT.md'),
|
||
'utf-8'
|
||
);
|
||
assert.ok(content.includes('User Acceptance Testing'), 'should have UAT heading');
|
||
assert.ok(content.includes('Test Results'), 'should have test results section');
|
||
});
|
||
|
||
test('scaffolds verification file', () => {
|
||
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', '03-api'), { recursive: true });
|
||
|
||
const result = runGsdTools('scaffold verification --phase 3', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.created, true);
|
||
|
||
const content = fs.readFileSync(
|
||
path.join(tmpDir, '.planning', 'phases', '03-api', '03-VERIFICATION.md'),
|
||
'utf-8'
|
||
);
|
||
assert.ok(content.includes('Goal-Backward Verification'), 'should have verification heading');
|
||
});
|
||
|
||
test('scaffolds phase directory', () => {
|
||
const result = runGsdTools('scaffold phase-dir --phase 5 --name User Dashboard', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.created, true);
|
||
assert.ok(
|
||
fs.existsSync(path.join(tmpDir, '.planning', 'phases', '05-user-dashboard')),
|
||
'directory should be created'
|
||
);
|
||
});
|
||
|
||
test('does not overwrite existing files', () => {
|
||
const phaseDir = path.join(tmpDir, '.planning', 'phases', '03-api');
|
||
fs.mkdirSync(phaseDir, { recursive: true });
|
||
fs.writeFileSync(path.join(phaseDir, '03-CONTEXT.md'), '# Existing content');
|
||
|
||
const result = runGsdTools('scaffold context --phase 3', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.created, false, 'should not overwrite');
|
||
assert.strictEqual(output.reason, 'already_exists');
|
||
});
|
||
});
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
// cmdGenerateSlug tests (CMD-01)
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
|
||
describe('generate-slug command', () => {
|
||
let tmpDir;
|
||
|
||
beforeEach(() => {
|
||
tmpDir = createTempProject();
|
||
});
|
||
|
||
afterEach(() => {
|
||
cleanup(tmpDir);
|
||
});
|
||
|
||
test('converts normal text to slug', () => {
|
||
const result = runGsdTools('generate-slug "Hello World"', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.slug, 'hello-world');
|
||
});
|
||
|
||
test('strips special characters', () => {
|
||
const result = runGsdTools('generate-slug "Test@#$%^Special!!!"', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.slug, 'test-special');
|
||
});
|
||
|
||
test('preserves numbers', () => {
|
||
const result = runGsdTools('generate-slug "Phase 3 Plan"', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.slug, 'phase-3-plan');
|
||
});
|
||
|
||
test('strips leading and trailing hyphens', () => {
|
||
const result = runGsdTools('generate-slug "---leading-trailing---"', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.slug, 'leading-trailing');
|
||
});
|
||
|
||
test('fails when no text provided', () => {
|
||
const result = runGsdTools('generate-slug', tmpDir);
|
||
assert.ok(!result.success, 'should fail without text');
|
||
assert.ok(result.error.includes('text required'), 'error should mention text required');
|
||
});
|
||
});
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
// cmdCurrentTimestamp tests (CMD-01)
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
|
||
describe('current-timestamp command', () => {
|
||
let tmpDir;
|
||
|
||
beforeEach(() => {
|
||
tmpDir = createTempProject();
|
||
});
|
||
|
||
afterEach(() => {
|
||
cleanup(tmpDir);
|
||
});
|
||
|
||
test('date format returns YYYY-MM-DD', () => {
|
||
const result = runGsdTools('current-timestamp date', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.match(output.timestamp, /^\d{4}-\d{2}-\d{2}$/, 'should be YYYY-MM-DD format');
|
||
});
|
||
|
||
test('filename format returns ISO without colons or fractional seconds', () => {
|
||
const result = runGsdTools('current-timestamp filename', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.match(output.timestamp, /^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}$/, 'should replace colons with hyphens and strip fractional seconds');
|
||
});
|
||
|
||
test('full format returns full ISO string', () => {
|
||
const result = runGsdTools('current-timestamp full', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.match(output.timestamp, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/, 'should be full ISO format');
|
||
});
|
||
|
||
test('default (no format) returns full ISO string', () => {
|
||
const result = runGsdTools('current-timestamp', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.match(output.timestamp, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/, 'default should be full ISO format');
|
||
});
|
||
|
||
test('dispatches directly to CJS handler (no SDK bridge) to avoid Windows native crash path', () => {
|
||
const sourcePath = path.join(__dirname, '..', 'get-shit-done', 'bin', 'gsd-tools.cjs');
|
||
const source = fs.readFileSync(sourcePath, 'utf8');
|
||
const match = source.match(/case 'current-timestamp':\s*\{[\s\S]*?\r?\n\s*break;\r?\n\s*\}/);
|
||
|
||
assert.ok(match, 'current-timestamp case block must exist in gsd-tools.cjs');
|
||
|
||
const block = match[0];
|
||
assert.ok(
|
||
!block.includes('_dispatchNonFamily('),
|
||
'current-timestamp must not route through SDK bridge'
|
||
);
|
||
assert.ok(
|
||
block.includes("commands.cmdCurrentTimestamp(args[1] || 'full', raw);"),
|
||
'current-timestamp must call the CJS handler directly'
|
||
);
|
||
});
|
||
});
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
// cmdListTodos tests (CMD-02)
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
|
||
describe('list-todos command', () => {
|
||
let tmpDir;
|
||
|
||
beforeEach(() => {
|
||
tmpDir = createTempProject();
|
||
});
|
||
|
||
afterEach(() => {
|
||
cleanup(tmpDir);
|
||
});
|
||
|
||
test('empty directory returns zero count', () => {
|
||
const result = runGsdTools('list-todos', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.count, 0, 'count should be 0');
|
||
assert.deepStrictEqual(output.todos, [], 'todos should be empty');
|
||
});
|
||
|
||
test('returns multiple todos with correct fields', () => {
|
||
const pendingDir = path.join(tmpDir, '.planning', 'todos', 'pending');
|
||
fs.mkdirSync(pendingDir, { recursive: true });
|
||
|
||
fs.writeFileSync(path.join(pendingDir, 'add-tests.md'), 'title: Add unit tests\narea: testing\ncreated: 2026-01-15\n');
|
||
fs.writeFileSync(path.join(pendingDir, 'fix-bug.md'), 'title: Fix login bug\narea: auth\ncreated: 2026-01-20\n');
|
||
|
||
const result = runGsdTools('list-todos', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.count, 2, 'should have 2 todos');
|
||
assert.strictEqual(output.todos.length, 2, 'todos array should have 2 entries');
|
||
|
||
const testTodo = output.todos.find(t => t.file === 'add-tests.md');
|
||
assert.ok(testTodo, 'add-tests.md should be in results');
|
||
assert.strictEqual(testTodo.title, 'Add unit tests');
|
||
assert.strictEqual(testTodo.area, 'testing');
|
||
assert.strictEqual(testTodo.created, '2026-01-15');
|
||
});
|
||
|
||
test('area filter returns only matching todos', () => {
|
||
const pendingDir = path.join(tmpDir, '.planning', 'todos', 'pending');
|
||
fs.mkdirSync(pendingDir, { recursive: true });
|
||
|
||
fs.writeFileSync(path.join(pendingDir, 'ui-task.md'), 'title: UI task\narea: ui\ncreated: 2026-01-01\n');
|
||
fs.writeFileSync(path.join(pendingDir, 'api-task.md'), 'title: API task\narea: api\ncreated: 2026-01-01\n');
|
||
|
||
const result = runGsdTools('list-todos ui', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.count, 1, 'should have 1 matching todo');
|
||
assert.strictEqual(output.todos[0].area, 'ui', 'should only return ui area');
|
||
});
|
||
|
||
test('area filter miss returns zero count', () => {
|
||
const pendingDir = path.join(tmpDir, '.planning', 'todos', 'pending');
|
||
fs.mkdirSync(pendingDir, { recursive: true });
|
||
|
||
fs.writeFileSync(path.join(pendingDir, 'task.md'), 'title: Some task\narea: backend\ncreated: 2026-01-01\n');
|
||
|
||
const result = runGsdTools('list-todos nonexistent-area', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.count, 0, 'should have 0 matching todos');
|
||
});
|
||
|
||
test('malformed files use defaults', () => {
|
||
const pendingDir = path.join(tmpDir, '.planning', 'todos', 'pending');
|
||
fs.mkdirSync(pendingDir, { recursive: true });
|
||
|
||
// File with no title or area fields
|
||
fs.writeFileSync(path.join(pendingDir, 'malformed.md'), 'some random content\nno fields here\n');
|
||
|
||
const result = runGsdTools('list-todos', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.count, 1, 'malformed file should still be counted');
|
||
assert.strictEqual(output.todos[0].title, 'Untitled', 'missing title defaults to Untitled');
|
||
assert.strictEqual(output.todos[0].area, 'general', 'missing area defaults to general');
|
||
assert.strictEqual(output.todos[0].created, 'unknown', 'missing created defaults to unknown');
|
||
});
|
||
});
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
// cmdVerifyPathExists tests (CMD-02)
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
|
||
describe('verify-path-exists command', () => {
|
||
let tmpDir;
|
||
|
||
beforeEach(() => {
|
||
tmpDir = createTempProject();
|
||
});
|
||
|
||
afterEach(() => {
|
||
cleanup(tmpDir);
|
||
});
|
||
|
||
test('existing file returns exists=true with type=file', () => {
|
||
fs.writeFileSync(path.join(tmpDir, 'test-file.txt'), 'hello');
|
||
|
||
const result = runGsdTools('verify-path-exists test-file.txt', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.exists, true);
|
||
assert.strictEqual(output.type, 'file');
|
||
});
|
||
|
||
test('existing directory returns exists=true with type=directory', () => {
|
||
fs.mkdirSync(path.join(tmpDir, 'test-dir'), { recursive: true });
|
||
|
||
const result = runGsdTools('verify-path-exists test-dir', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.exists, true);
|
||
assert.strictEqual(output.type, 'directory');
|
||
});
|
||
|
||
test('missing path returns exists=false', () => {
|
||
const result = runGsdTools('verify-path-exists nonexistent/path', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.exists, false);
|
||
assert.strictEqual(output.type, null);
|
||
});
|
||
|
||
test('absolute path resolves correctly', () => {
|
||
const absFile = path.join(tmpDir, 'abs-test.txt');
|
||
fs.writeFileSync(absFile, 'content');
|
||
|
||
const result = runGsdTools(['verify-path-exists', absFile], tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.exists, true);
|
||
assert.strictEqual(output.type, 'file');
|
||
});
|
||
|
||
test('fails when no path provided', () => {
|
||
const result = runGsdTools('verify-path-exists', tmpDir);
|
||
assert.ok(!result.success, 'should fail without path');
|
||
assert.ok(result.error.includes('path required'), 'error should mention path required');
|
||
});
|
||
});
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
// cmdResolveModel tests (CMD-03)
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
|
||
describe('resolve-model command', () => {
|
||
let tmpDir;
|
||
|
||
beforeEach(() => {
|
||
tmpDir = createTempProject();
|
||
});
|
||
|
||
afterEach(() => {
|
||
cleanup(tmpDir);
|
||
});
|
||
|
||
test('known agent returns model and profile without unknown_agent', () => {
|
||
const result = runGsdTools('resolve-model gsd-planner', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.ok(output.model, 'should have model field');
|
||
assert.ok(output.profile, 'should have profile field');
|
||
assert.strictEqual(output.unknown_agent, undefined, 'should not have unknown_agent for known agent');
|
||
});
|
||
|
||
test('shipped-but-previously-missing agent resolves under quality profile (#3229)', () => {
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'config.json'), JSON.stringify({ model_profile: 'quality' }));
|
||
const result = runGsdTools('resolve-model gsd-code-reviewer', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.model, 'opus');
|
||
assert.strictEqual(output.profile, 'quality');
|
||
assert.strictEqual(output.unknown_agent, undefined);
|
||
});
|
||
|
||
test('unknown agent returns unknown_agent=true', () => {
|
||
const result = runGsdTools('resolve-model fake-nonexistent-agent', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.unknown_agent, true, 'should flag unknown agent');
|
||
});
|
||
|
||
test('unknown agent uses quality-semantic fallback (opus)', () => {
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'config.json'), JSON.stringify({ model_profile: 'quality' }));
|
||
const result = runGsdTools('resolve-model fake-nonexistent-agent', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.model, 'opus');
|
||
assert.strictEqual(output.unknown_agent, true);
|
||
});
|
||
|
||
test('unknown agent uses budget-semantic fallback (haiku)', () => {
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'config.json'), JSON.stringify({ model_profile: 'budget' }));
|
||
const result = runGsdTools('resolve-model fake-nonexistent-agent', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.model, 'haiku');
|
||
assert.strictEqual(output.unknown_agent, true);
|
||
});
|
||
|
||
test('default profile fallback when no config exists', () => {
|
||
// tmpDir has no config.json, so defaults to balanced profile
|
||
const result = runGsdTools('resolve-model gsd-executor', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.profile, 'balanced', 'should default to balanced profile');
|
||
assert.ok(output.model, 'should resolve a model');
|
||
});
|
||
|
||
// #443: resolve-model now emits unified `effort` instead of `reasoning_effort`.
|
||
// reasoning_effort was flavor-text (resolved but consumed by nobody); effort is
|
||
// the wired, config-driven universal effort string for all runtimes.
|
||
test('emits unified effort (not reasoning_effort) when runtime supports tiered effort', () => {
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'config.json'), JSON.stringify({
|
||
model_profile: 'balanced',
|
||
runtime: 'codex',
|
||
models: { planning: 'opus' },
|
||
}));
|
||
const result = runGsdTools('resolve-model gsd-planner', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.model, 'gpt-5.4');
|
||
assert.strictEqual(output.profile, 'balanced');
|
||
// #443: effort is now the unified field (xhigh for gsd-planner heavy tier default)
|
||
assert.strictEqual(output.effort, 'xhigh');
|
||
// reasoning_effort must be absent — replaced by unified effort
|
||
assert.ok(!Object.prototype.hasOwnProperty.call(output, 'reasoning_effort'),
|
||
'reasoning_effort must not appear in resolve-model output (replaced by effort)');
|
||
});
|
||
|
||
test('does not include reasoning_effort for unsupported runtime overrides (effort present instead)', () => {
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'config.json'), JSON.stringify({
|
||
model_profile: 'balanced',
|
||
runtime: 'opencode',
|
||
models: { planning: 'opus' },
|
||
model_profile_overrides: {
|
||
opencode: {
|
||
opus: { model: 'openrouter/openai/gpt-5.5', reasoning_effort: 'high' },
|
||
},
|
||
},
|
||
}));
|
||
const result = runGsdTools('resolve-model gsd-planner', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.model, 'openrouter/openai/gpt-5.5');
|
||
assert.strictEqual(output.profile, 'balanced');
|
||
// #443: effort always present; reasoning_effort never present
|
||
assert.ok(Object.prototype.hasOwnProperty.call(output, 'effort'), 'effort must be present');
|
||
assert.ok(!Object.prototype.hasOwnProperty.call(output, 'reasoning_effort'),
|
||
'reasoning_effort must not appear (replaced by unified effort)');
|
||
});
|
||
|
||
test('does not include reasoning_effort for per-agent model_overrides (effort present instead)', () => {
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'config.json'), JSON.stringify({
|
||
model_profile: 'balanced',
|
||
runtime: 'codex',
|
||
models: { planning: 'opus' },
|
||
model_overrides: { 'gsd-planner': 'gpt-5.5' },
|
||
}));
|
||
const result = runGsdTools('resolve-model gsd-planner', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.model, 'gpt-5.5');
|
||
assert.strictEqual(output.profile, 'balanced');
|
||
// #443: effort always present; reasoning_effort never present
|
||
assert.ok(Object.prototype.hasOwnProperty.call(output, 'effort'), 'effort must be present');
|
||
assert.ok(!Object.prototype.hasOwnProperty.call(output, 'reasoning_effort'),
|
||
'reasoning_effort must not appear (replaced by unified effort)');
|
||
});
|
||
|
||
test('fails when no agent-type provided', () => {
|
||
const result = runGsdTools('resolve-model', tmpDir);
|
||
assert.ok(!result.success, 'should fail without agent-type');
|
||
assert.ok(result.error.includes('agent-type required'), 'error should mention agent-type required');
|
||
});
|
||
});
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
// cmdCommit tests (CMD-04)
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
|
||
describe('commit command', () => {
|
||
const { createTempGitProject } = require('./helpers.cjs');
|
||
const { execSync } = require('child_process');
|
||
let tmpDir;
|
||
|
||
beforeEach(() => {
|
||
tmpDir = createTempGitProject();
|
||
});
|
||
|
||
afterEach(() => {
|
||
cleanup(tmpDir);
|
||
});
|
||
|
||
test('skips when commit_docs is false', () => {
|
||
// Write config with commit_docs: false
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'config.json'),
|
||
JSON.stringify({ commit_docs: false })
|
||
);
|
||
|
||
const result = runGsdTools('commit "test message"', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.committed, false);
|
||
assert.strictEqual(output.reason, 'skipped_commit_docs_false');
|
||
});
|
||
|
||
test('skips when .planning is gitignored', () => {
|
||
// Add .planning/ to .gitignore and commit it so git recognizes the ignore
|
||
fs.writeFileSync(path.join(tmpDir, '.gitignore'), '.planning/\n');
|
||
execSync('git add .gitignore', { cwd: tmpDir, stdio: 'pipe' });
|
||
execSync('git commit -m "add gitignore"', { cwd: tmpDir, stdio: 'pipe' });
|
||
|
||
const result = runGsdTools('commit "test message"', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.committed, false);
|
||
assert.strictEqual(output.reason, 'skipped_gitignored');
|
||
});
|
||
|
||
test('handles nothing to commit', () => {
|
||
// Don't modify any files after initial commit
|
||
const result = runGsdTools('commit "test message"', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.committed, false);
|
||
assert.strictEqual(output.reason, 'nothing_to_commit');
|
||
});
|
||
|
||
test('creates real commit with correct hash', () => {
|
||
// Create a new file in .planning/
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'test-file.md'), '# Test\n');
|
||
|
||
const result = runGsdTools('commit "test: add test file" --files .planning/test-file.md', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.committed, true, 'should have committed');
|
||
assert.ok(output.hash, 'should have a commit hash');
|
||
assert.strictEqual(output.reason, 'committed');
|
||
|
||
// Verify via git log
|
||
const gitLog = execSync('git log --oneline -1', { cwd: tmpDir, encoding: 'utf-8' }).trim();
|
||
assert.ok(gitLog.includes('test: add test file'), 'git log should contain the commit message');
|
||
assert.ok(gitLog.includes(output.hash), 'git log should contain the returned hash');
|
||
});
|
||
|
||
test('amend mode works without crashing', () => {
|
||
// Create a file and commit it first
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'amend-file.md'), '# Initial\n');
|
||
execSync('git add .planning/amend-file.md', { cwd: tmpDir, stdio: 'pipe' });
|
||
execSync('git commit -m "initial file"', { cwd: tmpDir, stdio: 'pipe' });
|
||
|
||
// Modify the file and amend
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'amend-file.md'), '# Amended\n');
|
||
|
||
const result = runGsdTools('commit "ignored" --files .planning/amend-file.md --amend', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.committed, true, 'amend should succeed');
|
||
|
||
// Verify only 2 commits total (initial setup + amended)
|
||
const logCount = execSync('git log --oneline', { cwd: tmpDir, encoding: 'utf-8' }).trim().split('\n').length;
|
||
assert.strictEqual(logCount, 2, 'should have 2 commits (initial + amended)');
|
||
});
|
||
test('creates strategy branch before first commit when branching_strategy is milestone', () => {
|
||
// Configure milestone branching strategy
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'config.json'),
|
||
JSON.stringify({
|
||
commit_docs: true,
|
||
branching_strategy: 'milestone',
|
||
milestone_branch_template: 'gsd/{milestone}-{slug}',
|
||
})
|
||
);
|
||
// getMilestoneInfo reads ROADMAP.md for milestone version/name
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||
'## v1.0: Initial Release\n\n### Phase 1: Setup\n'
|
||
);
|
||
|
||
// Create a file to commit
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'test-context.md'), '# Context\n');
|
||
|
||
const result = runGsdTools('commit "docs: add context" --files .planning/test-context.md', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.committed, true, 'should have committed');
|
||
|
||
// Verify we're on the strategy branch
|
||
const { execFileSync } = require('child_process');
|
||
const branch = execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: tmpDir, encoding: 'utf-8' }).trim();
|
||
assert.strictEqual(branch, 'gsd/v1.0-initial-release', 'should be on milestone branch');
|
||
});
|
||
|
||
test('creates strategy branch before first commit when branching_strategy is phase', () => {
|
||
// Configure phase branching strategy
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'config.json'),
|
||
JSON.stringify({
|
||
commit_docs: true,
|
||
branching_strategy: 'phase',
|
||
phase_branch_template: 'gsd/phase-{phase}-{slug}',
|
||
})
|
||
);
|
||
// Create ROADMAP.md with a phase
|
||
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', '01-setup'), { recursive: true });
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||
'# Roadmap\n\n## Phase 1: Setup\nGoal: Initial setup\n'
|
||
);
|
||
|
||
// Create a context file for phase 1
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'phases', '01-setup', '01-CONTEXT.md'), '# Context\n');
|
||
|
||
const result = runGsdTools(
|
||
'commit "docs(01): add context" --files .planning/phases/01-setup/01-CONTEXT.md',
|
||
tmpDir
|
||
);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.committed, true, 'should have committed');
|
||
|
||
// Verify we're on the strategy branch
|
||
const { execFileSync } = require('child_process');
|
||
const branch = execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: tmpDir, encoding: 'utf-8' }).trim();
|
||
assert.strictEqual(branch, 'gsd/phase-01-setup', 'should be on phase branch');
|
||
});
|
||
|
||
test('decimal phase numbers are captured correctly in branching strategy', () => {
|
||
// Configure phase branching strategy
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'config.json'),
|
||
JSON.stringify({
|
||
commit_docs: true,
|
||
branching_strategy: 'phase',
|
||
phase_branch_template: 'gsd/phase-{phase}-{slug}',
|
||
})
|
||
);
|
||
// Create ROADMAP.md with a decimal phase
|
||
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', '45.14-golden-capture'), { recursive: true });
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||
'# Roadmap\n\n## Phase 45.14: Golden Capture\nGoal: Capture golden standard\n'
|
||
);
|
||
|
||
// Create a context file for phase 45.14
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'phases', '45.14-golden-capture', '45.14-CONTEXT.md'), '# Context\n');
|
||
|
||
const result = runGsdTools(
|
||
'commit "docs(45.14): add context" --files .planning/phases/45.14-golden-capture/45.14-CONTEXT.md',
|
||
tmpDir
|
||
);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.committed, true, 'should have committed');
|
||
|
||
// Verify we're on the correct branch (45.14, not 14)
|
||
const { execFileSync } = require('child_process');
|
||
const branch = execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: tmpDir, encoding: 'utf-8' }).trim();
|
||
assert.strictEqual(branch, 'gsd/phase-45.14-golden-capture', 'should be on decimal phase branch, not integer-only');
|
||
});
|
||
});
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
// groupFilesBySubrepo tests (#311)
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
|
||
describe('groupFilesBySubrepo (#311)', () => {
|
||
const { groupFilesBySubrepo } = require('../get-shit-done/bin/lib/commands.cjs');
|
||
|
||
test('single-segment subrepos route files correctly and unmatched collected', () => {
|
||
const result = groupFilesBySubrepo(
|
||
['packages/a.js', 'docs/x.md', 'README.md'],
|
||
['packages', 'docs']
|
||
);
|
||
assert.deepStrictEqual(result.grouped, { packages: ['packages/a.js'], docs: ['docs/x.md'] });
|
||
assert.deepStrictEqual(result.unmatched, ['README.md']);
|
||
});
|
||
|
||
test('multi-segment subrepo matches deep files, not shallow sibling', () => {
|
||
const result = groupFilesBySubrepo(
|
||
['vendor/pkg/x.js', 'vendor/other.js', 'vendor/pkg/y.js'],
|
||
['vendor/pkg']
|
||
);
|
||
assert.deepStrictEqual(result.grouped, { 'vendor/pkg': ['vendor/pkg/x.js', 'vendor/pkg/y.js'] });
|
||
assert.deepStrictEqual(result.unmatched, ['vendor/other.js']);
|
||
});
|
||
|
||
test('first-match-in-array-order wins (not longest-prefix)', () => {
|
||
// 'app' comes before 'app/sub' in subRepos array; 'app/sub/f.js' matches 'app' first
|
||
const result = groupFilesBySubrepo(
|
||
['app/sub/f.js'],
|
||
['app', 'app/sub']
|
||
);
|
||
assert.deepStrictEqual(result.grouped, { app: ['app/sub/f.js'] });
|
||
assert.deepStrictEqual(result.unmatched, []);
|
||
});
|
||
|
||
test('file with no slash does not match a same-name subrepo', () => {
|
||
const result = groupFilesBySubrepo(['top'], ['top']);
|
||
assert.deepStrictEqual(result.grouped, {});
|
||
assert.deepStrictEqual(result.unmatched, ['top']);
|
||
});
|
||
|
||
test('file with slash after prefix routes correctly', () => {
|
||
const result = groupFilesBySubrepo(['top/a'], ['top']);
|
||
assert.deepStrictEqual(result.grouped, { top: ['top/a'] });
|
||
assert.deepStrictEqual(result.unmatched, []);
|
||
});
|
||
|
||
test('empty files list returns empty grouped and unmatched', () => {
|
||
const result = groupFilesBySubrepo([], ['a']);
|
||
assert.deepStrictEqual(result.grouped, {});
|
||
assert.deepStrictEqual(result.unmatched, []);
|
||
});
|
||
|
||
test('empty subRepos list puts all files in unmatched', () => {
|
||
const result = groupFilesBySubrepo(['a/b'], []);
|
||
assert.deepStrictEqual(result.grouped, {});
|
||
assert.deepStrictEqual(result.unmatched, ['a/b']);
|
||
});
|
||
|
||
test('non-string subRepos entry does not throw and string entries still route (#311)', () => {
|
||
// Old inline code coerced non-string repos via `repo + '/'` and never threw.
|
||
let result;
|
||
assert.doesNotThrow(() => {
|
||
result = groupFilesBySubrepo(['a/b', 'README.md'], [null, 'a']);
|
||
});
|
||
assert.deepStrictEqual(result.grouped, { a: ['a/b'] });
|
||
assert.deepStrictEqual(result.unmatched, ['README.md']);
|
||
});
|
||
});
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
// cmdWebsearch tests (CMD-05)
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
|
||
describe('websearch command', () => {
|
||
const { cmdWebsearch } = require('../get-shit-done/bin/lib/commands.cjs');
|
||
let origFetch;
|
||
let origApiKey;
|
||
let origWriteSync;
|
||
let captured;
|
||
|
||
beforeEach(() => {
|
||
origFetch = global.fetch;
|
||
origApiKey = process.env.BRAVE_API_KEY;
|
||
origWriteSync = fs.writeSync;
|
||
captured = '';
|
||
// output() uses fs.writeSync(1, data) since #1276 — mock it to capture output
|
||
fs.writeSync = (fd, data) => { if (fd === 1) captured += data; return Buffer.byteLength(String(data)); };
|
||
});
|
||
|
||
afterEach(() => {
|
||
global.fetch = origFetch;
|
||
if (origApiKey !== undefined) {
|
||
process.env.BRAVE_API_KEY = origApiKey;
|
||
} else {
|
||
delete process.env.BRAVE_API_KEY;
|
||
}
|
||
fs.writeSync = origWriteSync;
|
||
});
|
||
|
||
test('returns available=false when BRAVE_API_KEY is unset', async () => {
|
||
delete process.env.BRAVE_API_KEY;
|
||
|
||
await cmdWebsearch('test query', {}, false);
|
||
|
||
const output = JSON.parse(captured);
|
||
assert.strictEqual(output.available, false);
|
||
assert.ok(output.reason.includes('BRAVE_API_KEY'), 'should mention missing API key');
|
||
});
|
||
|
||
test('returns error when no query provided', async () => {
|
||
process.env.BRAVE_API_KEY = 'test-key';
|
||
|
||
await cmdWebsearch(null, {}, false);
|
||
|
||
const output = JSON.parse(captured);
|
||
assert.strictEqual(output.available, false);
|
||
assert.ok(output.error.includes('Query required'), 'should mention query required');
|
||
});
|
||
|
||
test('returns results for successful API response', async () => {
|
||
process.env.BRAVE_API_KEY = 'test-key';
|
||
|
||
global.fetch = async () => ({
|
||
ok: true,
|
||
json: async () => ({
|
||
web: {
|
||
results: [
|
||
{ title: 'Test Result', url: 'https://example.com', description: 'A test result', age: '1d' },
|
||
],
|
||
},
|
||
}),
|
||
});
|
||
|
||
await cmdWebsearch('test query', { limit: 5, freshness: 'pd' }, false);
|
||
|
||
const output = JSON.parse(captured);
|
||
assert.strictEqual(output.available, true);
|
||
assert.strictEqual(output.query, 'test query');
|
||
assert.strictEqual(output.count, 1);
|
||
assert.strictEqual(output.results[0].title, 'Test Result');
|
||
assert.strictEqual(output.results[0].url, 'https://example.com');
|
||
assert.strictEqual(output.results[0].age, '1d');
|
||
});
|
||
|
||
test('constructs correct URL parameters', async () => {
|
||
process.env.BRAVE_API_KEY = 'test-key';
|
||
let capturedUrl = '';
|
||
|
||
global.fetch = async (url) => {
|
||
capturedUrl = url;
|
||
return {
|
||
ok: true,
|
||
json: async () => ({ web: { results: [] } }),
|
||
};
|
||
};
|
||
|
||
await cmdWebsearch('node.js testing', { limit: 5, freshness: 'pd' }, false);
|
||
|
||
const parsed = new URL(capturedUrl);
|
||
assert.strictEqual(parsed.searchParams.get('q'), 'node.js testing', 'query param should decode to original string');
|
||
assert.strictEqual(parsed.searchParams.get('count'), '5', 'count param should be 5');
|
||
assert.strictEqual(parsed.searchParams.get('freshness'), 'pd', 'freshness param should be pd');
|
||
});
|
||
|
||
test('handles API error (non-200 status)', async () => {
|
||
process.env.BRAVE_API_KEY = 'test-key';
|
||
|
||
global.fetch = async () => ({
|
||
ok: false,
|
||
status: 401,
|
||
headers: { get: () => null },
|
||
});
|
||
|
||
await cmdWebsearch('test query', {}, false);
|
||
|
||
const output = JSON.parse(captured);
|
||
assert.strictEqual(output.available, false);
|
||
assert.ok(output.error.includes('401'), 'error should include status code');
|
||
});
|
||
|
||
test('handles network failure', async () => {
|
||
process.env.BRAVE_API_KEY = 'test-key';
|
||
|
||
global.fetch = async () => {
|
||
throw new Error('Network timeout');
|
||
};
|
||
|
||
await cmdWebsearch('test query', {}, false);
|
||
|
||
const output = JSON.parse(captured);
|
||
assert.strictEqual(output.available, false);
|
||
assert.strictEqual(output.error, 'Network timeout');
|
||
});
|
||
|
||
// ── New retry/timeout tests (A–E) ──────────────────────────────────────────
|
||
|
||
test('A. timeout is bounded: AbortSignal fires, resolves with available=false and attempts field', async (t) => {
|
||
process.env.BRAVE_API_KEY = 'test-key';
|
||
process.env.GSD_WEBSEARCH_TIMEOUT_MS = '20';
|
||
t.after(() => { delete process.env.GSD_WEBSEARCH_TIMEOUT_MS; });
|
||
|
||
global.fetch = async (_url, init) => new Promise((_resolve, reject) => {
|
||
init.signal.addEventListener('abort', () => reject(new DOMException('aborted', 'AbortError')));
|
||
});
|
||
|
||
await cmdWebsearch('q', {}, false);
|
||
|
||
const output = JSON.parse(captured);
|
||
assert.strictEqual(output.available, false, 'should be available=false after timeout exhaustion');
|
||
assert.ok(typeof output.attempts === 'number', 'should include attempts field');
|
||
});
|
||
|
||
test('B. retry on 503 then success: succeeds on 2nd attempt, fetch called exactly twice', async () => {
|
||
process.env.BRAVE_API_KEY = 'test-key';
|
||
let callCount = 0;
|
||
|
||
global.fetch = async () => {
|
||
callCount++;
|
||
if (callCount === 1) {
|
||
return { ok: false, status: 503, headers: { get: () => null } };
|
||
}
|
||
return {
|
||
ok: true,
|
||
json: async () => ({
|
||
web: { results: [{ title: 'T', url: 'https://example.com', description: 'D' }] },
|
||
}),
|
||
};
|
||
};
|
||
|
||
await cmdWebsearch('test query', {}, false);
|
||
|
||
const output = JSON.parse(captured);
|
||
assert.strictEqual(output.available, true, 'should succeed after retry');
|
||
assert.strictEqual(output.results.length, 1, 'should have one result');
|
||
assert.strictEqual(callCount, 2, 'fetch should be called exactly twice');
|
||
});
|
||
|
||
test('C. 429 honors Retry-After then succeeds on 2nd call, fetch called exactly twice', async () => {
|
||
process.env.BRAVE_API_KEY = 'test-key';
|
||
let callCount = 0;
|
||
|
||
global.fetch = async () => {
|
||
callCount++;
|
||
if (callCount === 1) {
|
||
return {
|
||
ok: false,
|
||
status: 429,
|
||
headers: { get: (h) => h.toLowerCase() === 'retry-after' ? '0' : null },
|
||
};
|
||
}
|
||
return {
|
||
ok: true,
|
||
json: async () => ({
|
||
web: { results: [{ title: 'T', url: 'https://example.com', description: 'D' }] },
|
||
}),
|
||
};
|
||
};
|
||
|
||
await cmdWebsearch('test query', {}, false);
|
||
|
||
const output = JSON.parse(captured);
|
||
assert.strictEqual(output.available, true, 'should succeed after 429 retry');
|
||
assert.strictEqual(callCount, 2, 'fetch should be called exactly twice');
|
||
});
|
||
|
||
test('D. no retry on 401: fails immediately, fetch called exactly once', async () => {
|
||
process.env.BRAVE_API_KEY = 'test-key';
|
||
let callCount = 0;
|
||
|
||
global.fetch = async () => {
|
||
callCount++;
|
||
return { ok: false, status: 401, headers: { get: () => null } };
|
||
};
|
||
|
||
await cmdWebsearch('test query', {}, false);
|
||
|
||
const output = JSON.parse(captured);
|
||
assert.strictEqual(output.available, false, 'should be available=false');
|
||
assert.strictEqual(output.error, 'API error: 401', 'error should be API error: 401');
|
||
assert.strictEqual(output.attempts, undefined, 'should NOT have attempts field on immediate fail');
|
||
assert.strictEqual(callCount, 1, 'fetch should be called exactly once');
|
||
});
|
||
|
||
test('E. network error retried then exhausted: attempts=3, fetch called 3 times', async () => {
|
||
process.env.BRAVE_API_KEY = 'test-key';
|
||
let callCount = 0;
|
||
|
||
global.fetch = async () => {
|
||
callCount++;
|
||
throw new Error('boom');
|
||
};
|
||
|
||
await cmdWebsearch('test query', {}, false);
|
||
|
||
const output = JSON.parse(captured);
|
||
assert.strictEqual(output.available, false, 'should be available=false');
|
||
assert.ok(output.error.includes('boom'), 'error should include boom');
|
||
assert.strictEqual(output.attempts, 3, 'attempts should be 3');
|
||
assert.strictEqual(callCount, 3, 'fetch should be called 3 times');
|
||
});
|
||
});
|
||
|
||
describe('stats command', () => {
|
||
let tmpDir;
|
||
|
||
beforeEach(() => {
|
||
tmpDir = createTempProject();
|
||
});
|
||
|
||
afterEach(() => {
|
||
cleanup(tmpDir);
|
||
});
|
||
|
||
test('returns valid JSON with empty project', () => {
|
||
const result = runGsdTools('stats', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const stats = JSON.parse(result.output);
|
||
assert.ok(Array.isArray(stats.phases), 'phases should be an array');
|
||
assert.strictEqual(stats.total_plans, 0);
|
||
assert.strictEqual(stats.total_summaries, 0);
|
||
assert.strictEqual(stats.percent, 0);
|
||
assert.strictEqual(stats.phases_completed, 0);
|
||
assert.strictEqual(stats.phases_total, 0);
|
||
assert.strictEqual(stats.requirements_total, 0);
|
||
assert.strictEqual(stats.requirements_complete, 0);
|
||
});
|
||
|
||
test('counts phases, plans, and summaries correctly', () => {
|
||
const p1 = path.join(tmpDir, '.planning', 'phases', '01-auth');
|
||
const p2 = path.join(tmpDir, '.planning', 'phases', '02-api');
|
||
fs.mkdirSync(p1, { recursive: true });
|
||
fs.mkdirSync(p2, { recursive: true });
|
||
|
||
// Phase 1: 2 plans, 2 summaries, passing verification (complete)
|
||
fs.writeFileSync(path.join(p1, '01-01-PLAN.md'), '# Plan');
|
||
fs.writeFileSync(path.join(p1, '01-02-PLAN.md'), '# Plan');
|
||
fs.writeFileSync(path.join(p1, '01-01-SUMMARY.md'), '# Summary');
|
||
fs.writeFileSync(path.join(p1, '01-02-SUMMARY.md'), '# Summary');
|
||
fs.writeFileSync(path.join(p1, 'VERIFICATION.md'), '---\nstatus: passed\n---\n# Verification');
|
||
|
||
// Phase 2: 1 plan, 0 summaries (planned)
|
||
fs.writeFileSync(path.join(p2, '02-01-PLAN.md'), '# Plan');
|
||
|
||
const result = runGsdTools('stats', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const stats = JSON.parse(result.output);
|
||
assert.strictEqual(stats.phases_total, 2);
|
||
assert.strictEqual(stats.phases_completed, 1);
|
||
assert.strictEqual(stats.total_plans, 3);
|
||
assert.strictEqual(stats.total_summaries, 2);
|
||
assert.strictEqual(stats.percent, 50);
|
||
assert.strictEqual(stats.plan_percent, 67);
|
||
});
|
||
|
||
test('counts requirements from REQUIREMENTS.md', () => {
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'REQUIREMENTS.md'),
|
||
`# Requirements
|
||
|
||
## v1 Requirements
|
||
|
||
- [x] **AUTH-01**: User can sign up
|
||
- [x] **AUTH-02**: User can log in
|
||
- [ ] **API-01**: REST endpoints
|
||
- [ ] **API-02**: GraphQL support
|
||
`
|
||
);
|
||
|
||
const result = runGsdTools('stats', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const stats = JSON.parse(result.output);
|
||
assert.strictEqual(stats.requirements_total, 4);
|
||
assert.strictEqual(stats.requirements_complete, 2);
|
||
});
|
||
|
||
test('reads last activity from STATE.md', () => {
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'STATE.md'),
|
||
`# State\n\n**Current Phase:** 01\n**Status:** In progress\n**Last Activity:** 2025-06-15\n**Last Activity Description:** Working\n`
|
||
);
|
||
|
||
const result = runGsdTools('stats', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const stats = JSON.parse(result.output);
|
||
assert.strictEqual(stats.last_activity, '2025-06-15');
|
||
});
|
||
|
||
test('reads last activity from plain STATE.md template format', () => {
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'STATE.md'),
|
||
`# Project State\n\n## Current Position\n\nPhase: 1 of 2 (Foundation)\nPlan: 1 of 1 in current phase\nStatus: In progress\nLast activity: 2025-06-16 — Finished plan 01-01\n`
|
||
);
|
||
|
||
const result = runGsdTools('stats', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const stats = JSON.parse(result.output);
|
||
assert.strictEqual(stats.last_activity, '2025-06-16 — Finished plan 01-01');
|
||
});
|
||
|
||
test('includes roadmap-only phases in totals and preserves hyphenated names', () => {
|
||
const p1 = path.join(tmpDir, '.planning', 'phases', '14-auth-hardening');
|
||
const p2 = path.join(tmpDir, '.planning', 'phases', '15-proof-generation');
|
||
fs.mkdirSync(p1, { recursive: true });
|
||
fs.mkdirSync(p2, { recursive: true });
|
||
fs.writeFileSync(path.join(p1, '14-01-PLAN.md'), '# Plan');
|
||
fs.writeFileSync(path.join(p1, '14-01-SUMMARY.md'), '# Summary');
|
||
fs.writeFileSync(path.join(p1, 'VERIFICATION.md'), '---\nstatus: passed\n---\n# Verified');
|
||
fs.writeFileSync(path.join(p2, '15-01-PLAN.md'), '# Plan');
|
||
fs.writeFileSync(path.join(p2, '15-01-SUMMARY.md'), '# Summary');
|
||
fs.writeFileSync(path.join(p2, 'VERIFICATION.md'), '---\nstatus: passed\n---\n# Verified');
|
||
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||
`# Roadmap
|
||
|
||
- [x] **Phase 14: Auth Hardening**
|
||
- [x] **Phase 15: Proof Generation**
|
||
- [ ] **Phase 16: Multi-Claim Verification & UX**
|
||
|
||
## Milestone v1.0 Growth
|
||
|
||
### Phase 14: Auth Hardening
|
||
**Goal:** Improve auth checks
|
||
|
||
### Phase 15: Proof Generation
|
||
**Goal:** Improve proof generation
|
||
|
||
### Phase 16: Multi-Claim Verification & UX
|
||
**Goal:** Support multi-claim verification
|
||
`
|
||
);
|
||
|
||
const result = runGsdTools('stats', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const stats = JSON.parse(result.output);
|
||
assert.strictEqual(stats.phases_total, 3);
|
||
assert.strictEqual(stats.phases_completed, 2);
|
||
assert.strictEqual(stats.percent, 67);
|
||
assert.strictEqual(stats.plan_percent, 100);
|
||
assert.strictEqual(
|
||
stats.phases.find(p => p.number === '16')?.name,
|
||
'Multi-Claim Verification & UX'
|
||
);
|
||
assert.strictEqual(
|
||
stats.phases.find(p => p.number === '16')?.status,
|
||
'Not Started'
|
||
);
|
||
});
|
||
|
||
test('reports git commit count and first commit date from repository history', () => {
|
||
execSync('git init', { cwd: tmpDir, stdio: 'pipe' });
|
||
execSync('git config user.email "test@example.com"', { cwd: tmpDir, stdio: 'pipe' });
|
||
execSync('git config user.name "Test User"', { cwd: tmpDir, stdio: 'pipe' });
|
||
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'PROJECT.md'), '# Project\n');
|
||
execSync('git add -A', { cwd: tmpDir, stdio: 'pipe' });
|
||
execSync('git commit -m "initial commit"', {
|
||
cwd: tmpDir,
|
||
stdio: 'pipe',
|
||
env: {
|
||
...process.env,
|
||
GIT_AUTHOR_DATE: '2026-01-01T00:00:00Z',
|
||
GIT_COMMITTER_DATE: '2026-01-01T00:00:00Z',
|
||
},
|
||
});
|
||
|
||
fs.writeFileSync(path.join(tmpDir, 'README.md'), '# Updated\n');
|
||
execSync('git add README.md', { cwd: tmpDir, stdio: 'pipe' });
|
||
execSync('git commit -m "second commit"', {
|
||
cwd: tmpDir,
|
||
stdio: 'pipe',
|
||
env: {
|
||
...process.env,
|
||
GIT_AUTHOR_DATE: '2026-02-01T00:00:00Z',
|
||
GIT_COMMITTER_DATE: '2026-02-01T00:00:00Z',
|
||
},
|
||
});
|
||
|
||
const result = runGsdTools('stats', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const stats = JSON.parse(result.output);
|
||
assert.strictEqual(stats.git_commits, 2);
|
||
assert.strictEqual(stats.git_first_commit_date, '2026-01-01');
|
||
});
|
||
|
||
test('table format renders readable output', () => {
|
||
const p1 = path.join(tmpDir, '.planning', 'phases', '01-auth');
|
||
fs.mkdirSync(p1, { recursive: true });
|
||
fs.writeFileSync(path.join(p1, '01-01-PLAN.md'), '# Plan');
|
||
fs.writeFileSync(path.join(p1, '01-01-SUMMARY.md'), '# Summary');
|
||
fs.writeFileSync(path.join(p1, 'VERIFICATION.md'), '---\nstatus: passed\n---\n# Verified');
|
||
|
||
const result = runGsdTools('stats table', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const parsed = JSON.parse(result.output);
|
||
assert.ok(parsed.rendered, 'table format should include rendered field');
|
||
assert.ok(parsed.rendered.includes('Statistics'), 'should include Statistics header');
|
||
assert.ok(parsed.rendered.includes('| Phase |'), 'should include table header');
|
||
assert.ok(parsed.rendered.includes('| 1 |'), 'should include phase row');
|
||
assert.ok(parsed.rendered.includes('1/1 phases'), 'should report phase progress');
|
||
});
|
||
|
||
test('phase with summaries but no verification is Executed, not Complete', () => {
|
||
const p1 = path.join(tmpDir, '.planning', 'phases', '01-auth');
|
||
fs.mkdirSync(p1, { recursive: true });
|
||
fs.writeFileSync(path.join(p1, '01-01-PLAN.md'), '# Plan');
|
||
fs.writeFileSync(path.join(p1, '01-01-SUMMARY.md'), '# Summary');
|
||
const result = runGsdTools('stats', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const stats = JSON.parse(result.output);
|
||
const phase = stats.phases.find(p => p.number === '01' || p.number === '1');
|
||
assert.strictEqual(phase.status, 'Executed', 'should be Executed without verification');
|
||
assert.strictEqual(stats.phases_completed, 0, 'unverified phase should not count as completed');
|
||
});
|
||
|
||
test('phase with passing verification is Complete', () => {
|
||
const p1 = path.join(tmpDir, '.planning', 'phases', '01-auth');
|
||
fs.mkdirSync(p1, { recursive: true });
|
||
fs.writeFileSync(path.join(p1, '01-01-PLAN.md'), '# Plan');
|
||
fs.writeFileSync(path.join(p1, '01-01-SUMMARY.md'), '# Summary');
|
||
fs.writeFileSync(path.join(p1, 'VERIFICATION.md'), '---\nstatus: passed\n---\n# Verification');
|
||
const result = runGsdTools('stats', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const stats = JSON.parse(result.output);
|
||
const phase = stats.phases.find(p => p.number === '01' || p.number === '1');
|
||
assert.strictEqual(phase.status, 'Complete', 'should be Complete with passing verification');
|
||
assert.strictEqual(stats.phases_completed, 1);
|
||
});
|
||
|
||
test('phase with gaps_found verification is Executed', () => {
|
||
const p1 = path.join(tmpDir, '.planning', 'phases', '01-auth');
|
||
fs.mkdirSync(p1, { recursive: true });
|
||
fs.writeFileSync(path.join(p1, '01-01-PLAN.md'), '# Plan');
|
||
fs.writeFileSync(path.join(p1, '01-01-SUMMARY.md'), '# Summary');
|
||
fs.writeFileSync(path.join(p1, 'VERIFICATION.md'), '---\nstatus: gaps_found\n---\n# Verification');
|
||
const result = runGsdTools('stats', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const stats = JSON.parse(result.output);
|
||
const phase = stats.phases.find(p => p.number === '01' || p.number === '1');
|
||
assert.strictEqual(phase.status, 'Executed', 'gaps_found should show as Executed');
|
||
});
|
||
|
||
test('phase with human_needed verification shows Needs Review', () => {
|
||
const p1 = path.join(tmpDir, '.planning', 'phases', '01-auth');
|
||
fs.mkdirSync(p1, { recursive: true });
|
||
fs.writeFileSync(path.join(p1, '01-01-PLAN.md'), '# Plan');
|
||
fs.writeFileSync(path.join(p1, '01-01-SUMMARY.md'), '# Summary');
|
||
fs.writeFileSync(path.join(p1, 'VERIFICATION.md'), '---\nstatus: human_needed\n---\n# Verification');
|
||
const result = runGsdTools('stats', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const stats = JSON.parse(result.output);
|
||
const phase = stats.phases.find(p => p.number === '01' || p.number === '1');
|
||
assert.strictEqual(phase.status, 'Needs Review', 'human_needed should show as Needs Review');
|
||
});
|
||
|
||
test('progress command also uses verification-aware status', () => {
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||
`# Roadmap v1.0 MVP\n`
|
||
);
|
||
const p1 = path.join(tmpDir, '.planning', 'phases', '01-auth');
|
||
fs.mkdirSync(p1, { recursive: true });
|
||
fs.writeFileSync(path.join(p1, '01-01-PLAN.md'), '# Plan');
|
||
fs.writeFileSync(path.join(p1, '01-01-SUMMARY.md'), '# Summary');
|
||
|
||
const result = runGsdTools('progress json', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.phases[0].status, 'Executed', 'progress should show Executed without verification');
|
||
});
|
||
|
||
test('does not duplicate phases when ROADMAP uses unpadded numbers and dirs use padded numbers', () => {
|
||
// ROADMAP.md uses "Phase 1:" (unpadded) but directory is "01-auth" (padded).
|
||
// Without normalization, the Map holds two entries: "1" and "01", doubling phases_total.
|
||
const p1 = path.join(tmpDir, '.planning', 'phases', '01-auth');
|
||
fs.mkdirSync(p1, { recursive: true });
|
||
fs.writeFileSync(path.join(p1, '01-01-PLAN.md'), '# Plan');
|
||
fs.writeFileSync(path.join(p1, '01-01-SUMMARY.md'), '# Summary');
|
||
fs.writeFileSync(path.join(p1, 'VERIFICATION.md'), '---\nstatus: passed\n---\n# Verified');
|
||
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||
[
|
||
'# Roadmap',
|
||
'',
|
||
'## Milestone v1',
|
||
'',
|
||
'### Phase 1: Auth',
|
||
'**Goal:** Authentication',
|
||
].join('\n')
|
||
);
|
||
|
||
const result = runGsdTools('stats', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
|
||
const stats = JSON.parse(result.output);
|
||
assert.strictEqual(stats.phases_total, 1, 'unpadded ROADMAP heading and padded dir should merge into one phase');
|
||
assert.strictEqual(stats.phases_completed, 1);
|
||
assert.strictEqual(stats.phases.length, 1);
|
||
});
|
||
});
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
// check-commit command (#1395)
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
|
||
describe('check-commit command', () => {
|
||
const { createTempGitProject } = require('./helpers.cjs');
|
||
let tmpDir;
|
||
|
||
beforeEach(() => {
|
||
tmpDir = createTempGitProject();
|
||
});
|
||
|
||
afterEach(() => {
|
||
cleanup(tmpDir);
|
||
});
|
||
|
||
test('allows commit when commit_docs is true', () => {
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'config.json'),
|
||
JSON.stringify({ commit_docs: true })
|
||
);
|
||
const result = runGsdTools('check-commit', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.allowed, true);
|
||
});
|
||
|
||
test('allows commit when no .planning/ files staged and commit_docs is false', () => {
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'config.json'),
|
||
JSON.stringify({ commit_docs: false })
|
||
);
|
||
// Stage a non-planning file
|
||
fs.writeFileSync(path.join(tmpDir, 'src.js'), 'console.log("hi")');
|
||
execSync('git add src.js', { cwd: tmpDir, stdio: 'pipe' });
|
||
|
||
const result = runGsdTools('check-commit', tmpDir);
|
||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||
const output = JSON.parse(result.output);
|
||
assert.strictEqual(output.allowed, true);
|
||
});
|
||
|
||
test('blocks commit when .planning/ files staged and commit_docs is false', () => {
|
||
fs.writeFileSync(
|
||
path.join(tmpDir, '.planning', 'config.json'),
|
||
JSON.stringify({ commit_docs: false })
|
||
);
|
||
fs.writeFileSync(path.join(tmpDir, '.planning', 'STATE.md'), '# State');
|
||
execSync('git add .planning/STATE.md', { cwd: tmpDir, stdio: 'pipe' });
|
||
|
||
const result = runGsdTools('check-commit', tmpDir);
|
||
assert.ok(!result.success, 'should block commit');
|
||
assert.ok(result.error.includes('.planning/'), 'error should mention .planning/ files');
|
||
assert.ok(result.error.includes('unstage'), 'error should suggest unstage command');
|
||
});
|
||
});
|
||
|
||
describe('_wsParseRetryAfter (#308)', () => {
|
||
const { _wsParseRetryAfter } = require('../get-shit-done/bin/lib/commands.cjs');
|
||
|
||
test('integer seconds: "120" → 60000 (capped at 60s)', () => {
|
||
assert.strictEqual(_wsParseRetryAfter('120'), 60000);
|
||
});
|
||
|
||
test('leading zero: "01" → 1000', () => {
|
||
assert.strictEqual(_wsParseRetryAfter('01'), 1000);
|
||
});
|
||
|
||
test('whitespace: " 5 " → 5000', () => {
|
||
assert.strictEqual(_wsParseRetryAfter(' 5 '), 5000);
|
||
});
|
||
|
||
test('"0" → 0', () => {
|
||
assert.strictEqual(_wsParseRetryAfter('0'), 0);
|
||
});
|
||
|
||
test('value > 60s cap: "120000" → 60000', () => {
|
||
assert.strictEqual(_wsParseRetryAfter('120000'), 60000);
|
||
});
|
||
|
||
test('future HTTP-date → value in (0, 60000]', () => {
|
||
const futureDate = new Date(Date.now() + 5000).toUTCString();
|
||
const v = _wsParseRetryAfter(futureDate);
|
||
assert.ok(typeof v === 'number' && v > 0 && v <= 60000, `expected (0,60000], got ${v}`);
|
||
});
|
||
|
||
test('past HTTP-date → 0', () => {
|
||
const pastDate = new Date(Date.now() - 5000).toUTCString();
|
||
assert.strictEqual(_wsParseRetryAfter(pastDate), 0);
|
||
});
|
||
|
||
test('"garbage" → null', () => {
|
||
assert.strictEqual(_wsParseRetryAfter('garbage'), null);
|
||
});
|
||
|
||
test('"" → null', () => {
|
||
assert.strictEqual(_wsParseRetryAfter(''), null);
|
||
});
|
||
|
||
test('null → null', () => {
|
||
assert.strictEqual(_wsParseRetryAfter(null), null);
|
||
});
|
||
});
|