CodeBench: revert-if-worse + erillinen testFixRounds-laskuri
- Seurataan parasta testitulosta (bestPassed/bestFiles) - Jos korjaus huonontaa: palautetaan paras versio ja lopetetaan - fixRounds laskee vain testikorjaukset, ei cargo check -kierroksia - Estää 4/7 → 0/1 regressiot korjaussilmukassa
This commit is contained in:
@@ -457,6 +457,9 @@ async function runPipeline(model, scenario) {
|
|||||||
const testLabel = LANG === 'rust' ? 'Cargo test' : 'Pytest';
|
const testLabel = LANG === 'rust' ? 'Cargo test' : 'Pytest';
|
||||||
const dockerTimeout = LANG === 'rust' ? 300000 : 120000;
|
const dockerTimeout = LANG === 'rust' ? 300000 : 120000;
|
||||||
const MAX_TEST_FIX = 3;
|
const MAX_TEST_FIX = 3;
|
||||||
|
let bestFiles = { ...files }; // Paras versio tiedostoista
|
||||||
|
let bestPassed = -1; // Paras testitulos
|
||||||
|
let testFixRounds = 0; // Erillinen laskuri testikorjauksille
|
||||||
|
|
||||||
for (let testRound = 0; testRound <= MAX_TEST_FIX; testRound++) {
|
for (let testRound = 0; testRound <= MAX_TEST_FIX; testRound++) {
|
||||||
// Kirjoita tiedostot levylle
|
// Kirjoita tiedostot levylle
|
||||||
@@ -479,7 +482,6 @@ async function runPipeline(model, scenario) {
|
|||||||
}
|
}
|
||||||
if (syntaxErrors) {
|
if (syntaxErrors) {
|
||||||
console.log(` [5/5] ⚠ Syntaksivirhe — ohitetaan Docker`);
|
console.log(` [5/5] ⚠ Syntaksivirhe — ohitetaan Docker`);
|
||||||
// Suoraan itsekorjaukseen ilman Docker-ajoa
|
|
||||||
writeFileSync(`${dir}/_testout_${testRound}.txt`, `SYNTAX ERRORS:\n${syntaxErrors}`);
|
writeFileSync(`${dir}/_testout_${testRound}.txt`, `SYNTAX ERRORS:\n${syntaxErrors}`);
|
||||||
Object.assign(result, { testsPassed: 0, testsFailed: 1, testsTotal: 1 });
|
Object.assign(result, { testsPassed: 0, testsFailed: 1, testsTotal: 1 });
|
||||||
|
|
||||||
@@ -494,8 +496,8 @@ async function runPipeline(model, scenario) {
|
|||||||
for (const [fn, content] of Object.entries(fixedFiles)) {
|
for (const [fn, content] of Object.entries(fixedFiles)) {
|
||||||
if (LCONF.required.includes(fn)) files[fn] = content;
|
if (LCONF.required.includes(fn)) files[fn] = content;
|
||||||
}
|
}
|
||||||
result.fixRounds++;
|
testFixRounds++;
|
||||||
continue; // Aja uudestaan
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,7 +514,19 @@ async function runPipeline(model, scenario) {
|
|||||||
testOut = e.stdout || e.stderr || e.message || '';
|
testOut = e.stdout || e.stderr || e.message || '';
|
||||||
}
|
}
|
||||||
writeFileSync(`${dir}/_testout_${testRound}.txt`, testOut);
|
writeFileSync(`${dir}/_testout_${testRound}.txt`, testOut);
|
||||||
Object.assign(result, parseTestOutput(testOut));
|
const testResult = parseTestOutput(testOut);
|
||||||
|
Object.assign(result, testResult);
|
||||||
|
|
||||||
|
// Seuraa parasta tulosta — revert jos korjaus huononsi
|
||||||
|
if (result.testsPassed > bestPassed) {
|
||||||
|
bestPassed = result.testsPassed;
|
||||||
|
bestFiles = { ...files };
|
||||||
|
} else if (testRound > 0 && result.testsPassed < bestPassed) {
|
||||||
|
console.log(` [5/5] ⚠ Korjaus huononsi (${result.testsPassed}/${result.testsTotal} < ${bestPassed}) — palautetaan paras versio`);
|
||||||
|
files = { ...bestFiles };
|
||||||
|
Object.assign(result, { testsPassed: bestPassed });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Kaikki testit läpi → valmis
|
// Kaikki testit läpi → valmis
|
||||||
if (result.testsTotal > 0 && result.testsPassed === result.testsTotal) break;
|
if (result.testsTotal > 0 && result.testsPassed === result.testsTotal) break;
|
||||||
@@ -534,13 +548,20 @@ async function runPipeline(model, scenario) {
|
|||||||
timings.push(fixResp);
|
timings.push(fixResp);
|
||||||
|
|
||||||
const fixedFiles = parseGeneratedFiles(fixResp.text);
|
const fixedFiles = parseGeneratedFiles(fixResp.text);
|
||||||
// Päivitä vain tiedostot jotka malli palautti
|
|
||||||
for (const [fn, content] of Object.entries(fixedFiles)) {
|
for (const [fn, content] of Object.entries(fixedFiles)) {
|
||||||
if (LCONF.required.includes(fn)) files[fn] = content;
|
if (LCONF.required.includes(fn)) files[fn] = content;
|
||||||
}
|
}
|
||||||
result.fixRounds++;
|
testFixRounds++;
|
||||||
}
|
}
|
||||||
writeFileSync(`${dir}/_testout.txt`, ''); // Symlink viimeisimpään
|
|
||||||
|
// Kirjoita paras versio levylle
|
||||||
|
for (const [fn, content] of Object.entries(bestPassed >= 0 ? bestFiles : files)) {
|
||||||
|
const filePath = join(dir, fn);
|
||||||
|
mkdirSync(dirname(filePath), { recursive: true });
|
||||||
|
writeFileSync(filePath, content);
|
||||||
|
}
|
||||||
|
// fixRounds = vain testikorjaukset (cargo check -korjaukset erilliset vaihe 4:ssä)
|
||||||
|
result.fixRounds = testFixRounds;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
result.error = e.message;
|
result.error = e.message;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user