feat(#1137): migrate review verification hooks to capabilities (#1147)

* feat(#1137): migrate review verification hooks to capabilities

* chore(#1147): add changeset
This commit is contained in:
Tom Boucher
2026-06-12 21:24:09 -04:00
committed by GitHub
parent 44024aa535
commit 1b880fefd7
25 changed files with 951 additions and 109 deletions

View File

@@ -462,11 +462,18 @@ describe('CR-INTEGRATION: workflow integration points', () => {
'execute-phase.md missing code_review_gate step name');
});
test('execute-phase.md contains config-get workflow.code_review', { skip: !PLUGIN_AVAILABLE ? 'Plugin dir not installed' : false }, () => {
const content = fs.readFileSync(path.join(PLUGIN_WORKFLOWS_DIR, 'execute-phase.md'), 'utf-8');
test('execute-phase.md resolves code-review capability hook', () => {
const content = fs.readFileSync(path.join(WORKFLOWS_DIR, 'execute-phase.md'), 'utf-8');
const gateMatch = content.match(/<step name="code_review_gate"[^>]*>([\s\S]*?)<\/step>/);
assert.ok(gateMatch, 'execute-phase.md missing code_review_gate step');
const gateContent = gateMatch[1];
assert.match(content, /config-get\s+workflow\.code_review/,
'execute-phase.md missing config-get workflow.code_review call');
assert.ok(gateContent.includes('loop render-hooks execute:post'),
'execute-phase.md code_review_gate must resolve execute:post capability hooks');
assert.ok(gateContent.includes('ref.skill == "code-review"'),
'execute-phase.md code_review_gate must identify the code-review capability hook');
assert.ok(!gateContent.match(/config-get\s+workflow\.code_review/),
'execute-phase.md code_review_gate must not read workflow.code_review directly');
});
test('execute-phase.md does NOT contain ls.*REVIEW.md.*head pattern', { skip: !PLUGIN_AVAILABLE ? 'Plugin dir not installed' : false }, () => {
@@ -488,11 +495,19 @@ describe('CR-INTEGRATION: workflow integration points', () => {
'quick.md missing code-review invocation');
});
test('quick.md contains config-get workflow.code_review', { skip: !PLUGIN_AVAILABLE ? 'Plugin dir not installed' : false }, () => {
const content = fs.readFileSync(path.join(PLUGIN_WORKFLOWS_DIR, 'quick.md'), 'utf-8');
test('quick.md resolves code-review capability hook', () => {
const content = fs.readFileSync(path.join(WORKFLOWS_DIR, 'quick.md'), 'utf-8');
const start = content.indexOf('**Step 6.25: Code review (auto)**');
const end = content.indexOf('**Step 6.5: Verification', start);
assert.ok(start !== -1 && end !== -1, 'quick.md missing Step 6.25 code review section');
const reviewContent = content.slice(start, end);
assert.match(content, /config-get\s+workflow\.code_review/,
'quick.md missing config-get workflow.code_review call');
assert.ok(reviewContent.includes('loop render-hooks execute:post'),
'quick.md code review step must resolve execute:post capability hooks');
assert.ok(reviewContent.includes('ref.skill == "code-review"'),
'quick.md code review step must identify the code-review capability hook');
assert.ok(!reviewContent.match(/config-get\s+workflow\.code_review/),
'quick.md code review step must not read workflow.code_review directly');
});
// autonomous.md tests read from the repo's canonical workflow source (WORKFLOWS_DIR),

View File

@@ -252,7 +252,7 @@ describe('spike #1018 — off means off (structural proof)', () => {
"onError must be 'skip' on the ui-review step at verify:post");
// Also verify the rendered output contains the structured heading for this point
const rendered = renderLoopHooks(resolved);
assert.match(rendered, /### Step 1: skill:ui-review \(ui\)/,
assert.match(rendered, /### Step \d+: skill:ui-review \(ui\)/,
'rendered must include the properly-structured Step block heading for ui-review at verify:post');
});

View File

@@ -0,0 +1,205 @@
'use strict';
const { describe, test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const ROOT = path.resolve(__dirname, '..');
const registry = require('../gsd-core/bin/lib/capability-registry.cjs');
function workflow(name) {
return fs.readFileSync(path.join(ROOT, 'gsd-core', 'workflows', name), 'utf8');
}
function doc(name) {
return fs.readFileSync(path.join(ROOT, 'docs', name), 'utf8');
}
function sectionBetween(content, startNeedle, endNeedle) {
const start = content.indexOf(startNeedle);
assert.ok(start !== -1, `${startNeedle} section must exist`);
const end = endNeedle ? content.indexOf(endNeedle, start) : -1;
return content.slice(start, end === -1 ? undefined : end);
}
function hookAt(point, kind, capId) {
return registry.byLoopPoint[point][kind].find((hook) => hook.capId === capId);
}
describe('ADR-857 phase 6 verification and review capability migration', () => {
test('registry declares code-review, security, and nyquist feature capabilities', () => {
for (const capId of ['code-review', 'security', 'nyquist']) {
assert.ok(registry.capabilities[capId], `${capId} capability must exist`);
assert.equal(registry.capabilities[capId].role, 'feature');
}
});
test('code-review capability owns review skills, agents, config, and execute hook', () => {
assert.equal(registry.bySkill['code-review'], 'code-review');
assert.equal(registry.byAgent['gsd-code-reviewer'], 'code-review');
assert.equal(registry.byAgent['gsd-code-fixer'], 'code-review');
assert.equal(registry.configKeys['workflow.code_review'], 'code-review');
assert.equal(registry.configKeys['workflow.code_review_depth'], 'code-review');
const hook = hookAt('execute:post', 'steps', 'code-review');
assert.ok(hook, 'code-review must register an execute:post step');
assert.deepEqual(hook.ref, { skill: 'code-review' });
assert.equal(hook.when, 'workflow.code_review');
assert.deepEqual(hook.produces, ['REVIEW.md']);
assert.ok(hook.consumes.includes('SUMMARY.md'));
});
test('security capability owns secure-phase wiring and blocking ship gate', () => {
assert.equal(registry.bySkill['secure-phase'], 'security');
assert.equal(registry.byAgent['gsd-security-auditor'], 'security');
assert.equal(registry.configKeys['workflow.security_enforcement'], 'security');
assert.equal(registry.configKeys['workflow.security_asvs_level'], 'security');
assert.equal(registry.configKeys['workflow.security_block_on'], 'security');
const step = hookAt('verify:post', 'steps', 'security');
assert.ok(step, 'security must register a verify:post step');
assert.deepEqual(step.ref, { skill: 'secure-phase' });
assert.equal(step.when, 'workflow.security_enforcement');
assert.equal(step.onError, 'halt');
const gate = hookAt('ship:pre', 'gates', 'security');
assert.ok(gate, 'security must register a blocking ship:pre gate');
assert.equal(gate.blocking, true);
assert.equal(gate.onError, 'halt');
const planContribution = hookAt('plan:pre', 'contributions', 'security');
assert.ok(planContribution, 'security must register a plan:pre contribution for threat-model guidance');
assert.equal(planContribution.into, 'planner');
assert.equal(planContribution.when, 'workflow.security_enforcement');
});
test('nyquist capability owns validate-phase wiring and config', () => {
assert.equal(registry.bySkill['validate-phase'], 'nyquist');
assert.equal(registry.byAgent['gsd-nyquist-auditor'], 'nyquist');
assert.equal(registry.configKeys['workflow.nyquist_validation'], 'nyquist');
const hook = hookAt('verify:post', 'steps', 'nyquist');
assert.ok(hook, 'nyquist must register a verify:post step');
assert.deepEqual(hook.ref, { skill: 'validate-phase' });
assert.equal(hook.when, 'workflow.nyquist_validation');
assert.deepEqual(hook.produces, ['VALIDATION.md']);
assert.ok(hook.consumes.includes('SUMMARY.md'));
});
test('autonomous code review resolves execute:post hooks instead of inlining code_review config', () => {
const content = workflow('autonomous.md');
const section = sectionBetween(
content,
'**3c.5. Code Review and Fix**',
'**3d. Post-Execution Routing**',
);
assert.ok(section.includes('loop render-hooks execute:post'));
assert.ok(section.includes('gsd-${ref.skill}'));
assert.ok(!section.includes('config-get workflow.code_review'));
});
test('execute-phase code-review gate resolves execute:post hooks instead of inlining code_review config', () => {
const content = workflow('execute-phase.md');
const section = sectionBetween(content, '<step name="code_review_gate"', '<step name="close_parent_artifacts">');
assert.ok(section.includes('loop render-hooks execute:post'));
assert.ok(section.includes('gsd-${ref.skill}'));
assert.ok(!section.includes('config-get workflow.code_review'));
});
test('quick full-mode code review resolves execute:post hooks instead of inlining code_review config', () => {
const content = workflow('quick.md');
const section = sectionBetween(content, '**Step 6.25: Code review (auto)**', '**Step 6.5: Verification');
assert.ok(section.includes('loop render-hooks execute:post'));
assert.ok(section.includes('gsd-code-reviewer'));
assert.ok(!section.includes('config-get workflow.code_review'));
});
test('code-review command self-gates through execute:post hooks', () => {
const content = workflow('code-review.md');
const section = sectionBetween(content, '<step name="check_config_gate">', '<step name="resolve_depth">');
assert.ok(section.includes('loop render-hooks execute:post'));
assert.ok(section.includes('ref.skill == "code-review"'));
assert.ok(!section.includes('config-get workflow.code_review'));
});
test('code-review-fix command self-gates through execute:post hooks', () => {
const content = workflow('code-review-fix.md');
const section = sectionBetween(content, '<step name="check_config_gate">', '<step name="check_review_exists">');
assert.ok(section.includes('loop render-hooks execute:post'));
assert.ok(section.includes('ref.skill == "code-review"'));
assert.ok(!section.includes('config-get workflow.code_review'));
});
test('verify-work resolves verify:post security hooks instead of inlining security_enforcement config', () => {
const content = workflow('verify-work.md');
const transitionStart = content.indexOf('If issues == 0:');
assert.ok(transitionStart !== -1, 'verify-work transition block must exist');
const section = content.slice(transitionStart, content.indexOf('</step>', transitionStart));
assert.ok(section.includes('loop render-hooks verify:post'));
assert.ok(section.includes('gsd-${ref.skill}'));
assert.ok(!section.includes('config-get workflow.security_enforcement'));
});
test('plan-phase threat model gate resolves plan:pre security capability hooks', () => {
const content = workflow('plan-phase.md');
const section = sectionBetween(content, '## 5.55. Security Threat Model Gate', '## 5.6. UI Design Contract Gate');
assert.ok(section.includes('loop render-hooks plan:pre'));
assert.ok(section.includes('capId == "security"'));
assert.ok(!section.includes('config-get workflow.security_enforcement'));
});
test('secure-phase command self-gates through verify:post hooks', () => {
const content = workflow('secure-phase.md');
const initFence = ['```bash', 'AUDITOR_MODEL='].join('\n');
const section = sectionBetween(content, initFence, 'Display banner:');
assert.ok(section.includes('loop render-hooks verify:post'));
assert.ok(section.includes('ref.skill == "secure-phase"'));
assert.ok(!section.includes('config-get workflow.security_enforcement'));
});
test('validate-phase command self-gates through verify:post hooks', () => {
const content = workflow('validate-phase.md');
const initFence = ['```bash', 'AUDITOR_MODEL='].join('\n');
const section = sectionBetween(content, initFence, 'Display banner:');
assert.ok(section.includes('loop render-hooks verify:post'));
assert.ok(section.includes('ref.skill == "validate-phase"'));
assert.ok(!section.includes('config-get workflow.nyquist_validation'));
});
test('documentation covers migrated review and verification capability hooks', () => {
const content = doc('reference/review-verification-capabilities.md');
const manual = doc('how-to/develop-a-capability.md');
const index = doc('README.md');
for (const term of [
'`code-review`',
'`security`',
'`nyquist`',
'`execute:post`',
'`verify:post`',
'`ship:pre`',
'gsd-tools loop render-hooks <point>',
]) {
assert.ok(content.includes(term), `capability reference must document ${term}`);
}
assert.ok(
index.includes('reference/review-verification-capabilities.md'),
'docs index must link the review and verification capabilities reference',
);
assert.ok(
manual.includes('`security` registers a `plan:pre` contribution, a `verify:post` step, and a blocking `ship:pre` gate.'),
'capability developer manual must mention review/verification hook examples',
);
});
});

View File

@@ -1,21 +1,38 @@
'use strict';
// Policy regression test for issue #138:
// config-get workflow.nyquist_validation calls in validate-phase.md and
// audit-milestone.md MUST include --default so they don't error / emit
// stderr noise when the key is absent.
//
// Form-agnostic: matches on `config-get workflow.nyquist_validation` + `--default`
// regardless of the runtime prefix ($GSD_SDK vs gsd_run), so this test
// survives PR #379's prefix rename.
// Nyquist activation must be absent-safe. ADR-857 phase 6 moved that defaulting
// into `loop render-hooks verify:post`, so workflows must consume the capability
// hook instead of calling config-get directly.
const { test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const WORKFLOWS_DIR = path.join(__dirname, '..', 'gsd-core', 'workflows');
function readWorkflow(name) {
return fs.readFileSync(path.join(WORKFLOWS_DIR, name), 'utf8');
}
function assertNyquistCapabilityGate(name) {
const content = readWorkflow(name);
assert.ok(
content.includes('loop render-hooks verify:post'),
`${name} must resolve Nyquist activation through verify:post capability hooks`
);
assert.ok(
content.includes('ref.skill == "validate-phase"'),
`${name} must identify the validate-phase capability hook`
);
assert.ok(
!content.includes('config-get workflow.nyquist_validation'),
`${name} must not read workflow.nyquist_validation directly after capability cutover`
);
}
function findNyquistConfigLine(filePath) {
const content = fs.readFileSync(filePath, 'utf8');
const lines = content.split('\n');
@@ -27,22 +44,26 @@ function findNyquistConfigLine(filePath) {
return null;
}
test('validate-phase.md: config-get workflow.nyquist_validation must include --default', () => {
const filePath = path.join(WORKFLOWS_DIR, 'validate-phase.md');
const result = findNyquistConfigLine(filePath);
assert.ok(result, 'Should find a line containing config-get workflow.nyquist_validation in validate-phase.md');
assert.ok(
result.line.includes('--default'),
`Line ${result.lineNumber} of validate-phase.md is missing --default flag.\nFound: ${result.line.trim()}`
);
test('validate-phase.md: Nyquist activation uses verify:post capability hook', () => {
assertNyquistCapabilityGate('validate-phase.md');
});
test('audit-milestone.md: config-get workflow.nyquist_validation must include --default', () => {
const filePath = path.join(WORKFLOWS_DIR, 'audit-milestone.md');
const result = findNyquistConfigLine(filePath);
assert.ok(result, 'Should find a line containing config-get workflow.nyquist_validation in audit-milestone.md');
assert.ok(
result.line.includes('--default'),
`Line ${result.lineNumber} of audit-milestone.md is missing --default flag.\nFound: ${result.line.trim()}`
);
test('audit-milestone.md: Nyquist activation uses verify:post capability hook', () => {
assertNyquistCapabilityGate('audit-milestone.md');
});
test('legacy Nyquist config helper still detects unsafe direct reads', () => {
const tmp = path.join(os.tmpdir(), `policy-138-synthetic-${process.pid}.md`);
try {
fs.writeFileSync(tmp, 'NYQUIST_CFG=$(gsd_run query config-get workflow.nyquist_validation --raw)\n');
const result = findNyquistConfigLine(tmp);
assert.ok(result, 'synthetic direct config read should be detected');
assert.ok(!result.line.includes('--default'), 'synthetic unsafe read intentionally lacks --default');
} finally {
try {
fs.unlinkSync(tmp);
} catch {
// Best-effort cleanup for synthetic file.
}
}
});

View File

@@ -178,11 +178,19 @@ describe('SECURE: secure-phase workflow file', () => {
);
});
test('contains security_enforcement config check', () => {
test('contains security capability hook check', () => {
const content = fs.readFileSync(wfPath, 'utf-8');
assert.ok(
content.includes('security_enforcement'),
'must check security_enforcement config setting'
content.includes('loop render-hooks verify:post'),
'must resolve security activation through verify:post capability hooks'
);
assert.ok(
content.includes('ref.skill == "secure-phase"'),
'must identify the secure-phase capability hook'
);
assert.ok(
!content.includes('config-get workflow.security_enforcement'),
'must not read workflow.security_enforcement directly after capability cutover'
);
});

View File

@@ -48,27 +48,28 @@ describe('verify-work.md — auto-transition after UAT passes with 0 issues', ()
test('security gate check gates the transition (no auto-transition when security pending)', () => {
const content = fs.readFileSync(VERIFY_WORK, 'utf-8');
// The security check must appear before the transition reference
const securityCfgIdx = content.indexOf('SECURITY_CFG');
// The capability-resolved security check must appear before the transition reference.
const securityHookIdx = content.indexOf('loop render-hooks verify:post');
const transitionIdx = content.indexOf('transition.md');
assert.ok(
securityCfgIdx !== -1,
'verify-work.md must check SECURITY_CFG before transitioning'
securityHookIdx !== -1,
'verify-work.md must resolve verify:post capability hooks before transitioning'
);
assert.ok(
securityCfgIdx < transitionIdx,
'SECURITY_CFG check must appear before transition.md reference'
securityHookIdx < transitionIdx,
'verify:post capability hook check must appear before transition.md reference'
);
});
test('transition is only invoked when security gate is cleared or disabled', () => {
const content = fs.readFileSync(VERIFY_WORK, 'utf-8');
// Transition must be guarded by security check:
// Either SECURITY_CFG is false, or security file exists with 0 open threats
// Either no active secure-phase hook exists, or security file exists with 0 open threats.
const hasGuardedTransition =
content.includes('transition.md') &&
(
content.includes("SECURITY_CFG") &&
content.includes('loop render-hooks verify:post') &&
content.includes('ref.skill == "secure-phase"') &&
(content.includes('threats_open') || content.includes('SECURITY_FILE'))
);
assert.ok(

View File

@@ -6,13 +6,13 @@
"ai-integration-phase.md": 14761,
"analyze-dependencies.md": 3887,
"audit-fix.md": 10988,
"audit-milestone.md": 17556,
"audit-milestone.md": 17637,
"audit-uat.md": 7425,
"autonomous.md": 41838,
"autonomous.md": 42263,
"check-todos.md": 9431,
"cleanup.md": 9897,
"code-review-fix.md": 23676,
"code-review.md": 31397,
"code-review-fix.md": 23890,
"code-review.md": 31602,
"complete-milestone.md": 30228,
"debug.md": 13505,
"diagnose-issues.md": 12425,
@@ -24,7 +24,7 @@
"docs-update.md": 54770,
"edit-phase.md": 12883,
"eval-review.md": 9923,
"execute-phase.md": 92885,
"execute-phase.md": 93166,
"execute-plan.md": 29980,
"explore.md": 10497,
"extract-learnings.md": 12849,
@@ -51,20 +51,20 @@
"note.md": 6563,
"pause-work.md": 13654,
"plan-milestone-gaps.md": 11765,
"plan-phase.md": 94326,
"plan-phase.md": 94519,
"plan-review-convergence.md": 22949,
"plant-seed.md": 11741,
"pr-branch.md": 4994,
"profile-user.md": 20650,
"progress.md": 29387,
"quick.md": 46282,
"quick.md": 46412,
"reapply-patches.md": 20393,
"remove-phase.md": 8469,
"remove-workspace.md": 7507,
"resume-project.md": 15288,
"review.md": 38031,
"scan.md": 7688,
"secure-phase.md": 12187,
"secure-phase.md": 12282,
"session-report.md": 4044,
"settings-advanced.md": 39621,
"settings-integrations.md": 15801,
@@ -84,7 +84,7 @@
"ultraplan-phase.md": 10468,
"undo.md": 10431,
"update.md": 21053,
"validate-phase.md": 10630,
"validate-phase.md": 10745,
"verify-phase.md": 28430,
"verify-work.md": 30614
"verify-work.md": 31160
}