From 6ac90639cecbcfb5b5fc6667a4448454ae789f58 Mon Sep 17 00:00:00 2001 From: Arul Sharma Date: Mon, 23 Nov 2026 10:59:50 -0500 Subject: [PATCH 1/2] test: skip symlink fixtures on hosts that cannot create symlinks Windows without Developer Mode or an elevated token throws EPERM from fs.symlinkSync (SeCreateSymbolicLinkPrivilege), so fixtures that plant a symlink failed before their first assertion on a normal Windows dev machine. That makes the tests depend on the machine, which ADE's test rules forbid. Add a per-app probe (apps/desktop/src/test/symlinks.ts and apps/ade-cli/src/test/symlinks.ts). On Windows it attempts a real file symlink in a temp dir; elsewhere it is true without probing. The eight proven symlink fixtures use it.skipIf, so they still run on macOS, Linux and an elevated Windows CI runner, and skip only where the OS refuses the link. No production code, assertions or copy changed. Proof (Windows 11, non-elevated, Developer Mode off; raw fs.symlinkSync EPERM errno -4048, junction OK): - Pre-fix durableFile.test.ts: 1 failed | 21 passed | 6 skipped, EPERM at durableFile.test.ts:381 (fs.symlinkSync). - Pre-fix four-file desktop batch: 4 files failed, 6 tests failed | 43 passed, all six EPERM at their symlink fixture lines. - Pre-fix ade-cli batch: 3 files failed, 9 tests failed | 22 passed: 8 symlink EPERM (proofPublish 1, skill 1, cloudLaneBackup 6) plus 1 known CRLF restore mismatch unrelated to this patch. - Post-fix durableFile.test.ts: 0 failed | 21 passed | 7 skipped. - Post-fix desktop batch: 0 failed | 43 passed | 6 skipped. - Post-fix ade-cli batch: 0 symlink EPERM failures; 22 passed | 8 skipped, with only the pre-existing CRLF restore mismatch still red. - npm --prefix apps/desktop run typecheck and npm --prefix apps/ade-cli run typecheck both pass. Co-Authored-By: Claude Code --- apps/ade-cli/src/commands/skill.test.ts | 3 +- apps/ade-cli/src/proofPublish.test.ts | 3 +- .../cloudChats/cloudLaneBackup.test.ts | 11 +++---- apps/ade-cli/src/test/symlinks.ts | 29 +++++++++++++++++++ .../services/ai/providerContextReveal.test.ts | 7 +++-- .../builtInBrowserCapabilities.test.ts | 3 +- .../scenes/sceneSnapshotIngest.test.ts | 3 +- .../shared/agentObservationCache.test.ts | 3 +- .../main/services/state/durableFile.test.ts | 3 +- apps/desktop/src/test/symlinks.ts | 29 +++++++++++++++++++ 10 files changed, 80 insertions(+), 14 deletions(-) create mode 100644 apps/ade-cli/src/test/symlinks.ts create mode 100644 apps/desktop/src/test/symlinks.ts diff --git a/apps/ade-cli/src/commands/skill.test.ts b/apps/ade-cli/src/commands/skill.test.ts index 3087595ff9..05da0fe3b5 100644 --- a/apps/ade-cli/src/commands/skill.test.ts +++ b/apps/ade-cli/src/commands/skill.test.ts @@ -12,6 +12,7 @@ import { readAgentSkillFile, } from "../services/skills/agentSkillCatalogService"; import { CliSkillUsageError, runSkillCommand, runSkillList, runSkillShow } from "./skill"; +import { symlinksSupported } from "../test/symlinks"; describe("ade skill (bundled agent skills)", () => { it("list --json returns entries for known bundled skills", () => { @@ -68,7 +69,7 @@ describe("ade skill (bundled agent skills)", () => { // `skill show ` is read-only over ADE MCP, so a skill folder a // repo controls must not become a way to read, or probe for, other files. - it("reads a skill's own Markdown files and nothing outside its folder", () => { + it.skipIf(!symlinksSupported)("reads a skill's own Markdown files and nothing outside its folder", () => { const root = fs.mkdtempSync(path.join(os.tmpdir(), "ade-skill-file-")); const project = path.join(root, "project"); const skillDir = path.join(project, ".claude", "skills", "guide"); diff --git a/apps/ade-cli/src/proofPublish.test.ts b/apps/ade-cli/src/proofPublish.test.ts index e55bc869d1..6483cac529 100644 --- a/apps/ade-cli/src/proofPublish.test.ts +++ b/apps/ade-cli/src/proofPublish.test.ts @@ -10,6 +10,7 @@ import { publishProofToPullRequest, } from "./proofPublish"; import { resolveStoredProofFile, type PublishableArtifact } from "../../desktop/src/main/services/prs/prBodyProofStaging"; +import { symlinksSupported } from "./test/symlinks"; type Run = typeof spawnSync; type RunResult = { status: number; stdout?: string; stderr?: string }; @@ -69,7 +70,7 @@ describe("resolveStoredProofFile", () => { .toBe(fs.realpathSync(path.join(root, ".ade", "artifacts", "pic.png"))); }); - it("refuses a symlink inside the store that points outside it", () => { + it.skipIf(!symlinksSupported)("refuses a symlink inside the store that points outside it", () => { const root = project(); const outside = path.join(root, "secret.png"); fs.writeFileSync(outside, "secret"); diff --git a/apps/ade-cli/src/services/cloudChats/cloudLaneBackup.test.ts b/apps/ade-cli/src/services/cloudChats/cloudLaneBackup.test.ts index 25f754f369..7768021d3b 100644 --- a/apps/ade-cli/src/services/cloudChats/cloudLaneBackup.test.ts +++ b/apps/ade-cli/src/services/cloudChats/cloudLaneBackup.test.ts @@ -6,6 +6,7 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest"; import type { CloudBackupReport, CloudLaneBackup, CloudLaneBackupFacts } from "../../../../account-directory/src/cloud/contract"; import type { CloudApiClient } from "../../../../desktop/src/shared/cloudApiClient"; import { prepareLaneBranchFromBackup, restoreLaneBackupIfNeeded, runLaneBackups } from "./cloudLaneBackup"; +import { symlinksSupported } from "../../test/symlinks"; /** * A lane's unpushed work lives only in its backup once its computer is @@ -153,7 +154,7 @@ afterEach(() => { }); describe("lane backups", () => { - it("a new computer gets the lane's work back exactly: commits, staged, unstaged, deleted, untracked, binary and symlink; ignored files stay out; nothing reaches GitHub", async () => { + it.skipIf(!symlinksSupported)("a new computer gets the lane's work back exactly: commits, staged, unstaged, deleted, untracked, binary and symlink; ignored files stay out; nothing reaches GitHub", async () => { const { origin, source } = seedOrigin(); makeUnpushedWork(source); const originBefore = git(origin, "for-each-ref"); @@ -193,7 +194,7 @@ describe("lane backups", () => { expect(server.rows.size).toBe(0); }); - it.each<[string, (target: string) => void]>([ + it.skipIf(!symlinksSupported).each<[string, (target: string) => void]>([ ["uncommitted work of its own", (target) => write(target, "mine.txt", "newer\n")], ["a commit past the backup's base that the backup lacks", (target) => { write(target, "other.txt", "other\n"); @@ -218,7 +219,7 @@ describe("lane backups", () => { expect(server.rows.get(`key-old/${LANE}`)!.restoredByMachineKey).toBeNull(); }); - it("a lane at the backup's commit: one that holds the work is left alone and marked restored; one with other uncommitted work keeps it", async () => { + it.skipIf(!symlinksSupported)("a lane at the backup's commit: one that holds the work is left alone and marked restored; one with other uncommitted work keeps it", async () => { const { source } = seedOrigin(); makeUnpushedWork(source); const server = fakeServer(); @@ -234,7 +235,7 @@ describe("lane backups", () => { expect(treeOf(source)).toEqual(before); }); - it("a branch never pushed is made on the new computer from the backup, without a push, and its work is put back", async () => { + it.skipIf(!symlinksSupported)("a branch never pushed is made on the new computer from the backup, without a push, and its work is put back", async () => { const { origin, source } = seedOrigin(); git(source, "checkout", "-q", "-b", "ade/never-pushed", "main"); makeUnpushedWork(source); @@ -341,7 +342,7 @@ describe("lane backups", () => { expect([server.rows.size, server.deleted]).toEqual([1, []]); }); - it("a lane whose folder is missing counts as saved only by its backup", async () => { + it.skipIf(!symlinksSupported)("a lane whose folder is missing counts as saved only by its backup", async () => { const { source } = seedOrigin(); makeUnpushedWork(source); const missing = () => runLaneBackups({ api: fakeServer().api, instanceId: "box", machineKey: "key-old", logger, lanes: async () => ({ complete: true, lanes: [], missing: [LANE] }), mayGoOn: () => true }); diff --git a/apps/ade-cli/src/test/symlinks.ts b/apps/ade-cli/src/test/symlinks.ts new file mode 100644 index 0000000000..433f50abc2 --- /dev/null +++ b/apps/ade-cli/src/test/symlinks.ts @@ -0,0 +1,29 @@ +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +/** + * Whether this host can create a file symlink. Windows needs Developer Mode or + * an elevated token (SeCreateSymbolicLinkPrivilege); without it `fs.symlinkSync` + * throws EPERM. Tests that plant a symlink guard on this instead of failing + * before their first assertion. The probe is honest rather than a platform + * check so an elevated Windows CI runner still runs those tests. + */ +export const symlinksSupported = process.platform !== "win32" ? true : probeSymlinks(); + +function probeSymlinks(): boolean { + const root = fs.mkdtempSync(path.join(os.tmpdir(), "ade-symlink-probe-")); + try { + fs.writeFileSync(path.join(root, "target"), ""); + fs.symlinkSync(path.join(root, "target"), path.join(root, "link")); + return true; + } catch { + return false; + } finally { + try { + fs.rmSync(root, { recursive: true, force: true }); + } catch { + // Best effort: the setup file's temp tracker also cleans this up. + } + } +} diff --git a/apps/desktop/src/main/services/ai/providerContextReveal.test.ts b/apps/desktop/src/main/services/ai/providerContextReveal.test.ts index b1dfae8e1e..52435c9be8 100644 --- a/apps/desktop/src/main/services/ai/providerContextReveal.test.ts +++ b/apps/desktop/src/main/services/ai/providerContextReveal.test.ts @@ -12,6 +12,7 @@ import os from "node:os"; import path from "node:path"; import { afterEach, beforeEach, describe, expect, it } from "vitest"; import { resolveWithinAllowedDirs } from "../ipc/allowedRendererPath"; +import { symlinksSupported } from "../../../test/symlinks"; import { providerContextRevealRoots, resolveProviderContextRevealTarget } from "./providerContextReveal"; let tempRoot: string; @@ -70,7 +71,7 @@ describe("providerContextRevealRoots", () => { expect(() => resolveWithinAllowedDirs(roots(), file)).toThrow(/outside allowed directories/); }); - it("refuses a link inside an allowed folder whose target is outside every root", () => { + it.skipIf(!symlinksSupported)("refuses a link inside an allowed folder whose target is outside every root", () => { const secret = write(path.join(home, ".ssh", "id_ed25519")); const link = path.join(home, ".claude", "skills", "leak"); fs.mkdirSync(path.dirname(link), { recursive: true }); @@ -81,7 +82,7 @@ describe("providerContextRevealRoots", () => { }); describe("resolveProviderContextRevealTarget", () => { - it("shows a skill link where the provider sees it, even when its target is outside every root", () => { + it.skipIf(!symlinksSupported)("shows a skill link where the provider sees it, even when its target is outside every root", () => { const dotfiles = write(path.join(tempRoot, "dotfiles", "lint", "SKILL.md")); const link = path.join(home, ".claude", "skills", "lint"); fs.mkdirSync(path.dirname(link), { recursive: true }); @@ -90,7 +91,7 @@ describe("resolveProviderContextRevealTarget", () => { expect(resolveProviderContextRevealTarget(roots(), link)).toBe(link); }); - it("refuses a path that passes through a symlinked folder", () => { + it.skipIf(!symlinksSupported)("refuses a path that passes through a symlinked folder", () => { write(path.join(home, ".ssh", "id_ed25519")); const linkedDir = path.join(project, "keys"); fs.symlinkSync(path.join(home, ".ssh"), linkedDir); diff --git a/apps/desktop/src/main/services/builtInBrowser/builtInBrowserCapabilities.test.ts b/apps/desktop/src/main/services/builtInBrowser/builtInBrowserCapabilities.test.ts index 74949e0af0..8a9a85cf88 100644 --- a/apps/desktop/src/main/services/builtInBrowser/builtInBrowserCapabilities.test.ts +++ b/apps/desktop/src/main/services/builtInBrowser/builtInBrowserCapabilities.test.ts @@ -2,6 +2,7 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { afterAll, beforeAll, describe, expect, it } from "vitest"; +import { symlinksSupported } from "../../../test/symlinks"; import type { BuiltInBrowserNetworkLogEntry } from "../../../shared/types"; import { resolveBuiltInBrowserEmulation, @@ -296,7 +297,7 @@ describe("built-in browser upload roots", () => { // Regression: a symlink an agent can write inside the project root used to // pass the lexical containment check and upload its target to the page. - it("rejects a symlink inside an allowed root that points outside it", () => { + it.skipIf(!symlinksSupported)("rejects a symlink inside an allowed root that points outside it", () => { const link = path.join(projectRoot, ".ade", "tmp", "report.txt"); fs.symlinkSync(path.join(sandbox, "secrets", "id_ed25519"), link); try { diff --git a/apps/desktop/src/main/services/scenes/sceneSnapshotIngest.test.ts b/apps/desktop/src/main/services/scenes/sceneSnapshotIngest.test.ts index df069e952f..3db65183e5 100644 --- a/apps/desktop/src/main/services/scenes/sceneSnapshotIngest.test.ts +++ b/apps/desktop/src/main/services/scenes/sceneSnapshotIngest.test.ts @@ -5,6 +5,7 @@ import path from "node:path"; import { afterEach, describe, expect, it, vi } from "vitest"; import { resolveAdeLayout } from "../../../shared/adeLayout"; +import { symlinksSupported } from "../../../test/symlinks"; import { resolveSceneStillOwner, SceneStillScopeKeyError } from "./sceneStills"; import { ingestSceneSnapshot } from "./sceneSnapshotIngest"; @@ -104,7 +105,7 @@ describe("ingesting a scene snapshot", () => { * store passes string-only containment, and the ingest below it follows the * link — so the jail and the read disagreed about which file they meant. */ - it("refuses a symlink inside the store that points out of it", async () => { + it.skipIf(!symlinksSupported)("refuses a symlink inside the store that points out of it", async () => { const { projectRoot, artifactsRoot, filed, broker } = createFixture(); const elsewhere = fs.mkdtempSync(path.join(os.tmpdir(), "ade-scene-link-")); const secret = writePng(elsewhere, "secret.png"); diff --git a/apps/desktop/src/main/services/shared/agentObservationCache.test.ts b/apps/desktop/src/main/services/shared/agentObservationCache.test.ts index d75e7ce311..d56b49fe30 100644 --- a/apps/desktop/src/main/services/shared/agentObservationCache.test.ts +++ b/apps/desktop/src/main/services/shared/agentObservationCache.test.ts @@ -2,6 +2,7 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; +import { symlinksSupported } from "../../../test/symlinks"; import { pruneAgentObservationCacheRoot, pruneAgentObservationDirectory, @@ -71,7 +72,7 @@ describe("pruneAgentObservationCacheRoot", () => { // Regression: `fs.stat` resolved a symlink, so a link planted in the cache // root made a read-shaped sweep delete .json/.png files in the link's target. - it("skips a symlinked directory instead of deleting through it", async () => { + it.skipIf(!symlinksSupported)("skips a symlinked directory instead of deleting through it", async () => { const root = scratchDir(); const outside = scratchDir(); writeObservation(outside, "precious", 60 * 60_000); diff --git a/apps/desktop/src/main/services/state/durableFile.test.ts b/apps/desktop/src/main/services/state/durableFile.test.ts index bacf35f684..f43220008b 100644 --- a/apps/desktop/src/main/services/state/durableFile.test.ts +++ b/apps/desktop/src/main/services/state/durableFile.test.ts @@ -4,6 +4,7 @@ import path from "node:path"; import { isMainThread } from "node:worker_threads"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { injectFsFault } from "../../../test/faultInjection"; +import { symlinksSupported } from "../../../test/symlinks"; import { cleanupAbandonedTempFiles, createFileVersionTracker, @@ -368,7 +369,7 @@ describe("durableFile", () => { }); describe("cleanupAbandonedTempFiles", () => { - it("removes only matching old regular files and never follows symlinks", () => { + it.skipIf(!symlinksSupported)("removes only matching old regular files and never follows symlinks", () => { const oldTemp = path.join(root, ".state.json.tmp-123-old"); const youngTemp = path.join(root, ".state.json.tmp-123-young"); const nonMatching = path.join(root, "state.json.tmp-123-old"); diff --git a/apps/desktop/src/test/symlinks.ts b/apps/desktop/src/test/symlinks.ts new file mode 100644 index 0000000000..433f50abc2 --- /dev/null +++ b/apps/desktop/src/test/symlinks.ts @@ -0,0 +1,29 @@ +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +/** + * Whether this host can create a file symlink. Windows needs Developer Mode or + * an elevated token (SeCreateSymbolicLinkPrivilege); without it `fs.symlinkSync` + * throws EPERM. Tests that plant a symlink guard on this instead of failing + * before their first assertion. The probe is honest rather than a platform + * check so an elevated Windows CI runner still runs those tests. + */ +export const symlinksSupported = process.platform !== "win32" ? true : probeSymlinks(); + +function probeSymlinks(): boolean { + const root = fs.mkdtempSync(path.join(os.tmpdir(), "ade-symlink-probe-")); + try { + fs.writeFileSync(path.join(root, "target"), ""); + fs.symlinkSync(path.join(root, "target"), path.join(root, "link")); + return true; + } catch { + return false; + } finally { + try { + fs.rmSync(root, { recursive: true, force: true }); + } catch { + // Best effort: the setup file's temp tracker also cleans this up. + } + } +} From 3c10b0408652625293b2160253c6acf66a95ad5e Mon Sep 17 00:00:00 2001 From: Arul Sharma Date: Mon, 23 Nov 2026 11:55:24 -0500 Subject: [PATCH 2/2] test: keep non-symlink coverage on hosts that refuse symlinks The Windows symlink guard sat on whole tests, so their traversal, age and path-jail assertions disappeared wherever a link could not be made. Fix the review findings on PR #2475: - skill.test.ts: read references/detail.md and the traversal, absolute path, SKILL and missing-file refusals unguarded; only the references/leak.md link and its fs.symlinkSync are guarded now. - providerContextReveal.test.ts and agentObservationCache.test.ts: these fixtures plant directory links, which work on Windows as junctions, so build them the repo's way (junction on win32, dir elsewhere) and drop the guard. The probe now covers only genuine file symlinks. - durableFile.test.ts: keep old-matching-removed, young-kept and non-matching-kept unguarded; only the symlink assertions are guarded. Co-Authored-By: Claude Code --- apps/ade-cli/src/commands/skill.test.ts | 54 ++++++++++++------- .../services/ai/providerContextReveal.test.ts | 9 ++-- .../shared/agentObservationCache.test.ts | 6 +-- .../main/services/state/durableFile.test.ts | 16 ++++-- 4 files changed, 53 insertions(+), 32 deletions(-) diff --git a/apps/ade-cli/src/commands/skill.test.ts b/apps/ade-cli/src/commands/skill.test.ts index 05da0fe3b5..2d82de08bf 100644 --- a/apps/ade-cli/src/commands/skill.test.ts +++ b/apps/ade-cli/src/commands/skill.test.ts @@ -69,32 +69,35 @@ describe("ade skill (bundled agent skills)", () => { // `skill show ` is read-only over ADE MCP, so a skill folder a // repo controls must not become a way to read, or probe for, other files. - it.skipIf(!symlinksSupported)("reads a skill's own Markdown files and nothing outside its folder", () => { + const skillFileFixture = () => { const root = fs.mkdtempSync(path.join(os.tmpdir(), "ade-skill-file-")); const project = path.join(root, "project"); const skillDir = path.join(project, ".claude", "skills", "guide"); - try { - fs.mkdirSync(path.join(skillDir, "references"), { recursive: true }); - fs.writeFileSync(path.join(skillDir, "SKILL.md"), "---\nname: guide\ndescription: guide skill\n---\nBody.\n"); - fs.writeFileSync(path.join(skillDir, "references", "detail.md"), "# Detail\n"); - fs.writeFileSync(path.join(root, "outside.md"), "secret\n"); - fs.symlinkSync(path.join(root, "outside.md"), path.join(skillDir, "references", "leak.md")); - const skill = readAgentSkill("guide", { cwd: project, includeUser: false, env: process.env }); - expect(skill, "setup precondition: the project skill is found").not.toBeNull(); + fs.mkdirSync(path.join(skillDir, "references"), { recursive: true }); + fs.writeFileSync(path.join(skillDir, "SKILL.md"), "---\nname: guide\ndescription: guide skill\n---\nBody.\n"); + fs.writeFileSync(path.join(skillDir, "references", "detail.md"), "# Detail\n"); + fs.writeFileSync(path.join(root, "outside.md"), "secret\n"); + const skill = readAgentSkill("guide", { cwd: project, includeUser: false, env: process.env }); + expect(skill, "setup precondition: the project skill is found").not.toBeNull(); + const refusal = (file: string): string => { + try { + readAgentSkillFile(skill!.entry, file); + } catch (error) { + expect(error).toBeInstanceOf(AgentSkillFileError); + return (error as Error).message; + } + throw new Error(`${file} was read`); + }; + return { root, skillDir, entry: skill!.entry, refusal }; + }; - expect(readAgentSkillFile(skill!.entry, "references/detail.md").content).toBe("# Detail\n"); - const refusal = (file: string): string => { - try { - readAgentSkillFile(skill!.entry, file); - } catch (error) { - expect(error).toBeInstanceOf(AgentSkillFileError); - return (error as Error).message; - } - throw new Error(`${file} was read`); - }; + it("reads a skill's own Markdown files and refuses paths outside its folder", () => { + const { root, entry, refusal } = skillFileFixture(); + try { + expect(readAgentSkillFile(entry, "references/detail.md").content).toBe("# Detail\n"); // An escaping path reads the same whether or not the file exists. const outside = "is not a Markdown file inside the guide skill"; - for (const file of ["../../../../outside.md", "../../../../missing.md", "references/leak.md", path.join(root, "outside.md"), "SKILL"]) { + for (const file of ["../../../../outside.md", "../../../../missing.md", path.join(root, "outside.md"), "SKILL"]) { expect(refusal(file), file).toContain(outside); } expect(refusal("references/missing.md")).toContain("has no file"); @@ -103,6 +106,17 @@ describe("ade skill (bundled agent skills)", () => { } }); + // Windows refuses a file symlink without Developer Mode or an elevated token. + it.skipIf(!symlinksSupported)("refuses a link in a skill folder that points outside it", () => { + const { root, skillDir, refusal } = skillFileFixture(); + try { + fs.symlinkSync(path.join(root, "outside.md"), path.join(skillDir, "references", "leak.md")); + expect(refusal("references/leak.md")).toContain("is not a Markdown file inside the guide skill"); + } finally { + fs.rmSync(root, { recursive: true, force: true }); + } + }); + it("show --json returns full content including frontmatter name", () => { const result = runSkillShow(["ade-browser", "--json"]); expect(result.exitCode).toBe(0); diff --git a/apps/desktop/src/main/services/ai/providerContextReveal.test.ts b/apps/desktop/src/main/services/ai/providerContextReveal.test.ts index 52435c9be8..e6f0d11d66 100644 --- a/apps/desktop/src/main/services/ai/providerContextReveal.test.ts +++ b/apps/desktop/src/main/services/ai/providerContextReveal.test.ts @@ -82,19 +82,20 @@ describe("providerContextRevealRoots", () => { }); describe("resolveProviderContextRevealTarget", () => { - it.skipIf(!symlinksSupported)("shows a skill link where the provider sees it, even when its target is outside every root", () => { + it("shows a skill link where the provider sees it, even when its target is outside every root", () => { const dotfiles = write(path.join(tempRoot, "dotfiles", "lint", "SKILL.md")); const link = path.join(home, ".claude", "skills", "lint"); fs.mkdirSync(path.dirname(link), { recursive: true }); - fs.symlinkSync(path.dirname(dotfiles), link); + // A directory link works on Windows without Developer Mode as a junction. + fs.symlinkSync(path.resolve(path.dirname(dotfiles)), link, process.platform === "win32" ? "junction" : "dir"); expect(() => resolveWithinAllowedDirs(roots(), link)).toThrow(/outside allowed directories/); expect(resolveProviderContextRevealTarget(roots(), link)).toBe(link); }); - it.skipIf(!symlinksSupported)("refuses a path that passes through a symlinked folder", () => { + it("refuses a path that passes through a symlinked folder", () => { write(path.join(home, ".ssh", "id_ed25519")); const linkedDir = path.join(project, "keys"); - fs.symlinkSync(path.join(home, ".ssh"), linkedDir); + fs.symlinkSync(path.resolve(home, ".ssh"), linkedDir, process.platform === "win32" ? "junction" : "dir"); const through = path.join(linkedDir, "id_ed25519"); expect(fs.realpathSync(through)).toBe(path.join(home, ".ssh", "id_ed25519")); expect(() => resolveProviderContextRevealTarget(roots(), through)).toThrow(/outside allowed directories/); diff --git a/apps/desktop/src/main/services/shared/agentObservationCache.test.ts b/apps/desktop/src/main/services/shared/agentObservationCache.test.ts index d56b49fe30..34592fb1f0 100644 --- a/apps/desktop/src/main/services/shared/agentObservationCache.test.ts +++ b/apps/desktop/src/main/services/shared/agentObservationCache.test.ts @@ -2,7 +2,6 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; -import { symlinksSupported } from "../../../test/symlinks"; import { pruneAgentObservationCacheRoot, pruneAgentObservationDirectory, @@ -72,11 +71,12 @@ describe("pruneAgentObservationCacheRoot", () => { // Regression: `fs.stat` resolved a symlink, so a link planted in the cache // root made a read-shaped sweep delete .json/.png files in the link's target. - it.skipIf(!symlinksSupported)("skips a symlinked directory instead of deleting through it", async () => { + it("skips a symlinked directory instead of deleting through it", async () => { const root = scratchDir(); const outside = scratchDir(); writeObservation(outside, "precious", 60 * 60_000); - fs.symlinkSync(outside, path.join(root, "session-link")); + // A directory link works on Windows without Developer Mode as a junction. + fs.symlinkSync(path.resolve(outside), path.join(root, "session-link"), process.platform === "win32" ? "junction" : "dir"); await pruneAgentObservationCacheRoot(root, 30 * 60_000); diff --git a/apps/desktop/src/main/services/state/durableFile.test.ts b/apps/desktop/src/main/services/state/durableFile.test.ts index f43220008b..2a5524d8ca 100644 --- a/apps/desktop/src/main/services/state/durableFile.test.ts +++ b/apps/desktop/src/main/services/state/durableFile.test.ts @@ -369,17 +369,13 @@ describe("durableFile", () => { }); describe("cleanupAbandonedTempFiles", () => { - it.skipIf(!symlinksSupported)("removes only matching old regular files and never follows symlinks", () => { + it("removes only matching old regular files", () => { const oldTemp = path.join(root, ".state.json.tmp-123-old"); const youngTemp = path.join(root, ".state.json.tmp-123-young"); const nonMatching = path.join(root, "state.json.tmp-123-old"); - const outside = path.join(root, "outside.txt"); - const symlink = path.join(root, ".state.json.tmp-123-link"); fs.writeFileSync(oldTemp, "old"); fs.writeFileSync(youngTemp, "young"); fs.writeFileSync(nonMatching, "keep"); - fs.writeFileSync(outside, "outside"); - fs.symlinkSync(outside, symlink); const old = new Date(Date.now() - 10_000); fs.utimesSync(oldTemp, old, old); @@ -387,6 +383,16 @@ describe("durableFile", () => { expect(fs.existsSync(oldTemp)).toBe(false); expect(fs.existsSync(youngTemp)).toBe(true); expect(fs.existsSync(nonMatching)).toBe(true); + }); + + // Windows refuses a file symlink without Developer Mode or an elevated token. + it.skipIf(!symlinksSupported)("never follows a symlink", () => { + const outside = path.join(root, "outside.txt"); + const symlink = path.join(root, ".state.json.tmp-123-link"); + fs.writeFileSync(outside, "outside"); + fs.symlinkSync(outside, symlink); + + expect(cleanupAbandonedTempFiles(root, { maxAgeMs: 1_000 })).toBe(0); expect(fs.lstatSync(symlink).isSymbolicLink()).toBe(true); expect(fs.readFileSync(outside, "utf8")).toBe("outside"); });