Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

test(server): skip symlink-dependent cases where the process cannot create symlinks (#822)

Elijah9a85258d317f
diff --git a/packages/server/test/benchmarks.test.ts b/packages/server/test/benchmarks.test.ts
index 5bc9d470..84fc47a8 100644
--- a/packages/server/test/benchmarks.test.ts
+++ b/packages/server/test/benchmarks.test.ts
@@ -24,9 +24,13 @@ import type {
ProjectCreateResponse,
WorkspaceFilesResponse,
} from "../src/api/types.js";
-import { apiClient, createTestApp, provisionUser } from "./helpers.js";
+import { apiClient, canCreateSymlink, createTestApp, provisionUser } from "./helpers.js";
import type { TestApp } from "./helpers.js";
+// Symlink creation needs a privilege or Developer Mode on Windows; canCreateSymlink()
+// probes once and caches, so these cases still run where the capability exists.
+const itWithSymlinks = it.skipIf(!canCreateSymlink());
+
describe("benchmarks api", () => {
let t: TestApp;
let owner: ReturnType<typeof apiClient>;
@@ -69,290 +73,293 @@ describe("benchmarks api", () => {
});
});
- it("current scoreboard: model-written averages, runtime, and runs pass through", async () => {
- const dir = path.join(benchmarksDir(t.root, projectId), "swe-bench-v2");
- await fs.mkdir(path.join(dir, "CASE-001-excel-task", "statement"), { recursive: true });
- await fs.mkdir(path.join(dir, "CASE-001-excel-task", "statement", "assets"), {
- recursive: true,
- });
- await fs.mkdir(path.join(dir, "CASE-001-excel-task", "rubric"), { recursive: true });
- await fs.mkdir(path.join(dir, "CASE-002-web-task", "statement"), { recursive: true });
- await fs.mkdir(path.join(dir, "CASE-002-web-task", "rubric"), { recursive: true });
- await fs.writeFile(
- path.join(dir, "CASE-001-excel-task", "statement", "README.md"),
- "# Case 001: Excel cleanup\n\nClean the workbook.",
- "utf8",
- );
- await fs.writeFile(
- path.join(dir, "CASE-001-excel-task", "statement", "data.csv"),
- "id,value\n1,alpha\n",
- "utf8",
- );
- await fs.writeFile(
- path.join(dir, "CASE-001-excel-task", "statement", "assets", "notes.txt"),
- "public notes",
- "utf8",
- );
- await fs.writeFile(
- path.join(dir, "CASE-001-excel-task", "statement", "large.txt"),
- "x".repeat(300 * 1024),
- "utf8",
- );
- await fs.writeFile(
- path.join(dir, "CASE-001-excel-task", "rubric", "README.md"),
- "# Scoring rubric\n\n- Correct workbook: 100 points",
- "utf8",
- );
- await fs.writeFile(
- path.join(dir, "CASE-001-excel-task", "rubric", "expected.json"),
- '{"rows": 1}\n',
- "utf8",
- );
- await fs.writeFile(
- path.join(dir, "CASE-002-web-task", "statement", "README.md"),
- "# Web task\n\nBuild the page.",
- "utf8",
- );
- await fs.writeFile(
- path.join(dir, "CASE-002-web-task", "rubric", "README.md"),
- "PRIVATE GOLD: never return this text",
- "utf8",
- );
- await fs.symlink(
- path.join(dir, "CASE-002-web-task", "rubric", "README.md"),
- path.join(dir, "CASE-001-excel-task", "statement", "private-link.md"),
- );
- await fs.writeFile(
- path.join(dir, "benchmark_config.toml"),
- `title = "SWE Bench v2"\ndescription = "Example"\nruns = 2\n`,
- "utf8",
- );
- await fs.writeFile(
- path.join(dir, "scoreboard.yaml"),
- [
- "evaluations:",
- ' - time: "2026-07-16T10:00:00Z"',
- ' agent_id: "default_agent"',
- " version: 3",
- ' provider: "deepseek"',
- ' model_id: "deepseek-v4-pro"',
- ' thinking_level: "medium"',
- ' summary_title: "Added planning steps to the system Prompt"',
- ' summary: "Each case run twice and averaged; added planning steps."',
- " score: 72.35",
- " cost: 0.04",
- " duration_ms: 42500",
- " cases:",
- // Stored averages are authoritative even when inconsistent with the raw Runs.
- ' - case: "CASE-001-excel-task"',
- " score: 80.2",
- " cost: 0.04",
- " duration_ms: 50000",
- " runs:",
- " - score: 80",
- " cost: null",
- " duration_ms: 48000",
- ' session_id: "session-run-1"',
- " - score: 82",
- " cost: 0.04",
- " duration_ms: 52000",
- ' session_id: "session-run-2"',
- // All unknown Run costs produce a model-written null Case cost; the Evaluation ignores it.
- ' - case: "CASE-002-web-task"',
- " score: 64.5",
- " cost: null",
- " duration_ms: 35000",
- " runs:",
- " - score: 60",
- " cost: null",
- " duration_ms: 30000",
- ' session_id: "session-run-3"',
- " - score: 70",
- " cost: null",
- " duration_ms: 40000",
- ' session_id: "session-run-4"',
- // A second Agent evaluated by the same Benchmark: the two are peers, and one
- // Benchmark measures as many Agents as it is pointed at.
- ' - time: "2026-07-17T10:00:00Z"',
- ' agent_id: "report_writer"',
- " version: 1",
- ' provider: "deepseek"',
- ' model_id: "deepseek-v4-pro"',
- ' thinking_level: "medium"',
- " score: 55",
- " cost: null",
- " duration_ms: 30000",
- " cases:",
- ' - case: "CASE-001-excel-task"',
- " score: 55",
- " cost: null",
- " duration_ms: 30000",
- " runs:",
- " - score: 55",
- " cost: null",
- " duration_ms: 30000",
- ' session_id: "session-run-5"',
- // Recorded before evaluations named an Agent: still listed, just unlabelled.
- ' - time: "2026-07-18T10:00:00Z"',
- " version: 1",
- ' provider: "deepseek"',
- ' model_id: "deepseek-v4-pro"',
- ' thinking_level: "medium"',
- " score: 60",
- " cost: null",
- " duration_ms: 31000",
- " cases:",
- ' - case: "CASE-001-excel-task"',
- " score: 60",
- " cost: null",
- " duration_ms: 31000",
- " runs:",
- " - score: 60",
- " cost: null",
- " duration_ms: 31000",
- ' session_id: "session-run-6"',
- ].join("\n"),
- "utf8",
- );
+ itWithSymlinks(
+ "current scoreboard: model-written averages, runtime, and runs pass through",
+ async () => {
+ const dir = path.join(benchmarksDir(t.root, projectId), "swe-bench-v2");
+ await fs.mkdir(path.join(dir, "CASE-001-excel-task", "statement"), { recursive: true });
+ await fs.mkdir(path.join(dir, "CASE-001-excel-task", "statement", "assets"), {
+ recursive: true,
+ });
+ await fs.mkdir(path.join(dir, "CASE-001-excel-task", "rubric"), { recursive: true });
+ await fs.mkdir(path.join(dir, "CASE-002-web-task", "statement"), { recursive: true });
+ await fs.mkdir(path.join(dir, "CASE-002-web-task", "rubric"), { recursive: true });
+ await fs.writeFile(
+ path.join(dir, "CASE-001-excel-task", "statement", "README.md"),
+ "# Case 001: Excel cleanup\n\nClean the workbook.",
+ "utf8",
+ );
+ await fs.writeFile(
+ path.join(dir, "CASE-001-excel-task", "statement", "data.csv"),
+ "id,value\n1,alpha\n",
+ "utf8",
+ );
+ await fs.writeFile(
+ path.join(dir, "CASE-001-excel-task", "statement", "assets", "notes.txt"),
+ "public notes",
+ "utf8",
+ );
+ await fs.writeFile(
+ path.join(dir, "CASE-001-excel-task", "statement", "large.txt"),
+ "x".repeat(300 * 1024),
+ "utf8",
+ );
+ await fs.writeFile(
+ path.join(dir, "CASE-001-excel-task", "rubric", "README.md"),
+ "# Scoring rubric\n\n- Correct workbook: 100 points",
+ "utf8",
+ );
+ await fs.writeFile(
+ path.join(dir, "CASE-001-excel-task", "rubric", "expected.json"),
+ '{"rows": 1}\n',
+ "utf8",
+ );
+ await fs.writeFile(
+ path.join(dir, "CASE-002-web-task", "statement", "README.md"),
+ "# Web task\n\nBuild the page.",
+ "utf8",
+ );
+ await fs.writeFile(
+ path.join(dir, "CASE-002-web-task", "rubric", "README.md"),
+ "PRIVATE GOLD: never return this text",
+ "utf8",
+ );
+ await fs.symlink(
+ path.join(dir, "CASE-002-web-task", "rubric", "README.md"),
+ path.join(dir, "CASE-001-excel-task", "statement", "private-link.md"),
+ );
+ await fs.writeFile(
+ path.join(dir, "benchmark_config.toml"),
+ `title = "SWE Bench v2"\ndescription = "Example"\nruns = 2\n`,
+ "utf8",
+ );
+ await fs.writeFile(
+ path.join(dir, "scoreboard.yaml"),
+ [
+ "evaluations:",
+ ' - time: "2026-07-16T10:00:00Z"',
+ ' agent_id: "default_agent"',
+ " version: 3",
+ ' provider: "deepseek"',
+ ' model_id: "deepseek-v4-pro"',
+ ' thinking_level: "medium"',
+ ' summary_title: "Added planning steps to the system Prompt"',
+ ' summary: "Each case run twice and averaged; added planning steps."',
+ " score: 72.35",
+ " cost: 0.04",
+ " duration_ms: 42500",
+ " cases:",
+ // Stored averages are authoritative even when inconsistent with the raw Runs.
+ ' - case: "CASE-001-excel-task"',
+ " score: 80.2",
+ " cost: 0.04",
+ " duration_ms: 50000",
+ " runs:",
+ " - score: 80",
+ " cost: null",
+ " duration_ms: 48000",
+ ' session_id: "session-run-1"',
+ " - score: 82",
+ " cost: 0.04",
+ " duration_ms: 52000",
+ ' session_id: "session-run-2"',
+ // All unknown Run costs produce a model-written null Case cost; the Evaluation ignores it.
+ ' - case: "CASE-002-web-task"',
+ " score: 64.5",
+ " cost: null",
+ " duration_ms: 35000",
+ " runs:",
+ " - score: 60",
+ " cost: null",
+ " duration_ms: 30000",
+ ' session_id: "session-run-3"',
+ " - score: 70",
+ " cost: null",
+ " duration_ms: 40000",
+ ' session_id: "session-run-4"',
+ // A second Agent evaluated by the same Benchmark: the two are peers, and one
+ // Benchmark measures as many Agents as it is pointed at.
+ ' - time: "2026-07-17T10:00:00Z"',
+ ' agent_id: "report_writer"',
+ " version: 1",
+ ' provider: "deepseek"',
+ ' model_id: "deepseek-v4-pro"',
+ ' thinking_level: "medium"',
+ " score: 55",
+ " cost: null",
+ " duration_ms: 30000",
+ " cases:",
+ ' - case: "CASE-001-excel-task"',
+ " score: 55",
+ " cost: null",
+ " duration_ms: 30000",
+ " runs:",
+ " - score: 55",
+ " cost: null",
+ " duration_ms: 30000",
+ ' session_id: "session-run-5"',
+ // Recorded before evaluations named an Agent: still listed, just unlabelled.
+ ' - time: "2026-07-18T10:00:00Z"',
+ " version: 1",
+ ' provider: "deepseek"',
+ ' model_id: "deepseek-v4-pro"',
+ ' thinking_level: "medium"',
+ " score: 60",
+ " cost: null",
+ " duration_ms: 31000",
+ " cases:",
+ ' - case: "CASE-001-excel-task"',
+ " score: 60",
+ " cost: null",
+ " duration_ms: 31000",
+ " runs:",
+ " - score: 60",
+ " cost: null",
+ " duration_ms: 31000",
+ ' session_id: "session-run-6"',
+ ].join("\n"),
+ "utf8",
+ );
- const res = (await (await member.get(base)).json()) as BenchmarksResponse;
- const bench = res.benchmarks[0]!;
- expect(bench).toMatchObject({
- id: "swe-bench-v2",
- title: "SWE Bench v2",
- description: "Example",
- runs: 2,
- status: "published",
- caseCount: 2,
- });
- // config carries no model reference (the model lives on each evaluation).
- expect("modelId" in bench).toBe(false);
- expect("provider" in bench).toBe(false);
- // The Agents a Benchmark has evaluated come from its scoreboard, in first-seen order; an
- // evaluation without an agent_id contributes none.
- expect(bench.agentIds).toEqual(["default_agent", "report_writer"]);
- expect(bench.evaluations[2]!.agentId).toBeNull();
- const evaluation = bench.evaluations[0]!;
- // The evaluation entry carries the Agent it tested, this run's model (as a pair) and a
- // summary title (curve series / title-body are displayed separately).
- expect(evaluation.agentId).toBe("default_agent");
- expect(evaluation.provider).toBe("deepseek");
- expect(evaluation.modelId).toBe("deepseek-v4-pro");
- expect(evaluation.thinkingLevel).toBe("medium");
- expect(evaluation.summaryTitle).toBe("Added planning steps to the system Prompt");
- expect(evaluation.summary).toBe("Each case run twice and averaged; added planning steps.");
- expect(evaluation.score).toBe(72.35);
- expect(evaluation.cost).toBe(0.04);
- expect(evaluation.durationMs).toBe(42500);
- expect("maxScore" in evaluation).toBe(false);
- // Per-case metrics trust the file (80.2, not the Runs' arithmetic mean of 81).
- const full = evaluation.cases.find((c) => c.case === "CASE-001-excel-task")!;
- expect(full.score).toBe(80.2);
- expect(full.cost).toBe(0.04);
- expect(full.durationMs).toBe(50000);
- expect(full.runs).toEqual([
- { score: 80, cost: null, durationMs: 48000, sessionId: "session-run-1" },
- { score: 82, cost: 0.04, durationMs: 52000, sessionId: "session-run-2" },
- ]);
- const partialCost = evaluation.cases.find((c) => c.case === "CASE-002-web-task")!;
- expect(partialCost.score).toBe(64.5);
- expect(partialCost.cost).toBeNull();
- expect(partialCost.durationMs).toBe(35000);
- expect(partialCost.runs).toEqual([
- { score: 60, cost: null, durationMs: 30000, sessionId: "session-run-3" },
- { score: 70, cost: null, durationMs: 40000, sessionId: "session-run-4" },
- ]);
+ const res = (await (await member.get(base)).json()) as BenchmarksResponse;
+ const bench = res.benchmarks[0]!;
+ expect(bench).toMatchObject({
+ id: "swe-bench-v2",
+ title: "SWE Bench v2",
+ description: "Example",
+ runs: 2,
+ status: "published",
+ caseCount: 2,
+ });
+ // config carries no model reference (the model lives on each evaluation).
+ expect("modelId" in bench).toBe(false);
+ expect("provider" in bench).toBe(false);
+ // The Agents a Benchmark has evaluated come from its scoreboard, in first-seen order; an
+ // evaluation without an agent_id contributes none.
+ expect(bench.agentIds).toEqual(["default_agent", "report_writer"]);
+ expect(bench.evaluations[2]!.agentId).toBeNull();
+ const evaluation = bench.evaluations[0]!;
+ // The evaluation entry carries the Agent it tested, this run's model (as a pair) and a
+ // summary title (curve series / title-body are displayed separately).
+ expect(evaluation.agentId).toBe("default_agent");
+ expect(evaluation.provider).toBe("deepseek");
+ expect(evaluation.modelId).toBe("deepseek-v4-pro");
+ expect(evaluation.thinkingLevel).toBe("medium");
+ expect(evaluation.summaryTitle).toBe("Added planning steps to the system Prompt");
+ expect(evaluation.summary).toBe("Each case run twice and averaged; added planning steps.");
+ expect(evaluation.score).toBe(72.35);
+ expect(evaluation.cost).toBe(0.04);
+ expect(evaluation.durationMs).toBe(42500);
+ expect("maxScore" in evaluation).toBe(false);
+ // Per-case metrics trust the file (80.2, not the Runs' arithmetic mean of 81).
+ const full = evaluation.cases.find((c) => c.case === "CASE-001-excel-task")!;
+ expect(full.score).toBe(80.2);
+ expect(full.cost).toBe(0.04);
+ expect(full.durationMs).toBe(50000);
+ expect(full.runs).toEqual([
+ { score: 80, cost: null, durationMs: 48000, sessionId: "session-run-1" },
+ { score: 82, cost: 0.04, durationMs: 52000, sessionId: "session-run-2" },
+ ]);
+ const partialCost = evaluation.cases.find((c) => c.case === "CASE-002-web-task")!;
+ expect(partialCost.score).toBe(64.5);
+ expect(partialCost.cost).toBeNull();
+ expect(partialCost.durationMs).toBe(35000);
+ expect(partialCost.runs).toEqual([
+ { score: 60, cost: null, durationMs: 30000, sessionId: "session-run-3" },
+ { score: 70, cost: null, durationMs: 40000, sessionId: "session-run-4" },
+ ]);
- const caseResponse = (await (
- await member.get(`${base}/swe-bench-v2/cases`)
- ).json()) as BenchmarkCasesResponse;
- expect(caseResponse).toEqual({
- cases: [
- {
- id: "CASE-001-excel-task",
- title: "Excel cleanup",
- },
- {
- id: "CASE-002-web-task",
- title: "Web task",
- },
- ],
- });
- expect(JSON.stringify(caseResponse)).not.toContain("PRIVATE GOLD");
+ const caseResponse = (await (
+ await member.get(`${base}/swe-bench-v2/cases`)
+ ).json()) as BenchmarkCasesResponse;
+ expect(caseResponse).toEqual({
+ cases: [
+ {
+ id: "CASE-001-excel-task",
+ title: "Excel cleanup",
+ },
+ {
+ id: "CASE-002-web-task",
+ title: "Web task",
+ },
+ ],
+ });
+ expect(JSON.stringify(caseResponse)).not.toContain("PRIVATE GOLD");
- const filesBase = `${base}/swe-bench-v2/cases/CASE-001-excel-task/files`;
- const files = (await (await member.get(filesBase)).json()) as WorkspaceFilesResponse;
- expect(files.path).toBe("");
- expect(files.entries.map((entry) => `${entry.kind}:${entry.name}`)).toEqual([
- "dir:assets",
- "file:data.csv",
- "file:large.txt",
- "file:README.md",
- ]);
- expect(JSON.stringify(files)).not.toContain("private-link.md");
- expect(
- (
- await member.get(
- `${filesBase}/content?path=${encodeURIComponent("private-link.md")}&preview=1`,
- )
- ).status,
- ).toBe(400);
+ const filesBase = `${base}/swe-bench-v2/cases/CASE-001-excel-task/files`;
+ const files = (await (await member.get(filesBase)).json()) as WorkspaceFilesResponse;
+ expect(files.path).toBe("");
+ expect(files.entries.map((entry) => `${entry.kind}:${entry.name}`)).toEqual([
+ "dir:assets",
+ "file:data.csv",
+ "file:large.txt",
+ "file:README.md",
+ ]);
+ expect(JSON.stringify(files)).not.toContain("private-link.md");
+ expect(
+ (
+ await member.get(
+ `${filesBase}/content?path=${encodeURIComponent("private-link.md")}&preview=1`,
+ )
+ ).status,
+ ).toBe(400);
- const nested = (await (
- await member.get(`${filesBase}?path=${encodeURIComponent("assets")}`)
- ).json()) as WorkspaceFilesResponse;
- expect(nested.entries.map((entry) => entry.name)).toEqual(["notes.txt"]);
+ const nested = (await (
+ await member.get(`${filesBase}?path=${encodeURIComponent("assets")}`)
+ ).json()) as WorkspaceFilesResponse;
+ expect(nested.entries.map((entry) => entry.name)).toEqual(["notes.txt"]);
- const statement = await member.get(
- `${filesBase}/content?path=${encodeURIComponent("README.md")}&preview=1`,
- );
- expect(statement.status).toBe(200);
- expect(statement.headers.get("content-type")).toContain("markdown");
- expect(await statement.text()).toBe("# Case 001: Excel cleanup\n\nClean the workbook.");
+ const statement = await member.get(
+ `${filesBase}/content?path=${encodeURIComponent("README.md")}&preview=1`,
+ );
+ expect(statement.status).toBe(200);
+ expect(statement.headers.get("content-type")).toContain("markdown");
+ expect(await statement.text()).toBe("# Case 001: Excel cleanup\n\nClean the workbook.");
- const rubricFilesBase = `${base}/swe-bench-v2/cases/CASE-001-excel-task/rubric/files`;
- const rubricFiles = (await (
- await member.get(rubricFilesBase)
- ).json()) as WorkspaceFilesResponse;
- expect(rubricFiles.entries.map((entry) => `${entry.kind}:${entry.name}`)).toEqual([
- "file:expected.json",
- "file:README.md",
- ]);
+ const rubricFilesBase = `${base}/swe-bench-v2/cases/CASE-001-excel-task/rubric/files`;
+ const rubricFiles = (await (
+ await member.get(rubricFilesBase)
+ ).json()) as WorkspaceFilesResponse;
+ expect(rubricFiles.entries.map((entry) => `${entry.kind}:${entry.name}`)).toEqual([
+ "file:expected.json",
+ "file:README.md",
+ ]);
- const rubric = await member.get(
- `${rubricFilesBase}/content?path=${encodeURIComponent("README.md")}&preview=1`,
- );
- expect(rubric.status).toBe(200);
- expect(rubric.headers.get("content-type")).toContain("markdown");
- expect(await rubric.text()).toContain("Correct workbook: 100 points");
+ const rubric = await member.get(
+ `${rubricFilesBase}/content?path=${encodeURIComponent("README.md")}&preview=1`,
+ );
+ expect(rubric.status).toBe(200);
+ expect(rubric.headers.get("content-type")).toContain("markdown");
+ expect(await rubric.text()).toContain("Correct workbook: 100 points");
- const large = await member.get(
- `${filesBase}/content?path=${encodeURIComponent("large.txt")}&preview=1`,
- );
- expect(large.status).toBe(200);
- expect(large.headers.get("x-content-truncated")).toBe("1");
- expect((await large.text()).length).toBe(256 * 1024);
+ const large = await member.get(
+ `${filesBase}/content?path=${encodeURIComponent("large.txt")}&preview=1`,
+ );
+ expect(large.status).toBe(200);
+ expect(large.headers.get("x-content-truncated")).toBe("1");
+ expect((await large.text()).length).toBe(256 * 1024);
- const download = await member.get(
- `${filesBase}/content?path=${encodeURIComponent("data.csv")}&download=1`,
- );
- expect(download.headers.get("content-disposition")).toContain("attachment");
- expect(await download.text()).toBe("id,value\n1,alpha\n");
+ const download = await member.get(
+ `${filesBase}/content?path=${encodeURIComponent("data.csv")}&download=1`,
+ );
+ expect(download.headers.get("content-disposition")).toContain("attachment");
+ expect(await download.text()).toBe("id,value\n1,alpha\n");
- expect(
- (await member.get(`${filesBase}/content?path=${encodeURIComponent("../rubric/README.md")}`))
- .status,
- ).toBe(400);
- expect(
- (
- await member.get(
- `${rubricFilesBase}/content?path=${encodeURIComponent("../statement/README.md")}`,
- )
- ).status,
- ).toBe(400);
- expect((await outsider.get(`${base}/swe-bench-v2/cases`)).status).toBe(404);
- expect((await outsider.get(filesBase)).status).toBe(404);
- });
+ expect(
+ (await member.get(`${filesBase}/content?path=${encodeURIComponent("../rubric/README.md")}`))
+ .status,
+ ).toBe(400);
+ expect(
+ (
+ await member.get(
+ `${rubricFilesBase}/content?path=${encodeURIComponent("../statement/README.md")}`,
+ )
+ ).status,
+ ).toBe(400);
+ expect((await outsider.get(`${base}/swe-bench-v2/cases`)).status).toBe(404);
+ expect((await outsider.get(filesBase)).status).toBe(404);
+ },
+ );
it("does not migrate or backfill legacy Scoreboard entries", async () => {
const dir = path.join(benchmarksDir(t.root, projectId), "swe-bench-v1");
diff --git a/packages/server/test/directory-skills.test.ts b/packages/server/test/directory-skills.test.ts
index 4e47788b..22a3c299 100644
--- a/packages/server/test/directory-skills.test.ts
+++ b/packages/server/test/directory-skills.test.ts
@@ -21,9 +21,13 @@ import type {
DirectorySkillsResponse,
ProjectCreateResponse,
} from "../src/api/types.js";
-import { apiClient, createTestApp, provisionUser } from "./helpers.js";
+import { apiClient, canCreateSymlink, createTestApp, provisionUser } from "./helpers.js";
import type { TestApp } from "./helpers.js";
+// Symlink creation needs a privilege or Developer Mode on Windows; canCreateSymlink()
+// probes once and caches, so these cases still run where the capability exists.
+const itWithSymlinks = it.skipIf(!canCreateSymlink());
+
const skillMd = (name: string, description = `${name} does a thing`) =>
`---\nname: ${name}\ndescription: ${description}\nversion: 2026.08.23.3\n---\n\nBody of ${name}.\n`;
@@ -94,7 +98,7 @@ describe("directory skills api", () => {
expect(res.skills[0]).not.toHaveProperty("content");
});
- it("offers each Skill once when .claude is a symlink to .agents", async () => {
+ itWithSymlinks("offers each Skill once when .claude is a symlink to .agents", async () => {
await writeSkill(".agents/skills", "alpha");
await writeSkill(".agents/skills", "gamma");
await fs.symlink(path.join(dir, ".agents"), path.join(dir, ".claude"));
@@ -112,60 +116,66 @@ describe("directory skills api", () => {
expect(res.skills[0]!.source).toBe(".agents/skills");
});
- it("passes over what is not an installable Skill instead of offering it", async () => {
- await writeSkill(".agents/skills", "real");
- // No SKILL.md at all.
- await fs.mkdir(path.join(dir, ".agents/skills/empty-dir"), { recursive: true });
- // A SKILL.md with no frontmatter.
- await fs.mkdir(path.join(dir, ".agents/skills/no-frontmatter"), { recursive: true });
- await fs.writeFile(path.join(dir, ".agents/skills/no-frontmatter/SKILL.md"), "just prose\n");
- // A name the installer would reject.
- await fs.mkdir(path.join(dir, ".agents/skills/bad name"), { recursive: true });
- await fs.writeFile(path.join(dir, ".agents/skills/bad name/SKILL.md"), skillMd("bad name"));
- // A symlinked Skill directory: how a tree outside the layout would otherwise be read.
- const outside = path.join(dir, "outside-skill");
- await fs.mkdir(outside, { recursive: true });
- await fs.writeFile(path.join(outside, "SKILL.md"), skillMd("linked"));
- await fs.symlink(outside, path.join(dir, ".agents/skills/linked"));
+ itWithSymlinks(
+ "passes over what is not an installable Skill instead of offering it",
+ async () => {
+ await writeSkill(".agents/skills", "real");
+ // No SKILL.md at all.
+ await fs.mkdir(path.join(dir, ".agents/skills/empty-dir"), { recursive: true });
+ // A SKILL.md with no frontmatter.
+ await fs.mkdir(path.join(dir, ".agents/skills/no-frontmatter"), { recursive: true });
+ await fs.writeFile(path.join(dir, ".agents/skills/no-frontmatter/SKILL.md"), "just prose\n");
+ // A name the installer would reject.
+ await fs.mkdir(path.join(dir, ".agents/skills/bad name"), { recursive: true });
+ await fs.writeFile(path.join(dir, ".agents/skills/bad name/SKILL.md"), skillMd("bad name"));
+ // A symlinked Skill directory: how a tree outside the layout would otherwise be read.
+ const outside = path.join(dir, "outside-skill");
+ await fs.mkdir(outside, { recursive: true });
+ await fs.writeFile(path.join(outside, "SKILL.md"), skillMd("linked"));
+ await fs.symlink(outside, path.join(dir, ".agents/skills/linked"));
- const res = (await (await owner.get(listUrl(dir))).json()) as DirectorySkillsResponse;
- expect(res.skills.map((s) => s.name)).toEqual(["real"]);
- });
+ const res = (await (await owner.get(listUrl(dir))).json()) as DirectorySkillsResponse;
+ expect(res.skills.map((s) => s.name)).toEqual(["real"]);
+ },
+ );
- it("does not follow a symlinked SKILL.md or icon.svg out of the Skill directory", async () => {
- const secret = path.join(dir, "outside", "id_rsa");
- await fs.mkdir(path.dirname(secret), { recursive: true });
- await fs.writeFile(secret, "-----BEGIN PRIVATE KEY-----\nSECRET\n");
+ itWithSymlinks(
+ "does not follow a symlinked SKILL.md or icon.svg out of the Skill directory",
+ async () => {
+ const secret = path.join(dir, "outside", "id_rsa");
+ await fs.mkdir(path.dirname(secret), { recursive: true });
+ await fs.writeFile(secret, "-----BEGIN PRIVATE KEY-----\nSECRET\n");
- // A real Skill whose icon.svg is a link to that file: the Skill is still offered, without an
- // icon — the link's target never reaches the response, nor the Agent it would be installed on.
- await writeSkill(".agents/skills", "linked-icon");
- await fs.rm(path.join(dir, ".agents/skills/linked-icon/icon.svg"), { force: true });
- await fs.symlink(secret, path.join(dir, ".agents/skills/linked-icon/icon.svg"));
- // A Skill whose SKILL.md is itself a link is not a Skill at all.
- const outsideMd = path.join(dir, "outside", "SKILL.md");
- await fs.writeFile(outsideMd, skillMd("linked-md"));
- await fs.mkdir(path.join(dir, ".agents/skills/linked-md"), { recursive: true });
- await fs.symlink(outsideMd, path.join(dir, ".agents/skills/linked-md/SKILL.md"));
+ // A real Skill whose icon.svg is a link to that file: the Skill is still offered, without an
+ // icon — the link's target never reaches the response, nor the Agent it would be installed on.
+ await writeSkill(".agents/skills", "linked-icon");
+ await fs.rm(path.join(dir, ".agents/skills/linked-icon/icon.svg"), { force: true });
+ await fs.symlink(secret, path.join(dir, ".agents/skills/linked-icon/icon.svg"));
+ // A Skill whose SKILL.md is itself a link is not a Skill at all.
+ const outsideMd = path.join(dir, "outside", "SKILL.md");
+ await fs.writeFile(outsideMd, skillMd("linked-md"));
+ await fs.mkdir(path.join(dir, ".agents/skills/linked-md"), { recursive: true });
+ await fs.symlink(outsideMd, path.join(dir, ".agents/skills/linked-md/SKILL.md"));
- const res = (await (await owner.get(listUrl(dir))).json()) as DirectorySkillsResponse;
- expect(res.skills.map((s) => s.name)).toEqual(["linked-icon"]);
- expect(res.skills[0]).not.toHaveProperty("icon");
- expect(JSON.stringify(res)).not.toContain("SECRET");
+ const res = (await (await owner.get(listUrl(dir))).json()) as DirectorySkillsResponse;
+ expect(res.skills.map((s) => s.name)).toEqual(["linked-icon"]);
+ expect(res.skills[0]).not.toHaveProperty("icon");
+ expect(JSON.stringify(res)).not.toContain("SECRET");
- const created = await owner.post(`/api/projects/${projectId}/agents`, {
- agentId: "no_link_agent",
- skillsDirectory: dir,
- directorySkills: ["linked-icon"],
- });
- expect(created.status).toBe(201);
- await expect(
- fs.readFile(
- path.join(skillsDir(t.root, projectId, "no_link_agent"), "linked-icon", "icon.svg"),
- "utf8",
- ),
- ).rejects.toThrow();
- });
+ const created = await owner.post(`/api/projects/${projectId}/agents`, {
+ agentId: "no_link_agent",
+ skillsDirectory: dir,
+ directorySkills: ["linked-icon"],
+ });
+ expect(created.status).toBe(201);
+ await expect(
+ fs.readFile(
+ path.join(skillsDir(t.root, projectId, "no_link_agent"), "linked-icon", "icon.svg"),
+ "utf8",
+ ),
+ ).rejects.toThrow();
+ },
+ );
it("passes over a Skill that busts the size caps instead of hiding the whole directory", async () => {
await writeSkill(".agents/skills", "small");
diff --git a/packages/server/test/helpers.ts b/packages/server/test/helpers.ts
index 496ff25a..bbc23126 100644
--- a/packages/server/test/helpers.ts
+++ b/packages/server/test/helpers.ts
@@ -3,6 +3,7 @@
* requests via app.request() + building Trace files.
* None of these tests listen on a port or make real LLM requests.
*/
+import { mkdtempSync, rmSync, symlinkSync } from "node:fs";
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
@@ -84,6 +85,33 @@ export async function makeTempRoot(): Promise<string> {
return fs.mkdtemp(path.join(os.tmpdir(), "penguin-server-test-"));
}
+let symlinkCapability: boolean | undefined;
+
+/**
+ * Whether this process can create symbolic links at all. Windows denies symlink creation
+ * without a privilege or Developer Mode (EPERM), so tests that need a real symlink skip when
+ * the probe fails — and still run wherever the capability exists (Linux/macOS, elevated or
+ * Developer-Mode Windows) instead of vanishing on every Windows machine. The probe tries once
+ * in a temp directory and caches the answer.
+ */
+export function canCreateSymlink(): boolean {
+ if (symlinkCapability === undefined) {
+ const probeDir = mkdtempSync(path.join(os.tmpdir(), "penguin-symlink-probe-"));
+ try {
+ // A directory link, the variant the guarded cases create; the privilege gate is the
+ // same for file links.
+ symlinkSync(probeDir, path.join(probeDir, "probe"), "dir");
+ symlinkCapability = true;
+ } catch {
+ symlinkCapability = false;
+ } finally {
+ // maxRetries for the same ci-windows cascade reason createTestApp's cleanup documents.
+ rmSync(probeDir, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
+ }
+ }
+ return symlinkCapability;
+}
+
const DAY_MS = 24 * 60 * 60 * 1000;
/** Fixed seeded-admin password injected into every test app (in production the seed generates a random one). */
diff --git a/packages/server/test/memory.test.ts b/packages/server/test/memory.test.ts
index f85a1f1f..3c47d613 100644
--- a/packages/server/test/memory.test.ts
+++ b/packages/server/test/memory.test.ts
@@ -29,9 +29,13 @@ import type {
MemoryTransferFile,
ProjectCreateResponse,
} from "../src/api/types.js";
-import { apiClient, createTestApp, provisionUser } from "./helpers.js";
+import { apiClient, canCreateSymlink, createTestApp, provisionUser } from "./helpers.js";
import type { TestApp } from "./helpers.js";
+// Symlink creation needs a privilege or Developer Mode on Windows; canCreateSymlink()
+// probes once and caches, so these cases still run where the capability exists.
+const itWithSymlinks = it.skipIf(!canCreateSymlink());
+
const WORKSPACE_KEY = "my-app-a81f32c4";
// The `type:` line is the retired field earlier files may still carry — listing must ignore it.
const TOPIC = `---
@@ -134,7 +138,7 @@ describe("memory api", () => {
expect(await fs.readdir(wsDir)).not.toContain(name);
});
- it("neither lists nor follows a symlinked topic file", async () => {
+ itWithSymlinks("neither lists nor follows a symlinked topic file", async () => {
const outside = path.join(t.root, "outside-secret.txt");
await fs.writeFile(outside, "secret", "utf8");
await fs.symlink(outside, path.join(wsDir, "leak.md"));
@@ -144,7 +148,7 @@ describe("memory api", () => {
expect((await owner.get(`${filesPath()}/leak.md`)).status).toBe(404);
});
- it("404s a scope directory smuggled in as a symlink", async () => {
+ itWithSymlinks("404s a scope directory smuggled in as a symlink", async () => {
const outside = path.join(t.root, "outside-dir");
await fs.mkdir(outside, { recursive: true });
await fs.writeFile(path.join(outside, "loot.md"), "---\nname: l\n---\nx\n", "utf8");
@@ -622,43 +626,52 @@ describe("memory scope export/import", () => {
);
});
- it("replaces a symlink standing at a memory's name instead of writing through it", async () => {
- const outside = path.join(t.root, "outside-secret.md");
- await fs.writeFile(outside, "secret\n", "utf8");
- await fs.symlink(outside, path.join(wsDir, "leak.md"));
-
- const res = await runImport(document([topic("leak.md", "imported body")]), {
- mode: "overwrite",
- confirm: true,
- });
- expect(res.status).toBe(200);
- // The link is gone, the memory is a real file inside the scope, and the file it pointed at
- // never saw the write.
- expect((await fs.lstat(path.join(wsDir, "leak.md"))).isSymbolicLink()).toBe(false);
- expect(await fs.readFile(path.join(wsDir, "leak.md"), "utf8")).toContain("imported body");
- expect(await fs.readFile(outside, "utf8")).toBe("secret\n");
- });
+ itWithSymlinks(
+ "replaces a symlink standing at a memory's name instead of writing through it",
+ async () => {
+ const outside = path.join(t.root, "outside-secret.md");
+ await fs.writeFile(outside, "secret\n", "utf8");
+ await fs.symlink(outside, path.join(wsDir, "leak.md"));
+
+ const res = await runImport(document([topic("leak.md", "imported body")]), {
+ mode: "overwrite",
+ confirm: true,
+ });
+ expect(res.status).toBe(200);
+ // The link is gone, the memory is a real file inside the scope, and the file it pointed at
+ // never saw the write.
+ expect((await fs.lstat(path.join(wsDir, "leak.md"))).isSymbolicLink()).toBe(false);
+ expect(await fs.readFile(path.join(wsDir, "leak.md"), "utf8")).toContain("imported body");
+ expect(await fs.readFile(outside, "utf8")).toBe("secret\n");
+ },
+ );
it("leaves no temporary file behind in the scope directory", async () => {
expect((await runImport(document([topic("a.md", "x")]))).status).toBe(200);
expect((await fs.readdir(wsDir)).filter((n) => n.endsWith(".tmp"))).toEqual([]);
});
- it("rejects a bad scope key and a scope smuggled in as a symlink, on both routes", async () => {
- expect((await owner.get(exportPath("..%2Fescape"))).status).toBe(400);
- expect((await runImport(document([]), { key: "..%2Fescape" })).status).toBe(400);
- expect((await owner.get(exportPath("never-run-0badc0de"))).status).toBe(404);
- expect((await runImport(document([]), { key: "never-run-0badc0de" })).status).toBe(404);
-
- const outside = path.join(t.root, "outside-dir");
- await fs.mkdir(outside, { recursive: true });
- await fs.symlink(outside, memoryScopeDir(t.root, projectId, "default_agent", "evil-12345678"));
- expect((await owner.get(exportPath("evil-12345678"))).status).toBe(404);
- expect((await runImport(document([topic("a.md", "x")]), { key: "evil-12345678" })).status).toBe(
- 404,
- );
- expect(await fs.readdir(outside)).toEqual([]);
- });
+ itWithSymlinks(
+ "rejects a bad scope key and a scope smuggled in as a symlink, on both routes",
+ async () => {
+ expect((await owner.get(exportPath("..%2Fescape"))).status).toBe(400);
+ expect((await runImport(document([]), { key: "..%2Fescape" })).status).toBe(400);
+ expect((await owner.get(exportPath("never-run-0badc0de"))).status).toBe(404);
+ expect((await runImport(document([]), { key: "never-run-0badc0de" })).status).toBe(404);
+
+ const outside = path.join(t.root, "outside-dir");
+ await fs.mkdir(outside, { recursive: true });
+ await fs.symlink(
+ outside,
+ memoryScopeDir(t.root, projectId, "default_agent", "evil-12345678"),
+ );
+ expect((await owner.get(exportPath("evil-12345678"))).status).toBe(404);
+ expect(
+ (await runImport(document([topic("a.md", "x")]), { key: "evil-12345678" })).status,
+ ).toBe(404);
+ expect(await fs.readdir(outside)).toEqual([]);
+ },
+ );
// —— Authorization ——
diff --git a/packages/server/test/workspace-files.test.ts b/packages/server/test/workspace-files.test.ts
index 6261ccc2..f3836b7d 100644
--- a/packages/server/test/workspace-files.test.ts
+++ b/packages/server/test/workspace-files.test.ts
@@ -22,6 +22,7 @@ import type {
} from "../src/api/types.js";
import {
apiClient,
+ canCreateSymlink,
createDesktopApp,
createTestApp,
desktopLoginCookie,
@@ -31,6 +32,10 @@ import {
} from "./helpers.js";
import type { TestApp } from "./helpers.js";
+// Symlink creation needs a privilege or Developer Mode on Windows; canCreateSymlink()
+// probes once and caches, so these cases still run where the capability exists.
+const itWithSymlinks = it.skipIf(!canCreateSymlink());
+
describe("workspace-files-service", () => {
let ws: string;
let outside: string;
@@ -90,51 +95,60 @@ describe("workspace-files-service", () => {
expect(sub.entries.map((e) => e.name)).toEqual(["c.md"]);
});
- it("a symlink to a directory inside the Workspace: kind is dir and it can be drilled into", async () => {
- await fs.symlink(path.join(ws, "sub"), path.join(ws, "link-sub"));
- const root = await svc.list(ws, "");
- expect(root.entries.map((e) => `${e.kind}:${e.name}`)).toEqual([
- "dir:link-sub",
- "dir:sub",
- "file:b.txt",
- ]);
- const viaLink = await svc.list(ws, "link-sub");
- expect(viaLink.entries.map((e) => e.name)).toEqual(["c.md"]);
- });
-
- it("symlink escape: reads and writes are both rejected when the link points outside the Workspace", async () => {
- await fs.symlink(outside, path.join(ws, "link-out"));
- const root = await svc.list(ws, "");
- expect(root.entries.map((entry) => entry.name)).not.toContain("link-out");
- await expect(svc.list(ws, "link-out")).rejects.toMatchObject({ status: 400 });
- await expect(svc.read(ws, "link-out/secret.txt")).rejects.toMatchObject({ status: 400 });
- // Writing outside via a directory symlink: caught by the parent-directory realpath check.
- await expect(svc.write(ws, "link-out/evil.txt", Buffer.from("x"))).rejects.toMatchObject({
- status: 400,
- });
- // Auto-creation under a missing path is equally restricted: if the nearest
- // existing ancestor is a symlink pointing outside, mkdir must not be used to escape.
- await expect(svc.write(ws, "link-out/new/evil.txt", Buffer.from("x"))).rejects.toMatchObject({
- status: 400,
- });
- expect(
- await fs
- .stat(path.join(outside, "new"))
- .then(() => true)
- .catch(() => false),
- ).toBe(false);
- });
-
- it("writing through a last-segment symlink: O_NOFOLLOW refuses to overwrite files outside the Workspace by proxy", async () => {
- // The Agent has a symlink inside the Workspace pointing to an outside file; an upload attempts to overwrite it.
- const victim = path.join(outside, "secret.txt");
- await fs.symlink(victim, path.join(ws, "report.pdf"));
- await expect(svc.write(ws, "report.pdf", Buffer.from("PWNED"))).rejects.toMatchObject({
- status: 400,
- });
- // The outside file's content is unchanged.
- expect(await fs.readFile(victim, "utf8")).toBe("secret");
- });
+ itWithSymlinks(
+ "a symlink to a directory inside the Workspace: kind is dir and it can be drilled into",
+ async () => {
+ await fs.symlink(path.join(ws, "sub"), path.join(ws, "link-sub"));
+ const root = await svc.list(ws, "");
+ expect(root.entries.map((e) => `${e.kind}:${e.name}`)).toEqual([
+ "dir:link-sub",
+ "dir:sub",
+ "file:b.txt",
+ ]);
+ const viaLink = await svc.list(ws, "link-sub");
+ expect(viaLink.entries.map((e) => e.name)).toEqual(["c.md"]);
+ },
+ );
+
+ itWithSymlinks(
+ "symlink escape: reads and writes are both rejected when the link points outside the Workspace",
+ async () => {
+ await fs.symlink(outside, path.join(ws, "link-out"));
+ const root = await svc.list(ws, "");
+ expect(root.entries.map((entry) => entry.name)).not.toContain("link-out");
+ await expect(svc.list(ws, "link-out")).rejects.toMatchObject({ status: 400 });
+ await expect(svc.read(ws, "link-out/secret.txt")).rejects.toMatchObject({ status: 400 });
+ // Writing outside via a directory symlink: caught by the parent-directory realpath check.
+ await expect(svc.write(ws, "link-out/evil.txt", Buffer.from("x"))).rejects.toMatchObject({
+ status: 400,
+ });
+ // Auto-creation under a missing path is equally restricted: if the nearest
+ // existing ancestor is a symlink pointing outside, mkdir must not be used to escape.
+ await expect(svc.write(ws, "link-out/new/evil.txt", Buffer.from("x"))).rejects.toMatchObject({
+ status: 400,
+ });
+ expect(
+ await fs
+ .stat(path.join(outside, "new"))
+ .then(() => true)
+ .catch(() => false),
+ ).toBe(false);
+ },
+ );
+
+ itWithSymlinks(
+ "writing through a last-segment symlink: O_NOFOLLOW refuses to overwrite files outside the Workspace by proxy",
+ async () => {
+ // The Agent has a symlink inside the Workspace pointing to an outside file; an upload attempts to overwrite it.
+ const victim = path.join(outside, "secret.txt");
+ await fs.symlink(victim, path.join(ws, "report.pdf"));
+ await expect(svc.write(ws, "report.pdf", Buffer.from("PWNED"))).rejects.toMatchObject({
+ status: 400,
+ });
+ // The outside file's content is unchanged.
+ expect(await fs.readFile(victim, "utf8")).toBe("secret");
+ },
+ );
it("write precondition: a matching version writes, one the file has moved past is refused with nothing written", async () => {
const { version } = await svc.read(ws, "b.txt");
@@ -268,45 +282,52 @@ describe("workspace-files-service", () => {
});
});
- it("move and delete confinement: `..` at either end, a symlinked destination directory, and a symlink at the final segment are all refused", async () => {
- const outsideName = path.basename(outside);
- await fs.symlink(outside, path.join(ws, "link-out"));
-
- // `..` in the source: the file outside is neither read nor moved in.
- await expect(svc.move(ws, `../${outsideName}/secret.txt`, "stolen.txt")).rejects.toMatchObject({
- status: 400,
- });
- expect(await fs.stat(path.join(ws, "stolen.txt")).catch(() => null)).toBeNull();
-
- // `..` in the destination: nothing lands outside the Workspace.
- await expect(svc.move(ws, "b.txt", "../escape.txt")).rejects.toMatchObject({ status: 400 });
- expect(await fs.stat(path.join(path.dirname(ws), "escape.txt")).catch(() => null)).toBeNull();
- expect(await fs.readFile(path.join(ws, "b.txt"), "utf8")).toBe("hello");
-
- // A destination parent that is a symlink pointing outside: caught by the same
- // canonical-parent check an upload runs, including through a directory it would create.
- await expect(svc.move(ws, "b.txt", "link-out/evil.txt")).rejects.toMatchObject({ status: 400 });
- await expect(svc.move(ws, "b.txt", "link-out/new/evil.txt")).rejects.toMatchObject({
- status: 400,
- });
- expect(await fs.stat(path.join(outside, "evil.txt")).catch(() => null)).toBeNull();
-
- // `..` in a delete: the file outside survives.
- await expect(svc.remove(ws, `../${outsideName}/secret.txt`)).rejects.toMatchObject({
- status: 400,
- });
- expect(await fs.readFile(path.join(outside, "secret.txt"), "utf8")).toBe("secret");
-
- // A symlink at the final segment — the Agent's "preset a link, act on it by proxy"
- // pattern: O_NOFOLLOW refuses it, so neither the link's target nor the link is touched.
- await fs.symlink(path.join(outside, "secret.txt"), path.join(ws, "report.pdf"));
- await expect(svc.move(ws, "report.pdf", "sub/report.pdf")).rejects.toMatchObject({
- status: 400,
- });
- await expect(svc.remove(ws, "report.pdf")).rejects.toMatchObject({ status: 400 });
- expect(await fs.readFile(path.join(outside, "secret.txt"), "utf8")).toBe("secret");
- expect((await fs.lstat(path.join(ws, "report.pdf"))).isSymbolicLink()).toBe(true);
- });
+ itWithSymlinks(
+ "move and delete confinement: `..` at either end, a symlinked destination directory, and a symlink at the final segment are all refused",
+ async () => {
+ const outsideName = path.basename(outside);
+ await fs.symlink(outside, path.join(ws, "link-out"));
+
+ // `..` in the source: the file outside is neither read nor moved in.
+ await expect(
+ svc.move(ws, `../${outsideName}/secret.txt`, "stolen.txt"),
+ ).rejects.toMatchObject({
+ status: 400,
+ });
+ expect(await fs.stat(path.join(ws, "stolen.txt")).catch(() => null)).toBeNull();
+
+ // `..` in the destination: nothing lands outside the Workspace.
+ await expect(svc.move(ws, "b.txt", "../escape.txt")).rejects.toMatchObject({ status: 400 });
+ expect(await fs.stat(path.join(path.dirname(ws), "escape.txt")).catch(() => null)).toBeNull();
+ expect(await fs.readFile(path.join(ws, "b.txt"), "utf8")).toBe("hello");
+
+ // A destination parent that is a symlink pointing outside: caught by the same
+ // canonical-parent check an upload runs, including through a directory it would create.
+ await expect(svc.move(ws, "b.txt", "link-out/evil.txt")).rejects.toMatchObject({
+ status: 400,
+ });
+ await expect(svc.move(ws, "b.txt", "link-out/new/evil.txt")).rejects.toMatchObject({
+ status: 400,
+ });
+ expect(await fs.stat(path.join(outside, "evil.txt")).catch(() => null)).toBeNull();
+
+ // `..` in a delete: the file outside survives.
+ await expect(svc.remove(ws, `../${outsideName}/secret.txt`)).rejects.toMatchObject({
+ status: 400,
+ });
+ expect(await fs.readFile(path.join(outside, "secret.txt"), "utf8")).toBe("secret");
+
+ // A symlink at the final segment — the Agent's "preset a link, act on it by proxy"
+ // pattern: O_NOFOLLOW refuses it, so neither the link's target nor the link is touched.
+ await fs.symlink(path.join(outside, "secret.txt"), path.join(ws, "report.pdf"));
+ await expect(svc.move(ws, "report.pdf", "sub/report.pdf")).rejects.toMatchObject({
+ status: 400,
+ });
+ await expect(svc.remove(ws, "report.pdf")).rejects.toMatchObject({ status: 400 });
+ expect(await fs.readFile(path.join(outside, "secret.txt"), "utf8")).toBe("secret");
+ expect((await fs.lstat(path.join(ws, "report.pdf"))).isSymbolicLink()).toBe(true);
+ },
+ );
it("search: finds a file several directories down that no listing ever reached, reports it as a tree row would, and matches the name rather than the path", async () => {
await fs.mkdir(path.join(ws, "a", "b", "c"), { recursive: true });
@@ -368,25 +389,28 @@ describe("workspace-files-service", () => {
]);
});
- it("search confinement: an out-of-bounds symlink is never walked into and never appears as a hit, and a link back to the root cannot spin the walk", async () => {
- await fs.writeFile(path.join(outside, "secret-needle.txt"), "s");
- await fs.symlink(outside, path.join(ws, "link-out"));
- // A cycle: the Workspace root reachable from inside itself, twice over.
- await fs.symlink(ws, path.join(ws, "self"));
- await fs.symlink(ws, path.join(ws, "sub", "back"));
-
- // Nothing outside is reachable, and the link that points there is not itself a hit.
- expect((await svc.search(ws, "secret")).hits).toEqual([]);
- expect((await svc.search(ws, "link-out")).hits).toEqual([]);
-
- // The walk terminates and reports each in-bounds entry once.
- const all = await svc.search(ws, "b.txt");
- expect(all.hits.map((h) => h.path)).toEqual(["b.txt"]);
- expect(all.truncated).toBe(false);
- // A self-link is an in-bounds directory, so it is a legitimate hit — it is only never
- // descended into a second time.
- expect((await svc.search(ws, "self")).hits.map((h) => h.path)).toEqual(["self"]);
- });
+ itWithSymlinks(
+ "search confinement: an out-of-bounds symlink is never walked into and never appears as a hit, and a link back to the root cannot spin the walk",
+ async () => {
+ await fs.writeFile(path.join(outside, "secret-needle.txt"), "s");
+ await fs.symlink(outside, path.join(ws, "link-out"));
+ // A cycle: the Workspace root reachable from inside itself, twice over.
+ await fs.symlink(ws, path.join(ws, "self"));
+ await fs.symlink(ws, path.join(ws, "sub", "back"));
+
+ // Nothing outside is reachable, and the link that points there is not itself a hit.
+ expect((await svc.search(ws, "secret")).hits).toEqual([]);
+ expect((await svc.search(ws, "link-out")).hits).toEqual([]);
+
+ // The walk terminates and reports each in-bounds entry once.
+ const all = await svc.search(ws, "b.txt");
+ expect(all.hits.map((h) => h.path)).toEqual(["b.txt"]);
+ expect(all.truncated).toBe(false);
+ // A self-link is an in-bounds directory, so it is a legitimate hit — it is only never
+ // descended into a second time.
+ expect((await svc.search(ws, "self")).hits.map((h) => h.path)).toEqual(["self"]);
+ },
+ );
it("search: the hit cap truncates and says so; an empty or oversize query is a 400", async () => {
await Promise.all(
diff --git a/packages/server/test/workspace-guard.test.ts b/packages/server/test/workspace-guard.test.ts
index 1fc73f9e..00565ba4 100644
--- a/packages/server/test/workspace-guard.test.ts
+++ b/packages/server/test/workspace-guard.test.ts
@@ -8,7 +8,11 @@ import path from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { HttpError } from "../src/http/errors.js";
import { assertWorkspaceAllowed } from "../src/services/workspace-guard.js";
-import { makeTempRoot } from "./helpers.js";
+import { canCreateSymlink, makeTempRoot } from "./helpers.js";
+
+// Symlink creation needs a privilege or Developer Mode on Windows; canCreateSymlink()
+// probes once and caches, so these cases still run where the capability exists.
+const itWithSymlinks = it.skipIf(!canCreateSymlink());
describe("workspace-guard", () => {
let root: string;
@@ -36,7 +40,7 @@ describe("workspace-guard", () => {
await expect(guard(outside)).resolves.toBe(await fs.realpath(outside));
});
- it("symlinks resolve to their realpath before returning", async () => {
+ itWithSymlinks("symlinks resolve to their realpath before returning", async () => {
const outside = path.join(root, "linked");
await fs.mkdir(outside, { recursive: true });
const link = path.join(projectA, "escape");