mirror of
https://github.com/stablyai/orca
synced 2026-04-21 14:17:16 +00:00
* 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>
73 lines
2 KiB
TypeScript
73 lines
2 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const { browserWindowMock, openExternalMock } = vi.hoisted(() => ({
|
|
browserWindowMock: vi.fn(),
|
|
openExternalMock: vi.fn()
|
|
}))
|
|
|
|
vi.mock('electron', () => ({
|
|
BrowserWindow: browserWindowMock,
|
|
nativeTheme: { shouldUseDarkColors: false },
|
|
shell: { openExternal: openExternalMock }
|
|
}))
|
|
|
|
vi.mock('@electron-toolkit/utils', () => ({
|
|
is: { dev: false }
|
|
}))
|
|
|
|
vi.mock('../../../resources/icon.png?asset', () => ({
|
|
default: 'icon'
|
|
}))
|
|
|
|
vi.mock('../../../resources/icon-dev.png?asset', () => ({
|
|
default: 'icon-dev'
|
|
}))
|
|
|
|
import { createMainWindow } from './createMainWindow'
|
|
|
|
describe('createMainWindow', () => {
|
|
beforeEach(() => {
|
|
browserWindowMock.mockReset()
|
|
openExternalMock.mockReset()
|
|
})
|
|
|
|
it('enables renderer sandboxing and only opens http(s) URLs externally', () => {
|
|
const windowHandlers: Record<string, (...args: any[]) => void> = {}
|
|
const webContents = {
|
|
on: vi.fn((event, handler) => {
|
|
windowHandlers[event] = handler
|
|
}),
|
|
setZoomLevel: vi.fn(),
|
|
setWindowOpenHandler: vi.fn((handler) => {
|
|
windowHandlers.windowOpen = handler
|
|
}),
|
|
send: vi.fn()
|
|
}
|
|
const browserWindowInstance = {
|
|
webContents,
|
|
on: vi.fn(),
|
|
maximize: vi.fn(),
|
|
show: vi.fn(),
|
|
loadFile: vi.fn(),
|
|
loadURL: vi.fn()
|
|
}
|
|
browserWindowMock.mockImplementation(function () {
|
|
return browserWindowInstance
|
|
})
|
|
|
|
createMainWindow(null)
|
|
|
|
expect(browserWindowMock).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
webPreferences: expect.objectContaining({ sandbox: true })
|
|
})
|
|
)
|
|
|
|
expect(windowHandlers.windowOpen({ url: 'https://example.com' })).toEqual({ action: 'deny' })
|
|
expect(windowHandlers.windowOpen({ url: 'file:///etc/passwd' })).toEqual({ action: 'deny' })
|
|
expect(windowHandlers.windowOpen({ url: 'not a url' })).toEqual({ action: 'deny' })
|
|
|
|
expect(openExternalMock).toHaveBeenCalledTimes(1)
|
|
expect(openExternalMock).toHaveBeenCalledWith('https://example.com')
|
|
})
|
|
})
|