Files
msd-core/tests/bug-2410-stream-checkpoint-heartbeats.test.cjs
Tom Boucher b8c33647d8 refactor(tests): retire output-grep & source-grep via typed surfaces (finish #2974) (#462)
* refactor(#455): implement typed surfaces to retire grep tests

Production surfaces added:
- hooks/managed-hooks-registry.cjs: new CJS module exporting MANAGED_HOOKS
  as a typed array; gsd-check-update-worker.js now requires it instead of
  declaring an inline array
- bin/install.js: elevate inline gsdHooks to module-level GSD_UNINSTALL_HOOKS,
  export it alongside runtimeMap/allRuntimes (already exported)
- scripts/build-hooks.js: export HOOKS_TO_COPY; guard build() behind
  require.main===module so tests can require the file without triggering a build
- get-shit-done/bin/lib/init.cjs: add --json mode to agent-skills command,
  emitting typed IR { agent_type, block, skills_count } for test assertions
- get-shit-done/bin/gsd-tools.cjs: wire --json flag for agent-skills dispatch

Category-B source-grep migrations:
- tests/managed-hooks.test.cjs: require MANAGED_HOOKS from registry, drop fs.readFileSync+regex
- tests/orphaned-hooks.test.cjs: require MANAGED_HOOKS+HOOKS_TO_COPY as typed exports
- tests/hooks-opt-in.test.cjs: replace gsdHooks regex-parse with GSD_UNINSTALL_HOOKS import
- tests/install-minimal-hooks.test.cjs: replace gsdHooks regex-parse with GSD_UNINSTALL_HOOKS
- tests/copilot-install.test.cjs: replace src.includes() checks with typed
  assertions on runtimeMap, allRuntimes, parseRuntimeInput, buildRuntimePromptText
- tests/agent-skills.test.cjs: migrate to --json typed IR assertions

pending-migration-to-typed-ir token cleared (87 of 87 files):
- 78 files already had source-text-is-the-product; removed duplicate token
- 5 files already used typed assertions; reclassified or annotated
- 4 files required individual reclassification to source-text-is-the-product
  or architectural-invariant

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(#455): update workflow-guard test to typed GSD_UNINSTALL_HOOKS import; isolate HOME in runtime-launcher (D) test

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(#455): guard install.js main() behind require.main===module so the typed export is require-safe

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs(#455): document --json typed surfaces for agent-skills, progress, validate context

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs(#455): add changeset fragment for new --json surfaces

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(#455): complete grep migration for files flagged by lint-tests

The branch commit 4e630d99 stripped `allow-test-rule: pending-migration-to-typed-ir`
from ~80 test files without replacing their assertions or adding the correct
exemption annotation. The files were NOT source-grep tests — they read .md
workflow/agent/command/reference files (source-text-is-the-product) or hook
source files for structural invariants (structural-regression-guard). No
assertion logic was changed; only the correct allow-test-rule annotation was
added to each file per CONTRIBUTING.md exception matrix.

73 files: `source-text-is-the-product` — workflow/agent/command/reference .md
7 files:  `structural-regression-guard` — hook .js / bin/install.js structural checks

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: CI Rebase Check <ci@gsd-redux>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-29 11:39:52 -04:00

179 lines
7.0 KiB
JavaScript

// allow-test-rule: source-text-is-the-product
// Workflow .md / agent .md / command .md / reference .md files — their text
// IS what the runtime loads. Testing text content tests the deployed contract.
// Per CONTRIBUTING.md exception matrix.
/**
* Bug #2410 — /gsd:manager background execute-phase Task fails with
* "Stream idle timeout" on multi-plan phases.
*
* Fix: execute-phase.md instructs the orchestrator to emit `[checkpoint]`
* heartbeat lines at every wave boundary AND every plan boundary so the
* Claude API SSE stream never idles long enough to trigger the platform
* timeout. This test validates the workflow contract that backs that fix.
*/
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const WORKFLOW_PATH = path.join(
__dirname,
'..',
'get-shit-done',
'workflows',
'execute-phase.md'
);
const COMMANDS_DOC_PATH = path.join(__dirname, '..', 'docs', 'COMMANDS.md');
describe('bug #2410: execute-phase emits checkpoint heartbeats', () => {
const workflow = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
test('workflow references the stream idle timeout symptom by name', () => {
assert.ok(
/Stream idle timeout/.test(workflow),
'workflow should name the API error it is preventing'
);
assert.ok(
workflow.includes('#2410'),
'workflow should cite the tracking issue for future maintainers'
);
});
test('workflow defines a [checkpoint] heartbeat line format', () => {
assert.ok(
workflow.includes('[checkpoint]'),
'workflow should document the [checkpoint] marker prefix'
);
});
test('workflow emits a wave-start heartbeat (A: wave-boundary checkpoint)', () => {
assert.ok(
/\[checkpoint\][^\n]*wave \{N\}\/\{M\} starting/.test(workflow),
'workflow should emit a wave-start [checkpoint] marker before spawning agents'
);
});
test('workflow emits a wave-complete heartbeat (A: wave-boundary checkpoint)', () => {
assert.ok(
/\[checkpoint\][^\n]*wave \{N\}\/\{M\} complete/.test(workflow),
'workflow should emit a wave-complete [checkpoint] marker after spot-checks'
);
});
test('workflow emits a plan-start heartbeat (B: plan-boundary checkpoint)', () => {
assert.ok(
/\[checkpoint\][^\n]*plan \{plan_id\} starting/.test(workflow),
'workflow should emit a plan-start [checkpoint] marker before each Task() dispatch'
);
});
test('workflow emits a plan-complete heartbeat (B: plan-boundary checkpoint)', () => {
assert.ok(
/\[checkpoint\][^\n]*plan \{plan_id\} complete/.test(workflow),
'workflow should emit a plan-complete [checkpoint] marker after executor returns'
);
});
test('workflow handles plan failure and checkpoint-gate heartbeats too', () => {
assert.ok(
/\[checkpoint\][^\n]*plan \{plan_id\} failed/.test(workflow),
'workflow should emit a plan-failed [checkpoint] marker on executor error'
);
assert.ok(
/\[checkpoint\][^\n]*plan \{plan_id\} checkpoint/.test(workflow),
'workflow should emit a heartbeat when a plan returns a human-gate checkpoint'
);
});
test('heartbeats include a monotonic plans-done counter', () => {
// The {P}/{Q} counter lets grep-based recovery tools reconstruct progress
// from a truncated transcript if the agent dies mid-phase.
assert.ok(
/\{P\}\/\{Q\} plans done/.test(workflow),
'heartbeats should include a {P}/{Q} phase-wide completed-plan counter'
);
});
test('wave-start heartbeat precedes the "Describe what\'s being built" text', () => {
const describeIdx = workflow.indexOf("Describe what's being built");
const heartbeatIdx = workflow.indexOf(
'[checkpoint] phase {PHASE_NUMBER} wave {N}/{M} starting'
);
assert.ok(describeIdx !== -1, 'workflow should still have the describe step');
assert.ok(heartbeatIdx !== -1, 'wave-start heartbeat template should be present');
// The instruction to emit the heartbeat appears in step 2, which is the
// step titled "Describe what's being built". The actual sentinel text we
// look for is the inline literal template — it must be emitted BEFORE any
// tool calls in that step.
const step2 = workflow.slice(
describeIdx,
workflow.indexOf('3. **Spawn executor agents', describeIdx)
);
assert.ok(
step2.includes('[checkpoint]'),
'step 2 should instruct the orchestrator to emit a [checkpoint] heartbeat'
);
assert.ok(
/before any further reasoning or spawning/i.test(step2) ||
/before any tool call/i.test(step2) ||
/no tool call/i.test(step2),
'step 2 should make clear the heartbeat is an assistant-text line, not a tool call'
);
});
test('plan-start heartbeat is inside the spawn step', () => {
const spawnIdx = workflow.indexOf('3. **Spawn executor agents');
const waitIdx = workflow.indexOf('4. **Wait for all agents', spawnIdx);
assert.ok(spawnIdx !== -1 && waitIdx !== -1, 'spawn and wait steps must exist');
const step3 = workflow.slice(spawnIdx, waitIdx);
assert.ok(
/\[checkpoint\][^\n]*plan \{plan_id\} starting/.test(step3),
'plan-start heartbeat should be emitted inside step 3 (spawn executor agents)'
);
});
test('plan-complete and wave-complete heartbeats are inside the wait/report steps', () => {
const waitIdx = workflow.indexOf('4. **Wait for all agents');
const hookIdx = workflow.indexOf('5. **Post-wave hook validation', waitIdx);
assert.ok(waitIdx !== -1 && hookIdx !== -1, 'wait + hook steps must exist');
const step4 = workflow.slice(waitIdx, hookIdx);
assert.ok(
/\[checkpoint\][^\n]*plan \{plan_id\} complete/.test(step4),
'plan-complete heartbeat should be emitted in step 4 (wait for agents)'
);
const reportIdx = workflow.indexOf('6. **Report completion');
const failureIdx = workflow.indexOf('7. **Handle failures', reportIdx);
assert.ok(reportIdx !== -1 && failureIdx !== -1, 'report + failure steps must exist');
const step6 = workflow.slice(reportIdx, failureIdx);
assert.ok(
/\[checkpoint\][^\n]*wave \{N\}\/\{M\} complete/.test(step6),
'wave-complete heartbeat should be emitted in step 6 (report completion)'
);
});
});
describe('bug #2410: checkpoint heartbeat format is user-documented', () => {
const commandsDoc = fs.readFileSync(COMMANDS_DOC_PATH, 'utf-8');
test('COMMANDS.md documents the [checkpoint] format under /gsd-manager', () => {
const managerIdx = commandsDoc.indexOf('### `/gsd-manager`');
assert.ok(managerIdx !== -1, '/gsd-manager section should exist');
const section = commandsDoc.slice(managerIdx, managerIdx + 4000);
assert.ok(
/\[checkpoint\]/.test(section),
'COMMANDS.md /gsd-manager section should document [checkpoint] heartbeat markers'
);
assert.ok(
/Stream idle timeout/i.test(section),
'COMMANDS.md should explain what the heartbeats prevent'
);
assert.ok(
/#2410/.test(section),
'COMMANDS.md should reference the tracking issue'
);
});
});