server: reconcile ai_sessions persistence to Chunk 9 AISession shape
Reshape the ai_sessions table (migration 003) and mapping/routes to the full AISession contract: title, kind, notes, created_at, last_message_at; drop legacy role/model/settings. toAISession now maps the new columns and routes create/patch/messages handlers use the new shape.
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { AIStore } from "./index.js";
|
||||
import type { SessionRow } from "./index.js";
|
||||
import type { AISessionPersistence } from "./index.js";
|
||||
|
||||
/** A simple in-memory persistence backend for tests. */
|
||||
function memoryPersistence(): AISessionPersistence {
|
||||
const rows = new Map<string, unknown>();
|
||||
const rows = new Map<string, SessionRow>();
|
||||
return {
|
||||
list: async (projectId) =>
|
||||
Array.from(rows.values())
|
||||
.filter((r) => r.projectId === projectId)
|
||||
.map((r) => ({ ...r })),
|
||||
get: async (id) => (rows.has(id) ? { ...rows.get(id) } : null),
|
||||
get: async (id) => (rows.has(id) ? ({ ...rows.get(id) } as SessionRow) : null),
|
||||
save: async (session) => {
|
||||
rows.set(session.id, { ...session });
|
||||
},
|
||||
@@ -62,10 +63,8 @@ describe("AIStore", () => {
|
||||
it("adds a message to a session", async () => {
|
||||
const session = await store.createSession();
|
||||
const updated = await store.addMessage(session.id, {
|
||||
id: "m1",
|
||||
role: "user",
|
||||
content: "hello",
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
expect(updated.messages).toHaveLength(1);
|
||||
expect(updated.messages[0]?.role).toBe("user");
|
||||
@@ -74,14 +73,12 @@ describe("AIStore", () => {
|
||||
it("adds a suggestion and lists it", async () => {
|
||||
const session = await store.createSession();
|
||||
const updated = await store.addSuggestion(session.id, {
|
||||
id: "s1",
|
||||
sessionId: session.id,
|
||||
kind: "brainstorm",
|
||||
title: "Ideas",
|
||||
text: "some ideas",
|
||||
summary: "summary",
|
||||
status: "pending",
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
expect(updated.suggestions).toHaveLength(1);
|
||||
const list = await store.listSuggestions(session.id);
|
||||
|
||||
Reference in New Issue
Block a user