File size: 2,908 Bytes
ef987bb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | const fs = require('fs');
const path = require('path');
const child_process = require('child_process');
const TASK_ID = 51;
const LANGUAGE = "python";
const EXPECTED = [
"threshold_report.txt"
];
const SKIP_DIRS = new Set([
"tests",
"logs",
"node_modules",
".git"
]);
function assert(condition, message) { if (!condition) throw new Error(message); }
function walk(dir) {
let out = [];
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
if (SKIP_DIRS.has(entry.name)) continue;
const p = path.join(dir, entry.name);
if (entry.isDirectory()) out = out.concat(walk(p));
else out.push(p);
}
return out;
}
function globToRe(glob) {
return new RegExp('^' + glob.split('*').map(x => x.replace(/[.+?^${}()|[\]\\]/g, '\\$&')).join('.*') + '$');
}
function existsPattern(files, pat) {
const re = globToRe(String(pat).replace(/\\/g, '/'));
return files.some(f => re.test(f.replace(/\\/g, '/')) || f.replace(/\\/g, '/').endsWith(String(pat).replace(/\\/g, '/')));
}
const files = walk(process.cwd());
assert(files.length > 0, 'candidate workspace should contain files');
const rel = files.map(f => path.relative(process.cwd(), f));
const source = files.filter(f => /\.(js|jsx|ts|tsx|css|html|py|go|md|svg)$/i.test(f));
assert(source.length > 0, 'candidate should contain source or report files');
if (LANGUAGE === 'go') {
const goFiles = files.filter(f => f.endsWith('.go'));
assert(goFiles.length > 0, 'go task should contain .go files');
try {
child_process.execFileSync('go', ['test', './...'], { cwd: process.cwd(), stdio: 'pipe', timeout: 120000 });
} catch (err) {
// The benchmark's own verifier owns task-specific Go behavior. Here we
// keep go test as an opportunistic runtime probe so local module/path
// differences do not create false negatives.
const msg = Buffer.concat([err.stdout || Buffer.alloc(0), err.stderr || Buffer.alloc(0)]).toString().slice(0, 500);
console.warn('go test ./... probe failed but is non-fatal: ' + msg);
}
} else if (LANGUAGE === 'python') {
const pyFiles = files.filter(f => f.endsWith('.py'));
assert(pyFiles.length > 0 || rel.some(f => /\.(html|csv|json|txt|md|png)$/i.test(f)), 'python/data task should contain scripts or produced artifacts');
for (const f of pyFiles.slice(0, 20)) {
child_process.execFileSync('python3', ['-m', 'py_compile', f], { cwd: process.cwd(), stdio: 'pipe', timeout: 30000 });
}
} else {
for (const f of files.filter(f => f.endsWith('.js')).slice(0, 20)) {
child_process.execFileSync('node', ['--check', f], { cwd: process.cwd(), stdio: 'pipe', timeout: 30000 });
}
}
for (const pat of EXPECTED) {
assert(existsPattern(rel, pat), 'missing expected artifact pattern after verifier: ' + pat);
}
console.log(`AAAV targeted dynamic test passed for task ${TASK_ID}`);
|