mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 02:10:21 +00:00
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { cleanupTrackedTempDirs, makeTrackedTempDir } from "./test-helpers/fs-fixtures.js";
|
|
import {
|
|
getRegistryJitiMocks,
|
|
resetRegistryJitiMocks,
|
|
} from "./test-helpers/registry-jiti-mocks.js";
|
|
|
|
const tempDirs: string[] = [];
|
|
const mocks = getRegistryJitiMocks();
|
|
|
|
let clearPluginDoctorContractRegistryCache: typeof import("./doctor-contract-registry.js").clearPluginDoctorContractRegistryCache;
|
|
let listPluginDoctorLegacyConfigRules: typeof import("./doctor-contract-registry.js").listPluginDoctorLegacyConfigRules;
|
|
|
|
function makeTempDir(): string {
|
|
return makeTrackedTempDir("openclaw-doctor-contract-registry", tempDirs);
|
|
}
|
|
|
|
afterEach(() => {
|
|
cleanupTrackedTempDirs(tempDirs);
|
|
});
|
|
|
|
describe("doctor-contract-registry getJiti", () => {
|
|
beforeEach(async () => {
|
|
resetRegistryJitiMocks();
|
|
vi.resetModules();
|
|
({ clearPluginDoctorContractRegistryCache, listPluginDoctorLegacyConfigRules } =
|
|
await import("./doctor-contract-registry.js"));
|
|
clearPluginDoctorContractRegistryCache();
|
|
});
|
|
|
|
it("disables native jiti loading on Windows for contract-api modules", () => {
|
|
const pluginRoot = makeTempDir();
|
|
fs.writeFileSync(path.join(pluginRoot, "contract-api.js"), "export default {};\n", "utf-8");
|
|
mocks.loadPluginManifestRegistry.mockReturnValue({
|
|
plugins: [{ id: "test-plugin", rootDir: pluginRoot }],
|
|
diagnostics: [],
|
|
});
|
|
const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");
|
|
|
|
try {
|
|
listPluginDoctorLegacyConfigRules({
|
|
workspaceDir: pluginRoot,
|
|
env: {},
|
|
});
|
|
} finally {
|
|
platformSpy.mockRestore();
|
|
}
|
|
|
|
expect(mocks.createJiti).toHaveBeenCalledTimes(1);
|
|
expect(mocks.createJiti.mock.calls[0]?.[0]).toBe(path.join(pluginRoot, "contract-api.js"));
|
|
expect(mocks.createJiti.mock.calls[0]?.[1]).toEqual(
|
|
expect.objectContaining({
|
|
tryNative: false,
|
|
}),
|
|
);
|
|
});
|
|
});
|