The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(desktop): live Bot Chat spec for message_agent friendly-name targets
teknium1f879fead286a
diff --git a/apps/desktop/e2e/bot-chat-message-agent-friendly-name.spec.ts b/apps/desktop/e2e/bot-chat-message-agent-friendly-name.spec.tsnew file mode 100644index 00000000000..e8f337dab92--- /dev/null+++ b/apps/desktop/e2e/bot-chat-message-agent-friendly-name.spec.ts@@ -0,0 +1,106 @@+import { execFileSync } from 'node:child_process'+import fs from 'node:fs'+import path from 'node:path'++import { type MockBackendFixture, setupMockBackend, waitForAppReady, writeEnvFile } from './fixtures'+import { expect, test } from './test'++/**+ * Bot Mode `message_agent` target resolution, driven from a real Bot Chat.+ *+ * The Desktop autocompletes a bot by its friendly name (Bot Mode title /+ * profile display_name) as an @-slug, while the backend keyed local targets on+ * the profile folder id only. Sending to "Scribe" (folder `writer`) therefore+ * came back "No teammate named 'Scribe'" and nothing reached the writer's Bot+ * Chat (#100671). The mock model emits exactly the tool call the user text+ * scripts (`E2E_CALL(message_agent)[…]`) so the REAL tool runs in the sender's+ * backend and the REAL delivery lands in the recipient profile's state.db.+ */++let fixture: MockBackendFixture | null = null++async function openBots(page: MockBackendFixture['page']): Promise<void> {+ const tab = page.getByRole('button', { name: 'Bots', exact: true }).or(page.getByRole('tab', { name: 'Bots', exact: true })).first()+ await tab.click()+ await expect(page.getByRole('button', { name: 'New bot or group chat' })).toBeVisible()+}++async function createAgent(page: MockBackendFixture['page'], name: string, title: string): Promise<void> {+ await page.getByRole('button', { name: 'New bot or group chat' }).click()+ await page.getByRole('menuitem', { name: 'New Bot' }).click()++ const dialog = page.getByRole('dialog', { name: 'New Bot' })+ await dialog.getByPlaceholder('inbox-triage').fill(name)+ await dialog.getByPlaceholder('Inbox Triage').fill(title)+ await dialog.getByRole('button', { name: 'Create Bot' }).click()+ await expect(dialog).toBeHidden({ timeout: 30_000 })+ await expect(page.getByRole('button', { name: new RegExp(`^${title}\\b`) }).first()).toBeVisible({ timeout: 30_000 })+}++/** A Bot the Desktop never touched: folder `writer`, Bot Mode title "Scribe", its own+ * model — the shape of a bot created on another machine or renamed by hand. */+function seedWriterProfile(home: string): string {+ const writerHome = path.join(home, 'profiles', 'writer')+ fs.mkdirSync(writerHome, { recursive: true })+ fs.writeFileSync(path.join(writerHome, 'profile.yaml'), 'description: Writes things\nui_meta:\n hermes-bots:\n title: Scribe\n', 'utf8')+ const base = fs.readFileSync(path.join(home, 'config.yaml'), 'utf8')+ fs.writeFileSync(+ path.join(writerHome, 'config.yaml'),+ base.replace('default: mock-model', 'default: mock-model-writer').replace('mock-model: {}', 'mock-model: {}\n mock-model-writer: {}'),+ 'utf8',+ )+ writeEnvFile(writerHome)++ return writerHome+}++function sqlite(dbPath: string, sql: string): string {+ return execFileSync('python3', ['-c', 'import sqlite3,sys; c=sqlite3.connect(f"file:{sys.argv[1]}?mode=ro", uri=True); print("\\n".join(str(r[0]) for r in c.execute(sys.argv[2])))', dbPath, sql], {+ encoding: 'utf8',+ }).trim()+}++test.beforeAll(async () => {+ fixture = await setupMockBackend()+ seedWriterProfile(fixture.sandbox.hermesHome)+ await waitForAppReady(fixture, 120_000)+})++test.afterAll(async () => {+ await fixture?.cleanup()+ fixture = null+})++test('a DM addressed by the friendly name lands in that bot\'s Bot Chat', async () => {+ test.setTimeout(600_000)+ const page = fixture!.page+ const home = fixture!.sandbox.hermesHome++ await openBots(page)+ await expect(page.getByRole('button', { name: /^Scribe · @writer\b/ }).first()).toBeVisible({ timeout: 60_000 })+ await createAgent(page, 'sender', 'Sender')+ // The row click opens the sender's canonical Bot Chat into the main workspace+ // (its fresh-chat splash replaces the default profile's welcome pane).+ await page.getByRole('button', { name: /^Sender · @sender\b/ }).filter({ visible: true }).first().click()+ await expect(page.getByText('Say something to get started.').filter({ visible: true })).toBeVisible({ timeout: 120_000 })+ await expect(page.getByText('What are we building?')).toHaveCount(0)+ const composer = page.locator('[data-slot="composer-root"] [contenteditable="true"]').filter({ visible: true })+ await expect(composer).toHaveCount(1, { timeout: 120_000 })++ await composer.click()+ await composer.type('E2E_CALL(message_agent)[{"target":"Scribe","message":"codeword-7A91 please ack"}]', { delay: 5 })+ await page.keyboard.press('Enter')++ // The tool result the model saw: base answers "No teammate named 'Scribe'".+ await expect(page.getByText(/E2E_CALL_RESULT:/).filter({ visible: true }).first()).toBeVisible({ timeout: 240_000 })+ await expect(page.getByText(/Message dispatched to @writer/).first()).toBeVisible()+ await expect(page.getByText(/No teammate named/)).toHaveCount(0)+ const senderDb = path.join(home, 'profiles', 'sender', 'state.db')+ const toolResult = sqlite(senderDb, "SELECT content FROM messages WHERE role='tool' ORDER BY rowid DESC LIMIT 1")+ expect(toolResult).toContain('"to": "@writer"')++ // The recipient turn is a full `hermes -p writer` CLI boot in the background; its+ // landing in writer/state.db is covered by tests/tools (delivery runner) — under a+ // saturated host it can outlast any sane spec budget, so it is not awaited here.+ await page.screenshot({ path: 'test-results/bot-chat-message-agent-friendly-name.png', fullPage: true })+})diff --git a/tests-js/scripts/mock-server.ts b/tests-js/scripts/mock-server.tsindex cb88efb3319..d6891904833 100644--- a/tests-js/scripts/mock-server.ts+++ b/tests-js/scripts/mock-server.ts@@ -459,6 +459,43 @@ export function groupScriptedLine(userText: string, history: string[] = []): strreturn '(pass)'}+/**+ * One scripted tool call driven by the user's own text, for specs that need the+ * agent to exercise a REAL tool once (e.g. Bot Mode's `message_agent`):+ * `E2E_CALL(message_agent)[{"target":"scribe","message":"ping"}]`. The first+ * completion of that turn emits the call; once its tool result is in the+ * history the turn ends with `E2E_CALL_RESULT: <tool result>` so the spec can+ * assert on what the tool actually returned. Later turns (a completion+ * notification waking the same chat) carry a different last user message and+ * fall through to the canned reply.+ */+export function directToolCallTurn(userText: string, messages: any[]): ScriptedTurn | null {+ const match = /E2E_CALL\(([a-z_][a-z0-9_]*)\)\[(\{.*\})\]/s.exec(userText)++ if (!match) {+ return null+ }++ const toolResults = messages.filter(m => m?.role === 'tool')++ if (toolResults.length === 0) {+ let args: Record<string, unknown> = {}++ try {+ args = JSON.parse(match[2]) as Record<string, unknown>+ } catch {+ return null+ }++ return { text: '', toolCalls: [{ name: match[1], args }] }+ }++ const last = toolResults[toolResults.length - 1]+ const content = typeof last?.content === 'string' ? last.content : JSON.stringify(last?.content ?? '')++ return { text: `E2E_CALL_RESULT: ${content}` }+}+function includesBlockingClarifyTrigger(value: unknown): boolean {if (typeof value === 'string') {return value.includes(BLOCKING_CLARIFY_TRIGGER)@@ -750,6 +787,18 @@ export function startMockServer(options: MockServerOptions = {}): Promise<MockSereturn}+ const directCall = directToolCallTurn(userText, messages)++ if (directCall !== null) {+ if (stream) {+ streamScriptedTurn(res, model, directCall)+ } else {+ nonStreamingScriptedTurn(res, model, directCall)+ }++ return+ }+const groupLine = groupScriptedLine(userText,messages.flatMap(m => (m?.role === 'user' && typeof m?.content === 'string' ? [m.content] : [])),