feat(FN-2909): merge fusion/fn-2909
This commit is contained in:
@@ -430,6 +430,38 @@ describe("ChatStore", () => {
|
||||
expect(message.metadata).toEqual({ tokens: 150, finishReason: "stop" });
|
||||
});
|
||||
|
||||
it("round-trips attachments metadata", () => {
|
||||
const session = createTestSession(store);
|
||||
const attachments = [{
|
||||
id: "att-abc123",
|
||||
filename: "123-file.png",
|
||||
originalName: "file.png",
|
||||
mimeType: "image/png",
|
||||
size: 1024,
|
||||
createdAt: new Date().toISOString(),
|
||||
}];
|
||||
|
||||
const created = store.addMessage(session.id, {
|
||||
role: "user",
|
||||
content: "with attachment",
|
||||
attachments,
|
||||
});
|
||||
|
||||
expect(created.attachments).toEqual(attachments);
|
||||
const loaded = store.getMessage(created.id);
|
||||
expect(loaded?.attachments).toEqual(attachments);
|
||||
});
|
||||
|
||||
it("returns undefined attachments when not provided", () => {
|
||||
const session = createTestSession(store);
|
||||
const created = store.addMessage(session.id, {
|
||||
role: "user",
|
||||
content: "without attachment",
|
||||
});
|
||||
|
||||
expect(created.attachments).toBeUndefined();
|
||||
});
|
||||
|
||||
it("throws error when session does not exist", () => {
|
||||
expect(() => {
|
||||
store.addMessage("chat-nonexistent", {
|
||||
@@ -454,6 +486,53 @@ describe("ChatStore", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("addMessageAttachment", () => {
|
||||
it("appends to existing attachments", () => {
|
||||
const session = createTestSession(store);
|
||||
const message = store.addMessage(session.id, {
|
||||
role: "user",
|
||||
content: "hello",
|
||||
attachments: [{
|
||||
id: "att-1",
|
||||
filename: "a.txt",
|
||||
originalName: "a.txt",
|
||||
mimeType: "text/plain",
|
||||
size: 1,
|
||||
createdAt: new Date().toISOString(),
|
||||
}],
|
||||
});
|
||||
|
||||
const updated = store.addMessageAttachment(session.id, message.id, {
|
||||
id: "att-2",
|
||||
filename: "b.txt",
|
||||
originalName: "b.txt",
|
||||
mimeType: "text/plain",
|
||||
size: 2,
|
||||
createdAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
expect(updated.attachments).toHaveLength(2);
|
||||
expect(updated.attachments?.[1]?.id).toBe("att-2");
|
||||
});
|
||||
|
||||
it("creates attachment array when message has none", () => {
|
||||
const session = createTestSession(store);
|
||||
const message = store.addMessage(session.id, { role: "user", content: "hello" });
|
||||
|
||||
const updated = store.addMessageAttachment(session.id, message.id, {
|
||||
id: "att-3",
|
||||
filename: "c.txt",
|
||||
originalName: "c.txt",
|
||||
mimeType: "text/plain",
|
||||
size: 3,
|
||||
createdAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
expect(updated.attachments).toHaveLength(1);
|
||||
expect(updated.attachments?.[0]?.id).toBe("att-3");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getMessages", () => {
|
||||
it("returns messages for a session ordered by createdAt ASC", async () => {
|
||||
const session = createTestSession(store);
|
||||
@@ -771,6 +850,26 @@ describe("ChatStore", () => {
|
||||
expect(handler.mock.calls[0][0].id).toBe(session.id);
|
||||
});
|
||||
|
||||
it("addMessageAttachment emits chat:message:updated", () => {
|
||||
const handler = vi.fn();
|
||||
store.on("chat:message:updated", handler);
|
||||
|
||||
const session = createTestSession(store);
|
||||
const message = store.addMessage(session.id, { role: "user", content: "hello" });
|
||||
|
||||
const updated = store.addMessageAttachment(session.id, message.id, {
|
||||
id: "att-evt",
|
||||
filename: "evt.txt",
|
||||
originalName: "evt.txt",
|
||||
mimeType: "text/plain",
|
||||
size: 4,
|
||||
createdAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
expect(handler).toHaveBeenCalledTimes(1);
|
||||
expect(handler).toHaveBeenCalledWith(updated);
|
||||
});
|
||||
|
||||
it("deleteMessage does NOT emit for non-existent message", () => {
|
||||
const handler = vi.fn();
|
||||
store.on("chat:message:deleted", handler);
|
||||
|
||||
@@ -131,7 +131,7 @@ describe("Database", () => {
|
||||
});
|
||||
|
||||
it("seeds schema version", () => {
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
});
|
||||
|
||||
it("seeds lastModified", () => {
|
||||
@@ -154,7 +154,7 @@ describe("Database", () => {
|
||||
|
||||
it("is idempotent - calling init() twice does not fail", () => {
|
||||
expect(() => db.init()).not.toThrow();
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
});
|
||||
|
||||
it("does not overwrite existing config on re-init", () => {
|
||||
@@ -761,7 +761,7 @@ describe("schema migrations", () => {
|
||||
db.init();
|
||||
|
||||
// Verify version bumped to 29 (includes v1→v2 through v26→v29)
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
|
||||
// Verify new columns exist and existing data is intact
|
||||
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
|
||||
@@ -786,11 +786,11 @@ describe("schema migrations", () => {
|
||||
const db = new Database(fusionDir);
|
||||
db.init();
|
||||
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
|
||||
// Re-init should not fail
|
||||
db.init();
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
|
||||
db.close();
|
||||
});
|
||||
@@ -825,7 +825,7 @@ describe("schema migrations", () => {
|
||||
|
||||
db.init();
|
||||
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
|
||||
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
|
||||
expect(cols.map((col) => col.name)).toContain("priority");
|
||||
@@ -866,7 +866,7 @@ describe("schema migrations", () => {
|
||||
|
||||
db.init();
|
||||
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
|
||||
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
|
||||
const colNames = cols.map((col) => col.name);
|
||||
@@ -935,7 +935,7 @@ describe("schema migrations", () => {
|
||||
|
||||
db.init();
|
||||
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
|
||||
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
|
||||
const colNames = cols.map((col) => col.name);
|
||||
@@ -976,7 +976,7 @@ describe("schema migrations", () => {
|
||||
|
||||
db.init();
|
||||
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
|
||||
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" }]);
|
||||
@@ -1000,7 +1000,7 @@ describe("schema migrations", () => {
|
||||
|
||||
db.init();
|
||||
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
|
||||
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" }]);
|
||||
@@ -1104,7 +1104,7 @@ describe("schema migrations", () => {
|
||||
db.init();
|
||||
|
||||
// Verify version bumped to 29
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
|
||||
// Verify new columns exist and existing data is intact
|
||||
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
|
||||
@@ -1555,7 +1555,7 @@ describe("createDatabase factory", () => {
|
||||
const db = createDatabase(fusionDir);
|
||||
db.init();
|
||||
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
expect(db.getLastModified()).toBeGreaterThan(0);
|
||||
|
||||
db.close();
|
||||
|
||||
@@ -779,7 +779,7 @@ describe("Migration: pre-33 DB upgrade", () => {
|
||||
// Step 1: Create a fresh database at v33 (runs all migrations up to 33)
|
||||
const db1 = createDatabase(legacyDir);
|
||||
db1.init();
|
||||
expect(db1.getSchemaVersion()).toBe(50);
|
||||
expect(db1.getSchemaVersion()).toBe(51);
|
||||
db1.close();
|
||||
|
||||
// Step 2: Manually downgrade to version 32 and drop insight tables
|
||||
@@ -814,7 +814,7 @@ describe("Migration: pre-33 DB upgrade", () => {
|
||||
expect(tableNamesBefore).not.toContain("project_insight_runs");
|
||||
// Now run init — this triggers the v32→v33 migration
|
||||
db3.init();
|
||||
expect(db3.getSchemaVersion()).toBe(50);
|
||||
expect(db3.getSchemaVersion()).toBe(51);
|
||||
|
||||
// Step 4: Verify insight tables exist after migration
|
||||
const tablesAfter = db3.prepare(
|
||||
@@ -845,12 +845,12 @@ describe("Migration: pre-33 DB upgrade", () => {
|
||||
try {
|
||||
const db1 = createDatabase(testDir);
|
||||
db1.init();
|
||||
expect(db1.getSchemaVersion()).toBe(50);
|
||||
expect(db1.getSchemaVersion()).toBe(51);
|
||||
db1.close();
|
||||
|
||||
const db2 = createDatabase(testDir);
|
||||
expect(() => db2.init()).not.toThrow();
|
||||
expect(db2.getSchemaVersion()).toBe(50);
|
||||
expect(db2.getSchemaVersion()).toBe(51);
|
||||
db2.close();
|
||||
} finally {
|
||||
rmSync(testDir, { recursive: true, force: true });
|
||||
|
||||
@@ -2629,7 +2629,7 @@ describe("MissionStore", () => {
|
||||
|
||||
describe("Loop State & Validator Run Schema (v31)", () => {
|
||||
it("schema version is 40 after migration", () => {
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
});
|
||||
|
||||
it("mission_features table has loop state columns", () => {
|
||||
|
||||
@@ -742,7 +742,7 @@ describe("RoadmapStore", () => {
|
||||
|
||||
describe("schema version", () => {
|
||||
it("schema version is 40 after init", () => {
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -465,7 +465,7 @@ describe("Run Audit", () => {
|
||||
});
|
||||
|
||||
it("schema version is bumped to 40", () => {
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -51,7 +51,7 @@ describe("TaskStore task documents", () => {
|
||||
|
||||
expect(tableNames.has("task_documents")).toBe(true);
|
||||
expect(tableNames.has("task_document_revisions")).toBe(true);
|
||||
expect(db.getSchemaVersion()).toBe(50);
|
||||
expect(db.getSchemaVersion()).toBe(51);
|
||||
|
||||
const index = db
|
||||
.prepare(
|
||||
|
||||
Reference in New Issue
Block a user