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(desktop): 修复 Windows 路径断言

zhanghengxd671d1300c67b
diff --git a/apps/desktop/src/main/__tests__/installCliCommand.test.ts b/apps/desktop/src/main/__tests__/installCliCommand.test.ts
index 16ff78b083..80c09e3253 100644
--- a/apps/desktop/src/main/__tests__/installCliCommand.test.ts
+++ b/apps/desktop/src/main/__tests__/installCliCommand.test.ts
@@ -36,15 +36,13 @@ describe('CLI_COMMAND_NAME 跟随 edition 品牌', () => {
describe('resolveBundledCliPath', () => {
it('由 resourcesPath 推出包内 cli/cindy', () => {
- expect(resolveBundledCliPath('/Applications/Cindy.app/Contents/Resources')).toBe(
- '/Applications/Cindy.app/Contents/Resources/cli/cindy',
- );
+ const resourcesPath = '/Applications/Cindy.app/Contents/Resources';
+ expect(resolveBundledCliPath(resourcesPath)).toBe(path.join(resourcesPath, 'cli', 'cindy'));
});
it('路径含空格也正确', () => {
- expect(resolveBundledCliPath('/Users/a/My Apps/Cindy.app/Contents/Resources')).toBe(
- '/Users/a/My Apps/Cindy.app/Contents/Resources/cli/cindy',
- );
+ const resourcesPath = '/Users/a/My Apps/Cindy.app/Contents/Resources';
+ expect(resolveBundledCliPath(resourcesPath)).toBe(path.join(resourcesPath, 'cli', 'cindy'));
});
});
diff --git a/apps/desktop/src/main/plugin-market/__tests__/service-custom-sources.test.ts b/apps/desktop/src/main/plugin-market/__tests__/service-custom-sources.test.ts
index be36d5471f..afb020a64a 100644
--- a/apps/desktop/src/main/plugin-market/__tests__/service-custom-sources.test.ts
+++ b/apps/desktop/src/main/plugin-market/__tests__/service-custom-sources.test.ts
@@ -1,6 +1,7 @@
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
+import { fileURLToPath } from 'node:url';
import { afterEach, describe, expect, it, vi } from 'vitest';
@@ -1123,7 +1124,7 @@ describe('PluginMarketService 自定义市场 detail/install', () => {
// 已安装目录同样可能被外部进程/同步盘改动,且摘要读取在每次市场快照都会
// 执行;所有此类读取必须走 readBoundedFileNoFollow 系列(单句柄限量闸)。
const source = await fs.promises.readFile(
- path.join(path.dirname(new URL(import.meta.url).pathname), '..', 'service.ts'),
+ path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'service.ts'),
'utf8',
);
expect(source).not.toMatch(/fs\.promises\.readFile\(/);
diff --git a/apps/desktop/src/main/plugin-market/__tests__/sources-discover.test.ts b/apps/desktop/src/main/plugin-market/__tests__/sources-discover.test.ts
index b6d93b5c74..20a97eec8b 100644
--- a/apps/desktop/src/main/plugin-market/__tests__/sources-discover.test.ts
+++ b/apps/desktop/src/main/plugin-market/__tests__/sources-discover.test.ts
@@ -316,7 +316,7 @@ describe('discoverMarketplace', () => {
expect(result.marketplace.skippedCount).toBe(1);
});
- it('validates and reads ghost.json through one file handle, never by pathname', async () => {
+ it('validates and reads ghost.json through one file handle', async () => {
const root = makeRoot();
writePlugin(root, 'plugins/good', 'good-one');
writeManifest(root, { name: 'lib', plugins: [{ name: 'good', source: 'plugins/good' }] });
@@ -335,10 +335,12 @@ describe('discoverMarketplace', () => {
try {
const result = await discoverMarketplace(root);
expect(result.ok).toBe(true);
- expect(pathReads.some((target) => target.endsWith('ghost.json'))).toBe(false);
- expect(
- lstatSpy.mock.calls.some((call) => String(call[0]).endsWith('ghost.json')),
- ).toBe(false);
+ expect(pathReads.some((target) => path.basename(target) === 'ghost.json')).toBe(false);
+ const lstatByPath = lstatSpy.mock.calls.some(
+ (call) => path.basename(String(call[0])) === 'ghost.json',
+ );
+ // Windows 没有 O_NOFOLLOW,安全读取器必须用 lstat + inode 对账回退。
+ expect(lstatByPath).toBe(fs.constants.O_NOFOLLOW == null);
} finally {
readSpy.mockRestore();
lstatSpy.mockRestore();
diff --git a/apps/desktop/src/main/plugin-market/__tests__/sources-parse.test.ts b/apps/desktop/src/main/plugin-market/__tests__/sources-parse.test.ts
index c4681697c6..8c0cf930b5 100644
--- a/apps/desktop/src/main/plugin-market/__tests__/sources-parse.test.ts
+++ b/apps/desktop/src/main/plugin-market/__tests__/sources-parse.test.ts
@@ -1,8 +1,10 @@
+import path from 'node:path';
+
import { describe, expect, it } from 'vitest';
import { parseMarketSource, resolveLocalSourcePath } from '../sources/parse';
-const HOME = '/home/tester';
+const HOME = path.join(path.parse(process.cwd()).root, 'home', 'tester');
function parse(input: { source: string; ref?: string; sparsePaths?: string[] }) {
return parseMarketSource(input, HOME);
@@ -72,7 +74,7 @@ describe('parseMarketSource', () => {
const result = parse({ source: '~/team/plugins' });
expect(result).toEqual({
ok: true,
- source: { type: 'local', path: `${HOME}/team/plugins` },
+ source: { type: 'local', path: path.join(HOME, 'team', 'plugins') },
});
});
@@ -140,7 +142,7 @@ describe('parseMarketSource', () => {
});
it('resolves local paths without touching the filesystem', () => {
- expect(resolveLocalSourcePath('~/a/b', HOME)).toBe(`${HOME}/a/b`);
+ expect(resolveLocalSourcePath('~/a/b', HOME)).toBe(path.join(HOME, 'a', 'b'));
});
it('rejects backslash in git URL authority (WHATWG/git 分歧,凭证闸失明)', () => {