Skip to content

The agent that grows with you

test: restore Desktop composer-core and inline-code theming guards dropped by #120071

teknium1dae17c20db62
diff --git a/apps/desktop/src/app/chat/composer/composer-text-guard.test.tsx b/apps/desktop/src/app/chat/composer/composer-text-guard.test.tsx
new file mode 100644
index 00000000000..2c238e0cb57
--- /dev/null
+++ b/apps/desktop/src/app/chat/composer/composer-text-guard.test.tsx
@@ -0,0 +1,75 @@
+import { cleanup, render } from '@testing-library/react'
+import { afterEach, describe, expect, it, vi } from 'vitest'
+
+import { clearSessionDraft, mainComposerScope, stashSessionDraft } from '@/store/composer'
+
+import type { QueueEditState } from './composer-utils'
+import { useComposerDraft } from './hooks/use-composer-draft'
+
+// Regression for #49903: on desktop v0.17.0 the composer threw an uncaught
+// `Error: Composer is not available` at startup and the input went
+// unresponsive. @assistant-ui/core's composer mutators (setText/send/…) throw
+// when the thread's composer core is not bound yet, and the mount-time draft
+// restore pushes text through `aui.composer().setText` inside that window (the
+// popout refactor, #49488, widened it). The real draft hook must swallow the
+// unbound-core throw; the editor DOM + draftRef carry the text until it binds.
+const composer = vi.hoisted(() => ({
+ applied: [] as string[],
+ bound: false,
+ setText(value: string) {
+ if (!composer.bound) {
+ throw new Error('Composer is not available')
+ }
+
+ composer.applied.push(value)
+ }
+}))
+
+vi.mock('@assistant-ui/react', () => ({
+ useAui: () => ({ composer: () => composer }),
+ useAuiState: (selector: (state: { composer: { text: string } }) => unknown) => selector({ composer: { text: '' } }),
+ useComposerRuntime: () => ({
+ getState: () => ({ text: '' }),
+ subscribe: () => () => undefined
+ })
+}))
+
+const SESSION = 'session-guard'
+
+function Harness() {
+ useComposerDraft({
+ activeQueueSessionKey: SESSION,
+ focusKey: null,
+ inputDisabled: false,
+ queueEditRef: { current: null as QueueEditState | null },
+ sessionId: SESSION
+ })
+
+ return null
+}
+
+afterEach(() => {
+ cleanup()
+ mainComposerScope.clear()
+ clearSessionDraft(SESSION)
+ composer.applied = []
+ composer.bound = false
+})
+
+describe('composer draft restore vs an unbound composer core (#49903)', () => {
+ it('swallows the unbound-core throw at startup instead of crashing the renderer', () => {
+ stashSessionDraft(SESSION, 'restored draft', [])
+
+ expect(() => render(<Harness />)).not.toThrow()
+ expect(composer.applied).toEqual([])
+ })
+
+ it('writes the restored draft through once the core is bound', () => {
+ composer.bound = true
+ stashSessionDraft(SESSION, 'restored draft', [])
+
+ render(<Harness />)
+
+ expect(composer.applied).toContain('restored draft')
+ })
+})
diff --git a/apps/desktop/src/components/assistant-ui/thread/system-message.test.tsx b/apps/desktop/src/components/assistant-ui/thread/system-message.test.tsx
index 5ee1206fa66..aab8867ad2a 100644
--- a/apps/desktop/src/components/assistant-ui/thread/system-message.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/system-message.test.tsx
@@ -1,3 +1,7 @@
+import { readFileSync } from 'node:fs'
+import { dirname, resolve } from 'node:path'
+import { fileURLToPath } from 'node:url'
+
import { AssistantRuntimeProvider, type ThreadMessage, useExternalStoreRuntime } from '@assistant-ui/react'
import { cleanup, fireEvent, render } from '@testing-library/react'
import { afterEach, describe, expect, it } from 'vitest'
@@ -46,6 +50,31 @@ function expectTimestampSeparated(container: HTMLElement, precedingText: string)
afterEach(cleanup)
+describe('background report inline code', () => {
+ // The report body is the same `aui-md prose` markdown renderer the
+ // assistant turn uses, rendered with no assistant/room slot ancestor. The
+ // real stylesheet's cascade must still reach its `<code>`, or Tailwind
+ // Typography's fixed near-black ink wins on every dark theme (#107486).
+ const stylesheet = readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), '../../../styles.css'), 'utf8')
+
+ it('themes inline code in an opened report with the chat inline-code tokens', () => {
+ const { container, getByRole } = render(
+ <>
+ <style>{stylesheet}</style>
+ <Harness asyncResult="run `discover_models` first" text="1 background agent finished" />
+ </>
+ )
+
+ fireEvent.click(getByRole('button', { name: '1 background agent finished' }))
+ const code = container.querySelector('[data-role="system"] :not(pre) > code')
+ expect(code).toBeTruthy()
+ const style = getComputedStyle(code as Element)
+
+ expect(style.color).toBe('var(--ui-inline-code-foreground)')
+ expect(style.background).toBe('var(--ui-inline-code-background)')
+ })
+})
+
describe('background report disclosure', () => {
it('keeps result bodies out of the transcript until opened and removes them when collapsed', () => {
const report = '{"blockers":[{"title":"Local-model readiness uses the wrong endpoint"}]}'
diff --git a/apps/desktop/src/plugins/hermes-bots/group-chat-view.inline-code.test.tsx b/apps/desktop/src/plugins/hermes-bots/group-chat-view.inline-code.test.tsx
new file mode 100644
index 00000000000..b9dc2e124cc
--- /dev/null
+++ b/apps/desktop/src/plugins/hermes-bots/group-chat-view.inline-code.test.tsx
@@ -0,0 +1,90 @@
+import { readFileSync } from 'node:fs'
+import { dirname, resolve } from 'node:path'
+import { fileURLToPath } from 'node:url'
+
+import { cleanup, render } from '@testing-library/react'
+import type { ReactNode } from 'react'
+import { afterEach, beforeAll, expect, it, vi } from 'vitest'
+
+import { translateBots } from './i18n-test-helper'
+
+// Room bodies render through the shell's message renderer, whose markdown
+// root is `aui-md prose` — the same container the 1:1 chat uses, minus the
+// `[data-slot='aui_assistant-message-content']` ancestor that scopes the
+// themed inline-code rule in styles.css. Without a room-owned hook the room's
+// `<code>` falls through to Tailwind Typography's fixed near-black ink, which
+// is invisible on every dark theme (#114086). The stubs below emit the two
+// shapes the room can produce (renderer path, raw Streamdown fallback) so the
+// real stylesheet's cascade decides, not a regex over the source text.
+vi.mock('@hermes/plugin-sdk', async () => {
+ const { pluginSdkMock, createGroupGateway } = await import('./group-test-utils')
+ const base = await pluginSdkMock(createGroupGateway().host)
+
+ const Button = ({ children, onClick, title }: { children?: ReactNode; onClick?: () => void; title?: string }) => (
+ <button onClick={onClick} title={title}>
+ {children}
+ </button>
+ )
+
+ return {
+ ...base,
+ Button,
+ RowButton: Button,
+ cn: (...values: unknown[]) => values.filter(Boolean).join(' '),
+ Codicon: () => null,
+ CopyButton: () => null,
+ Switch: () => null,
+ ConfirmDialog: () => null,
+ Dialog: () => null,
+ DialogContent: () => null,
+ DialogDescription: () => null,
+ DialogFooter: () => null,
+ DialogHeader: () => null,
+ DialogTitle: () => null,
+ Input: () => null,
+ MessageTextContent: ({ text }: { text: string }) => (
+ <div className="aui-md prose">
+ <p>
+ set <code data-testid="renderer-code">{text}</code> first
+ </p>
+ </div>
+ ),
+ Tip: ({ children }: { children: ReactNode }) => children,
+ relativeTime: () => 'now',
+ useI18n: () => ({ t: { common: { cancel: 'Cancel', save: 'Save' } } }),
+ usePluginI18n: () => translateBots
+ }
+})
+vi.mock('./avatar', () => ({ avatarColor: () => '#888', botAppearance: () => ({}), BotFace: () => null }))
+vi.mock('./group-chat-parts', () => ({
+ GroupClarifyCard: () => null,
+ GroupImageControls: () => null,
+ GroupMentionInput: () => null
+}))
+
+const STYLES = resolve(dirname(fileURLToPath(import.meta.url)), '../../styles.css')
+
+beforeAll(() => {
+ Element.prototype.scrollIntoView = vi.fn()
+ const sheet = document.createElement('style')
+ sheet.textContent = readFileSync(STYLES, 'utf8')
+ document.head.appendChild(sheet)
+})
+afterEach(cleanup)
+
+it('themes inline code in room message bodies with the chat inline-code tokens', async () => {
+ const { $groupChats } = await import('./group-chat')
+ const { GroupChatWorkspace } = await import('./group-chat-view')
+
+ const log = [
+ { id: 'm1', thread: 'a', from: { kind: 'member' as const, name: 'builder' }, text: 'discover_models', at: 1 }
+ ]
+
+ $groupChats.set({ Room: { log, watermarks: {}, sessions: {} } })
+
+ const { getByTestId } = render(<GroupChatWorkspace group="Room" members={[{ name: 'builder' }] as never} />)
+ const style = getComputedStyle(getByTestId('renderer-code'))
+
+ expect(style.color).toBe('var(--ui-inline-code-foreground)')
+ expect(style.background).toBe('var(--ui-inline-code-background)')
+})