
























@@ -78,6 +78,22 @@ function requireRecord(value: unknown): Record<string, unknown> {
7878return value as Record<string, unknown>;
7979}
808081+function firstRespondCall(
82+opts: GatewayRequestHandlerOptions & { respond: ReturnType<typeof vi.fn> },
83+) {
84+return opts.respond.mock.calls.at(0);
85+}
86+87+function firstEnsureAuthProfileStoreCall() {
88+return mocks.ensureAuthProfileStore.mock.calls.at(0);
89+}
90+91+function firstBuildAuthHealthSummaryCall() {
92+return mocks.buildAuthHealthSummary.mock.calls.at(0) as unknown as
93+| [{ providers?: string[] }]
94+| undefined;
95+}
96+8197function createOpenAiCodexOauthHealthSummary(): AuthHealthSummary {
8298const profile = {
8399profileId: "openai-codex:default",
@@ -127,7 +143,7 @@ describe("models.authStatus", () => {
127143await handler(opts);
128144129145expect(opts.respond).toHaveBeenCalledTimes(1);
130-const [ok, payload, error] = opts.respond.mock.calls[0] ?? [];
146+const [ok, payload, error] = firstRespondCall(opts) ?? [];
131147expect(ok).toBe(true);
132148expect(error).toBeUndefined();
133149const result = payload as ModelAuthStatusResult;
@@ -230,8 +246,8 @@ describe("models.authStatus", () => {
230246await handler(createOptions());
231247232248expect(mocks.ensureAuthProfileStore).toHaveBeenCalledTimes(1);
233-expect(mocks.ensureAuthProfileStore.mock.calls[0]?.[0]).toBe("/tmp/agent");
234-const [, options] = mocks.ensureAuthProfileStore.mock.calls[0] ?? [];
249+expect(firstEnsureAuthProfileStoreCall()?.[0]).toBe("/tmp/agent");
250+const [, options] = firstEnsureAuthProfileStoreCall() ?? [];
235251const externalCli = requireRecord(requireRecord(options).externalCli);
236252expect(externalCli.mode).toBe("scoped");
237253expect(externalCli.allowKeychainPrompt).toBe(false);
@@ -245,8 +261,8 @@ describe("models.authStatus", () => {
245261await handler(createOptions());
246262247263expect(mocks.ensureAuthProfileStore).toHaveBeenCalledTimes(1);
248-expect(mocks.ensureAuthProfileStore.mock.calls[0]?.[0]).toBe("/tmp/agent");
249-const [, options] = mocks.ensureAuthProfileStore.mock.calls[0] ?? [];
264+expect(firstEnsureAuthProfileStoreCall()?.[0]).toBe("/tmp/agent");
265+const [, options] = firstEnsureAuthProfileStoreCall() ?? [];
250266const externalCli = requireRecord(requireRecord(options).externalCli);
251267expect(externalCli.mode).toBe("none");
252268expect(externalCli.allowKeychainPrompt).toBe(false);
@@ -260,7 +276,7 @@ describe("models.authStatus", () => {
260276const opts = createOptions();
261277await handler(opts);
262278263-const [ok, payload] = opts.respond.mock.calls[0] ?? [];
279+const [ok, payload] = firstRespondCall(opts) ?? [];
264280expect(ok).toBe(true);
265281const result = payload as ModelAuthStatusResult;
266282expect(result.providers).toHaveLength(1);
@@ -313,7 +329,7 @@ describe("models.authStatus", () => {
313329314330const opts = createOptions();
315331await handler(opts);
316-const [, payload] = opts.respond.mock.calls[0] ?? [];
332+const [, payload] = firstRespondCall(opts) ?? [];
317333const serialised = JSON.stringify(payload);
318334expect(serialised).not.toContain("sk-SECRET-TOKEN");
319335expect(serialised).not.toContain("rt-SECRET-REFRESH");
@@ -332,9 +348,7 @@ describe("models.authStatus", () => {
332348},
333349});
334350await handler(createOptions());
335-const call = mocks.buildAuthHealthSummary.mock.calls[0] as unknown as
336-| [{ providers?: string[] }]
337-| undefined;
351+const call = firstBuildAuthHealthSummaryCall();
338352expect(call?.[0]?.providers).toBeUndefined();
339353});
340354@@ -359,9 +373,7 @@ describe("models.authStatus", () => {
359373},
360374});
361375await handler(createOptions());
362-const call = mocks.buildAuthHealthSummary.mock.calls[0] as unknown as
363-| [{ providers?: string[] }]
364-| undefined;
376+const call = firstBuildAuthHealthSummaryCall();
365377expect(call?.[0]?.providers).toEqual(["openai-codex"]);
366378});
367379@@ -383,9 +395,7 @@ describe("models.authStatus", () => {
383395});
384396try {
385397await handler(createOptions());
386-const call = mocks.buildAuthHealthSummary.mock.calls[0] as unknown as
387-| [{ providers?: string[] }]
388-| undefined;
398+const call = firstBuildAuthHealthSummaryCall();
389399expect(call?.[0]?.providers).toBeUndefined();
390400} finally {
391401delete process.env.MODELS_AUTH_STATUS_TEST_SET_KEY;
@@ -410,9 +420,7 @@ describe("models.authStatus", () => {
410420},
411421});
412422await handler(createOptions());
413-const call = mocks.buildAuthHealthSummary.mock.calls[0] as unknown as
414-| [{ providers?: string[] }]
415-| undefined;
423+const call = firstBuildAuthHealthSummaryCall();
416424expect(call?.[0]?.providers).toBeUndefined();
417425});
418426@@ -447,7 +455,7 @@ describe("models.authStatus", () => {
447455});
448456const opts = createOptions();
449457await handler(opts);
450-const [, payload] = opts.respond.mock.calls[0] ?? [];
458+const [, payload] = firstRespondCall(opts) ?? [];
451459const result = payload as ModelAuthStatusResult;
452460expect(result.providers[0]?.status).toBe("missing");
453461});
@@ -482,7 +490,7 @@ describe("models.authStatus", () => {
482490483491const opts = createOptions();
484492await handler(opts);
485-const [, payload] = opts.respond.mock.calls[0] ?? [];
493+const [, payload] = firstRespondCall(opts) ?? [];
486494const result = payload as ModelAuthStatusResult;
487495expect(result.providers[0]?.status).toBe("missing");
488496});
@@ -494,7 +502,7 @@ describe("models.authStatus", () => {
494502495503const opts = createOptions();
496504await handler(opts);
497-const [ok, payload, error] = opts.respond.mock.calls[0] ?? [];
505+const [ok, payload, error] = firstRespondCall(opts) ?? [];
498506expect(ok).toBe(false);
499507expect(payload).toBeUndefined();
500508expect(String(requireRecord(error).code)).toMatch(/unavailable/i);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。