Skip to content

Commit 7ac4f50

Browse files
committed
fix(runtime): the organization-ownership boot refusals say what 18.0 supports and name no step of the withdrawn ceremony command
In 18.0, os migrate organization-ownership refuses plan and apply on every database. Three branches of the v18 boot refusal (the v17 shape, the no-column marker branch, and the failed column read) still prescribed its --out PLAN / --apply --plan-file PLAN --backup-taken steps. Each now closes on the sentence os migrate apply's drop gate and os dev already use: 18.0 supports fresh installs only and does not upgrade a v17 database; keep a v17 database on a 17.x release until the 18.x release that carries the upgrade path. An unreadable marker or column read says to fix the read first. Refusal text only: the refusal code, the refused tables and the boot outcome do not move. The unit and kernel pins and the dogfood step-1 pin that named the command are updated, with one pin per branch asserting the sentence and the absence of the command's steps. Claude-Session: https://claude.ai/code/session_01SYEJqDL3NXxrJRBVqaMu9T Co-authored-by: Claude <noreply@anthropic.com>
1 parent bfc1539 commit 7ac4f50

5 files changed

Lines changed: 164 additions & 55 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/runtime': patch
3+
---
4+
5+
fix(runtime): the organization-ownership boot refusals say what 18.0 supports for a v17 database and name no step of `os migrate organization-ownership`, which 18.0 refuses on every database
6+
7+
Clause-②: no (refusal text only: the refusal code `ORGANIZATION_OWNERSHIP_MIGRATION_REQUIRED`, the refused tables and the boot outcome do not move)
8+
9+
In 18.0, `os migrate organization-ownership` refuses plan and apply on every database (`NOT_IMPLEMENTED`): 18.0 supports fresh installs only. Three branches of the v18 boot refusal still told the operator to run that command's plan and its `--apply --plan-file PLAN --backup-taken`, so following them led to a second refusal.
10+
11+
Each branch now closes on the sentence `os migrate apply`'s drop gate and `os dev` already use: "18.0 supports fresh installs only and does not upgrade a v17 database: keep a v17 database on a 17.x release until the 18.x release that carries the upgrade path, and upgrade it there."
12+
13+
- **A table still in the v17 shape** (an object that declares no organization column, over a table that still carries `organization_id`). This branch already said that 18.0 does not upgrade a v17 database. It no longer follows that with the command's plan and apply steps.
14+
- **No table left in the v17 shape, and the ceremony's marker is not verified.** The refusal no longer prescribes a re-plan and a re-apply, which 18.0 cannot run.
15+
- **No table left in the v17 shape, and the marker could not be read.** The refusal now says to fix the read and start again: a database no ceremony ran on boots once the read answers. It no longer prescribes a re-plan and a re-apply.
16+
- **The column read itself failed.** The refusal still says to fix the read. It no longer offers the command as the alternative.
17+
18+
A development boot (`OrganizationOwnershipBootGuardPlugin({ dev: true })`, as `os serve --dev` composes it) says "a v17 development database" in place of "a v17 database". Before, it named the command with `--dev`.

‎packages/qa/dogfood/test/organization-ownership-boot-refusal-order.dogfood.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
// that declare no organization column) still carrying a physical
1717
// `organization_id`:
1818
//
19-
// 1. the v18 boot is refused, naming the command — and the refused boot has
19+
// 1. the v18 boot is refused, saying what 18.0 supports for a v17 database and
20+
// naming no step of the command 18.0 refuses — and the refused boot has
2021
// ALREADY added the column the ceremony waits for: the guard judges in its
2122
// own `start()`, after the engine's `start()`, which is where the schema
2223
// sync runs (and before every plugin that writes rows at start, so the
@@ -109,7 +110,7 @@ describe('[ADR-0131 D10 item 5] a 17.x database upgrades through the boot refusa
109110
rmSync(dir, { recursive: true, force: true });
110111
});
111112

