feat(#1136): consume resolved capability state (#1153)

* feat(#1136): consume resolved capability state

* chore(#1136): add capability state changeset
This commit is contained in:
Tom Boucher
2026-06-12 23:43:07 -04:00
committed by GitHub
parent b431b1fab4
commit 607813f5d0
22 changed files with 513 additions and 141 deletions

View File

@@ -4,7 +4,7 @@
* Regression tests for config key bugs:
* #2530 — workflow._auto_chain_active is internal state, must not be in VALID_CONFIG_KEYS
* #2531 — hooks.workflow_guard is used by hook and documented but missing from VALID_CONFIG_KEYS
* #2532 — workflow.ui_review is used in autonomous.md but missing from VALID_CONFIG_KEYS
* #2532 — workflow.ui_review is used in autonomous.md but missing from config validation
* #2533 — workflow.max_discuss_passes is used in discuss-phase.md but missing from VALID_CONFIG_KEYS
* #2535 — sub_repos and plan_checker legacy keys need CONFIG_KEY_SUGGESTIONS migration hints
* #3162 — resolve_model_ids missing from VALID_CONFIG_KEYS; workflow._auto_chain_active must be
@@ -15,7 +15,13 @@ const { describe, test } = require('node:test');
const assert = require('node:assert/strict');
const { createTempProject, cleanup, runGsdTools } = require('./helpers.cjs');
const { VALID_CONFIG_KEYS, isValidConfigKey } = require('../gsd-core/bin/lib/config-schema.cjs');
const {
VALID_CONFIG_KEYS,
isCentralConfigKey,
isValidConfigKey,
} = require('../gsd-core/bin/lib/config-schema.cjs');
const capabilityRegistry = require('../gsd-core/bin/lib/capability-registry.cjs');
describe('VALID_CONFIG_KEYS correctness', () => {
test('#2530: workflow._auto_chain_active must not be in VALID_CONFIG_KEYS (internal state)', () => {
@@ -32,10 +38,16 @@ describe('VALID_CONFIG_KEYS correctness', () => {
);
});
test('#2532: workflow.ui_review must be in VALID_CONFIG_KEYS (used in autonomous.md)', () => {
assert.ok(
VALID_CONFIG_KEYS.has('workflow.ui_review'),
'workflow.ui_review is read in autonomous.md via gsd-sdk query config-get'
test('#2532: workflow.ui_review must remain valid but is no longer centrally owned', () => {
assert.strictEqual(
isValidConfigKey('workflow.ui_review'),
true,
'workflow.ui_review is still user-facing config and must validate'
);
assert.strictEqual(
isCentralConfigKey('workflow.ui_review'),
false,
'workflow.ui_review is owned by the UI capability after ADR-857 Phase 6 cutover'
);
});
@@ -62,6 +74,19 @@ describe('VALID_CONFIG_KEYS correctness', () => {
});
});
describe('ADR-857 Phase 6 capability config ownership', () => {
test('migrated capability config keys are valid through the registry, not central schema residue', () => {
const capabilityKeys = Object.keys(capabilityRegistry.configSchema || {}).sort();
assert.ok(capabilityKeys.length > 0, 'expected generated registry config schema keys');
for (const key of capabilityKeys) {
assert.strictEqual(isValidConfigKey(key), true, `${key} must remain accepted by config validation`);
assert.strictEqual(isCentralConfigKey(key), false, `${key} must be capability-owned, not central`);
assert.strictEqual(VALID_CONFIG_KEYS.has(key), false, `${key} must not remain in central VALID_CONFIG_KEYS`);
}
});
});
describe('CONFIG_KEY_SUGGESTIONS migration hints (#2535)', () => {
let tmpDir;

View File

@@ -288,6 +288,7 @@ describe('resolveCapabilityState — UI capability with real registry', () => {
assert.ok(uiCap, 'ui capability should be present');
assert.strictEqual(uiCap.installed, true);
assert.strictEqual(uiCap.surfaced, true);
assert.strictEqual(uiCap.enabled, true);
});
test('UI cap: installed=false when ui-review missing from installedSkills', () => {
@@ -301,6 +302,7 @@ describe('resolveCapabilityState — UI capability with real registry', () => {
const uiCap = result.capabilities.find((c) => c.id === 'ui');
assert.ok(uiCap);
assert.strictEqual(uiCap.installed, false);
assert.strictEqual(uiCap.enabled, false);
});
test('UI cap: surfaced=false when ui-review missing from surfacedSkills', () => {
@@ -314,13 +316,14 @@ describe('resolveCapabilityState — UI capability with real registry', () => {
const uiCap = result.capabilities.find((c) => c.id === 'ui');
assert.ok(uiCap);
assert.strictEqual(uiCap.surfaced, false);
assert.strictEqual(uiCap.enabled, false);
});
test('UI cap step hook: workflow.ui_phase true → active=true', () => {
const result = resolveCapabilityState({
registry: realRegistry,
installedSkills: '*',
surfacedSkills: new Set(),
surfacedSkills: new Set(['ui-phase', 'ui-review']),
config: { workflow: { ui_phase: true, ui_review: true, ui_safety_gate: true } },
cwd: tmpProjectDir,
});
@@ -331,9 +334,29 @@ describe('resolveCapabilityState — UI capability with real registry', () => {
(h) => h.kind === 'step' && h.when === 'workflow.ui_phase',
);
assert.ok(planPreStep, 'should have plan:pre step with when=workflow.ui_phase');
assert.strictEqual(planPreStep.configured, true);
assert.strictEqual(planPreStep.active, true);
});
test('UI cap step hook: surfaced=false and workflow.ui_phase true → configured=true but active=false', () => {
const result = resolveCapabilityState({
registry: realRegistry,
installedSkills: '*',
surfacedSkills: new Set(),
config: { workflow: { ui_phase: true, ui_review: true, ui_safety_gate: true } },
cwd: tmpProjectDir,
});
const uiCap = result.capabilities.find((c) => c.id === 'ui');
assert.ok(uiCap);
assert.strictEqual(uiCap.enabled, false);
const planPreStep = uiCap.hooks.find(
(h) => h.kind === 'step' && h.when === 'workflow.ui_phase',
);
assert.ok(planPreStep, 'should have plan:pre step with when=workflow.ui_phase');
assert.strictEqual(planPreStep.configured, true);
assert.strictEqual(planPreStep.active, false);
});
test('UI cap step hook: workflow.ui_phase false → active=false', () => {
const result = resolveCapabilityState({
registry: realRegistry,
@@ -348,6 +371,7 @@ describe('resolveCapabilityState — UI capability with real registry', () => {
(h) => h.kind === 'step' && h.when === 'workflow.ui_phase',
);
assert.ok(planPreStep, 'should have plan:pre step with when=workflow.ui_phase');
assert.strictEqual(planPreStep.configured, false);
assert.strictEqual(planPreStep.active, false);
});
@@ -355,7 +379,7 @@ describe('resolveCapabilityState — UI capability with real registry', () => {
const result = resolveCapabilityState({
registry: realRegistry,
installedSkills: '*',
surfacedSkills: new Set(),
surfacedSkills: new Set(['ui-phase', 'ui-review']),
config: { workflow: { ui_phase: true, ui_review: true, ui_safety_gate: true } },
cwd: tmpProjectDir,
});
@@ -365,6 +389,7 @@ describe('resolveCapabilityState — UI capability with real registry', () => {
(h) => h.kind === 'gate' && h.when === 'workflow.ui_safety_gate',
);
assert.ok(safetyGate, 'should have gate with when=workflow.ui_safety_gate');
assert.strictEqual(safetyGate.configured, true);
assert.strictEqual(safetyGate.active, true);
});
@@ -382,6 +407,7 @@ describe('resolveCapabilityState — UI capability with real registry', () => {
(h) => h.kind === 'gate' && h.when === 'workflow.ui_safety_gate',
);
assert.ok(safetyGate, 'should have gate with when=workflow.ui_safety_gate');
assert.strictEqual(safetyGate.configured, false);
assert.strictEqual(safetyGate.active, false);
});
});
@@ -643,6 +669,7 @@ function runCapabilityState(cwd, configDir) {
describe('cmdCapabilityState — end-to-end via gsd-tools CLI', () => {
let tmpConfigDir;
let tmpConfigDirCore;
let tmpConfigDirUiDisabled;
before(() => {
// Tmp runtime config dir without .gsd-profile (defaults to 'full')
@@ -651,11 +678,24 @@ describe('cmdCapabilityState — end-to-end via gsd-tools CLI', () => {
// Tmp runtime config dir with core profile marker
tmpConfigDirCore = fs.mkdtempSync(path.join(os.tmpdir(), 'cap-state-cfg-core-'));
fs.writeFileSync(path.join(tmpConfigDirCore, '.gsd-profile'), 'core\n', 'utf8');
tmpConfigDirUiDisabled = fs.mkdtempSync(path.join(os.tmpdir(), 'cap-state-cfg-ui-disabled-'));
fs.writeFileSync(
path.join(tmpConfigDirUiDisabled, '.gsd-surface.json'),
JSON.stringify({
baseProfile: 'full',
disabledClusters: ['ui'],
explicitAdds: [],
explicitRemoves: [],
}, null, 2),
'utf8',
);
});
after(() => {
cleanup(tmpConfigDir);
cleanup(tmpConfigDirCore);
cleanup(tmpConfigDirUiDisabled);
});
test('emits envelope with runtimeConfigDir and capabilities array', () => {
@@ -685,4 +725,21 @@ describe('cmdCapabilityState — end-to-end via gsd-tools CLI', () => {
const envelope = JSON.parse(result.stdout);
assert.strictEqual(envelope.runtimeConfigDir, tmpConfigDir);
});
test('surface-disabled UI capability reports enabled=false and inactive hooks', () => {
const result = runCapabilityState(tmpProjectDir, tmpConfigDirUiDisabled);
assert.strictEqual(result.status, 0, `gsd-tools exited ${result.status}: ${result.stderr}`);
const envelope = JSON.parse(result.stdout);
const uiCap = envelope.capabilities.find((c) => c.id === 'ui');
assert.ok(uiCap, 'ui capability should be present in output');
assert.strictEqual(uiCap.installed, true, 'full base profile still installs UI');
assert.strictEqual(uiCap.surfaced, false, 'surface disables UI capability skills');
assert.strictEqual(uiCap.enabled, false, 'disabled surface must disable the capability');
const planPreStep = uiCap.hooks.find(
(h) => h.kind === 'step' && h.when === 'workflow.ui_phase',
);
assert.ok(planPreStep, 'ui plan step should be present in diagnostic state');
assert.strictEqual(planPreStep.configured, true, 'project config/schema still configures UI on');
assert.strictEqual(planPreStep.active, false, 'effective hook activity must match workflow dispatch');
});
});

View File

@@ -5,8 +5,8 @@
* six visual sections. Adds 8 new fields (pattern_mapper, tdd_mode, code_review,
* code_review_depth, ui_review, commit_docs, intel.enabled, graphify.enabled)
* and verifies each is present in the AskUserQuestion block, the update_config
* step, the confirmation table, the ~/.gsd/defaults.json save step, and
* VALID_CONFIG_KEYS.
* step, the confirmation table, the ~/.gsd/defaults.json save step, and the
* effective config-key validator.
*
* Closes: #2527
*/
@@ -18,7 +18,11 @@ const path = require('path');
const { runGsdTools, createTempProject, cleanup } = require('./helpers.cjs');
const SETTINGS_PATH = path.join(__dirname, '..', 'gsd-core', 'workflows', 'settings.md');
const { VALID_CONFIG_KEYS } = require('../gsd-core/bin/lib/config-schema.cjs');
const {
VALID_CONFIG_KEYS,
isCentralConfigKey,
isValidConfigKey,
} = require('../gsd-core/bin/lib/config-schema.cjs');
const NEW_FIELDS = [
'workflow.pattern_mapper',
@@ -31,6 +35,13 @@ const NEW_FIELDS = [
'graphify.enabled',
];
const CENTRAL_NEW_FIELDS = [
'workflow.tdd_mode',
'commit_docs',
];
const CAPABILITY_OWNED_NEW_FIELDS = NEW_FIELDS.filter((field) => !CENTRAL_NEW_FIELDS.includes(field));
const SECTION_HEADERS = ['Planning', 'Execution', 'Docs & Output', 'Features', 'Model & Pipeline', 'Misc'];
/**
@@ -134,12 +145,40 @@ describe('#2527: settings.md adds grouped settings layers', () => {
});
});
describe('Acceptance: all 8 new fields registered in VALID_CONFIG_KEYS', () => {
describe('Acceptance: all 8 new fields accepted by the config validator', () => {
for (const field of NEW_FIELDS) {
test(`VALID_CONFIG_KEYS contains ${field}`, () => {
test(`config validator accepts ${field}`, () => {
assert.ok(
isValidConfigKey(field),
`${field} must be accepted so config-set can write it`
);
});
}
});
describe('Acceptance: migrated capability fields are no longer central config keys', () => {
for (const field of CAPABILITY_OWNED_NEW_FIELDS) {
test(`${field} is capability-owned, not central-schema residue`, () => {
assert.equal(
isCentralConfigKey(field),
false,
`${field} must be owned by the capability registry instead of the central schema`
);
assert.equal(
VALID_CONFIG_KEYS.has(field),
false,
`${field} must not be duplicated in VALID_CONFIG_KEYS after Phase 6 migration`
);
});
}
});
describe('Acceptance: still-central settings remain in VALID_CONFIG_KEYS', () => {
for (const field of CENTRAL_NEW_FIELDS) {
test(`VALID_CONFIG_KEYS contains central setting ${field}`, () => {
assert.ok(
VALID_CONFIG_KEYS.has(field),
`${field} must be in VALID_CONFIG_KEYS so config-set accepts it`
`${field} is not a migrated capability key and must remain in VALID_CONFIG_KEYS`
);
});
}

View File

@@ -69,10 +69,10 @@ function mkTemp() {
return d;
}
// ─── 1. Equivalence / no-op with real registry ───────────────────────────────
// ─── 1. Real registry overlay after Phase 6 cutover ──────────────────────────
describe('EQUIVALENCE: real registry is a no-op overlay', () => {
test('loadConfig with an empty config.json returns base config without extra federated keys', () => {
describe('REAL REGISTRY: capability config keys are surfaced by federated overlay', () => {
test('loadConfig with an empty config.json returns capability-owned defaults', () => {
const tmpDir = mkTemp();
// Write an empty config to trigger the try-branch (federated overlay path)
writeConfig(tmpDir, {});
@@ -99,30 +99,14 @@ describe('EQUIVALENCE: real registry is a no-op overlay', () => {
);
}
// UI-capability keys must NOT appear as new top-level keys (they're still central
// and the overlay is empty — so these keys should not be added)
// Note: 'workflow' IS an existing top-level key concept via VALID_CONFIG_KEYS,
// but the nested keys like 'ui_phase' must not be present.
const workflowSection = result['workflow'];
if (workflowSection && typeof workflowSection === 'object') {
// workflow section may already exist from user config but should not have ui_phase
// in the default no-config case
assert.ok(
!Object.prototype.hasOwnProperty.call(workflowSection, 'ui_phase'),
'workflow.ui_phase should not be injected by the federated overlay (key is still central)',
);
assert.ok(
!Object.prototype.hasOwnProperty.call(workflowSection, 'ui_review'),
'workflow.ui_review should not be injected by the federated overlay (key is still central)',
);
assert.ok(
!Object.prototype.hasOwnProperty.call(workflowSection, 'ui_safety_gate'),
'workflow.ui_safety_gate should not be injected by the federated overlay (key is still central)',
);
}
assert.ok(typeof workflowSection === 'object' && workflowSection !== null, 'workflow section must be created by federated overlay');
assert.strictEqual(workflowSection.ui_phase, true, 'workflow.ui_phase comes from the UI capability default');
assert.strictEqual(workflowSection.ui_review, true, 'workflow.ui_review comes from the UI capability default');
assert.strictEqual(workflowSection.ui_safety_gate, true, 'workflow.ui_safety_gate comes from the UI capability default');
});
test('loadConfig with a real config.json returns expected values + no unexpected keys from overlay', () => {
test('loadConfig with a real config.json returns expected values plus capability defaults', () => {
const tmpDir = mkTemp();
writeConfig(tmpDir, { model_profile: 'balanced', research: true });
const result = loadConfig(tmpDir);
@@ -130,10 +114,8 @@ describe('EQUIVALENCE: real registry is a no-op overlay', () => {
assert.strictEqual(result['model_profile'], 'balanced', 'model_profile from config');
assert.strictEqual(result['research'], true, 'research from config');
// The overlay must not have added any unexpected keys from the registry
// (all UI keys are central → skipped → no additions)
// Verify a spot-check: 'ui_phase' should not exist anywhere
assert.strictEqual(result['ui_phase'], undefined, 'ui_phase should not appear as top-level key');
assert.strictEqual(result.workflow.ui_phase, true, 'workflow.ui_phase must be nested under workflow');
});
});
@@ -309,8 +291,7 @@ describe('FIX 2: overlay applied on the no-config path', () => {
);
});
test('no-config path with REAL registry (all keys central) → output is byte-identical to defaults (no-op)', () => {
// No config.json — use real registry which has all keys central
test('no-config path with REAL registry → capability defaults are surfaced', () => {
_resetFederatedRegistryForTests();
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-fed-noconfig-real-'));
tmpDirs.push(tmpDir);
@@ -320,16 +301,9 @@ describe('FIX 2: overlay applied on the no-config path', () => {
const result = loadConfig(tmpDir);
assert.ok(typeof result === 'object' && result !== null, 'result must be an object');
// With real registry (all keys central → overlay is empty → no-op), the result
// should be the defaults object WITHOUT any extra injected keys.
// Spot-check: ui_phase / ui_review / ui_safety_gate must NOT be injected
const workflowSection = result['workflow'];
if (workflowSection && typeof workflowSection === 'object') {
assert.ok(
!Object.prototype.hasOwnProperty.call(workflowSection, 'ui_phase'),
'workflow.ui_phase must not be injected on no-config path (no-op)',
);
}
assert.ok(typeof workflowSection === 'object' && workflowSection !== null, 'workflow section must be created by real registry overlay');
assert.strictEqual(workflowSection.ui_phase, true, 'workflow.ui_phase must be injected on no-config path');
// model_profile must be present (it comes from defaults)
assert.ok(Object.prototype.hasOwnProperty.call(result, 'model_profile'), 'model_profile must be present');
});

View File

@@ -641,16 +641,15 @@ describe('FIX 6c: N-level nested write and prototype-pollution via dotted keys',
});
});
// ─── 8. Real registry — all UI keys are central (no-op guarantee) ────────────
// ─── 8. Real registry — capability-owned keys are live ───────────────────────
describe('real registry: all UI keys are central → no-op channel', () => {
test('with real capability-registry, all configSchema keys are skipped (pending-migration)', () => {
describe('real registry: capability config keys are federated', () => {
test('with real capability-registry, configSchema keys are accepted through the federated channel', () => {
const capRegistry = require('../gsd-core/bin/lib/capability-registry.cjs');
const configSchemaFromRegistry = capRegistry.configSchema;
// Import the real isValidConfigKey
const configSchemaModule = require('../gsd-core/bin/lib/config-schema.cjs');
const { isValidConfigKey } = configSchemaModule;
const { isCentralConfigKey } = configSchemaModule;
if (!configSchemaFromRegistry || Object.keys(configSchemaFromRegistry).length === 0) {
// Registry has no configSchema keys — no-op by definition
@@ -659,22 +658,17 @@ describe('real registry: all UI keys are central → no-op channel', () => {
const result = mergeFederatedConfig({
configSchema: configSchemaFromRegistry,
isCentralKey: isValidConfigKey,
isCentralKey: isCentralConfigKey,
userConfig: {},
});
// Every key should be skipped (pending-migration) because UI keys are still in central schema
assert.strictEqual(Object.keys(result.values).length, 0, 'values must be empty — all keys are central (pending-migration)');
assert.deepEqual(result.validKeys, [], 'validKeys must be empty');
assert.ok(result.warnings.length > 0, 'Should have pending-migration warnings');
assert.ok(Object.keys(result.values).length > 0, 'values must include capability-owned defaults');
assert.ok(result.validKeys.includes('workflow.ui_phase'), 'workflow.ui_phase must flow through federated config');
assert.strictEqual(result.values['workflow.ui_phase'], true);
// Confirm each UI key specifically
const uiKeys = ['workflow.ui_phase', 'workflow.ui_review', 'workflow.ui_safety_gate'];
for (const key of uiKeys) {
assert.ok(
result.warnings.some((w) => w.includes(key)),
'Should have a warning for ' + key + ', got: ' + JSON.stringify(result.warnings),
);
assert.ok(result.validKeys.includes(key), 'Expected ' + key + ' in validKeys');
}
});
});

View File

@@ -54,6 +54,8 @@ let tmpProjectDir;
let tmpEmptyProjectDir;
// A project where ui_phase is explicitly false in root config
let tmpFalseConfigProjectDir;
// Runtime config dir whose surface disables the UI capability
let tmpUiDisabledConfigDir;
before(() => {
tmpProjectDir = fs.mkdtempSync(path.join(os.tmpdir(), 'loop-resolver-test-'));
@@ -79,12 +81,25 @@ before(() => {
JSON.stringify({ workflow: { ui_phase: false, ui_review: false, ui_safety_gate: false } }),
'utf8',
);
tmpUiDisabledConfigDir = fs.mkdtempSync(path.join(os.tmpdir(), 'loop-resolver-ui-disabled-'));
fs.writeFileSync(
path.join(tmpUiDisabledConfigDir, '.gsd-surface.json'),
JSON.stringify({
baseProfile: 'full',
disabledClusters: ['ui'],
explicitAdds: [],
explicitRemoves: [],
}, null, 2),
'utf8',
);
});
after(() => {
if (tmpProjectDir) cleanup(tmpProjectDir);
if (tmpEmptyProjectDir) cleanup(tmpEmptyProjectDir);
if (tmpFalseConfigProjectDir) cleanup(tmpFalseConfigProjectDir);
if (tmpUiDisabledConfigDir) cleanup(tmpUiDisabledConfigDir);
});
// ─── 1. Canonical-point validation ───────────────────────────────────────────
@@ -799,6 +814,31 @@ describe('cmdLoopRenderHooks end-to-end (via gsd-tools)', () => {
assert.match(envelope.rendered, /ui-phase/);
});
test('loop render-hooks plan:pre with ui capability disabled in surface → ui hooks absent', () => {
const result = spawnSync(
process.execPath,
[
GSD_TOOLS,
'loop',
'render-hooks',
'plan:pre',
'--cwd',
tmpEmptyProjectDir,
'--config-dir',
tmpUiDisabledConfigDir,
],
{ cwd: ROOT, encoding: 'utf8' },
);
assert.strictEqual(result.status, 0, 'Expected exit 0. stderr: ' + (result.stderr || ''));
const envelope = JSON.parse(result.stdout.trim());
const uiHooks = envelope.activeHooks.filter(h => h.capId === 'ui');
assert.deepStrictEqual(
uiHooks,
[],
'UI hooks must be absent when the UI capability is disabled at the runtime surface',
);
});
// FIX 4: explicit false in config.json overrides schema default
test('loop render-hooks plan:pre with ui_phase=false in config.json → ui-phase step absent', () => {
const result = spawnSync(