diff --git a/scripts/gan-harness.sh b/scripts/gan-harness.sh index 093e696d1..79dd5038f 100755 --- a/scripts/gan-harness.sh +++ b/scripts/gan-harness.sh @@ -62,15 +62,30 @@ extract_score() { # Extract the TOTAL weighted score from a feedback file local file="$1" awk ' - /\*\*TOTAL\*\*/ || /Verdict:/ { - if (match($0, /[0-9]+[.][0-9]+/)) { - print substr($0, RSTART, RLENGTH) + /\*\*TOTAL\*\*/ { + total_line = $0 + total = "" + while (match(total_line, /[0-9]+[.][0-9]+/)) { + total = substr(total_line, RSTART, RLENGTH) + total_line = substr(total_line, RSTART + RLENGTH) + } + if (total != "") { + print total found = 1 exit } } + /Verdict:/ && /[Ss]core[[:space:]]*[:=]?[[:space:]]*[0-9]+[.][0-9]+/ { + verdict = $0 + sub(/^.*[Ss]core[[:space:]]*[:=]?[[:space:]]*/, "", verdict) + if (match(verdict, /^[0-9]+[.][0-9]+/)) { + verdict = substr(verdict, RSTART, RLENGTH) + } else { + verdict = "" + } + } END { - if (!found) print "0.0" + if (!found) print (verdict != "" ? verdict : "0.0") } ' "$file" 2>/dev/null } diff --git a/tests/gan-harness.test.js b/tests/gan-harness.test.js index 4c42111fc..36c7255ce 100644 --- a/tests/gan-harness.test.js +++ b/tests/gan-harness.test.js @@ -82,6 +82,23 @@ const results = Object.freeze([ assert.strictEqual(result, '9.1'); }), + test('extract_score does not treat a Verdict threshold as a score', () => { + const feedback = '## Verdict: PASS / FAIL (threshold: 7.0)\n'; + const result = extractScore(feedback); + + assert.strictEqual(result, '0.0'); + }), + + test('extract_score prefers a TOTAL score after a Verdict threshold', () => { + const feedback = [ + '## Verdict: PASS / FAIL (threshold: 7.0)', + '| **TOTAL** | **1.0** | **9.0** |', + ].join('\n'); + const result = extractScore(feedback); + + assert.strictEqual(result, '9.0'); + }), + test('extract_score returns the fallback when no supported score exists', () => { const feedback = 'Other score: 9.9\n'; const result = extractScore(feedback); diff --git a/tests/scripts/codex-hooks.test.js b/tests/scripts/codex-hooks.test.js index 628a37da7..353c64efe 100644 --- a/tests/scripts/codex-hooks.test.js +++ b/tests/scripts/codex-hooks.test.js @@ -43,15 +43,20 @@ function cleanup(dirPath) { fs.rmSync(dirPath, { recursive: true, force: true }); } +function resolveBashExecutable(env = process.env) { + return env.BASH_PATH + || (process.platform === 'win32' && fs.existsSync('C:\\Program Files\\Git\\bin\\bash.exe') + ? 'C:\\Program Files\\Git\\bin\\bash.exe' + : fs.existsSync('/bin/bash') + ? '/bin/bash' + : 'bash'); +} + function runBash( scriptPath, { args = [], env = {}, cwd = repoRoot, input = undefined, preservePath = true } = {}, ) { - const bash = process.platform === 'win32' && fs.existsSync('C:\\Program Files\\Git\\bin\\bash.exe') - ? 'C:\\Program Files\\Git\\bin\\bash.exe' - : fs.existsSync('/bin/bash') - ? '/bin/bash' - : 'bash'; + const bash = resolveBashExecutable(); return spawnSync(bash, [scriptPath, ...args], { cwd, env: { @@ -132,6 +137,17 @@ const cacheManifestWithLocalRefs = { let passed = 0; let failed = 0; +if ( + test('shell test runner honors an explicit BASH_PATH override', () => { + assert.strictEqual( + resolveBashExecutable({ BASH_PATH: '/custom/git/bin/bash' }), + '/custom/git/bin/bash', + ); + }) +) + passed++; +else failed++; + function runHermeticPrePush({ failScript = null, includeCorepack = true,