fix(plugins): bound allowlist warning cache (#127126)

Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Peter Steinberger
2026-08-25 11:39:27 -07:00
committed by GitHub
parent 8bfcdbe884
commit 95fcb5275e
2 changed files with 16 additions and 3 deletions
+12
View File
@@ -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);
+4 -3
View File
@@ -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);
}
}