Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(blueprint): save reads back a question with 3+ choices [S1]

Corey Olson656f85457689
diff --git a/src/blueprints.js b/src/blueprints.js
index 184a0efd..e7a92d05 100644
--- a/src/blueprints.js
+++ b/src/blueprints.js
@@ -374,9 +374,12 @@ function positions(text, separator) {
/**
* Read an approved question row back into its ask, choices and answer, or say why it cannot be.
- * The ask and the choices may hold ": " and ", ", so every split is tried: a reading counts only if
- * its answer is one of two or more choices and questionText gives back the exact row text. One
- * reading is kept; none or several leave the row out, so a save never changes a question [S1].
+ * The ask and the choices may hold ": " and ", ", so every split of the ask is tried. The answer
+ * is the one run of comma-separated parts it equals; every other part is a choice of its own, so
+ * a question with three or more choices keeps its listed choices exactly as written instead of
+ * reading as every way its parts could join. A reading counts only if it has two or more choices
+ * and questionText gives back the exact row text. One reading is kept; none or several leave the
+ * row out, so a save never changes a question [S1].
*
* @param {string} text
* @returns {{ question?: { ask: string, choices: string[], default: string }, reason?: string } | null} null when the row is no question
@@ -391,15 +394,14 @@ function readQuestion(text) {
for (const colon of positions(head, ': ')) {
const ask = head.slice(0, colon);
const answer = head.slice(colon + 2);
- for (let mask = 0; mask < 2 ** (tokens.length - 1); mask += 1) {
- const choices = [tokens[0]];
- for (let index = 1; index < tokens.length; index += 1) {
- if (mask & (2 ** (index - 1))) choices[choices.length - 1] += `, ${tokens[index]}`;
- else choices.push(tokens[index]);
+ for (let from = 0; from < tokens.length; from += 1) {
+ for (let to = from + 1; to <= tokens.length; to += 1) {
+ if (tokens.slice(from, to).join(', ') !== answer) continue;
+ const choices = [...tokens.slice(0, from), answer, ...tokens.slice(to)];
+ const question = { ask, choices, default: answer };
+ if (choices.length < 2 || [ask, ...choices].some((part) => !part.trim() || part !== part.trim())) continue;
+ if (questionText(question) === text) readings.set(JSON.stringify(question), question);
}
- const question = { ask, choices, default: answer };
- if (choices.length < 2 || !choices.includes(answer) || [ask, ...choices].some((part) => !part.trim() || part !== part.trim())) continue;
- if (questionText(question) === text) readings.set(JSON.stringify(question), question);
}
}
}
diff --git a/test/blueprint.test.js b/test/blueprint.test.js
index 1c732492..bbc6feab 100644
--- a/test/blueprint.test.js
+++ b/test/blueprint.test.js
@@ -404,6 +404,7 @@ test('a saved board adds back as the same rows [S1]', () => {
'- K3 [approved, must] The app is built with: SvelteKit. Choices: Next.js, SvelteKit, Rails. | gate: review',
'- K12 [approved, must] Deploy: where it goes: Fly.io. Choices: Vercel, Fly.io. | gate: review',
'- K13 [approved, must] People sign in with: Email, then a link. Choices: Email, then a link, Passwords. | gate: review',
+ '- K14 [approved, must] Pick one: x. Choices: x, y, z, w. | gate: review',
];
const planted = [
'- K4 [approved, must] Logs live in web/logs/app.js. Why: one place to look. | gate: review',
@@ -414,7 +415,6 @@ test('a saved board adds back as the same rows [S1]', () => {
'- K9 [approved, must] The page renders without a reason. | gate: review',
'- K10 [draft, must] A draft never leaves. Why: nobody decided it. | gate: review',
'- K11 [pending, must] Deploys go to: Vercel. Choices: Vercel, Fly.io. | gate: review',
- '- K14 [approved, must] Pick one: x. Choices: x, y, z, w. | gate: review',
'- K15 [approved, must] Pick a host: Rails. Choices: Vercel, Fly.io. | gate: review',
'- K16 [approved, must] A rule. Why: one. Why: two. | gate: review',
];
@@ -429,7 +429,7 @@ test('a saved board adds back as the same rows [S1]', () => {
const saved = box.run(box.repo, 'blueprint', 'save', '--json');
assert.equal(saved.code, 0, `${saved.err}\n${saved.out}`);
- assert.deepEqual(JSON.parse(saved.out).left.map((entry) => entry.id).sort(), ['G1', 'G2', 'K14', 'K15', 'K16', 'K4', 'K5', 'K6', 'K7', 'K8', 'K9'], 'only clean, exactly readable approved rows leave');
+ assert.deepEqual(JSON.parse(saved.out).left.map((entry) => entry.id).sort(), ['G1', 'G2', 'K15', 'K16', 'K4', 'K5', 'K6', 'K7', 'K8', 'K9'], 'only clean, exactly readable approved rows leave');
const file = join(box.repo, 'Dana Whitlock board.blueprint.json');
const text = readFileSync(file, 'utf8');
for (const secret of ['web/', '@', 'Dana', 'Whitlock', 'web-1', machine, 'zebra', 'walrus', 'narwhal', 'signers', 'DW', 'items', 'pullboard-blueprint', 'Logs live', 'draft never', 'Deploys go']) {
@@ -441,7 +441,7 @@ test('a saved board adds back as the same rows [S1]', () => {
assert.equal(JSON.parse(named.out).error?.code, 'PRIVATE_BLUEPRINT', 'a chosen name that names someone is refused');
assert.deepEqual(Object.keys(blueprint).sort(), ['blueprint', 'gate', 'name', 'questions', 'rules', 'title', 'version'], 'only allow-listed fields are written');
assert.deepEqual(blueprint.rules.map((rule) => Object.keys(rule).sort()), [['gate', 'key', 'text', 'tier', 'why'], ['gate', 'key', 'text', 'tier', 'why']]);
- assert.deepEqual(blueprint.questions.map((question) => Object.keys(question).sort()), Array(3).fill(['ask', 'choices', 'default', 'key']));
+ assert.deepEqual(blueprint.questions.map((question) => Object.keys(question).sort()), Array(4).fill(['ask', 'choices', 'default', 'key']));
assert.equal(box.run(box.repo, 'blueprint', 'save', '--json').code, 1, 'an existing file is never overwritten');
const fresh = e2e.project();
@@ -455,6 +455,36 @@ test('a saved board adds back as the same rows [S1]', () => {
['pending', 'must', 'The app is built with: SvelteKit. Choices: Next.js, SvelteKit, Rails.'],
['pending', 'must', 'Deploy: where it goes: Fly.io. Choices: Vercel, Fly.io.'],
['pending', 'must', 'People sign in with: Email, then a link. Choices: Email, then a link, Passwords.'],
+ ['pending', 'must', 'Pick one: x. Choices: x, y, z, w.'],
], 'the approved rows come back as drafts, each answered question exactly, its answer the default');
assert.deepEqual(JSON.parse(fresh.run(fresh.repo, 'list', '--json').out).items ?? [], [], 'a saved blueprint files no items');
});
+
+test('blueprint save reads back a question with three or more choices [S1]', () => {
+ const box = freshBoard();
+ const questions = [
+ 'The app is built with: Next.js. Choices: Next.js, SvelteKit, Rails.',
+ 'People sign in with: Magic links. Choices: Passwords, Passkeys, Single sign-on, Magic links.',
+ 'Deploy: where it goes: Fly.io, then Vercel. Choices: Render, Fly.io, then Vercel, Railway.',
+ ];
+ const spec = join(box.repo, 'SPEC.md');
+ writeFileSync(spec, `${readFileSync(spec, 'utf8')}\n## Q · Questions\n\n${questions.map((text, index) => `- Q${index + 1} [approved, must] ${text} | gate: review`).join('\n')}\n`);
+ box.git('add', 'SPEC.md');
+ box.git('commit', '-q', '-m', 'chore: answer three questions');
+
+ const saved = json(box, 'blueprint', 'save', 'questions.json', '--name', 'stack-questions', '--title', 'Stack questions');
+ assert.deepEqual(saved.left.filter((entry) => entry.id.startsWith('Q')), [], 'no answered question is left out');
+ const blueprint = JSON.parse(readFileSync(join(box.repo, 'questions.json'), 'utf8'));
+ assert.deepEqual(blueprint.questions.map(({ key, ask, choices, default: answer }) => [key, ask, choices, answer]), [
+ ['Q1', 'The app is built with', ['Next.js', 'SvelteKit', 'Rails'], 'Next.js'],
+ ['Q2', 'People sign in with', ['Passwords', 'Passkeys', 'Single sign-on', 'Magic links'], 'Magic links'],
+ ['Q3', 'Deploy: where it goes', ['Render', 'Fly.io, then Vercel', 'Railway'], 'Fly.io, then Vercel'],
+ ], 'a three-choice and a four-choice question keep their listed choices and the chosen answer');
+
+ const fresh = freshBoard();
+ const before = parseSpec(readFileSync(join(fresh.repo, 'SPEC.md'), 'utf8')).rows.map((row) => row.id);
+ json(fresh, 'blueprint', 'add', join(box.repo, 'questions.json'));
+ const rows = parseSpec(readFileSync(join(fresh.repo, 'SPEC.md'), 'utf8')).rows.filter((row) => !before.includes(row.id));
+ assert.deepEqual(rows.map((row) => [row.status, row.text]), questions.map((text) => ['pending', text]),
+ 'each question round-trips to its exact row text');
+});