test(#1973): consolidate 48 workflow regression tests into workflow-aspect suites

Fold 48 issue-named workflow-markdown regression files into the canonical test
that owns each workflow aspect (execute-phase-*, plan-phase-*, quick-*, discuss-*,
worktree-cleanup, secure-phase, verify, update, settings, etc.), across 32 existing
suites. Verbatim block-scoped describe wrappers; 281 subtests conserved 1:1. No new
test files. Host-env pre-check: only gsd-settings-advanced spawns CLI and it sets no
GSD_WORKSTREAM/GSD_PROJECT value — no leak risk.

Regenerates regression-name allowlist (222->181), ratchets file-count allowlist
(verify 11->10), makes 30 relocated allow-test-rule exemptions issue-ref-compliant
(ADR-456; prunes 30 stale ids). lint:ci green.

Part of epic #1969. Closes #1973.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-07-03 02:14:17 -04:00
parent 7b515687ce
commit 2c32e8d890
83 changed files with 5488 additions and 5086 deletions

View File

@@ -86,3 +86,116 @@ describe('AskUserQuestion text-mode fallback (#2012)', () => {
);
});
});
// ────────────────────────────────────────────────────────────────────────
// Folded from tests/bug-17-askuserquestion-option-cap.test.cjs — consolidation epic #1969 (B4 #1973)
// ────────────────────────────────────────────────────────────────────────
{
const { describe: __foldDescribe } = require('node:test');
__foldDescribe("folded:bug-17-askuserquestion-option-cap (consolidation epic #1969 B4 #1973)", () => {
'use strict';
// allow-test-rule: source-text-is-the-product (see #17)
// Workflow markdown is the shipped runtime contract; validating its AskUserQuestion
// option limits is a behavioral guard, not an implementation-detail assertion.
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.join(__dirname, '..', 'gsd-core', 'workflows');
const ASK_USER_QUESTION_OPTION_CAP = 4;
function walkMarkdownFiles(dir, out = []) {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) {
walkMarkdownFiles(full, out);
continue;
}
if (entry.isFile() && full.endsWith('.md')) out.push(full);
}
return out;
}
function findBalancedClose(text, openIndex, openCh, closeCh) {
let depth = 0;
for (let i = openIndex; i < text.length; i++) {
const ch = text[i];
if (ch === openCh) depth++;
else if (ch === closeCh) {
depth--;
if (depth === 0) return i;
}
}
return -1;
}
function getLineNumber(text, index) {
return text.slice(0, index).split('\n').length;
}
function collectOptionCapViolations(file, text) {
const violations = [];
const askRe = /\bAskUserQuestion\s*\(\s*\[/g;
let askMatch;
while ((askMatch = askRe.exec(text)) !== null) {
const askStart = askMatch.index;
const arrayOpen = text.indexOf('[', askStart);
if (arrayOpen === -1) continue;
const arrayClose = findBalancedClose(text, arrayOpen, '[', ']');
if (arrayClose === -1) continue;
const askBlock = text.slice(arrayOpen, arrayClose + 1);
const blockOffset = arrayOpen;
const optionsRe = /\boptions\s*:\s*\[/g;
let optionsMatch;
while ((optionsMatch = optionsRe.exec(askBlock)) !== null) {
const openInBlock = optionsMatch.index + optionsMatch[0].length - 1;
const closeInBlock = findBalancedClose(askBlock, openInBlock, '[', ']');
if (closeInBlock === -1) continue;
const optionsBody = askBlock.slice(openInBlock, closeInBlock + 1);
const labelCount = (optionsBody.match(/\blabel\s*:\s*"[^"]+"/g) || []).length;
if (labelCount > ASK_USER_QUESTION_OPTION_CAP) {
const globalIdx = blockOffset + optionsMatch.index;
violations.push({
file,
line: getLineNumber(text, globalIdx),
count: labelCount,
});
}
}
}
return violations;
}
describe('bug #17: AskUserQuestion options arrays respect runtime cap', () => {
test('every AskUserQuestion options array in workflows has at most 4 options', () => {
const files = walkMarkdownFiles(ROOT);
const violations = [];
for (const file of files) {
const text = fs.readFileSync(file, 'utf8');
violations.push(...collectOptionCapViolations(file, text));
}
assert.equal(
violations.length,
0,
[
`Found ${violations.length} AskUserQuestion options-array cap violation(s).`,
`Runtime cap is ${ASK_USER_QUESTION_OPTION_CAP} options per question.`,
...violations.map((v) => {
const rel = path.relative(path.join(__dirname, '..'), v.file);
return ` ${rel}:${v.line} -> ${v.count} options`;
}),
].join('\n')
);
});
});
});
}