Files
openclaw/src/plugins/host-hook-cleanup.config.test.ts
Eva 8afc9ef73c [plugin sdk] Harden finalize retry and run context cleanup (#75600)
Merged via squash.

Prepared head SHA: ec58a6212b
Co-authored-by: 100yenadmin <239388517+100yenadmin@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
2026-05-04 07:04:22 -07:00

55 lines
1.4 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
import { runPluginHostCleanup } from "./host-hook-cleanup.js";
import { createEmptyPluginRegistry } from "./registry-empty.js";
const mocks = vi.hoisted(() => ({
getRuntimeConfig: vi.fn(),
}));
vi.mock("../config/config.js", () => ({
getRuntimeConfig: mocks.getRuntimeConfig,
}));
describe("plugin host cleanup config fallback", () => {
afterEach(() => {
mocks.getRuntimeConfig.mockReset();
});
it("records session store config failures while continuing runtime cleanup", async () => {
const registry = createEmptyPluginRegistry();
const cleanup = vi.fn();
registry.runtimeLifecycles ??= [];
registry.runtimeLifecycles.push({
pluginId: "cleanup-plugin",
pluginName: "Cleanup Plugin",
source: "test",
lifecycle: {
id: "runtime-cleanup",
cleanup,
},
});
mocks.getRuntimeConfig.mockImplementation(() => {
throw new Error("invalid config");
});
const result = await runPluginHostCleanup({
registry,
pluginId: "cleanup-plugin",
reason: "disable",
});
expect(cleanup).toHaveBeenCalledWith(
expect.objectContaining({
reason: "disable",
}),
);
expect(result.cleanupCount).toBe(1);
expect(result.failures).toEqual([
expect.objectContaining({
pluginId: "cleanup-plugin",
hookId: "session-store",
}),
]);
});
});