Files
msd-core/tests/gates-taxonomy.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

130 lines
4.7 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.
/**
* Validates the gates taxonomy reference document (#1715).
*
* Ensures the reference file exists, defines all 4 canonical gate types,
* includes the gate matrix table, and is cross-referenced from workflows.
*/
const { describe, test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const ROOT = path.join(__dirname, '..');
const GATES_REF = path.join(ROOT, 'get-shit-done', 'references', 'gates.md');
describe('gates taxonomy (#1715)', () => {
test('reference file exists', () => {
assert.ok(
fs.existsSync(GATES_REF),
'get-shit-done/references/gates.md must exist'
);
});
test('defines all 4 canonical gate types', () => {
const content = fs.readFileSync(GATES_REF, 'utf-8');
const gateTypes = ['Pre-flight Gate', 'Revision Gate', 'Escalation Gate', 'Abort Gate'];
for (const gate of gateTypes) {
assert.ok(
content.includes(`### ${gate}`),
`gates.md must define "${gate}" as an h3 heading`
);
}
});
test('each gate type has Purpose, Behavior, Recovery, and Examples', () => {
const content = fs.readFileSync(GATES_REF, 'utf-8');
const sections = content.split('### ').slice(1); // split by h3, drop preamble
for (const section of sections) {
const name = section.split('\n')[0].trim();
// Only check gate type sections (not other h3s if any)
if (!name.endsWith('Gate')) continue;
for (const field of ['**Purpose:**', '**Behavior:**', '**Recovery:**', '**Examples:**']) {
assert.ok(
section.includes(field),
`Gate "${name}" must include ${field}`
);
}
}
});
test('contains Gate Matrix table', () => {
const content = fs.readFileSync(GATES_REF, 'utf-8');
assert.ok(
content.includes('## Gate Matrix'),
'gates.md must include a "Gate Matrix" section'
);
// Verify table header row
assert.ok(
content.includes('| Workflow |'),
'Gate Matrix must contain a table with Workflow column'
);
// Verify key workflow rows exist
assert.ok(content.includes('plan-phase'), 'Gate Matrix must reference plan-phase');
assert.ok(content.includes('execute-phase'), 'Gate Matrix must reference execute-phase');
assert.ok(content.includes('verify-work'), 'Gate Matrix must reference verify-work');
assert.ok(content.includes('| next |'), 'Gate Matrix must reference next workflow');
});
test('plan-phase.md references gates.md', () => {
const planPhase = path.join(ROOT, 'get-shit-done', 'workflows', 'plan-phase.md');
const content = fs.readFileSync(planPhase, 'utf-8');
assert.ok(
content.includes('references/gates.md'),
'plan-phase.md must reference gates.md in its required_reading block'
);
});
test('execute-phase.md references gates.md', () => {
const execPhase = path.join(ROOT, 'get-shit-done', 'workflows', 'execute-phase.md');
const content = fs.readFileSync(execPhase, 'utf-8');
assert.ok(
content.includes('references/gates.md'),
'execute-phase.md must reference gates.md in its required_reading block'
);
});
test('gsd-plan-checker.md references gates.md in required_reading block', () => {
const planChecker = path.join(ROOT, 'agents', 'gsd-plan-checker.md');
const content = fs.readFileSync(planChecker, 'utf-8');
const match = content.match(/<required_reading>\r?\n([\s\S]*?)\r?\n<\/required_reading>/);
assert.ok(
match,
'gsd-plan-checker.md must have a <required_reading> block'
);
assert.ok(
match[1].includes('references/gates.md'),
'gsd-plan-checker.md must reference gates.md inside <required_reading>'
);
});
test('gsd-verifier.md references gates.md in required_reading block', () => {
const verifier = path.join(ROOT, 'agents', 'gsd-verifier.md');
const content = fs.readFileSync(verifier, 'utf-8');
const match = content.match(/<required_reading>\r?\n([\s\S]*?)\r?\n<\/required_reading>/);
assert.ok(
match,
'gsd-verifier.md must have a <required_reading> block'
);
assert.ok(
match[1].includes('references/gates.md'),
'gsd-verifier.md must reference gates.md inside <required_reading>'
);
});
test('Revision Gate recovery mentions stall detection', () => {
const content = fs.readFileSync(GATES_REF, 'utf-8');
assert.ok(
content.includes('stall detection'),
'Revision Gate recovery must mention stall detection (early escalation when issues stop decreasing)'
);
});
});