From a8fde89a2ec4abcf342382138021e6281e5ec872 Mon Sep 17 00:00:00 2001 From: Jari Mustonen Date: Wed, 18 Mar 2026 10:37:42 +0200 Subject: [PATCH] fix(memory): reset memory prompt section on plugin cache clear --- src/memory/prompt-section.test.ts | 14 +++++++++++++- src/plugins/loader.test.ts | 19 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/memory/prompt-section.test.ts b/src/memory/prompt-section.test.ts index b537447b844..53a19d1861e 100644 --- a/src/memory/prompt-section.test.ts +++ b/src/memory/prompt-section.test.ts @@ -2,6 +2,7 @@ import { describe, it, expect, beforeEach } from "vitest"; import { registerMemoryPromptSection, buildMemoryPromptSection, + clearMemoryPromptSection, _resetMemoryPromptSection, } from "./prompt-section.js"; @@ -19,7 +20,9 @@ describe("memory prompt section registry", () => { it("delegates to the registered builder", () => { registerMemoryPromptSection(({ availableTools }) => { - if (!availableTools.has("memory_search")) return []; + if (!availableTools.has("memory_search")) { + return []; + } return ["## Custom Memory", "Use custom memory tools.", ""]; }); @@ -49,4 +52,13 @@ describe("memory prompt section registry", () => { const result = buildMemoryPromptSection({ availableTools: new Set() }); expect(result).toEqual(["second"]); }); + + it("clearMemoryPromptSection resets the builder", () => { + registerMemoryPromptSection(() => ["stale section"]); + expect(buildMemoryPromptSection({ availableTools: new Set() })).toEqual(["stale section"]); + + clearMemoryPromptSection(); + + expect(buildMemoryPromptSection({ availableTools: new Set() })).toEqual([]); + }); }); diff --git a/src/plugins/loader.test.ts b/src/plugins/loader.test.ts index a4bf12fad15..0336f2fb14d 100644 --- a/src/plugins/loader.test.ts +++ b/src/plugins/loader.test.ts @@ -22,12 +22,13 @@ async function importFreshPluginTestModules() { vi.doUnmock("./hooks.js"); vi.doUnmock("./loader.js"); vi.doUnmock("jiti"); - const [loader, hookRunnerGlobal, hooks, runtime, registry] = await Promise.all([ + const [loader, hookRunnerGlobal, hooks, runtime, registry, promptSection] = await Promise.all([ import("./loader.js"), import("./hook-runner-global.js"), import("./hooks.js"), import("./runtime.js"), import("./registry.js"), + import("../memory/prompt-section.js"), ]); return { ...loader, @@ -35,11 +36,13 @@ async function importFreshPluginTestModules() { ...hooks, ...runtime, ...registry, + ...promptSection, }; } const { __testing, + buildMemoryPromptSection, clearPluginLoaderCache, createHookRunner, createEmptyPluginRegistry, @@ -47,6 +50,7 @@ const { getActivePluginRegistryKey, getGlobalHookRunner, loadOpenClawPlugins, + registerMemoryPromptSection, resetGlobalHookRunner, setActivePluginRegistry, } = await importFreshPluginTestModules(); @@ -3674,3 +3678,16 @@ export const runtimeValue = helperValue;`, expect(resolved).toBe(expected === "dist" ? fixture.distFile : fixture.srcFile); }); }); + +describe("clearPluginLoaderCache", () => { + it("resets the registered memory prompt section builder", () => { + registerMemoryPromptSection(() => ["stale memory section"]); + expect(buildMemoryPromptSection({ availableTools: new Set() })).toEqual([ + "stale memory section", + ]); + + clearPluginLoaderCache(); + + expect(buildMemoryPromptSection({ availableTools: new Set() })).toEqual([]); + }); +});