diff --git a/lib/shared-store/__tests__/server-state-guard.test.ts b/lib/shared-store/__tests__/server-state-guard.test.ts index d64fdd8be..8135e5bc0 100644 --- a/lib/shared-store/__tests__/server-state-guard.test.ts +++ b/lib/shared-store/__tests__/server-state-guard.test.ts @@ -50,6 +50,8 @@ describe('the scan', () => { 'const sessions = new Map();', 'let counter = 0;', 'const queue: string[] = [];', + 'export const NONE = [] as const;', + 'const later = [] as string[];', "const budget = createFailureBudget({ name: 'x' });", "const pattern = new RegExp('x');", 'function f() {', @@ -59,7 +61,7 @@ describe('the scan', () => { "(globalThis as any)[KEY] ??= new Map();", ].join('\n')); const names = findStateSites(dir, file).map((s) => s.name); - expect(names).toEqual(['sessions', 'counter', 'queue', 'budget', 'globalThis:KEY']); + expect(names).toEqual(['sessions', 'counter', 'queue', 'later', 'budget', 'globalThis:KEY']); } finally { rmSync(dir, { recursive: true, force: true }); } diff --git a/lib/shared-store/__tests__/server-state-scan.ts b/lib/shared-store/__tests__/server-state-scan.ts index 3ede53417..8576c2e9d 100644 --- a/lib/shared-store/__tests__/server-state-scan.ts +++ b/lib/shared-store/__tests__/server-state-scan.ts @@ -13,7 +13,7 @@ import path from 'node:path'; * - top-level `const x = new Something(`, except constructors of values that * can't change (RegExp, URL, TextEncoder/TextDecoder, Intl.*, Error types); * - top-level `const x = []` / `{}` / `new Map()`… (empty containers, which - * only exist to be filled); + * only exist to be filled; `[] as const` is a readonly tuple and can't be); * - top-level `const x = createSomethingBudget|Cache|Store|Limiter(`; * - any `globalThis` access that stores something (`??=`, `= new`, `[KEY] =`). * @@ -130,7 +130,7 @@ export function findStateSites(root: string, file: string): StateSite[] { // SCREAMING_CASE tables built once from a literal list are constants by convention. const constantTable = /^[A-Z][A-Z0-9_]*$/.test(name) && /^new (Set|Map)(<.*?>)?\(\s*\S/.test(value) && !/^new (Set|Map)(<.*?>)?\(\s*\)/.test(value); const isNew = /^new\s/.test(value) && !IMMUTABLE_CONSTRUCTORS.test(value) && !constantTable; - const isEmpty = /^(\[\s*\]|\{\s*\})\s*(as\s.+)?;?$/.test(value); + const isEmpty = /^(\[\s*\]|\{\s*\})\s*(as\s.+)?;?$/.test(value) && !/^(\[\s*\]|\{\s*\})\s*as\s+const\s*;?$/.test(value); const isFactory = /^create\w*(Budget|Cache|Store|Limiter|Queue)\s*[(<]/.test(value); if (isNew || isEmpty || isFactory) sites.push({ file: rel, name, line: i + 1, text: raw.trim() }); return;