forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentry.test.ts
More file actions
62 lines (48 loc) 路 1.84 KB
/
Copy pathentry.test.ts
File metadata and controls
62 lines (48 loc) 路 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { describe, expect, it, vi } from "vitest";
import { tryHandleRootHelpFastPath } from "./entry.js";
const outputPrecomputedRootHelpTextMock = vi.hoisted(() => vi.fn(() => false));
vi.mock("./cli/root-help-metadata.js", () => ({
outputPrecomputedRootHelpText: outputPrecomputedRootHelpTextMock,
}));
describe("entry root help fast path", () => {
it("prefers precomputed root help text when available", async () => {
outputPrecomputedRootHelpTextMock.mockReturnValueOnce(true);
const handled = tryHandleRootHelpFastPath(["node", "openclaw", "--help"], {
env: {},
});
await vi.dynamicImportSettled();
expect(handled).toBe(true);
expect(outputPrecomputedRootHelpTextMock).toHaveBeenCalledTimes(1);
});
it("renders root help without importing the full program", async () => {
const outputRootHelpMock = vi.fn();
const handled = tryHandleRootHelpFastPath(["node", "openclaw", "--help"], {
outputRootHelp: outputRootHelpMock,
env: {},
});
await Promise.resolve();
expect(handled).toBe(true);
expect(outputRootHelpMock).toHaveBeenCalledTimes(1);
});
it("ignores non-root help invocations", () => {
const outputRootHelpMock = vi.fn();
const handled = tryHandleRootHelpFastPath(["node", "openclaw", "status", "--help"], {
outputRootHelp: outputRootHelpMock,
env: {},
});
expect(handled).toBe(false);
expect(outputRootHelpMock).not.toHaveBeenCalled();
});
it("skips the host help fast path when a container target is active", () => {
const outputRootHelpMock = vi.fn();
const handled = tryHandleRootHelpFastPath(
["node", "openclaw", "--container", "demo", "--help"],
{
outputRootHelp: outputRootHelpMock,
env: {},
},
);
expect(handled).toBe(false);
expect(outputRootHelpMock).not.toHaveBeenCalled();
});
});