Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✅ test: fix test types and improve desktop ci workflow (#10552)

Arvin Xua05795348013
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 322c5cc5031..c5abbe2b3c6 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -145,6 +145,9 @@ jobs:
env:
NODE_OPTIONS: --max-old-space-size=6144
+ - name: Typecheck Desktop
+ run: pnpm typecheck
+ working-directory: apps/desktop
- name: Test Desktop Client
run: pnpm test
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 01c32deaf63..8109dc034c2 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -65,6 +65,7 @@
"happy-dom": "^20.0.11",
"http-proxy-agent": "^7.0.2",
"https-proxy-agent": "^7.0.6",
+ "i18next": "^25.6.3",
"just-diff": "^6.0.2",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
@@ -74,6 +75,7 @@
"tsx": "^4.20.6",
"typescript": "^5.9.3",
"undici": "^7.16.0",
+ "uuid": "^13.0.0",
"vite": "^7.2.4",
"vitest": "^3.2.4"
},
diff --git a/apps/desktop/src/main/controllers/__tests__/UploadFileCtr.test.ts b/apps/desktop/src/main/controllers/__tests__/UploadFileCtr.test.ts
index 7c82c9fcc2c..0429aac862c 100644
--- a/apps/desktop/src/main/controllers/__tests__/UploadFileCtr.test.ts
+++ b/apps/desktop/src/main/controllers/__tests__/UploadFileCtr.test.ts
@@ -34,10 +34,9 @@ describe('UploadFileCtr', () => {
const params = {
hash: 'abc123',
path: '/test/file.txt',
- dataType: 'base64' as const,
- data: 'dGVzdCBjb250ZW50',
+ content: new ArrayBuffer(16),
filename: 'file.txt',
- fileType: 'txt',
+ type: 'text/plain',
};
const expectedResult = { id: 'file-id-123', url: '/files/file-id-123' };
mockFileService.uploadFile.mockResolvedValue(expectedResult);
@@ -52,10 +51,9 @@ describe('UploadFileCtr', () => {
const params = {
hash: 'abc123',
path: '/test/file.txt',
- dataType: 'base64' as const,
- data: 'dGVzdCBjb250ZW50',
+ content: new ArrayBuffer(16),
filename: 'file.txt',
- fileType: 'txt',
+ type: 'text/plain',
};
const error = new Error('Upload failed');
mockFileService.uploadFile.mockRejectedValue(error);
@@ -139,10 +137,9 @@ describe('UploadFileCtr', () => {
const params = {
hash: 'xyz789',
path: '/test/newfile.txt',
- dataType: 'base64' as const,
- data: 'bmV3IGZpbGUgY29udGVudA==',
+ content: 'bmV3IGZpbGUgY29udGVudA==',
filename: 'newfile.txt',
- fileType: 'txt',
+ type: 'text/plain',
};
const expectedResult = { id: 'new-file-id', url: '/files/new-file-id' };
mockFileService.uploadFile.mockResolvedValue(expectedResult);
@@ -157,10 +154,9 @@ describe('UploadFileCtr', () => {
const params = {
hash: 'xyz789',
path: '/test/newfile.txt',
- dataType: 'base64' as const,
- data: 'bmV3IGZpbGUgY29udGVudA==',
+ content: 'bmV3IGZpbGUgY29udGVudA==',
filename: 'newfile.txt',
- fileType: 'txt',
+ type: 'text/plain',
};
const error = new Error('Create failed');
mockFileService.uploadFile.mockRejectedValue(error);
diff --git a/apps/desktop/src/main/core/infrastructure/__tests__/ProtocolManager.test.ts b/apps/desktop/src/main/core/infrastructure/__tests__/ProtocolManager.test.ts
index fbdf41ed71d..27dc34b65de 100644
--- a/apps/desktop/src/main/core/infrastructure/__tests__/ProtocolManager.test.ts
+++ b/apps/desktop/src/main/core/infrastructure/__tests__/ProtocolManager.test.ts
@@ -315,6 +315,7 @@ describe('ProtocolManager', () => {
it('should show main window and dispatch to handler', async () => {
vi.mocked(parseProtocolUrl).mockReturnValue({
action: 'install',
+ originalUrl: 'lobehub://plugin/install?url=https://example.com',
params: { url: 'https://example.com' },
urlType: 'plugin',
});
diff --git a/apps/desktop/src/main/core/ui/__tests__/Tray.test.ts b/apps/desktop/src/main/core/ui/__tests__/Tray.test.ts
index c1dc5471a42..a2bc67bf24b 100644
--- a/apps/desktop/src/main/core/ui/__tests__/Tray.test.ts
+++ b/apps/desktop/src/main/core/ui/__tests__/Tray.test.ts
@@ -242,7 +242,7 @@ describe('Tray', () => {
const templateArg = vi.mocked(Menu.buildFromTemplate).mock.calls[0][0];
const showMainWindowItem = templateArg.find((item: any) => item.label === 'Show Main Window');
- showMainWindowItem?.click?.();
+ showMainWindowItem?.click?.(null as any, null as any, null as any);
expect(mockApp.browserManager.showMainWindow).toHaveBeenCalled();
});
@@ -253,7 +253,7 @@ describe('Tray', () => {
const templateArg = vi.mocked(Menu.buildFromTemplate).mock.calls[0][0];
const quitItem = templateArg.find((item: any) => item.label === 'Quit');
- quitItem?.click?.();
+ quitItem?.click?.(null as any, null as any, null as any);
expect(app.quit).toHaveBeenCalled();
});
diff --git a/apps/desktop/src/main/utils/__tests__/file-system.test.ts b/apps/desktop/src/main/utils/__tests__/file-system.test.ts
index 2977d426e8c..32e802bc6d5 100644
--- a/apps/desktop/src/main/utils/__tests__/file-system.test.ts
+++ b/apps/desktop/src/main/utils/__tests__/file-system.test.ts
@@ -81,7 +81,7 @@ describe('file-system', () => {
vi.mocked(statSync).mockImplementation(() => {
throw new Error('ENOENT: no such file or directory');
});
- vi.mocked(mkdirSync).mockImplementation(() => {});
+ vi.mocked(mkdirSync).mockImplementation(() => undefined);
makeSureDirExist(dir);
diff --git a/apps/desktop/src/main/utils/__tests__/logger.test.ts b/apps/desktop/src/main/utils/__tests__/logger.test.ts
index 538124d9930..465b59cb9a9 100644
--- a/apps/desktop/src/main/utils/__tests__/logger.test.ts
+++ b/apps/desktop/src/main/utils/__tests__/logger.test.ts
@@ -27,7 +27,7 @@ describe('logger', () => {
});
afterEach(() => {
- delete process.env.NODE_ENV;
+ delete (process.env as NodeJS.ProcessEnv & { NODE_ENV?: string }).NODE_ENV;
delete process.env.DEBUG_VERBOSE;
});
@@ -73,7 +73,7 @@ describe('logger', () => {
describe('logger.error', () => {
it('should use electronLog.error in production', () => {
- process.env.NODE_ENV = 'production';
+ (process.env as NodeJS.ProcessEnv & { NODE_ENV?: string }).NODE_ENV = 'production';
const logger = createLogger('test:error');
logger.error('error message', { error: 'details' });
@@ -82,7 +82,7 @@ describe('logger', () => {
});
it('should use console.error in development', () => {
- process.env.NODE_ENV = 'development';
+ (process.env as NodeJS.ProcessEnv & { NODE_ENV?: string }).NODE_ENV = 'development';
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
const logger = createLogger('test:error');
logger.error('error message', { error: 'details' });
@@ -107,7 +107,7 @@ describe('logger', () => {
describe('logger.info', () => {
it('should use electronLog.info with namespace in production', () => {
- process.env.NODE_ENV = 'production';
+ (process.env as NodeJS.ProcessEnv & { NODE_ENV?: string }).NODE_ENV = 'production';
const logger = createLogger('test:info');
logger.info('info message', { data: 'value' });
@@ -118,7 +118,7 @@ describe('logger', () => {
});
it('should use debug logger in development', () => {
- process.env.NODE_ENV = 'development';
+ (process.env as NodeJS.ProcessEnv & { NODE_ENV?: string }).NODE_ENV = 'development';
const logger = createLogger('test:info');
logger.info('info message', { data: 'value' });
@@ -162,7 +162,7 @@ describe('logger', () => {
describe('logger.warn', () => {
it('should use electronLog.warn in production', () => {
- process.env.NODE_ENV = 'production';
+ (process.env as NodeJS.ProcessEnv & { NODE_ENV?: string }).NODE_ENV = 'production';
const logger = createLogger('test:warn');
logger.warn('warn message', { warning: 'details' });
@@ -171,7 +171,7 @@ describe('logger', () => {
});
it('should not use electronLog.warn in development', () => {
- process.env.NODE_ENV = 'development';
+ (process.env as NodeJS.ProcessEnv & { NODE_ENV?: string }).NODE_ENV = 'development';
const logger = createLogger('test:warn');
logger.warn('warn message');
diff --git a/apps/desktop/src/main/utils/next-electron-rsc.ts b/apps/desktop/src/main/utils/next-electron-rsc.ts
index ebd77e5e0bd..fd1dd5b7758 100644
--- a/apps/desktop/src/main/utils/next-electron-rsc.ts
+++ b/apps/desktop/src/main/utils/next-electron-rsc.ts
@@ -1,7 +1,9 @@
// copy from https://github.com/kirill-konshin/next-electron-rsc
import { serialize as serializeCookie } from 'cookie';
import { type Protocol, type Session } from 'electron';
+// @ts-ignore
import type { NextConfig } from 'next';
+// @ts-ignore
import type NextNodeServer from 'next/dist/server/next-server';
import assert from 'node:assert';
import { IncomingMessage, ServerResponse } from 'node:http';
@@ -204,7 +206,7 @@ export function createHandler({
logger.info('Initializing Next.js app for production');
// https://github.com/lobehub/lobe-chat/pull/9851
- // @ts-expect-error
+ // @ts-ignore
// noinspection JSConstantReassignment
process.env.NODE_ENV = 'production';
const next = require(resolve.sync('next', { basedir: standaloneDir }));
diff --git a/apps/desktop/src/preload/invoke.test.ts b/apps/desktop/src/preload/invoke.test.ts
index bad7d12f2f4..6910e943fb1 100644
--- a/apps/desktop/src/preload/invoke.test.ts
+++ b/apps/desktop/src/preload/invoke.test.ts
@@ -47,7 +47,8 @@ describe('invoke', () => {
const expectedResult = { processed: true };
mockIpcRendererInvoke.mockResolvedValue(expectedResult);
- const result = await invoke('someEvent' as ClientDispatchEventKey, param1, param2, param3);
+ // Use 'as any' to bypass type checking for testing multiple parameters
+ const result = await (invoke as any)('someEvent', param1, param2, param3);
expect(mockIpcRendererInvoke).toHaveBeenCalledWith('someEvent', param1, param2, param3);
expect(mockIpcRendererInvoke).toHaveBeenCalledTimes(1);
@@ -109,7 +110,8 @@ describe('invoke', () => {
const expectedResponse: TestResponse = { message: 'success', status: 200 };
mockIpcRendererInvoke.mockResolvedValue(expectedResponse);
- const result = await invoke('testEvent' as ClientDispatchEventKey);
+ // Use 'as any' to bypass type checking for testing with mock event
+ const result = (await (invoke as any)('testEvent')) as TestResponse;
expect(result).toEqual(expectedResponse);
expect(typeof result.message).toBe('string');
diff --git a/apps/desktop/src/preload/routeInterceptor.test.ts b/apps/desktop/src/preload/routeInterceptor.test.ts
index f6f6529b63a..0cdc46aa33e 100644
--- a/apps/desktop/src/preload/routeInterceptor.test.ts
+++ b/apps/desktop/src/preload/routeInterceptor.test.ts
@@ -110,7 +110,12 @@ describe('setupRouteInterceptors', () => {
it('should intercept internal link matching route pattern', async () => {
setupRouteInterceptors();
- const matchedRoute = { pathPrefix: '/desktop/devtools', targetWindow: 'devtools' };
+ const matchedRoute = {
+ description: 'Developer Tools',
+ enabled: true,
+ pathPrefix: '/desktop/devtools',
+ targetWindow: 'devtools',
+ };
vi.mocked(findMatchingRoute).mockReturnValue(matchedRoute);
const link = document.createElement('a');
@@ -142,7 +147,12 @@ describe('setupRouteInterceptors', () => {
pathname: '/desktop/devtools/console',
});
- const matchedRoute = { pathPrefix: '/desktop/devtools', targetWindow: 'devtools' };
+ const matchedRoute = {
+ description: 'Developer Tools',
+ enabled: true,
+ pathPrefix: '/desktop/devtools',
+ targetWindow: 'devtools',
+ };
vi.mocked(findMatchingRoute).mockReturnValue(matchedRoute);
const link = document.createElement('a');
@@ -183,7 +193,12 @@ describe('setupRouteInterceptors', () => {
it('should intercept pushState for matched routes', () => {
setupRouteInterceptors();
- const matchedRoute = { pathPrefix: '/desktop/devtools', targetWindow: 'devtools' };
+ const matchedRoute = {
+ description: 'Developer Tools',
+ enabled: true,
+ pathPrefix: '/desktop/devtools',
+ targetWindow: 'devtools',
+ };
vi.mocked(findMatchingRoute).mockReturnValue(matchedRoute);
const originalLength = history.length;
@@ -208,7 +223,12 @@ describe('setupRouteInterceptors', () => {
pathname: '/desktop/devtools/console',
});
- const matchedRoute = { pathPrefix: '/desktop/devtools', targetWindow: 'devtools' };
+ const matchedRoute = {
+ description: 'Developer Tools',
+ enabled: true,
+ pathPrefix: '/desktop/devtools',
+ targetWindow: 'devtools',
+ };
vi.mocked(findMatchingRoute).mockReturnValue(matchedRoute);
history.pushState({}, '', '/desktop/devtools/network');
@@ -248,7 +268,12 @@ describe('setupRouteInterceptors', () => {
it('should intercept replaceState for matched routes', () => {
setupRouteInterceptors();
- const matchedRoute = { pathPrefix: '/desktop/devtools', targetWindow: 'devtools' };
+ const matchedRoute = {
+ description: 'Developer Tools',
+ enabled: true,
+ pathPrefix: '/desktop/devtools',
+ targetWindow: 'devtools',
+ };
vi.mocked(findMatchingRoute).mockReturnValue(matchedRoute);
history.replaceState({}, '', '/desktop/devtools');
@@ -270,7 +295,12 @@ describe('setupRouteInterceptors', () => {
pathname: '/desktop/devtools/console',
});
- const matchedRoute = { pathPrefix: '/desktop/devtools', targetWindow: 'devtools' };
+ const matchedRoute = {
+ description: 'Developer Tools',
+ enabled: true,
+ pathPrefix: '/desktop/devtools',
+ targetWindow: 'devtools',
+ };
vi.mocked(findMatchingRoute).mockReturnValue(matchedRoute);
history.replaceState({}, '', '/desktop/devtools/network');
@@ -296,7 +326,12 @@ describe('setupRouteInterceptors', () => {
setupRouteInterceptors();
// First trigger a route interception to add path to preventedPaths
- const matchedRoute = { pathPrefix: '/desktop/devtools', targetWindow: 'devtools' };
+ const matchedRoute = {
+ description: 'Developer Tools',
+ enabled: true,
+ pathPrefix: '/desktop/devtools',
+ targetWindow: 'devtools',
+ };
vi.mocked(findMatchingRoute).mockReturnValue(matchedRoute);
history.pushState({}, '', '/desktop/devtools');
@@ -338,7 +373,12 @@ describe('setupRouteInterceptors', () => {
setupRouteInterceptors();
- const matchedRoute = { pathPrefix: '/desktop/devtools', targetWindow: 'devtools' };
+ const matchedRoute = {
+ description: 'Developer Tools',
+ enabled: true,
+ pathPrefix: '/desktop/devtools',
+ targetWindow: 'devtools',
+ };
vi.mocked(findMatchingRoute).mockReturnValue(matchedRoute);
history.pushState({}, '', '/desktop/devtools');
@@ -358,7 +398,12 @@ describe('setupRouteInterceptors', () => {
setupRouteInterceptors();
- const matchedRoute = { pathPrefix: '/desktop/devtools', targetWindow: 'devtools' };
+ const matchedRoute = {
+ description: 'Developer Tools',
+ enabled: true,
+ pathPrefix: '/desktop/devtools',
+ targetWindow: 'devtools',
+ };
vi.mocked(findMatchingRoute).mockReturnValue(matchedRoute);
history.pushState({}, '', '/desktop/devtools');
diff --git a/apps/desktop/src/preload/streamer.test.ts b/apps/desktop/src/preload/streamer.test.ts
index e13f23aa1ee..5428d6c99f8 100644
--- a/apps/desktop/src/preload/streamer.test.ts
+++ b/apps/desktop/src/preload/streamer.test.ts
@@ -30,9 +30,9 @@ describe('onStreamInvoke', () => {
it('should set up stream listeners and send start event', () => {
const params: ProxyTRPCRequestParams = {
- input: { query: 'test' },
- path: 'test.endpoint',
- type: 'query',
+ headers: { 'content-type': 'application/json' },
+ method: 'POST',
+ urlPath: '/trpc/lambda/test.endpoint',
};
const callbacks = {
@@ -78,9 +78,9 @@ describe('onStreamInvoke', () => {
};
const params: ProxyTRPCRequestParams = {
- input: {},
- path: 'test',
- type: 'query',
+ headers: {},
+ method: 'GET',
+ urlPath: '/trpc/test',
};
onStreamInvoke(params, callbacks);
@@ -106,9 +106,9 @@ describe('onStreamInvoke', () => {
};
const params: ProxyTRPCRequestParams = {
- input: {},
- path: 'test',
- type: 'query',
+ headers: {},
+ method: 'GET',
+ urlPath: '/trpc/test',
};
onStreamInvoke(params, callbacks);
@@ -138,9 +138,9 @@ describe('onStreamInvoke', () => {
};
const params: ProxyTRPCRequestParams = {
- input: {},
- path: 'test',
- type: 'query',
+ headers: {},
+ method: 'GET',
+ urlPath: '/trpc/test',
};
onStreamInvoke(params, callbacks);
@@ -179,9 +179,9 @@ describe('onStreamInvoke', () => {
};
const params: ProxyTRPCRequestParams = {
- input: {},
- path: 'test',
- type: 'query',
+ headers: {},
+ method: 'GET',
+ urlPath: '/trpc/test',
};
onStreamInvoke(params, callbacks);
@@ -221,9 +221,9 @@ describe('onStreamInvoke', () => {
};
const params: ProxyTRPCRequestParams = {
- input: {},
- path: 'test',
- type: 'query',
+ headers: {},
+ method: 'GET',
+ urlPath: '/trpc/test',
};
const cleanup = onStreamInvoke(params, callbacks);
@@ -255,9 +255,9 @@ describe('onStreamInvoke', () => {
};
const params: ProxyTRPCRequestParams = {
- input: {},
- path: 'test',
- type: 'query',
+ headers: {},
+ method: 'GET',
+ urlPath: '/trpc/test',
};
onStreamInvoke(params, callbacks);
@@ -290,13 +290,14 @@ describe('onStreamInvoke', () => {
};
const params: ProxyTRPCRequestParams = {
- input: {
+ body: JSON.stringify({
filters: { active: true },
query: 'complex query',
sort: { field: 'date', order: 'desc' },
- },
- path: 'complex.nested.endpoint',
- type: 'mutation',
+ }),
+ headers: { 'content-type': 'application/json', 'x-custom-header': 'value' },
+ method: 'POST',
+ urlPath: '/trpc/lambda/complex.nested.endpoint',
};
onStreamInvoke(params, callbacks);
@@ -316,9 +317,9 @@ describe('onStreamInvoke', () => {
};
const params: ProxyTRPCRequestParams = {
- input: {},
- path: 'test',
- type: 'query',
+ headers: {},
+ method: 'GET',
+ urlPath: '/trpc/test',
};
const cleanup = onStreamInvoke(params, callbacks);
@@ -346,9 +347,9 @@ describe('onStreamInvoke', () => {
};
const params: ProxyTRPCRequestParams = {
- input: {},
- path: 'test',
- type: 'query',
+ headers: {},
+ method: 'GET',
+ urlPath: '/trpc/test',
};
onStreamInvoke(params, callbacks);
diff --git a/packages/electron-client-ipc/src/events/system.ts b/packages/electron-client-ipc/src/events/system.ts
index 22550d10a58..b06d052c8aa 100644
--- a/packages/electron-client-ipc/src/events/system.ts
+++ b/packages/electron-client-ipc/src/events/system.ts
@@ -1,6 +1,4 @@
-import { ThemeAppearance } from 'antd-style';
-
-import { ElectronAppState, ThemeMode } from '../types';
+import { ElectronAppState, ThemeAppearance, ThemeMode } from '../types';
export interface SystemDispatchEvents {
checkSystemAccessibility: () => boolean | undefined;
diff --git a/packages/electron-client-ipc/src/types/system.ts b/packages/electron-client-ipc/src/types/system.ts
index 2738f305cbe..4418e27491c 100644
--- a/packages/electron-client-ipc/src/types/system.ts
+++ b/packages/electron-client-ipc/src/types/system.ts
@@ -25,3 +25,4 @@ export interface UserPathData {
}
export type ThemeMode = 'auto' | 'dark' | 'light';
+export type ThemeAppearance = 'dark' | 'light' | string;