test(perf): reduce guardrail and media test overhead

This commit is contained in:
Peter Steinberger
2026-03-02 11:16:29 +00:00
parent bff785aecc
commit 1b98879295
3 changed files with 22 additions and 25 deletions

View File

@@ -10,6 +10,8 @@ type QuoteScanState = {
quote: QuoteChar | null;
escaped: boolean;
};
const WEAK_RANDOM_SAME_LINE_PATTERN =
/(?:Date\.now[^\r\n]*Math\.random|Math\.random[^\r\n]*Date\.now)/u;
function shouldSkip(relativePath: string): boolean {
return shouldSkipGuardrailRuntimeSource(relativePath);
@@ -223,15 +225,8 @@ describe("temp path guard", () => {
if (hasDynamicTmpdirJoin(file.source)) {
offenders.push(relativePath);
}
if (file.source.includes("Date.now") && file.source.includes("Math.random")) {
const lines = file.source.split(/\r?\n/);
for (let idx = 0; idx < lines.length; idx += 1) {
const line = lines[idx] ?? "";
if (!line.includes("Date.now") || !line.includes("Math.random")) {
continue;
}
weakRandomMatches.push(`${relativePath}:${idx + 1}`);
}
if (WEAK_RANDOM_SAME_LINE_PATTERN.test(file.source)) {
weakRandomMatches.push(relativePath);
}
}