fix(regression): auto-enable memory runtime loads

This commit is contained in:
Tak Hoffman
2026-03-27 22:44:03 -05:00
parent 2ba5e7ebf9
commit 63e35b2d9d
2 changed files with 103 additions and 1 deletions

View File

@@ -0,0 +1,100 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
const loadOpenClawPluginsMock = vi.fn();
const applyPluginAutoEnableMock = vi.fn();
const getMemoryRuntimeMock = vi.fn();
vi.mock("../config/plugin-auto-enable.js", () => ({
applyPluginAutoEnable: (...args: unknown[]) => applyPluginAutoEnableMock(...args),
}));
vi.mock("./loader.js", () => ({
loadOpenClawPlugins: (...args: unknown[]) => loadOpenClawPluginsMock(...args),
}));
vi.mock("./memory-state.js", () => ({
getMemoryRuntime: () => getMemoryRuntimeMock(),
}));
let getActiveMemorySearchManager: typeof import("./memory-runtime.js").getActiveMemorySearchManager;
let resolveActiveMemoryBackendConfig: typeof import("./memory-runtime.js").resolveActiveMemoryBackendConfig;
describe("memory runtime auto-enable loading", () => {
beforeEach(async () => {
vi.resetModules();
loadOpenClawPluginsMock.mockReset();
applyPluginAutoEnableMock.mockReset();
getMemoryRuntimeMock.mockReset();
applyPluginAutoEnableMock.mockImplementation((params: { config: unknown }) => ({
config: params.config,
changes: [],
}));
({ getActiveMemorySearchManager, resolveActiveMemoryBackendConfig } =
await import("./memory-runtime.js"));
});
it("loads memory runtime from the auto-enabled config snapshot", async () => {
const rawConfig = {
plugins: {},
channels: { memory: { enabled: true } },
};
const autoEnabledConfig = {
...rawConfig,
plugins: {
entries: {
memory: { enabled: true },
},
},
};
const runtime = {
getMemorySearchManager: vi.fn(async () => ({ manager: null, error: "no index" })),
resolveMemoryBackendConfig: vi.fn(() => ({ backend: "builtin" as const })),
};
applyPluginAutoEnableMock.mockReturnValue({ config: autoEnabledConfig, changes: [] });
getMemoryRuntimeMock.mockReturnValueOnce(undefined).mockReturnValue(runtime);
await getActiveMemorySearchManager({
cfg: rawConfig as never,
agentId: "main",
});
expect(applyPluginAutoEnableMock).toHaveBeenCalledWith({
config: rawConfig,
env: process.env,
});
expect(loadOpenClawPluginsMock).toHaveBeenCalledWith({
config: autoEnabledConfig,
});
});
it("reuses the same auto-enabled load path for backend config resolution", () => {
const rawConfig = {
plugins: {},
channels: { memory: { enabled: true } },
};
const autoEnabledConfig = {
...rawConfig,
plugins: {
entries: {
memory: { enabled: true },
},
},
};
const runtime = {
getMemorySearchManager: vi.fn(async () => ({ manager: null })),
resolveMemoryBackendConfig: vi.fn(() => ({ backend: "builtin" as const })),
};
applyPluginAutoEnableMock.mockReturnValue({ config: autoEnabledConfig, changes: [] });
getMemoryRuntimeMock.mockReturnValueOnce(undefined).mockReturnValue(runtime);
const result = resolveActiveMemoryBackendConfig({
cfg: rawConfig as never,
agentId: "main",
});
expect(result).toEqual({ backend: "builtin" });
expect(loadOpenClawPluginsMock).toHaveBeenCalledWith({
config: autoEnabledConfig,
});
});
});

View File

@@ -1,4 +1,5 @@
import type { OpenClawConfig } from "../config/config.js";
import { applyPluginAutoEnable } from "../config/plugin-auto-enable.js";
import { loadOpenClawPlugins } from "./loader.js";
import { getMemoryRuntime } from "./memory-state.js";
@@ -7,7 +8,8 @@ function ensureMemoryRuntime(cfg?: OpenClawConfig) {
if (current || !cfg) {
return current;
}
loadOpenClawPlugins({ config: cfg });
const resolvedConfig = applyPluginAutoEnable({ config: cfg, env: process.env }).config;
loadOpenClawPlugins({ config: resolvedConfig });
return getMemoryRuntime();
}