The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(desktop): tighten the live-draft race coverage and dedupe the sibling reads
DavidMetcalfe7679556d9093
diff --git a/apps/desktop/src/app/chat/composer/composer-utils.test.ts b/apps/desktop/src/app/chat/composer/composer-utils.test.tsindex f4f00c1e9fe..5eea0eb6ba8 100644--- a/apps/desktop/src/app/chat/composer/composer-utils.test.ts+++ b/apps/desktop/src/app/chat/composer/composer-utils.test.ts@@ -1,5 +1,5 @@import type { Unstable_TriggerItem } from '@assistant-ui/core'-import { describe, expect, it } from 'vitest'+import { afterEach, describe, expect, it } from 'vitest'import {acceptsTriggerCompletion,@@ -193,6 +193,12 @@ function editorWith(text: string): HTMLDivElement {return el}+// editorWith appends to the shared JSDOM body; empty it so the element does not+// leak into other cases in this file.+afterEach(() => {+ document.body.replaceChildren()+})+describe('liveComposerDraft (stale-mirror guard for the ArrowUp recall)', () => {it('reads the live editor text even when the mirror is still empty', () => {// The race this exists for: a keystroke or paste flushed only by the@@ -223,12 +229,11 @@ describe('liveComposerDraft (stale-mirror guard for the ArrowUp recall)', () =>expect(liveComposerDraft(missing, 'mirrored draft')).toBe('mirrored draft')})- it('an empty editor reads as empty against a fresh mirror (behaviour unchanged)', () => {+ it('an empty editor reads as empty even against a stale non-empty mirror', () => {+ // The cleared-draft race: select-all + delete is flushed by the same+ // coalesced rAF, so the mirror can still hold the text the user deleted.const editor = editorWith('')- editor.replaceChildren()- normalizeComposerEditorDom(editor)-- expect(liveComposerDraft(editor, '')).toBe('')+ expect(liveComposerDraft(editor, 'stale draft before delete')).toBe('')})})diff --git a/apps/desktop/src/app/chat/composer/index.tsx b/apps/desktop/src/app/chat/composer/index.tsxindex b056b04ca38..9c1b4ed3819 100644--- a/apps/desktop/src/app/chat/composer/index.tsx+++ b/apps/desktop/src/app/chat/composer/index.tsx@@ -923,7 +923,7 @@ export function ChatBar({if (busy && !disabled) {// As with plain Enter, source the just-typed content from the DOM so a// fast keypress cannot queue a stale draft.- const editorText = editorRef.current ? composerPlainText(editorRef.current) : draftRef.current+ const editorText = liveComposerDraft(editorRef.current, draftRef.current)if (editorText !== draftRef.current) {draftRef.current = editorText@@ -945,7 +945,7 @@ export function ChatBar({// Without the live read, a real message typed while prompts are queued// would drain the queue instead of sending. submitDraft() re-syncs and// sends the live editor text.- const editorText = editorRef.current ? composerPlainText(editorRef.current) : draftRef.current+ const editorText = liveComposerDraft(editorRef.current, draftRef.current)const hasLivePayload = editorText.trim().length > 0 || attachments.length > 0if (disabled) {