

























@@ -46,6 +46,14 @@ function mockEmbeddingFetch(embedding: number[]) {
4646return fetchMock;
4747}
484849+function firstFetchInit(fetchMock: ReturnType<typeof mockEmbeddingFetch>): RequestInit | undefined {
50+const call = fetchMock.mock.calls.at(0);
51+if (!call) {
52+throw new Error("expected embedding fetch call");
53+}
54+return call.at(1) as RequestInit | undefined;
55+}
56+4957function readEmbeddingRequestBody(init: RequestInit | undefined): { input?: unknown } {
5058if (typeof init?.body !== "string") {
5159throw new Error("expected JSON string request body");
@@ -54,7 +62,7 @@ function readEmbeddingRequestBody(init: RequestInit | undefined): { input?: unkn
5462}
55635664function readFirstEmbeddingInput(fetchMock: ReturnType<typeof mockEmbeddingFetch>): unknown {
57-const [, init] = (fetchMock.mock.calls[0] ?? []) as unknown as [string, RequestInit | undefined];
65+const init = firstFetchInit(fetchMock);
5866const body = readEmbeddingRequestBody(init);
5967return body.input;
6068}
@@ -379,10 +387,7 @@ describe("ollama embedding provider", () => {
379387380388await provider.embedQuery("hello");
381389382-const [, init] = (fetchMock.mock.calls[0] ?? []) as unknown as [
383-string,
384-RequestInit | undefined,
385-];
390+const init = firstFetchInit(fetchMock);
386391const headers = init?.headers as Record<string, string> | undefined;
387392expect(headers?.Authorization).toBeUndefined();
388393});
@@ -433,10 +438,7 @@ describe("ollama embedding provider", () => {
433438434439await provider.embedQuery("hello");
435440436-const [, init] = (fetchMock.mock.calls[0] ?? []) as unknown as [
437-string,
438-RequestInit | undefined,
439-];
441+const init = firstFetchInit(fetchMock);
440442const headers = init?.headers as Record<string, string> | undefined;
441443expect(headers?.Authorization).toBeUndefined();
442444});
@@ -486,10 +488,7 @@ describe("ollama embedding provider", () => {
486488487489await provider.embedQuery("hello");
488490489-const [, init] = (fetchMock.mock.calls[0] ?? []) as unknown as [
490-string,
491-RequestInit | undefined,
492-];
491+const init = firstFetchInit(fetchMock);
493492const headers = init?.headers as Record<string, string> | undefined;
494493expect(headers?.Authorization).toBeUndefined();
495494});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。