The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): pin the edit composer's owner-routed completions with tests
Tekniumde000e6f938b
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-completions-owner-route.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-completions-owner-route.test.tsxindex 7adf5210b65..12746768201 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-completions-owner-route.test.tsx+++ b/apps/desktop/src/app/chat/composer/hooks/use-completions-owner-route.test.tsx@@ -112,6 +112,49 @@ describe('composer completions route to the session owner', () => {})})+ it('does not replay an ambient answer once the session owner resolves', async () => {+ // Before the owner hint lands the lookup rides the ambient socket (completions+ // are advisory). That answer is the launch profile's catalog; it must not be+ // served from cache for the same session once its real owner is known.+ _resetSessionOwnerHintsForTests()++ const gateway = {+ request: vi.fn(async () => ({+ categories: [{ name: 'Session', pairs: [['/launch-only', 'Launch profile command']] }],+ pairs: [['/launch-only', 'Launch profile command']]+ }))+ } as unknown as HermesGateway & { request: ReturnType<typeof vi.fn> }++ const api: { search?: Search } = {}++ function Probe() {+ api.search = useSlashCompletions({ gateway, sessionId: SESSION }).adapter.search++ return null+ }++ const view = render(<Probe />)++ const commands = (items: readonly Unstable_TriggerItem[]) =>+ items.map(item => (item.metadata as { command?: string }).command)++ expect(commands(await settle(api, ''))).toContain('/launch-only')++ setSessionOwnerHint(SESSION, OWNER)+ // A fresh composer (next popover open, a pane remount) asks the shared+ // completion cache again; only the owner-scoped key keeps it honest.+ view.unmount()+ render(<Probe />)++ const owned = commands(await settle(api, ''))++ expect(owned).toContain('/new')+ expect(owned).not.toContain('/launch-only')+ expect(routed.requestGatewayForAgent).toHaveBeenCalledWith('local', 'research', 'commands.catalog', {+ session_id: SESSION+ })+ })+it('serves @ path completions from the owning profile, not the ambient socket', async () => {const gateway = ambientGateway()const api: { search?: Search } = {}diff --git a/apps/desktop/src/components/assistant-ui/thread/user-edit-composer-owner-route.test.tsx b/apps/desktop/src/components/assistant-ui/thread/user-edit-composer-owner-route.test.tsxnew file mode 100644index 00000000000..c2691d054b8--- /dev/null+++ b/apps/desktop/src/components/assistant-ui/thread/user-edit-composer-owner-route.test.tsx@@ -0,0 +1,86 @@+// The inline message-edit composer is a second `/` palette: it must reach the+// edited session's OWNER exactly like the main composer does (#141583). Before+// it passed its sessionId, its catalog went out on the ambient socket with no+// session at all, so a non-primary-profile chat's edit palette listed the+// launch profile's commands (or nothing).+import { ExportedMessageRepository, type ThreadMessage } from '@assistant-ui/react'+import { AssistantRuntimeProvider } from '@assistant-ui/react'+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'++import type { HermesGateway } from '@/hermes'+import { useIncrementalExternalStoreRuntime } from '@/lib/incremental-external-store-runtime'+import { queryClient } from '@/lib/query-client'+import type * as GatewayStore from '@/store/gateway'+import { _resetSessionOwnerHintsForTests, setSessionOwnerHint } from '@/store/session'++import { assistantMessage, stubThreadEnvironment, stubThreadViewportSize, userMessage } from '../test-utils'++import { Thread } from '.'++const routed = vi.hoisted(() => ({ requestGatewayForAgent: vi.fn() }))++vi.mock('@/store/gateway', async importOriginal => ({+ ...(await importOriginal<typeof GatewayStore>()),+ requestGatewayForAgent: routed.requestGatewayForAgent+}))++stubThreadEnvironment()+stubThreadViewportSize()++const SESSION = 'sess-research-edit'+const OWNER = { connectionId: 'local', profile: 'research' }++const CATALOG = {+ categories: [{ name: 'Session', pairs: [['/new', 'Start a new session']] }],+ pairs: [['/new', 'Start a new session']]+}++function Harness({ gateway }: { gateway: HermesGateway }) {+ const runtime = useIncrementalExternalStoreRuntime<ThreadMessage>({+ messageRepository: ExportedMessageRepository.fromArray([userMessage(), assistantMessage()]),+ isRunning: false,+ setMessages: () => {},+ onNew: async () => {},+ onEdit: async () => {},+ onCancel: async () => {},+ onReload: async () => {}+ })++ return (+ <AssistantRuntimeProvider runtime={runtime}>+ <Thread gateway={gateway} sessionId={SESSION} />+ </AssistantRuntimeProvider>+ )+}++beforeEach(() => {+ routed.requestGatewayForAgent.mockResolvedValue(CATALOG)+ setSessionOwnerHint(SESSION, OWNER)+})++afterEach(() => {+ cleanup()+ queryClient.clear()+ _resetSessionOwnerHintsForTests()+ routed.requestGatewayForAgent.mockReset()+})++describe('message-edit composer completions', () => {+ it('fetch the `/` catalog from the edited session’s owner, not the ambient socket', async () => {+ const gateway = { request: vi.fn(async () => CATALOG) } as unknown as HermesGateway & {+ request: ReturnType<typeof vi.fn>+ }++ render(<Harness gateway={gateway} />)+ fireEvent.click(await screen.findByRole('button', { name: 'Edit message' }))+ await screen.findByRole('textbox', { name: 'Edit message' })++ await waitFor(() =>+ expect(routed.requestGatewayForAgent).toHaveBeenCalledWith('local', 'research', 'commands.catalog', {+ session_id: SESSION+ })+ )+ expect(gateway.request).not.toHaveBeenCalledWith('commands.catalog', expect.anything())+ })+})