mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-22 22:52:03 +00:00
fix(regression): auto-enable memory runtime loads
This commit is contained in:
100
src/plugins/memory-runtime.test.ts
Normal file
100
src/plugins/memory-runtime.test.ts
Normal 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,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user