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.

docs: verify in-place format upgrades

Corey Olson2a05be6044f5
diff --git a/docs/formats.md b/docs/formats.md
index d59cf884..b802279a 100644
--- a/docs/formats.md
+++ b/docs/formats.md
@@ -67,12 +67,26 @@ The board file is in the repository's Git common directory at `.git/pullboard/bo
| Format | Version | Version source | Upgrade rule |
| --- | --- | --- | --- |
| `CLI JSON envelope` | `1` | `JSON_SHAPES.version` in `src/json.js` | Keep optional fields additive within version 1; bump the envelope version for incompatible command/export shapes. |
-| `row grammar` | `1` | `SPEC_GRAMMAR_VERSION` in `src/spec.js`; optional `<!-- pullboard-grammar N -->` line in either file (absence means 1) | Both files share the version. A declared version must match; an incompatible grammar change requires a coordinated version bump and compatible files. No automatic conversion occurs. |
+| `row grammar` | `1` | `SPEC_GRAMMAR_VERSION` in `src/spec.js`; optional `<!-- pullboard-grammar N -->` line in either file (absence means the current grammar) | Both files share the version. A declared version must match; an incompatible grammar change requires a coordinated version bump and compatible files. No automatic conversion occurs. |
| `board schema` | `2` | `SCHEMA_VERSION` in `src/board.js`, persisted as `PRAGMA user_version` | Create missing tables and indexes, add missing columns in place with declared defaults, restore missing or changed triggers, and remove stale machine triggers without replacing rows. |
| `event log` | `1` | `EVENT_LOG_VERSION` in `src/board.js`; event rows do not store a separate version marker | This append-only record format has its own version, independent of `SCHEMA_VERSION`. Preserve event rows when the board schema changes. |
<!-- format-versions:end -->
-On open, Pullboard creates missing tables and indexes, then adds each missing column with `ALTER TABLE ... ADD COLUMN` and its declared default; it does not replace the board file or existing rows. It restores missing or changed declared triggers and removes stale `machine_` triggers. A board that already has its guard marker records trigger repair in a `guards` event, including missing, changed and stale trigger names; an older board receives the current marker after installation. Existing event rows are preserved.
+The in-place upgrade behavior is exercised by `exerciseUpgrade` in `docs/formats.test.js`:
+
+<!-- upgrade-rules:start -->
+| Older board condition | Behavior when opened |
+| --- | --- |
+| Missing declared tables or indexes | Create them with `CREATE ... IF NOT EXISTS`. |
+| Missing declared columns | Add each with `ALTER TABLE ... ADD COLUMN` and its declared default. |
+| Missing or changed declared triggers | Install the declared trigger definitions. |
+| Undeclared `machine_` triggers | Drop them as stale. |
+| A board that previously had guard triggers | Append a `guards` event listing missing, changed and stale trigger names. |
+| An older schema version | Set `PRAGMA user_version` to the current `SCHEMA_VERSION` after installation. |
+| Existing rows and event history | Keep them in the same board file; guard repair may append its `guards` event. |
+<!-- upgrade-rules:end -->
+
+An older board that has not yet recorded its guard marker receives the current triggers and marker quietly. `openBoard` does not replace the board file or existing rows.
The following live SQLite declarations include nullability, defaults, primary and unique keys, and foreign keys:
diff --git a/docs/formats.test.js b/docs/formats.test.js
index 87e0946b..93b54f39 100644
--- a/docs/formats.test.js
+++ b/docs/formats.test.js
@@ -127,6 +127,14 @@ function documentedIndexes() {
});
}
+/** List the documented in-place upgrade conditions exercised by exerciseUpgrade. */
+function documentedUpgradeConditions() {
+ return block('<!-- upgrade-rules:start -->', '<!-- upgrade-rules:end -->').split(/\r?\n/).flatMap((line) => {
+ const row = /^\| (.+) \| (.+) \|$/.exec(line);
+ return row && row[1] !== 'Older board condition' && row[1] !== '---' ? [[row[1], row[2]]] : [];
+ });
+}
+
/** Exercise each board event through the public API and return the rows it actually records. */
function recordEventContract() {
const board = openBoard(':memory:');
@@ -193,7 +201,7 @@ function exerciseUpgrade() {
board = null;
const old = new DatabaseSync(file);
- old.exec('ALTER TABLE shout DROP COLUMN shout_evidence_kind; DROP TABLE hold; DROP INDEX item_lane_status; DROP TRIGGER machine_event_update; CREATE TRIGGER machine_old_extra AFTER INSERT ON item BEGIN SELECT 1; END; PRAGMA user_version = 1;');
+ old.exec("ALTER TABLE shout DROP COLUMN shout_evidence_kind; DROP TABLE hold; DROP INDEX item_lane_status; DROP TRIGGER machine_event_delete; DROP TRIGGER machine_event_update; CREATE TRIGGER machine_event_update AFTER DELETE ON event BEGIN SELECT 1; END; CREATE TRIGGER machine_old_extra AFTER INSERT ON item BEGIN SELECT 1; END; PRAGMA user_version = 1;");
old.close();
board = openBoard(file);
@@ -202,11 +210,12 @@ function exerciseUpgrade() {
assert.ok(board.db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'hold'").get());
assert.ok(board.db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'index' AND name = 'item_lane_status'").get());
assert.equal(board.db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'trigger' AND name = 'machine_old_extra'").get(), undefined);
+ assert.equal(board.db.prepare('PRAGMA user_version').get().user_version, SCHEMA_VERSION);
const repair = events(board).find((row) => row.event_kind === 'guards');
assert.ok(repair, 'reopening reports repaired/missing/stale guards in the event log');
assert.equal(events(board).length, originalEvents + 1, 'reopening preserves old events and appends one guard-repair event');
assert.deepEqual(JSON.parse(repair.event_detail), {
- missing: ['machine_event_update'], changed: [], stale: ['machine_old_extra'],
+ missing: ['machine_event_delete'], changed: ['machine_event_update'], stale: ['machine_old_extra'],
});
return events(board).map((row) => ({ ...row, detail: JSON.parse(row.event_detail) }));
} finally {
@@ -299,6 +308,15 @@ test('[A5] schema, versions, event kinds and event detail fields match live beha
assert.deepEqual(documentedTriggers('<!-- board-triggers:start -->', '<!-- board-triggers:end -->'), liveTriggers(board.db, 'main'));
assert.deepEqual(documentedTriggers('<!-- temp-triggers:start -->', '<!-- temp-triggers:end -->'), liveTriggers(board.db, 'temp'));
assert.deepEqual(documentedIndexes(), liveIndexes(board.db));
+ assert.deepEqual(documentedUpgradeConditions(), [
+ ['Missing declared tables or indexes', 'Create them with `CREATE ... IF NOT EXISTS`.'],
+ ['Missing declared columns', 'Add each with `ALTER TABLE ... ADD COLUMN` and its declared default.'],
+ ['Missing or changed declared triggers', 'Install the declared trigger definitions.'],
+ ['Undeclared `machine_` triggers', 'Drop them as stale.'],
+ ['A board that previously had guard triggers', 'Append a `guards` event listing missing, changed and stale trigger names.'],
+ ['An older schema version', 'Set `PRAGMA user_version` to the current `SCHEMA_VERSION` after installation.'],
+ ['Existing rows and event history', 'Keep them in the same board file; guard repair may append its `guards` event.'],
+ ]);
const versions = block('<!-- format-versions:start -->', '<!-- format-versions:end -->');
const versionOf = (name) => {
const match = new RegExp('^\\| `' + name + '` \\| `(\\d+)` \\|', 'm').exec(versions);