From b2da3e0a0290a60797385b71c1ef1ea85293d53f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 13 May 2026 03:15:02 +0100 Subject: [PATCH] test: dedupe embeddings http mock reads --- src/gateway/embeddings-http.test.ts | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/gateway/embeddings-http.test.ts b/src/gateway/embeddings-http.test.ts index 9cb7581f776..da23b3d6bbf 100644 --- a/src/gateway/embeddings-http.test.ts +++ b/src/gateway/embeddings-http.test.ts @@ -89,6 +89,19 @@ async function postEmbeddings(body: unknown, headers?: Record) { }); } +function latestCreateEmbeddingProviderOptions(): { + agentDir?: string; + model?: string; + provider?: string; +} { + const calls = createEmbeddingProviderMock.mock.calls; + const call = calls[calls.length - 1]; + if (!call) { + throw new Error("expected embedding provider create call"); + } + return call[0]; +} + describe("OpenAI-compatible embeddings HTTP API (e2e)", () => { it("embeds string and array inputs", async () => { const single = await postEmbeddings({ @@ -127,11 +140,9 @@ describe("OpenAI-compatible embeddings HTTP API (e2e)", () => { expect(qualified.status).toBe(200); const qualifiedJson = (await qualified.json()) as { model?: string }; expect(qualifiedJson.model).toBe("openclaw/default"); - const lastCall = createEmbeddingProviderMock.mock.calls.at(-1)?.[0] as - | { provider?: string; model?: string } - | undefined; - expect(lastCall?.provider).toBe("openai"); - expect(lastCall?.model).toBe("text-embedding-3-small"); + const lastCall = latestCreateEmbeddingProviderOptions(); + expect(lastCall.provider).toBe("openai"); + expect(lastCall.model).toBe("text-embedding-3-small"); }); it("supports base64 encoding and agent-scoped auth/config resolution", async () => { @@ -147,11 +158,9 @@ describe("OpenAI-compatible embeddings HTTP API (e2e)", () => { const json = (await res.json()) as { data?: Array<{ embedding?: string }> }; expect(typeof json.data?.[0]?.embedding).toBe("string"); expect(createEmbeddingProviderMock).toHaveBeenCalled(); - const lastCall = createEmbeddingProviderMock.mock.calls.at(-1)?.[0] as - | { provider?: string; model?: string; agentDir?: string } - | undefined; - expect(typeof lastCall?.model).toBe("string"); - expect(lastCall?.agentDir).toBe(resolveAgentDir({}, "beta")); + const lastCall = latestCreateEmbeddingProviderOptions(); + expect(typeof lastCall.model).toBe("string"); + expect(lastCall.agentDir).toBe(resolveAgentDir({}, "beta")); }); it("rejects invalid input shapes", async () => {