Files
openclaw/extensions/memory-core/src/runtime-provider.test.ts
Peter Steinberger e873a7f955 refactor(memory): move QMD coordination to SQLite (#109636)
* refactor(memory): move QMD coordination to SQLite

* chore: keep release notes in PR body

* chore: annotate lease SQLite primitive
2026-07-16 22:01:34 -07:00

101 lines
2.8 KiB
TypeScript

// Memory Core provider tests cover plugin runtime integration.
import type { OpenClawConfig } from "openclaw/plugin-sdk/memory-core-host-runtime-core";
import { describe, expect, it, vi } from "vitest";
const managerDebug = {
backend: "qmd" as const,
purpose: "default" as const,
managerMs: 7,
managerCacheState: "cached-full-hit" as const,
qmdIdentityHash: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
};
const getMemorySearchManagerMock = vi.hoisted(() =>
vi.fn(async () => ({
manager: null,
debug: managerDebug,
error: undefined,
})),
);
vi.mock("./memory/index.js", () => ({
closeAllMemorySearchManagers: vi.fn(async () => {}),
closeMemorySearchManager: vi.fn(async () => {}),
getMemorySearchManager: getMemorySearchManagerMock,
}));
import { createMemoryRuntime, memoryRuntime } from "./runtime-provider.js";
describe("memoryRuntime", () => {
it("preserves manager debug metadata", async () => {
const cfg = {} as OpenClawConfig;
const result = await memoryRuntime.getMemorySearchManager({
cfg,
agentId: "main",
});
expect(result.debug).toEqual(managerDebug);
expect(getMemorySearchManagerMock).toHaveBeenCalledWith({
cfg,
agentId: "main",
});
});
it("keeps local-service acquisition scoped to each runtime instance", async () => {
const cfg = {} as OpenClawConfig;
const firstAcquire = vi.fn(async () => undefined);
const secondAcquire = vi.fn(async () => undefined);
await Promise.all([
createMemoryRuntime({ acquireLocalService: firstAcquire }).getMemorySearchManager({
cfg,
agentId: "first",
}),
createMemoryRuntime({ acquireLocalService: secondAcquire }).getMemorySearchManager({
cfg,
agentId: "second",
}),
]);
expect(getMemorySearchManagerMock).toHaveBeenCalledWith({
cfg,
agentId: "first",
acquireLocalService: firstAcquire,
});
expect(getMemorySearchManagerMock).toHaveBeenCalledWith({
cfg,
agentId: "second",
acquireLocalService: secondAcquire,
});
});
it("keeps SQLite lease coordination scoped to each runtime instance", async () => {
const cfg = {} as OpenClawConfig;
const firstLease = vi.fn();
const secondLease = vi.fn();
await Promise.all([
createMemoryRuntime({ withLease: firstLease }).getMemorySearchManager({
cfg,
agentId: "first",
}),
createMemoryRuntime({ withLease: secondLease }).getMemorySearchManager({
cfg,
agentId: "second",
}),
]);
expect(getMemorySearchManagerMock).toHaveBeenCalledWith({
cfg,
agentId: "first",
withLease: firstLease,
});
expect(getMemorySearchManagerMock).toHaveBeenCalledWith({
cfg,
agentId: "second",
withLease: secondLease,
});
});
});