Files
openclaw/src/plugin-sdk/fs-safe-compat.test.ts
Paul Campbell 008f04a656 feat(mxc): add Windows MXC sandbox backend (#97086)
* feat(mxc): add Windows MXC sandbox backend

Add the official MXC sandbox plugin package with Windows ProcessContainer execution, plugin-owned MXC SDK dependency packaging, host-backed filesystem bridge support, and configured MXC policy file loading via mxcPolicyPaths.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(mxc): preserve Windows binary override paths

* fix: remove stray sandbox barrel export

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 9ea19539-b8ca-44fb-93bd-b8496e3deb2c

* fix(mxc): address sandbox review feedback

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mxc): satisfy test type checks

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mxc): clarify protected skill enforcement

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(mxc): align fail-closed expectations

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mxc): satisfy extension lint

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(plugin-sdk): narrow fs-safe remove surface

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mxc): repair rebased CI failures

* fix(scripts): declare shrinkwrap override normalizer

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Gio Della-Libera <235387111+giodl73-repo@users.noreply.github.com>
Co-authored-by: Dallin Romney <dallinromney@gmail.com>
2026-07-12 23:07:25 -07:00

69 lines
2.3 KiB
TypeScript

/**
* Tests fs-safe compatibility exports used by plugin SDK callers.
*/
import fs from "node:fs";
import path from "node:path";
import { loadSecretFileSync as loadSecretFileSyncFromCore } from "openclaw/plugin-sdk/core";
import {
readFileWithinRoot,
removePathWithinRoot,
writeFileWithinRoot,
} from "openclaw/plugin-sdk/file-access-runtime";
import {
loadSecretFileSync,
type SecretFileReadResult,
} from "openclaw/plugin-sdk/secret-file-runtime";
import { describe, expect, it } from "vitest";
import { withTempDir } from "../test-helpers/temp-dir.js";
describe("plugin SDK fs-safe compatibility exports", () => {
it("keeps deprecated secret-file result helpers on public SDK subpaths", async () => {
await withTempDir({ prefix: "openclaw-sdk-secret-compat-" }, async (root) => {
const secretPath = path.join(root, "token.txt");
fs.writeFileSync(secretPath, "secret\n", { mode: 0o600 });
const result: SecretFileReadResult = loadSecretFileSync(secretPath, "token");
expect(result.ok).toBe(true);
if (!result.ok) {
throw new Error("expected secret-file read to succeed");
}
expect(result.secret).toBe("secret");
expect(result.resolvedPath).toBe(secretPath);
const coreResult = loadSecretFileSyncFromCore(secretPath, "token");
expect(coreResult.ok).toBe(true);
if (!coreResult.ok) {
throw new Error("expected core secret-file read to succeed");
}
expect(coreResult.secret).toBe("secret");
});
});
it("keeps root-bounded file-access helpers on file-access-runtime", async () => {
await withTempDir({ prefix: "openclaw-sdk-file-access-compat-" }, async (root) => {
await writeFileWithinRoot({
rootDir: root,
relativePath: "nested/file.txt",
data: "hello",
mkdir: true,
});
const result = await readFileWithinRoot({
rootDir: root,
relativePath: "nested/file.txt",
});
expect(result.buffer.toString("utf8")).toBe("hello");
expect(result.realPath).toBe(fs.realpathSync(path.join(root, "nested", "file.txt")));
await removePathWithinRoot({
rootDir: root,
relativePath: "nested/file.txt",
force: false,
});
expect(fs.existsSync(path.join(root, "nested", "file.txt"))).toBe(false);
});
});
});