

















@@ -48,12 +48,23 @@ type AuthRequestCall = {
4848store?: unknown;
4949};
505051-function requireFirstMockCall(mock: { mock: { calls: unknown[][] } }, label: string): unknown[] {
52-const [call] = mock.mock.calls;
51+function requireMockCallAt<const Calls extends readonly unknown[][]>(
52+mock: { mock: { calls: Calls } },
53+index: number,
54+label: string,
55+): Calls[number] {
56+const call = mock.mock.calls.at(index);
5357if (!call) {
54-throw new Error(`Expected ${label} call`);
58+throw new Error(`Expected ${label} call ${index}`);
5559}
56-return call;
60+return call as Calls[number];
61+}
62+63+function requireFirstMockCall<const Calls extends readonly unknown[][]>(
64+mock: { mock: { calls: Calls } },
65+label: string,
66+): Calls[number] {
67+return requireMockCallAt(mock, 0, label);
5768}
58695970function requireRecord(value: unknown, label: string): Record<string, unknown> {
@@ -163,7 +174,7 @@ describe("describeImageWithModel", () => {
163174});
164175165176function getApiKeyForModelCall(index = 0): AuthRequestCall {
166-const call = (getApiKeyForModelMock.mock.calls as unknown[][])[index];
177+const call = (getApiKeyForModelMock.mock.calls as unknown[][]).at(index);
167178if (!call) {
168179throw new Error(`Expected getApiKeyForModel call ${index}`);
169180}
@@ -415,10 +426,7 @@ describe("describeImageWithModel", () => {
415426model: "gpt-5.4",
416427});
417428expect(completeMock).toHaveBeenCalledOnce();
418-const firstCall = completeMock.mock.calls[0];
419-if (!firstCall) {
420-throw new Error("Expected image completion call");
421-}
429+const firstCall = requireFirstMockCall(completeMock, "image completion");
422430const [completionModel, context, options] = firstCall;
423431expect(completionModel).toEqual({
424432provider: "openai-codex",
@@ -483,10 +491,7 @@ describe("describeImageWithModel", () => {
483491text: "openrouter ok",
484492model: "google/gemini-2.5-flash",
485493});
486-const firstCall = completeMock.mock.calls[0];
487-if (!firstCall) {
488-throw new Error("Expected OpenRouter image completion call");
489-}
494+const firstCall = requireFirstMockCall(completeMock, "OpenRouter image completion");
490495const [, context] = firstCall;
491496expect(context.systemPrompt).toBeUndefined();
492497const userMessage = context.messages[0];
@@ -606,10 +611,7 @@ describe("describeImageWithModel", () => {
606611model: model.id,
607612});
608613expect(completeMock).toHaveBeenCalledTimes(2);
609-const retryCall = completeMock.mock.calls[1];
610-if (!retryCall) {
611-throw new Error("Expected retry image completion call");
612-}
614+const retryCall = requireMockCallAt(completeMock, 1, "retry image completion");
613615const [retryModel, , retryOptions] = retryCall;
614616if (!retryOptions?.onPayload) {
615617throw new Error("expected retry payload mapper");
@@ -654,10 +656,7 @@ describe("describeImageWithModel", () => {
654656const assertion = expect(result).rejects.toThrow("image description timed out after 25ms");
655657await vi.advanceTimersByTimeAsync(25);
656658await assertion;
657-const firstCall = completeMock.mock.calls[0];
658-if (!firstCall) {
659-throw new Error("Expected timed image completion call");
660-}
659+const firstCall = requireFirstMockCall(completeMock, "timed image completion");
661660const [, , options] = firstCall;
662661if (!options?.signal) {
663662throw new Error("Expected image completion abort signal");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。