Files
orca/src/main/project-groups/folder-workspace-path-status.test.ts
T
OrcaWinandm4air c5224f70d8 refactor(providers): delete the SSH git and filesystem providers and relay-only wiring (#27644)
* refactor(providers): delete the SSH git and filesystem providers and relay-only wiring

* refactor(ssh): drop relay-protocol exports only the deleted stream readers used

---------

Co-authored-by: m4air <m4air@Mac.localdomain>
2026-10-11 17:48:43 -07:00

190 lines
5.6 KiB
TypeScript

import { mkdtemp, rm, writeFile } from 'node:fs/promises'
import { randomUUID } from 'node:crypto'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { describe, expect, it } from 'vitest'
import {
getFolderWorkspacePathStatus,
getFolderWorkspacePathStatusForPath,
inferFolderWorkspacePathConnection
} from './folder-workspace-path-status'
import type { ProjectGroup } from '../../shared/project-group-types'
import type { Repo } from '../../shared/repo-types'
function makeGroup(overrides: Partial<ProjectGroup> = {}): ProjectGroup {
return {
id: 'group-1',
name: 'Platform',
parentPath: '/workspace/platform',
parentGroupId: null,
createdFrom: 'folder-scan',
tabOrder: 0,
isCollapsed: false,
color: null,
createdAt: 1,
updatedAt: 1,
...overrides
}
}
function makeRepo(overrides: Partial<Repo> = {}): Repo {
return {
id: 'repo-1',
path: '/workspace/platform/api',
displayName: 'api',
badgeColor: 'gray',
addedAt: 1,
projectGroupId: 'group-1',
...overrides
}
}
describe('folder workspace path status', () => {
it('reports existing local directories and local files', async () => {
const root = await mkdtemp(join(tmpdir(), 'orca-folder-status-'))
try {
const filePath = join(root, 'notes.txt')
await writeFile(filePath, 'hello')
await expect(
getFolderWorkspacePathStatusForPath({
folderPath: root,
projectGroupId: 'group-1',
projectGroups: [makeGroup({ parentPath: root })],
repos: []
})
).resolves.toEqual({ path: root, exists: true })
await expect(
getFolderWorkspacePathStatusForPath({
folderPath: filePath,
projectGroupId: 'group-1',
projectGroups: [makeGroup({ parentPath: filePath })],
repos: []
})
).resolves.toEqual({
path: filePath,
exists: false,
reason: 'not-directory'
})
} finally {
await rm(root, { recursive: true, force: true })
}
})
it('reports missing local directories', async () => {
const missingPath = join(tmpdir(), `orca-folder-status-missing-${randomUUID()}`)
await expect(
getFolderWorkspacePathStatusForPath({
folderPath: missingPath,
projectGroupId: 'group-1',
projectGroups: [makeGroup({ parentPath: missingPath })],
repos: []
})
).resolves.toEqual({ path: missingPath, exists: false, reason: 'missing' })
})
it('reports unavailable for an inferred SSH scope, which this process does not serve', async () => {
await expect(
getFolderWorkspacePathStatusForPath({
folderPath: '/workspace/platform',
projectGroupId: 'group-1',
projectGroups: [makeGroup()],
repos: [makeRepo({ connectionId: 'ssh-1' })]
})
).resolves.toEqual({
path: '/workspace/platform',
exists: false,
reason: 'unavailable'
})
})
it('reports ambiguous connection for mixed SSH scopes', () => {
expect(
inferFolderWorkspacePathConnection({
folderPath: '/workspace/platform',
projectGroupId: 'group-1',
projectGroups: [makeGroup()],
repos: [
makeRepo({ id: 'repo-1', connectionId: 'ssh-1' }),
makeRepo({ id: 'repo-2', connectionId: 'ssh-2' })
]
})
).toEqual({ kind: 'ambiguous' })
})
it('reports ambiguous connection for mixed local and SSH scopes', () => {
expect(
inferFolderWorkspacePathConnection({
folderPath: '/workspace/platform',
projectGroupId: 'group-1',
projectGroups: [makeGroup()],
repos: [
makeRepo({ id: 'repo-1', connectionId: undefined }),
makeRepo({ id: 'repo-2', connectionId: 'ssh-1' })
]
})
).toEqual({ kind: 'ambiguous' })
})
it('reports ambiguous connection when explicit SSH scope conflicts with repos', () => {
expect(
inferFolderWorkspacePathConnection({
folderPath: '/workspace/platform',
projectGroupId: 'group-1',
connectionId: 'ssh-1',
projectGroups: [makeGroup({ connectionId: 'ssh-1' })],
repos: [
makeRepo({ id: 'repo-1', connectionId: 'ssh-1' }),
makeRepo({ id: 'repo-2', connectionId: 'ssh-2' })
]
})
).toEqual({ kind: 'ambiguous' })
})
it('reports a direct SSH path scope unavailable without a persisted project group', async () => {
await expect(
getFolderWorkspacePathStatus(
{
getRepos: () => [makeRepo({ connectionId: 'ssh-1' })],
getProjectGroups: () => [],
getFolderWorkspaces: () => []
},
{ scope: 'path', path: '/workspace/platform', connectionId: 'ssh-1' }
)
).resolves.toEqual({
path: '/workspace/platform',
exists: false,
reason: 'unavailable'
})
})
it('keeps explicit SSH scopes isolated from unrelated same-path SSH repos', () => {
expect(
inferFolderWorkspacePathConnection({
folderPath: '/workspace/platform',
projectGroupId: 'group-1',
connectionId: 'ssh-1',
projectGroups: [
makeGroup({ id: 'group-1', connectionId: 'ssh-1' }),
makeGroup({ id: 'group-2', connectionId: 'ssh-2' })
],
repos: [
makeRepo({
id: 'repo-1',
path: '/workspace/platform/api',
connectionId: 'ssh-1'
}),
makeRepo({
id: 'repo-2',
path: '/workspace/platform/api',
projectGroupId: 'group-2',
connectionId: 'ssh-2'
})
]
})
).toEqual({ kind: 'ssh', connectionId: 'ssh-1' })
})
})