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: 建立 Windows 路径单测门禁 (#1348)

DavidShenXD2bce88301752
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9e3cb279d8..2899e24d5a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -118,6 +118,66 @@ jobs:
- name: Run mobile scope guard
run: pnpm --filter mobile test:scope
+ # Linux 全绿不能覆盖 path separator、盘符、大小写和文件系统能力差异。Windows
+ # 单测独立并行运行,避免重复 typecheck / i18n 等平台无关检查;完整 test:unit
+ # 是工程规范中的跨平台可执行契约,不能缩成少量 smoke。
+ windows-unit:
+ name: Windows unit tests
+ runs-on: windows-latest
+ timeout-minutes: 40
+
+ steps:
+ - name: Checkout client
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ fetch-depth: 0
+ lfs: true
+
+ # GitHub-hosted Windows 带 Git Bash;复用 Linux job 的 fail-closed 来源校验,
+ # 同时保留 win32 Node / 文件系统语义供后续单测覆盖。
+ - name: Verify cindy-protocol submodule source
+ shell: bash
+ run: |
+ set -euo pipefail
+ expected_url='https://github.com/makecindy/cindy-protocol.git'
+ expected_path='cindy-protocol'
+ actual_url="$(git config -f .gitmodules --get submodule.cindy-protocol.url || true)"
+ actual_path="$(git config -f .gitmodules --get submodule.cindy-protocol.path || true)"
+ if [ "$actual_url" != "$expected_url" ] || [ "$actual_path" != "$expected_path" ]; then
+ echo "::error file=.gitmodules::cindy-protocol source mismatch: url='$actual_url' path='$actual_path' (expected url='$expected_url' path='$expected_path')"
+ exit 1
+ fi
+ echo "cindy-protocol submodule source verified: $actual_url"
+
+ - name: Fetch cindy-protocol submodule
+ shell: bash
+ run: |
+ git submodule sync -- cindy-protocol
+ git submodule update --init --force --recursive -- cindy-protocol
+
+ - name: Setup pnpm
+ uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6
+ with:
+ run_install: false
+
+ - name: Setup Node.js
+ uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
+ with:
+ node-version: 22
+ cache: pnpm
+ cache-dependency-path: pnpm-lock.yaml
+
+ - name: Install dependencies
+ run: pnpm install --frozen-lockfile
+
+ - name: Install bundled ripgrep
+ env:
+ GITHUB_TOKEN: ${{ github.token }}
+ run: pnpm install:ripgrep
+
+ - name: Run client and package unit tests
+ run: pnpm test:unit
+
git-integration:
name: Desktop Git integration
runs-on: ubuntu-latest
diff --git a/apps/desktop/src/main/__tests__/installCliCommand.test.ts b/apps/desktop/src/main/__tests__/installCliCommand.test.ts
index 80c09e3253..d001ec3325 100644
--- a/apps/desktop/src/main/__tests__/installCliCommand.test.ts
+++ b/apps/desktop/src/main/__tests__/installCliCommand.test.ts
@@ -145,7 +145,8 @@ describe('随包分发的启动器脚本 resources/cli/cindy', () => {
fileURLToPath(import.meta.url),
'../../../../resources/cli/cindy',
);
- const script = readFileSync(scriptPath, 'utf8');
+ // Git checkout 可能按平台写成 CRLF;这里验证的是 shell 内容,不是工作区换行策略。
+ const script = readFileSync(scriptPath, 'utf8').replaceAll('\r\n', '\n');
it('是 sh 脚本', () => {
expect(script.startsWith('#!/bin/sh\n')).toBe(true);
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts
index e97be68404..c55b25eca6 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts
@@ -22,6 +22,22 @@ import {
} from '../forge';
import { GhostManager } from '../GhostManager';
+const canSymlink = (() => {
+ const probeDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-forge-symlink-probe-'));
+ try {
+ const target = path.join(probeDir, 'target.txt');
+ fs.writeFileSync(target, 'probe');
+ fs.symlinkSync(target, path.join(probeDir, 'link.txt'));
+ return true;
+ } catch {
+ return false;
+ } finally {
+ fs.rmSync(probeDir, { recursive: true, force: true });
+ }
+})();
+
+const directoryLinkType = process.platform === 'win32' ? 'junction' : 'dir';
+
let workDir: string;
beforeEach(async () => {
@@ -109,8 +125,8 @@ describe('packGhostDir', () => {
}
});
- it('ghost.json 为符号链接或超限 → MANIFEST_INVALID(与市场发现/安装同一把闸)', async () => {
- // 符号链接:目标是合法清单也不放行——"符号链接一律不穿透"覆盖身份卡本身,
+ it.skipIf(!canSymlink)('ghost.json 为符号链接 → MANIFEST_INVALID(与市场发现/安装同一把闸)', async () => {
+ // 符号链接:目标是合法清单也不放行——“符号链接一律不穿透”覆盖身份卡本身,
// 否则打包输入目录里一根链接就能把目录外的文件读进打包管道。
const outside = path.join(workDir, 'outside-ghost.json');
await fs.promises.writeFile(outside, JSON.stringify(GOOD_MANIFEST));
@@ -122,7 +138,9 @@ describe('packGhostDir', () => {
ok: false,
errorCode: 'MANIFEST_INVALID',
});
+ });
+ it('ghost.json 超限 → MANIFEST_INVALID(与市场发现/安装同一把闸)', async () => {
// 超限:JSON 本身合法(合法清单 + 尾随空白撑体积),必须在读取层按大小拒,
// 不能等到 JSON.parse/validate——那时数 GB 的文件已经进内存了。
const big = path.join(workDir, 'src-big');
@@ -189,7 +207,11 @@ describe('packGhostDir', () => {
const expectedRealDir = await fs.promises.realpath(pluginDir);
// 校验之后被换成指向外部目录的链接(外部目录留着同样的 ghost.json)。
await fs.promises.rm(pluginDir, { recursive: true, force: true });
- await fs.promises.symlink(await fs.promises.realpath(outside), pluginDir);
+ await fs.promises.symlink(
+ await fs.promises.realpath(outside),
+ pluginDir,
+ directoryLinkType,
+ );
const dest = path.join(workDir, 'out.cindy');
const r = await packGhostDirToFile(pluginDir, dest, expectedRealDir);
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/handoffWorkingDir.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/handoffWorkingDir.test.ts
index 081339c090..a622733f4b 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/handoffWorkingDir.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/handoffWorkingDir.test.ts
@@ -10,7 +10,7 @@ import { afterAll, describe, expect, it } from 'vitest';
import { validateHandoffWorkingDir } from '../handoffWorkingDir.js';
const dir = mkdtempSync(path.join(tmpdir(), 'cindy-handoff-wd-'));
-const realpathSyncDir = (await import('node:fs')).realpathSync(dir);
+const realDir = await (await import('node:fs')).promises.realpath(dir);
const file = path.join(dir, 'plain.txt');
writeFileSync(file, 'x');
@@ -20,13 +20,13 @@ afterAll(() => {
describe('validateHandoffWorkingDir', () => {
it('已存在目录(绝对路径)→ ok 且返回规范化路径', async () => {
- expect(await validateHandoffWorkingDir(dir)).toEqual({ ok: true, dir: realpathSyncDir });
+ expect(await validateHandoffWorkingDir(dir)).toEqual({ ok: true, dir: realDir });
});
it('带前后空白的合法路径 → trim 后通过,返回规范化路径(review 反馈)', async () => {
expect(await validateHandoffWorkingDir(` ${dir} `)).toEqual({
ok: true,
- dir: realpathSyncDir,
+ dir: realDir,
});
});
@@ -51,7 +51,7 @@ describe('validateHandoffWorkingDir', () => {
it('软链目录 → 返回真身路径(review 反馈:base repo 解析看真身)', async () => {
const linkPath = path.join(dir, 'link-to-dir');
const target = path.join(dir, 'real-target');
- const { mkdirSync, symlinkSync, realpathSync } = await import('node:fs');
+ const { mkdirSync, promises, symlinkSync } = await import('node:fs');
mkdirSync(target);
try {
symlinkSync(target, linkPath, 'dir');
@@ -60,7 +60,7 @@ describe('validateHandoffWorkingDir', () => {
}
expect(await validateHandoffWorkingDir(linkPath)).toEqual({
ok: true,
- dir: realpathSync(target),
+ dir: await promises.realpath(target),
});
});
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 d1622ebdc2..7f4108f9df 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
@@ -997,7 +997,7 @@ describe('PluginMarketService 自定义市场 detail/install', () => {
// 的目录"这种永久错误,按内容非法跳过才对(否则这类市场永久阻塞默认安装)。
// 路径必须按 realpath 拼:发现层用的是 realpath(macOS 上 /var → /private/var),
// 用 mkdtemp 原样路径做匹配会让 mock 永不命中。
- const target = path.join(fs.realpathSync(dir), 'plugins', 'srv', 'ghost.json');
+ const target = path.join(await fs.promises.realpath(dir), 'plugins', 'srv', 'ghost.json');
const realOpen = fs.promises.open;
const spy = vi.spyOn(fs.promises, 'open').mockImplementation((async (
...args: Parameters<typeof fs.promises.open>
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 20a97eec8b..2774972c2e 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
@@ -7,6 +7,21 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
import { discoverMarketplace } from '../sources/discover';
const roots: string[] = [];
+const directoryLinkType = process.platform === 'win32' ? 'junction' : 'dir';
+
+const canSymlink = (() => {
+ const probeDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-market-symlink-probe-'));
+ try {
+ const target = path.join(probeDir, 'target.txt');
+ fs.writeFileSync(target, 'probe');
+ fs.symlinkSync(target, path.join(probeDir, 'link.txt'));
+ return true;
+ } catch {
+ return false;
+ } finally {
+ fs.rmSync(probeDir, { recursive: true, force: true });
+ }
+})();
afterEach(() => {
for (const root of roots.splice(0)) fs.rmSync(root, { recursive: true, force: true });
@@ -137,7 +152,7 @@ describe('discoverMarketplace', () => {
const outside = makeRoot();
writePlugin(outside, 'escaped', 'escaped');
writePlugin(root, 'plugins/good', 'good-one');
- fs.symlinkSync(outside, path.join(root, 'plugins', 'linked-out'), 'dir');
+ fs.symlinkSync(outside, path.join(root, 'plugins', 'linked-out'), directoryLinkType);
writeManifest(root, {
name: 'linked',
plugins: [
@@ -287,7 +302,9 @@ describe('discoverMarketplace', () => {
expect(result.marketplace.displayName).toBeNull();
});
- it('skips a plugin whose ghost.json is a symlink, even to a valid manifest outside', async () => {
+ // 无宿主 symlink 权限时跳过集成夹具;Windows lstat 回退由 readBoundedFile.test.ts
+ // 的注入用例继续覆盖,不会随这里的 capability skip 一起消失。
+ it.skipIf(!canSymlink)('skips a plugin whose ghost.json is a symlink, even to a valid manifest outside', async () => {
const root = makeRoot();
const outside = makeRoot();
// 市场外放一份**内容完全合法**的身份卡:只断言"被跳过"才有区分度——
@@ -351,10 +368,18 @@ describe('discoverMarketplace', () => {
const root = makeRoot();
const outside = makeRoot();
// 恶意市场把清单做成指向根目录外的 symlink,借宿主之手读任意路径。
- const secret = path.join(outside, 'secret.json');
- fs.writeFileSync(secret, JSON.stringify({ name: 'stolen', plugins: [] }));
- fs.mkdirSync(path.join(root, '.agents', 'plugins'), { recursive: true });
- fs.symlinkSync(secret, path.join(root, '.agents', 'plugins', 'marketplace.json'));
+ const outsideManifestDir = path.join(outside, 'manifest');
+ fs.mkdirSync(outsideManifestDir, { recursive: true });
+ fs.writeFileSync(
+ path.join(outsideManifestDir, 'marketplace.json'),
+ JSON.stringify({ name: 'stolen', plugins: [] }),
+ );
+ fs.mkdirSync(path.join(root, '.agents'), { recursive: true });
+ fs.symlinkSync(
+ outsideManifestDir,
+ path.join(root, '.agents', 'plugins'),
+ directoryLinkType,
+ );
const result = await discoverMarketplace(root);
expect(result.ok).toBe(false);
diff --git a/apps/desktop/src/main/plugin-market/__tests__/sources-manager.test.ts b/apps/desktop/src/main/plugin-market/__tests__/sources-manager.test.ts
index efacfa4fc6..1265f36cb7 100644
--- a/apps/desktop/src/main/plugin-market/__tests__/sources-manager.test.ts
+++ b/apps/desktop/src/main/plugin-market/__tests__/sources-manager.test.ts
@@ -478,7 +478,7 @@ describe('MarketSourceManager git sources', () => {
? discovered.result.marketplace.plugins[0]!.dir
: '';
// discover 返回 realpath(macOS 下 /var → /private/var),按 realpath 比对。
- expect(pluginDir.startsWith(fs.realpathSync(heldDir))).toBe(true);
+ expect(pluginDir.startsWith(await fs.promises.realpath(heldDir))).toBe(true);
await refresher.refreshSource('hub');
const switched = fs.readFileSync(path.join(slot, 'current'), 'utf8').trim();
diff --git a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts b/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
index ecdc165e49..a2a9e2b503 100644
--- a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
+++ b/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
@@ -750,7 +750,7 @@ describe('skillhub/installService', () => {
fs.writeFileSync(path.join(externalDir, 'SKILL.md'), 'external content');
makeDirectoryLink(physicalDir, externalDir);
makeDirectoryLink(logicalDir, physicalDir);
- const externalRegistryPath = fs.realpathSync(physicalDir);
+ const externalRegistryPath = await fs.promises.realpath(physicalDir);
const zipBuf = await makeZip({ 'SKILL.md': 'new content' });
await setupInstallDownload(skillName, zipBuf);
@@ -842,7 +842,7 @@ describe('skillhub/installService', () => {
fs.mkdirSync(physicalDir, { recursive: true });
fs.writeFileSync(path.join(physicalDir, 'SKILL.md'), 'old content');
makeDirectoryLink(logicalDir, physicalDir);
- const physicalRegistryPath = fs.realpathSync(physicalDir);
+ const physicalRegistryPath = await fs.promises.realpath(physicalDir);
const zipBuf = await makeZip({ 'SKILL.md': 'new content' });
await setupInstallDownload(skillName, zipBuf);
diff --git a/apps/desktop/src/main/usage/__tests__/accountCurrencyStore.test.ts b/apps/desktop/src/main/usage/__tests__/accountCurrencyStore.test.ts
index 6066f8bc64..6506c8df36 100644
--- a/apps/desktop/src/main/usage/__tests__/accountCurrencyStore.test.ts
+++ b/apps/desktop/src/main/usage/__tests__/accountCurrencyStore.test.ts
@@ -24,6 +24,7 @@ vi.mock('../../localDb/client/current', () => ({
}));
import {
+ __flushAccountCurrencyStoreForTesting,
__resetAccountCurrencyStoreForTesting,
hydrateAccountCurrency,
noteActiveAccount,
@@ -50,8 +51,7 @@ async function writeStore(entries: Record<string, string>): Promise<void> {
/** 等 rememberAccountCurrency 的串行写链跑完(它是 fire-and-forget)。 */
async function flushWrites(): Promise<void> {
- for (let i = 0; i < 20; i += 1) await Promise.resolve();
- await new Promise((resolve) => setTimeout(resolve, 10));
+ await __flushAccountCurrencyStoreForTesting();
}
beforeEach(async () => {
diff --git a/apps/desktop/src/main/usage/accountCurrencyStore.ts b/apps/desktop/src/main/usage/accountCurrencyStore.ts
index f3311c1d4e..7e67389cc9 100644
--- a/apps/desktop/src/main/usage/accountCurrencyStore.ts
+++ b/apps/desktop/src/main/usage/accountCurrencyStore.ts
@@ -187,3 +187,8 @@ export function __resetAccountCurrencyStoreForTesting(): void {
writeChain = Promise.resolve();
hydratedUserId = null;
}
+
+/** 仅测试:等待 fire-and-forget 的串行写链完成,避免用固定延时猜测磁盘时序。 */
+export async function __flushAccountCurrencyStoreForTesting(): Promise<void> {
+ await writeChain;
+}
diff --git a/apps/desktop/src/main/utils/__tests__/readBoundedFile.test.ts b/apps/desktop/src/main/utils/__tests__/readBoundedFile.test.ts
index de51382c40..d3de6490e2 100644
--- a/apps/desktop/src/main/utils/__tests__/readBoundedFile.test.ts
+++ b/apps/desktop/src/main/utils/__tests__/readBoundedFile.test.ts
@@ -62,6 +62,25 @@ describe('readBoundedFileNoFollow', () => {
expect((await readBoundedFileNoFollow(file, 1024, { noFollowFlag: null }))?.toString('utf8')).toBe('{"ok":1}');
});
+ it('无 O_NOFOLLOW 的平台:lstat 报告符号链接时拒绝,不依赖宿主 symlink 权限', async () => {
+ const file = path.join(workDir, 'link-shaped.json');
+ await fs.promises.writeFile(file, '{"ok":1}');
+ const realStat = await fs.promises.lstat(file, { bigint: true });
+ const linkStat = new Proxy(realStat, {
+ get(target, key) {
+ if (key === 'isSymbolicLink') return () => true;
+ const value = Reflect.get(target, key);
+ return typeof value === 'function' ? value.bind(target) : value;
+ },
+ });
+ const lstatSpy = vi.spyOn(fs.promises, 'lstat').mockResolvedValue(linkStat as never);
+ try {
+ expect(await readBoundedFileNoFollow(file, 1024, { noFollowFlag: null })).toBeNull();
+ } finally {
+ lstatSpy.mockRestore();
+ }
+ });
+
it.runIf(process.platform !== 'win32')(
'containWithin:中间目录被换成根外链接时拒绝(最终分量是普通文件,O_NOFOLLOW 拦不住)',
async () => {
diff --git a/apps/mobile/src/__tests__/historyWindowBackfillWiring.test.ts b/apps/mobile/src/__tests__/historyWindowBackfillWiring.test.ts
index 66974f0ab1..2b03060e87 100644
--- a/apps/mobile/src/__tests__/historyWindowBackfillWiring.test.ts
+++ b/apps/mobile/src/__tests__/historyWindowBackfillWiring.test.ts
@@ -22,8 +22,12 @@ import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { describe, expect, it } from 'vitest';
+function readSource(...segments: string[]): string {
+ return readFileSync(resolve(process.cwd(), ...segments), 'utf8').replaceAll('\r\n', '\n');
+}
+
describe('history window backfill wiring', () => {
- const source = readFileSync(resolve(process.cwd(), 'app/sessions/[sessionId].tsx'), 'utf8');
+ const source = readSource('app/sessions/[sessionId].tsx');
it('不变量 1:一轮的身份是单调 seq,取消不可撤销', () => {
expect(source).toContain('const runSeq = backfillRunSeqRef.current + 1;');
@@ -110,7 +114,7 @@ describe('history window backfill wiring', () => {
* (#1210 review)。
*/
describe('live stream interruption wiring', () => {
- const source = readFileSync(resolve(process.cwd(), 'src/device-link/DeviceLinkContext.tsx'), 'utf8');
+ const source = readSource('src/device-link/DeviceLinkContext.tsx');
it('订阅被远端 ACK:按真正记进 ACK 表的 topic 生效', () => {
const sendSubscribe = source.slice(
diff --git a/docs/dev-rules/engineering-conventions.md b/docs/dev-rules/engineering-conventions.md
index 6aa80b8469..62e542b3be 100644
--- a/docs/dev-rules/engineering-conventions.md
+++ b/docs/dev-rules/engineering-conventions.md
@@ -89,6 +89,32 @@ UI 文案的语气与措辞另见 [`DESIGN.md`](../design-rules/DESIGN.md) 的 V
`scripts/__tests__/test-workspaces.test.mjs` 是 tier 边界的可执行契约;调整测试命名、include
或 exclude 时必须同步更新并运行 `pnpm test:runner`。
+### 3.2 路径断言的跨平台宪法
+
+测试必须先区分路径代表的语义,不能把当前开发机的路径表示误当成跨平台事实:
+
+- **宿主文件系统路径**:传给或来自 Node `fs`、Electron、子进程 `cwd` 等本机 API 的路径,
+ 期望值必须用 `path.join`/`path.resolve`/`path.relative` 构造;按被测语义使用
+ `path.normalize`,涉及软链、junction 或物理文件身份时使用 `realpath` 后比较。禁止在这类
+ 断言中把 `/` 或 `\` 写成固定期望,也禁止只为让断言通过而把整段输出统一
+ `replace(/\\/g, '/')`——整段替换会掩盖产品代码返回了错误路径格式,并可能误改 URL、转义
+ 内容或其它非路径文本。
+- **逻辑路径**:URL/URI、远程 POSIX 路径、归档条目、wire protocol,以及契约明确规定用
+ `/` 的 repo-relative 路径,不跟随宿主分隔符。这类测试可以固定写 `/`,但测试名称、类型或
+ 邻近注释必须明确它是稳定协议格式,不能仅凭字符串“看起来像路径”就归入例外。
+- **模拟目标平台**:验证 Windows/POSIX 路径算法时使用 `path.win32`/`path.posix`,或把目标
+ platform/path API 注入被测函数;禁止只 mock `process.platform` 后继续调用由宿主系统决定的
+ 默认 `path` 实现。Windows 大小写折叠也只在被测契约明确需要时进行,不能作为所有路径断言的
+ 通用归一化。
+- **平台能力差异**:symlink、junction、文件权限等能力先做 capability probe。宿主确实不支持
+ 时可以跳过真实文件系统用例,但核心语义必须在支持该能力的受控 CI 平台继续实跑,或通过
+ 依赖注入/纯函数用例保留等价覆盖;禁止按 `process.platform` 大面积跳过后让整个 CI 矩阵
+ 失去相应回归保护。
+
+PR 门禁必须在 Windows 上运行完整 `pnpm test:unit`;`scripts/__tests__/dev-docs-contract.test.mjs`
+锁住该 CI 契约。不能用静态扫描“测试字符串是否含斜杠”代替 Windows 实跑,因为它无法可靠区分
+宿主路径与逻辑路径。
+
## 4. 跨平台双端兼容(macOS / Windows)
任何功能都必须同时考虑 macOS / Windows,并在两端做到最优性能。
diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-agent.integration.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-agent.integration.test.ts
index 97a9268892..231ac3bc4b 100644
--- a/packages/maker-core/src/agents/pi/__tests__/pi-agent.integration.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/pi-agent.integration.test.ts
@@ -42,6 +42,24 @@ const PREVIOUS_PI_BINARY = path.join(
const piAvailable = existsSync(PI_BINARY);
+const canSymlink = (() => {
+ const probeDir = mkdtempSync(path.join(tmpdir(), 'pi-symlink-probe-'));
+ try {
+ const target = path.join(probeDir, 'target.txt');
+ writeFileSync(target, 'probe');
+ symlinkSync(target, path.join(probeDir, 'link.txt'));
+ return true;
+ } catch {
+ return false;
+ } finally {
+ rmSync(probeDir, { recursive: true, force: true });
+ }
+})();
+
+function jsonStringContent(value: string): string {
+ return JSON.stringify(value).slice(1, -1);
+}
+
const noopLogger: Logger = {
trace: () => {},
debug: () => {},
@@ -576,8 +594,9 @@ describe.skipIf(!piAvailable)('PiAgent integration (real pi binary + fake gatewa
});
await done;
const bodies = seenRequests.slice(before).map((request) => request.body).join('\n');
- expect(bodies).toContain(filePath);
- expect(bodies).toContain(referenceDir);
+ // 请求体是 JSON 文本;Windows 路径的反斜杠会按 JSON 规则转义。
+ expect(bodies).toContain(jsonStringContent(filePath));
+ expect(bodies).toContain(jsonStringContent(referenceDir));
expect(agent.capabilities.multimodal.file.supported).toBe(true);
expect(agent.capabilities.extraDirs.supported).toBe(true);
} finally {
@@ -1075,7 +1094,7 @@ describe.skipIf(!piAvailable)('PiAgent integration (real pi binary + fake gatewa
},
);
- it(
+ it.skipIf(!canSymlink)(
'full access blocks credential reads reached through a workspace symlink',
{ timeout: 60_000 },
async () => {
diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts
index faf296d8fd..12866a6e9e 100644
--- a/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts
@@ -143,8 +143,13 @@ describe('pi auto-review dispatch & spawn config (mocked pi process)', () => {
}
it('spawns with --append-system-prompt (default pi prompt preserved) and offline/no-proxy env', async () => {
- process.env.no_proxy = 'corp.internal';
- delete process.env.NO_PROXY;
+ if (process.platform === 'win32') {
+ // Windows 的环境变量键不区分大小写,无法同时构造“仅有小写键”的进程环境。
+ process.env.NO_PROXY = 'corp.internal';
+ } else {
+ process.env.no_proxy = 'corp.internal';
+ delete process.env.NO_PROXY;
+ }
await start();
expect(captured.args).not.toContain('--system-prompt');
const idx = captured.args.indexOf('--append-system-prompt');
diff --git a/scripts/__tests__/dev-docs-contract.test.mjs b/scripts/__tests__/dev-docs-contract.test.mjs
index 217ae2953a..fa6f9ea3bd 100644
--- a/scripts/__tests__/dev-docs-contract.test.mjs
+++ b/scripts/__tests__/dev-docs-contract.test.mjs
@@ -26,6 +26,17 @@ function readJson(relativePath) {
return JSON.parse(readText(relativePath));
}
+function workflowJob(workflow, jobId) {
+ const lines = workflow.split(/\r?\n/);
+ const start = lines.findIndex((line) => line === ` ${jobId}:`);
+ if (start === -1) return undefined;
+ const endOffset = lines
+ .slice(start + 1)
+ .findIndex((line) => /^ [a-zA-Z0-9_-]+:$/.test(line));
+ const end = endOffset === -1 ? lines.length : start + 1 + endOffset;
+ return lines.slice(start + 1, end).join("\n");
+}
+
function shellLines(relativePath) {
const markdown = readText(relativePath);
return [...markdown.matchAll(/```(?:bash|sh)?\r?\n([\s\S]*?)```/g)]
@@ -125,3 +136,12 @@ test("runtime versions and the docs contract are code-owned", () => {
assert.match(rootPackage.packageManager, /^pnpm@10\./);
assert.match(rootPackage.scripts["test:runner"], /scripts\/__tests__\/dev-docs-contract\.test\.mjs/);
});
+
+test("client CI keeps the complete unit gate on Windows", () => {
+ const workflow = readText(".github/workflows/ci.yml");
+ const job = workflowJob(workflow, "windows-unit");
+ assert.ok(job, "client CI must define a windows-unit job");
+ assert.match(job, /^ runs-on: windows-latest$/m);
+ assert.match(job, /^ run: pnpm test:unit$/m);
+ assert.doesNotMatch(job, /pnpm test:unit\s+--/);
+});
diff --git a/scripts/__tests__/ensure-agent-binaries.test.mjs b/scripts/__tests__/ensure-agent-binaries.test.mjs
index b0a5123c77..2224f1d627 100644
--- a/scripts/__tests__/ensure-agent-binaries.test.mjs
+++ b/scripts/__tests__/ensure-agent-binaries.test.mjs
@@ -220,7 +220,7 @@ test('listSiblingWorktreeRoots: lists other worktrees of the same repo, excludin
git('worktree', 'add', wt, '-b', 'wt-a');
const fromMain = listSiblingWorktreeRoots(repo);
- assert.deepEqual(fromMain, [fs.realpathSync(wt)]);
+ assert.deepEqual(fromMain, [fs.realpathSync.native(wt)]);
const fromWt = listSiblingWorktreeRoots(wt);
- assert.deepEqual(fromWt, [fs.realpathSync(repo)]);
+ assert.deepEqual(fromWt, [fs.realpathSync.native(repo)]);
});
diff --git a/scripts/ensure-agent-binaries.mjs b/scripts/ensure-agent-binaries.mjs
index f5295ff36d..5b1fb2997f 100644
--- a/scripts/ensure-agent-binaries.mjs
+++ b/scripts/ensure-agent-binaries.mjs
@@ -107,7 +107,9 @@ export function listSiblingWorktreeRoots(rootDir) {
}
let selfReal = rootDir;
try {
- selfReal = fs.realpathSync(rootDir);
+ // Windows 的 TEMP 可能是 8.3 短路径,而 git worktree 输出长路径。native
+ // realpath 会把两种表示解析到同一物理目录,避免把当前 worktree 当成兄弟项。
+ selfReal = fs.realpathSync.native(rootDir);
} catch {
/* keep rootDir as-is */
}
@@ -118,7 +120,7 @@ export function listSiblingWorktreeRoots(rootDir) {
if (!raw) continue;
let real;
try {
- real = fs.realpathSync(raw); // stale 的 worktree 条目(目录已删)直接跳过
+ real = fs.realpathSync.native(raw); // stale 的 worktree 条目(目录已删)直接跳过
} catch {
continue;
}