mirror of
https://github.com/stablyai/orca.git
synced 2026-10-30 16:47:34 +00:00
The six oversized src/main/ipc modules each carried a file-level `eslint-disable max-lines` and ran 427-671 counted lines against a 300-line budget. AGENTS.md calls for splitting rather than suppressing, and config/max-lines-baseline.txt is a shrink-only ratchet, so this removes all six suppressions and prunes their entries (341 -> 335). Pure move, no behavior change. Each file is cut along the seams it already had: pet splits into format allowlist / storage paths / symlink-safe copy / bundle manifest + import; filesystem-auth into path-containment primitives, the config-derived allow-list, and the git-registered root cache; notifications into sound selection, native lifecycle, permission probe, and burst cooldown; crash-reporting into renderer error reports, breadcrumbs, and sender. The IPC surface is proved intact rather than assumed: comparing (method, channel) multisets between HEAD and the split gives 49 registrations across 49 distinct channels on both sides. filesystem-auth's security boundary keeps its acyclic layering -- containment primitives, then allow-list, then root cache, then path-resolution orchestration -- with no layer gaining a back-edge. Also keeps clipboard-ipc-handlers.test.ts under the 800-line test budget. The split had briefly added a redundant vi.mock for isENOENT (byte-identical to the real implementation) that pushed it to 801; the mock is dropped in favor of the real function, with realpath added to the existing node:fs/promises mock. Verified: oxlint clean, ratchet passes, typecheck clean, full unit suite green (the one remaining failure is a pre-existing load flake in an untouched file, green when re-run serially), no new runtime import cycles among 617 modules, and no lint suppression added anywhere.
201 lines
6.4 KiB
TypeScript
201 lines
6.4 KiB
TypeScript
import path from 'node:path'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import {
|
|
handlers,
|
|
store,
|
|
dirEntry,
|
|
WORKTREE_FEATURE_PATH,
|
|
readdirMock,
|
|
getSshFilesystemProviderMock,
|
|
resetFilesystemIpcMocks
|
|
} from './filesystem-test-harness'
|
|
|
|
vi.mock('electron', async () => (await import('./filesystem-test-harness')).electronMock)
|
|
vi.mock('fs/promises', async () => (await import('./filesystem-test-harness')).fsPromisesMock)
|
|
vi.mock(
|
|
'../wsl-unc-delete',
|
|
async () => (await import('./filesystem-test-harness')).wslUncDeleteMock
|
|
)
|
|
vi.mock(
|
|
'../crash-reporting/crash-breadcrumb-store',
|
|
async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock
|
|
)
|
|
vi.mock(
|
|
'../local-downloaded-folder-promotion',
|
|
async () => (await import('./filesystem-test-harness')).folderPromotionMock
|
|
)
|
|
vi.mock(
|
|
'../git/status',
|
|
async () => (await import('./filesystem-test-harness')).gitStatusModuleMock
|
|
)
|
|
vi.mock(
|
|
'../git/check-ignored-paths',
|
|
async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock
|
|
)
|
|
vi.mock('../git/worktree', async () => (await import('./filesystem-test-harness')).gitWorktreeMock)
|
|
vi.mock(
|
|
'../providers/ssh-filesystem-dispatch',
|
|
async () => (await import('./filesystem-test-harness')).sshFilesystemDispatchMock
|
|
)
|
|
vi.mock(
|
|
'../providers/ssh-git-dispatch',
|
|
async () => (await import('./filesystem-test-harness')).sshGitDispatchMock
|
|
)
|
|
vi.mock(
|
|
'../text-generation/commit-message-text-generation',
|
|
async () => (await import('./filesystem-test-harness')).textGenerationModuleMock
|
|
)
|
|
vi.mock(
|
|
'../text-generation/pull-request-context',
|
|
async () => (await import('./filesystem-test-harness')).pullRequestContextMock
|
|
)
|
|
vi.mock(
|
|
'../source-control/pull-request-template',
|
|
async () => (await import('./filesystem-test-harness')).pullRequestTemplateMock
|
|
)
|
|
vi.mock(
|
|
'../source-control/pull-request-linked-issue',
|
|
async () => (await import('./filesystem-test-harness')).pullRequestLinkedIssueMock
|
|
)
|
|
|
|
import { registerFilesystemHandlers } from './filesystem'
|
|
import { invalidateAuthorizedRootsCache } from './registered-worktree-roots-cache'
|
|
|
|
describe('registerFilesystemHandlers', () => {
|
|
beforeEach(() => {
|
|
resetFilesystemIpcMocks()
|
|
// Reset module-level auth cache so each test starts with a fresh dirty
|
|
// flag — prevents stale worktree data from a prior test's cache rebuild.
|
|
invalidateAuthorizedRootsCache()
|
|
})
|
|
|
|
it('lists markdown documents recursively for a registered worktree', async () => {
|
|
readdirMock.mockImplementation(async (dirPath: string) => {
|
|
if (dirPath === WORKTREE_FEATURE_PATH) {
|
|
return [
|
|
dirEntry({ name: 'README.md', file: true }),
|
|
dirEntry({ name: 'docs', directory: true }),
|
|
dirEntry({ name: 'script.ts', file: true })
|
|
]
|
|
}
|
|
if (dirPath === path.join(WORKTREE_FEATURE_PATH, 'docs')) {
|
|
return [
|
|
dirEntry({ name: 'Guide.MDX', file: true }),
|
|
dirEntry({ name: 'notes.markdown', file: true })
|
|
]
|
|
}
|
|
return []
|
|
})
|
|
|
|
registerFilesystemHandlers(store as never)
|
|
|
|
await expect(
|
|
handlers.get('fs:listMarkdownDocuments')!(null, {
|
|
rootPath: WORKTREE_FEATURE_PATH
|
|
})
|
|
).resolves.toEqual([
|
|
{
|
|
filePath: path.join(WORKTREE_FEATURE_PATH, 'docs', 'Guide.MDX'),
|
|
relativePath: 'docs/Guide.MDX',
|
|
basename: 'Guide.MDX',
|
|
name: 'Guide'
|
|
},
|
|
{
|
|
filePath: path.join(WORKTREE_FEATURE_PATH, 'docs', 'notes.markdown'),
|
|
relativePath: 'docs/notes.markdown',
|
|
basename: 'notes.markdown',
|
|
name: 'notes'
|
|
},
|
|
{
|
|
filePath: path.join(WORKTREE_FEATURE_PATH, 'README.md'),
|
|
relativePath: 'README.md',
|
|
basename: 'README.md',
|
|
name: 'README'
|
|
}
|
|
])
|
|
})
|
|
|
|
it('skips ignored and symlinked directories when listing markdown documents', async () => {
|
|
readdirMock.mockImplementation(async (dirPath: string) => {
|
|
if (dirPath === WORKTREE_FEATURE_PATH) {
|
|
return [
|
|
dirEntry({ name: '.git', directory: true }),
|
|
dirEntry({ name: '.hidden', directory: true }),
|
|
dirEntry({ name: '.github', directory: true }),
|
|
dirEntry({ name: 'node_modules', directory: true }),
|
|
dirEntry({ name: 'linked-docs', directory: true, symlink: true }),
|
|
dirEntry({ name: 'visible.md', file: true })
|
|
]
|
|
}
|
|
if (dirPath === path.join(WORKTREE_FEATURE_PATH, '.github')) {
|
|
return [dirEntry({ name: 'CONTRIBUTING.md', file: true })]
|
|
}
|
|
throw new Error(`Unexpected readdir: ${dirPath}`)
|
|
})
|
|
|
|
registerFilesystemHandlers(store as never)
|
|
|
|
await expect(
|
|
handlers.get('fs:listMarkdownDocuments')!(null, {
|
|
rootPath: WORKTREE_FEATURE_PATH
|
|
})
|
|
).resolves.toEqual([
|
|
{
|
|
filePath: path.join(WORKTREE_FEATURE_PATH, '.github', 'CONTRIBUTING.md'),
|
|
relativePath: '.github/CONTRIBUTING.md',
|
|
basename: 'CONTRIBUTING.md',
|
|
name: 'CONTRIBUTING'
|
|
},
|
|
{
|
|
filePath: path.join(WORKTREE_FEATURE_PATH, 'visible.md'),
|
|
relativePath: 'visible.md',
|
|
basename: 'visible.md',
|
|
name: 'visible'
|
|
}
|
|
])
|
|
})
|
|
|
|
it('rejects markdown document listing for authorized but unregistered roots', async () => {
|
|
registerFilesystemHandlers(store as never)
|
|
|
|
await expect(
|
|
handlers.get('fs:listMarkdownDocuments')!(null, {
|
|
rootPath: path.resolve('/workspace/unregistered')
|
|
})
|
|
).rejects.toThrow('Access denied: unknown repository or worktree path')
|
|
|
|
expect(readdirMock).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('lists remote markdown documents through the SSH filesystem provider', async () => {
|
|
const provider = {
|
|
listFiles: vi
|
|
.fn()
|
|
.mockResolvedValue(['README.md', 'docs/guide.mdx', '../outside.md', 'src/app.ts'])
|
|
}
|
|
getSshFilesystemProviderMock.mockReturnValue(provider)
|
|
|
|
registerFilesystemHandlers(store as never)
|
|
|
|
await expect(
|
|
handlers.get('fs:listMarkdownDocuments')!(null, {
|
|
rootPath: '/home/user/project',
|
|
connectionId: 'ssh-1'
|
|
})
|
|
).resolves.toEqual([
|
|
{
|
|
filePath: '/home/user/project/docs/guide.mdx',
|
|
relativePath: 'docs/guide.mdx',
|
|
basename: 'guide.mdx',
|
|
name: 'guide'
|
|
},
|
|
{
|
|
filePath: '/home/user/project/README.md',
|
|
relativePath: 'README.md',
|
|
basename: 'README.md',
|
|
name: 'README'
|
|
}
|
|
])
|
|
})
|
|
})
|