mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-25 07:30:03 +00:00
test(perf): simplify temp-path guard scan loop
This commit is contained in:
@@ -12,6 +12,8 @@ type QuoteScanState = {
|
||||
};
|
||||
const WEAK_RANDOM_SAME_LINE_PATTERN =
|
||||
/(?:Date\.now[^\r\n]*Math\.random|Math\.random[^\r\n]*Date\.now)/u;
|
||||
const PATH_JOIN_CALL_PATTERN = /path\s*\.\s*join\s*\(/u;
|
||||
const OS_TMPDIR_CALL_PATTERN = /os\s*\.\s*tmpdir\s*\(/u;
|
||||
|
||||
function shouldSkip(relativePath: string): boolean {
|
||||
return shouldSkipGuardrailRuntimeSource(relativePath);
|
||||
@@ -144,10 +146,12 @@ function isOsTmpdirExpression(argument: string): boolean {
|
||||
}
|
||||
|
||||
function mightContainDynamicTmpdirJoin(source: string): boolean {
|
||||
if (!source.includes("path") || !source.includes("join") || !source.includes("tmpdir")) {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
source.includes("path") &&
|
||||
source.includes("path.join") &&
|
||||
source.includes("os.tmpdir") &&
|
||||
(source.includes("path.join") || PATH_JOIN_CALL_PATTERN.test(source)) &&
|
||||
(source.includes("os.tmpdir") || OS_TMPDIR_CALL_PATTERN.test(source)) &&
|
||||
source.includes("`") &&
|
||||
source.includes("${")
|
||||
);
|
||||
@@ -220,9 +224,6 @@ describe("temp path guard", () => {
|
||||
|
||||
for (const file of files) {
|
||||
const relativePath = file.relativePath;
|
||||
if (shouldSkip(relativePath)) {
|
||||
continue;
|
||||
}
|
||||
if (hasDynamicTmpdirJoin(file.source)) {
|
||||
offenders.push(relativePath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user