fix(25): handle missing chat_files table in listMessages and update addMessage test

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Nexus Dev 2026-04-01 23:35:59 +00:00
parent eeaf6468a7
commit 939ebd6dc3
2 changed files with 16 additions and 12 deletions

View file

@ -300,7 +300,7 @@ describe("chatService", () => {
expect(insertChain.values).toHaveBeenCalledWith( expect(insertChain.values).toHaveBeenCalledWith(
expect.objectContaining({ conversationId: "conv-1", role: "user", content: "Hi" }), expect.objectContaining({ conversationId: "conv-1", role: "user", content: "Hi" }),
); );
expect(result).toEqual(message); expect(result).toEqual({ ...message, files: [] });
}); });
it("bumps conversation updatedAt after insert (Pitfall 3)", async () => { it("bumps conversation updatedAt after insert (Pitfall 3)", async () => {

View file

@ -134,8 +134,9 @@ export function chatService(db: Db) {
// Load files for these messages and attach them // Load files for these messages and attach them
const messageIds = items.map((m) => m.id); const messageIds = items.map((m) => m.id);
let filesByMessageId = new Map<string, typeof chatFiles.$inferSelect[]>(); const filesByMessageId = new Map<string, typeof chatFiles.$inferSelect[]>();
if (messageIds.length > 0) { if (messageIds.length > 0) {
try {
const fileRows = await db const fileRows = await db
.select() .select()
.from(chatFiles) .from(chatFiles)
@ -147,6 +148,9 @@ export function chatService(db: Db) {
existing.push(f); existing.push(f);
filesByMessageId.set(f.messageId, existing); filesByMessageId.set(f.messageId, existing);
} }
} catch {
// chat_files table may not exist yet — treat as no files
}
} }
const itemsWithFiles = items.map((m) => ({ const itemsWithFiles = items.map((m) => ({