Files
openclaw/extensions/memory-core/cli-metadata.test.ts
Peter Steinberger 9809375fda refactor(plugins)!: remove the plugin state lease API (#121140)
* refactor(plugins)!: remove plugin state lease API

* docs(plugins): document state lease removal
2026-08-09 11:16:07 -07:00

54 lines
1.8 KiB
TypeScript

// Memory Core tests cover metadata-only CLI host propagation.
import { Command } from "commander";
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/core";
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
import { describe, expect, it, vi } from "vitest";
const registerMemoryCliMock = vi.hoisted(() => vi.fn());
vi.mock("./src/cli.js", () => ({
registerMemoryCli: registerMemoryCliMock,
}));
import plugin from "./cli-metadata.js";
describe("memory-core CLI metadata", () => {
it("passes the SQLite state host to the standalone CLI", async () => {
let registrar: Parameters<OpenClawPluginApi["registerCli"]>[0] | undefined;
const keyedStore = {};
const openKeyedStore = vi.fn(() => keyedStore);
const acquireLocalService = vi.fn(async () => undefined);
plugin.register(
createTestPluginApi({
runtime: {
llm: { acquireLocalService },
state: { openKeyedStore },
} as unknown as OpenClawPluginApi["runtime"],
registerCli(nextRegistrar) {
registrar = nextRegistrar;
},
}),
);
if (!registrar) {
throw new Error("CLI registrar missing");
}
const program = new Command();
await registrar({ program } as never);
expect(registerMemoryCliMock).toHaveBeenCalledWith(program, {
acquireLocalService,
openKeyedStore: expect.any(Function),
});
const boundOpenKeyedStore = registerMemoryCliMock.mock.calls[0]?.[1]?.openKeyedStore as
| ((options: unknown) => unknown)
| undefined;
if (!boundOpenKeyedStore) {
throw new Error("bound SQLite state hook missing");
}
const storeOptions = { namespace: "cli-status-regression", maxEntries: 1 };
expect(boundOpenKeyedStore(storeOptions)).toBe(keyedStore);
expect(openKeyedStore).toHaveBeenCalledWith(storeOptions);
});
});