This commit is contained in:
Storme-bit
2026-08-23 06:57:58 -07:00
parent 6c953a346a
commit 00101ba14a
3 changed files with 6 additions and 5 deletions
+4 -3
View File
@@ -4,7 +4,6 @@
// advance user_version correctly, and no-op when the DB is already current. // advance user_version correctly, and no-op when the DB is already current.
const { test } = require('node:test'); const { test } = require('node:test');
const assert = require('node:assert'); const assert = require('node:assert');
const Database = require('better-sqlite3');
const { migrate, LATEST_VERSION } = require('../packages/memory-service/src/db/migrations'); const { migrate, LATEST_VERSION } = require('../packages/memory-service/src/db/migrations');
// Emulates just the slice of the better-sqlite3 API that migrate() uses. // Emulates just the slice of the better-sqlite3 API that migrate() uses.
@@ -26,14 +25,16 @@ function fakeDb(startVersion = 0) {
test('a fresh DB (user_version 0) is stamped to LATEST_VERSION', () => { test('a fresh DB (user_version 0) is stamped to LATEST_VERSION', () => {
const db = fakeDb(0); const db = fakeDb(0);
const result = migrate(db); const stubs = Array.from({ length: LATEST_VERSION }, () => () => {});
const result = migrate(db, stubs); // inject no-op migrations
assert.strictEqual(result, LATEST_VERSION); assert.strictEqual(result, LATEST_VERSION);
assert.strictEqual(db.version, LATEST_VERSION); assert.strictEqual(db.version, LATEST_VERSION);
}); });
test('an already-current DB is a no-op (no version writes)', () => { test('an already-current DB is a no-op (no version writes)', () => {
const db = fakeDb(LATEST_VERSION); const db = fakeDb(LATEST_VERSION);
const result = migrate(db); const stubs = Array.from({ length: LATEST_VERSION }, () => () => {});
const result = migrate(stubs);
assert.strictEqual(result, LATEST_VERSION); assert.strictEqual(result, LATEST_VERSION);
assert.deepStrictEqual(db.setCalls, [], 'should not touch user_version when current'); assert.deepStrictEqual(db.setCalls, [], 'should not touch user_version when current');
}); });
+1 -1
View File
@@ -13,7 +13,7 @@ try { ({ DatabaseSync } = require('node:sqlite')); } catch { DatabaseSync = null
// The complete intended shape = original base tables + every historical ALTER. // The complete intended shape = original base tables + every historical ALTER.
const EXPECTED = { const EXPECTED = {
sessions: ['id','external_id','created_at','updated_at','metadata','name','project_id'], sessions: ['id','external_id','created_at','updated_at','metadata','name','project_id'],
episodes: ['id','session_id','user_message','ai_response','created_at','token_count','metadata'], episodes: ['access_count', 'ai_response', 'created_at', 'id', 'last_accessed_at', 'metadata', 'session_id', 'token_count', 'user_message'],
entities: ['id','name','type','notes','created_at','updated_at','metadata','mention_count','confidence','source','last_seen_at'], entities: ['id','name','type','notes','created_at','updated_at','metadata','mention_count','confidence','source','last_seen_at'],
relationships: ['id','from_id','to_id','label','created_at','metadata','mention_count','notes'], relationships: ['id','from_id','to_id','label','created_at','metadata','mention_count','notes'],
entity_episodes: ['entity_id','episode_id'], entity_episodes: ['entity_id','episode_id'],
+1 -1
View File
@@ -19,7 +19,7 @@ function mockMemory({ stats, summaries, since }) {
calls.sinceAfterId = Number(u.split('/since/').at(-1)); calls.sinceAfterId = Number(u.split('/since/').at(-1));
return json(since.filter(ep => ep.id > calls.sinceAfterId)); return json(since.filter(ep => ep.id > calls.sinceAfterId));
} }
if (u.includes('/api/generate')) return json({ response: 'A concise third-person summary.' }); if (u.endsWith('/utility/complete')) return json({ text: 'A concise third-person summary.' });
if (u.endsWith('/summaries') && opts.method === 'POST') { calls.posted = JSON.parse(opts.body); return json({ id: 99 }); } if (u.endsWith('/summaries') && opts.method === 'POST') { calls.posted = JSON.parse(opts.body); return json({ id: 99 }); }
if (/\/summaries\/\d+$/.test(u) && opts.method === 'PATCH') { calls.patched = JSON.parse(opts.body); return json({ ok: true }); } if (/\/summaries\/\d+$/.test(u) && opts.method === 'PATCH') { calls.patched = JSON.parse(opts.body); return json({ ok: true }); }
throw new Error('unexpected fetch: ' + u); throw new Error('unexpected fetch: ' + u);