Files
openclaw/src/agents/tools/media-tool-shared.test.ts
Jacob Tomlinson 1ca4261d7e fix(media): keep local roots configuration-derived (#57770)
* fix(media): keep local roots configuration-derived

Co-authored-by: Jacob Tomlinson <jtomlinson@nvidia.com>

* fix(media): simplify local root lookup

* fix(media): keep legacy local roots export
2026-03-30 17:15:03 +01:00

38 lines
1.5 KiB
TypeScript

import path from "node:path";
import { pathToFileURL } from "node:url";
import { afterEach, describe, expect, it, vi } from "vitest";
import { resolveMediaToolLocalRoots } from "./media-tool-shared.js";
function normalizeHostPath(value: string): string {
return path.normalize(path.resolve(value));
}
describe("resolveMediaToolLocalRoots", () => {
afterEach(() => {
vi.unstubAllEnvs();
});
it("does not widen default local roots from media sources", () => {
const stateDir = path.join("/tmp", "openclaw-media-tool-roots-state");
const picturesDir =
process.platform === "win32" ? "C:\\Users\\peter\\Pictures" : "/Users/peter/Pictures";
const moviesDir =
process.platform === "win32" ? "C:\\Users\\peter\\Movies" : "/Users/peter/Movies";
vi.stubEnv("OPENCLAW_STATE_DIR", stateDir);
const roots = resolveMediaToolLocalRoots(path.join(stateDir, "workspace-agent"), undefined, [
path.join(picturesDir, "photo.png"),
pathToFileURL(path.join(moviesDir, "clip.mp4")).href,
"/top-level-file.png",
]);
const normalizedRoots = roots.map(normalizeHostPath);
expect(normalizedRoots).toContain(normalizeHostPath(path.join(stateDir, "workspace-agent")));
expect(normalizedRoots).toContain(normalizeHostPath(path.join(stateDir, "workspace")));
expect(normalizedRoots).not.toContain(normalizeHostPath(picturesDir));
expect(normalizedRoots).not.toContain(normalizeHostPath(moviesDir));
expect(normalizedRoots).not.toContain(normalizeHostPath("/"));
});
});