Skip to content

Commit 2b90978

Browse files
author
NIO
committed
fix(google): repair embedding-batch test types and lint
1 parent 3b4fa7d commit 2b90978

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

‎extensions/google/embedding-batch.test.ts‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Google tests cover embedding batch bounded JSON response reads.
22
import { afterEach, describe, expect, it, vi } from "vitest";
33
import { runGeminiEmbeddingBatches } from "./embedding-batch.js";
4+
import type { GeminiEmbeddingClient } from "./embedding-provider.js";
45

56
// Pass-through so onResponse receives real Response objects (required by
67
// readProviderJsonResponse which needs a real .body ReadableStream).
@@ -27,8 +28,12 @@ afterEach(() => {
2728
});
2829

2930
function fetchInputUrl(input: RequestInfo | URL): string {
30-
if (typeof input === "string") return input;
31-
if (input instanceof URL) return input.href;
31+
if (typeof input === "string") {
32+
return input;
33+
}
34+
if (input instanceof URL) {
35+
return input.href;
36+
}
3237
return input.url;
3338
}
3439

@@ -39,11 +44,13 @@ function jsonResponse(body: unknown, status = 200): Response {
3944
});
4045
}
4146

42-
function makeGeminiClient() {
47+
function makeGeminiClient(): GeminiEmbeddingClient {
4348
return {
4449
baseUrl: "https://gemini-compatible.example/v1beta",
50+
model: "text-embedding-004",
4551
modelPath: "models/text-embedding-004",
4652
headers: { "x-goog-api-key": "test-key" },
53+
apiKeys: ["test-key"],
4754
ssrfPolicy: undefined,
4855
};
4956
}
@@ -57,6 +64,7 @@ function singleRequest(): GeminiBatchRequest[] {
5764
request: {
5865
model: "models/text-embedding-004",
5966
content: { parts: [{ text: "hello" }] },
67+
taskType: "RETRIEVAL_DOCUMENT",
6068
},
6169
},
6270
];
@@ -99,7 +107,9 @@ describe("Google embedding-batch bounded JSON reads", () => {
99107
vi.stubGlobal(
100108
"fetch",
101109
vi.fn(async (input: RequestInfo | URL) => {
102-
if (fetchInputUrl(input).includes("/upload/")) return streamed.response;
110+
if (fetchInputUrl(input).includes("/upload/")) {
111+
return streamed.response;
112+
}
103113
return new Response("unexpected", { status: 500 });
104114
}),
105115
);
@@ -126,8 +136,12 @@ describe("Google embedding-batch bounded JSON reads", () => {
126136
"fetch",
127137
vi.fn(async (input: RequestInfo | URL) => {
128138
const url = fetchInputUrl(input);
129-
if (url.includes("/upload/")) return jsonResponse({ name: "files/f-ok" });
130-
if (url.includes(":asyncBatchEmbedContent")) return streamed.response;
139+
if (url.includes("/upload/")) {
140+
return jsonResponse({ name: "files/f-ok" });
141+
}
142+
if (url.includes(":asyncBatchEmbedContent")) {
143+
return streamed.response;
144+
}
131145
return new Response("unexpected", { status: 500 });
132146
}),
133147
);
@@ -155,7 +169,9 @@ describe("Google embedding-batch bounded JSON reads", () => {
155169
"fetch",
156170
vi.fn(async (input: RequestInfo | URL) => {
157171
const url = fetchInputUrl(input);
158-
if (url.includes("/upload/")) return jsonResponse({ name: "files/f-ok" });
172+
if (url.includes("/upload/")) {
173+
return jsonResponse({ name: "files/f-ok" });
174+
}
159175
if (url.includes(":asyncBatchEmbedContent")) {
160176
return jsonResponse({ name: "batches/b-0", state: "PENDING" });
161177
}
@@ -194,7 +210,9 @@ describe("Google embedding-batch bounded JSON reads", () => {
194210
"fetch",
195211
vi.fn(async (input: RequestInfo | URL) => {
196212
const url = fetchInputUrl(input);
197-
if (url.includes("/upload/")) return jsonResponse({ name: "files/f-ok" });
213+
if (url.includes("/upload/")) {
214+
return jsonResponse({ name: "files/f-ok" });
215+
}
198216
if (url.includes(":asyncBatchEmbedContent")) {
199217
return jsonResponse({ name: "batches/b-0", state: "PENDING" });
200218
}

0 commit comments

Comments
 (0)