fix(maintainability): harden tracked scan and baseline checks

This commit is contained in:
Tam Nhu Tran committed 2026-02-12 15:01:33 +07:00
1 parent b7481cf346
commit 33e9a88494
1 file changed
+24 -10
+24 -10
View File
@@ -119,12 +119,18 @@ function parseArgs(argv) {
} }
function collectTrackedFilesFromGit() { function collectTrackedFilesFromGit() {
let output;
try { try {
const output = execFileSync('git', ['ls-files', '-z', '--', 'src'], { output = execFileSync('git', ['ls-files', '-z', '--', 'src'], {
cwd: PROJECT_ROOT, cwd: PROJECT_ROOT,
encoding: 'utf8', encoding: 'utf8',
stdio: ['ignore', 'pipe', 'ignore'], stdio: ['ignore', 'pipe', 'ignore'],
}); });
} catch {
throw new Error(
'Unable to enumerate tracked files via git. Run this command from a git checkout with git installed.'
);
}
if (!output) { if (!output) {
return []; return [];
@@ -141,17 +147,13 @@ function collectTrackedFilesFromGit() {
return false; return false;
} }
try { const stats = fs.statSync(filePath);
return fs.statSync(filePath).isFile(); if (!stats.isFile()) {
} catch { throw new Error(`Tracked path is not a file: ${path.relative(PROJECT_ROOT, filePath)}`);
return false;
} }
return true;
}); });
} catch {
throw new Error(
'Unable to enumerate tracked files via git. Run this command from a git checkout with git installed.'
);
}
} }
function collectFilesInSrc() { function collectFilesInSrc() {
@@ -228,6 +230,18 @@ function runCheck(checkPath, currentMetrics) {
const baselineContent = fs.readFileSync(resolvedCheckPath, 'utf8'); const baselineContent = fs.readFileSync(resolvedCheckPath, 'utf8');
const baselineMetrics = JSON.parse(baselineContent); const baselineMetrics = JSON.parse(baselineContent);
if (baselineMetrics.sourceDirectory !== currentMetrics.sourceDirectory) {
throw new Error(
`Baseline sourceDirectory mismatch: expected "${currentMetrics.sourceDirectory}", got "${baselineMetrics.sourceDirectory}"`
);
}
if (baselineMetrics.largeFileThresholdLoc !== currentMetrics.largeFileThresholdLoc) {
throw new Error(
`Baseline largeFileThresholdLoc mismatch: expected ${currentMetrics.largeFileThresholdLoc}, got ${baselineMetrics.largeFileThresholdLoc}`
);
}
const gatedKeys = [ const gatedKeys = [
'processExitReferenceCount', 'processExitReferenceCount',
'synchronousFsApiReferenceCount', 'synchronousFsApiReferenceCount',