Add unit tests for channel utilities and configure testing environment

- Created a new test file `channels.test.ts` to cover utilities related to channel configurations and targets.
- Implemented tests for normalizing and grouping selected channels by type, as well as building channel targets from account data and cron history.
- Mocked necessary dependencies to isolate tests and ensure accurate results.
- Updated `vite.config.ts` to set up the testing environment with jsdom and enable global variables for tests.
This commit is contained in:
duanshuwen
2026-04-18 16:12:49 +08:00
parent ee72cf7261
commit ef46c73c3e
26 changed files with 4056 additions and 186 deletions

View File

@@ -35,11 +35,6 @@ function refreshProviderRuntime(): { warnings: string[] } {
}
}
function shouldPreferUpstreamHostApi(path: string, method: string): boolean {
const pathname = new URL(path, 'http://127.0.0.1').pathname;
return method.toUpperCase() === 'GET' && pathname === '/api/channels/targets';
}
async function requestUpstreamHostApi(path: string, method: string, headers: Record<string, string> | undefined, body: unknown) {
const url = `${HOST_API_BASE_URL}${path}`;
try {
@@ -81,13 +76,6 @@ async function requestUpstreamHostApi(path: string, method: string, headers: Rec
ipcMain.handle('hostapi:fetch', async (_event, { path, method, headers, body }) => {
const normalizedMethod = method || 'GET';
if (shouldPreferUpstreamHostApi(path, normalizedMethod)) {
const upstreamPreferred = await requestUpstreamHostApi(path, normalizedMethod, headers, body);
if (upstreamPreferred.success !== false && upstreamPreferred.ok !== false) {
return upstreamPreferred;
}
}
// 1. 优先本地处理 Host API 路由(逐步对齐 ClawX
const localResult = await dispatchLocalHostApi({
path,