Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(switchdash): only offer a CLI update switchdash can actually perform (CHOO-1809)

Louis Amaudruz9fddabc63bd6
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.ts
index 9c0ef9b81..4a4ecffbf 100644
--- 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.ts
@@ -5,6 +5,8 @@ const mocks = vi.hoisted(() => ({
checkForUpdates: vi.fn(),
listAgentTypeStatuses: vi.fn(),
probe: vi.fn(),
+ getHostDependency: vi.fn(),
+ enrichHostDependency: vi.fn(),
remoteDependencyDescriptor: vi.fn(),
probeGhAuthStatus: vi.fn(),
getUpdateInfo: vi.fn(),
@@ -20,7 +22,10 @@ vi.mock('@main/core/switch-setup/remote-switch-setup', () => ({
}));
vi.mock('@main/core/dependencies/agent-update-service', () => ({
- agentUpdateService: { getUpdateInfo: mocks.getUpdateInfo },
+ agentUpdateService: {
+ getUpdateInfo: mocks.getUpdateInfo,
+ enrichHostDependency: mocks.enrichHostDependency,
+ },
}));
vi.mock('@main/core/dependencies/remote-dependency-manager', () => ({
@@ -83,7 +88,24 @@ function step(patch: Partial<HostSetupStep>): HostSetupStep {
};
}
-const manager = { probe: mocks.probe } as unknown as HostDependencyManager;
+const manager = {
+ probe: mocks.probe,
+ getHostDependency: mocks.getHostDependency,
+} as unknown as HostDependencyManager;
+
+/** An installation as the manager reports it, enriched with update info. */
+function installation(patch: Record<string, unknown> = {}) {
+ return {
+ realpath: '/usr/lib/node_modules/@openai/codex/bin/codex.js',
+ version: '2.1.0',
+ isActive: true,
+ manageable: true,
+ latestVersion: '2.2.0',
+ updateAvailable: true,
+ provenance: { kind: 'npm', confidence: 'confirmed' },
+ ...patch,
+ };
+}
/** A full connector status, the shape the service always returns. */
function status(patch: Record<string, unknown> = {}) {
@@ -211,6 +233,8 @@ describe('update detection', () => {
// for local agents answers here — no extra SSH to find it out.
mocks.probe.mockResolvedValue({ id: 'claude', status: 'installed', version: '2.1.0' });
mocks.getUpdateInfo.mockReturnValue({ latestVersion: '2.2.0', updateAvailable: true });
+ mocks.getHostDependency.mockReturnValue({ installations: [installation()] });
+ mocks.enrichHostDependency.mockReturnValue({ installations: [installation()] });
const result = await checkStep(
SSH_HOST,
@@ -303,3 +327,86 @@ describe('readAllSetupPlans', () => {
expect(saveSetupPlan).not.toHaveBeenCalled();
});
});
+
+/**
+ * A newer version existing is not the same as being able to install it.
+ *
+ * Reported from a real host: Codex read "Update available", Update failed, and
+ * the row went back to "Update available". The version comparison was right —
+ * a newer Codex does exist — but the installation lived in a root-owned npm
+ * prefix that switchdash cannot write to, so the update could never have run.
+ * The agents page gates this through `installationCanUpdate`; this path did not.
+ */
+describe('offering a CLI update only when it can be carried out', () => {
+ const cliStep = () =>
+ step({ id: 'codex', kind: 'agent-cli', name: 'Codex', dependsOn: ['node'] });
+
+ beforeEach(() => {
+ mocks.probe.mockResolvedValue({ id: 'codex', status: 'installed', version: '0.146.0' });
+ mocks.getUpdateInfo.mockReturnValue({ latestVersion: '0.147.0', updateAvailable: true });
+ });
+
+ it('offers the update when the installation is one we can drive', async () => {
+ const enriched = { installations: [installation({ updateAvailable: true })] };
+ mocks.getHostDependency.mockReturnValue(enriched);
+ mocks.enrichHostDependency.mockReturnValue(enriched);
+
+ expect(await checkStep(SSH_HOST, manager, cliStep())).toMatchObject({
+ updateAvailable: true,
+ });
+ });
+
+ it('withholds it when the installation is not manageable', async () => {
+ // Same version difference, but nothing switchdash could do about it.
+ const enriched = {
+ installations: [installation({ manageable: false, updateAvailable: false })],
+ };
+ mocks.getHostDependency.mockReturnValue(enriched);
+ mocks.enrichHostDependency.mockReturnValue(enriched);
+
+ expect(await checkStep(SSH_HOST, manager, cliStep())).toMatchObject({
+ updateAvailable: false,
+ });
+ });
+
+ it('still reports the newer version it found', async () => {
+ // Withholding the *offer* is not a reason to withhold the fact. The sheet
+ // can still say what exists upstream.
+ const enriched = {
+ installations: [installation({ manageable: false, updateAvailable: false })],
+ };
+ mocks.getHostDependency.mockReturnValue(enriched);
+ mocks.enrichHostDependency.mockReturnValue(enriched);
+
+ expect(await checkStep(SSH_HOST, manager, cliStep())).toMatchObject({
+ latestVersion: '0.147.0',
+ });
+ });
+
+ it('withholds it when the host detail has not been built yet', async () => {
+ // Host detail is populated asynchronously after the probe. Not knowing
+ // whether an update can be performed is not grounds for offering it.
+ mocks.getHostDependency.mockReturnValue(undefined);
+
+ expect(await checkStep(SSH_HOST, manager, cliStep())).toMatchObject({
+ updateAvailable: false,
+ });
+ });
+
+ it('judges the active installation, not whichever comes first', async () => {
+ // Several copies of a CLI on one PATH is ordinary. The one that answers is
+ // the one whose updateability matters.
+ const enriched = {
+ installations: [
+ installation({ isActive: false, manageable: true, updateAvailable: true }),
+ installation({ isActive: true, manageable: false, updateAvailable: false }),
+ ],
+ };
+ mocks.getHostDependency.mockReturnValue(enriched);
+ mocks.enrichHostDependency.mockReturnValue(enriched);
+
+ expect(await checkStep(SSH_HOST, manager, cliStep())).toMatchObject({
+ updateAvailable: false,
+ });
+ });
+});
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.ts
index 9a688f9dc..e11456288 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
@@ -240,10 +240,32 @@ export async function checkStep(
// not the machine — so the same coordinator that answers for local agents
// answers here, given this host's own installed version. No extra SSH.
const update = agentUpdateService.getUpdateInfo(step.id as DependencyId, result.version ?? null);
+
+ // A newer version existing is not the same as switchdash being able to
+ // install it. Whether an installation can be driven at all depends on how it
+ // got there: `installationCanUpdate` says no for one whose provenance we
+ // could not confirm, because the update would run some package manager's
+ // command against files it does not own. The agents page has always applied
+ // that gate; this path compared versions and skipped it, so a host page could
+ // offer Update over an installation the manager then refuses outright with
+ // `no-update-strategy` — or, on a root-owned npm prefix, with EACCES. Either
+ // way the row bounced straight back to "Update available", which reads as the
+ // page being confused rather than the update being impossible.
+ const hostDependency = manager.getHostDependency(step.id as DependencyId);
+ const active = hostDependency
+ ? (agentUpdateService
+ .enrichHostDependency(step.id as DependencyId, hostDependency)
+ .installations.find((installation) => installation.isActive) ?? null)
+ : null;
+
return {
...result,
latestVersion: update.latestVersion,
- updateAvailable: update.updateAvailable,
+ // Host detail is built asynchronously after the probe, so the very first
+ // check of a dependency may not have it yet. Withhold the claim rather than
+ // guess: the next check has it, and under-reporting an update is a great
+ // deal cheaper than offering one that cannot be carried out.
+ updateAvailable: active?.updateAvailable ?? false,
};
}