fix: address platform source review feedback

Tighten platform source persistence so legacy callers cannot silently relabel existing sessions, repair migration 24 when schema_versions drifts from the real schema, and polish the follow-up UI/error-handler review nits.

- only backfill platform_source when it is blank and raise on explicit source conflicts for an existing session
- make migration 24 verify both the sdk_sessions column and its index before treating it as applied
- expose platform_source from the functional session getters and add regression tests for source preservation and schema drift recovery
- add the required APPROVED OVERRIDE annotation for centralized HTTP error translation
- keep mobile source pills on a single horizontal row
This commit is contained in:
huakson
2026-03-24 10:46:48 -03:00
parent 2b60dd2932
commit 4f6fb9e614
13 changed files with 245 additions and 121 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