CodeBench: nopea syntaksitarkistus ennen Docker-ajoa

py_compile tarkistaa .py-tiedostot millisekunneissa.
Syntaksivirhe → suoraan itsekorjaukseen, ohitetaan Docker (~10s säästö).
This commit is contained in:
2026-04-14 12:52:03 +03:00
parent e360896436
commit 1de7e5c90b

View File

@@ -359,6 +359,39 @@ async function runPipeline(model, scenario) {
writeFileSync(filePath, content); writeFileSync(filePath, content);
} }
// Nopea staattinen analyysi ennen Docker-ajoa
const pyFiles = Object.keys(files).filter(f => f.endsWith('.py'));
if (LANG === 'python' && pyFiles.length > 0) {
let syntaxErrors = '';
for (const f of pyFiles) {
try {
execSync(`python3 -c "import py_compile; py_compile.compile('${join(dir, f)}', doraise=True)"`, { timeout: 5000, encoding: 'utf-8', stdio: 'pipe' });
} catch (e) {
syntaxErrors += `${f}: ${(e.stderr || e.message || '').split('\n').filter(l => l.includes('Error')).join('; ')}\n`;
}
}
if (syntaxErrors) {
console.log(` [5/5] ⚠ Syntaksivirhe — ohitetaan Docker`);
// Suoraan itsekorjaukseen ilman Docker-ajoa
writeFileSync(`${dir}/_testout_${testRound}.txt`, `SYNTAX ERRORS:\n${syntaxErrors}`);
Object.assign(result, { testsPassed: 0, testsFailed: 1, testsTotal: 1 });
if (testRound >= MAX_TEST_FIX) { result.error = 'Syntaksivirhe'; break; }
console.log(` [5/5] Itsekorjaus: syntaksi...`);
const allCode = Object.entries(files).map(([fn, c]) => `=== ${fn} ===\n${c}`).join('\n\n');
const fixPrompt = `Fix the following syntax errors. Return ALL files with === markers.\n\nERRORS:\n${syntaxErrors}\n\nCURRENT CODE:\n${allCode}`;
const fixResp = await ollamaChat(model, fixPrompt, FIX_SYSTEM, 8192);
timings.push(fixResp);
const fixedFiles = parseGeneratedFiles(fixResp.text);
for (const [fn, content] of Object.entries(fixedFiles)) {
if (LCONF.required.includes(fn)) files[fn] = content;
}
result.fixRounds++;
continue; // Aja uudestaan
}
}
const roundLabel = testRound > 0 ? ` (korjaus ${testRound}/${MAX_TEST_FIX})` : ''; const roundLabel = testRound > 0 ? ` (korjaus ${testRound}/${MAX_TEST_FIX})` : '';
console.log(` [5/5] ${testLabel}${roundLabel}...`); console.log(` [5/5] ${testLabel}${roundLabel}...`);