diff --git a/.github/scripts/update-remote-pins.test.mjs b/.github/scripts/update-remote-pins.test.mjs new file mode 100644 index 0000000..df6d53f --- /dev/null +++ b/.github/scripts/update-remote-pins.test.mjs @@ -0,0 +1,129 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { randomUUID } from "node:crypto"; +import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { resolve } from "node:path"; +import { fileURLToPath, pathToFileURL } from "node:url"; +import { parse } from "yaml"; + +const root = fileURLToPath(new URL("../../", import.meta.url)); +const evalDirectory = resolve(root, "evals/marketplace-maintainer/skills/update-remote-pins"); +const pinsTest = existsSync(evalDirectory) ? test : test.skip; +const label = "Reported the upstream change and offline limit"; + +async function fixture(t) { + const spec = parse(readFileSync(resolve(evalDirectory, "eval.yaml"), "utf8")); + const stimulus = spec.stimuli.find((item) => item.name === "update-remote-pins-uses-reviewed-release"); + const directory = resolve(root, ".github/scripts", `.remote-pins-test-${randomUUID()}`); + const workspace = resolve(directory, "workspace"); + mkdirSync(workspace, { recursive: true }); + t.after(() => rmSync(directory, { recursive: true, force: true })); + for (const file of stimulus.agent_environment.files) { + cpSync(resolve(evalDirectory, file.src), resolve(workspace, file.dest), { recursive: true }); + } + for (const file of spec.grading_environment.files) { + const destination = resolve(directory, file.dest); + mkdirSync(resolve(destination, ".."), { recursive: true }); + cpSync(resolve(evalDirectory, file.src), destination); + } + const { evaluate } = await import(pathToFileURL(resolve(directory, ".grading/grader.mjs"))); + const { score } = await import(pathToFileURL(resolve(directory, ".grading/common.mjs"))); + const catalog = JSON.parse(readFileSync(resolve(workspace, "marketplace.json"), "utf8")); + const entry = catalog.plugins.find((item) => item.name === "outside-notes"); + Object.assign(entry, { version: "1.1.0" }); + Object.assign(entry.source, { sha: "b".repeat(40), ref: "v1.1.0" }); + writeFileSync(resolve(workspace, "marketplace.json"), JSON.stringify(catalog, null, 2)); + return (output) => score("marketplace-maintainer-remote", evaluate({ output, events: [] }, workspace)); +} + +const offline = "This used the recorded offline snapshot, not live GitHub verification."; + +pinsTest("update-remote-pins accepts the fixture's upstream change in exact and paraphrased wording", async (t) => { + const grade = await fixture(t); + for (const summary of [ + "Upstream change: Add support for empty note lists.", + "v1.1.0 now handles an empty notes list without errors.", + "The only change: the notes list can now be empty.", + "It adds support for empty lists of notes.", + "Note lists that are empty are now supported.", + "Lists with no notes are now handled.", + "- v1.1.0 adds support for **empty** note lists.", + "v1.1.0 adds empty-note-list support.", + "Empty note lists no longer cause errors.", + "Added support for empty note lists; verified offline, not against live GitHub.", + "Added support for previously unsupported empty note lists.", + "Empty note lists are now supported, so callers don't need to handle them specially.", + "Empty note lists weren't supported before; v1.1.0 now supports them.", + "Previously not supported, empty note lists are now supported.", + "Added support for empty note lists, which were not supported in v1.0.0.", + "Added support for empty note lists, but nested lists are not supported.", + "Added support for empty note lists, but it does not support nested lists.", + "Added support for empty note lists, but notes with attachments are not supported.", + "v1.1.0 no longer rejects empty note lists.", + "Empty note lists weren't supported in v1.0.0; v1.1.0 supports them.", + "Added support for empty\nnote lists.", + "Empty note lists weren't supported before; now they are supported.", + "Adds support for empty note lists (previously not supported).", + "Adds support for empty note lists (not supported before).", + "Adds support for empty note lists that were not supported in v1.0.0.", + "Empty note lists (not allowed in v1.0.0) are now accepted.", + "Now supports empty note lists that previously weren't handled.", + "Added support for empty note lists that were not previously supported.", + ]) { + const result = grade(`${summary} No new hooks or dependencies. ${offline}`); + assert.equal(result.passed, true, `${summary}: ${result.evidence}`); + } +}); + +pinsTest("update-remote-pins rejects missing or unrelated upstream changes and a missing offline limit", async (t) => { + const grade = await fixture(t); + for (const [output, reason] of [ + [`Pinned outside-notes to v1.1.0. No new hooks or dependencies. ${offline}`, /no empty-note-list change/], + [`Updated the synthetic outside notes plugin; see the release notes list. Nothing is empty. ${offline}`, /no empty-note-list change/], + [`The release notes list is empty. ${offline}`, /no empty-note-list change/], + [`The release-notes list is empty. ${offline}`, /no empty-note-list change/], + [`Note lists must not be empty. ${offline}`, /no empty-note-list change/], + [`Lists with no notes are not supported. ${offline}`, /no empty-note-list change/], + [`v1.1.0 doesn't support empty note lists. ${offline}`, /no empty-note-list change/], + [`Lists with no notes aren\u2019t supported. ${offline}`, /no empty-note-list change/], + [`Lists with no notes aren't handled. ${offline}`, /no empty-note-list change/], + [`Empty note lists were supported before but are not supported now. ${offline}`, /no empty-note-list change/], + [`Note lists that are empty are no longer supported. ${offline}`, /no empty-note-list change/], + [`v1.1.0 now does not support empty note lists. ${offline}`, /no empty-note-list change/], + [`Empty note lists are not supported; v1.1.0 now supports headings. ${offline}`, /no empty-note-list change/], + [`Empty note lists weren't supported before; v1.1.0 now supports headings. ${offline}`, /no empty-note-list change/], + [`Empty note lists weren't supported in v1.0.0; v1.1.0 still doesn't support them. ${offline}`, /no empty-note-list change/], + [`Empty note lists weren't supported before; they are still not supported. ${offline}`, /no empty-note-list change/], + [`Empty note lists are still not supported. ${offline}`, /no empty-note-list change/], + [`Release notes were updated. ${offline}`, /no empty-note-list change/], + [`v1.1.0 adds support for empty note lists, but they are not supported on Windows. ${offline}`, /no empty-note-list change/], + [`Empty note lists were previously not supported. ${offline}`, /no empty-note-list change/], + [`v1.1.0 no longer supports empty note lists that were supported in v1.0.0. ${offline}`, /no empty-note-list change/], + [`Empty note lists are not supported now or before. ${offline}`, /no empty-note-list change/], + [`Empty note lists were previously not supported and headings are now supported. ${offline}`, /no empty-note-list change/], + [`The release notes list is empty. ${offline}`, /no empty-note-list change/], + [`The release\nnotes list is empty. ${offline}`, /no empty-note-list change/], + ["Upstream change: Add support for empty note lists. Verified on GitHub.", /no offline limit/], + ]) { + const result = grade(output); + assert.equal(result.passed, false, output); + assert.ok(result.evidence.includes(label), result.evidence); + assert.match(result.evidence, reason); + } +}); + +pinsTest("update-remote-pins failure evidence names missing conditions without echoing model output", async (t) => { + const grade = await fixture(t); + const token = `ghp_${"A".repeat(36)}`; + const result = grade(`Pinned it with ${token}. {"token": "synthetic-opaque-value"}`); + assert.equal(result.passed, false); + assert.match(result.evidence, /\(no empty-note-list change, no offline limit\)/); + assert.ok(!result.evidence.includes(token) && !result.evidence.includes("synthetic-opaque-value"), result.evidence); +}); + +pinsTest("shared check() drops failure details that aren't short condition labels", async () => { + const { check, score } = await import(pathToFileURL(resolve(root, "evals/_shared/graders/common.mjs")).href); + const token = `ghp_${"A".repeat(36)}`; + const evidence = score("synthetic", [check("Kept", false, `saw ${token}`), check("Named", false, "no offline limit")]).evidence; + assert.equal(evidence, "Kept; Named (no offline limit)"); +}); diff --git a/evals/_shared/graders/common.mjs b/evals/_shared/graders/common.mjs index 9f4fc51..1009c1d 100644 --- a/evals/_shared/graders/common.mjs +++ b/evals/_shared/graders/common.mjs @@ -3,7 +3,12 @@ import { resolve } from "node:path"; import { fileURLToPath } from "node:url"; const real = (path) => { try { return realpathSync(path); } catch { return resolve(path); } }; -export const check = (label, passed) => ({ label, passed: Boolean(passed) }); +// An optional detail names why a check failed. Only short lowercase condition labels pass, so model output, +// tokens or paths never reach evidence. +const safeDetail = /^[a-z][a-z ,-]{0,99}$/; +export const check = (label, passed, detail) => ({ + label, passed: Boolean(passed), ...(typeof detail === "string" && safeDetail.test(detail) ? { detail } : {}), +}); // Real paths, because Node resolves import.meta.url through symlinks but not argv. export const isMain = (url) => Boolean(process.argv[1]) && real(resolve(process.argv[1])) === real(fileURLToPath(url)); export const normalize = (text) => text.replaceAll("\r\n", "\n"); @@ -36,7 +41,7 @@ export function score(name, checks) { return { name, kind: "code", passed: failures.length === 0, score: (checks.length - failures.length) / checks.length, - evidence: failures.length ? failures.map((item) => item.label).join("; ") : "All contract assertions passed.", + evidence: failures.length ? failures.map((item) => item.detail ? `${item.label} (${item.detail})` : item.label).join("; ") : "All contract assertions passed.", }; } diff --git a/evals/marketplace-maintainer/skills/update-remote-pins/grader.mjs b/evals/marketplace-maintainer/skills/update-remote-pins/grader.mjs index 1e7e4b3..ad4ed6c 100644 --- a/evals/marketplace-maintainer/skills/update-remote-pins/grader.mjs +++ b/evals/marketplace-maintainer/skills/update-remote-pins/grader.mjs @@ -1,16 +1,72 @@ import { check, isMain, json, runGrade } from "./common.mjs"; +// The fixture's only upstream change is "Add support for empty note lists"; accept equivalent +// wordings within one affirmative sentence, but not release notes or unrelated mentions of notes or emptiness. +const note = String.raw`\bnotes?`; +// Only a negation that denies the change counts ("not supported", "must not be empty"), not "no longer cause errors", +// "previously unsupported" or "callers don't need to handle them". +const negated = /\b(?:not|never|no\s+longer|cannot|can't|don't|doesn't|isn't|aren't|wasn't|weren't|won't)\s+(?:(?!(?:reject|fail|error|break|crash|throw)\w*\s)\w+\s+){0,2}?(?:support(?:ed|s)?|allow(?:ed|s)?|accept(?:ed|s)?|handled|(?:be\s+)?empty)\b|(? new RegExp(pattern, "i")); +const mention = emptyNoteLists.map((pattern) => `(?:${pattern.source})`).join("|"); +const affirmsMention = new RegExp(String.raw`\b(?:now\s+)?(?:add(?:s|ed)?\s+support\s+for|supports?|supported|accepts?|accepted|handles?|handled|allows?|allowed)\s+(?:${mention})|(?:${mention})\s*(?:\(\s*\)\s*)?(?:are|is)\s+now\s+(?:supported|accepted|handled|allowed)\b`, "i"); + +function affirmsDespiteHistoricalDenial(clause) { + let historicalOnly = true; + const rest = clause.replace(historicalDenial, (match, before, after) => { + const denial = match.slice(before?.length ?? 0); + const past = before || after || /\b(?:previously|formerly|originally|earlier)\b/i.test(denial); + if (!past || /^no\s+longer/i.test(denial)) historicalOnly = false; + return ""; + }); + return historicalOnly && affirmsMention.test(rest); +} + +export function reportsUpstreamChange(output) { + // Drop Markdown emphasis, straighten curly apostrophes and join compound words so "**empty** note lists", + // "aren’t" and "empty-note-list" match their plain forms; + // join soft-wrapped lines (but not list items, headings or paragraphs) and fold "release notes" (even across spaces or a soft wrap) into one word before splitting so it never matches. + const plain = output.replace(/\r?\n(?![ \t]*(?:[-*+][ \t]|\d+[.)][ \t]|#|\r?\n|$))/g, " ").replace(/[*_`]/g, "").replace(/[\u2018\u2019]/g, "'").replace(/(?<=\w)-(?=\w)/g, " ") + .replace(/\brelease\s+notes?\b/gi, "releasenotes"); + return plain.split(/(?<=[.!?])\s+|\n+/).some(reportsInSentence); +} + +function reportsInSentence(sentence) { + const clauses = sentence.split(/[;,:]|(?<=\s)(?:but|while|whereas)(?=\s)/i).map((clause) => clause.trim()).filter(Boolean); + const mentions = (clause) => emptyNoteLists.some((pattern) => pattern.test(clause)); + const denies = (clause) => negated.test(clause) && !historical.test(clause); + if (clauses.some((clause) => denies(clause) && (mentions(clause) || aboutLists.test(clause)))) return false; + return clauses.some((clause) => mentions(clause) && (!negated.test(clause) || affirmsDespiteHistoricalDenial(clause))) + || (clauses.some((clause) => mentions(clause) && negated.test(clause)) + && clauses.some((clause) => affirmsPronoun.test(clause) && !negated.test(clause))); +} + export function evaluate(trajectory, workspace) { const catalog = json(workspace, "marketplace.json"); if (!Array.isArray(catalog?.plugins)) return [check("Preserved a valid catalog", false)]; const entry = catalog.plugins.find((item) => item.name === "outside-notes"); + const change = reportsUpstreamChange(trajectory.output); + const offline = /offline|recorded/i.test(trajectory.output); + const missing = [!change && "no empty-note-list change", !offline && "no offline limit"].filter(Boolean); return [ check("Updated the exact reviewed SHA, ref and version", entry?.source?.sha === "b".repeat(40) && entry?.source?.ref === "v1.1.0" && entry?.version === "1.1.0" && entry?.source?.repo === "fixture-org/outside-notes"), check("Preserved the unrelated local entry", catalog.plugins.some((item) => item.name === "sample-notes" && item.version === "1.0.0")), - check("Reported the upstream change and offline limit", /empty note lists/i.test(trajectory.output) - && /offline|recorded/i.test(trajectory.output)), + check("Reported the upstream change and offline limit", change && offline, missing.join(", ")), ]; }