mirror of
https://github.com/thedotmack/claude-mem
synced 2026-04-25 17:15:04 +02:00
Merge branch 'pr-1472' into integration/validation-batch
# Conflicts: # plugin/scripts/context-generator.cjs # plugin/scripts/mcp-server.cjs # plugin/scripts/worker-service.cjs # plugin/ui/viewer-bundle.js # src/cli/handlers/context.ts # src/services/sqlite/SessionStore.ts # src/services/sqlite/migrations/runner.ts # src/services/worker-service.ts # src/shared/SettingsDefaultsManager.ts
This commit is contained in:
@@ -22,6 +22,10 @@ interface TableColumnInfo {
|
||||
notnull: number;
|
||||
}
|
||||
|
||||
interface IndexInfo {
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface SchemaVersion {
|
||||
version: number;
|
||||
}
|
||||
@@ -46,6 +50,11 @@ function getSchemaVersions(db: Database): number[] {
|
||||
return rows.map(r => r.version);
|
||||
}
|
||||
|
||||
function getIndexNames(db: Database, table: string): string[] {
|
||||
const rows = db.prepare(`PRAGMA index_list(${table})`).all() as IndexInfo[];
|
||||
return rows.map(r => r.name);
|
||||
}
|
||||
|
||||
describe('MigrationRunner', () => {
|
||||
let db: Database;
|
||||
|
||||
@@ -158,6 +167,43 @@ describe('MigrationRunner', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('schema drift recovery for migration 24', () => {
|
||||
it('should repair platform_source column and index even when version 24 is already recorded', () => {
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS schema_versions (
|
||||
id INTEGER PRIMARY KEY,
|
||||
version INTEGER UNIQUE NOT NULL,
|
||||
applied_at TEXT NOT NULL
|
||||
)
|
||||
`);
|
||||
db.prepare('INSERT INTO schema_versions (version, applied_at) VALUES (?, ?)').run(24, new Date().toISOString());
|
||||
|
||||
db.run(`
|
||||
CREATE TABLE sdk_sessions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
content_session_id TEXT UNIQUE NOT NULL,
|
||||
memory_session_id TEXT UNIQUE,
|
||||
project TEXT NOT NULL,
|
||||
user_prompt TEXT,
|
||||
started_at TEXT NOT NULL,
|
||||
started_at_epoch INTEGER NOT NULL,
|
||||
completed_at TEXT,
|
||||
completed_at_epoch INTEGER,
|
||||
status TEXT NOT NULL CHECK(status IN ('active','completed','failed'))
|
||||
)
|
||||
`);
|
||||
|
||||
const runner = new MigrationRunner(db);
|
||||
expect(() => runner.runAllMigrations()).not.toThrow();
|
||||
|
||||
const columnNames = getColumns(db, 'sdk_sessions').map(column => column.name);
|
||||
expect(columnNames).toContain('platform_source');
|
||||
|
||||
const indexNames = getIndexNames(db, 'sdk_sessions');
|
||||
expect(indexNames).toContain('idx_sdk_sessions_platform_source');
|
||||
});
|
||||
});
|
||||
|
||||
describe('issue #979 — old DatabaseManager version conflict', () => {
|
||||
it('should create core tables even when old migration versions 1-7 are in schema_versions', () => {
|
||||
// Simulate the old DatabaseManager having applied its migrations 1-7
|
||||
|
||||
@@ -130,6 +130,38 @@ describe('Sessions Module', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('platform_source', () => {
|
||||
it('should default new sessions to claude when platformSource is omitted', () => {
|
||||
const sessionId = createSDKSession(db, 'session-platform-1', 'project', 'prompt');
|
||||
const session = getSessionById(db, sessionId);
|
||||
|
||||
expect(session?.platform_source).toBe('claude');
|
||||
});
|
||||
|
||||
it('should preserve a non-default platform_source for legacy callers that omit platformSource', () => {
|
||||
const sessionId = createSDKSession(db, 'session-platform-2', 'project', 'prompt', undefined, 'codex');
|
||||
let session = getSessionById(db, sessionId);
|
||||
expect(session?.platform_source).toBe('codex');
|
||||
|
||||
createSDKSession(db, 'session-platform-2', 'project', 'prompt');
|
||||
session = getSessionById(db, sessionId);
|
||||
expect(session?.platform_source).toBe('codex');
|
||||
});
|
||||
|
||||
it('should reject explicit platform_source conflicts for the same session', () => {
|
||||
createSDKSession(db, 'session-platform-3', 'project', 'prompt', undefined, 'codex');
|
||||
|
||||
expect(() => createSDKSession(
|
||||
db,
|
||||
'session-platform-3',
|
||||
'project',
|
||||
'prompt',
|
||||
undefined,
|
||||
'claude'
|
||||
)).toThrow(/Platform source conflict/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateMemorySessionId', () => {
|
||||
it('should update memory_session_id for existing session', () => {
|
||||
const contentSessionId = 'content-session-update';
|
||||
|
||||
Reference in New Issue
Block a user