diff --git a/kipina-codebench/benchmark.mjs b/kipina-codebench/benchmark.mjs index 50c24e4..f49da1e 100644 --- a/kipina-codebench/benchmark.mjs +++ b/kipina-codebench/benchmark.mjs @@ -359,6 +359,39 @@ async function runPipeline(model, scenario) { 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})` : ''; console.log(` [5/5] ${testLabel}${roundLabel}...`);