fix(memory): reset memory prompt section on plugin cache clear

This commit is contained in:
Jari Mustonen 2026-03-18 10:37:42 +02:00 committed by Josh Lehman
parent df5f2cb77f
commit a8fde89a2e
No known key found for this signature in database
GPG Key ID: D141B425AC7F876B
2 changed files with 31 additions and 2 deletions

View File

@ -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([]);
});
});

View File

@ -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([]);
});
});