|
| 1 | +import fs from "node:fs/promises"; |
| 2 | +import path from "node:path"; |
| 3 | +import { describe, expect, it } from "vitest"; |
| 4 | +import { buildSandboxFsMounts, resolveSandboxFsPathWithMounts } from "./fs-paths.js"; |
| 5 | +import { createSandbox, withTempDir } from "./fs-bridge.test-helpers.js"; |
| 6 | + |
| 7 | +describe("workspace skills bridge mount policy", () => { |
| 8 | +it("resolves workspace skill roots as read-only", async () => { |
| 9 | +await withTempDir("openclaw-skills-bridge-", async (stateDir) => { |
| 10 | +const workspaceDir = path.join(stateDir, "workspace"); |
| 11 | +await fs.mkdir(path.join(workspaceDir, "skills", "demo"), { recursive: true }); |
| 12 | +await fs.mkdir(path.join(workspaceDir, ".agents", "skills", "demo"), { recursive: true }); |
| 13 | + |
| 14 | +const sandbox = createSandbox({ workspaceDir, agentWorkspaceDir: workspaceDir }); |
| 15 | +const mounts = buildSandboxFsMounts(sandbox); |
| 16 | +const resolve = (filePath: string) => |
| 17 | +resolveSandboxFsPathWithMounts({ |
| 18 | + filePath, |
| 19 | +cwd: sandbox.workspaceDir, |
| 20 | +defaultWorkspaceRoot: sandbox.workspaceDir, |
| 21 | +defaultContainerRoot: sandbox.containerWorkdir, |
| 22 | + mounts, |
| 23 | +}); |
| 24 | + |
| 25 | +expect(resolve("normal.txt").writable).toBe(true); |
| 26 | +expect(resolve("skills/demo/SKILL.md").writable).toBe(false); |
| 27 | +expect(resolve(".agents/skills/demo/SKILL.md").writable).toBe(false); |
| 28 | +expect(resolve("/workspace/skills/demo/SKILL.md").writable).toBe(false); |
| 29 | +}); |
| 30 | +}); |
| 31 | +}); |