From 45474697b3207cd21e6a7a614e5e788ce8dd8a58 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Sat, 29 Aug 2026 09:11:04 -0700 Subject: [PATCH] test(windows): put the policy ratchet on the shared source walk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `src/shared/source-scan` exists because four guards had each grown their own `collectSourceFiles` and drifted — one of them scanned the cross-version e2e checkouts and reported 21 offenders that were copies of shipped releases. This ratchet had just become the fifth. It now uses `scanSourceTree`, which also gets it dot-directory skipping and `/`-normalised paths on Windows for free, and `stripComments` so a commented-out declaration is not an offender. --- .../windows-transient-lock-removal.test.ts | 32 ++++++------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/src/shared/windows-transient-lock-removal.test.ts b/src/shared/windows-transient-lock-removal.test.ts index 0d0145ac973..8f7e7b1c894 100644 --- a/src/shared/windows-transient-lock-removal.test.ts +++ b/src/shared/windows-transient-lock-removal.test.ts @@ -1,6 +1,6 @@ -import { readFileSync, readdirSync, statSync } from 'node:fs' -import { join, relative } from 'node:path' +import { join } from 'node:path' import { afterEach, describe, expect, it, vi } from 'vitest' +import { scanSourceTree, stripComments } from './source-scan/source-tree-scan' import { WINDOWS_RM_MAX_RETRIES, WINDOWS_RM_RETRY_DELAY_MS, @@ -12,33 +12,19 @@ function withPlatform(platform: NodeJS.Platform): void { } const SOURCE_ROOT = join(__dirname, '..') -const OWNING_MODULE = join('shared', 'windows-transient-lock-removal.ts') -const IGNORED_DIRECTORIES = new Set(['node_modules', 'dist', 'out', 'build', '.git']) +const OWNING_MODULE = 'shared/windows-transient-lock-removal.ts' /** A `const WINDOWS_RM_… =` line, i.e. a file stating the policy rather than importing it. */ const POLICY_DECLARATION = /^\s*(?:export\s+)?const\s+WINDOWS_RM_(?:MAX_RETRIES|RETRY_DELAY_MS)\s*=/m -function collectSourceFiles(root: string): string[] { - const found: string[] = [] - for (const entry of readdirSync(root)) { - if (IGNORED_DIRECTORIES.has(entry)) { - continue - } - const path = join(root, entry) - if (statSync(path).isDirectory()) { - found.push(...collectSourceFiles(path)) - } else if (/\.tsx?$/.test(entry)) { - found.push(path) - } - } - return found -} - /** Every file that declares the retry policy instead of importing it. */ function findPolicyDeclarations(): string[] { - return collectSourceFiles(SOURCE_ROOT) - .filter((path) => POLICY_DECLARATION.test(readFileSync(path, 'utf8'))) - .map((path) => relative(SOURCE_ROOT, path)) + return scanSourceTree(SOURCE_ROOT, { includeTests: true }) + .filter( + (file) => + POLICY_DECLARATION.test(file.source) && POLICY_DECLARATION.test(stripComments(file.source)) + ) + .map((file) => file.relativePath) .sort() }