Skip to content

Commit d272b23

Browse files
committed
test(dogfood): sys_notification_preference's organization unique is runtime-managed now, like sys_setting's
The metadata protocol's kernel:ready migration rebuilds it over (organization_id, COALESCE(user_id, ''), topic, channel) on every boot, so the 18.0 COALESCE-organization spelling does not survive a HEAD boot; the byte-for-byte pins exclude it the way they exclude sys_setting's. Claude-Session: https://claude.ai/code/session_01UnHcTADjeg3VwxF21QHj7W Co-authored-by: Claude <noreply@anthropic.com>
1 parent f7ad7e7 commit d272b23

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

‎packages/qa/dogfood/test/upgrade-18x-index-equivalence.dogfood.test.ts‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ import { relaxTenantColumns } from './pre-18-tenant-column.testkit.js';
3434

3535
const fixtureSql = readFileSync(new URL('./upgrade-harness/fixture-18.0/database.sql', import.meta.url), 'utf8');
3636

37+
/**
38+
* The organization uniques a `kernel:ready` migration in `metadata-protocol`
39+
* rebuilds on every boot (runtime-managed, ADR-0120 D4), so no boot leaves
40+
* their 18.0 spelling in place: `sys_setting`'s identity index, and
41+
* `sys_notification_preference`'s, NULL-safe on `user_id`.
42+
*/
43+
const RUNTIME_MANAGED_TABLES = new Set(['sys_setting', 'sys_notification_preference']);
44+
const RUNTIME_MANAGED_INDEX = /^uniq_(sys_setting_|sys_notification_preference_)/;
45+
3746
/** One unique index of the file, as SQLite recorded its DDL. */
3847
interface UniqueIndex {
3948
name: string;
@@ -166,12 +175,14 @@ describe('[18.x step 7b] the organization key part across the 18.0 → HEAD upgr
166175
expectNoDestructiveIndexDrift(await managedDrift(stack!));
167176
});
168177

169-
it('the 12 declared organization composites survive the HEAD boot byte for byte', () => {
170-
// `sys_setting`'s identity index is the thirteenth: the metadata
171-
// protocol's own runtime migration rebuilds it on every boot, now over
172-
// the plain organization key.
173-
const declared = COALESCE_INDEXES_18_0.filter((i) => !i.name.startsWith('uniq_sys_setting_'));
174-
expect(declared).toHaveLength(12);
178+
it('the 11 declared organization composites survive the HEAD boot byte for byte', () => {
179+
// The other two are runtime-managed: the metadata protocol's own
180+
// migrations rebuild them on every boot over the plain organization key —
181+
// `sys_setting`'s identity index, and `sys_notification_preference`'s
182+
// one-global-default-per-key index, NULL-safe on its `user_id` (an empty
183+
// User is the admin-global default, ADR-0118 D1).
184+
const declared = COALESCE_INDEXES_18_0.filter((i) => !RUNTIME_MANAGED_INDEX.test(i.name));
185+
expect(declared).toHaveLength(11);
175186
const after = new Map(organizationUniqueIndexes(restored).map((i) => [i.name, i.sql]));
176187
for (const index of declared) expect(after.get(index.name), index.name).toBe(index.sql);
177188
});
@@ -197,10 +208,10 @@ describe('[18.x step 7b] the organization key part across the 18.0 → HEAD upgr
197208
try {
198209
const ql = (await first.kernel.getServiceAsync('objectql')) as { getDriverForObject(object: string): unknown };
199210
// The tables whose organization unique 18.0.0 keyed through COALESCE —
200-
// the ones whose equivalence is under test. (`sys_setting`'s identity
201-
// index is its runtime migration's, rebuilt every boot.)
211+
// the ones whose equivalence is under test. (The runtime-managed
212+
// indexes are their migrations', rebuilt every boot.)
202213
const tenantTables = [
203-
...new Set(organizationUniqueIndexes(born).map((i) => i.table).filter((t) => t !== 'sys_setting')),
214+
...new Set(organizationUniqueIndexes(born).map((i) => i.table).filter((t) => !RUNTIME_MANAGED_TABLES.has(t))),
204215
];
205216
await relaxTenantColumns(ql, tenantTables);
206217
} finally {
@@ -209,8 +220,8 @@ describe('[18.x step 7b] the organization key part across the 18.0 → HEAD upgr
209220
const db = new DatabaseSync(born);
210221
try {
211222
for (const index of organizationUniqueIndexes(born)) {
212-
// `sys_setting`'s identity index is its runtime migration's, rebuilt every boot.
213-
if (index.table === 'sys_setting') continue;
223+
// A runtime-managed index is its migration's, rebuilt every boot.
224+
if (RUNTIME_MANAGED_TABLES.has(index.table)) continue;
214225
const sql = index.sql.replace(/\(\s*([`"]?)organization_id\1\s*([,)])/, "(COALESCE($1organization_id$1, '__global__')$2")
215226
.replace(/,\s*([`"]?)organization_id\1\s*([,)])/, ", COALESCE($1organization_id$1, '__global__')$2");
216227
if (sql === index.sql) continue;

0 commit comments

Comments
 (0)