CodeBench: Rust cargo check -vaihe ennen testejä + käännösvirheiden itsekorjaus
- Vaihe 4/5: cargo check Docker-kontissa ennen cargo test -ajoa - Käännösvirheet syötetään mallille korjattavaksi (max 2 kierrosta) - Estää turhat cargo test -ajot kun koodi ei käänny
This commit is contained in:
@@ -389,8 +389,43 @@ async function runPipeline(model, scenario) {
|
|||||||
const missing = LCONF.required.filter(f => !files[f]);
|
const missing = LCONF.required.filter(f => !files[f]);
|
||||||
if (missing.length > 0) { result.error = `Puuttuvat: ${missing.join(', ')}`; return result; }
|
if (missing.length > 0) { result.error = `Puuttuvat: ${missing.join(', ')}`; return result; }
|
||||||
|
|
||||||
// 4. Validointi + korjaussilmukka (Python-spesifi)
|
// 4. Validointi + korjaussilmukka
|
||||||
let fixRound = 0;
|
let fixRound = 0;
|
||||||
|
if (LANG === 'rust') {
|
||||||
|
// Rust: cargo check Docker-kontissa ennen testejä
|
||||||
|
for (let checkRound = 0; checkRound < MAX_FIX_ROUNDS; checkRound++) {
|
||||||
|
// Kirjoita tiedostot levylle
|
||||||
|
for (const [fn, content] of Object.entries(files)) {
|
||||||
|
const filePath = join(dir, fn);
|
||||||
|
mkdirSync(dirname(filePath), { recursive: true });
|
||||||
|
writeFileSync(filePath, content);
|
||||||
|
}
|
||||||
|
console.log(` [4/5] Cargo check${checkRound > 0 ? ` (korjaus ${checkRound})` : ''}...`);
|
||||||
|
let checkOut = '';
|
||||||
|
try {
|
||||||
|
checkOut = execSync(
|
||||||
|
`docker run --rm --entrypoint sh -v "${dir}:/src:ro" ${LCONF.dockerImage} -c "cp -r /src/* . && cargo check 2>&1"`,
|
||||||
|
{ timeout: 300000, encoding: 'utf-8' }
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
checkOut = e.stdout || e.stderr || e.message || '';
|
||||||
|
}
|
||||||
|
const compileErrors = checkOut.split('\n').filter(l => /^error/.test(l));
|
||||||
|
if (compileErrors.length === 0) break; // Kääntyy — jatka testeihin
|
||||||
|
|
||||||
|
console.log(` [4/5] ${compileErrors.length} käännösvirhettä — korjataan...`);
|
||||||
|
fixRound++;
|
||||||
|
const errorLines = checkOut.split('\n').filter(l => /^error|^\s+-->/.test(l)).slice(0, 30).join('\n');
|
||||||
|
const allCode = Object.entries(files).map(([fn, c]) => `=== ${fn} ===\n${c}`).join('\n\n');
|
||||||
|
const fixPrompt = `Fix the following Rust compilation errors. Return ALL files with === markers.\n\nERRORS:\n${errorLines}\n\nCURRENT CODE:\n${allCode}`;
|
||||||
|
const fixResp = await ollamaChat(model, fixPrompt, CODE_SYSTEM, 12288);
|
||||||
|
timings.push(fixResp);
|
||||||
|
const fixedFiles = parseGeneratedFiles(fixResp.text);
|
||||||
|
for (const [fn, content] of Object.entries(fixedFiles)) {
|
||||||
|
if (LCONF.required.includes(fn)) files[fn] = content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (LANG === 'python') {
|
if (LANG === 'python') {
|
||||||
let issues = validateProjectCode(files);
|
let issues = validateProjectCode(files);
|
||||||
while (issues.length > 0 && fixRound < MAX_FIX_ROUNDS) {
|
while (issues.length > 0 && fixRound < MAX_FIX_ROUNDS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user