diff --git a/apps/ade-cli/src/commands/skill.test.ts b/apps/ade-cli/src/commands/skill.test.ts index 3087595ff9..2d82de08bf 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,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("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"); @@ -102,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/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..e6f0d11d66 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 }); @@ -85,7 +86,8 @@ describe("resolveProviderContextRevealTarget", () => { 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); }); @@ -93,7 +95,7 @@ describe("resolveProviderContextRevealTarget", () => { 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/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..34592fb1f0 100644 --- a/apps/desktop/src/main/services/shared/agentObservationCache.test.ts +++ b/apps/desktop/src/main/services/shared/agentObservationCache.test.ts @@ -75,7 +75,8 @@ describe("pruneAgentObservationCacheRoot", () => { 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 bacf35f684..2a5524d8ca 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,17 +369,13 @@ describe("durableFile", () => { }); describe("cleanupAbandonedTempFiles", () => { - it("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); @@ -386,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"); }); 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. + } + } +}