From fc84dd398bf633844197d7ef9be9665a22d2157d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 28 Mar 2026 04:43:25 +0000 Subject: [PATCH] test: dedupe plugin runtime registry suites --- .../memory-embedding-providers.test.ts | 24 ++++++-- src/plugins/memory-runtime.test.ts | 57 +++++++++++-------- src/plugins/runtime.channel-pin.test.ts | 17 ++++-- src/plugins/runtime.test.ts | 17 ++++-- 4 files changed, 75 insertions(+), 40 deletions(-) diff --git a/src/plugins/memory-embedding-providers.test.ts b/src/plugins/memory-embedding-providers.test.ts index 5917a76f4bd..9a7c9628883 100644 --- a/src/plugins/memory-embedding-providers.test.ts +++ b/src/plugins/memory-embedding-providers.test.ts @@ -57,17 +57,33 @@ function expectMemoryEmbeddingProviderIds(expectedIds: readonly string[]) { expect(listMemoryEmbeddingProviders().map((adapter) => adapter.id)).toEqual([...expectedIds]); } +function expectMemoryEmbeddingProviderState(params: { + expectedIds: readonly string[]; + expectedCurrent?: { id: string; adapter: MemoryEmbeddingProviderAdapter }; +}) { + if (params.expectedCurrent) { + expect(getMemoryEmbeddingProvider(params.expectedCurrent.id)).toBe( + params.expectedCurrent.adapter, + ); + } + expectMemoryEmbeddingProviderIds(params.expectedIds); +} + afterEach(() => { clearMemoryEmbeddingProviders(); }); describe("memory embedding provider registry", () => { it("registers and lists adapters in insertion order", () => { - registerMemoryEmbeddingProvider(createAdapter("alpha")); - registerMemoryEmbeddingProvider(createAdapter("beta")); + const alpha = createAdapter("alpha"); + const beta = createAdapter("beta"); + registerMemoryEmbeddingProvider(alpha); + registerMemoryEmbeddingProvider(beta); - expect(getMemoryEmbeddingProvider("alpha")?.id).toBe("alpha"); - expectMemoryEmbeddingProviderIds(["alpha", "beta"]); + expectMemoryEmbeddingProviderState({ + expectedIds: ["alpha", "beta"], + expectedCurrent: { id: "alpha", adapter: alpha }, + }); }); it("restores a previous snapshot", () => { diff --git a/src/plugins/memory-runtime.test.ts b/src/plugins/memory-runtime.test.ts index 1296e77feeb..058883a42a0 100644 --- a/src/plugins/memory-runtime.test.ts +++ b/src/plugins/memory-runtime.test.ts @@ -49,6 +49,14 @@ function expectMemoryRuntimeLoaded(autoEnabledConfig: unknown) { }); } +function setAutoEnabledMemoryRuntime() { + const { rawConfig, autoEnabledConfig } = createMemoryAutoEnableFixture(); + const runtime = createMemoryRuntimeFixture(); + applyPluginAutoEnableMock.mockReturnValue({ config: autoEnabledConfig, changes: [] }); + getMemoryRuntimeMock.mockReturnValueOnce(undefined).mockReturnValue(runtime); + return { rawConfig, autoEnabledConfig, runtime }; +} + describe("memory runtime auto-enable loading", () => { beforeEach(async () => { vi.resetModules(); @@ -66,17 +74,33 @@ describe("memory runtime auto-enable loading", () => { } = await import("./memory-runtime.js")); }); - it("loads memory runtime from the auto-enabled config snapshot", async () => { - const { rawConfig, autoEnabledConfig } = createMemoryAutoEnableFixture(); - const runtime = createMemoryRuntimeFixture(); - applyPluginAutoEnableMock.mockReturnValue({ config: autoEnabledConfig, changes: [] }); - getMemoryRuntimeMock.mockReturnValueOnce(undefined).mockReturnValue(runtime); + it.each([ + { + name: "loads memory runtime from the auto-enabled config snapshot", + run: async (rawConfig: unknown) => + getActiveMemorySearchManager({ + cfg: rawConfig as never, + agentId: "main", + }), + expectedResult: undefined, + }, + { + name: "reuses the same auto-enabled load path for backend config resolution", + run: async (rawConfig: unknown) => + resolveActiveMemoryBackendConfig({ + cfg: rawConfig as never, + agentId: "main", + }), + expectedResult: { backend: "builtin" }, + }, + ] as const)("$name", async ({ run, expectedResult }) => { + const { rawConfig, autoEnabledConfig } = setAutoEnabledMemoryRuntime(); - await getActiveMemorySearchManager({ - cfg: rawConfig as never, - agentId: "main", - }); + const result = await run(rawConfig); + if (expectedResult !== undefined) { + expect(result).toEqual(expectedResult); + } expect(applyPluginAutoEnableMock).toHaveBeenCalledWith({ config: rawConfig, env: process.env, @@ -84,21 +108,6 @@ describe("memory runtime auto-enable loading", () => { expectMemoryRuntimeLoaded(autoEnabledConfig); }); - it("reuses the same auto-enabled load path for backend config resolution", () => { - const { rawConfig, autoEnabledConfig } = createMemoryAutoEnableFixture(); - const runtime = createMemoryRuntimeFixture(); - applyPluginAutoEnableMock.mockReturnValue({ config: autoEnabledConfig, changes: [] }); - getMemoryRuntimeMock.mockReturnValueOnce(undefined).mockReturnValue(runtime); - - const result = resolveActiveMemoryBackendConfig({ - cfg: rawConfig as never, - agentId: "main", - }); - - expect(result).toEqual({ backend: "builtin" }); - expectMemoryRuntimeLoaded(autoEnabledConfig); - }); - it("does not bootstrap the memory runtime just to close managers", async () => { const rawConfig = { plugins: {}, diff --git a/src/plugins/runtime.channel-pin.test.ts b/src/plugins/runtime.channel-pin.test.ts index f24a1342e44..2ec3ae17571 100644 --- a/src/plugins/runtime.channel-pin.test.ts +++ b/src/plugins/runtime.channel-pin.test.ts @@ -38,6 +38,16 @@ function expectActiveChannelRegistry(registry: ReturnType, + replacementRegistry: ReturnType, +) { + setActivePluginRegistry(startupRegistry); + pinActivePluginChannelRegistry(startupRegistry); + setActivePluginRegistry(replacementRegistry); + expectActiveChannelRegistry(startupRegistry); +} + describe("channel registry pinning", () => { afterEach(() => { resetPluginRuntimeStateForTest(); @@ -51,14 +61,9 @@ describe("channel registry pinning", () => { it("preserves pinned channel registry across setActivePluginRegistry calls", () => { const { registry: startup } = createRegistryWithChannel(); - setActivePluginRegistry(startup); - pinActivePluginChannelRegistry(startup); - // A subsequent registry swap (e.g., config-schema load) must not evict channels. const replacement = createEmptyPluginRegistry(); - setActivePluginRegistry(replacement); - - expectActiveChannelRegistry(startup); + expectPinnedChannelRegistry(startup, replacement); expect(getActivePluginChannelRegistry()!.channels).toHaveLength(1); }); diff --git a/src/plugins/runtime.test.ts b/src/plugins/runtime.test.ts index 8f60aa70d9a..db10218421e 100644 --- a/src/plugins/runtime.test.ts +++ b/src/plugins/runtime.test.ts @@ -49,6 +49,16 @@ function expectActiveRouteRegistryResolution(params: { ); } +function expectPinnedRouteRegistry( + startupRegistry: ReturnType, + laterRegistry: ReturnType, +) { + setActivePluginRegistry(startupRegistry); + pinActivePluginHttpRouteRegistry(startupRegistry); + setActivePluginRegistry(laterRegistry); + expect(resolveActivePluginHttpRouteRegistry(laterRegistry)).toBe(startupRegistry); +} + describe("plugin runtime route registry", () => { afterEach(() => { releasePinnedPluginHttpRouteRegistry(); @@ -63,12 +73,7 @@ describe("plugin runtime route registry", () => { it("keeps the pinned route registry when the active plugin registry changes", () => { const { startupRegistry, laterRegistry } = createRuntimeRegistryPair(); - - setActivePluginRegistry(startupRegistry); - pinActivePluginHttpRouteRegistry(startupRegistry); - setActivePluginRegistry(laterRegistry); - - expect(resolveActivePluginHttpRouteRegistry(laterRegistry)).toBe(startupRegistry); + expectPinnedRouteRegistry(startupRegistry, laterRegistry); }); it("tracks route registry repins separately from the active registry version", () => {