mirror of
https://github.com/hanzo-studio/studio-desktop.git
synced 2026-10-30 18:54:12 +00:00
Replaces Electron's `any`-typed IPC with compile-time type safety. ### Type Contract - Central `IpcChannels` interface defines all channels with param/return types - Compile-time tests ensure complete coverage of `IPC_CHANNELS` - `strictIpcMain`/`strictIpcRenderer` wrappers enforce type contract ### Migration - All IPC usage migrated to type-safe wrappers - ESLint prevents import of untyped `ipcMain`/`ipcRenderer` - Fixed pre-existing type mismatches discovered during migration ### API Fixes - Terminal write: Returns `void` instead of `string` - Download pause/resume/cancel: Return `void` instead of `boolean` - Validation complete: Marked as returning incorrect type - Validate installation: Marked as returning incorrect type - Terminal restore: Marked as potentially `undefined` - Get base path: Correctly typed as `string | undefined` - Get GPU: Needs API fix to send `GpuType` instead of `TorchDeviceType` ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-1366-Type-safe-IPC-system-2866d73d365081ffb02ac1d2dce7ce62) by [Unito](https://www.unito.io)
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { describe, expectTypeOf, test } from 'vitest';
|
|
|
|
import { IPC_CHANNELS } from '@/constants';
|
|
import type { IpcChannels } from '@/infrastructure/ipcChannels';
|
|
|
|
type ChannelName = (typeof IPC_CHANNELS)[keyof typeof IPC_CHANNELS];
|
|
|
|
describe('IpcChannels type contract', () => {
|
|
test('IpcChannels includes all channels from IPC_CHANNELS', () => {
|
|
type MissingChannels = Exclude<ChannelName, keyof IpcChannels>;
|
|
expectTypeOf<MissingChannels>().toEqualTypeOf<never>();
|
|
});
|
|
|
|
test('IpcChannels does not have extra channels not in IPC_CHANNELS', () => {
|
|
type ExtraChannels = Exclude<keyof IpcChannels, ChannelName>;
|
|
expectTypeOf<ExtraChannels>().toEqualTypeOf<never>();
|
|
});
|
|
|
|
test('All channels have params and return properties', () => {
|
|
// Verify structure of each channel
|
|
type AllChannelsValid = {
|
|
[K in keyof IpcChannels]: IpcChannels[K] extends { params: unknown[]; return: unknown } ? true : never;
|
|
};
|
|
|
|
// This will error if any channel doesn't have the correct structure
|
|
expectTypeOf<AllChannelsValid>().toMatchObjectType<Record<keyof IpcChannels, true>>();
|
|
});
|
|
});
|