diff --git a/packages/bus/tests/session-compactions.test.mjs b/packages/bus/tests/session-compactions.test.mjs index bde15c282..4493d1d70 100644 --- a/packages/bus/tests/session-compactions.test.mjs +++ b/packages/bus/tests/session-compactions.test.mjs @@ -1,14 +1,18 @@ import test from 'node:test'; import assert from 'node:assert/strict'; -import { mkdtempSync, rmSync } from 'node:fs'; +import { randomUUID } from 'node:crypto'; +import { mkdtempSync, readFileSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; +import { fileURLToPath } from 'node:url'; import { Store } from '../src/store.mjs'; import { Broker } from '../src/broker.mjs'; // Row 270 (264c, #1775, T1 item 7 D6): session.list's `compactions` key, from the host's ledger // reader (runtime.mjs gives the seat's compactionCount). The reader itself is // packages/seat/tests/compactions.test.mjs's. +const shipped = (name) => + JSON.parse(readFileSync(fileURLToPath(new URL(`../../../roles/${name}.json`, import.meta.url)), 'utf8')); const businesses = { demo: { id: 'demo', @@ -16,9 +20,10 @@ const businesses = { arbiters: { technical: 'pm', delivery: 'chief' }, roles: { chief: { definition: 'chief-of-staff', authority: { withinRole: ['message.send'], crossRole: [] } }, + assistant: { definition: 'assistant', authority: { withinRole: ['message.send'], crossRole: [] } }, pm: { definition: 'pm', authority: { withinRole: ['message.send'], crossRole: [] } }, }, - definitions: { 'chief-of-staff': {}, pm: {} }, + definitions: { 'chief-of-staff': {}, assistant: { messaging: shipped('assistant').messaging }, pm: {} }, projects: { stack: { root: '/nonexistent' } }, }, }; @@ -35,7 +40,7 @@ function setup(t, options = {}) { const call = (verb, args = {}) => b.request(human, { verb, args }); const project = call('project.create', { name: 'stack work', repo: 'stack' }).id; const A = call('thread.create', { project, name: 'alpha' }).id; - return { store, call, A }; + return { store, call, project, A }; } test('session.list rows carry the reader count for each session, with its store identity', (t) => { @@ -56,13 +61,19 @@ test('session.list rows carry the reader count for each session, with its store assert.ok(rows.every((r) => !('op' in r))); }); -// A legacy session (op legacy-3l, from the 3k-3l migration) keeps the thread's store. +// A legacy session (op legacy-3l, from the 3k-3l migration, its id the thread's) keeps the +// thread's store. The thread is made by hand with the session the migration gives it, as +// message-filter.test.mjs does; sessions is append-only. test('a legacy session is asked for with legacy true', (t) => { const asked = []; const f = setup(t, { compactions: (q) => (asked.push(q), { count: 0, known: true, reason: null, at: null }) }); - f.store.run("UPDATE sessions SET op='legacy-3l' WHERE thread=?", f.A); - f.call('session.list', { thread: f.A }); - assert.deepEqual(asked.map((q) => q.legacy), [true]); + const L = randomUUID(); + const at = '2026-10-21T00:00:00.000Z'; + f.store.run('INSERT INTO threads(id,at,business,project,instance,owner,name) VALUES(?,?,?,?,?,?,?)', L, at, 'demo', f.project, 'assistant', 'jason', 'legacy'); + f.store.run("INSERT INTO sessions(at,business,thread,id,instance,owner,name,op) SELECT at,business,id,id,instance,owner,'default','legacy-3l' FROM threads WHERE id=?", L); + f.store.run("INSERT INTO session_defaults(at,thread,session,by) SELECT at,id,id,'migration-3l' FROM threads WHERE id=?", L); + f.call('session.list', { thread: L }); + assert.deepEqual(asked, [{ business: 'demo', thread: L, session: L, legacy: true }]); }); test('without a reader the count is unknown, never 0; a reader that throws is store-unreadable', (t) => {