

























@@ -0,0 +1,77 @@
1+import { Command } from "commander";
2+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3+4+describe("models cli lazy runtime boundary", () => {
5+beforeEach(() => {
6+vi.resetModules();
7+});
8+9+afterEach(() => {
10+vi.doUnmock("./models-cli.runtime.js");
11+vi.doUnmock("../commands/models/list.status-command.js");
12+vi.resetModules();
13+});
14+15+it("renders help without importing the models runtime", async () => {
16+const runtimeLoaded = vi.fn();
17+vi.doMock("./models-cli.runtime.js", () => {
18+runtimeLoaded();
19+return {
20+defaultRuntime: {},
21+rejectAgentScopedModelWrite: vi.fn(),
22+resolveModelAgentOption: vi.fn(),
23+runModelsCommand: vi.fn(),
24+};
25+});
26+27+const { registerModelsCli } = await import("./models-cli.js");
28+const program = new Command();
29+program.exitOverride();
30+program.configureOutput({
31+writeErr: () => {},
32+writeOut: () => {},
33+});
34+registerModelsCli(program);
35+36+await expect(program.parseAsync(["models", "--help"], { from: "user" })).rejects.toMatchObject({
37+exitCode: 0,
38+});
39+expect(runtimeLoaded).not.toHaveBeenCalled();
40+});
41+42+it("loads the models runtime for command actions", async () => {
43+const defaultRuntime = {};
44+const modelsStatusCommand = vi.fn().mockResolvedValue(undefined);
45+const runModelsCommand = vi.fn(async (action: () => Promise<void>) => {
46+await action();
47+});
48+const resolveModelAgentOption = vi.fn(() => "poe");
49+const runtimeLoaded = vi.fn();
50+51+vi.doMock("./models-cli.runtime.js", () => {
52+runtimeLoaded();
53+return {
54+ defaultRuntime,
55+rejectAgentScopedModelWrite: vi.fn(),
56+ resolveModelAgentOption,
57+ runModelsCommand,
58+};
59+});
60+vi.doMock("../commands/models/list.status-command.js", () => ({
61+ modelsStatusCommand,
62+}));
63+64+const { registerModelsCli } = await import("./models-cli.js");
65+const program = new Command();
66+registerModelsCli(program);
67+68+await program.parseAsync(["models", "status", "--json"], { from: "user" });
69+70+expect(runtimeLoaded).toHaveBeenCalledTimes(1);
71+expect(runModelsCommand).toHaveBeenCalledTimes(1);
72+expect(modelsStatusCommand).toHaveBeenCalledWith(
73+expect.objectContaining({ agent: "poe", json: true }),
74+defaultRuntime,
75+);
76+});
77+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。