Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

test: retire duplicate read-sheet packaging fix

xuzini-xznda6a0196a603
diff --git a/apps/desktop/scripts/fixtures/read-sheet-runtime-probe.mjs b/apps/desktop/scripts/fixtures/read-sheet-runtime-probe.mjs
deleted file mode 100644
index fe7ddc29da..0000000000
--- a/apps/desktop/scripts/fixtures/read-sheet-runtime-probe.mjs
+++ /dev/null
@@ -1,63 +0,0 @@
-// Run the real synchronous packaging helpers outside the Vitest worker so
-// large dependency trees cannot starve its RPC event loop on Windows.
-import fs from 'node:fs';
-import { createRequire } from 'node:module';
-import path from 'node:path';
-import { fileURLToPath } from 'node:url';
-
-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';
-
-const desktopRoot = fileURLToPath(new URL('../../', import.meta.url));
-const workspaceRequire = createRequire(import.meta.url);
-const temp = process.argv[2];
-if (!temp) throw new Error('missing staging directory');
-
-function packageDirectory(name, fromDirs) {
- const options = { paths: fromDirs ?? [desktopRoot] };
- for (const manifest of [`${name}/package.json`, `${name}/package`]) {
- try {
- return path.dirname(workspaceRequire.resolve(manifest, options));
- } catch { /* Some packages do not export their manifest. */ }
- }
- 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 manifest = path.join(current, 'package.json');
- if (fs.existsSync(manifest) && JSON.parse(fs.readFileSync(manifest, 'utf8')).name === name) {
- return current;
- }
- current = path.dirname(current);
- }
- throw new Error(`cannot resolve package directory: ${name}`);
-}
-
-copyRuntimeDependencyTrees(
- [...READ_SHEET_RUNTIME_PACKAGES, 'discord.js'],
- path.join(temp, 'node_modules'),
- packageDirectory,
-);
-process.stderr.write('runtime dependencies staged\n');
-prunePackagedRuntime(temp);
-process.stderr.write('runtime dependencies pruned\n');
-
-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 new 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.ts
index 4d68108c55..01907cee3e 100644
--- a/apps/desktop/src/main/doc-tools/__tests__/readSheetProcessPackaging.test.ts
+++ b/apps/desktop/src/main/doc-tools/__tests__/readSheetProcessPackaging.test.ts
@@ -1,22 +1,48 @@
-import { execFile } from 'node:child_process';
+import { spawnSync } 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 { afterEach, describe, expect, it } from 'vitest';
+import { describe, expect, it } 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 execFileAsync = promisify(execFile);
-let cleanup: (() => Promise<void>) | undefined;
+const workspaceRequire = createRequire(import.meta.url);
-afterEach(async () => {
- const dispose = cleanup;
- cleanup = undefined;
- await dispose?.();
-});
+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}`);
+ }
+}
describe('read_sheet XLSX worker packaging contract', () => {
it('copies the worker runtime dependency closures into packaged node_modules', () => {
@@ -26,26 +52,46 @@ 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', async () => {
- const temp = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'cindy-read-sheet-package-'));
- const abort = new AbortController();
- const pending = execFileAsync(process.execPath, [
- '--experimental-strip-types',
- path.join(desktopRoot, 'scripts/fixtures/read-sheet-runtime-probe.mjs'),
- temp,
- ], { cwd: temp, encoding: 'utf8', signal: abort.signal, timeout: 120_000, windowsHide: true });
- const closed = new Promise<void>((resolve) => pending.child.once('close', () => resolve()));
- cleanup = async () => {
- abort.abort();
- await pending.catch(() => undefined);
- await closed;
- await fs.promises.rm(temp, { recursive: true, force: true });
- };
- const probe = await pending; // Nonzero exits reject, including runtime import failures.
- expect(fs.existsSync(path.join(temp, 'node_modules', 'exceljs', 'dist'))).toBe(false);
- expect(probe.stdout).toBe('ok');
- // CI #6973: synchronous staging/cleanup blocked Vitest RPC for >60s on
- // Windows. Keep the real dependency closure and original 120s test budget;
- // yield during staging and clean up in the separately bounded lifecycle hook.
+ it('loads ExcelJS and JSZip from an isolated staged dependency tree', () => {
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-read-sheet-package-'));
+ 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(
+ 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; });`,
+ ],
+ { cwd: temp, encoding: 'utf8' },
+ );
+ expect(probe.status, probe.stderr || String(probe.error ?? '')).toBe(0);
+ expect(probe.stdout).toBe('ok');
+ } finally {
+ fs.rmSync(temp, { recursive: true, force: true });
+ }
+ // exceljs + jszip 整棵依赖树 cp 进 tmpdir + 子进程 require 探针,纯磁盘 IO;
+ // 满载 Windows runner 上 60s 盖不住,放宽避免把环境慢误判为契约失败。
}, 120_000);
});