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.

feat(blueprint): bundled blueprint rows say what they check [S1,I1]

Corey Olsona68ba325692e
diff --git a/src/blueprints/library.json b/src/blueprints/library.json
index b174e59f..cfb48704 100644
--- a/src/blueprints/library.json
+++ b/src/blueprints/library.json
@@ -8,8 +8,9 @@
"summary": "Your users get a changelog line and the right version bump, every release.",
"prefix": "LIB",
"rules": [
- { "key": "LIB1", "text": "A breaking change bumps the major version.", "why": "people pin a major version, so a breaking change must never arrive inside one." },
- { "key": "LIB2", "text": "Every public function has a working example in the docs.", "why": "an example that runs teaches a function fastest and breaks loudly when the function changes." }
+ { "key": "LIB1", "text": "A breaking change bumps the major version.", "why": "people pin a major version, so a breaking change must never arrive inside one; before 1.0 people pin the minor version, so there a breaking change bumps the minor.", "tier": "must", "gate": "test/public-api.test.js" },
+ { "key": "LIB2", "text": "Every public function has a working example in the docs.", "why": "an example that runs teaches a function fastest and breaks loudly when the function changes.", "tier": "must", "gate": "test/docs-examples.test.js" },
+ { "key": "LIB3", "text": "Every release adds a changelog line for each change its users can see.", "why": "the changelog is where users learn what an upgrade changes, so a change left out of it surprises them.", "tier": "must", "gate": "review" }
],
"questions": [
{ "key": "Q1", "ask": "The library is written in", "choices": ["JavaScript or TypeScript", "Python", "Rust", "Something else"], "default": "JavaScript or TypeScript" },
diff --git a/src/blueprints/test-reliability.json b/src/blueprints/test-reliability.json
index 33e641ab..264e9e75 100644
--- a/src/blueprints/test-reliability.json
+++ b/src/blueprints/test-reliability.json
@@ -9,10 +9,12 @@
"prefix": "TR",
"rules": [
{ "key": "TR1", "text": "No test waits on the wall clock or a fixed sleep.", "why": "a test that sleeps is slow on an idle machine and flaky on a busy one." },
- { "key": "TR2", "text": "A flake is pinned on a change only after a run without it.", "why": "a test that fails under load looks like a broken change until it fails without that change too." }
+ { "key": "TR2", "text": "A flake is pinned on a change only after a run without it.", "why": "a test that fails under load looks like a broken change until it fails without that change too." },
+ { "key": "TR3", "text": "A flake fix is proven by repeated runs.", "why": "a flaky test already passes some of the time, so one green run after a fix proves nothing; only a run of passes shows the flake is gone.", "tier": "must", "gate": "the whole test suite, run as many times in a row as the run count question says, every run passing" }
],
"questions": [
- { "key": "Q1", "ask": "Tests run with", "choices": ["Vitest", "Jest", "pytest", "Something else"], "default": "Vitest" }
+ { "key": "Q1", "ask": "Tests run with", "choices": ["Vitest", "Jest", "pytest", "Something else"], "default": "Vitest" },
+ { "key": "Q2", "ask": "A flake fix passes this many runs in a row", "choices": ["5", "10", "20"], "default": "10" }
],
"items": [
{ "key": "1", "title": "Find a flaky test and make it deterministic", "cites": ["TR1", "TR2"], "criterion": "A test that failed in repeated runs of the unchanged suite is found, named in the submit note, and fixed so the suite passes ten runs in a row with no sleep or wall-clock wait. Before the fix, ten repeated runs of npm test fail at least once.", "brief": "Files:\n- the flaky test and the code it waits on\nTest:\n- run npm test twenty times with nothing changed to find a test that fails some of the time (TR2)\n- replace its sleep or wall-clock wait with a fake clock or an awaited event (TR1), then run the check", "check": "set -e; for run in 1 2 3 4 5 6 7 8 9 10; do npm test; done" }
diff --git a/src/blueprints/web-app.json b/src/blueprints/web-app.json
index 38287d59..8dc703d5 100644
--- a/src/blueprints/web-app.json
+++ b/src/blueprints/web-app.json
@@ -14,7 +14,8 @@
{ "key": "W3", "text": "Every page works at phone width before it ships.", "why": "a page that only works on a laptop is a bug nobody reports." },
{ "key": "W4", "text": "Secrets never appear in code, logs or commits.", "why": "a key pushed once stays public, even after you delete it." },
{ "key": "W5", "text": "A new dependency comes with a one-line reason.", "why": "every package you add is code you now maintain." },
- { "key": "W6", "text": "An error a person sees says what to do next.", "why": "\"something went wrong\" is a support ticket waiting to happen." }
+ { "key": "W6", "text": "An error a person sees says what to do next.", "why": "\"something went wrong\" is a support ticket waiting to happen." },
+ { "key": "W7", "text": "Tests bind a local port, so a sandboxed agent asks the person instead of rewriting the tests.", "why": "a test rewritten into a fake passes inside the sandbox and proves nothing about the real server.", "tier": "must", "gate": "review" }
],
"questions": [
{ "key": "Q1", "ask": "The app is built with", "choices": ["Next.js", "SvelteKit", "Rails", "Something else"], "default": "Next.js" },
diff --git a/test/blueprint.test.js b/test/blueprint.test.js
index f74ff6ca..97d58e39 100644
--- a/test/blueprint.test.js
+++ b/test/blueprint.test.js
@@ -70,7 +70,7 @@ test('blueprint add files a blueprint as drafts [S1,I1]', () => {
assert.equal(section.length, 1, 'one section named after the blueprint');
assert.equal(added.section, section[0].name);
const rows = spec.rows.filter((row) => row.section === section[0].name);
- assert.equal(rows.length, 10, '6 rules and 4 questions');
+ assert.equal(rows.length, 11, '7 rules and 4 questions');
assert.equal(spec.rows.filter((row) => row.status === 'approved').length, 0, 'nothing is approved');
const rules = rows.filter((row) => row.status === 'draft');
assert.deepEqual(rules.map((row) => row.text), PUBLISHED.rules.map((rule) => `${rule.text} Why: ${rule.why}`));
@@ -143,10 +143,10 @@ test('blueprint add files a blueprint as drafts even when approved rows say the
`## G · Goals: what the client asked for\n- G1 [approved, must] ${rule} | gate: review\n- G2 [approved, must] ${PUBLISHED.questions[0].ask}: Rails. Choices: Rails. | gate: review\n`));
box.git('commit', '-q', '-am', 'chore: approve two rows first');
const added = json(box, 'blueprint', 'add', 'web-app');
- assert.deepEqual(added.rows.map((row) => row.status), [...Array(6).fill('draft'), ...Array(4).fill('pending')]);
+ assert.deepEqual(added.rows.map((row) => row.status), [...Array(7).fill('draft'), ...Array(4).fill('pending')]);
const spec = parseSpec(readFileSync(file, 'utf8'));
const own = spec.rows.filter((row) => row.section === added.section);
- assert.equal(own.length, 10, 'the blueprint section holds all its own rows');
+ assert.equal(own.length, 11, 'the blueprint section holds all its own rows');
assert.deepEqual(spec.rows.filter((row) => row.status === 'approved').map((row) => row.id), ['G1', 'G2'], 'the approved rows are untouched');
const items = json(box, 'list', '--all').items.sort((a, b) => a.item_id - b.item_id);
assert.equal(items[0].item_spec_ids, `${added.rows[0].id},${added.rows[1].id}`, 'starter items cite the blueprint rows, not the approved ones');
@@ -179,7 +179,7 @@ test('blueprint add files a blueprint as drafts or nothing at all [S1,I1]', () =
}
// After the refusals, the same blueprint fixed adds everything at once.
const added = json(box, 'blueprint', 'add', 'web-app');
- assert.equal(added.rows.length, 10);
+ assert.equal(added.rows.length, 11);
assert.equal(added.items.length, 3);
});
@@ -350,7 +350,67 @@ test('blueprint add files a blueprint as drafts beside approved rows in its own
...PUBLISHED.rules.map((entry) => [entry.key, 'draft']), ...PUBLISHED.questions.map((entry) => [entry.key, 'pending'])]);
const spec = parseSpec(readFileSync(file, 'utf8'));
assert.deepEqual(spec.rows.filter((row) => row.status === 'approved').map((row) => row.id), ['A1', 'A2']);
- assert.equal(spec.rows.filter((row) => row.section === 'A · Web app').length, 12);
+ assert.equal(spec.rows.filter((row) => row.section === 'A · Web app').length, 13);
+});
+
+test('bundled blueprint rows carry their checks [S1,I1]', async () => {
+ // Imported here so the file's import lines stay as they are for the items editing them now.
+ const { questionText, ruleText, saveBlueprint } = await import('../src/blueprints.js');
+ const rule = (blueprint, key) => blueprint.rules.find((entry) => entry.key === key);
+ const library = readBlueprint('library', process.cwd());
+ const reliability = readBlueprint('test-reliability', process.cwd());
+ const web = readBlueprint('web-app', process.cwd());
+
+ // library: a row for the changelog its summary promises, with a reason and a gate.
+ assert.match(library.summary, /changelog/u);
+ const changelog = library.rules.filter((entry) => /\bchangelog\b/u.test(entry.text));
+ assert.equal(changelog.length, 1, 'library files one rule for the changelog it promises');
+ assert.ok(changelog[0].why.trim() && changelog[0].gate.trim(), 'the changelog rule gives a reason and names a gate');
+
+ // LIB1 and LIB2 carry a machine check: a test file their own starter's check runs, not review.
+ for (const key of ['LIB1', 'LIB2']) {
+ const { gate } = rule(library, key);
+ assert.match(gate, /^test\/[\w.-]+\.test\.js$/u, `${key} names a test file as its gate, a machine check`);
+ assert.ok(library.items.some((item) => item.cites.includes(key) && item.check.includes(gate)), `${key}'s gate is a test its own starter's check runs`);
+ }
+ // LIB1 keeps its card text and says what holds before 1.0.
+ assert.equal(rule(library, 'LIB1').text, 'A breaking change bumps the major version.');
+ assert.match(ruleText(rule(library, 'LIB1')), /before 1\.0[^.]*\bminor\b/u, 'LIB1 says a breaking change bumps the minor version before 1.0');
+
+ // test-reliability: a flake fix is proven by repeated runs, with a question for the run count.
+ const proven = reliability.rules.find((entry) => entry.text === 'A flake fix is proven by repeated runs.');
+ assert.ok(proven, 'test-reliability carries "A flake fix is proven by repeated runs."');
+ assert.match(proven.gate, /\brun\b.*\bin a row\b/u, 'the flake-fix rule is gated on the repeated runs themselves');
+ const runs = reliability.questions.find((entry) => /\bruns in a row\b/u.test(entry.ask));
+ assert.ok(runs, 'test-reliability asks how many runs in a row prove a flake fix');
+ assert.ok(runs.choices.length <= 12 && runs.choices.every((choice) => /^\d+$/u.test(choice)), 'the run count choices are whole numbers, 12 or fewer');
+ assert.match(proven.gate, /run count question/u, 'the flake-fix gate points at the run count question');
+
+ // web-app: its tests bind a local port, so a sandboxed agent asks the person, never rewrites them.
+ const port = web.rules.filter((entry) => /\blocal port\b/u.test(entry.text));
+ assert.equal(port.length, 1, 'web-app says its tests bind a local port');
+ assert.match(port[0].text, /sandbox[^.]*asks the person instead of rewriting the tests/u, 'a sandboxed agent asks the person instead of rewriting the tests');
+
+ // Every row marked must names a gate, in every bundled file, so an approved row passes spec check.
+ for (const name of bundledBlueprints()) {
+ const raw = JSON.parse(readFileSync(resolve(import.meta.dirname, `../src/blueprints/${name}.json`), 'utf8'));
+ for (const entry of raw.rules ?? []) {
+ if (entry.tier !== 'must') continue;
+ assert.ok(typeof entry.gate === 'string' && entry.gate.trim(), `${name} ${entry.key} is marked must and names a gate`);
+ assert.doesNotMatch(entry.gate, UNSAFE_CHECK, `${name} ${entry.key}'s gate runs nothing unsafe`);
+ }
+ }
+
+ // The new and changed rows round-trip through blueprint save exactly as written. Save keeps a
+ // question only when its row reads back one way, so the run count's default sits between choices.
+ const rows = [
+ ...[rule(library, 'LIB1'), rule(library, 'LIB2'), changelog[0], proven, port[0]].map((entry, index) => `- R${index + 1} [approved, must] ${ruleText(entry)} | gate: review`),
+ `- R9 [approved, must] ${questionText(runs)} | gate: review`,
+ ];
+ const saved = saveBlueprint(parseSpec(`# Spec\n\n## R · Rows\n\n${rows.join('\n')}\n`), { names: [] });
+ assert.deepEqual(saved.left, [], 'no new or changed row is left out of a save');
+ assert.deepEqual(saved.blueprint.questions.map(({ ask, choices, default: answer }) => ({ ask, choices, default: answer })), [{ ask: runs.ask, choices: runs.choices, default: runs.default }]);
+ assert.equal(saved.blueprint.rules.length, 5);
});
test('blueprint add files a blueprint as drafts after an add stopped part way [S1,I1]', () => {