Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
test(desktop): keep packaging IO off the Vitest RPC worker
ylliuuu6675e848ed3973
diff --git a/apps/desktop/src/main/doc-tools/__tests__/fixtures/readSheetPackageProbe.mjs b/apps/desktop/src/main/doc-tools/__tests__/fixtures/readSheetPackageProbe.mjsnew file mode 100644index 0000000000..c896be2098--- /dev/null+++ b/apps/desktop/src/main/doc-tools/__tests__/fixtures/readSheetPackageProbe.mjs@@ -0,0 +1,63 @@+import fs from 'node:fs';+import { createRequire } from 'node:module';+import path from 'node:path';++import { copyRuntimeDependencyTrees } from '../../../../../forge-runtime-deps.ts';+import { prunePackagedRuntime } from '../../../../../forge-prune-runtime.ts';+import { READ_SHEET_RUNTIME_PACKAGES } from '../../../../../../../packages/lizi-mcps/src/cindy-docs/readSheetRuntimeDeps.ts';++// Run the real synchronous packaging helpers outside Vitest's RPC worker.+const [desktopRoot, temp] = process.argv.slice(2);+const workspaceRequire = createRequire(import.meta.url);++function packageDirectory(name, fromDirs) {+ const options = fromDirs ? { paths: fromDirs } : { paths: [desktopRoot] };+ try {+ return path.dirname(workspaceRequire.resolve(`${name}/package.json`, options));+ } catch {+ try {+ return path.dirname(workspaceRequire.resolve(`${name}/package`, options));+ } catch {+ // Some packages export their manifest as ./package instead of ./package.json.+ }+ let entry;+ try {+ entry = workspaceRequire.resolve(name, options);+ } catch {+ const hoisted = path.resolve(desktopRoot, '../../node_modules', name);+ if (fs.existsSync(path.join(hoisted, 'package.json'))) return hoisted;+ throw new Error(`cannot resolve package directory: ${name}`);+ }+ let current = path.dirname(entry);+ while (current !== path.dirname(current)) {+ const packageJson = path.join(current, 'package.json');+ if (fs.existsSync(packageJson)) {+ const manifest = JSON.parse(fs.readFileSync(packageJson, 'utf8'));+ if (manifest.name === name) return current;+ }+ current = path.dirname(current);+ }+ throw new Error(`cannot resolve package directory: ${name}`);+ }+}++const stagedModules = path.join(temp, 'node_modules');+copyRuntimeDependencyTrees(+ [...READ_SHEET_RUNTIME_PACKAGES, 'discord.js'],+ stagedModules,+ packageDirectory,+);+prunePackagedRuntime(temp);++const stagedRequire = createRequire(path.join(temp, 'probe.cjs'));+const ExcelJS = stagedRequire('exceljs');+const JSZip = stagedRequire('jszip');+const { Client, GatewayIntentBits, EmbedBuilder } = stagedRequire('discord.js');+const client = new Client({ intents: [GatewayIntentBits.Guilds] });+if (new EmbedBuilder().setTitle('ok').toJSON().title !== 'ok') throw Error('Discord builder');+await client.destroy();+const workbook = new ExcelJS.Workbook();+workbook.addWorksheet('Sheet1').addRow(['ok']);+const bytes = await workbook.xlsx.writeBuffer();+const zip = await JSZip.loadAsync(bytes);+process.stdout.write(zip.file('xl/workbook.xml') ? 'ok' : 'missing');diff --git a/apps/desktop/src/main/doc-tools/__tests__/readSheetProcessPackaging.test.ts b/apps/desktop/src/main/doc-tools/__tests__/readSheetProcessPackaging.test.tsindex 01907cee3e..f4760ab860 100644--- a/apps/desktop/src/main/doc-tools/__tests__/readSheetProcessPackaging.test.ts+++ b/apps/desktop/src/main/doc-tools/__tests__/readSheetProcessPackaging.test.ts@@ -1,48 +1,15 @@-import { spawnSync } from 'node:child_process';+import { execFile } from 'node:child_process';import fs from 'node:fs';-import { createRequire } from 'node:module';import os from 'node:os';import path from 'node:path';+import { promisify } from 'node:util';-import { describe, expect, it } from 'vitest';+import { describe, expect, it, onTestFinished } from 'vitest';import { READ_SHEET_RUNTIME_PACKAGES } from '../../../../../../packages/lizi-mcps/src/cindy-docs/readSheetRuntimeDeps';-import { prunePackagedRuntime } from '../../../../forge-prune-runtime';-import { copyRuntimeDependencyTrees } from '../../../../forge-runtime-deps';const desktopRoot = path.resolve(process.cwd());-const workspaceRequire = createRequire(import.meta.url);--function packageDirectory(name: string, fromDirs?: string[]): string {- const options = fromDirs ? { paths: fromDirs } : { paths: [desktopRoot] };- try {- return path.dirname(workspaceRequire.resolve(`${name}/package.json`, options));- } catch {- try {- return path.dirname(workspaceRequire.resolve(`${name}/package`, options));- } catch {- // Some packages export their manifest as ./package instead of ./package.json.- }- let entry: string;- try {- entry = workspaceRequire.resolve(name, options);- } catch {- const hoisted = path.resolve(desktopRoot, '../../node_modules', name);- if (fs.existsSync(path.join(hoisted, 'package.json'))) return hoisted;- throw new Error(`cannot resolve package directory: ${name}`);- }- let current = path.dirname(entry);- while (current !== path.dirname(current)) {- const packageJson = path.join(current, 'package.json');- if (fs.existsSync(packageJson)) {- const manifest = JSON.parse(fs.readFileSync(packageJson, 'utf8')) as { name?: string };- if (manifest.name === name) return current;- }- current = path.dirname(current);- }- throw new Error(`cannot resolve package directory: ${name}`);- }-}+const execFileAsync = promisify(execFile);describe('read_sheet XLSX worker packaging contract', () => {it('copies the worker runtime dependency closures into packaged node_modules', () => {@@ -52,46 +19,27 @@ describe('read_sheet XLSX worker packaging contract', () => {expect(forge).toContain('copyRuntimeTrees(deps, destModules, resolvePackageDir)');});- it('loads ExcelJS and JSZip from an isolated staged dependency tree', () => {- const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-read-sheet-package-'));+ it('loads ExcelJS and JSZip from an isolated staged dependency tree', async () => {+ const temp = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'cindy-read-sheet-package-'));+ const controller = new AbortController();+ onTestFinished(() => controller.abort());try {- const stagedModules = path.join(temp, 'node_modules');- copyRuntimeDependencyTrees(- [...READ_SHEET_RUNTIME_PACKAGES, 'discord.js'],- stagedModules,- packageDirectory,- );- prunePackagedRuntime(temp);- expect(fs.existsSync(path.join(stagedModules, 'exceljs', 'dist'))).toBe(false);- const probeRequirePath = path.join(temp, 'probe.cjs');- const probe = spawnSync(+ // Copying/pruning the real dependency trees can block for >60s on Windows.+ // Await a child so Vitest can process RPC replies during that synchronous IO.+ const probe = await execFileAsync(process.execPath,[- '-e',- `const { createRequire } = require('node:module');-const stagedRequire = createRequire(${JSON.stringify(probeRequirePath)});-const ExcelJS = stagedRequire('exceljs');-const JSZip = stagedRequire('jszip');-const { Client, GatewayIntentBits, EmbedBuilder } = stagedRequire('discord.js');-(async () => {- const client = new Client({ intents: [GatewayIntentBits.Guilds] });- if (new EmbedBuilder().setTitle('ok').toJSON().title !== 'ok') throw Error('Discord builder');- await client.destroy();- const workbook = new ExcelJS.Workbook();- workbook.addWorksheet('Sheet1').addRow(['ok']);- const bytes = await workbook.xlsx.writeBuffer();- const zip = await JSZip.loadAsync(bytes);- process.stdout.write(zip.file('xl/workbook.xml') ? 'ok' : 'missing');-})().catch((error) => { console.error(error); process.exitCode = 1; });`,+ '--experimental-strip-types',+ path.join(__dirname, 'fixtures', 'readSheetPackageProbe.mjs'),+ desktopRoot,+ temp,],- { cwd: temp, encoding: 'utf8' },+ { cwd: temp, encoding: 'utf8', signal: controller.signal },);- expect(probe.status, probe.stderr || String(probe.error ?? '')).toBe(0);+ expect(fs.existsSync(path.join(temp, 'node_modules', 'exceljs', 'dist'))).toBe(false);expect(probe.stdout).toBe('ok');} finally {- fs.rmSync(temp, { recursive: true, force: true });+ await fs.promises.rm(temp, { recursive: true, force: true });}- // exceljs + jszip 整棵依赖树 cp 进 tmpdir + 子进程 require 探针,纯磁盘 IO;- // 满载 Windows runner 上 60s 盖不住,放宽避免把环境慢误判为契约失败。}, 120_000);});