mirror of
https://github.com/stablyai/orca.git
synced 2026-10-24 16:03:45 +00:00
test(windows): put the policy ratchet on the shared source walk
`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.
This commit is contained in:
committed by
Merge Sim
parent
2a4fd2f263
commit
45474697b3
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user