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:
Alex Newman
2026-04-06 14:23:18 -07:00
50 changed files with 3852 additions and 683 deletions
@@ -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