refactor(ipc): harden channels and unify IPC contracts

This commit is contained in:
test
2026-03-08 12:35:00 +08:00
parent 616e2b31a5
commit 8f3e5273e2
25 changed files with 991 additions and 1263 deletions

View File

@@ -0,0 +1,21 @@
import { describe, it, expect } from 'vitest'
import { withErrorHandling } from '../../src/main/ipc'
import { ValidationError } from '../../src/main/types/errors'
describe('IPC Result Wrapper', () => {
it('wraps successful values into IpcResult.data', async () => {
const result = await withErrorHandling(async () => ({ value: 42 }), 'test:success')
expect(result.success).toBe(true)
expect(result.data).toEqual({ value: 42 })
})
it('wraps exceptions into IpcResult.error/code', async () => {
const result = await withErrorHandling(async () => {
throw new ValidationError('Invalid input', 'VAL_INVALID_INPUT')
}, 'test:failure')
expect(result.success).toBe(false)
expect(result.error).toBe('Invalid input')
expect(result.code).toBe('VAL_INVALID_INPUT')
})
})