From ee4e8038f9adebe04721902d5df9d0b3d66d6474 Mon Sep 17 00:00:00 2001 From: Vincent Koc <25068+vincentkoc@users.noreply.github.com> Date: Fri, 10 Jul 2026 22:03:18 -0700 Subject: [PATCH] test(gateway): cover embedding local service injection --- src/gateway/embeddings-http.test.ts | 60 ++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/src/gateway/embeddings-http.test.ts b/src/gateway/embeddings-http.test.ts index db4bfdb4e9df..6765e75c620e 100644 --- a/src/gateway/embeddings-http.test.ts +++ b/src/gateway/embeddings-http.test.ts @@ -18,7 +18,12 @@ const WRITE_SCOPE_HEADER = { "x-openclaw-scopes": "operator.write" }; let startGatewayServer: typeof import("./server.js").startGatewayServer; let createEmbeddingProviderMock: ReturnType< typeof vi.fn< - (options: { provider: string; model: string; agentDir?: string }) => Promise<{ + (options: { + provider: string; + model: string; + agentDir?: string; + acquireLocalService?: unknown; + }) => Promise<{ provider: { id: string; model: string; @@ -125,10 +130,14 @@ beforeAll(async () => { autoSelectPriority: 20, allowExplicitWhenConfiguredAuto: true, create: async (options) => { + const localServiceOptions = options as typeof options & { + acquireLocalService?: unknown; + }; const result = await createEmbeddingProviderMock({ - provider: "openai", + provider: options.provider ?? "openai", model: options.model, agentDir: options.agentDir, + acquireLocalService: localServiceOptions.acquireLocalService, }); return result; }, @@ -220,6 +229,7 @@ function latestCreateEmbeddingProviderOptions(): { agentDir?: string; model?: string; provider?: string; + acquireLocalService?: unknown; } { const calls = createEmbeddingProviderMock.mock.calls; const call = calls[calls.length - 1]; @@ -303,6 +313,52 @@ describe("OpenAI-compatible embeddings HTTP API (e2e)", () => { } }); + it("passes provider aliases and local-service acquisition to memory adapters", async () => { + const configPath = createConfigIO().configPath; + await fs.mkdir(path.dirname(configPath), { recursive: true }); + await fs.writeFile( + configPath, + `${JSON.stringify( + { + models: { + providers: { + "tenant-embeddings": { + api: "openai", + baseUrl: genericEmbeddingBaseUrl, + models: [], + }, + }, + }, + }, + null, + 2, + )}\n`, + "utf-8", + ); + try { + testState.agentConfig = { + memorySearch: { + provider: "tenant-embeddings", + model: "tenant-embeddings/nomic-embed-text", + }, + }; + resetConfigRuntimeState(); + + const res = await postEmbeddings({ + model: "openclaw/default", + input: "hello", + }); + await expectDefaultEmbeddingResponse(res); + const lastCall = latestCreateEmbeddingProviderOptions(); + expect(lastCall.provider).toBe("tenant-embeddings"); + expect(lastCall.model).toBe("nomic-embed-text"); + expect(lastCall.acquireLocalService).toEqual(expect.any(Function)); + } finally { + testState.agentConfig = undefined; + resetConfigRuntimeState(); + } + }); + it("rejects explicit unknown agent ids", async () => { try { testState.agentsConfig = { list: [{ id: "main" }, { id: "beta" }] };