























@@ -159,13 +159,38 @@ function makeRuntime() {
159159};
160160}
161161162+function firstMockArg(mockFn: ReturnType<typeof vi.fn>, label: string): unknown {
163+const call = mockFn.mock.calls.at(0);
164+if (!call) {
165+throw new Error(`Expected ${label} call`);
166+}
167+return call.at(0);
168+}
169+170+function runtimeLogText(runtime: ReturnType<typeof makeRuntime>): string {
171+const value = firstMockArg(runtime.log, "runtime.log");
172+if (typeof value !== "string") {
173+throw new Error("Expected runtime.log text");
174+}
175+return value;
176+}
177+178+function runtimeErrorText(runtime: ReturnType<typeof makeRuntime>): string {
179+const value = firstMockArg(runtime.error, "runtime.error");
180+if (typeof value !== "string") {
181+throw new Error("Expected runtime.error text");
182+}
183+return value;
184+}
185+162186function expectModelRegistryUnavailable(
163187runtime: ReturnType<typeof makeRuntime>,
164188expectedDetail: string,
165189) {
166190expect(runtime.error).toHaveBeenCalledTimes(1);
167-expect(runtime.error.mock.calls[0]?.[0]).toContain("Model registry unavailable:");
168-expect(runtime.error.mock.calls[0]?.[0]).toContain(expectedDetail);
191+const errorText = runtimeErrorText(runtime);
192+expect(errorText).toContain("Model registry unavailable:");
193+expect(errorText).toContain(expectedDetail);
169194expect(runtime.log).not.toHaveBeenCalled();
170195expect(process.exitCode).toBe(1);
171196}
@@ -312,7 +337,7 @@ describe("models list/status", () => {
312337313338function parseJsonLog(runtime: ReturnType<typeof makeRuntime>) {
314339expect(runtime.log).toHaveBeenCalledTimes(1);
315-return JSON.parse(String(runtime.log.mock.calls[0]?.[0]));
340+return JSON.parse(runtimeLogText(runtime));
316341}
317342318343async function expectZaiProviderFilter(provider: string) {
@@ -397,7 +422,7 @@ describe("models list/status", () => {
397422await modelsListCommand({ plain: true }, runtime);
398423399424expect(runtime.log).toHaveBeenCalledTimes(1);
400-expect(runtime.log.mock.calls[0]?.[0]).toBe("zai/glm-4.7");
425+expect(runtimeLogText(runtime)).toBe("zai/glm-4.7");
401426});
402427403428it("models list plain keeps canonical OpenRouter native ids", async () => {
@@ -420,7 +445,7 @@ describe("models list/status", () => {
420445await modelsListCommand({ plain: true }, runtime);
421446422447expect(runtime.log).toHaveBeenCalledTimes(1);
423-expect(runtime.log.mock.calls[0]?.[0]).toBe("openrouter/hunter-alpha");
448+expect(runtimeLogText(runtime)).toBe("openrouter/hunter-alpha");
424449});
425450426451it.each(["z.ai", "Z.AI", "z-ai"] as const)(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。