Skip to content

Commit a130dd0

Browse files
committed
test: tighten image completion call assertions
1 parent 8f30e37 commit a130dd0

1 file changed

Lines changed: 29 additions & 10 deletions

File tree

src/media-understanding/image.test.ts

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,12 @@ describe("describeImageWithModel", () => {
382382
}),
383383
expect.any(Object),
384384
);
385-
const [, context] = completeMock.mock.calls[0] ?? [];
386-
expect(context?.messages?.[0]?.content).toHaveLength(1);
385+
const firstCall = completeMock.mock.calls[0];
386+
if (!firstCall) {
387+
throw new Error("Expected image completion call");
388+
}
389+
const [, context] = firstCall;
390+
expect(context.messages[0]?.content).toHaveLength(1);
387391
});
388392

389393
it("places OpenRouter image prompts in user content before images", async () => {
@@ -422,9 +426,13 @@ describe("describeImageWithModel", () => {
422426
text: "openrouter ok",
423427
model: "google/gemini-2.5-flash",
424428
});
425-
const [, context] = completeMock.mock.calls[0] ?? [];
426-
expect(context?.systemPrompt).toBeUndefined();
427-
expect(context?.messages?.[0]?.content).toEqual([
429+
const firstCall = completeMock.mock.calls[0];
430+
if (!firstCall) {
431+
throw new Error("Expected OpenRouter image completion call");
432+
}
433+
const [, context] = firstCall;
434+
expect(context.systemPrompt).toBeUndefined();
435+
expect(context.messages[0]?.content).toEqual([
428436
{ type: "text", text: "Describe the image." },
429437
expect.objectContaining({
430438
type: "image",
@@ -536,7 +544,11 @@ describe("describeImageWithModel", () => {
536544
model: model.id,
537545
});
538546
expect(completeMock).toHaveBeenCalledTimes(2);
539-
const [, , retryOptions] = completeMock.mock.calls[1] ?? [];
547+
const retryCall = completeMock.mock.calls[1];
548+
if (!retryCall) {
549+
throw new Error("Expected retry image completion call");
550+
}
551+
const [retryModel, , retryOptions] = retryCall;
540552
if (!retryOptions?.onPayload) {
541553
throw new Error("expected retry payload mapper");
542554
}
@@ -546,7 +558,7 @@ describe("describeImageWithModel", () => {
546558
reasoning_effort: "high",
547559
include: ["reasoning.encrypted_content"],
548560
},
549-
completeMock.mock.calls[1]?.[0],
561+
retryModel,
550562
);
551563
expect(retryPayload).toEqual(expectedRetryPayload);
552564
},
@@ -580,9 +592,16 @@ describe("describeImageWithModel", () => {
580592
const assertion = expect(result).rejects.toThrow("image description timed out after 25ms");
581593
await vi.advanceTimersByTimeAsync(25);
582594
await assertion;
583-
const [, , options] = completeMock.mock.calls[0] ?? [];
584-
expect(options?.signal?.aborted).toBe(true);
585-
expect(options?.timeoutMs).toBe(25);
595+
const firstCall = completeMock.mock.calls[0];
596+
if (!firstCall) {
597+
throw new Error("Expected timed image completion call");
598+
}
599+
const [, , options] = firstCall;
600+
if (!options?.signal) {
601+
throw new Error("Expected image completion abort signal");
602+
}
603+
expect(options.signal.aborted).toBe(true);
604+
expect(options.timeoutMs).toBe(25);
586605
});
587606

588607
it("rejects when image runtime setup exceeds the request timeout", async () => {

0 commit comments

Comments
 (0)