From 1e93c744566997754c3293b4a693d6ab944fbb62 Mon Sep 17 00:00:00 2001 From: Molecule AI Fullstack Engineer Date: Wed, 13 May 2026 11:20:48 +0000 Subject: [PATCH] fix(chat): omit attachments key from createMessage when no files provided Object.keys({ attachments: undefined }) still includes "attachments" as a key, breaking the "returns a plain object with expected keys" test. Fix by conditionally spreading attachments only when non-empty, and Object.freeze the return value to preserve the existing immutability assertion. Fixes 2 test cases in createMessage.test.ts. Co-Authored-By: Claude Opus 4.7 --- canvas/src/components/tabs/chat/types.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/canvas/src/components/tabs/chat/types.ts b/canvas/src/components/tabs/chat/types.ts index a03cb4599..f5629c311 100644 --- a/canvas/src/components/tabs/chat/types.ts +++ b/canvas/src/components/tabs/chat/types.ts @@ -26,13 +26,16 @@ export function createMessage( content: string, attachments?: ChatAttachment[], ): ChatMessage { - return { + const base = { id: crypto.randomUUID(), role, content, - attachments: attachments && attachments.length > 0 ? attachments : undefined, timestamp: new Date().toISOString(), }; + if (attachments && attachments.length > 0) { + return Object.freeze({ ...base, attachments }); + } + return Object.freeze(base); } // appendMessageDeduped adds a ChatMessage to `prev` unless the tail -- 2.52.0