Files
openclaw/src/index.test.ts
2026-03-15 20:12:37 -07:00

47 lines
1.3 KiB
TypeScript

import fs from "node:fs";
import { afterEach, describe, expect, it, vi } from "vitest";
const runtimeMocks = vi.hoisted(() => ({
runCli: vi.fn(async () => {}),
}));
vi.mock("./cli/run-main.js", () => ({
runCli: runtimeMocks.runCli,
}));
describe("legacy root entry", () => {
afterEach(() => {
vi.clearAllMocks();
vi.resetModules();
});
it("routes the package root export to the pure library entry", () => {
const packageJson = JSON.parse(
fs.readFileSync(new URL("../package.json", import.meta.url), "utf8"),
) as {
exports?: Record<string, unknown>;
main?: string;
};
expect(packageJson.main).toBe("dist/index.js");
expect(packageJson.exports?.["."]).toBe("./dist/index.js");
});
it("does not run CLI bootstrap when imported as a library dependency", async () => {
const mod = await import("./index.js");
expect(typeof mod.runLegacyCliEntry).toBe("function");
expect(runtimeMocks.runCli).not.toHaveBeenCalled();
});
it("delegates legacy direct-entry execution to run-main", async () => {
const mod = await import("./index.js");
const argv = ["node", "dist/index.js", "status"];
await mod.runLegacyCliEntry(argv);
expect(runtimeMocks.runCli).toHaveBeenCalledOnce();
expect(runtimeMocks.runCli).toHaveBeenCalledWith(argv);
});
});