Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
Test what switch-buddy did untested: creating it, its chat, the intro and the start choices
Simon Flackcfbc083fe480
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-intro-store.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-intro-store.test.tsnew file mode 100644index 000000000..77271158a--- /dev/null+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-intro-store.test.ts@@ -0,0 +1,39 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';++const stored = new Map<string, string>();+vi.stubGlobal('localStorage', {+ getItem: (key: string) => stored.get(key) ?? null,+ setItem: (key: string, value: string) => void stored.set(key, value),+});++async function freshStore() {+ vi.resetModules();+ return (await import('./buddy-intro-store')).buddyIntroStore;+}++beforeEach(() => {+ stored.clear();+});++describe('buddyIntroStore', () => {+ it('asks once per workspace, and remembers the answer across launches', async () => {+ const store = await freshStore();+ expect(store.isAnswered('ws-1')).toBe(false);++ store.answered('ws-1');++ expect(store.isAnswered('ws-1')).toBe(true);+ expect(store.isAnswered('ws-2')).toBe(false);+ expect((await freshStore()).isAnswered('ws-1')).toBe(true);+ });++ it('keeps away for the rest of the launch after Skip, and asks again on the next', async () => {+ const store = await freshStore();+ expect(store.skippedThisSession).toBe(false);++ store.skipped();++ expect(store.skippedThisSession).toBe(true);+ expect((await freshStore()).skippedThisSession).toBe(false);+ });+});diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-telemetry.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-telemetry.test.tsnew file mode 100644index 000000000..2b1a66196--- /dev/null+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-telemetry.test.ts@@ -0,0 +1,53 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';++const report = vi.hoisted(() => vi.fn());+vi.mock('@renderer/lib/telemetry/report', () => ({ report }));++const { reportBuddyMessage, reportBuddyStep } = await import('./buddy-telemetry');++const buddy = { id: 'a-1', name: 'switch-buddy-max' } as never;+const helper = { id: 'a-2', name: 'helper' } as never;++beforeEach(() => {+ vi.clearAllMocks();+});++describe('reportBuddyMessage', () => {+ it('counts a message to the buddy alone as the how-manyth in its chat', () => {+ reportBuddyMessage([buddy], 0);+ reportBuddyMessage([buddy], 4);+ expect(report.mock.calls).toEqual([+ ['buddy_message_sent', { nth: '1' }],+ ['buddy_message_sent', { nth: '5' }],+ ]);+ });++ it('counts the sixth and every later one together', () => {+ reportBuddyMessage([buddy], 5);+ reportBuddyMessage([buddy], 40);+ expect(report.mock.calls).toEqual([+ ['buddy_message_sent', { nth: '6+' }],+ ['buddy_message_sent', { nth: '6+' }],+ ]);+ });++ it('says nothing of a chat with another agent, or with the buddy and others', () => {+ reportBuddyMessage([helper], 0);+ reportBuddyMessage([buddy, helper], 0);+ reportBuddyMessage([], 0);+ expect(report).not.toHaveBeenCalled();+ });+});++describe('reportBuddyStep', () => {+ it('reports a known provider as itself and anything else as none', () => {+ reportBuddyStep('start', 'codex');+ reportBuddyStep('skip', null);+ reportBuddyStep('start', 'unheard-of');+ expect(report.mock.calls).toEqual([+ ['buddy_step', { action: 'start', provider: 'codex' }],+ ['buddy_step', { action: 'skip', provider: 'none' }],+ ['buddy_step', { action: 'start', provider: 'none' }],+ ]);+ });+});diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/create-buddy.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/create-buddy.test.tsnew file mode 100644index 000000000..4d891d0c7--- /dev/null+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/create-buddy.test.ts@@ -0,0 +1,138 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';++const list = vi.hoisted(() => vi.fn());+const getTemplateDetail = vi.hoisted(() => vi.fn());+const runTemplateDocument = vi.hoisted(() => vi.fn());+const report = vi.hoisted(() => vi.fn());++vi.mock('@renderer/lib/ipc', () => ({+ rpc: {+ managedAgents: { list },+ workspaces: { getTemplateDetail, runTemplateDocument },+ },+}));+vi.mock('@renderer/lib/telemetry/report', () => ({ report }));+vi.mock('@renderer/features/workspaces/workspaces-store', () => ({+ workspacesStore: { idOnServerInScope: () => 'ws-1' },+}));++const { BuddyNotCreated, createBuddy } = await import('./create-buddy');++const input = {+ serverId: 'srv-1',+ workspaceId: 'ws-1',+ machineId: 'm-1',+ provider: 'claude',+ person: { name: 'Max Tam', email: '[email protected]' },+ entryPoint: 'onboarding' as const,+};++function created(name: string) {+ return { kind: 'created', createdAgents: [{ agentId: `id-${name}`, name }] };+}++function refused(...problems: { code: string; message: string }[]) {+ return { kind: 'refused', problems, message: 'Nothing was created.' };+}++beforeEach(() => {+ vi.clearAllMocks();+ list.mockResolvedValue([]);+ getTemplateDetail.mockResolvedValue({ name: 'switch-buddy', definition: 'version: 2' });+});++describe('createBuddy', () => {+ it('creates the buddy from the server template, under the person name', async () => {+ runTemplateDocument.mockResolvedValue(created('switch-buddy-max-tam'));++ await expect(createBuddy(input)).resolves.toEqual({+ agentId: 'id-switch-buddy-max-tam',+ name: 'switch-buddy-max-tam',+ });++ expect(getTemplateDetail).toHaveBeenCalledWith({+ workspaceId: 'ws-1',+ templateId: 'official:switch-buddy',+ });+ expect(runTemplateDocument).toHaveBeenCalledWith('ws-1', {+ template: 'version: 2',+ inputs: { agent_name: 'switch-buddy-max-tam', provider: 'claude', machine: 'm-1' },+ filled: {},+ templateName: 'switch-buddy',+ entryPoint: 'onboarding',+ });+ expect(report).toHaveBeenCalledWith('buddy_step', { action: 'created', provider: 'claude' });+ });++ it('opens the buddy the person already has rather than making a second', async () => {+ list.mockResolvedValue([{ agentId: 'a-old', name: 'switch-buddy-max' }]);++ await expect(createBuddy(input)).resolves.toEqual({+ agentId: 'a-old',+ name: 'switch-buddy-max',+ });+ expect(runTemplateDocument).not.toHaveBeenCalled();+ });++ it('never picks a name the person already uses', async () => {+ list.mockResolvedValue([{ agentId: 'a-1', name: 'switch-buddyish' }]);+ runTemplateDocument.mockResolvedValue(created('switch-buddy-max-tam'));++ await createBuddy({ ...input, person: { name: 'Max Tam', email: null } });++ expect(runTemplateDocument.mock.calls[0]![1].inputs.agent_name).toBe('switch-buddy-max-tam');+ });++ it('tries the next number when someone else in the workspace has the name', async () => {+ runTemplateDocument+ .mockResolvedValueOnce(refused({ code: 'name_taken', message: 'Taken.' }))+ .mockResolvedValueOnce(refused({ code: 'name_taken', message: 'Taken.' }))+ .mockResolvedValueOnce(created('switch-buddy-max-tam-3'));++ await expect(createBuddy(input)).resolves.toMatchObject({ name: 'switch-buddy-max-tam-3' });+ expect(runTemplateDocument.mock.calls.map((call) => call[1].inputs.agent_name)).toEqual([+ 'switch-buddy-max-tam',+ 'switch-buddy-max-tam-2',+ 'switch-buddy-max-tam-3',+ ]);+ });++ it('gives up after five taken names, and says so', async () => {+ runTemplateDocument.mockResolvedValue(refused({ code: 'name_taken', message: 'Taken.' }));++ await expect(createBuddy(input)).rejects.toThrow(/Every name tried/);+ expect(runTemplateDocument).toHaveBeenCalledTimes(5);+ expect(report).toHaveBeenCalledWith('buddy_step', {+ action: 'create_failed',+ provider: 'claude',+ });+ });++ it("fails with the server's own reasons for any other refusal", async () => {+ runTemplateDocument.mockResolvedValue(+ refused(+ { code: 'controller_offline', message: 'Your computer is offline.' },+ { code: 'provider_login_missing', message: 'Sign in to Claude.' }+ )+ );++ const error = await createBuddy(input).catch((e: unknown) => e);+ expect(error).toBeInstanceOf(BuddyNotCreated);+ expect((error as Error).message).toBe('Your computer is offline. Sign in to Claude.');+ expect(runTemplateDocument).toHaveBeenCalledTimes(1);+ });++ it('fails when the server says it created the buddy but returns no agent', async () => {+ runTemplateDocument.mockResolvedValue({ kind: 'created', createdAgents: [] });++ await expect(createBuddy(input)).rejects.toThrow(/created no agent/);+ });++ it('reports a provider telemetry does not know as none', async () => {+ runTemplateDocument.mockResolvedValue(created('switch-buddy-max-tam'));++ await createBuddy({ ...input, provider: 'something-new' });++ expect(report).toHaveBeenCalledWith('buddy_step', { action: 'created', provider: 'none' });+ });+});diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/open-buddy.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/open-buddy.test.tsnew file mode 100644index 000000000..4a7f18006--- /dev/null+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/open-buddy.test.ts@@ -0,0 +1,113 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';++const listChats = vi.hoisted(() => vi.fn());+const createChat = vi.hoisted(() => vi.fn());+const navigate = vi.hoisted(() => vi.fn());+const toast = vi.hoisted(() => vi.fn());+const focusComposerWhenOpened = vi.hoisted(() => vi.fn());+const addChat = vi.hoisted(() => vi.fn());+const titled = vi.hoisted(() => vi.fn());++vi.mock('@renderer/lib/ipc', () => ({+ rpc: { chats: { list: listChats, create: createChat } },+}));+vi.mock('@renderer/lib/stores/app-state', () => ({ appState: { navigation: { navigate } } }));+vi.mock('@renderer/lib/hooks/use-toast', () => ({ toast }));+vi.mock('@renderer/features/chats/components/chat-composer', () => ({+ focusComposerWhenOpened,+}));+vi.mock('@renderer/features/chats/stores/chats', () => ({+ chatsStore: { add: addChat },+ chatTitler: { created: titled },+}));+vi.mock('@renderer/features/switch-servers/switch-servers-store', () => ({+ switchServersStore: { statusFor: () => ({ user: { name: 'Max Tam' } }) },+}));+vi.mock('./buddy-welcome-message', () => ({+ buddyWelcomeMessage: ({ firstName, agentName }: { firstName: string; agentName: string }) =>+ `welcome ${firstName} from ${agentName}`,+}));++const { BUDDY_CHAT_NAME, openBuddyChat } = await import('./open-buddy');++const buddy = { agentId: 'a-1', name: 'switch-buddy-max' };++function chat(roomId: string, name: string, agentId = 'a-1', channelType = 'direct') {+ return { roomId, name, channelType, agents: [{ id: agentId }] };+}++beforeEach(() => {+ vi.clearAllMocks();+});++describe('openBuddyChat', () => {+ it("opens the buddy's Welcome chat when it has one", async () => {+ listChats.mockResolvedValue([chat('r-other', 'Later'), chat('r-welcome', BUDDY_CHAT_NAME)]);++ await openBuddyChat('srv-1', buddy);++ expect(createChat).not.toHaveBeenCalled();+ expect(focusComposerWhenOpened).toHaveBeenCalledWith('r-welcome');+ expect(navigate).toHaveBeenCalledWith('managedAgent', {+ serverId: 'srv-1',+ agentId: 'a-1',+ name: 'switch-buddy-max',+ roomId: 'r-welcome',+ });+ });++ it('else its newest direct chat, never a room or another agent’s chat', async () => {+ listChats.mockResolvedValue([+ chat('r-room', BUDDY_CHAT_NAME, 'a-1', 'channel_public'),+ chat('r-someone', BUDDY_CHAT_NAME, 'a-2'),+ chat('r-newest', 'Ideas'),+ chat('r-older', 'Notes'),+ ]);++ await openBuddyChat('srv-1', buddy);++ expect(createChat).not.toHaveBeenCalled();+ expect(navigate).toHaveBeenCalledWith(+ 'managedAgent',+ expect.objectContaining({ roomId: 'r-newest' })+ );+ });++ it('makes a Welcome chat, with its welcome as the greeting, when the buddy has none', async () => {+ listChats.mockResolvedValue([]);+ const made = chat('r-new', BUDDY_CHAT_NAME);+ createChat.mockResolvedValue(made);++ await openBuddyChat('srv-1', buddy);++ expect(createChat).toHaveBeenCalledWith({+ serverId: 'srv-1',+ agentIds: ['a-1'],+ name: BUDDY_CHAT_NAME,+ requestId: expect.any(String),+ greeting: 'welcome Max from switch-buddy-max',+ });+ expect(addChat).toHaveBeenCalledWith('srv-1', made);+ // Named here, so its first message does not rename it.+ expect(titled).toHaveBeenCalledWith(made, true);+ expect(navigate).toHaveBeenCalledWith(+ 'managedAgent',+ expect.objectContaining({ roomId: 'r-new' })+ );+ });++ it("still opens the buddy's page, and says why, when its chat cannot be had", async () => {+ listChats.mockRejectedValue(new Error('Switch is down.'));++ await openBuddyChat('srv-1', buddy);++ expect(toast).toHaveBeenCalledWith(+ expect.objectContaining({ title: 'Could not open the chat with switch-buddy' })+ );+ expect(navigate).toHaveBeenCalledWith('managedAgent', {+ serverId: 'srv-1',+ agentId: 'a-1',+ name: 'switch-buddy-max',+ });+ });+});diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/buddy-intro-dialog.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/buddy-intro-dialog.test.tsxnew file mode 100644index 000000000..029957741--- /dev/null+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/buddy-intro-dialog.test.tsx@@ -0,0 +1,149 @@+/**+ * The pop-up that introduces switch-buddy to someone who set Switch up+ * before it existed: shown on a server that offers the buddy, in a workspace+ * where the person has none and has not answered it, and not on the buddy's+ * own page or after Skip in this launch.+ */+import { act } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++vi.hoisted(() => {+ window.electronAPI ??= {+ invoke: () => Promise.resolve(undefined),+ eventOn: () => () => {},+ eventSend: () => {},+ } as unknown as typeof window.electronAPI;+});++const state = vi.hoisted(() => ({+ flags: { switch_buddy: true, agent_management: true },+ agents: [] as { name: string }[] | undefined,+ viewId: 'home',+ workspaceId: 'ws-1' as string | null,+ serverId: 'srv-1' as string | null,+ answered: new Set<string>(),+ skipped: false,+ navigate: vi.fn(),+ report: vi.fn(),+}));++vi.mock('@renderer/lib/hooks/useFeatureFlags', () => ({ useFeatureFlags: () => state.flags }));+vi.mock('@renderer/features/managed-agents/use-managed-agents', () => ({+ useManagedAgents: () => ({ data: state.agents }),+}));+vi.mock('@renderer/lib/layout/navigation-provider', () => ({+ useCurrentViewId: () => state.viewId,+ useNavigate: () => ({ navigate: state.navigate }),+}));+vi.mock('@renderer/features/switch-servers/switch-servers-store', () => ({+ switchServersStore: {+ get activeServerId() {+ return state.serverId;+ },+ statusFor: () => ({ user: { name: 'Max Tam' } }),+ },+}));+vi.mock('@renderer/features/workspaces/workspaces-store', () => ({+ workspacesStore: { idOnServerInScope: () => state.workspaceId },+}));+vi.mock('@renderer/features/switch-buddy/buddy-intro-store', () => ({+ buddyIntroStore: {+ get skippedThisSession() {+ return state.skipped;+ },+ isAnswered: (workspaceId: string) => state.answered.has(workspaceId),+ answered: (workspaceId: string) => state.answered.add(workspaceId),+ },+}));+vi.mock('@renderer/lib/telemetry/report', () => ({ report: state.report }));++import { BuddyIntroDialog } from '@renderer/features/switch-buddy/buddy-intro-dialog';+import '@renderer/index.css';++let container: HTMLDivElement | null = null;+let root: Root | null = null;++beforeEach(() => {+ state.flags = { switch_buddy: true, agent_management: true };+ state.agents = [];+ state.viewId = 'home';+ state.workspaceId = 'ws-1';+ state.serverId = 'srv-1';+ state.answered = new Set();+ state.skipped = false;+ state.navigate.mockClear();+ state.report.mockClear();+});++afterEach(async () => {+ await act(async () => root?.unmount());+ container?.remove();+ container = null;+ root = null;+});++async function render() {+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ await act(async () => root!.render(<BuddyIntroDialog />));+}++function shown(): boolean {+ return document.body.textContent?.includes('Your first AI assistant in Switch') ?? false;+}++function button(label: string): HTMLButtonElement {+ const found = [...document.body.querySelectorAll('button')].find((b) => b.textContent === label);+ if (!found) throw new Error(`no ${label} button`);+ return found;+}++describe('BuddyIntroDialog', () => {+ it('introduces the buddy to someone who has none', async () => {+ await render();+ expect(shown()).toBe(true);+ expect(document.body.textContent).toContain('Max');+ });++ it.each([+ ['the server does not offer switch-buddy', () => (state.flags.switch_buddy = false)],+ ['the server does not manage agents', () => (state.flags.agent_management = false)],+ ['the person already has a buddy', () => (state.agents = [{ name: 'switch-buddy-max' }])],+ ['their agents are not known yet', () => (state.agents = undefined)],+ ['it is on the buddy page already', () => (state.viewId = 'switchBuddy')],+ ['they skipped the buddy in this launch', () => (state.skipped = true)],+ ['they answered it in this workspace', () => state.answered.add('ws-1')],+ ['no workspace is open', () => (state.workspaceId = null)],+ ['no server is open', () => (state.serverId = null)],+ ])('stays away when %s', async (_, arrange) => {+ arrange();+ await render();+ expect(shown()).toBe(false);+ });++ it('Meet switch-buddy opens its page and is the answer for the workspace', async () => {+ await render();+ await act(async () => button('Meet switch-buddy').click());++ expect(state.navigate).toHaveBeenCalledWith('switchBuddy', { serverId: 'srv-1' });+ expect(state.answered.has('ws-1')).toBe(true);+ expect(state.report).toHaveBeenCalledWith('buddy_step', {+ action: 'intro_opened',+ provider: 'none',+ });+ });++ it('Not now is the answer too, and opens nothing', async () => {+ await render();+ await act(async () => button('Not now').click());++ expect(state.navigate).not.toHaveBeenCalled();+ expect(state.answered.has('ws-1')).toBe(true);+ expect(state.report).toHaveBeenCalledWith('buddy_step', {+ action: 'intro_dismissed',+ provider: 'none',+ });+ });+});diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/meet-buddy-page.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/meet-buddy-page.test.tsxnew file mode 100644index 000000000..667c8ed36--- /dev/null+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/meet-buddy-page.test.tsx@@ -0,0 +1,180 @@+/**+ * Meet switch-buddy's start choices settle once and stay as they first were:+ * the row of providers does not change under the eye as later checks come+ * back. A choice made before this computer is ready starts once it is.+ */+import { act } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++vi.hoisted(() => {+ window.electronAPI ??= {+ invoke: () => Promise.resolve(undefined),+ eventOn: () => () => {},+ eventSend: () => {},+ } as unknown as typeof window.electronAPI;+});++type Reported = { provider: string; ready: boolean; problem: string | null; detail: null };++const state = vi.hoisted(() => ({+ computer: { kind: 'starting' } as+ | { kind: 'starting' }+ | { kind: 'ready'; machine: { id: string; providers: Reported[] } }+ | { kind: 'failed'; error: string },+ early: null as Reported[] | null,+ agents: [] as { agentId: string; name: string }[],+ createBuddy: vi.fn(),+}));++vi.mock('@renderer/features/switch-buddy/use-this-computer', () => ({+ useThisComputer: () => ({+ state: state.computer,+ recheck: vi.fn(),+ earlyProviders: state.early,+ }),+}));+vi.mock('@renderer/features/switch-buddy/create-buddy', () => ({+ createBuddy: state.createBuddy,+}));+vi.mock('@renderer/features/managed-agents/use-managed-agents', () => ({+ useManagedAgents: () => ({ data: state.agents }),+}));+vi.mock('@renderer/features/switch-servers/switch-servers-store', () => ({+ switchServersStore: { statusFor: () => ({ user: { name: 'Max Tam', email: null } }) },+}));+vi.mock('@renderer/features/switch-buddy/meet-buddy-intro', () => ({+ MeetBuddyIntro: () => <p>intro</p>,+}));+vi.mock('@renderer/lib/components/agent-icon', () => ({+ AgentIcon: ({ id }: { id: string }) => <span data-provider-icon={id} />,+}));+vi.mock('@renderer/lib/telemetry/report', () => ({ report: vi.fn() }));++import { MeetBuddyPage } from '@renderer/features/switch-buddy/meet-buddy-page';+import '@renderer/index.css';++let container: HTMLDivElement | null = null;+let root: Root | null = null;+const onCreated = vi.fn();+const onSkip = vi.fn();++const ready = (provider: string): Reported => ({+ provider,+ ready: true,+ problem: null,+ detail: null,+});+const signedOut = (provider: string): Reported => ({+ provider,+ ready: false,+ problem: 'not signed in',+ detail: null,+});++function machine(...providers: Reported[]) {+ return { kind: 'ready' as const, machine: { id: 'm-1', providers } };+}++beforeEach(() => {+ state.computer = { kind: 'starting' };+ state.early = null;+ state.agents = [];+ state.createBuddy.mockReset();+ onCreated.mockReset();+});++afterEach(async () => {+ await act(async () => root?.unmount());+ container?.remove();+ container = null;+ root = null;+});++async function render() {+ if (!root) {+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ }+ // A new callback each time, so the page renders again with what the hooks+ // now say (it is memoised on its props).+ await act(async () =>+ root!.render(+ <MeetBuddyPage+ serverId="srv-1"+ workspaceId="ws-1"+ onCreated={(agent) => onCreated(agent)}+ onSkip={onSkip}+ />+ )+ );+}++function buttons(): string[] {+ return [...container!.querySelectorAll('button')].map((b) => b.textContent ?? '');+}++describe('MeetBuddyPage', () => {+ it('waits while the providers are being checked', async () => {+ await render();+ expect(container!.textContent).toContain('Checking AI providers');+ });++ it('settles on the providers first found ready, and keeps them as later checks come back', async () => {+ // Claude ready and Codex known: decided, without waiting for the others.+ state.computer = machine(ready('claude'), signedOut('codex'));+ await render();+ expect(buttons()).toEqual(['Claude Code', 'Use other AI providers']);++ // Codex signs in afterwards: the row stays as it first was.+ state.computer = machine(ready('claude'), ready('codex'));+ await render();+ expect(buttons()).toEqual(['Claude Code', 'Use other AI providers']);+ });++ it('offers to set one up, or skip, when none is ready', async () => {+ state.computer = machine(+ signedOut('claude'),+ signedOut('codex'),+ signedOut('opencode'),+ signedOut('cursor'),+ signedOut('antigravity')+ );+ await render();+ expect(buttons()).toEqual(['Skip', 'Set up AI provider']);+ });++ it("goes by Console's own early check until this computer reports", async () => {+ state.early = [ready('codex'), signedOut('claude')];+ await render();+ expect(buttons()).toEqual(['Codex', 'Use other AI providers']);+ });++ it('starts a provider chosen before this computer is ready, once it is', async () => {+ state.early = [ready('claude'), signedOut('codex')];+ state.createBuddy.mockResolvedValue({ agentId: 'a-1', name: 'switch-buddy-max-tam' });+ await render();++ await act(async () =>+ [...container!.querySelectorAll('button')]+ .find((b) => b.textContent === 'Claude Code')!+ .click()+ );+ expect(state.createBuddy).not.toHaveBeenCalled();++ state.computer = machine(ready('claude'), signedOut('codex'));+ await render();++ expect(state.createBuddy).toHaveBeenCalledWith(+ expect.objectContaining({ machineId: 'm-1', provider: 'claude', entryPoint: 'onboarding' })+ );+ expect(onCreated).toHaveBeenCalledWith({ agentId: 'a-1', name: 'switch-buddy-max-tam' });+ });++ it('offers to open the buddy someone already has', async () => {+ state.agents = [{ agentId: 'a-1', name: 'switch-buddy-max' }];+ await render();+ expect(buttons()).toEqual(['Open switch-buddy']);+ });+});