Final epic-#1969 batch. Fold 22 issue-named files: the 4 genuine repo-wide invariant scans (551-eslint-bin-lib-coverage, bug-3054 stale /gsd-next, bug-3810 no-gsd-sdk-runtime-refs, feat-3593 cli-negative-universal) into a NEW shared repo-invariants.test.cjs; the other 18 as singletons into their nearest module suite (model-resolver, codex-config, runtime-converters, security, state-transition, worktree-safety, roadmap-parser, etc.). Verbatim block-scoped describe wrappers; 334 subtests conserved 1:1. Host-env pre-check (B2+B6): the 6 CLI folds into GSD_TEST_MODE-setting hosts (model-resolver/ codex-config/runtime-converters) are benign — each origin independently sets GSD_TEST_MODE=1 itself (idempotent), unlike the B6 real-install case. Regenerates regression-name allowlist (222->213), ratchets file-count allowlist (state 17->16), makes 7 relocated allow-test-rule exemptions issue-ref-compliant (ADR-456; prunes stale ids). Repoints 2 tests/ refs in docs/TESTING-SUITES.md. lint:ci green. Part of epic #1969. Closes #1977. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
820 lines
34 KiB
JavaScript
820 lines
34 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.
|
|
'use strict';
|
|
|
|
|
|
/**
|
|
* Tests for `/gsd-settings-advanced` — power-user configuration command (#2528).
|
|
*
|
|
* Covers:
|
|
* - Command file exists with correct frontmatter
|
|
* - Workflow file exists with required section structure
|
|
* - Every field in the issue spec is rendered in the workflow with its default
|
|
* - Current values are pre-selected in prompts
|
|
* - Config merge preserves unrelated keys (sibling preservation)
|
|
* - Confirmation table is rendered after save
|
|
* - Every field is accepted by VALID_CONFIG_KEYS
|
|
* - /gsd-settings confirmation output advertises /gsd-settings-advanced
|
|
* - Negative: non-numeric value rejected for numeric field via config-set
|
|
*/
|
|
|
|
const { describe, test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const { createTempProject, cleanup, runGsdTools } = require('./helpers.cjs');
|
|
const { VALID_CONFIG_KEYS } = require('../gsd-core/bin/lib/config-schema.cjs');
|
|
|
|
const ROOT = path.resolve(__dirname, '..');
|
|
// #2790: settings-advanced.md was consolidated into config.md as the --advanced flag.
|
|
const COMMAND_PATH = path.join(ROOT, 'commands', 'gsd', 'config.md');
|
|
const WORKFLOW_PATH = path.join(ROOT, 'gsd-core', 'workflows', 'settings-advanced.md');
|
|
const SETTINGS_WORKFLOW_PATH = path.join(ROOT, 'gsd-core', 'workflows', 'settings.md');
|
|
|
|
// ─── Spec — every field the advanced command must expose ──────────────────────
|
|
|
|
const SPEC_FIELDS = {
|
|
planning: [
|
|
{ key: 'workflow.plan_bounce', default: 'false' },
|
|
{ key: 'workflow.plan_bounce_passes', default: '2' },
|
|
{ key: 'workflow.plan_bounce_script', default: 'null' },
|
|
{ key: 'workflow.subagent_timeout', default: '300000' },
|
|
{ key: 'workflow.inline_plan_threshold', default: '3' },
|
|
],
|
|
execution: [
|
|
{ key: 'workflow.node_repair', default: 'true' },
|
|
{ key: 'workflow.node_repair_budget', default: '2' },
|
|
{ key: 'workflow.auto_prune_state', default: 'false' },
|
|
],
|
|
discussion: [
|
|
{ key: 'workflow.max_discuss_passes', default: '3' },
|
|
],
|
|
cross_ai: [
|
|
{ key: 'workflow.cross_ai_execution', default: 'false' },
|
|
{ key: 'workflow.cross_ai_command', default: 'null' },
|
|
{ key: 'workflow.cross_ai_timeout', default: '300' },
|
|
],
|
|
git: [
|
|
{ key: 'git.base_branch', default: 'main' },
|
|
{ key: 'git.phase_branch_template', default: 'gsd/phase-{phase}-{slug}' },
|
|
{ key: 'git.milestone_branch_template', default: 'gsd/{milestone}-{slug}' },
|
|
],
|
|
runtime: [
|
|
{ key: 'response_language', default: 'null' },
|
|
{ key: 'context_window', default: '200000' },
|
|
{ key: 'search_gitignored', default: 'false' },
|
|
{ key: 'graphify.build_timeout', default: '300' },
|
|
],
|
|
};
|
|
|
|
const ALL_SPEC_KEYS = Object.values(SPEC_FIELDS).flat().map((f) => f.key);
|
|
|
|
// ─── File existence + frontmatter ─────────────────────────────────────────────
|
|
|
|
describe('gsd-settings-advanced — file scaffolding', () => {
|
|
test('consolidated config.md command exists (#2790: settings-advanced absorbed)', () => {
|
|
assert.ok(fs.existsSync(COMMAND_PATH), `missing ${COMMAND_PATH}`);
|
|
});
|
|
|
|
test('workflow file exists at gsd-core/workflows/settings-advanced.md', () => {
|
|
assert.ok(fs.existsSync(WORKFLOW_PATH), `missing ${WORKFLOW_PATH}`);
|
|
});
|
|
|
|
test('command frontmatter has name, description, allowed-tools', () => {
|
|
const text = fs.readFileSync(COMMAND_PATH, 'utf-8');
|
|
const fmMatch = text.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
assert.ok(fmMatch, 'command file missing frontmatter block');
|
|
const fm = fmMatch[1];
|
|
assert.match(fm, /name:\s*gsd:config/, 'frontmatter missing name (gsd:config)');
|
|
assert.match(fm, /description:\s*\S/, 'frontmatter missing non-empty description');
|
|
assert.match(fm, /allowed-tools:/, 'frontmatter missing allowed-tools');
|
|
});
|
|
|
|
test('command routes to the settings-advanced workflow via --advanced flag', () => {
|
|
const text = fs.readFileSync(COMMAND_PATH, 'utf-8');
|
|
assert.ok(
|
|
text.includes('workflows/settings-advanced.md') || text.includes('--advanced'),
|
|
'config.md must reference settings-advanced workflow or --advanced flag'
|
|
);
|
|
});
|
|
});
|
|
|
|
// ─── Workflow content — sections and fields ───────────────────────────────────
|
|
|
|
describe('gsd-settings-advanced — workflow structure', () => {
|
|
let workflow;
|
|
try {
|
|
workflow = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
} catch { workflow = ''; }
|
|
|
|
const requiredSteps = [
|
|
'ensure_and_load_config',
|
|
'read_current',
|
|
'present_settings',
|
|
'update_config',
|
|
'confirm',
|
|
];
|
|
for (const step of requiredSteps) {
|
|
test(`workflow defines <step name="${step}">`, () => {
|
|
assert.ok(
|
|
workflow.includes(`<step name="${step}">`),
|
|
`workflow missing step ${step}`
|
|
);
|
|
});
|
|
}
|
|
|
|
const requiredSections = [
|
|
'Planning Tuning',
|
|
'Execution Tuning',
|
|
'Discussion Tuning',
|
|
'Cross-AI Execution',
|
|
'Git Customization',
|
|
'Runtime / Output',
|
|
];
|
|
for (const section of requiredSections) {
|
|
test(`workflow renders section "${section}"`, () => {
|
|
assert.ok(
|
|
workflow.includes(section),
|
|
`workflow missing section heading "${section}"`
|
|
);
|
|
});
|
|
}
|
|
|
|
for (const field of Object.values(SPEC_FIELDS).flat()) {
|
|
test(`workflow mentions key \`${field.key}\``, () => {
|
|
assert.ok(
|
|
workflow.includes(field.key),
|
|
`workflow missing field ${field.key}`
|
|
);
|
|
});
|
|
test(`workflow documents default for \`${field.key}\` (${field.default})`, () => {
|
|
// Search for the default token in proximity to the key. Keep this
|
|
// forgiving: same line, or within ~200 chars after the key.
|
|
const idx = workflow.indexOf(field.key);
|
|
assert.ok(idx >= 0, `key ${field.key} not found`);
|
|
const window = workflow.slice(idx, idx + 400);
|
|
assert.ok(
|
|
window.includes(field.default),
|
|
`default "${field.default}" not found near key ${field.key}. Window:\n${window}`
|
|
);
|
|
});
|
|
}
|
|
|
|
test('workflow pre-selects current values from loaded config', () => {
|
|
assert.match(
|
|
workflow,
|
|
/pre-selected|current value|Current:/i,
|
|
'workflow must document that current values are pre-selected'
|
|
);
|
|
});
|
|
|
|
test('confirmation step renders a table with saved settings', () => {
|
|
const confirmStart = workflow.indexOf('<step name="confirm">');
|
|
assert.ok(confirmStart >= 0, 'confirm step missing');
|
|
const confirmBlock = workflow.slice(confirmStart);
|
|
assert.ok(
|
|
confirmBlock.includes('|') && /\|[^\n]*Setting[^\n]*\|/.test(confirmBlock),
|
|
'confirm step must render a markdown table with a Setting column'
|
|
);
|
|
});
|
|
|
|
test('update_config step describes merge-preserving-siblings behavior', () => {
|
|
assert.match(
|
|
workflow,
|
|
/(preserv(e|ing) (unrelated|sibling)|do not clobber|merge .*existing|...existing_config)/i,
|
|
'update_config step must describe preserving unrelated keys'
|
|
);
|
|
});
|
|
});
|
|
|
|
// ─── VALID_CONFIG_KEYS membership ─────────────────────────────────────────────
|
|
|
|
describe('gsd-settings-advanced — VALID_CONFIG_KEYS coverage', () => {
|
|
for (const key of ALL_SPEC_KEYS) {
|
|
test(`VALID_CONFIG_KEYS contains "${key}"`, () => {
|
|
assert.ok(
|
|
VALID_CONFIG_KEYS.has(key),
|
|
`VALID_CONFIG_KEYS missing ${key} — add it to gsd-core/bin/lib/config-schema.cjs`
|
|
);
|
|
});
|
|
}
|
|
});
|
|
|
|
// ─── /gsd-settings mentions /gsd-settings-advanced ────────────────────────────
|
|
|
|
describe('/gsd-settings advertises /gsd-settings-advanced', () => {
|
|
test('settings workflow mentions canonical /gsd-config --advanced', () => {
|
|
const text = fs.readFileSync(SETTINGS_WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(
|
|
text.includes('/gsd:config --advanced'),
|
|
'gsd-core/workflows/settings.md must mention /gsd:config --advanced'
|
|
);
|
|
assert.ok(
|
|
!text.includes('gsd-settings-advanced') && !text.includes('gsd:settings-advanced'),
|
|
'gsd-core/workflows/settings.md must not mention legacy /gsd-settings-advanced variants'
|
|
);
|
|
});
|
|
});
|
|
|
|
// ─── Sibling-preservation via config-set ──────────────────────────────────────
|
|
|
|
describe('gsd-settings-advanced — config merge preserves unrelated keys', () => {
|
|
test('setting workflow.plan_bounce_passes does not clobber model_profile or git.branching_strategy', (t) => {
|
|
const tmpDir = createTempProject();
|
|
t.after(() => cleanup(tmpDir));
|
|
|
|
// Seed config
|
|
const configPath = path.join(tmpDir, '.planning', 'config.json');
|
|
const initial = {
|
|
model_profile: 'quality',
|
|
git: {
|
|
branching_strategy: 'phase',
|
|
phase_branch_template: 'feature/{phase}-{slug}',
|
|
},
|
|
workflow: {
|
|
research: true,
|
|
plan_check: false,
|
|
},
|
|
hooks: {
|
|
context_warnings: true,
|
|
},
|
|
};
|
|
fs.writeFileSync(configPath, JSON.stringify(initial, null, 2), 'utf-8');
|
|
|
|
const result = runGsdTools(
|
|
['config-set', 'workflow.plan_bounce_passes', '5'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(result.success, `config-set failed: ${result.error || result.output}`);
|
|
|
|
const updated = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
assert.strictEqual(updated.model_profile, 'quality', 'model_profile clobbered');
|
|
assert.strictEqual(updated.git.branching_strategy, 'phase', 'git.branching_strategy clobbered');
|
|
assert.strictEqual(updated.git.phase_branch_template, 'feature/{phase}-{slug}', 'git.phase_branch_template clobbered');
|
|
assert.strictEqual(updated.workflow.research, true, 'workflow.research clobbered');
|
|
assert.strictEqual(updated.workflow.plan_check, false, 'workflow.plan_check clobbered');
|
|
assert.strictEqual(updated.hooks.context_warnings, true, 'hooks.context_warnings clobbered');
|
|
assert.strictEqual(updated.workflow.plan_bounce_passes, 5, 'new value not written');
|
|
});
|
|
|
|
test('setting context_window preserves existing top-level keys', (t) => {
|
|
const tmpDir = createTempProject();
|
|
t.after(() => cleanup(tmpDir));
|
|
|
|
const configPath = path.join(tmpDir, '.planning', 'config.json');
|
|
fs.writeFileSync(configPath, JSON.stringify({
|
|
model_profile: 'balanced',
|
|
response_language: 'Japanese',
|
|
search_gitignored: true,
|
|
}, null, 2));
|
|
|
|
const result = runGsdTools(
|
|
['config-set', 'context_window', '1000000'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(result.success, `config-set context_window failed: ${result.error || result.output}`);
|
|
|
|
const updated = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
assert.strictEqual(updated.context_window, 1000000);
|
|
assert.strictEqual(updated.model_profile, 'balanced');
|
|
assert.strictEqual(updated.response_language, 'Japanese');
|
|
assert.strictEqual(updated.search_gitignored, true);
|
|
});
|
|
});
|
|
|
|
// ─── Negative: non-numeric for numeric field / unknown key rejected ───────────
|
|
|
|
describe('gsd-settings-advanced — negative scenarios', () => {
|
|
test('config-set rejects an unknown key with a helpful error', (t) => {
|
|
const tmpDir = createTempProject();
|
|
t.after(() => cleanup(tmpDir));
|
|
|
|
const result = runGsdTools(
|
|
['config-set', 'workflow.no_such_knob_at_all', 'true'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(!result.success, 'config-set should reject unknown keys');
|
|
const combined = (result.error || '') + (result.output || '');
|
|
assert.match(combined, /Unknown config key/i);
|
|
});
|
|
|
|
test('workflow.subagent_timeout numeric input is coerced and stored as Number', (t) => {
|
|
// The config-set parser coerces numeric-looking strings to Number.
|
|
// This test locks in the coercion so users can't accidentally save
|
|
// a string for a numeric knob. A non-numeric string would be stored
|
|
// verbatim — we assert the parser prefers Number for numeric literals.
|
|
const tmpDir = createTempProject();
|
|
t.after(() => cleanup(tmpDir));
|
|
|
|
const configPath = path.join(tmpDir, '.planning', 'config.json');
|
|
fs.writeFileSync(configPath, '{}');
|
|
|
|
const okNum = runGsdTools(
|
|
['config-set', 'workflow.subagent_timeout', '900'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(okNum.success);
|
|
const c1 = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
assert.strictEqual(typeof c1.workflow.subagent_timeout, 'number');
|
|
assert.strictEqual(c1.workflow.subagent_timeout, 900);
|
|
});
|
|
|
|
test('workflow documents numeric-input rejection for non-numeric answers', () => {
|
|
const workflow = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.match(
|
|
workflow,
|
|
/(non-numeric|must be a number|integer|numeric input|re-?prompt)/i,
|
|
'workflow must document how non-numeric input is handled for numeric fields'
|
|
);
|
|
});
|
|
|
|
// Behavioral coverage for numeric-key inputs at the config-set boundary.
|
|
// The /gsd-settings-advanced workflow promises non-numeric input is never
|
|
// silently coerced — that promise is enforced by the AskUserQuestion
|
|
// re-prompt loop in the workflow runner, not by config-set itself. The
|
|
// CLI parser passes numeric-looking strings through Number() and stores
|
|
// anything else verbatim. These tests lock in both behaviors so a future
|
|
// regression that changes either layer surfaces immediately.
|
|
test('config-set on a numeric key stores non-numeric input verbatim as string (workflow layer must reject before reaching here)', (t) => {
|
|
const tmpDir = createTempProject();
|
|
t.after(() => cleanup(tmpDir));
|
|
|
|
const configPath = path.join(tmpDir, '.planning', 'config.json');
|
|
fs.writeFileSync(configPath, '{}');
|
|
|
|
const result = runGsdTools(
|
|
['config-set', 'workflow.subagent_timeout', 'not-a-number'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
// The CLI layer accepts the write — type validation lives in the
|
|
// /gsd-settings-advanced workflow. If a future change adds a numeric
|
|
// type-check at config-set, flip this assertion to !result.success.
|
|
assert.ok(result.success, `config-set should accept the raw value at the CLI boundary: ${result.error || result.output}`);
|
|
const stored = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
assert.strictEqual(
|
|
typeof stored.workflow.subagent_timeout,
|
|
'string',
|
|
'non-numeric input on a numeric key currently lands as a string at the CLI boundary'
|
|
);
|
|
assert.strictEqual(stored.workflow.subagent_timeout, 'not-a-number');
|
|
});
|
|
|
|
test('config-set on a numeric key coerces a numeric string to Number (parser invariant)', (t) => {
|
|
const tmpDir = createTempProject();
|
|
t.after(() => cleanup(tmpDir));
|
|
|
|
const configPath = path.join(tmpDir, '.planning', 'config.json');
|
|
fs.writeFileSync(configPath, '{}');
|
|
|
|
const result = runGsdTools(
|
|
['config-set', 'workflow.max_discuss_passes', '7'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(result.success, `config-set failed: ${result.error || result.output}`);
|
|
const stored = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
assert.strictEqual(typeof stored.workflow.max_discuss_passes, 'number');
|
|
assert.strictEqual(stored.workflow.max_discuss_passes, 7);
|
|
});
|
|
});
|
|
|
|
|
|
// ────────────────────────────────────────────────────────────────────────
|
|
// Folded from tests/bug-2506-settings-profile-nonclaude-warning.test.cjs — consolidation epic #1969 (B4 #1973)
|
|
// ────────────────────────────────────────────────────────────────────────
|
|
{
|
|
const { describe: __foldDescribe } = require('node:test');
|
|
__foldDescribe("folded:bug-2506-settings-profile-nonclaude-warning (consolidation epic #1969 B4 #1973)", () => {
|
|
/**
|
|
* Regression test for bug #2506
|
|
*
|
|
* /gsd-settings presents Quality/Balanced/Budget model profiles without any
|
|
* warning that on non-Claude runtimes (Codex, Gemini CLI, etc.) these profiles
|
|
* select Claude model tiers and have no effect on actual agent model selection.
|
|
*
|
|
* Fix: settings.md must include a non-Claude runtime note instructing users to
|
|
* use "Inherit" or configure model_overrides manually, and the Inherit option
|
|
* description must explicitly call out non-Claude runtimes.
|
|
*
|
|
* Closes: #2506
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const { describe, test, before } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const SETTINGS_PATH = path.join(__dirname, '..', 'gsd-core', 'workflows', 'settings.md');
|
|
|
|
describe('bug #2506: settings.md non-Claude runtime warning for model profiles', () => {
|
|
let content;
|
|
|
|
before(() => {
|
|
content = fs.readFileSync(SETTINGS_PATH, 'utf-8');
|
|
});
|
|
|
|
test('settings.md contains a non-Claude runtime note for model profiles', () => {
|
|
assert.ok(
|
|
content.includes('non-Claude runtime') || content.includes('non-Claude runtimes'),
|
|
'settings.md must include a note about non-Claude runtimes and model profiles'
|
|
);
|
|
});
|
|
|
|
test('non-Claude note explains profiles are no-ops without model_overrides', () => {
|
|
assert.ok(
|
|
content.includes('model_overrides') || content.includes('no effect'),
|
|
'note must explain profiles have no effect on non-Claude runtimes without model_overrides'
|
|
);
|
|
});
|
|
|
|
test('Inherit option description explicitly mentions non-Claude runtimes', () => {
|
|
// The Inherit option in AskUserQuestion must call out non-Claude runtimes
|
|
const inheritOptionMatch = content.match(/label:\s*"Inherit"[^}]*description:\s*"([^"]+)"/s);
|
|
assert.ok(inheritOptionMatch, 'Inherit option with label/description must exist in settings.md');
|
|
const desc = inheritOptionMatch[1];
|
|
assert.ok(
|
|
desc.includes('non-Claude') || desc.includes('Codex') || desc.includes('Gemini'),
|
|
`Inherit option description must mention non-Claude runtimes; got: "${desc}"`
|
|
);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
// ────────────────────────────────────────────────────────────────────────
|
|
// Folded from tests/bug-3784-gsd-settings-model-profile-ui-omits-adaptive.test.cjs — consolidation epic #1969 (B4 #1973)
|
|
// ────────────────────────────────────────────────────────────────────────
|
|
{
|
|
const { describe: __foldDescribe } = require('node:test');
|
|
__foldDescribe("folded:bug-3784-gsd-settings-model-profile-ui-omits-adaptive (consolidation epic #1969 B4 #1973)", () => {
|
|
'use strict';
|
|
|
|
// allow-test-rule: source-text-is-the-product (see #3784)
|
|
// The deployed settings.md IS the product — testing its text content tests the deployed contract.
|
|
|
|
/**
|
|
* Regression test for bug #3784
|
|
*
|
|
* /gsd-settings model profile UI omits `adaptive`. The AskUserQuestion block
|
|
* for model_profile in settings.md lists only four options (Quality, Balanced,
|
|
* Budget, Inherit) but the settings schema registers five valid profiles:
|
|
* quality, balanced, budget, adaptive, inherit. The `adaptive` profile is
|
|
* reachable by name via `gsd:config --profile adaptive` but cannot be selected
|
|
* interactively through `/gsd:settings`.
|
|
*
|
|
* Root cause: the options array in the model-profile AskUserQuestion block was
|
|
* written before the `adaptive` profile was introduced and was never updated.
|
|
* Because AskUserQuestion enforces a hard 4-option cap, the fix uses a two-
|
|
* question split: Q1 asks "Standard tier or Adaptive?" (2 options); if the
|
|
* user picks Standard, Q2 asks which of the three standard profiles to use
|
|
* (Quality, Balanced, Budget). This keeps every call within the 4-option cap
|
|
* while making all five profiles reachable.
|
|
*
|
|
* Fixes: #3784
|
|
*/
|
|
|
|
const { describe, test, before } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const SETTINGS_PATH = path.join(__dirname, '..', 'gsd-core', 'workflows', 'settings.md');
|
|
|
|
/**
|
|
* Extract all AskUserQuestion option labels from a text block.
|
|
* Returns them lowercased for case-insensitive comparison.
|
|
*/
|
|
function extractOptionLabels(block) {
|
|
const labelPattern = /label:\s*"([^"]+)"/g;
|
|
const labels = [];
|
|
let match;
|
|
while ((match = labelPattern.exec(block)) !== null) {
|
|
labels.push(match[1].toLowerCase());
|
|
}
|
|
return labels;
|
|
}
|
|
|
|
describe('bug #3784: settings.md model profile UI exposes all 5 profiles', () => {
|
|
let content;
|
|
let presentBlock;
|
|
|
|
before(() => {
|
|
content = fs.readFileSync(SETTINGS_PATH, 'utf-8');
|
|
const presentMatch = content.match(/<step name="present_settings">[\s\S]*?<\/step>/);
|
|
assert.ok(presentMatch, 'settings.md must have a present_settings step');
|
|
presentBlock = presentMatch[0];
|
|
});
|
|
|
|
// ── Core contract: all five valid profiles reachable via the settings UI ──
|
|
|
|
test('present_settings step includes Adaptive as a selectable option (#3784)', () => {
|
|
// This is the primary assertion for bug #3784 — adaptive was missing.
|
|
const labels = extractOptionLabels(presentBlock);
|
|
assert.ok(
|
|
labels.some(l => l === 'adaptive' || l.startsWith('adaptive')),
|
|
[
|
|
'Bug #3784: present_settings step must include an "Adaptive" label in',
|
|
'its model profile AskUserQuestion options so users can select it',
|
|
`interactively. Got labels: [${labels.join(', ')}]`,
|
|
].join(' ')
|
|
);
|
|
});
|
|
|
|
test('present_settings step includes Quality as a selectable option', () => {
|
|
const labels = extractOptionLabels(presentBlock);
|
|
assert.ok(
|
|
labels.some(l => l === 'quality' || l.startsWith('quality')),
|
|
`present_settings step must include a "Quality" option. Got: [${labels.join(', ')}]`
|
|
);
|
|
});
|
|
|
|
test('present_settings step includes Balanced as a selectable option', () => {
|
|
const labels = extractOptionLabels(presentBlock);
|
|
assert.ok(
|
|
labels.some(l => l === 'balanced' || l.startsWith('balanced')),
|
|
`present_settings step must include a "Balanced" option. Got: [${labels.join(', ')}]`
|
|
);
|
|
});
|
|
|
|
test('present_settings step includes Budget as a selectable option', () => {
|
|
const labels = extractOptionLabels(presentBlock);
|
|
assert.ok(
|
|
labels.some(l => l === 'budget' || l.startsWith('budget')),
|
|
`present_settings step must include a "Budget" option. Got: [${labels.join(', ')}]`
|
|
);
|
|
});
|
|
|
|
test('present_settings step includes Inherit as a selectable option', () => {
|
|
const labels = extractOptionLabels(presentBlock);
|
|
assert.ok(
|
|
labels.some(l => l === 'inherit' || l.startsWith('inherit')),
|
|
`present_settings step must include an "Inherit" option. Got: [${labels.join(', ')}]`
|
|
);
|
|
});
|
|
|
|
// ── update_config step writes adaptive as a valid value ──
|
|
|
|
test('update_config step lists adaptive as a valid model_profile value', () => {
|
|
const updateMatch = content.match(/<step name="update_config">[\s\S]*?<\/step>/);
|
|
assert.ok(updateMatch, 'settings.md must have an update_config step');
|
|
const block = updateMatch[0];
|
|
assert.ok(
|
|
block.includes('adaptive'),
|
|
'update_config step must list "adaptive" as a valid model_profile value'
|
|
);
|
|
});
|
|
|
|
// ── confirm step displays adaptive as a possible profile value ──
|
|
|
|
test('confirm step table shows adaptive as a possible model profile value', () => {
|
|
const confirmMatch = content.match(/<step name="confirm">[\s\S]*?<\/step>/);
|
|
assert.ok(confirmMatch, 'settings.md must have a confirm step');
|
|
const block = confirmMatch[0];
|
|
assert.ok(
|
|
block.includes('adaptive'),
|
|
'confirm step must include "adaptive" in the Model Profile row placeholder'
|
|
);
|
|
});
|
|
|
|
// ── adaptive described with role-based routing semantics ──
|
|
|
|
test('settings.md describes adaptive profile with role-based routing semantics', () => {
|
|
// Adaptive uses heavy/light role tiers per routingTier.
|
|
// The UI description must convey role-based cost optimization and the heavy/light tier
|
|
// split — not just mention "Adaptive" somewhere (that word appears 6+ times in the file).
|
|
const lower = content.toLowerCase();
|
|
assert.ok(
|
|
lower.includes('role-based cost optimization') && lower.includes('heavy roles'),
|
|
'settings.md must describe the adaptive profile with "role-based cost optimization" and "heavy roles" wording so the description is meaningful across all supported runtimes'
|
|
);
|
|
});
|
|
|
|
// ── 4-option cap enforcement ──
|
|
|
|
test('each question object in present_settings AskUserQuestion blocks has at most 4 options (AskUserQuestion runtime cap)', () => {
|
|
// The AskUserQuestion runtime enforces a hard 4-option cap per individual question object
|
|
// (each { question:..., options:[...] } entry). This test guards against a naïve revert
|
|
// that puts all 5 profiles into a single question object instead of using the Q1/Q2 split.
|
|
const ASK_USER_QUESTION_OPTION_CAP = 4; // hard limit enforced by the AskUserQuestion runtime
|
|
|
|
// Extract each individual options array by finding 'options: [' and walking to the
|
|
// matching balanced ']', then count label: entries within that span.
|
|
const optionsKeyRe = /\boptions\s*:\s*\[/g;
|
|
let match;
|
|
let questionIndex = 0;
|
|
while ((match = optionsKeyRe.exec(presentBlock)) !== null) {
|
|
questionIndex++;
|
|
// Walk forward from the opening '[' to find the balanced close ']'.
|
|
let depth = 0;
|
|
const start = match.index + match[0].length - 1; // points at '['
|
|
let end = start;
|
|
for (let k = start; k < presentBlock.length; k++) {
|
|
if (presentBlock[k] === '[') { depth++; }
|
|
else if (presentBlock[k] === ']') {
|
|
depth--;
|
|
if (depth === 0) { end = k; break; }
|
|
}
|
|
}
|
|
const optionsBody = presentBlock.slice(start, end + 1);
|
|
const labelMatches = optionsBody.match(/label:\s*"[^"]+"/g) || [];
|
|
const optionCount = labelMatches.length;
|
|
assert.ok(
|
|
optionCount <= ASK_USER_QUESTION_OPTION_CAP,
|
|
`Question object ${questionIndex} in present_settings has ${optionCount} options — exceeds the runtime cap of ${ASK_USER_QUESTION_OPTION_CAP}. Split into multiple questions (as #3784 did for model_profile).`
|
|
);
|
|
}
|
|
// Sanity check: there must be at least one options array found.
|
|
assert.ok(questionIndex > 0, 'present_settings must contain at least one AskUserQuestion options array');
|
|
});
|
|
|
|
// ── Brace-balance regression (bd53925f fixed duplicate '{' from 35fc1d21) ──
|
|
|
|
test('present_settings step has balanced braces — regression: brace-balance after #3784 split', () => {
|
|
// commit bd53925f fixed a duplicate '{' introduced by 35fc1d21 when the model-profile
|
|
// AskUserQuestion was split into Q1+Q2. This test guards against a recurrence.
|
|
let depth = 0;
|
|
for (const ch of presentBlock) {
|
|
if (ch === '{') { depth++; }
|
|
if (ch === '}') { depth--; }
|
|
}
|
|
assert.strictEqual(
|
|
depth,
|
|
0,
|
|
`present_settings step has unbalanced braces: net depth after full scan is ${depth} (positive = extra '{', negative = extra '}'). Regression guard for bd53925f / #3784.`
|
|
);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
// ────────────────────────────────────────────────────────────────────────
|
|
// Folded from tests/bug-33-settings-model-profile-adaptive.test.cjs — consolidation epic #1969 (B8 #1977)
|
|
// ────────────────────────────────────────────────────────────────────────
|
|
{
|
|
const { describe: __foldDescribe } = require('node:test');
|
|
__foldDescribe("folded:bug-33-settings-model-profile-adaptive (consolidation epic #1969 B8 #1977)", () => {
|
|
'use strict';
|
|
|
|
// allow-test-rule: source-text-is-the-product (see #33)
|
|
// The deployed settings.md IS the product — testing its text content tests the deployed contract.
|
|
|
|
/**
|
|
* Regression test for issue #33
|
|
*
|
|
* model_profile UI shows 4 options, schema has 5 — `adaptive` missing from
|
|
* `settings.md` AskUserQuestion.
|
|
*
|
|
* The schema (gsd-core/bin/shared/model-catalog.json `profiles` array) defines 5 valid
|
|
* model_profile values: quality, balanced, budget, adaptive, inherit. The
|
|
* settings.md AskUserQuestion block for model_profile originally listed only 4
|
|
* options (Quality, Balanced, Budget, Inherit) — `adaptive` was missing.
|
|
*
|
|
* Fix: the model_profile selection uses a two-question split. Q1 routes between
|
|
* Adaptive / Standard-tier / Inherit (3 options). Q2 (only when Q1 = Standard)
|
|
* asks Quality / Balanced / Budget. This keeps every individual options array
|
|
* within the AskUserQuestion 4-option cap while making all 5 profiles reachable.
|
|
*
|
|
* Fixes: #33
|
|
*/
|
|
|
|
const { describe, test, before } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const REPO_ROOT = path.join(__dirname, '..');
|
|
const SETTINGS_PATH = path.join(REPO_ROOT, 'gsd-core', 'workflows', 'settings.md');
|
|
const CATALOG_PATH = path.join(REPO_ROOT, 'gsd-core', 'bin', 'shared', 'model-catalog.json');
|
|
|
|
/**
|
|
* Collect every label: "..." value within a text block, lowercased.
|
|
*/
|
|
function extractOptionLabels(block) {
|
|
const re = /label:\s*"([^"]+)"/g;
|
|
const labels = [];
|
|
let m;
|
|
while ((m = re.exec(block)) !== null) {
|
|
labels.push(m[1].toLowerCase());
|
|
}
|
|
return labels;
|
|
}
|
|
|
|
describe('issue #33: model_profile schema and settings.md UI are in sync', () => {
|
|
let catalog;
|
|
let settingsContent;
|
|
let presentBlock;
|
|
|
|
before(() => {
|
|
catalog = JSON.parse(fs.readFileSync(CATALOG_PATH, 'utf-8'));
|
|
settingsContent = fs.readFileSync(SETTINGS_PATH, 'utf-8');
|
|
const presentMatch = settingsContent.match(/<step name="present_settings">[\s\S]*?<\/step>/);
|
|
assert.ok(presentMatch, 'settings.md must contain a present_settings step');
|
|
presentBlock = presentMatch[0];
|
|
});
|
|
|
|
// -- (a) Schema contract ---------------------------------------------------
|
|
|
|
test('schema includes the adaptive model_profile value', () => {
|
|
assert.ok(
|
|
Array.isArray(catalog.profiles),
|
|
'model-catalog.json must have a "profiles" array'
|
|
);
|
|
assert.ok(
|
|
catalog.profiles.includes('adaptive'),
|
|
'model-catalog should include the adaptive profile. Got: [' + catalog.profiles.join(', ') + ']'
|
|
);
|
|
});
|
|
|
|
test('schema includes adaptive as a model_profile value', () => {
|
|
assert.ok(
|
|
catalog.profiles.includes('adaptive'),
|
|
'"adaptive" must be in model-catalog.json profiles. Got: [' + catalog.profiles.join(', ') + ']'
|
|
);
|
|
});
|
|
|
|
test('schema includes all expected model_profile values', () => {
|
|
const expected = ['quality', 'balanced', 'budget', 'adaptive', 'inherit'];
|
|
for (const profile of expected) {
|
|
assert.ok(
|
|
catalog.profiles.includes(profile),
|
|
'Schema must include "' + profile + '" in profiles. Got: [' + catalog.profiles.join(', ') + ']'
|
|
);
|
|
}
|
|
});
|
|
|
|
// -- (b) UI contract — all 5 profiles reachable via present_settings -------
|
|
|
|
test('present_settings includes Adaptive as a selectable option (#33)', () => {
|
|
const labels = extractOptionLabels(presentBlock);
|
|
assert.ok(
|
|
labels.some(l => l === 'adaptive' || l.startsWith('adaptive')),
|
|
'Issue #33: present_settings must include an "Adaptive" label in its model_profile AskUserQuestion options so users can select it interactively. Got labels: [' + labels.join(', ') + ']'
|
|
);
|
|
});
|
|
|
|
test('present_settings includes Quality as a selectable option', () => {
|
|
const labels = extractOptionLabels(presentBlock);
|
|
assert.ok(
|
|
labels.some(l => l === 'quality' || l.startsWith('quality')),
|
|
'present_settings must include a "Quality" option. Got: [' + labels.join(', ') + ']'
|
|
);
|
|
});
|
|
|
|
test('present_settings includes Balanced as a selectable option', () => {
|
|
const labels = extractOptionLabels(presentBlock);
|
|
assert.ok(
|
|
labels.some(l => l === 'balanced' || l.startsWith('balanced')),
|
|
'present_settings must include a "Balanced" option. Got: [' + labels.join(', ') + ']'
|
|
);
|
|
});
|
|
|
|
test('present_settings includes Budget as a selectable option', () => {
|
|
const labels = extractOptionLabels(presentBlock);
|
|
assert.ok(
|
|
labels.some(l => l === 'budget' || l.startsWith('budget')),
|
|
'present_settings must include a "Budget" option. Got: [' + labels.join(', ') + ']'
|
|
);
|
|
});
|
|
|
|
test('present_settings includes Inherit as a selectable option', () => {
|
|
const labels = extractOptionLabels(presentBlock);
|
|
assert.ok(
|
|
labels.some(l => l === 'inherit' || l.startsWith('inherit')),
|
|
'present_settings must include an "Inherit" option. Got: [' + labels.join(', ') + ']'
|
|
);
|
|
});
|
|
|
|
// -- update_config and confirm steps reference adaptive --------------------
|
|
|
|
test('update_config step lists adaptive as a valid model_profile value', () => {
|
|
const m = settingsContent.match(/<step name="update_config">[\s\S]*?<\/step>/);
|
|
assert.ok(m, 'settings.md must have an update_config step');
|
|
assert.ok(
|
|
m[0].includes('adaptive'),
|
|
'update_config step must list "adaptive" as a valid model_profile value'
|
|
);
|
|
});
|
|
|
|
test('confirm step table shows adaptive as a possible model profile value', () => {
|
|
const m = settingsContent.match(/<step name="confirm">[\s\S]*?<\/step>/);
|
|
assert.ok(m, 'settings.md must have a confirm step');
|
|
assert.ok(
|
|
m[0].includes('adaptive'),
|
|
'confirm step must include "adaptive" in the Model Profile row'
|
|
);
|
|
});
|
|
});
|
|
});
|
|
}
|