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(core): report incomplete doctor layouts [A1,A6]

Corey Olsond7f2b69f7c17
diff --git a/src/doctor.js b/src/doctor.js
index b0766bbe..9540220d 100644
--- a/src/doctor.js
+++ b/src/doctor.js
@@ -21,11 +21,13 @@ export function doctorProblems(file, root, tryGit) {
try {
const schemaProblems = versionProblems(db);
if (schemaProblems.length) return schemaProblems;
+ const layout = layoutProblems(db);
return [
...triggerProblems(db),
- ...itemProblems(db),
- ...pinProblems(db, root, tryGit),
- ...verdictProblems(db, root, tryGit),
+ ...layout.problems,
+ ...(layout.itemFields ? itemProblems(db) : []),
+ ...(layout.itemPins ? pinProblems(db, root, tryGit) : []),
+ ...(layout.verdicts ? verdictProblems(db, root, tryGit) : []),
];
} finally {
db.close();
@@ -42,6 +44,35 @@ export function doctorProblems(file, root, tryGit) {
*/
const finding = (code, message, next) => ({ code, message, next });
+/** Inspect the layout before each row check, retaining trigger findings on an incomplete board. */
+function layoutProblems(db) {
+ const required = {
+ item: ['item_id', 'item_status', 'item_commit', ...new Set(STATES.flatMap((state) => state.requires))],
+ verdict: ['verdict_id', 'item_id', 'verdict_commit'],
+ };
+ const tables = new Set(db.prepare("SELECT name FROM sqlite_master WHERE type = 'table'").all().map((table) => table.name));
+ const columns = new Map();
+ const problems = [];
+ for (const [table, fields] of Object.entries(required)) {
+ if (!tables.has(table)) {
+ problems.push(finding('TABLE_MISSING', `board table ${table} is missing`, 'restore a consistent board backup, or run pullboard status to recreate the missing table'));
+ columns.set(table, new Set());
+ continue;
+ }
+ const present = new Set(db.prepare(`PRAGMA table_info(${table})`).all().map((column) => column.name));
+ columns.set(table, present);
+ const missing = fields.filter((field) => !present.has(field));
+ if (missing.length) problems.push(finding('COLUMN_MISSING', `board table ${table} is missing columns ${missing.join(', ')}`, 'restore a consistent board backup, then run pullboard status'));
+ }
+ const has = (table, fields) => fields.every((field) => columns.get(table).has(field));
+ return {
+ problems,
+ itemFields: has('item', ['item_id', 'item_status']),
+ itemPins: has('item', ['item_id', 'item_status', 'item_commit']),
+ verdicts: has('verdict', required.verdict),
+ };
+}
+
/**
* Report a schema version this executable cannot safely use.
*
diff --git a/src/json.js b/src/json.js
index 84169483..90331fb0 100644
--- a/src/json.js
+++ b/src/json.js
@@ -21,6 +21,7 @@ export const JSON_SHAPES = {
list: shape({ items: 'array' }),
show: shape({ item_id: 'number', item_title: 'string', item_lane: 'string', item_status: 'string', verdicts: 'array' }),
status: shape({ me: 'object', mine: 'array', stats: 'object', unread: 'number' }),
+ doctor: shape({ problems: 'array' }),
inbox: shape({ shouts: 'array' }),
decisions: shape({ decisions: 'array' }),
ledger: shape({ items: 'array', stats: 'object' }),
diff --git a/test/api.test.js b/test/api.test.js
index abc35bda..e5ac6efc 100644
--- a/test/api.test.js
+++ b/test/api.test.js
@@ -172,6 +172,7 @@ test('[A1] command results match the catalog across roots and subcommands', () =
json(box, repo, 'lanes');
json(box, repo, 'resume');
json(box, repo, 'status');
+ json(box, repo, 'doctor');
const plainStatus = box.run(repo, 'status');
assert.equal(plainStatus.status, 0, plainStatus.stderr);
assert.equal(plainStatus.stderr, '');
diff --git a/test/doctor.test.js b/test/doctor.test.js
index 170ec830..ddc832cc 100644
--- a/test/doctor.test.js
+++ b/test/doctor.test.js
@@ -170,3 +170,26 @@ test('doctor reports an older empty SQLite layout without querying current table
assert.doesNotMatch(result.stderr, /no such table|SQLITE_ERROR|Error:/);
assert.deepEqual(readFileSync(box.dbFile), before);
});
+
+test('doctor reports missing triggers on a current empty layout without changing it [A6]', () => {
+ const box = boardBox({ initialize: false });
+ const db = new DatabaseSync(box.dbFile);
+ db.exec('PRAGMA user_version = 1');
+ db.close();
+ const before = readFileSync(box.dbFile);
+ for (const flags of [[], ['--json']]) {
+ const result = box.run('doctor', ...flags);
+ assert.equal(result.status, 1);
+ assert.equal(result.stderr, '');
+ if (flags.length) {
+ const document = JSON.parse(result.stdout);
+ assert.equal(document.version, 1);
+ assert.ok(document.problems.some((problem) => problem.code === 'TRIGGER_MISSING' && problem.message.includes('machine_item_start') && problem.next === 'run pullboard status'));
+ assert.ok(document.problems.some((problem) => problem.code === 'TABLE_MISSING' && problem.message.includes('item') && problem.next.includes('pullboard status')));
+ } else {
+ assert.match(result.stdout, /machine_item_start is missing; repair: run pullboard status/);
+ assert.doesNotMatch(result.stdout, /no such table|Error:/);
+ }
+ assert.deepEqual(readFileSync(box.dbFile), before);
+ }
+});