mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 05:10:41 +00:00
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { PluginLoaderCacheState, PluginLoadReentryError } from "./loader-cache-state.js";
|
|
|
|
describe("PluginLoaderCacheState", () => {
|
|
it("evicts the least recently used registry cache entry", () => {
|
|
const cache = new PluginLoaderCacheState<string>(2);
|
|
|
|
cache.set("", "empty");
|
|
cache.set("a", "alpha");
|
|
cache.set("b", "bravo");
|
|
expect(cache.get("a")).toBe("alpha");
|
|
|
|
cache.set("c", "charlie");
|
|
|
|
expect(cache.get("b")).toBeUndefined();
|
|
expect(cache.get("a")).toBe("alpha");
|
|
expect(cache.get("c")).toBe("charlie");
|
|
});
|
|
|
|
it("tracks in-flight loads and reports reentry by cache key", () => {
|
|
const cache = new PluginLoaderCacheState<string>(2);
|
|
|
|
cache.beginLoad("demo");
|
|
expect(cache.isLoadInFlight("demo")).toBe(true);
|
|
expect(() => cache.beginLoad("demo")).toThrow(PluginLoadReentryError);
|
|
|
|
cache.finishLoad("demo");
|
|
expect(cache.isLoadInFlight("demo")).toBe(false);
|
|
});
|
|
|
|
it("clears registry, in-flight, and warning state together", () => {
|
|
const cache = new PluginLoaderCacheState<string>(2);
|
|
|
|
cache.set("demo", "registry");
|
|
cache.beginLoad("demo");
|
|
cache.recordOpenAllowlistWarning("demo-warning");
|
|
|
|
cache.clear();
|
|
|
|
expect(cache.get("demo")).toBeUndefined();
|
|
expect(cache.isLoadInFlight("demo")).toBe(false);
|
|
expect(cache.hasOpenAllowlistWarning("demo-warning")).toBe(false);
|
|
});
|
|
});
|