Files
orca/src/main/runtime/runtime-visible-catalog.test.ts
T
Neil 74863c2a88 fix(runtime): hide retained SSH rows by repo id and execution host (#29873)
A visible repo on another host sharing the retained source's repo id un-hid
the retired SSH host and its worktrees in CLI and phone listings.
2026-10-16 17:08:22 -07:00

108 lines
4.2 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
import type { Repo } from '../../shared/repo-types'
const { visibleRepos } = vi.hoisted(() => ({
visibleRepos:
vi.fn<(store: { getRepos: () => Repo[]; getSshTargets: () => unknown[] }) => Repo[]>()
}))
vi.mock('../ssh/orcad-retained-source', () => ({
visibleRepos,
visibleProjectGroups: vi.fn(() => []),
visibleFolderWorkspaces: vi.fn(() => [])
}))
const { runtimeHiddenHostIds, runtimeHiddenRepos, runtimeVisibleRepos } =
await import('./runtime-visible-catalog')
const sshTarget = { id: 'target-1', label: 'dev', host: 'dev', port: 22, username: 'dev' }
const repo = (id: string, connectionId?: string): Repo => ({
id,
...(connectionId ? { connectionId } : {}),
path: `/src/${id}`,
displayName: id,
badgeColor: '#000',
addedAt: 0
})
const storeWith = (repos: Repo[], withTargets: boolean) => ({
getRepos: () => repos,
...(withTargets ? { getSshTargets: () => [sshTarget] } : {})
})
describe('runtime visible catalog', () => {
it('lists what the desktop shows and names the rest as hidden', () => {
const all = [repo('local'), repo('retained')]
visibleRepos.mockImplementation((store) => store.getRepos().filter((r) => r.id !== 'retained'))
const store = storeWith(all, true)
expect(runtimeVisibleRepos(store).map((r) => r.id)).toEqual(['local'])
expect(runtimeHiddenRepos(store).hasRepo(all[1]!)).toBe(true)
expect(runtimeHiddenRepos(store).hasRepo(all[0]!)).toBe(false)
})
it('treats a store with no SSH targets (headless orcad) as hiding nothing of its own', () => {
visibleRepos.mockImplementation((store) => {
expect(store.getSshTargets()).toEqual([])
return store.getRepos()
})
const store = storeWith([repo('a')], false)
expect(runtimeVisibleRepos(store)).toHaveLength(1)
expect(runtimeHiddenRepos(store).size).toBe(0)
})
it('lists nothing without a store', () => {
expect(runtimeVisibleRepos(null)).toEqual([])
expect(runtimeHiddenRepos(null).size).toBe(0)
})
it('names a host known only through hidden rows, but never this machine', () => {
visibleRepos.mockImplementation((store) =>
store.getRepos().filter((r) => r.id !== 'retained' && r.id !== 'moved-local')
)
const store = storeWith(
[
repo('retained', 'target-1'),
repo('moved-local'),
repo('shared-a', 'target-2'),
repo('shared-b', 'target-2')
],
true
)
expect([...runtimeHiddenHostIds(store)]).toEqual(['ssh:target-1'])
})
it('keeps a host that still has a visible row', () => {
visibleRepos.mockImplementation((store) => store.getRepos().filter((r) => r.id !== 'a'))
const store = storeWith([repo('a', 'target-2'), repo('b', 'target-2')], true)
expect(runtimeHiddenHostIds(store).size).toBe(0)
})
describe('a repo id shared by a visible host and a retained SSH source', () => {
const local = repo('same-project')
const retained = repo('same-project', 'target-1')
const store = storeWith([local, retained], true)
// Same id on both rows: only the SSH row is the retired source.
const hideRetained = (s: { getRepos: () => Repo[] }): Repo[] =>
s.getRepos().filter((r) => r.connectionId !== 'target-1')
it('still names the retired SSH host as hidden', () => {
visibleRepos.mockImplementation(hideRetained)
expect([...runtimeHiddenHostIds(store)]).toEqual(['ssh:target-1'])
})
it('hides only the worktrees on the retained host', () => {
visibleRepos.mockImplementation(hideRetained)
const hidden = runtimeHiddenRepos(store)
expect(hidden.hasRepo(retained)).toBe(true)
expect(hidden.hasRepo(local)).toBe(false)
expect(hidden.hasWorktree({ repoId: 'same-project', hostId: 'ssh:target-1' })).toBe(true)
expect(hidden.hasWorktree({ repoId: 'same-project', hostId: 'local' })).toBe(false)
// A legacy worktree with no host cannot be placed on either row, and one row is visible.
expect(hidden.hasWorktree({ repoId: 'same-project' })).toBe(false)
})
it('hides a hostless worktree whose every row is hidden', () => {
visibleRepos.mockImplementation(() => [])
expect(runtimeHiddenRepos(store).hasWorktree({ repoId: 'same-project' })).toBe(true)
})
})
})