112-
it('1. a v17-shape database is refused, naming the command', async () => {
113+
it('1. a v17-shape database is refused, saying what 18.0 supports and naming no step of the refused command', async () => {
113114
const seed = new DatabaseSync(file);
114115
seed.exec(`
115116
CREATE TABLE sys_user_permission_set (id TEXT PRIMARY KEY, user_id TEXT, permission_set_id TEXT, organization_id TEXT);
@@ -121,7 +122,8 @@ describe('[ADR-0131 D10 item 5] a 17.x database upgrades through the boot refusa
121122

122123
refusal = refusalIn(await boot(file));
123124
expect(refusal, 'the boot was refused for the v17 shape').toBeDefined();
124-
expect(String((refusal as Error).message)).toContain('os migrate organization-ownership');
125+
expect(String((refusal as Error).message)).toContain('18.0 supports fresh installs only and does not upgrade a v17 database');
126+
expect(String((refusal as Error).message)).not.toMatch(/os migrate organization-ownership|--plan-file|--out PLAN|--backup-taken/);
125127
expect((refusal as { tables?: string[] }).tables).toEqual(expect.arrayContaining(['sys_metadata', 'sys_migration_journal']));
126128
}, 240_000);
127129

‎packages/runtime/src/organization-ownership-boot-guard.kernel.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
* 3. a fresh database boots;
1717
* 4. a database the ceremony ran on to the end (no column left) whose marker
1818
* is NOT verified — its post-check found rows still without their
19-
* organization — is refused, naming the re-run;
19+
* organization — is refused, saying what 18.0 supports (it cannot re-run
20+
* the ceremony);
2021
* 5. ⭐ a refused boot writes nothing: the plugins that write rows in their
2122
* own `start()` — `AppPlugin` (the inline seed) and plugin-auth's
2223
* identity-objects plugin (the Default Organization, `AuthPlugin`'s twin
@@ -181,7 +182,7 @@ describe('the v18 boot refusal on a real kernel (ADR-0131 D10 item 5)', () => {
181182
await expect(engine.findOne('sys_migration', { where: { id: MARKER }, context: { isSystem: true } })).resolves.toBeNull();
182183
});
183184

184-
it('⭐ a ceremony that ran every step and did not verify (no v17 column left, marker unverified) is refused, naming the re-run', async () => {
185+
it('⭐ a ceremony that ran every step and did not verify (no v17 column left, marker unverified) is refused, saying what 18.0 supports', async () => {
185186
const file = databaseFile();
186187
const db = new DatabaseSync(file);
187188
writeMarker(db, null, 602);
@@ -191,7 +192,10 @@ describe('the v18 boot refusal on a real kernel (ADR-0131 D10 item 5)', () => {
191192
expect(refusal?.code, String(error)).toBe(ORGANIZATION_OWNERSHIP_BOOT_REFUSAL_CODE);
192193
expect(refusal?.tables).toEqual([]);
193194
expect(refusal?.message).toMatch(/^The organization-ownership ceremony has not finished on this database: its marker/);
194-
expect(refusal?.message).toContain("os migrate organization-ownership --apply --plan-file PLAN --backup-taken");
195+
// 18.0 cannot re-run the ceremony (its `os migrate organization-ownership` refuses on every
196+
// database), so the refusal names no step of it and says what 18.0 supports instead.
197+
expect(refusal?.message).toContain('18.0 supports fresh installs only and does not upgrade a v17 database');
198+
expect(refusal?.message).not.toMatch(/os migrate organization-ownership|--plan-file|--out PLAN|--backup-taken/);
195199
expect(kernel.getState()).not.toBe('running');
196200
});
197201

‎packages/runtime/src/organization-ownership-boot-guard.test.ts‎

Lines changed: 98 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ const marker = (verifiedAt: string | null, blocking = 0): void => {
6868
);
6969
};
7070

71+
/**
72+
* What 18.0 supports for a v17 database: the sentence every refusal closes on,
73+
* in the words `@objectstack/cli`'s other 18.0 refusals use (the drop gate of
74+
* `os migrate apply`; `os dev`'s way on for a development database).
75+
*/
76+
const FRESH_INSTALLS_ONLY =
77+
'18.0 supports fresh installs only and does not upgrade a v17 database: keep a v17 database on a 17.x release ' +
78+
'until the 18.x release that carries the upgrade path, and upgrade it there.';
79+
const FRESH_INSTALLS_ONLY_DEV =
80+
'18.0 supports fresh installs only and does not upgrade a v17 database: keep a v17 development database on a ' +
81+
'17.x release until the 18.x release that carries the upgrade path, and upgrade it there.';
82+
/** `os migrate organization-ownership` refuses on every database in 18.0: no refusal names it or a step of it. */
83+
const WITHDRAWN_COMMAND = /os migrate organization-ownership|--plan-file|--out PLAN|--backup-taken/;
84+
85+
/** The message closes on `tail` (compared as a string, so a failure shows the diff). */
86+
function expectTail(message: string, tail: string): void {
87+
expect(message.slice(-tail.length)).toBe(tail);
88+
}
89+
7190
async function refusalOf(run: () => Promise<unknown>): Promise<any> {
7291
try {
7392
await run();
@@ -85,32 +104,26 @@ afterEach(() => {
85104
});
86105

87106
describe('the v18 boot refusal (ADR-0131 D10 item 5)', () => {
88-
it('⭐ a v17-shape database is refused, naming the command and every table still carrying the column', async () => {
107+
it('⭐ a v17-shape database is refused, naming every table still carrying the column', async () => {
89108
v17Shape();
90109
const err = await refusalOf(() => assertOrganizationOwnershipMigrated(engine()));
91110
expect(isOrganizationOwnershipBootRefusal(err)).toBe(true);
92111
expect(err.code).toBe(ORGANIZATION_OWNERSHIP_BOOT_REFUSAL_CODE);
93112
expect(err.tables).toEqual(['sys_job', 'sys_metadata']);
94113
expect(err.message).toMatch(/still in the v17 organization-ownership shape: sys_job, sys_metadata/);
95-
// The apply the refusal names is one the ceremony accepts: a reviewed plan file and the backup acknowledged.
96-
expect(err.message).toMatch(/os migrate organization-ownership --apply --plan-file PLAN --backup-taken/);
97114
expect(err.message).toMatch(/the ceremony has not run on it/);
98-
// In 18.0 the command it names refuses too, so the refusal names the release answer itself, ahead of the command.
99-
const release = err.message.indexOf('18.0 does not upgrade a v17 database');
100-
expect(release).toBeGreaterThan(-1);
101-
expect(err.message.indexOf('17.x release until the 18.x release', release)).toBeGreaterThan(release);
102-
expect(release).toBeLessThan(err.message.indexOf("Run 'os migrate organization-ownership --out PLAN'"));
115+
// What it prescribes is pinned per branch below: what 18.0 supports, and no step of the withdrawn command.
103116
});
104117

105-
it('a development boot names the ceremony with --dev, so it boots the way the refused boot did', async () => {
118+
it('a development boot speaks of a development database, as os dev does; a served boot does not', async () => {
106119
v17Shape();
107120
const dev = await refusalOf(() => assertOrganizationOwnershipMigrated(engine(), undefined, { dev: true }));
108-
expect(dev.message).toContain(
109-
"Run 'os migrate organization-ownership --dev --out PLAN' to write and review its plan, take a backup, then run " +
110-
"'os migrate organization-ownership --dev --apply --plan-file PLAN --backup-taken'",
111-
);
121+
expect(dev.message).toContain(FRESH_INSTALLS_ONLY_DEV);
122+
expect(dev.message).not.toMatch(WITHDRAWN_COMMAND);
123+
expect(dev.message).not.toContain('--dev');
112124
const served = await refusalOf(() => assertOrganizationOwnershipMigrated(engine()));
113-
expect(served.message).not.toContain('--dev');
125+
expect(served.message).toContain(FRESH_INSTALLS_ONLY);
126+
expect(served.message).not.toContain('development');
114127
});
115128

116129
it('a marker that is not verified (an unfinished ceremony, or one whose post-check found discrepancies) is refused', async () => {
@@ -152,10 +165,6 @@ describe('the v18 boot refusal (ADR-0131 D10 item 5)', () => {
152165
expect(err.code).toBe(ORGANIZATION_OWNERSHIP_BOOT_REFUSAL_CODE);
153166
expect(err.tables).toEqual([]);
154167
expect(err.message).toMatch(/^The organization-ownership ceremony has not finished on this database: its marker \(sys_migration 'adr-0131-organization-ownership'\) is not verified/);
155-
expect(err.message).toContain(
156-
"Resolve what the apply report names, then run 'os migrate organization-ownership --out PLAN' again, review it, run " +
157-
"'os migrate organization-ownership --apply --plan-file PLAN --backup-taken', and start again.",
158-
);
159168
// A verified_at with blocking left is not verified either (`isDataMigrationFlagVerified`).
160169
db.exec('DELETE FROM sys_migration');
161170
marker('2026-10-14T01:00:00Z', 3);
@@ -250,4 +259,75 @@ describe('the v18 boot refusal (ADR-0131 D10 item 5)', () => {
250259
process.env = saved;
251260
}
252261
});
262+
263+
// 18.0 supports fresh installs only, and its `os migrate organization-ownership`
264+
// refuses on every database, plan and apply alike. One pin per refusal branch:
265+
// each closes on what 18.0 supports for a v17 database and names no step of that
266+
// command. The code and the outcome (refused) are the ones the pins above hold.
267+
describe('18.0: each branch says what 18.0 supports for a v17 database, and names no step of the withdrawn command', () => {
268+
const unreadableMarker = () => ({ ...engine(), findOne: async () => { throw new Error('SQLITE_BUSY: database is locked'); } });
269+
270+
it('⭐ the v17 shape (a table still carries the column), whatever the marker says', async () => {
271+
v17Shape();
272+
const absent = await refusalOf(() => assertOrganizationOwnershipMigrated(engine()));
273+
marker(null);
274+
const unverified = await refusalOf(() => assertOrganizationOwnershipMigrated(engine()));
275+
const unreadable = await refusalOf(() => assertOrganizationOwnershipMigrated(unreadableMarker()));
276+
expect([absent, unverified, unreadable].map((e) => e.tables)).toEqual([
277+
['sys_job', 'sys_metadata'], ['sys_job', 'sys_metadata'], ['sys_job', 'sys_metadata'],
278+
]);
279+
for (const err of [absent, unverified, unreadable]) {
280+
expect(err.code).toBe(ORGANIZATION_OWNERSHIP_BOOT_REFUSAL_CODE);
281+
expectTail(err.message, `The server refuses to start rather than serve v17 data with v18 semantics. ${FRESH_INSTALLS_ONLY}`);
282+
expect(err.message).not.toMatch(WITHDRAWN_COMMAND);
283+
}
284+
});
285+
286+
it('⭐ a ceremony that ran every step and did not verify (no column left): 18.0 cannot re-run it', async () => {
287+
migrated();
288+
marker(null, 602);
289+
const err = await refusalOf(() => assertOrganizationOwnershipMigrated(engine()));
290+
expect(err.code).toBe(ORGANIZATION_OWNERSHIP_BOOT_REFUSAL_CODE);
291+
expectTail(err.message, `rather than serve rows of an organization-owned object with no organization. ${FRESH_INSTALLS_ONLY}`);
292+
expect(err.message).not.toMatch(WITHDRAWN_COMMAND);
293+
});
294+
295+
it('⭐ a ceremony marker that could not be read (no column left): fix the read first', async () => {
296+
migrated();
297+
const err = await refusalOf(() => assertOrganizationOwnershipMigrated(unreadableMarker()));
298+
expect(err.code).toBe(ORGANIZATION_OWNERSHIP_BOOT_REFUSAL_CODE);
299+
expect(err.message).toMatch(/its marker \(sys_migration 'adr-0131-organization-ownership'\) could not be read/);
300+
expectTail(err.message, `Fix the read, then start again. ${FRESH_INSTALLS_ONLY}`);
301+
expect(err.message).not.toMatch(WITHDRAWN_COMMAND);
302+
});
303+
304+
it('⭐ a column read that failed: fix the read first', async () => {
305+
v17Shape();
306+
const err = await refusalOf(() => assertOrganizationOwnershipMigrated(engine({ failRead: true })));
307+
expect(err.code).toBe(ORGANIZATION_OWNERSHIP_BOOT_REFUSAL_CODE);
308+
expect(err.tables).toEqual([]);
309+
expect(err.message).toContain('(SQLITE_BUSY: database is locked)');
310+
expectTail(err.message, `Fix the read, then start again. ${FRESH_INSTALLS_ONLY}`);
311+
expect(err.message).not.toMatch(WITHDRAWN_COMMAND);
312+
});
313+
314+
it('a development boot says the same of a development database in every branch, and names no --dev command', async () => {
315+
const dev = { dev: true };
316+
v17Shape();
317+
const shape = await refusalOf(() => assertOrganizationOwnershipMigrated(engine(), undefined, dev));
318+
const columnRead = await refusalOf(() => assertOrganizationOwnershipMigrated(engine({ failRead: true }), undefined, dev));
319+
db.close();
320+
db = new DatabaseSync(':memory:');
321+
migrated();
322+
const markerRead = await refusalOf(() => assertOrganizationOwnershipMigrated(unreadableMarker(), undefined, dev));
323+
marker(null, 602);
324+
const rerun = await refusalOf(() => assertOrganizationOwnershipMigrated(engine(), undefined, dev));
325+
for (const err of [shape, columnRead, markerRead, rerun]) {
326+
expect(err.code).toBe(ORGANIZATION_OWNERSHIP_BOOT_REFUSAL_CODE);
327+
expectTail(err.message, FRESH_INSTALLS_ONLY_DEV);
328+
expect(err.message).not.toMatch(WITHDRAWN_COMMAND);
329+
expect(err.message).not.toContain('--dev');
330+
}
331+
});
332+
});
253333
});

0 commit comments

Comments
 (0)