Skip to content

The agent that grows with you

fix(bot-mode): resolve room MEDIA only for members on this gateway; make the code-block spec bite

teknium1c27d67a93452
diff --git a/apps/desktop/e2e/group-chat-code-block-and-media.spec.ts b/apps/desktop/e2e/group-chat-code-block-and-media.spec.ts
index 634d016cdb1..b70754f5d31 100644
--- a/apps/desktop/e2e/group-chat-code-block-and-media.spec.ts
+++ b/apps/desktop/e2e/group-chat-code-block-and-media.spec.ts
@@ -13,7 +13,10 @@ import { expect, test } from './test'
// go through the same message renderer as the 1:1 chat.
const SHOT_DIR = '/tmp/batchbots/panes-layout-cron-tile/shots'
-const LONG_LINE = 'const veryLongIdentifierNameForTheGroupChatCodeBlockRepro = computeSomethingWith(argumentNumberOne, argumentNumberTwo, argumentNumberThree)'
+// One unbroken 600+ char token: it cannot wrap, so it MUST overflow the
+// message column — the probe asserts that overflow exists before asserting
+// nothing clips it (a line that fits proves nothing about #91878).
+const LONG_LINE = `const veryLongIdentifierNameForTheGroupChatCodeBlockRepro_${'x'.repeat(600)} = 1`
// 1x1 PNG.
const PNG_BASE64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=='
@@ -123,19 +126,25 @@ test('a group reply renders its code block inside the message and its MEDIA: lin
const clippedWithoutScroll = chain.filter(
box => box.scrollWidth > box.clientWidth + 1 && !['auto', 'scroll'].includes(box.overflowX)
)
+ const scrollingPre = chain.find(
+ box => box.tag === 'pre' && box.scrollWidth > box.clientWidth + 1 && ['auto', 'scroll'].includes(box.overflowX)
+ )
return {
body: { left: bodyRect.left, right: bodyRect.right },
pre: { left: preRect.left, right: preRect.right, width: preRect.width },
chain,
clippedWithoutScroll,
+ scrollingPre,
rawMedia: body.textContent?.includes('MEDIA:') ?? false,
inlineMedia: Boolean(body.querySelector('img, audio, video'))
}
})
console.log('GROUP CODE BLOCK GEOMETRY', JSON.stringify(geometry))
- // The code block stays inside the message column...
+ // The fixture really overflows and the code block scrolls to show it...
+ expect.soft(geometry.scrollingPre).toBeDefined()
+ // ...while staying inside the message column...
expect.soft(geometry.pre.right).toBeLessThanOrEqual(geometry.body.right + 1)
// ...and no box between the code and the message clips text it cannot scroll.
expect.soft(geometry.clippedWithoutScroll).toEqual([])
diff --git a/apps/desktop/src/components/assistant-ui/markdown-text.tsx b/apps/desktop/src/components/assistant-ui/markdown-text.tsx
index f8f5a72f8a6..4d219f747f1 100644
--- a/apps/desktop/src/components/assistant-ui/markdown-text.tsx
+++ b/apps/desktop/src/components/assistant-ui/markdown-text.tsx
@@ -757,9 +757,12 @@ interface MarkdownTextContentProps extends MarkdownTextSurfaceProps {
* so the canonical link component can route them to inline players/previews.
* Fenced blocks stay plain code (`disableArtifacts`): a transcript rendered
* outside a session — a Bot Mode group room — has no session to own artifact
- * versions. */
-export function MessageTextContent({ text }: { text: string }) {
- return <MarkdownTextContent disableArtifacts isRunning={false} text={renderMediaTags(text)} />
+ * versions. `media={false}` leaves `MEDIA:` lines as prose: media paths resolve
+ * against the ACTIVE gateway, so a message written on another machine (a
+ * Connections Bot in a cross-machine room) must not have its path read here —
+ * that is a broken image at best and a same-path local file at worst. */
+export function MessageTextContent({ media = true, text }: { media?: boolean; text: string }) {
+ return <MarkdownTextContent disableArtifacts isRunning={false} text={media ? renderMediaTags(text) : text} />
}
export function MarkdownTextContent({ isRunning, text, ...surfaceProps }: MarkdownTextContentProps) {
diff --git a/apps/desktop/src/plugins/hermes-bots/group-chat-view.render.test.tsx b/apps/desktop/src/plugins/hermes-bots/group-chat-view.render.test.tsx
new file mode 100644
index 00000000000..0ed76c01477
--- /dev/null
+++ b/apps/desktop/src/plugins/hermes-bots/group-chat-view.render.test.tsx
@@ -0,0 +1,85 @@
+import { cleanup, render } from '@testing-library/react'
+import type { ReactNode } from 'react'
+import { afterEach, expect, it, vi } from 'vitest'
+
+import { translateBots } from './i18n-test-helper'
+
+// Room bodies go through the shell's message renderer (the 1:1 chat's code
+// card + `MEDIA:` transform) when the SDK exports it. The stub records what the
+// room handed it so the test asserts the wiring, not the renderer's output.
+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,
+ ConfirmDialog: () => null,
+ Dialog: () => null,
+ DialogContent: () => null,
+ DialogDescription: () => null,
+ DialogFooter: () => null,
+ DialogHeader: () => null,
+ DialogTitle: () => null,
+ Input: () => null,
+ MessageTextContent: ({ media = true, text }: { media?: boolean; text: string }) => (
+ <span data-media={String(media)} data-testid="message-text-content">
+ {text}
+ </span>
+ ),
+ 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
+}))
+afterEach(cleanup)
+
+it('renders member replies through the shell message renderer, resolving media only for members on this gateway', async () => {
+ Element.prototype.scrollIntoView = vi.fn()
+ const { $groupChats } = await import('./group-chat')
+ const { GroupChatWorkspace } = await import('./group-chat-view')
+
+ const log = [
+ { id: 'u1', thread: 'a', from: { kind: 'user' as const, name: 'You' }, text: 'Show me', at: 1 },
+ { id: 'm1', thread: 'a', from: { kind: 'member' as const, name: 'builder' }, text: 'MEDIA:/tmp/local.png', at: 2 },
+ {
+ id: 'm2',
+ thread: 'a',
+ from: { kind: 'member' as const, name: 'builder', source: 'mini' },
+ text: 'MEDIA:/tmp/remote.png',
+ at: 3
+ }
+ ]
+
+ const members = [
+ { name: 'builder' },
+ { connectionId: 'mini', connectionLabel: 'mini', name: 'builder', remoteSource: true, sourceScoped: true }
+ ] as never
+
+ $groupChats.set({ Room: { log, watermarks: {}, sessions: {} } })
+ const { getAllByTestId } = render(<GroupChatWorkspace group="Room" members={members} />)
+ const bodies = getAllByTestId('message-text-content').map(el => [el.textContent, el.dataset.media])
+
+ expect(bodies).toEqual([
+ ['Show me', 'true'],
+ ['MEDIA:/tmp/local.png', 'true'],
+ ['MEDIA:/tmp/remote.png', 'false']
+ ])
+})
diff --git a/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx b/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx
index 9a67f3034f6..bb81861faac 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx
@@ -1066,7 +1066,7 @@ export function GroupChatWorkspace({ group, members, onBack, visible = true }: G
data-selectable-text="true"
>
{MessageTextContent ? (
- <MessageTextContent text={entry.text} />
+ <MessageTextContent media={!member?.remoteSource} text={entry.text} />
) : Streamdown ? (
<Streamdown>{entry.text}</Streamdown>
) : (