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: 阻止 symlink 用例按平台硬跳过

DavidShen9ef3de486615
diff --git a/apps/desktop/src/main/__tests__/clientEndpointsService.test.ts b/apps/desktop/src/main/__tests__/clientEndpointsService.test.ts
index 7fc96ef819..8d4028d29d 100644
--- a/apps/desktop/src/main/__tests__/clientEndpointsService.test.ts
+++ b/apps/desktop/src/main/__tests__/clientEndpointsService.test.ts
@@ -19,6 +19,20 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { TEST_CLIENT_ENDPOINTS } from '../../test/vitest/clientEndpointsFixture';
+const canLinkFile = (() => {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'client-endpoints-file-link-probe-'));
+ try {
+ const target = path.join(root, 'target');
+ fs.writeFileSync(target, 'probe');
+ fs.symlinkSync(target, path.join(root, 'link'), 'file');
+ return true;
+ } catch {
+ return false;
+ } finally {
+ fs.rmSync(root, { recursive: true, force: true });
+ }
+})();
+
const ipcOn = vi.hoisted(() => vi.fn());
const netRequest = vi.hoisted(() => vi.fn());
const showMessageBoxSync = vi.hoisted(() => vi.fn());
@@ -1387,12 +1401,15 @@ describe('netlog 产物事后核对(verifyEndpointNetLogCapture)', () => {
it('目录项被换成 symlink → 不通过(产物丢弃)', () => {
// 这是攻击的真实形状:把我们创建的目录项换成指向别处的 symlink,好让 Chromium
// 写到别的地方去。lstat 不跟随 symlink,所以 isDirectory() 为 false。
- if (process.platform === 'win32') return;
const capture = prepareEndpointNetLogFile(logDir)!;
const captureDir = path.dirname(capture.file);
const elsewhere = fs.mkdtempSync(path.join(logDir, 'elsewhere-'));
fs.rmSync(captureDir, { recursive: true, force: true });
- fs.symlinkSync(elsewhere, captureDir);
+ fs.symlinkSync(
+ elsewhere,
+ captureDir,
+ process.platform === 'win32' ? 'junction' : 'dir',
+ );
fs.writeFileSync(capture.file, '{}', 'utf8');
expect(verifyEndpointNetLogCapture(capture)).toBe(false);
});
@@ -1414,7 +1431,7 @@ describe('netlog 产物事后核对(verifyEndpointNetLogCapture)', () => {
});
it('目标被换成 symlink → 不通过', () => {
- if (process.platform === 'win32') return;
+ if (!canLinkFile) return;
const capture = prepareEndpointNetLogFile(logDir)!;
const real = path.join(logDir, 'elsewhere.json');
fs.writeFileSync(real, '{}', 'utf8');
diff --git a/apps/desktop/src/main/__tests__/codexFileRestoreExecutor.git-integration.test.ts b/apps/desktop/src/main/__tests__/codexFileRestoreExecutor.git-integration.test.ts
index 0cf55ab68a..bd1090fa62 100644
--- a/apps/desktop/src/main/__tests__/codexFileRestoreExecutor.git-integration.test.ts
+++ b/apps/desktop/src/main/__tests__/codexFileRestoreExecutor.git-integration.test.ts
@@ -301,7 +301,6 @@ describe('executeCodexFileRestorePlan', () => {
}, REAL_GIT_TEST_TIMEOUT_MS);
it('never deletes through a symlinked parent that escapes the repository', async () => {
- if (process.platform === 'win32') return; // 符号链接在 Windows CI 上需要特权
await writeFile('a.txt', 'base\n');
await commitAll('seed');
const turnStart = await shadowSavepoint('turn-start');
@@ -313,7 +312,11 @@ describe('executeCodexFileRestorePlan', () => {
try {
await fs.writeFile(path.join(outside, 'target.txt'), 'precious external data\n', 'utf8');
await fs.rm(path.join(repoPath, 'evil'), { recursive: true });
- await fs.symlink(outside, path.join(repoPath, 'evil'));
+ await fs.symlink(
+ outside,
+ path.join(repoPath, 'evil'),
+ process.platform === 'win32' ? 'junction' : 'dir',
+ );
const plan = buildPlan([{ commit: afterEdit, baselineCommit: turnStart }], await head());
const result = await executeCodexFileRestorePlan(plan, {
@@ -335,7 +338,6 @@ describe('executeCodexFileRestorePlan', () => {
}, REAL_GIT_TEST_TIMEOUT_MS);
it('never restores through a symlinked parent that escapes the repository', async () => {
- if (process.platform === 'win32') return; // 符号链接在 Windows CI 上需要特权
await writeFile('evil/target.txt', 'baseline\n');
await commitAll('seed evil');
const turnStart = await shadowSavepoint('turn-start');
@@ -346,7 +348,11 @@ describe('executeCodexFileRestorePlan', () => {
const outside = await fs.mkdtemp(path.join(path.dirname(repoPath), 'outside-'));
try {
await fs.writeFile(path.join(outside, 'target.txt'), 'external data\n', 'utf8');
- await fs.symlink(outside, path.join(repoPath, 'evil'));
+ await fs.symlink(
+ outside,
+ path.join(repoPath, 'evil'),
+ process.platform === 'win32' ? 'junction' : 'dir',
+ );
const plan = buildPlan([{ commit: afterEdit, baselineCommit: turnStart }], await head());
// 恢复目标的最近存在祖先(evil)真实路径在仓库外 → 改动前中止:
diff --git a/apps/desktop/src/main/__tests__/codexGlobalPlugins.test.ts b/apps/desktop/src/main/__tests__/codexGlobalPlugins.test.ts
index 7e42e0d5e6..946a15f943 100644
--- a/apps/desktop/src/main/__tests__/codexGlobalPlugins.test.ts
+++ b/apps/desktop/src/main/__tests__/codexGlobalPlugins.test.ts
@@ -477,7 +477,7 @@ describe('prepareCodexGlobalPluginsBridge', () => {
expect(isolatedMcp.mcpServers).not.toHaveProperty('feishu-delegate');
});
- it.skipIf(process.platform === 'win32')(
+ it(
'fails closed instead of following symlinks out of a protected plugin',
async () => {
const { homeDir, codexHome, paths } = await setup();
@@ -498,7 +498,7 @@ describe('prepareCodexGlobalPluginsBridge', () => {
await fs.symlink(
outsideSkill,
path.join(pluginDir, 'skills', 'message-feishu-coworkers'),
- 'dir',
+ process.platform === 'win32' ? 'junction' : 'dir',
);
await writePluginEnabledState(
paths.sourceConfigFile,
@@ -521,7 +521,7 @@ describe('prepareCodexGlobalPluginsBridge', () => {
},
);
- it.skipIf(process.platform === 'win32')(
+ it(
'fails closed when the protected plugin root itself is a symlink',
async () => {
const { homeDir, codexHome, paths } = await setup();
@@ -543,7 +543,7 @@ describe('prepareCodexGlobalPluginsBridge', () => {
await fs.symlink(
realPluginDir,
path.join(marketplaceDir, 'feishu-delegate'),
- 'dir',
+ process.platform === 'win32' ? 'junction' : 'dir',
);
await writePluginEnabledState(
paths.sourceConfigFile,
diff --git a/apps/desktop/src/main/__tests__/gitSnapshotShadow.git-integration.test.ts b/apps/desktop/src/main/__tests__/gitSnapshotShadow.git-integration.test.ts
index 555dac5d18..f8ea3bbd7f 100644
--- a/apps/desktop/src/main/__tests__/gitSnapshotShadow.git-integration.test.ts
+++ b/apps/desktop/src/main/__tests__/gitSnapshotShadow.git-integration.test.ts
@@ -7,6 +7,8 @@
*/
import { promises as fs } from 'node:fs';
+import fsSync from 'node:fs';
+import os from 'node:os';
import path from 'node:path';
import { afterAll, afterEach, beforeEach, describe, expect, it } from 'vitest';
@@ -33,6 +35,20 @@ import { gitExec } from '../worktree/gitExec';
const REAL_GIT_TEST_TIMEOUT_MS = process.platform === 'win32' ? 60_000 : 20_000;
const SESSION = 'shadow-sess-1';
+const canLinkFile = (() => {
+ const root = fsSync.mkdtempSync(path.join(os.tmpdir(), 'shadow-file-link-probe-'));
+ try {
+ const target = path.join(root, 'target');
+ fsSync.writeFileSync(target, 'probe');
+ fsSync.symlinkSync(target, path.join(root, 'link'), 'file');
+ return true;
+ } catch {
+ return false;
+ } finally {
+ fsSync.rmSync(root, { recursive: true, force: true });
+ }
+})();
+
let repoPath: string;
const originalGitLocaleEnv = {
LC_ALL: process.env.LC_ALL,
@@ -226,8 +242,8 @@ describe('createShadowSavepoint', () => {
expect(entries[0]?.baseHead).toBeUndefined();
}, REAL_GIT_TEST_TIMEOUT_MS);
- it('treats tracked files behind an out-of-repo symlinked parent as deleted', async () => {
- if (process.platform === 'win32') return; // 符号链接在 Windows CI 上需要特权
+ it.skipIf(!canLinkFile)('treats tracked files behind an out-of-repo symlinked parent as deleted', async () => {
+ await gitExec(['config', 'core.symlinks', 'true'], repoPath);
await commitSeed();
await writeRepoFile('evil/target.txt', 'tracked base\n');
await gitExec(['add', '-A'], repoPath);
@@ -238,7 +254,7 @@ describe('createShadowSavepoint', () => {
try {
await fs.writeFile(path.join(outside, 'target.txt'), 'external secret\n', 'utf8');
await fs.rm(path.join(repoPath, 'evil'), { recursive: true });
- await fs.symlink(outside, path.join(repoPath, 'evil'));
+ await fs.symlink(outside, path.join(repoPath, 'evil'), 'dir');
const result = await createShadowSavepoint(repoPath, {
sessionId: SESSION,
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts
index bf6e0d63fe..991f664334 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts
@@ -23,6 +23,20 @@ import { GhostInstallReceiptStore, hashApprovedSkillContent } from '../ghostInst
import { forgeInstallOriginForMembership } from '../forgeOidcInstallConfirmBridge';
import { runGhostSnapshotWorkerRequest } from '../ghostSnapshotWorkerProcess';
+const canLinkFile = (() => {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ghost-manager-file-link-probe-'));
+ try {
+ const target = path.join(root, 'target');
+ fs.writeFileSync(target, 'probe');
+ fs.symlinkSync(target, path.join(root, 'link'), 'file');
+ return true;
+ } catch {
+ return false;
+ } finally {
+ fs.rmSync(root, { recursive: true, force: true });
+ }
+})();
+
/** 每个用例独立的临时仓库根 + 源文件目录(规则 23:测试路径一律 os.tmpdir)。 */
let workDir: string;
let rootDir: string;
@@ -857,7 +871,7 @@ describe('GhostManager · 迁移崩溃安全(in-progress 状态机)与隔离命
expect(await fs.promises.readFile(migrationLedgerPath(), 'utf8')).toBe('{ not valid json');
});
- it.skipIf(process.platform === 'win32')(
+ it.skipIf(!canLinkFile)(
'台账是非普通文件(symlink)→ 门保守关死,不迁也不重写',
async () => {
await writeLegacyInstall('aaa', goodManifest('aaa'));
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/ghostManual.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/ghostManual.test.ts
index f196c83d11..3069ae7f2a 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/ghostManual.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/ghostManual.test.ts
@@ -8,6 +8,20 @@ import type { GhostManifest, InstalledGhost } from '../../../shared/ghost';
import { readInstalledGhostManual } from '../ghostManual';
let workDir: string;
+const directoryLinkType = process.platform === 'win32' ? 'junction' : 'dir';
+const canLinkFile = (() => {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ghost-manual-file-link-probe-'));
+ try {
+ const target = path.join(root, 'target');
+ fs.writeFileSync(target, 'probe');
+ fs.symlinkSync(target, path.join(root, 'link'), 'file');
+ return true;
+ } catch {
+ return false;
+ } finally {
+ fs.rmSync(root, { recursive: true, force: true });
+ }
+})();
beforeEach(async () => {
workDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'cindy-ghost-manual-test-'));
@@ -175,12 +189,15 @@ describe('readInstalledGhostManual', () => {
});
it('声明目录的中间层符号链接不能逃出插件安装根', async () => {
- if (process.platform === 'win32') return;
const outsideDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'cindy-manual-outside-'));
try {
await fs.promises.mkdir(path.join(workDir, 'docs'), { recursive: true });
await fs.promises.writeFile(path.join(outsideDir, 'MANUAL.md'), '# 根外私密正文');
- await fs.promises.symlink(outsideDir, path.join(workDir, 'docs/physical-dir'));
+ await fs.promises.symlink(
+ outsideDir,
+ path.join(workDir, 'docs/physical-dir'),
+ directoryLinkType,
+ );
const result = await readInstalledGhostManual(ghost(), 'logical-name');
expect(result).toMatchObject({
ok: false,
@@ -196,7 +213,6 @@ describe('readInstalledGhostManual', () => {
});
it('item.dir 任一中间组件是根内或根外 symlink 都不可用,普通中间目录可读', async () => {
- if (process.platform === 'win32') return;
await write('docs/plain/unit/MANUAL.md', '# 普通中间目录');
expect(await readInstalledGhostManual(ghost('docs/plain/unit'), 'logical-name')).toMatchObject({
ok: true,
@@ -215,7 +231,7 @@ describe('readInstalledGhostManual', () => {
] as const) {
const linkPath = path.join(workDir, 'docs/link');
await fs.promises.rm(linkPath, { force: true });
- await fs.promises.symlink(target, linkPath);
+ await fs.promises.symlink(target, linkPath, directoryLinkType);
const result = await readInstalledGhostManual(ghost('docs/link/unit'), 'logical-name');
expect(result).toMatchObject({
ok: false,
@@ -252,7 +268,7 @@ describe('readInstalledGhostManual', () => {
await write('docs/physical-dir/MANUAL.md', Buffer.from([0xff, 0xfe, 0xfd]));
await assertUnavailable();
- if (process.platform !== 'win32') {
+ if (canLinkFile) {
const target = path.join(workDir, 'outside.md');
await fs.promises.writeFile(target, '# outside');
await fs.promises.rm(path.join(workDir, 'docs/physical-dir/MANUAL.md'));
@@ -262,7 +278,6 @@ describe('readInstalledGhostManual', () => {
});
it('单元内的中间目录符号链接无论指向根内还是根外都不可读取', async () => {
- if (process.platform === 'win32') return;
await write('docs/physical-dir/MANUAL.md', '# 入口');
await write('docs/physical-dir/real-inside/private.md', '# 根内私密正文');
const outsideDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'cindy-manual-child-'));
@@ -272,7 +287,11 @@ describe('readInstalledGhostManual', () => {
['inside-link', path.join(workDir, 'docs/physical-dir/real-inside'), '根内私密正文'],
['outside-link', outsideDir, '根外私密正文'],
] as const) {
- await fs.promises.symlink(target, path.join(workDir, `docs/physical-dir/${linkName}`));
+ await fs.promises.symlink(
+ target,
+ path.join(workDir, `docs/physical-dir/${linkName}`),
+ directoryLinkType,
+ );
const result = await readInstalledGhostManual(
ghost(),
`logical-name/${linkName}/private.md`,
diff --git a/apps/desktop/src/main/git-review/__tests__/stageOps.git-integration.test.ts b/apps/desktop/src/main/git-review/__tests__/stageOps.git-integration.test.ts
index 554b8d910e..af3f00851b 100644
--- a/apps/desktop/src/main/git-review/__tests__/stageOps.git-integration.test.ts
+++ b/apps/desktop/src/main/git-review/__tests__/stageOps.git-integration.test.ts
@@ -1,4 +1,5 @@
import { promises as fs } from 'node:fs';
+import fsSync from 'node:fs';
import os from 'node:os';
import path from 'node:path';
@@ -15,6 +16,20 @@ import type { DiffSelection, FileDiff, ReviewDiffReadOptions, ReviewFileTarget,
let repoPath: string;
+const canLinkFile = (() => {
+ const root = fsSync.mkdtempSync(path.join(os.tmpdir(), 'git-review-file-link-probe-'));
+ try {
+ const target = path.join(root, 'target');
+ fsSync.writeFileSync(target, 'probe');
+ fsSync.symlinkSync(target, path.join(root, 'link'), 'file');
+ return true;
+ } catch {
+ return false;
+ } finally {
+ fsSync.rmSync(root, { recursive: true, force: true });
+ }
+})();
+
const repoTemplate = new TestDirectoryTemplate('xdt-git-review-stage-', async (dir) => {
await runGit(['init'], { cwd: dir });
await runGit(['config', 'user.email', '[email protected]'], { cwd: dir });
@@ -395,7 +410,8 @@ describe('git-review stageOps', () => {
await expect(applyHunkSelection(scope(), current, 'unstage', diff, selectLines(diff))).rejects.toThrow(GitReviewStageError);
});
- it.skipIf(process.platform === 'win32')('rejects partial typechange staging while whole-file staging remains valid', async () => {
+ it.skipIf(!canLinkFile)('rejects partial typechange staging while whole-file staging remains valid', async () => {
+ await runGit(['config', 'core.symlinks', 'true'], { cwd: repoPath });
await fs.rm(path.join(repoPath, 'file.txt'));
await fs.symlink('target.txt', path.join(repoPath, 'file.txt'));
diff --git a/apps/desktop/src/main/reviewer/__tests__/reviewArtifactFingerprint.test.ts b/apps/desktop/src/main/reviewer/__tests__/reviewArtifactFingerprint.test.ts
index 044db7740d..cf0bef206e 100644
--- a/apps/desktop/src/main/reviewer/__tests__/reviewArtifactFingerprint.test.ts
+++ b/apps/desktop/src/main/reviewer/__tests__/reviewArtifactFingerprint.test.ts
@@ -1,4 +1,4 @@
-import { constants, promises as fs } from 'node:fs';
+import fsSync, { constants, promises as fs } from 'node:fs';
import os from 'node:os';
import path from 'node:path';
@@ -14,6 +14,20 @@ import {
const tempDirs: string[] = [];
+const canLinkFile = (() => {
+ const root = fsSync.mkdtempSync(path.join(os.tmpdir(), 'review-fingerprint-file-link-probe-'));
+ try {
+ const target = path.join(root, 'target');
+ fsSync.writeFileSync(target, 'probe');
+ fsSync.symlinkSync(target, path.join(root, 'link'), 'file');
+ return true;
+ } catch {
+ return false;
+ } finally {
+ fsSync.rmSync(root, { recursive: true, force: true });
+ }
+})();
+
async function makeTempDir(): Promise<string> {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'cindy-review-fingerprint-'));
tempDirs.push(dir);
@@ -195,7 +209,7 @@ describe('review artifact fingerprint', () => {
});
it('does not follow a symlink that already replaced an artifact root', async () => {
- if (process.platform === 'win32') return;
+ if (!canLinkFile) return;
const dir = await makeTempDir();
const link = path.join(dir, 'approved.txt');
const sensitive = path.join(dir, 'private-key');
@@ -242,6 +256,7 @@ describe('review artifact fingerprint', () => {
);
});
+ // symlink-platform-skip: This case validates POSIX inode and hard-link confinement semantics.
it('accepts a scoped pnpm mirror derived from confined package metadata', async () => {
if (process.platform === 'win32') return;
const root = await makeTempDir();
diff --git a/apps/desktop/src/main/reviewer/__tests__/reviewArtifactSnapshot.test.ts b/apps/desktop/src/main/reviewer/__tests__/reviewArtifactSnapshot.test.ts
index 428d2fb20f..84b2827108 100644
--- a/apps/desktop/src/main/reviewer/__tests__/reviewArtifactSnapshot.test.ts
+++ b/apps/desktop/src/main/reviewer/__tests__/reviewArtifactSnapshot.test.ts
@@ -1,4 +1,5 @@
import { promises as fs } from 'node:fs';
+import fsSync from 'node:fs';
import os from 'node:os';
import path from 'node:path';
@@ -20,6 +21,19 @@ import {
import { ReviewArtifactChangedDuringPreparationError } from '../reviewArtifactFingerprint.js';
const tempDirs: string[] = [];
+const canLinkFile = (() => {
+ const root = fsSync.mkdtempSync(path.join(os.tmpdir(), 'review-snapshot-file-link-probe-'));
+ try {
+ const target = path.join(root, 'target');
+ fsSync.writeFileSync(target, 'probe');
+ fsSync.symlinkSync(target, path.join(root, 'link'), 'file');
+ return true;
+ } catch {
+ return false;
+ } finally {
+ fsSync.rmSync(root, { recursive: true, force: true });
+ }
+})();
const TEST_OWNER: ReviewRunOwner = {
instanceId: 'snapshot-test-owner',
processId: process.pid,
@@ -212,7 +226,7 @@ describe('materializeReviewArtifactSnapshots', () => {
});
it('rejects a symlink substituted after the original path was authorized', async () => {
- if (process.platform === 'win32') return;
+ if (!canLinkFile) return;
const workingDir = await tempDir();
const externalDir = await tempDir();
const sourcePath = path.join(externalDir, 'poster.png');
@@ -373,13 +387,16 @@ describe('materializeReviewArtifactSnapshots', () => {
});
it('does not follow a snapshot-shaped symlink while reaping orphans', async () => {
- if (process.platform === 'win32') return;
const scanRoot = await tempDir();
const targetRoot = await tempDir();
const targetFile = path.join(targetRoot, 'keep.txt');
const linkPath = path.join(scanRoot, 'cindy-review-artifacts-v1-424242-Ij56Kl');
await fs.writeFile(targetFile, 'keep');
- await fs.symlink(targetRoot, linkPath);
+ await fs.symlink(
+ targetRoot,
+ linkPath,
+ process.platform === 'win32' ? 'junction' : 'dir',
+ );
await cleanupOrphanedReviewArtifactSnapshots({
currentOwner: TEST_OWNER,
diff --git a/apps/desktop/src/main/reviewer/__tests__/reviewCappedWorkspaceFingerprint.test.ts b/apps/desktop/src/main/reviewer/__tests__/reviewCappedWorkspaceFingerprint.test.ts
index b06744eb70..cf69f5a9de 100644
--- a/apps/desktop/src/main/reviewer/__tests__/reviewCappedWorkspaceFingerprint.test.ts
+++ b/apps/desktop/src/main/reviewer/__tests__/reviewCappedWorkspaceFingerprint.test.ts
@@ -1,4 +1,5 @@
import { promises as fs } from 'node:fs';
+import fsSync from 'node:fs';
import os from 'node:os';
import path from 'node:path';
@@ -12,6 +13,20 @@ import {
const tempDirs: string[] = [];
+const canLinkFile = (() => {
+ const root = fsSync.mkdtempSync(path.join(os.tmpdir(), 'review-capped-file-link-probe-'));
+ try {
+ const target = path.join(root, 'target');
+ fsSync.writeFileSync(target, 'probe');
+ fsSync.symlinkSync(target, path.join(root, 'link'), 'file');
+ return true;
+ } catch {
+ return false;
+ } finally {
+ fsSync.rmSync(root, { recursive: true, force: true });
+ }
+})();
+
async function makeTempDir(): Promise<string> {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'cindy-review-capped-fingerprint-'));
tempDirs.push(dir);
@@ -65,7 +80,7 @@ describe('capped Review workspace fingerprint', () => {
fingerprintReviewCappedWorkspaceFiles(repoRoot, ['../outside.ts']),
).rejects.toBeInstanceOf(ReviewCappedWorkspaceFingerprintError);
- if (process.platform === 'win32') return;
+ if (!canLinkFile) return;
const outside = await makeTempDir();
await fs.writeFile(path.join(outside, 'outside.ts'), 'outside');
await fs.symlink(path.join(outside, 'outside.ts'), path.join(repoRoot, 'linked.ts'));
@@ -80,7 +95,7 @@ describe('capped Review workspace fingerprint', () => {
).rejects.toBeInstanceOf(ReviewCappedWorkspaceFingerprintError);
});
- it.skipIf(process.platform === 'win32')(
+ it.skipIf(!canLinkFile)(
'symlinkMode link-text binds the link text without resolving the target (#2463 review)',
async () => {
// 悬空 / 指向仓库外的 symlink 是合法 Git 改动(Git 记录的内容就是链接
@@ -101,6 +116,7 @@ describe('capped Review workspace fingerprint', () => {
},
);
+ // symlink-platform-skip: Windows cannot represent a symlink target containing arbitrary non-UTF-8 bytes.
it.skipIf(process.platform === 'win32')(
'symlinkMode link-text distinguishes non-UTF-8 target bytes (#2463 review)',
async () => {
@@ -120,7 +136,7 @@ describe('capped Review workspace fingerprint', () => {
},
);
- it.skipIf(process.platform === 'win32')(
+ it.skipIf(!canLinkFile)(
'symlinkMode link-text never reads target bytes (#2463 review)',
async () => {
// 指向敏感文件的链接:只绑定文本,目标内容变化不得进入指纹 ——
diff --git a/apps/desktop/src/main/reviewer/__tests__/reviewSubmoduleIdentity.git-integration.test.ts b/apps/desktop/src/main/reviewer/__tests__/reviewSubmoduleIdentity.git-integration.test.ts
index 4a05a9f708..c5c62eb77e 100644
--- a/apps/desktop/src/main/reviewer/__tests__/reviewSubmoduleIdentity.git-integration.test.ts
+++ b/apps/desktop/src/main/reviewer/__tests__/reviewSubmoduleIdentity.git-integration.test.ts
@@ -1,4 +1,6 @@
import { promises as fs } from 'node:fs';
+import fsSync from 'node:fs';
+import os from 'node:os';
import path from 'node:path';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
@@ -17,6 +19,20 @@ import {
let workRoot: string;
let parentPath: string;
+const canLinkFile = (() => {
+ const root = fsSync.mkdtempSync(path.join(os.tmpdir(), 'review-submodule-file-link-probe-'));
+ try {
+ const target = path.join(root, 'target');
+ fsSync.writeFileSync(target, 'probe');
+ fsSync.symlinkSync(target, path.join(root, 'link'), 'file');
+ return true;
+ } catch {
+ return false;
+ } finally {
+ fsSync.rmSync(root, { recursive: true, force: true });
+ }
+})();
+
// CI runner 没有全局 git 身份;每个会执行 commit 的仓库(含 submodule 克隆)都要配本地身份。
async function configureRepo(dir: string): Promise<void> {
await runGit(['config', 'user.email', '[email protected]'], { cwd: dir });
@@ -585,7 +601,7 @@ describe('readReviewSubmoduleIdentity intent-to-add 状态绑定 (#2463 review)'
});
describe('子仓 symlink 按链接文本绑定 (#2463 review)', () => {
- it.skipIf(process.platform === 'win32')(
+ it.skipIf(!canLinkFile)(
'binds a dirty submodule symlink pointing outside the sub without aborting',
async () => {
// 子仓里指向子仓外(../ 解析进父仓)或悬空的 symlink 是常见合法改动:
@@ -606,7 +622,7 @@ describe('子仓 symlink 按链接文本绑定 (#2463 review)', () => {
},
);
- it.skipIf(process.platform === 'win32')(
+ it.skipIf(!canLinkFile)(
'binds a gitlink replaced by an outside-pointing symlink (typechange) without aborting',
async () => {
// gitlink 整个被 symlink 替换(typechange):sub 字段仍标 S 路由到子仓
@@ -627,7 +643,7 @@ describe('子仓 symlink 按链接文本绑定 (#2463 review)', () => {
},
);
- it.skipIf(process.platform === 'win32')(
+ it(
'fails closed when a symlinked ancestor resolves the sub outside the parent repo',
async () => {
// 祖先目录 vendor 被换成指向父仓外的 symlink:lstat/realpath 跟随中间
@@ -643,7 +659,11 @@ describe('子仓 symlink 按链接文本绑定 (#2463 review)', () => {
await runGit(['commit', '--no-gpg-sign', '-m', 'outside seed'], { cwd: escapeCheckout });
await fs.rm(path.join(parent, 'vendor'), { recursive: true, force: true });
- await fs.symlink(escapeRoot, path.join(parent, 'vendor'));
+ await fs.symlink(
+ escapeRoot,
+ path.join(parent, 'vendor'),
+ process.platform === 'win32' ? 'junction' : 'dir',
+ );
await expect(
readReviewSubmoduleIdentity(parentPath, ['vendor/lib']),
diff --git a/apps/desktop/src/main/skillhub/__tests__/scanner.test.ts b/apps/desktop/src/main/skillhub/__tests__/scanner.test.ts
index 0f5e59f5e8..98d6cb7feb 100644
--- a/apps/desktop/src/main/skillhub/__tests__/scanner.test.ts
+++ b/apps/desktop/src/main/skillhub/__tests__/scanner.test.ts
@@ -25,6 +25,20 @@ import type { Maker } from '@cindy/maker-core';
const tempRoots: string[] = [];
+const canLinkFile = (() => {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'skillhub-file-link-probe-'));
+ try {
+ const target = path.join(root, 'target');
+ fs.writeFileSync(target, 'probe');
+ fs.symlinkSync(target, path.join(root, 'link'), 'file');
+ return true;
+ } catch {
+ return false;
+ } finally {
+ fs.rmSync(root, { recursive: true, force: true });
+ }
+})();
+
afterEach(() => {
for (const root of tempRoots.splice(0)) {
fs.rmSync(root, { recursive: true, force: true });
@@ -441,7 +455,7 @@ describe('scanAllSkills', () => {
});
describe('skill file access', () => {
- it.skipIf(process.platform === 'win32')('rejects writing through a final file symlink', async () => {
+ it.skipIf(!canLinkFile)('rejects writing through a final file symlink', async () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'skillhub-write-file-link-'));
tempRoots.push(root);
const skillDir = path.join(root, '.agents', 'skills', 'linked-file');
@@ -508,7 +522,7 @@ describe('skill file access', () => {
);
});
- it.skipIf(process.platform === 'win32')('rejects renaming a skill whose SKILL.md is a symlink', async () => {
+ it.skipIf(!canLinkFile)('rejects renaming a skill whose SKILL.md is a symlink', async () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'skillhub-pi-rename-md-link-'));
tempRoots.push(root);
const skillRoot = path.join(root, 'project', '.pi', 'skills');
diff --git a/packages/lizi-mcps/src/computer/computerMcpServer.test.ts b/packages/lizi-mcps/src/computer/computerMcpServer.test.ts
index d7220d0ae4..25fec20b65 100644
--- a/packages/lizi-mcps/src/computer/computerMcpServer.test.ts
+++ b/packages/lizi-mcps/src/computer/computerMcpServer.test.ts
@@ -1,4 +1,5 @@
import { promises as fs } from 'node:fs';
+import fsSync from 'node:fs';
import os from 'node:os';
import path from 'node:path';
@@ -8,6 +9,20 @@ import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
import { createComputerMcpServer } from './server.js';
import type { ComputerMcpDeps } from '../types.js';
+const canLinkFile = (() => {
+ const root = fsSync.mkdtempSync(path.join(os.tmpdir(), 'computer-file-link-probe-'));
+ try {
+ const target = path.join(root, 'target');
+ fsSync.writeFileSync(target, 'probe');
+ fsSync.symlinkSync(target, path.join(root, 'link'), 'file');
+ return true;
+ } catch {
+ return false;
+ } finally {
+ fsSync.rmSync(root, { recursive: true, force: true });
+ }
+})();
+
/** Temp session workingDir for path-boundary-constrained tools (recording/replay). */
async function makeWorkingDir(): Promise<string> {
return fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), 'computer-wd-')));
@@ -988,7 +1003,7 @@ describe('createComputerMcpServer', () => {
await fs.rm(root, { recursive: true, force: true });
});
- it.skipIf(process.platform === 'win32')(
+ it(
'replays inside a workingDir reached through a symbolic link',
async () => {
const deps: ComputerMcpDeps = {
@@ -999,7 +1014,11 @@ describe('createComputerMcpServer', () => {
const realWorkingDir = path.join(container, 'real-workspace');
const linkedWorkingDir = path.join(container, 'linked-workspace');
await fs.mkdir(realWorkingDir);
- await fs.symlink(realWorkingDir, linkedWorkingDir, 'dir');
+ await fs.symlink(
+ realWorkingDir,
+ linkedWorkingDir,
+ process.platform === 'win32' ? 'junction' : 'dir',
+ );
await writeTrajectory(realWorkingDir, [
{
tool: 'get_window_state',
@@ -1123,7 +1142,7 @@ describe('createComputerMcpServer', () => {
await fs.rm(root, { recursive: true, force: true });
});
- it.skipIf(process.platform === 'win32')(
+ it(
'rejects a recorded turn that escapes through a symlink',
async () => {
const deps: ComputerMcpDeps = {
@@ -1138,7 +1157,11 @@ describe('createComputerMcpServer', () => {
JSON.stringify({ tool: 'get_screen_size', arguments: {} }),
'utf8',
);
- await fs.symlink(outside, path.join(root, 'rec', 'turn-00001'), 'dir');
+ await fs.symlink(
+ outside,
+ path.join(root, 'rec', 'turn-00001'),
+ process.platform === 'win32' ? 'junction' : 'dir',
+ );
const h = await makeHarness(deps, {
getSessionContext: () => ({
agentKind: 'claude-code',
@@ -1166,7 +1189,7 @@ describe('createComputerMcpServer', () => {
},
);
- it.skipIf(process.platform === 'win32')(
+ it.skipIf(!canLinkFile)(
'rejects a symbolic-link action file even when its target stays in the task',
async () => {
const deps: ComputerMcpDeps = {
diff --git a/packages/maker-core/src/agents/claude-code/__tests__/auto-review-wiring.test.ts b/packages/maker-core/src/agents/claude-code/__tests__/auto-review-wiring.test.ts
index 78b2fdfe5e..3ab91d19a2 100644
--- a/packages/maker-core/src/agents/claude-code/__tests__/auto-review-wiring.test.ts
+++ b/packages/maker-core/src/agents/claude-code/__tests__/auto-review-wiring.test.ts
@@ -671,12 +671,16 @@ describe('Auto-review wiring: safe builtin tools auto-approve silently', () => {
await handle.close();
});
- it.skipIf(process.platform === 'win32')(
+ it(
'prompts when a dangling link prevents proving the write target',
async () => {
const writableDir = await makeTempDir();
const linkedDir = path.join(writableDir, 'dangling-output');
- await fs.symlink(path.join(writableDir, 'missing-target'), linkedDir, 'dir');
+ await fs.symlink(
+ path.join(writableDir, 'missing-target'),
+ linkedDir,
+ process.platform === 'win32' ? 'junction' : 'dir',
+ );
const { handle, canUseTool, reviewAutoPermissionAction, seen } = await startSession('auto', {
writableDirs: [writableDir],
});
diff --git a/packages/maker-core/src/agents/pi/__tests__/cindyBridgeSource.test.ts b/packages/maker-core/src/agents/pi/__tests__/cindyBridgeSource.test.ts
index 879f278065..e0df5f3f39 100644
--- a/packages/maker-core/src/agents/pi/__tests__/cindyBridgeSource.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/cindyBridgeSource.test.ts
@@ -28,6 +28,20 @@ import {
CINDY_PI_BASH_MAX_TIMEOUT_SECONDS,
} from '../cindy-bridge-source.js';
+const canLinkFile = (() => {
+ const root = mkdtempSync(path.join(tmpdir(), 'cindy-bridge-file-link-probe-'));
+ try {
+ const target = path.join(root, 'target');
+ writeFileSync(target, 'probe');
+ symlinkSync(target, path.join(root, 'link'), 'file');
+ return true;
+ } catch {
+ return false;
+ } finally {
+ rmSync(root, { recursive: true, force: true });
+ }
+})();
+
type ReviewSearchHelpers = {
collectReadonlyCredentialEvidence: (
toolName: string,
@@ -527,6 +541,7 @@ describe('cindy-bridge extension source', () => {
}
});
+ // symlink-platform-skip: This case validates POSIX shell and filename semantics that Windows cannot represent.
it.skipIf(process.platform === 'win32')(
'collects canonical credential targets without flagging ordinary symlinks',
() => {
@@ -1625,7 +1640,7 @@ describe('cindy-bridge extension source', () => {
expect(source).toContain('REVIEW_CREDENTIAL_GLOB_PATTERNS.some');
});
- it.skipIf(process.platform === 'win32')(
+ it.skipIf(!canLinkFile)(
'pins every Pi read tool to the real path that passed Review validation',
() => {
const source = CINDY_BRIDGE_EXTENSION_SOURCE;
diff --git a/packages/maker-core/src/agents/pi/__tests__/cindySubagentRunner.test.ts b/packages/maker-core/src/agents/pi/__tests__/cindySubagentRunner.test.ts
index ae53e5bf95..5dad5b390c 100644
--- a/packages/maker-core/src/agents/pi/__tests__/cindySubagentRunner.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/cindySubagentRunner.test.ts
@@ -1011,7 +1011,7 @@ describe('Cindy durable PI Subagent runner', () => {
expect(resumedPrompts.at(-1)).toBe('continue for a second resumed generation');
});
- it.skipIf(process.platform === 'win32')('refuses a resume catalog redirected through a symlink', async () => {
+ it('refuses a resume catalog redirected through a symlink', async () => {
const fixture = await makeFixture();
const first = await waitFor(async () => {
const runs = await listPiSubagentRuns(fixture.root);
@@ -1022,7 +1022,11 @@ describe('Cindy durable PI Subagent runner', () => {
await mkdir(outside);
await writeFile(path.join(outside, 'models.json'), '{"providers":{"redirected":{}}}\n');
await rm(path.join(fixture.runDir, 'pi-home'), { recursive: true });
- await symlink(outside, path.join(fixture.runDir, 'pi-home'), 'dir');
+ await symlink(
+ outside,
+ path.join(fixture.runDir, 'pi-home'),
+ process.platform === 'win32' ? 'junction' : 'dir',
+ );
await expect(resumePiSubagentRun(
fixture.root,
diff --git a/packages/maker-core/src/agents/pi/__tests__/customization-scanner.test.ts b/packages/maker-core/src/agents/pi/__tests__/customization-scanner.test.ts
index 9f0d06cb70..3a0c8f699d 100644
--- a/packages/maker-core/src/agents/pi/__tests__/customization-scanner.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/customization-scanner.test.ts
@@ -288,14 +288,18 @@ describe('scanPiCustomizations', () => {
expect(result.errors).toEqual([]);
});
- it.skipIf(process.platform === 'win32')('resolves a symlinked working directory for scanning while preserving its ownership path', async () => {
+ it.skipIf(!canLinkDirectory)('resolves a symlinked working directory for scanning while preserving its ownership path', async () => {
const root = tempRoot();
const repo = path.join(root, 'repo');
const physicalCwd = path.join(repo, 'src');
const linkedCwd = path.join(root, 'linked-cwd');
mkdirSync(path.join(repo, '.git'), { recursive: true });
mkdirSync(physicalCwd, { recursive: true });
- symlinkSync(physicalCwd, linkedCwd, 'dir');
+ symlinkSync(
+ physicalCwd,
+ linkedCwd,
+ process.platform === 'win32' ? 'junction' : 'dir',
+ );
writeSkill(repo, path.join('.agents', 'skills'), 'repo-skill');
const result = await scanPiCustomizations({ workingDirs: [linkedCwd] });
@@ -305,12 +309,16 @@ describe('scanPiCustomizations', () => {
expect(canonical(found?.absolutePath ?? '')).toBe(canonical(path.join(repo, '.agents', 'skills', 'repo-skill')));
});
- it.skipIf(process.platform === 'win32')('keeps lexical project aliases distinct for the same physical checkout', async () => {
+ it.skipIf(!canLinkDirectory)('keeps lexical project aliases distinct for the same physical checkout', async () => {
const root = tempRoot();
const repo = path.join(root, 'repo');
const linkedRepo = path.join(root, 'linked-repo');
mkdirSync(path.join(repo, '.git'), { recursive: true });
- symlinkSync(repo, linkedRepo, 'dir');
+ symlinkSync(
+ repo,
+ linkedRepo,
+ process.platform === 'win32' ? 'junction' : 'dir',
+ );
writeSkill(repo, path.join('.pi', 'skills'), 'aliased-skill');
const items = projectItems(await scanPiCustomizations({ workingDirs: [repo, linkedRepo] }))
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 14dee18fb3..4cdb6cb9c9 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
@@ -2525,6 +2525,7 @@ describe.skipIf(!piAvailable)('PiAgent integration (real pi binary + fake gatewa
},
);
+ // symlink-platform-skip: CDPATH and the redirect commands in this case require a POSIX Bash host.
it.skipIf(process.platform === 'win32' || !canSymlink)(
'auto mode fail closes inherited CDPATH while explicit relative cd keeps ordinary reads fast',
{ timeout: 60_000 },
diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-subagent-runs.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-subagent-runs.test.ts
index 078cf495cc..e0d8359462 100644
--- a/packages/maker-core/src/agents/pi/__tests__/pi-subagent-runs.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/pi-subagent-runs.test.ts
@@ -2806,12 +2806,16 @@ describe('PI durable subagent run store', () => {
expect(new Set(controls.map((control) => control.requestId)).size).toBe(2);
});
- it.skipIf(process.platform === 'win32')('refuses a control mailbox redirected through a symlink', async () => {
+ it('refuses a control mailbox redirected through a symlink', async () => {
const root = await makeRoot();
const runId = '123e4567-e89b-42d3-a456-426614174014';
const outside = await makeRoot();
await writeStatus(root, status(runId));
- await symlink(outside, path.join(root, runId, 'controls'), 'dir');
+ await symlink(
+ outside,
+ path.join(root, runId, 'controls'),
+ process.platform === 'win32' ? 'junction' : 'dir',
+ );
await expect(controlPiSubagentRuns(root, runId, 'stop')).rejects.toThrow(/control directory is unavailable/);
await expect(readdir(outside)).resolves.toEqual([]);
diff --git a/packages/maker-core/src/agents/shared/image-resizer.test.ts b/packages/maker-core/src/agents/shared/image-resizer.test.ts
index c6e944898e..d97e01e876 100644
--- a/packages/maker-core/src/agents/shared/image-resizer.test.ts
+++ b/packages/maker-core/src/agents/shared/image-resizer.test.ts
@@ -43,17 +43,21 @@ describe("ImageResizer private cache", () => {
});
it("refuses a symlink in place of the cache directory", async () => {
- if (process.platform === "win32") return;
const root = await tempDir();
const target = path.join(root, "attacker-readable");
const cacheDir = path.join(root, "cache-link");
await fs.mkdir(target, { mode: 0o755 });
- await fs.symlink(target, cacheDir);
+ const targetMode = (await fs.stat(target)).mode & 0o777;
+ await fs.symlink(
+ target,
+ cacheDir,
+ process.platform === "win32" ? "junction" : "dir",
+ );
const resizer = new ImageResizer({ cacheDir });
await expect(resizer.process("/does/not/matter.png")).resolves.toBe(
"/does/not/matter.png",
);
- expect((await fs.stat(target)).mode & 0o777).toBe(0o755);
+ expect((await fs.stat(target)).mode & 0o777).toBe(targetMode);
});
});
diff --git a/packages/maker-core/src/agents/shared/review-read-scope.test.ts b/packages/maker-core/src/agents/shared/review-read-scope.test.ts
index ee478cc170..b001dae8c2 100644
--- a/packages/maker-core/src/agents/shared/review-read-scope.test.ts
+++ b/packages/maker-core/src/agents/shared/review-read-scope.test.ts
@@ -247,6 +247,7 @@ describe("review read scope", () => {
expect(await resolveReviewReadPath(source, workspace, grants)).toBeNull();
});
+ // symlink-platform-skip: This case validates POSIX inode and hard-link confinement semantics.
it("uses a confined package manifest to resolve scoped pnpm mirrors", async () => {
if (process.platform === "win32") return;
const root = await makeTempDir();
diff --git a/scripts/__tests__/test-workspaces.test.mjs b/scripts/__tests__/test-workspaces.test.mjs
index 51675363ef..81438d83a1 100644
--- a/scripts/__tests__/test-workspaces.test.mjs
+++ b/scripts/__tests__/test-workspaces.test.mjs
@@ -53,6 +53,7 @@ import {
resolvePnpmInvocation,
usablePnpmExecPath,
} from "../shared/pnpm-invocation.mjs";
+import { findSymlinkPlatformSkips } from "../shared/symlink-test-guard.mjs";
const ROOT = path.resolve(fileURLToPath(new URL("../..", import.meta.url)));
@@ -531,6 +532,65 @@ test("tests never bind a fixed numeric port", () => {
assert.deepEqual(violations, []);
});
+test("symlink platform-skip guard detects hard skips without flagging capability probes", () => {
+ assert.deepEqual(
+ findSymlinkPlatformSkips(`
+ it.skipIf(process.platform === "win32")("rejects escape", async () => {
+ await fs.symlink(outside, link);
+ });
+ `),
+ [{ line: 2 }],
+ );
+ assert.deepEqual(
+ findSymlinkPlatformSkips(`
+ it.skipIf(!canCreateSymlink)("rejects escape", async () => {
+ await fs.symlink(outside, link);
+ });
+ it.skipIf(process.platform === "win32")("sends SIGTERM", async () => {
+ await stopProcess();
+ });
+ `),
+ [],
+ );
+ assert.deepEqual(
+ findSymlinkPlatformSkips(`
+ it("rejects escape", async () => {
+ if (process.platform === "win32") return;
+ await fs.symlink(outside, link);
+ });
+ `),
+ [{ line: 3 }],
+ );
+});
+
+test("symlink platform-skip guard requires a concrete POSIX-only exception", () => {
+ const skippedTest = `
+ // symlink-platform-skip: Windows cannot represent non-UTF-8 link target bytes.
+ it.skipIf(process.platform === "win32")("hashes raw link bytes", async () => {
+ await fs.symlink(Buffer.from([0xff]), link);
+ });
+ `;
+ assert.deepEqual(findSymlinkPlatformSkips(skippedTest), []);
+ assert.deepEqual(
+ findSymlinkPlatformSkips(skippedTest.replace(
+ "Windows cannot represent non-UTF-8 link target bytes.",
+ "POSIX only",
+ )),
+ [{ line: 3 }],
+ );
+});
+
+test("symlink tests never skip solely because the host is Windows", () => {
+ const violations = [];
+ for (const file of discoverTestFiles(readAllFiles(ROOT))) {
+ const source = fs.readFileSync(path.join(ROOT, file), "utf8");
+ for (const violation of findSymlinkPlatformSkips(source)) {
+ violations.push(`${file}:${violation.line}`);
+ }
+ }
+ assert.deepEqual(violations, []);
+});
+
test("desktop guard selects source-contract tests only", () => {
const workspace = manifest.workspaces.find(
(candidate) => candidate.cwd === "apps/desktop",
diff --git a/scripts/shared/symlink-test-guard.mjs b/scripts/shared/symlink-test-guard.mjs
new file mode 100644
index 0000000000..20c47fd51f
--- /dev/null
+++ b/scripts/shared/symlink-test-guard.mjs
@@ -0,0 +1,136 @@
+const PLATFORM_SKIP_PATTERN = /\.\s*skipIf\s*\(/g;
+const TEST_CALL_PATTERN = /\b(?:it|test)\s*\(/g;
+const SYMLINK_CALL_PATTERN = /\b(?:symlink|symlinkSync)\s*\(/;
+const PLATFORM_EARLY_RETURN_PATTERN =
+ /\bif\s*\(\s*process\s*\.\s*platform\s*={2,3}\s+\)\s*(?:\{\s*)?return\b/g;
+const EXCEPTION_PATTERN = /^\s*\/\/\s*symlink-platform-skip:\s*(.{20,})\s*$/i;
+
+function maskNonCode(source) {
+ const chars = [...source];
+ let index = 0;
+ while (index < chars.length) {
+ const current = chars[index];
+ const next = chars[index + 1];
+ if (current === "/" && next === "/") {
+ chars[index] = " ";
+ chars[index + 1] = " ";
+ index += 2;
+ while (index < chars.length && chars[index] !== "\n") {
+ chars[index] = " ";
+ index += 1;
+ }
+ continue;
+ }
+ if (current === "/" && next === "*") {
+ chars[index] = " ";
+ chars[index + 1] = " ";
+ index += 2;
+ while (index < chars.length) {
+ if (chars[index] === "*" && chars[index + 1] === "/") {
+ chars[index] = " ";
+ chars[index + 1] = " ";
+ index += 2;
+ break;
+ }
+ if (chars[index] !== "\n") chars[index] = " ";
+ index += 1;
+ }
+ continue;
+ }
+ if (current === '"' || current === "'" || current === "`") {
+ const quote = current;
+ chars[index] = " ";
+ index += 1;
+ while (index < chars.length) {
+ if (chars[index] === "\\") {
+ chars[index] = " ";
+ if (chars[index + 1] !== "\n") chars[index + 1] = " ";
+ index += 2;
+ continue;
+ }
+ if (chars[index] === quote) {
+ chars[index] = " ";
+ index += 1;
+ break;
+ }
+ if (chars[index] !== "\n") chars[index] = " ";
+ index += 1;
+ }
+ continue;
+ }
+ index += 1;
+ }
+ return chars.join("");
+}
+
+function matchingParen(source, openIndex) {
+ let depth = 0;
+ for (let index = openIndex; index < source.length; index += 1) {
+ if (source[index] === "(") depth += 1;
+ else if (source[index] === ")") {
+ depth -= 1;
+ if (depth === 0) return index;
+ }
+ }
+ return -1;
+}
+
+function previousLine(source, index) {
+ const lineStart = source.lastIndexOf("\n", index - 1) + 1;
+ const previousEnd = lineStart > 0 ? lineStart - 1 : 0;
+ const previousStart = source.lastIndexOf("\n", previousEnd - 1) + 1;
+ return source.slice(previousStart, previousEnd).replace(/\r$/, "");
+}
+
+/**
+ * Finds test/suite calls that skip on win32 while exercising a real symlink.
+ * A genuinely POSIX-only contract may use an immediately preceding
+ * `symlink-platform-skip:` comment with a concrete rationale.
+ */
+export function findSymlinkPlatformSkips(source) {
+ const masked = maskNonCode(source);
+ const violations = [];
+ for (const match of masked.matchAll(PLATFORM_SKIP_PATTERN)) {
+ const conditionOpen = masked.indexOf("(", match.index);
+ const conditionClose = matchingParen(masked, conditionOpen);
+ if (conditionClose < 0) continue;
+ const condition = source.slice(conditionOpen + 1, conditionClose);
+ if (!/process\s*\.\s*platform/.test(condition) || !/["']win32["']/.test(condition)) {
+ continue;
+ }
+
+ let testOpen = conditionClose + 1;
+ while (/\s/.test(masked[testOpen] ?? "")) testOpen += 1;
+ if (masked[testOpen] !== "(") continue;
+ const testClose = matchingParen(masked, testOpen);
+ if (testClose < 0) continue;
+ if (!SYMLINK_CALL_PATTERN.test(masked.slice(testOpen + 1, testClose))) continue;
+ if (EXCEPTION_PATTERN.test(previousLine(source, match.index))) continue;
+
+ violations.push({
+ line: source.slice(0, match.index).split("\n").length,
+ });
+ }
+ for (const match of masked.matchAll(TEST_CALL_PATTERN)) {
+ const testOpen = masked.indexOf("(", match.index);
+ const testClose = matchingParen(masked, testOpen);
+ if (testClose < 0) continue;
+ const testBody = masked.slice(testOpen + 1, testClose);
+ if (!SYMLINK_CALL_PATTERN.test(testBody)) continue;
+ const earlyReturn = PLATFORM_EARLY_RETURN_PATTERN.exec(testBody);
+ PLATFORM_EARLY_RETURN_PATTERN.lastIndex = 0;
+ if (!earlyReturn) continue;
+ const earlyReturnStart = testOpen + 1 + earlyReturn.index;
+ const earlyReturnSource = source.slice(
+ earlyReturnStart,
+ earlyReturnStart + earlyReturn[0].length,
+ );
+ if (!/["']win32["']/.test(earlyReturnSource)) continue;
+ if (EXCEPTION_PATTERN.test(previousLine(source, match.index))) continue;
+
+ violations.push({
+ line: source.slice(0, earlyReturnStart).split("\n").length,
+ });
+ }
+ return violations;
+}