* 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>
146 lines
5.1 KiB
JavaScript
146 lines
5.1 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.
|
|
|
|
/**
|
|
* Tests for code_review_command hook in ship workflow (#1876)
|
|
*
|
|
* Validates that the external code review command integration is properly
|
|
* wired into config, templates, and the ship workflow.
|
|
*/
|
|
|
|
const { describe, test, beforeEach, afterEach } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { createTempProject, cleanup, runGsdTools } = require('./helpers.cjs');
|
|
|
|
const CONFIG_CJS_PATH = path.join(__dirname, '..', 'get-shit-done', 'bin', 'lib', 'config.cjs');
|
|
const SHIP_MD_PATH = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'ship.md');
|
|
const CONFIG_TEMPLATE_PATH = path.join(__dirname, '..', 'get-shit-done', 'templates', 'config.json');
|
|
|
|
describe('code_review_command config key', () => {
|
|
test('workflow.code_review_command is in VALID_CONFIG_KEYS', () => {
|
|
const { VALID_CONFIG_KEYS } = require(CONFIG_CJS_PATH);
|
|
assert.ok(
|
|
VALID_CONFIG_KEYS.has('workflow.code_review_command'),
|
|
'workflow.code_review_command must be in VALID_CONFIG_KEYS'
|
|
);
|
|
});
|
|
|
|
test('config-set accepts workflow.code_review_command', () => {
|
|
const tmpDir = createTempProject();
|
|
try {
|
|
// Create config.json first
|
|
fs.mkdirSync(path.join(tmpDir, '.planning'), { recursive: true });
|
|
fs.writeFileSync(
|
|
path.join(tmpDir, '.planning', 'config.json'),
|
|
JSON.stringify({ workflow: {} }, null, 2)
|
|
);
|
|
|
|
const result = runGsdTools(
|
|
['config-set', 'workflow.code_review_command', 'my-review-tool --review'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(result.success, 'config-set should succeed');
|
|
|
|
const parsed = JSON.parse(result.output);
|
|
assert.strictEqual(parsed.updated, true);
|
|
assert.strictEqual(parsed.key, 'workflow.code_review_command');
|
|
assert.strictEqual(parsed.value, 'my-review-tool --review');
|
|
} finally {
|
|
cleanup(tmpDir);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('config template', () => {
|
|
test('config.json template has code_review_command under workflow section', () => {
|
|
const template = JSON.parse(fs.readFileSync(CONFIG_TEMPLATE_PATH, 'utf-8'));
|
|
assert.ok(template.workflow, 'template must have workflow section');
|
|
assert.ok(
|
|
'code_review_command' in template.workflow,
|
|
'workflow section must contain code_review_command key'
|
|
);
|
|
assert.strictEqual(
|
|
template.workflow.code_review_command,
|
|
null,
|
|
'code_review_command default should be null'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('ship workflow code_review_command integration', () => {
|
|
const shipContent = fs.readFileSync(SHIP_MD_PATH, 'utf-8');
|
|
|
|
test('ship.md contains code_review_command config check', () => {
|
|
assert.ok(
|
|
shipContent.includes('code_review_command'),
|
|
'ship.md must reference code_review_command'
|
|
);
|
|
});
|
|
|
|
test('ship.md has external review sub-step that reads config', () => {
|
|
assert.ok(
|
|
shipContent.includes('config-get') && shipContent.includes('workflow.code_review_command'),
|
|
'ship.md must read workflow.code_review_command from config'
|
|
);
|
|
});
|
|
|
|
test('ship.md generates diff against base branch for review', () => {
|
|
assert.ok(
|
|
shipContent.includes('git diff') && shipContent.includes('BASE_BRANCH'),
|
|
'ship.md must generate a diff using BASE_BRANCH for the external review'
|
|
);
|
|
});
|
|
|
|
test('ship.md has JSON parsing for external review output', () => {
|
|
assert.ok(
|
|
shipContent.includes('verdict') && shipContent.includes('APPROVED'),
|
|
'ship.md must parse JSON output with verdict field'
|
|
);
|
|
assert.ok(
|
|
shipContent.includes('REVISE'),
|
|
'ship.md must handle REVISE verdict'
|
|
);
|
|
});
|
|
|
|
test('ship.md has timeout handling for external review command (120s)', () => {
|
|
assert.ok(
|
|
shipContent.includes('120') || shipContent.includes('timeout'),
|
|
'ship.md must have timeout handling (120s) for external review command'
|
|
);
|
|
});
|
|
|
|
test('ship.md has stderr capture on failure', () => {
|
|
assert.ok(
|
|
shipContent.includes('stderr'),
|
|
'ship.md must capture stderr on external review command failure'
|
|
);
|
|
});
|
|
|
|
test('ship.md pipes review prompt to command via stdin', () => {
|
|
assert.ok(
|
|
shipContent.includes('stdin'),
|
|
'ship.md must pipe the review prompt to the command via stdin'
|
|
);
|
|
});
|
|
|
|
test('ship.md includes diff stats in review prompt', () => {
|
|
assert.ok(
|
|
shipContent.includes('diff --stat') || shipContent.includes('diffstat') || shipContent.includes('--stat'),
|
|
'ship.md must include diff stats in the review prompt'
|
|
);
|
|
});
|
|
|
|
test('ship.md falls through to existing review flow on failure', () => {
|
|
// The external review should not block the existing manual review options
|
|
assert.ok(
|
|
shipContent.includes('AskUserQuestion') || shipContent.includes('Skip review'),
|
|
'ship.md must still offer the existing manual review flow after external review'
|
|
);
|
|
});
|
|
});
|