diff --git a/.github/workflows/evals.yml b/.github/workflows/evals.yml index 4cac0e61..82d36b4f 100644 --- a/.github/workflows/evals.yml +++ b/.github/workflows/evals.yml @@ -16,6 +16,7 @@ on: paths: - "packages/evals/**" - ".github/workflows/evals.yml" + - ".github/workflows/scripts/eval-check.js" pull_request: types: [opened, synchronize, reopened, labeled] @@ -33,6 +34,7 @@ jobs: const evalPaths = [ 'packages/evals/', '.github/workflows/evals.yml', + '.github/workflows/scripts/eval-check.js', ]; function setRun(run, reason) { @@ -91,6 +93,7 @@ jobs: WARDEN_OPENROUTER_API_KEY: ${{ secrets.WARDEN_OPENROUTER_API_KEY }} WARDEN_ANTHROPIC_API_KEY: ${{ secrets.WARDEN_ANTHROPIC_API_KEY }} WARDEN_OPENAI_API_KEY: ${{ secrets.WARDEN_OPENAI_API_KEY }} + # Sits under recent scores (0.77-0.82). Below it, the check is neutral. EVAL_SCORE_BASELINE: "0.75" steps: - uses: actions/checkout@v4 @@ -154,106 +157,5 @@ jobs: if: ${{ !cancelled() && steps.verify.outcome == 'success' }} with: script: | - const fs = require('fs'); - const path = require('path'); - const baseline = Number(process.env.EVAL_SCORE_BASELINE ?? '0.75'); - - if (!Number.isFinite(baseline) || baseline < 0 || baseline > 1) { - throw new Error(`Invalid EVAL_SCORE_BASELINE: ${process.env.EVAL_SCORE_BASELINE}`); - } - - const resultsPath = path.resolve(process.cwd(), 'eval-results.json'); - let vitestResults; - try { - vitestResults = JSON.parse(fs.readFileSync(resultsPath, 'utf-8')); - } catch (error) { - if (error.code === 'ENOENT') { - throw new Error(`Eval results file not found at ${resultsPath}`); - } - throw new Error(`Failed to read eval results: ${error.message}`); - } - - const evalResults = []; - for (const testFile of vitestResults.testResults || []) { - for (const test of testFile.assertionResults || []) { - if (test.meta?.eval) { - evalResults.push({ - name: test.fullName || test.title, - avgScore: test.meta.eval.avgScore ?? null, - scores: test.meta.eval.scores || [], - passed: test.status === 'passed', - duration: test.duration, - }); - } - } - } - - if (evalResults.length === 0) { - throw new Error('No eval results were recorded.'); - } - - const scores = evalResults.map((result) => result.avgScore ?? 0); - const avgScore = scores.reduce((sum, score) => sum + score, 0) / scores.length; - const green = scores.filter((score) => score >= 0.75).length; - const yellow = scores.filter((score) => score >= 0.5 && score < 0.75).length; - const red = scores.filter((score) => score < 0.5).length; - const conclusion = avgScore >= baseline ? 'success' : 'failure'; - - function formatScore(score) { - if (score >= 0.75) return `green ${score.toFixed(2)}`; - if (score >= 0.5) return `yellow ${score.toFixed(2)}`; - return `red ${score.toFixed(2)}`; - } - - const title = `Eval Score: ${avgScore.toFixed(2)} (${green} green, ${yellow} yellow, ${red} red)`; - const summary = [ - '## Overall Statistics', - '', - `- **Total Evaluations**: ${evalResults.length}`, - `- **Average Score**: ${formatScore(avgScore)}`, - `- **Baseline Threshold**: ${baseline.toFixed(2)}`, - '', - '### Score Distribution', - `- Green (>=0.75): ${green} evals`, - `- Yellow (0.50-0.74): ${yellow} evals`, - `- Red (<0.50): ${red} evals`, - ].join('\n'); - - const details = [ - '## Individual Eval Scores', - '', - ...evalResults - .sort((a, b) => (b.avgScore ?? 0) - (a.avgScore ?? 0)) - .map((result) => { - const score = result.avgScore ?? 0; - const status = result.passed ? 'PASS' : 'FAIL'; - let line = `${status} **${result.name}**: ${formatScore(score)}`; - const firstScore = result.scores[0]; - if (!result.passed || score < 0.75) { - const rationale = firstScore?.metadata?.rationale; - if (rationale) { - line += `\n - ${rationale}`; - } - } - return line; - }), - ].join('\n'); - - const headSha = context.payload.pull_request?.head?.sha ?? context.sha; - await github.rest.checks.create({ - owner: context.repo.owner, - repo: context.repo.repo, - name: 'Evaluation Results', - head_sha: headSha, - status: 'completed', - conclusion, - output: { - title, - summary, - text: details, - }, - }); - - if (conclusion === 'failure') { - core.setFailed(`Eval score ${avgScore.toFixed(2)} is below baseline ${baseline.toFixed(2)}.`); - } + const { createEvalCheck } = await import(`${process.env.GITHUB_WORKSPACE}/.github/workflows/scripts/eval-check.js`); + await createEvalCheck({ github, context, core }); diff --git a/.github/workflows/scripts/eval-check.js b/.github/workflows/scripts/eval-check.js new file mode 100644 index 00000000..7f99c49a --- /dev/null +++ b/.github/workflows/scripts/eval-check.js @@ -0,0 +1,111 @@ +import fs from 'node:fs'; +import path from 'node:path'; + +/** + * Publish the Evaluation Results check from eval-results.json. Green at or + * above EVAL_SCORE_BASELINE, neutral below it. + */ +export async function createEvalCheck({ github, context, core }) { + const baseline = Number(process.env.EVAL_SCORE_BASELINE ?? '0.75'); + + if (!Number.isFinite(baseline) || baseline < 0 || baseline > 1) { + throw new Error(`Invalid EVAL_SCORE_BASELINE: ${process.env.EVAL_SCORE_BASELINE}`); + } + + const resultsPath = path.resolve(process.cwd(), 'eval-results.json'); + let vitestResults; + try { + vitestResults = JSON.parse(fs.readFileSync(resultsPath, 'utf-8')); + } catch (error) { + if (error.code === 'ENOENT') { + throw new Error(`Eval results file not found at ${resultsPath}`); + } + throw new Error(`Failed to read eval results: ${error.message}`); + } + + const evalResults = []; + for (const testFile of vitestResults.testResults || []) { + for (const test of testFile.assertionResults || []) { + if (test.meta?.eval) { + evalResults.push({ + name: test.fullName || test.title, + avgScore: test.meta.eval.avgScore ?? null, + scores: test.meta.eval.scores || [], + passed: test.status === 'passed', + duration: test.duration, + }); + } + } + } + + if (evalResults.length === 0) { + throw new Error('No eval results were recorded.'); + } + + const scores = evalResults.map((result) => result.avgScore ?? 0); + const avgScore = scores.reduce((sum, score) => sum + score, 0) / scores.length; + const green = scores.filter((score) => score >= 0.75).length; + const yellow = scores.filter((score) => score >= 0.5 && score < 0.75).length; + const red = scores.filter((score) => score < 0.5).length; + // Below baseline is neutral, never a failure. Missing or empty results throw above. + const conclusion = avgScore >= baseline ? 'success' : 'neutral'; + + function formatScore(score) { + if (score >= 0.75) return `green ${score.toFixed(2)}`; + if (score >= 0.5) return `yellow ${score.toFixed(2)}`; + return `red ${score.toFixed(2)}`; + } + + const title = `Eval Score: ${avgScore.toFixed(2)} (${green} green, ${yellow} yellow, ${red} red)`; + const summary = [ + '## Overall Statistics', + '', + `- **Total Evaluations**: ${evalResults.length}`, + `- **Average Score**: ${formatScore(avgScore)}`, + `- **Baseline Threshold**: ${baseline.toFixed(2)}`, + '', + '### Score Distribution', + `- Green (>=0.75): ${green} evals`, + `- Yellow (0.50-0.74): ${yellow} evals`, + `- Red (<0.50): ${red} evals`, + ].join('\n'); + + const details = [ + '## Individual Eval Scores', + '', + ...evalResults + .sort((a, b) => (b.avgScore ?? 0) - (a.avgScore ?? 0)) + .map((result) => { + const score = result.avgScore ?? 0; + const status = result.passed ? 'PASS' : 'FAIL'; + let line = `${status} **${result.name}**: ${formatScore(score)}`; + const firstScore = result.scores[0]; + if (!result.passed || score < 0.75) { + const rationale = firstScore?.metadata?.rationale; + if (rationale) { + line += `\n - ${rationale}`; + } + } + return line; + }), + ].join('\n'); + + const headSha = context.payload.pull_request?.head?.sha ?? context.sha; + await github.rest.checks.create({ + owner: context.repo.owner, + repo: context.repo.repo, + name: 'Evaluation Results', + head_sha: headSha, + status: 'completed', + conclusion, + output: { + title, + summary, + text: details, + }, + }); + + if (conclusion === 'neutral') { + core.warning(`Eval score ${avgScore.toFixed(2)} is below baseline ${baseline.toFixed(2)}.`); + } +} diff --git a/packages/evals/INTERNAL.md b/packages/evals/INTERNAL.md index 31999ee1..97faecda 100644 --- a/packages/evals/INTERNAL.md +++ b/packages/evals/INTERNAL.md @@ -36,8 +36,10 @@ records it when it does not. The raw Vitest eval command can exit non-zero when individual evals miss. CI still records the JSON report, publishes a vitest-evals job summary and workflow -annotations for per-case reporting, and gates the workflow on the aggregate -`Evaluation Results` baseline. The baseline is `0.75`. +annotations for per-case reporting, and publishes the aggregate +`Evaluation Results` check. At or above the `0.75` baseline the check is green; +below it the check is neutral, and CI does not fail. Missing or empty results +still fail. Individual misses are useful harness debt. For a verified real bug, write the expected `should_find` for the bug Warden should catch even if the current diff --git a/packages/evals/README.md b/packages/evals/README.md index 0cad074c..9898fde0 100644 --- a/packages/evals/README.md +++ b/packages/evals/README.md @@ -263,8 +263,8 @@ matching `WARDEN__API_KEY` secret to the workflow env. Individual eval misses are expected while we tune the harness. CI publishes a vitest-evals job summary and workflow annotations for per-case reporting, then -gates the workflow on the aggregate `Evaluation Results` score. The current -baseline threshold is `0.75`. +publishes the aggregate `Evaluation Results` score check. At or above the `0.75` +baseline it is green; below it the check is neutral and CI does not fail. ## Security Corpus