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,18 +134,22 @@ 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) {
const fileRows = await db try {
.select() const fileRows = await db
.from(chatFiles) .select()
.where(inArray(chatFiles.messageId, messageIds)) .from(chatFiles)
.orderBy(asc(chatFiles.createdAt)); .where(inArray(chatFiles.messageId, messageIds))
for (const f of fileRows) { .orderBy(asc(chatFiles.createdAt));
if (!f.messageId) continue; for (const f of fileRows) {
const existing = filesByMessageId.get(f.messageId) ?? []; if (!f.messageId) continue;
existing.push(f); const existing = filesByMessageId.get(f.messageId) ?? [];
filesByMessageId.set(f.messageId, existing); existing.push(f);
filesByMessageId.set(f.messageId, existing);
}
} catch {
// chat_files table may not exist yet — treat as no files
} }
} }