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
fix(switchdash): make a single check check a single thing (CHOO-1809)
Louis Amaudruz216d9b873ebd
diff --git a/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/host-setup-service.test.ts b/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/host-setup-service.test.tsnew file mode 100644index 000000000..e75f764c4--- /dev/null+++ b/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/host-setup-service.test.ts@@ -0,0 +1,164 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';++const mocks = vi.hoisted(() => ({+ getStatus: vi.fn(),+ listAgentTypeStatuses: vi.fn(),+ probe: vi.fn(),+ remoteDependencyDescriptor: vi.fn(),+ probeGhAuthStatus: vi.fn(),+}));++vi.mock('@main/core/switch-setup/remote-switch-setup', () => ({+ getRemoteSwitchSetupService: () =>+ Promise.resolve({+ getStatus: mocks.getStatus,+ listAgentTypeStatuses: mocks.listAgentTypeStatuses,+ }),+}));++vi.mock('@main/core/dependencies/remote-dependency-manager', () => ({+ getRemoteDependencyManager: vi.fn(),+ remoteDependencyDescriptor: mocks.remoteDependencyDescriptor,+}));++vi.mock('../gh-auth', () => ({+ probeGhAuthStatus: mocks.probeGhAuthStatus,+ startGhAuth: vi.fn(),+}));++vi.mock('@main/lib/logger', () => ({+ log: { warn: vi.fn(), info: vi.fn(), error: vi.fn(), child: () => ({ warn: vi.fn() }) },+}));++// The module under test reaches the plan store, the event bus and the+// reachability service at import time; all three land in Electron. None is+// involved in observing a single step.+vi.mock('./setup-plan-store', () => ({+ getSetupPlan: vi.fn(),+ saveSetupPlan: vi.fn(),+ listSetupPlans: vi.fn(),+ deleteSetupPlan: vi.fn(),+}));++vi.mock('@main/lib/events', () => ({ events: { emit: vi.fn() } }));++vi.mock('../production-host-reachability', () => ({+ hostReachabilityService: { requireReachable: vi.fn() },+}));++vi.mock('@main/core/dependencies/install-output', () => ({+ installOutput: { subscribe: vi.fn(() => () => {}) },+}));++import type { HostDependencyManager } from '@switchdash/core/deps/runtime';+import type { HostSetupStep } from '@shared/core/remote-hosts/setup';+import { checkStep } from './host-setup-service';++const SSH_HOST = 'dev-vm';++function step(patch: Partial<HostSetupStep>): HostSetupStep {+ return {+ id: 'claude:plugin',+ kind: 'agent-plugin',+ name: 'Claude Code · Switch connector',+ state: 'pending',+ outcome: null,+ version: null,+ error: null,+ output: null,+ optional: false,+ dependsOn: ['claude'],+ updatedAt: '2026-02-02T00:00:00.000Z',+ ...patch,+ };+}++const manager = { probe: mocks.probe } as unknown as HostDependencyManager;++beforeEach(() => {+ vi.clearAllMocks();+ mocks.remoteDependencyDescriptor.mockReturnValue({ name: 'Claude Code' });+});++/**+ * Checking one row must touch one agent type.+ *+ * This branch used to ask for *every* agent type's status and then discard all+ * but the one it wanted. Each discarded status ran that type's CLI over SSH, so+ * re-checking the Claude Code connector shelled out to `codex` as well — which+ * on a host without Codex produced `command not found` failures attributed to+ * the row the user had not touched, and cost two extra round trips per type.+ */+describe('checking an agent-plugin step', () => {+ it('asks about its own agent type only', async () => {+ mocks.getStatus.mockResolvedValue({+ supported: true,+ installed: true,+ installedVersion: '1.0',+ });++ await checkStep(SSH_HOST, manager, step({}));++ expect(mocks.getStatus).toHaveBeenCalledExactlyOnceWith('claude');+ });++ it('never enumerates the other agent types', async () => {+ mocks.getStatus.mockResolvedValue({+ supported: true,+ installed: true,+ installedVersion: '1.0',+ });++ await checkStep(SSH_HOST, manager, step({}));++ expect(mocks.listAgentTypeStatuses).not.toHaveBeenCalled();+ });++ it('strips the plugin suffix to get the agent id', async () => {+ mocks.getStatus.mockResolvedValue({ supported: true, installed: false });++ await checkStep(SSH_HOST, manager, step({ id: 'codex:plugin' }));++ expect(mocks.getStatus).toHaveBeenCalledWith('codex');+ });++ it('reports an installed connector as satisfied, carrying its version', async () => {+ mocks.getStatus.mockResolvedValue({+ supported: true,+ installed: true,+ installedVersion: '0.7.7',+ });++ expect(await checkStep(SSH_HOST, manager, step({}))).toEqual({+ outcome: 'satisfied',+ version: '0.7.7',+ });+ });++ it('reports an absent connector as missing', async () => {+ mocks.getStatus.mockResolvedValue({ supported: true, installed: false });++ expect(await checkStep(SSH_HOST, manager, step({}))).toEqual({ outcome: 'missing' });+ });++ it('reports unknown — not missing — for a type switchdash cannot drive', async () => {+ // "We cannot answer this" is not "it is not installed".+ mocks.getStatus.mockResolvedValue({ supported: false, installed: false });++ const result = await checkStep(SSH_HOST, manager, step({}));++ expect(result.outcome).toBe('unknown');+ expect(result.error).toContain('no longer a known agent type');+ });+});++describe('checking a core-dependency step', () => {+ it('goes to the dependency manager, not the plugin CLIs', async () => {+ mocks.probe.mockResolvedValue({ id: 'git', status: 'installed', version: '2.43.0' });++ await checkStep(SSH_HOST, manager, step({ id: 'git', kind: 'core-dependency', name: 'Git' }));++ expect(mocks.probe).toHaveBeenCalledExactlyOnceWith('git');+ expect(mocks.getStatus).not.toHaveBeenCalled();+ });+});diff --git a/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/host-setup-service.ts b/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/host-setup-service.tsindex e43cb51cd..35a507be1 100644--- a/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/host-setup-service.ts+++ b/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/host-setup-service.ts@@ -14,6 +14,7 @@ import {getRemoteDependencyManager,remoteDependencyDescriptor,} from '@main/core/dependencies/remote-dependency-manager';+import { listPlugins } from '@main/core/providers/plugin-registry';import { getRemoteSwitchSetupService } from '@main/core/switch-setup/remote-switch-setup';import { events } from '@main/lib/events';import { log } from '@main/lib/logger';@@ -44,14 +45,26 @@ import {/** Runners are per-host so two hosts can be set up at once, but a host only once. */const runners = new Map<string, HostSetupRunner>();-async function plannableAgentTypes(sshHost: string) {- const service = await getRemoteSwitchSetupService(sshHost);- const statuses = await service.listAgentTypeStatuses();- return statuses- .filter((status) => status.supported)- .map((status) => ({- agentId: status.agentId,- name: remoteDependencyDescriptor(status.agentId)?.name ?? status.agentId,+/**+ * Agent types worth planning for: those whose connector switchdash can drive.+ *+ * Read from the plugin registry, not from the host. Whether a type is+ * *supported* is a static fact about the plugin — its `switchSetup` dialect and+ * the binary it names — and asking the host meant running every agent type's+ * CLI over SSH on every plan build, purely to be told what the registry already+ * knew. Whether a type is *installed* is a per-host question, and that is what+ * the plan's own steps are for.+ */+function plannableAgentTypes() {+ return listPlugins()+ .filter(+ (plugin) =>+ plugin.capabilities.switchSetup.kind === 'cli' &&+ plugin.capabilities.hostDependency.binaryNames.length > 0+ )+ .map((plugin) => ({+ agentId: plugin.metadata.id,+ name: remoteDependencyDescriptor(plugin.metadata.id)?.name ?? plugin.metadata.id,}));}@@ -68,7 +81,7 @@ export async function ensureSetupPlan(sshHost: string): Promise<HostSetupPlan> {const plan = buildSetupPlan({sshHost,coreDependencies: CORE_DEPENDENCIES.map((dep) => ({ id: dep.id, name: dep.name })),- agentTypes: await plannableAgentTypes(sshHost),+ agentTypes: plannableAgentTypes(),existing: existing ? reconcileInterruptedPlan(existing, now) : null,now,});@@ -121,7 +134,15 @@ function runnerFor(sshHost: string, manager: HostDependencyManager): HostSetupRureturn runner;}-async function checkStep(+/**+ * Observe one step, whatever kind it is.+ *+ * Exported so the rule that checking one row touches one agent type — and no+ * others — can be tested directly; it is not obvious from the call site, and+ * getting it wrong is silent apart from stray failures against an unrelated+ * row's CLI.+ */+export async function checkStep(sshHost: string,manager: HostDependencyManager,step: HostSetupStep@@ -132,10 +153,13 @@ async function checkStep(if (step.kind === 'agent-plugin') {const service = await getRemoteSwitchSetupService(sshHost);- const statuses = await service.listAgentTypeStatuses();const agentId = stepAgentId(step);- const status = statuses.find((s) => s.agentId === agentId);- if (!status) {+ // Ask about this agent type alone. Listing every type's status and then+ // discarding all but one ran each other type's CLI over SSH as a side+ // effect, so checking one row reported failures for a different row's+ // absent CLI — and cost two extra round trips per type to do it.+ const status = await service.getStatus(agentId);+ if (!status.supported) {return {outcome: 'unknown',error: `${agentId} is no longer a known agent type on this host.`,diff --git a/dash/apps/switchdash-desktop/src/main/core/switch-setup/remote-switch-setup.ts b/dash/apps/switchdash-desktop/src/main/core/switch-setup/remote-switch-setup.tsindex a93da5211..86aefc7b8 100644--- a/dash/apps/switchdash-desktop/src/main/core/switch-setup/remote-switch-setup.ts+++ b/dash/apps/switchdash-desktop/src/main/core/switch-setup/remote-switch-setup.ts@@ -10,6 +10,9 @@ import { isNewerVersion, marketplaceMatchesSource } from './switch-setup-serviceconst EXEC_TIMEOUT_MS = 120_000;+/** POSIX shells use 127 for "command not found". */+const COMMAND_NOT_FOUND = 127;+type RunResult = { code: number; stdout: string; stderr: string };/**@@ -113,6 +116,17 @@ export class RemoteSwitchSetupService {stdout: e.stdout ?? '',stderr: e.stderr ?? e.message ?? '',};+ // A shell reports 127 when the binary is not on PATH. For "is this agent+ // type's connector installed?" that is the answer, not a fault: a host+ // without Codex is a normal host. Warning about it filled the log with+ // failures every time a plan was checked, which trains people to ignore+ // the warnings that do matter.+ if (result.code === COMMAND_NOT_FOUND) {+ log.info('[remote-switch-setup] command not present on host', {+ cmd: `${bin} ${args.join(' ')}`,+ });+ return result;+ }log.warn('[remote-switch-setup] command failed', {cmd: `${bin} ${args.join(' ')}`,code: result.code,diff --git a/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/setup-rows.tsx b/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/setup-rows.tsxindex f182db1c3..0e1b89276 100644--- a/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/setup-rows.tsx+++ b/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/setup-rows.tsx@@ -223,12 +223,6 @@ export function PrerequisiteRow({highlighted={isCurrent}action={<>- <RecheckAction- rechecking={rechecking}- disabled={hostBusy}- label={step.name}- onRecheck={onRecheck}- />{/*Signing in is this row's install: it is the one action that makes thestep satisfied, so it belongs beside it rather than one click away@@ -248,6 +242,14 @@ export function PrerequisiteRow({) : (<InstallAction step={step} installing={installing} onInstall={onInstall} />)}+ {/* Last, so the primary action keeps the same place whether or not+ there is one to take. */}+ <RecheckAction+ rechecking={rechecking}+ disabled={hostBusy}+ label={step.name}+ onRecheck={onRecheck}+ /></>}onClick={onOpen}@@ -297,12 +299,6 @@ export function AgentTypeRowItem({highlighted={isCurrent}action={<>- <RecheckAction- rechecking={rechecking}- disabled={hostBusy}- label={row.name}- onRecheck={onRecheck}- />{next ? (<InstallActionstep={next}@@ -310,6 +306,12 @@ export function AgentTypeRowItem({onInstall={() => onInstall(next.id)}/>) : null}+ <RecheckAction+ rechecking={rechecking}+ disabled={hostBusy}+ label={row.name}+ onRecheck={onRecheck}+ /></>}onClick={onOpen}