mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 10:00:43 +00:00
* fix(agents): normalize Windows runtime imports * test(providers): align manifest contract coverage
83 lines
2.9 KiB
TypeScript
83 lines
2.9 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
importRuntimeModule,
|
|
resolveRuntimeImportSpecifier,
|
|
toSafeRuntimeImportPath,
|
|
} from "./runtime-import.js";
|
|
|
|
describe("runtime-import", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("converts Windows absolute import specifiers to file URLs", () => {
|
|
vi.spyOn(process, "platform", "get").mockReturnValue("win32");
|
|
|
|
expect(toSafeRuntimeImportPath("C:\\Users\\alice\\plugin\\index.mjs")).toBe(
|
|
"file:///C:/Users/alice/plugin/index.mjs",
|
|
);
|
|
expect(toSafeRuntimeImportPath("C:\\Users\\alice\\plugin folder\\x#y.mjs")).toBe(
|
|
"file:///C:/Users/alice/plugin%20folder/x%23y.mjs",
|
|
);
|
|
expect(toSafeRuntimeImportPath("\\\\server\\share\\plugin\\index.mjs")).toBe(
|
|
"file://server/share/plugin/index.mjs",
|
|
);
|
|
});
|
|
|
|
it("resolves runtime imports from Windows absolute base paths", () => {
|
|
vi.spyOn(process, "platform", "get").mockReturnValue("win32");
|
|
|
|
expect(
|
|
resolveRuntimeImportSpecifier("C:\\Users\\alice\\openclaw\\dist\\subagent-registry.js", [
|
|
"./subagent-registry.runtime.js",
|
|
]),
|
|
).toBe("file:///C:/Users/alice/openclaw/dist/subagent-registry.runtime.js");
|
|
});
|
|
|
|
it("resolves runtime imports from file URL base paths", () => {
|
|
vi.spyOn(process, "platform", "get").mockReturnValue("win32");
|
|
|
|
expect(
|
|
resolveRuntimeImportSpecifier("file:///C:/Users/alice/openclaw/dist/subagent-registry.js", [
|
|
"./subagent-registry.runtime.js",
|
|
]),
|
|
).toBe("file:///C:/Users/alice/openclaw/dist/subagent-registry.runtime.js");
|
|
});
|
|
|
|
it("resolves absolute Windows runtime import parts directly", () => {
|
|
vi.spyOn(process, "platform", "get").mockReturnValue("win32");
|
|
|
|
expect(
|
|
resolveRuntimeImportSpecifier("file:///C:/Users/alice/openclaw/dist/subagent-registry.js", [
|
|
"D:\\OpenClaw\\dist\\subagent-registry.runtime.js",
|
|
]),
|
|
).toBe("file:///D:/OpenClaw/dist/subagent-registry.runtime.js");
|
|
});
|
|
|
|
it("keeps non-Windows import paths unchanged", () => {
|
|
vi.spyOn(process, "platform", "get").mockReturnValue("linux");
|
|
|
|
expect(toSafeRuntimeImportPath("C:\\Users\\alice\\plugin\\index.mjs")).toBe(
|
|
"C:\\Users\\alice\\plugin\\index.mjs",
|
|
);
|
|
});
|
|
|
|
it("imports with the normalized runtime specifier", async () => {
|
|
vi.spyOn(process, "platform", "get").mockReturnValue("win32");
|
|
const importModule = vi.fn(async (specifier: string) => ({ specifier }));
|
|
|
|
const result = await importRuntimeModule(
|
|
"C:\\Users\\alice\\openclaw\\dist\\subagent-registry.js",
|
|
["./subagent-registry.runtime.js"],
|
|
importModule,
|
|
);
|
|
|
|
expect(importModule).toHaveBeenCalledWith(
|
|
"file:///C:/Users/alice/openclaw/dist/subagent-registry.runtime.js",
|
|
);
|
|
expect(result).toEqual({
|
|
specifier: "file:///C:/Users/alice/openclaw/dist/subagent-registry.runtime.js",
|
|
});
|
|
});
|
|
});
|