* fix: extract path-security helpers and refactor IPC modules - Extracted path-security helpers from filesystem.ts into filesystem-auth.ts to fix max-lines lint error (402 -> 293 lines) - Extracted duplicated ENOENT detection into isENOENT() helper to eliminate code duplication - Fixed missing curly braces on single-line if-return in isDescendantOrEqual (lint violation) - Replaced any with unknown in test files to satisfy lint rules - All tests passing (29/29) - Lint clean (0 errors, 0 warnings) * fix: bundle preload deps for sandbox mode and fix editor test types The sandbox: true change in createMainWindow broke the app because electron-vite was externalizing @electron-toolkit/preload, producing a require() call that fails in sandboxed preload scripts. Exclude it from externalization so it gets bundled inline. Also fix type errors in editor.test.ts from the partial store setup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
88 lines
2.3 KiB
TypeScript
88 lines
2.3 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const {
|
|
onMock,
|
|
removeAllListenersMock,
|
|
setPermissionRequestHandlerMock,
|
|
registerRepoHandlersMock,
|
|
registerWorktreeHandlersMock,
|
|
registerPtyHandlersMock,
|
|
setupAutoUpdaterMock
|
|
} = vi.hoisted(() => ({
|
|
onMock: vi.fn(),
|
|
removeAllListenersMock: vi.fn(),
|
|
setPermissionRequestHandlerMock: vi.fn(),
|
|
registerRepoHandlersMock: vi.fn(),
|
|
registerWorktreeHandlersMock: vi.fn(),
|
|
registerPtyHandlersMock: vi.fn(),
|
|
setupAutoUpdaterMock: vi.fn()
|
|
}))
|
|
|
|
vi.mock('electron', () => ({
|
|
app: {},
|
|
clipboard: {},
|
|
ipcMain: {
|
|
on: onMock,
|
|
removeAllListeners: removeAllListenersMock,
|
|
removeHandler: vi.fn(),
|
|
handle: vi.fn()
|
|
}
|
|
}))
|
|
|
|
vi.mock('../ipc/repos', () => ({
|
|
registerRepoHandlers: registerRepoHandlersMock
|
|
}))
|
|
|
|
vi.mock('../ipc/worktrees', () => ({
|
|
registerWorktreeHandlers: registerWorktreeHandlersMock
|
|
}))
|
|
|
|
vi.mock('../ipc/pty', () => ({
|
|
registerPtyHandlers: registerPtyHandlersMock
|
|
}))
|
|
|
|
vi.mock('../updater', () => ({
|
|
checkForUpdates: vi.fn(),
|
|
getUpdateStatus: vi.fn(),
|
|
quitAndInstall: vi.fn(),
|
|
setupAutoUpdater: setupAutoUpdaterMock
|
|
}))
|
|
|
|
import { attachMainWindowServices } from './attach-main-window-services'
|
|
|
|
describe('attachMainWindowServices', () => {
|
|
beforeEach(() => {
|
|
onMock.mockReset()
|
|
removeAllListenersMock.mockReset()
|
|
setPermissionRequestHandlerMock.mockReset()
|
|
registerRepoHandlersMock.mockReset()
|
|
registerWorktreeHandlersMock.mockReset()
|
|
registerPtyHandlersMock.mockReset()
|
|
setupAutoUpdaterMock.mockReset()
|
|
})
|
|
|
|
it('only allows the explicit permission allowlist', () => {
|
|
const mainWindow = {
|
|
webContents: {
|
|
session: {
|
|
setPermissionRequestHandler: setPermissionRequestHandlerMock
|
|
}
|
|
}
|
|
}
|
|
const store = { flush: vi.fn() }
|
|
|
|
attachMainWindowServices(mainWindow as never, store as never)
|
|
|
|
expect(setPermissionRequestHandlerMock).toHaveBeenCalledTimes(1)
|
|
const permissionHandler = setPermissionRequestHandlerMock.mock.calls[0][0]
|
|
const callback = vi.fn()
|
|
|
|
permissionHandler(null, 'media', callback)
|
|
permissionHandler(null, 'fullscreen', callback)
|
|
permissionHandler(null, 'pointerLock', callback)
|
|
permissionHandler(null, 'clipboard-read', callback)
|
|
|
|
expect(callback.mock.calls).toEqual([[true], [true], [true], [false]])
|
|
})
|
|
})
|