From 70e997f4e5b2e2378b273e18c2e7379b22d52cec Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Wed, 21 Oct 2026 23:44:49 -0700 Subject: [PATCH] refactor(runtime): resolve a watched repo's host through the canonical routing API (#31866) * refactor(runtime): resolve a watched repo's host through the canonical routing API * test(runtime): drop an unused mock reset --- .../workspace-host-notifications.test.ts | 31 +++++++++++++++++++ .../workspace-host-notifications.ts | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/main/runtime/workspaces/workspace-host-notifications.test.ts diff --git a/src/main/runtime/workspaces/workspace-host-notifications.test.ts b/src/main/runtime/workspaces/workspace-host-notifications.test.ts new file mode 100644 index 00000000000..e05cd0779ed --- /dev/null +++ b/src/main/runtime/workspaces/workspace-host-notifications.test.ts @@ -0,0 +1,31 @@ +import { describe, expect, it } from 'vitest' +import type { Repo } from '../../../shared/repo-types' +import type { RuntimeClientEvent } from '../../../shared/runtime-client-events' +import { OrcaRuntimeService } from '../orca-runtime' +import type { RuntimeStore } from '../runtime-store-contract' + +function catalogEventsFor(repo: Repo): RuntimeClientEvent[] { + const store: Pick = { getRepos: () => [repo] } + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the catalog notification reads only repos. + const runtime = new OrcaRuntimeService(store as RuntimeStore) + const events: RuntimeClientEvent[] = [] + runtime.onClientEvent((event) => events.push(event)) + runtime.notifyWorktreeCatalogChangedForRemoteClients(repo.id) + return events.filter((event) => event.type === 'worktreesChanged') +} + +const baseRepo: Repo = { id: 'r', path: '/r', displayName: 'r', badgeColor: 'blue', addedAt: 1 } + +describe('notifyWorktreeCatalogChangedForRemoteClients', () => { + it('tells remote clients about a local repo', () => { + expect(catalogEventsFor(baseRepo)).toHaveLength(1) + }) + + it('skips an SSH repo named only by its execution host', () => { + expect(catalogEventsFor({ ...baseRepo, executionHostId: 'ssh:target-1' })).toHaveLength(0) + }) + + it('skips an SSH repo named by its legacy connection id', () => { + expect(catalogEventsFor({ ...baseRepo, connectionId: 'target-1' })).toHaveLength(0) + }) +}) diff --git a/src/main/runtime/workspaces/workspace-host-notifications.ts b/src/main/runtime/workspaces/workspace-host-notifications.ts index a69329ce337..563179c0394 100644 --- a/src/main/runtime/workspaces/workspace-host-notifications.ts +++ b/src/main/runtime/workspaces/workspace-host-notifications.ts @@ -176,7 +176,7 @@ export abstract class OrcaRuntimeWithNotifySshStateChanged extends OrcaRuntimeWi notifyWorktreeCatalogChangedForRemoteClients(repoId: string): void { this.invalidateWorktreeScanCacheForRepo(repoId) const matchingRepos = this.store?.getRepos().filter((repo) => repo.id === repoId) ?? [] - if (matchingRepos.length !== 1 || matchingRepos[0]?.connectionId) { + if (matchingRepos.length !== 1 || getRepoRoutingConnectionId(matchingRepos[0])) { return } this.notifyWorktreesChangedForRemoteClients(repoId)