mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 20:05:46 -06:00
fix(plugins): bound allowlist warning cache (#127126)
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
committed by
GitHub
parent
8bfcdbe884
commit
95fcb5275e
@@ -18,6 +18,18 @@ describe("PluginLoaderCacheState", () => {
|
||||
expect(cache.get("c")).toBe("charlie");
|
||||
});
|
||||
|
||||
it("bounds open-allowlist warning suppression by loader cache capacity", () => {
|
||||
const cache = new PluginLoaderCacheState<string>(2);
|
||||
|
||||
cache.recordOpenAllowlistWarning("first");
|
||||
cache.recordOpenAllowlistWarning("second");
|
||||
cache.recordOpenAllowlistWarning("third");
|
||||
|
||||
expect(cache.hasOpenAllowlistWarning("first")).toBe(false);
|
||||
expect(cache.hasOpenAllowlistWarning("second")).toBe(true);
|
||||
expect(cache.hasOpenAllowlistWarning("third")).toBe(true);
|
||||
});
|
||||
|
||||
it("clears registry, in-flight, and warning state together", () => {
|
||||
const cache = new PluginLoaderCacheState<string>(2);
|
||||
|
||||
|
||||
@@ -16,10 +16,11 @@ class PluginLoadReentryError extends Error {
|
||||
export class PluginLoaderCacheState<T> {
|
||||
readonly #registryCache: PluginLruCache<T>;
|
||||
readonly #inFlightLoads = new Set<string>();
|
||||
readonly #openAllowlistWarningCache = new Set<string>();
|
||||
readonly #openAllowlistWarningCache: PluginLruCache<true>;
|
||||
|
||||
constructor(defaultMaxEntries: number) {
|
||||
this.#registryCache = new PluginLruCache<T>(defaultMaxEntries);
|
||||
this.#openAllowlistWarningCache = new PluginLruCache<true>(defaultMaxEntries);
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
@@ -57,10 +58,10 @@ export class PluginLoaderCacheState<T> {
|
||||
}
|
||||
|
||||
hasOpenAllowlistWarning(cacheKey: string): boolean {
|
||||
return this.#openAllowlistWarningCache.has(cacheKey);
|
||||
return this.#openAllowlistWarningCache.get(cacheKey) === true;
|
||||
}
|
||||
|
||||
recordOpenAllowlistWarning(cacheKey: string): void {
|
||||
this.#openAllowlistWarningCache.add(cacheKey);
|
||||
this.#openAllowlistWarningCache.set(cacheKey, true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user