fix(gan): distinguish scores from verdict thresholds

This commit is contained in:
haelyra
2026-08-29 14:24:16 -04:00
parent b2a8091440
commit 4c7e965209
3 changed files with 57 additions and 9 deletions

View File

@@ -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
}

View File

@@ -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);

View File

@@ -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,