* chore(lint): upgrade oxlint to 1.71 and enable 7 new rules Upgrade oxlint 1.67.0 -> 1.71.0 (1.72 was blocked by the repo's 3-day minimum-release-age supply-chain guard; nothing here needs it). The bump is a no-op on the existing config. Enable 3 error rules (backlog autofixed to zero in this commit) and 4 warn rules (surface signal without gating CI): error (autofixed, behavior-preserving): - unicorn/prefer-node-protocol (~1531 sites: bare builtin -> node:) - typescript/no-import-type-side-effects (~36: all-inline-type -> import type) - unicorn/no-array-reverse (19: copy-then-reverse -> toReversed) warn (real signal, current fires are test-only/correct): - unicorn/no-array-fill-with-reference-type (aliasing footgun guard) - typescript/no-unsafe-function-type (bans bare Function type) - unicorn/prefer-array-flat-map (map().flat() -> flatMap()) - unicorn/prefer-regexp-test (.match() in bool ctx -> .test()) mobile/.oxlintrc.json extends root, so it inherits all 7; the autofix ran from root and covered mobile/ too. Verification (all green): oxlint 0 errors (root+mobile+aux configs), oxfmt clean, typecheck (node+cli+web), vitest 22795 passed / 0 failed, builds (electron-vite + web + cli) succeed. node: rewrites confirmed to skip embedded SSH/CLI string payloads (AST-only); all toReversed sites verified to operate on fresh copies or write-once locals. * chore(lint): bump mobile oxlint to 1.71 so inherited rules parse mobile/ is a standalone pnpm project pinning its own oxlint@1.67, which lacks unicorn/no-array-fill-with-reference-type (needs >=1.70). Since mobile/.oxlintrc.json extends the root config, mobile CI's 'cd mobile && oxlint' failed to parse the new rule. Bump mobile to match root (1.71). Verified in mobile/: oxlint 0 errors, oxfmt --check clean, tsc --noEmit pass, vitest 978 passed / 0 failed. Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
242 lines
7.8 KiB
TypeScript
242 lines
7.8 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, vi } from 'vitest'
|
|
import {
|
|
getFolderWorkspacePathStatus,
|
|
getFolderWorkspacePathStatusForPath,
|
|
inferFolderWorkspacePathConnection
|
|
} from './folder-workspace-path-status'
|
|
import type { IFilesystemProvider } from '../providers/types'
|
|
import type { ProjectGroup, Repo } from '../../shared/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: []
|
|
},
|
|
{ getSshFilesystemProvider: () => undefined }
|
|
)
|
|
).resolves.toEqual({ path: root, exists: true })
|
|
|
|
await expect(
|
|
getFolderWorkspacePathStatusForPath(
|
|
{
|
|
folderPath: filePath,
|
|
projectGroupId: 'group-1',
|
|
projectGroups: [makeGroup({ parentPath: filePath })],
|
|
repos: []
|
|
},
|
|
{ getSshFilesystemProvider: () => undefined }
|
|
)
|
|
).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: []
|
|
},
|
|
{ getSshFilesystemProvider: () => undefined }
|
|
)
|
|
).resolves.toEqual({ path: missingPath, exists: false, reason: 'missing' })
|
|
})
|
|
|
|
it('routes inferred SSH folder scopes through the SSH filesystem provider', async () => {
|
|
const provider = {
|
|
stat: vi.fn().mockResolvedValue({ size: 0, type: 'directory', mtime: 1 })
|
|
} as unknown as IFilesystemProvider
|
|
|
|
await expect(
|
|
getFolderWorkspacePathStatusForPath(
|
|
{
|
|
folderPath: '/workspace/platform',
|
|
projectGroupId: 'group-1',
|
|
projectGroups: [makeGroup()],
|
|
repos: [makeRepo({ connectionId: 'ssh-1' })]
|
|
},
|
|
{ getSshFilesystemProvider: () => provider }
|
|
)
|
|
).resolves.toEqual({ path: '/workspace/platform', exists: true })
|
|
expect(provider.stat).toHaveBeenCalledWith('/workspace/platform')
|
|
})
|
|
|
|
it('routes explicit SSH folder scopes through SSH without child repos', async () => {
|
|
const provider = {
|
|
stat: vi.fn().mockResolvedValue({ size: 0, type: 'directory', mtime: 1 })
|
|
} as unknown as IFilesystemProvider
|
|
|
|
await expect(
|
|
getFolderWorkspacePathStatusForPath(
|
|
{
|
|
folderPath: '/workspace/platform',
|
|
projectGroupId: 'group-1',
|
|
connectionId: 'ssh-1',
|
|
projectGroups: [makeGroup({ connectionId: 'ssh-1' })],
|
|
repos: []
|
|
},
|
|
{ getSshFilesystemProvider: () => provider }
|
|
)
|
|
).resolves.toEqual({ path: '/workspace/platform', exists: true })
|
|
expect(provider.stat).toHaveBeenCalledWith('/workspace/platform')
|
|
})
|
|
|
|
it('reports unavailable when an inferred SSH provider is missing', async () => {
|
|
await expect(
|
|
getFolderWorkspacePathStatusForPath(
|
|
{
|
|
folderPath: '/workspace/platform',
|
|
projectGroupId: 'group-1',
|
|
projectGroups: [makeGroup()],
|
|
repos: [makeRepo({ connectionId: 'ssh-1' })]
|
|
},
|
|
{ getSshFilesystemProvider: () => undefined }
|
|
)
|
|
).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('supports direct path scope without a persisted project group', async () => {
|
|
const provider = {
|
|
stat: vi.fn().mockResolvedValue({ size: 0, type: 'directory', mtime: 1 })
|
|
} as unknown as IFilesystemProvider
|
|
|
|
await expect(
|
|
getFolderWorkspacePathStatus(
|
|
{
|
|
getRepos: () => [makeRepo({ connectionId: 'ssh-1' })],
|
|
getProjectGroups: () => [],
|
|
getFolderWorkspaces: () => []
|
|
},
|
|
{ scope: 'path', path: '/workspace/platform', connectionId: 'ssh-1' },
|
|
{ getSshFilesystemProvider: () => provider }
|
|
)
|
|
).resolves.toEqual({ path: '/workspace/platform', exists: true })
|
|
expect(provider.stat).toHaveBeenCalledWith('/workspace/platform')
|
|
})
|
|
|
|
it('keeps explicit SSH scopes isolated from unrelated same-path SSH repos', async () => {
|
|
const provider = {
|
|
stat: vi.fn().mockResolvedValue({ size: 0, type: 'directory', mtime: 1 })
|
|
} as unknown as IFilesystemProvider
|
|
|
|
await expect(
|
|
getFolderWorkspacePathStatusForPath(
|
|
{
|
|
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'
|
|
})
|
|
]
|
|
},
|
|
{
|
|
getSshFilesystemProvider: (connectionId) =>
|
|
connectionId === 'ssh-1' ? provider : undefined
|
|
}
|
|
)
|
|
).resolves.toEqual({ path: '/workspace/platform', exists: true })
|
|
expect(provider.stat).toHaveBeenCalledWith('/workspace/platform')
|
|
})
|
|
})
|