feat(FN-1270): add task document storage with revision history

- Add task document domain types and key validation helpers in core types
- Introduce schema v18 migration creating task_documents and task_document_revisions tables with indexes
- Implement TaskStore CRUD/upsert APIs for task documents, including revision archiving and task update events
- Export task document types from the core index for downstream consumers
- Add comprehensive task document tests and update database schema/version assertions
This commit is contained in:
gsxdsm
2026-04-08 12:09:41 -07:00
parent f35515ed19
commit bae9d8cd2a
6 changed files with 629 additions and 13 deletions

View File

@@ -73,6 +73,8 @@ describe("Database", () => {
expect(tableNames).toContain("ai_sessions");
expect(tableNames).toContain("messages");
expect(tableNames).toContain("agentRatings");
expect(tableNames).toContain("task_documents");
expect(tableNames).toContain("task_document_revisions");
});
it("creates all expected indexes", () => {
@@ -97,10 +99,13 @@ describe("Database", () => {
expect(indexNames).toContain("idxMissionEventsMissionId");
expect(indexNames).toContain("idxMissionEventsTimestamp");
expect(indexNames).toContain("idxMissionEventsType");
expect(indexNames).toContain("idxTaskDocumentsTaskKey");
expect(indexNames).toContain("idxTaskDocumentsTaskId");
expect(indexNames).toContain("idxTaskDocumentRevisionsTaskKey");
});
it("seeds schema version", () => {
expect(db.getSchemaVersion()).toBe(17);
expect(db.getSchemaVersion()).toBe(18);
});
it("seeds lastModified", () => {
@@ -123,7 +128,7 @@ describe("Database", () => {
it("is idempotent - calling init() twice does not fail", () => {
expect(() => db.init()).not.toThrow();
expect(db.getSchemaVersion()).toBe(17);
expect(db.getSchemaVersion()).toBe(18);
});
it("does not overwrite existing config on re-init", () => {
@@ -730,7 +735,7 @@ describe("schema migrations", () => {
db.init();
// Verify version bumped to 5 (includes v1→v2, v2→v3, v3→v4, and v4→v5 migrations)
expect(db.getSchemaVersion()).toBe(17);
expect(db.getSchemaVersion()).toBe(18);
// Verify new columns exist and existing data is intact
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
@@ -755,11 +760,11 @@ describe("schema migrations", () => {
const db = new Database(kbDir);
db.init();
expect(db.getSchemaVersion()).toBe(17);
expect(db.getSchemaVersion()).toBe(18);
// Re-init should not fail
db.init();
expect(db.getSchemaVersion()).toBe(17);
expect(db.getSchemaVersion()).toBe(18);
db.close();
});
@@ -775,7 +780,7 @@ describe("schema migrations", () => {
db.init();
expect(db.getSchemaVersion()).toBe(17);
expect(db.getSchemaVersion()).toBe(18);
const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'agentRatings'").all() as Array<{ name: string }>;
expect(tables).toEqual([{ name: "agentRatings" }]);
@@ -799,7 +804,7 @@ describe("schema migrations", () => {
db.init();
expect(db.getSchemaVersion()).toBe(17);
expect(db.getSchemaVersion()).toBe(18);
const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'mission_events'").all() as Array<{ name: string }>;
expect(tables).toEqual([{ name: "mission_events" }]);
@@ -903,7 +908,7 @@ describe("schema migrations", () => {
db.init();
// Verify version bumped to 5
expect(db.getSchemaVersion()).toBe(17);
expect(db.getSchemaVersion()).toBe(18);
// Verify new columns exist and existing data is intact
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
@@ -1113,7 +1118,7 @@ describe("createDatabase factory", () => {
const db = createDatabase(kbDir);
db.init();
expect(db.getSchemaVersion()).toBe(17);
expect(db.getSchemaVersion()).toBe(18);
expect(db.getLastModified()).toBeGreaterThan(0);
db.close();