Files
openclaw-zero-token/media/store.outside-workspace.test.ts
sjhu 571e14a236 feat: upgrade to upstream v2026.3.28
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
2026-03-30 17:58:12 +08:00

60 lines
1.8 KiB
TypeScript

import fs from "node:fs/promises";
import path from "node:path";
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { createTempHomeEnv, type TempHomeEnv } from "../test-utils/temp-home.js";
const mocks = vi.hoisted(() => ({
readLocalFileSafely: vi.fn(),
}));
vi.mock("../infra/fs-safe.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../infra/fs-safe.js")>();
return {
...actual,
readLocalFileSafely: mocks.readLocalFileSafely,
};
});
type StoreModule = typeof import("./store.js");
type FsSafeModule = typeof import("../infra/fs-safe.js");
let saveMediaSource: StoreModule["saveMediaSource"];
let SafeOpenError: FsSafeModule["SafeOpenError"];
async function expectOutsideWorkspaceStoreFailure(sourcePath: string) {
await expect(saveMediaSource(sourcePath)).rejects.toMatchObject({
code: "invalid-path",
message: "Media path is outside workspace root",
});
}
describe("media store outside-workspace mapping", () => {
let tempHome: TempHomeEnv;
let home = "";
beforeEach(async () => {
vi.resetModules();
({ saveMediaSource } = await import("./store.js"));
({ SafeOpenError } = await import("../infra/fs-safe.js"));
});
beforeAll(async () => {
tempHome = await createTempHomeEnv("openclaw-media-store-test-home-");
home = tempHome.home;
});
afterAll(async () => {
await tempHome.restore();
});
it("maps outside-workspace reads to a descriptive invalid-path error", async () => {
const sourcePath = path.join(home, "outside-media.txt");
await fs.writeFile(sourcePath, "hello");
mocks.readLocalFileSafely.mockRejectedValueOnce(
new SafeOpenError("outside-workspace", "file is outside workspace root"),
);
await expectOutsideWorkspaceStoreFailure(sourcePath);
});
});