mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 08:02:28 +00:00
Validate shell openPath targets (#5830)
Co-authored-by: brennanb2025 <brennankbenson@gmail.com>
This commit is contained in:
co-authored by
brennanb2025
parent
8ef8596ba1
commit
6f6664e744
@@ -131,6 +131,45 @@ describe('registerShellHandlers', () => {
|
||||
await expect(handler({})).resolves.toBeNull()
|
||||
})
|
||||
|
||||
describe('shell:openPath', () => {
|
||||
it('ignores relative paths', async () => {
|
||||
const handler = getHandler('shell:openPath')
|
||||
|
||||
await expect(handler({}, 'relative/workspace')).resolves.toBeUndefined()
|
||||
expect(statMock).not.toHaveBeenCalled()
|
||||
expect(showItemInFolderMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('ignores missing paths', async () => {
|
||||
statMock.mockRejectedValueOnce(new Error('missing'))
|
||||
const workspacePath = resolve('missing-workspace')
|
||||
const handler = getHandler('shell:openPath')
|
||||
|
||||
await expect(handler({}, workspacePath)).resolves.toBeUndefined()
|
||||
expect(statMock).toHaveBeenCalledWith(normalize(workspacePath))
|
||||
expect(showItemInFolderMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('reveals existing absolute paths', async () => {
|
||||
const workspacePath = resolve('workspace')
|
||||
const handler = getHandler('shell:openPath')
|
||||
|
||||
await expect(handler({}, workspacePath)).resolves.toBeUndefined()
|
||||
expect(showItemInFolderMock).toHaveBeenCalledWith(normalize(workspacePath))
|
||||
})
|
||||
|
||||
it('swallows launcher failures', async () => {
|
||||
showItemInFolderMock.mockImplementationOnce(() => {
|
||||
throw new Error('launcher unavailable')
|
||||
})
|
||||
const workspacePath = resolve('workspace')
|
||||
const handler = getHandler('shell:openPath')
|
||||
|
||||
await expect(handler({}, workspacePath)).resolves.toBeUndefined()
|
||||
expect(showItemInFolderMock).toHaveBeenCalledWith(normalize(workspacePath))
|
||||
})
|
||||
})
|
||||
|
||||
describe('shell:openInFileManager', () => {
|
||||
it('rejects relative paths', async () => {
|
||||
const handler = getHandler('shell:openInFileManager')
|
||||
|
||||
@@ -126,8 +126,10 @@ async function openWithSystemDefault(pathValue: string): Promise<boolean> {
|
||||
}
|
||||
|
||||
export function registerShellHandlers(): void {
|
||||
ipcMain.handle('shell:openPath', (_event, path: string) => {
|
||||
shell.showItemInFolder(path)
|
||||
ipcMain.handle('shell:openPath', async (_event, path: string): Promise<void> => {
|
||||
// Why: keep the legacy fire-and-forget renderer contract while reusing the
|
||||
// same absolute/existing path validation as the explicit file-manager API.
|
||||
void (await openInFileManager(path))
|
||||
})
|
||||
|
||||
ipcMain.handle(
|
||||
|
||||
Reference in New Issue
Block a user