Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
test(companions): exercise interpreter links on Windows
Chris90d283c3b370
diff --git a/apps/desktop/src/main/bot-import/__tests__/files.test.ts b/apps/desktop/src/main/bot-import/__tests__/files.test.tsindex fc71360968..e57f29c2ef 100644--- a/apps/desktop/src/main/bot-import/__tests__/files.test.ts+++ b/apps/desktop/src/main/bot-import/__tests__/files.test.ts@@ -124,20 +124,21 @@ it('copies native venv interpreter aliases while keeping unrelated external linkconst root = await fs.mkdtemp(path.join(os.tmpdir(), 'cindy-import-venv-'));try {const skill = path.join(root, 'skill'), runtime = path.join(root, 'runtime');- const bin = path.join(skill, '.venv', 'bin');+ const binName = `.venv/${process.platform === 'win32' ? 'Scripts' : 'bin'}`;+ const bin = path.join(skill, binName);await fs.mkdir(bin, { recursive: true }); await fs.mkdir(runtime);await fs.writeFile(path.join(skill, 'SKILL.md'), '# Fixture');await fs.writeFile(path.join(skill, '.venv/pyvenv.cfg'), `home = ${runtime}\n`);const executable = Buffer.from('7f454c460102030405060708', 'hex');await fs.writeFile(path.join(runtime, 'python3.12'), executable, { mode: 0o700 });- try { await fs.symlink(path.join(runtime, 'python3.12'), path.join(bin, 'python')); }+ try { await fs.symlink(path.join(runtime, 'python3.12'), path.join(bin, 'python'), 'file'); }catch (error) { if ((error as NodeJS.ErrnoException).code === 'EPERM') { ctx.skip(); return; } throw error; }- await fs.symlink('python', path.join(bin, 'python3'));+ await fs.symlink('python', path.join(bin, 'python3'), 'file');const files = await readImportSkillTree(skill, undefined, createImportBudget());- for (const name of ['.venv/bin/python', '.venv/bin/python3']) expect(files.find(file => file.name === name)).toMatchObject({ bytes: executable, interpreterLink: await fs.realpath(path.join(runtime, 'python3.12')) });+ for (const name of [`${binName}/python`, `${binName}/python3`]) expect(files.find(file => file.name === name)).toMatchObject({ bytes: executable, interpreterLink: await fs.realpath(path.join(runtime, 'python3.12')) });expect(files.find(file => file.name === '.venv/pyvenv.cfg')?.bytes.toString()).toContain(runtime);await fs.writeFile(path.join(runtime, 'private.txt'), 'fixture-private-token');- await fs.symlink(path.join(runtime, 'private.txt'), path.join(skill, 'credentials.txt'));+ await fs.symlink(path.join(runtime, 'private.txt'), path.join(skill, 'credentials.txt'), 'file');await expect(readImportSkillTree(skill)).rejects.toThrow('SOURCE_LINK_OUTSIDE_FOLDER');await fs.unlink(path.join(skill, 'credentials.txt'));await fs.writeFile(path.join(runtime, 'python3.12'), 'fixture-private-token');diff --git a/apps/desktop/src/main/bot-import/__tests__/skillResources.test.ts b/apps/desktop/src/main/bot-import/__tests__/skillResources.test.tsindex e3d86a76a7..716e2ef7ad 100644--- a/apps/desktop/src/main/bot-import/__tests__/skillResources.test.ts+++ b/apps/desktop/src/main/bot-import/__tests__/skillResources.test.ts@@ -1,5 +1,6 @@import { promises as fs } from 'node:fs';import path from 'node:path';+import os from 'node:os';import { expect, it } from 'vitest';import { projectImportedSkill, withImportedSkillResources } from '../skillResources.js';import type { CompanionEnvironment } from '../environment.js';@@ -48,15 +49,19 @@ it('executes the preserved resource with credentials while keeping ordinary codeexpect(result).toEqual({ stdout: 'store_true\n', exitCode: 0 });});-it.skipIf(process.platform === 'win32')('retains and materializes native interpreter aliases without copying them into broken standalone executables', async () => {+it('retains and materializes native interpreter aliases without copying them into broken standalone executables', async ctx => {+ const target = path.join(os.tmpdir(), 'fixture-native-python3');+ const interpreterName = `.venv/${process.platform === 'win32' ? 'Scripts' : 'bin'}/python`;const files = [{ name: 'SKILL.md', bytes: Buffer.from('# Native'), executable: false },- { name: '.venv/bin/python', bytes: Buffer.from('native fixture'), executable: true, interpreterLink: '/fixture/native/python3' },+ { name: interpreterName, bytes: Buffer.from('native fixture'), executable: true, interpreterLink: target },];const projected = projectImportedSkill(files, 'native', {});expect(projected.files).toEqual(files);- expect(projected.originals?.[1]?.interpreterLink).toBe('/fixture/native/python3');- await withImportedSkillResources({ version: 1, env: {}, mcp: [], credentials: [], skillFiles: { native: projected.originals! } }, () => {}, async env => {- expect(await fs.readlink(path.join(env.CINDY_IMPORTED_SKILLS!, 'native/.venv/bin/python'))).toBe('/fixture/native/python3');- });+ expect(projected.originals?.[1]?.interpreterLink).toBe(target);+ try {+ await withImportedSkillResources({ version: 1, env: {}, mcp: [], credentials: [], skillFiles: { native: projected.originals! } }, () => {}, async env => {+ expect(await fs.readlink(path.join(env.CINDY_IMPORTED_SKILLS!, 'native', interpreterName))).toBe(target);+ });+ } catch (error) { if ((error as NodeJS.ErrnoException).code === 'EPERM') { ctx.skip(); return; } throw error; }});diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botSkillStore.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botSkillStore.test.tsindex 81de1ce13b..7c07fc2018 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/botSkillStore.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/botSkillStore.test.ts@@ -335,18 +335,23 @@ it('deletes only the read/edit target if older data contains duplicate enabled aexpect(await readBotSkill(userDataDir, 'bot-1', 'report')).toMatchObject({ enabled: false, body: '# Retain disabled copy' });});-it.skipIf(process.platform === 'win32')('preserves native interpreter links across save/retry and rejects a changed alias', async () => {+it('preserves native interpreter links across save/retry and rejects a changed alias', async ctx => {const runtime = path.join(userDataDir, 'runtime-python');await fs.writeFile(runtime, 'fixture-runtime');+ const probe = path.join(userDataDir, 'link-probe');+ try { await fs.symlink(runtime, probe, 'file'); }+ catch (error) { if ((error as NodeJS.ErrnoException).code === 'EPERM') { ctx.skip(); return; } throw error; }+ await fs.unlink(probe);+ const interpreterName = `.venv/${process.platform === 'win32' ? 'Scripts' : 'bin'}/python`;const files = [{ name: 'SKILL.md', bytes: Buffer.from('# Imported'), executable: false },- { name: '.venv/bin/python', bytes: Buffer.from('fixture-runtime'), executable: true, interpreterLink: runtime },+ { name: interpreterName, bytes: Buffer.from('fixture-runtime'), executable: true, interpreterLink: runtime },];await importBotSkillFiles(userDataDir, 'bot', 'native', files, () => {});- const alias = path.join(botSkillsDir(userDataDir, 'bot'), 'native/.venv/bin/python');+ const alias = path.join(botSkillsDir(userDataDir, 'bot'), 'native', interpreterName);expect(await fs.readlink(alias)).toBe(runtime);await importBotSkillFiles(userDataDir, 'bot', 'native', files, () => {});- await fs.unlink(alias); await fs.symlink(path.join(userDataDir, 'other-python'), alias);+ await fs.unlink(alias); await fs.symlink(path.join(userDataDir, 'other-python'), alias, 'file');await expect(importBotSkillFiles(userDataDir, 'bot', 'native', files, () => {})).rejects.toThrow('Imported interpreter was edited');expect(await fs.readFile(runtime, 'utf8')).toBe('fixture-runtime');await expect(importBotSkillFiles(userDataDir, 'bot', 'unsafe', [{ ...files[0]!, interpreterLink: runtime }], () => {})).rejects.toThrow('Invalid imported interpreter');