diff --git a/.changeset/37928-skill-evals-any-of.md b/.changeset/37928-skill-evals-any-of.md new file mode 100644 index 00000000000..6a1bdfc77d8 --- /dev/null +++ b/.changeset/37928-skill-evals-any-of.md @@ -0,0 +1,15 @@ +--- +'@objectstack/scenarios': patch +'@objectstack/skills': patch +--- + +feat(qa): the skill-evals grader takes an any-of form, `must_contain_any`; `objectstack-ai` case 6 moves to it + +Clause-②: no +Metadata-protocol: none + +A skill eval case can now list `assertions.must_contain_any` beside `must_contain` and `must_not_contain`: a list of groups, each a list of tokens, and a group is met when at least one of its tokens is in the answer. Every group is required, so `[["a", "b"], ["c"]]` reads "(`a` or `b`) and `c`". Matching is the same as the other two forms: a literal, case-sensitive substring, nothing normalised, no model judge. The reader refuses a `must_contain_any` that is not a list of groups, a group that is empty or not a list of strings, a group holding an empty token, and a case with no token in any of the three forms. A failing run record names each unmet group whole in `unmetAny` (the key is absent when every group is met), and the round summary prints it in the missed column as `(none of: a / b)`. The runner runs from a checkout only; of `@objectstack/scenarios`, the published README is what changes. + +The case hash covers the groups only when a case has any, so every case without the form keeps its hash and `skill-evals --regrade` reads its earlier records as before. A case that gains a group, or has one edited, has a new hash: its earlier records are set apart, and it compares across rounds only after a re-run. + +`skills/objectstack-ai/evals/skills-tools-knowledge.json` case 6 (an operator script asked to approve AI pending actions on an API token) now requires one of `ai:approve`, `signed-in session`, `refused` or `never decides` in place of both `signed-in session` and `refused`, which failed correct answers that worded the refusal another way or answered in another language. Its prompt, reference answer and forbidden token are unchanged, and so is the skill text. diff --git a/packages/qa/scenarios/README.md b/packages/qa/scenarios/README.md index 4f9d2d3b3d2..838f716cdc8 100644 --- a/packages/qa/scenarios/README.md +++ b/packages/qa/scenarios/README.md @@ -995,7 +995,7 @@ wrapper, with no change to the runner. ## Running the published skills' eval cases — `skill-evals` Every published skill bundle carries eval cases (`skills/BUNDLE/evals/*.json`: a `prompt`, an `expected_output` and -`assertions.must_contain` / `must_not_contain`). `skill-evals` sends each case to the local Claude Code login twice, +`assertions.must_contain` / `must_contain_any` / `must_not_contain`). `skill-evals` sends each case to the local Claude Code login twice, once with the bundle installed and once without, and grades each answer by the case's own tokens. A trigger case asks instead whether the skill was loaded, and runs with the bundle installed beside its competitors only. It runs from this checkout only. It is not part of the published `bin` or `exports`, not a CI job and not a merge gate. The cases are the skill authors' and the runner never edits them. @@ -1025,8 +1025,13 @@ pnpm --filter @objectstack/scenarios skill-evals --self-test # the runner's o `--no-session-persistence`. A read outside the directory needs a permission no turn is given, and `-p` denies it. The skills built into Claude Code are present in both arms. - **Grading**: the answer is the result line's text, the reply a user reads. It passes when every `must_contain` token - is in it and no `must_not_contain` token is. Tokens match as literal, case-sensitive substrings, and no model judges - an answer. A turn whose init line shows the wrong arm is `invalid`: the with-skill arm does not list the bundle, or + is in it, every `must_contain_any` group has at least one of its tokens in it, and no `must_not_contain` token is. + Tokens match as literal, case-sensitive substrings in all three forms, nothing is normalised, and no model judges + an answer. `must_contain_any` is a list of groups, each a list of tokens, for a case whose correct answers do not + share one literal: `[["ai:approve", "signed-in session"], ["refused", "403"]]` reads "(the first or the second) and + (the third or the fourth)". The reader refuses a group that is empty or holds an empty token, and a case with no + token in any of the three forms. A failing record names each unmet group whole in `unmetAny` (the key is absent when + every group is met), and the summary's missed column prints it as `(none of: a / b)`. A turn whose init line shows the wrong arm is `invalid`: the with-skill arm does not list the bundle, or the no-skill arm lists one or launches one. A bundle whose `SKILL.md` sets `user-invocable: false` (`objectui`) is never in the init line's `skills` list, though the model can launch it. Its with-skill turns are graded, and each record's `armEvidence` says whether the turn launched the bundle (`launched`) or nothing in the stream shows it @@ -1060,11 +1065,12 @@ pnpm --filter @objectstack/scenarios skill-evals --self-test # the runner's o `evals/files/`, so the arms still differ only in the bundle. A case whose prompt states its context needs none. `--regrade DIR` applies the current rules to a recorded round's answers and arm facts. A changed record keeps the verdict its turn was first given as `regradedFrom`. Each record carries `caseHash`, a hash of its case's prompt and - token lists as the turn ran them. A case changed or removed since the round is set apart: it is not regraded, its + token lists as the turn ran them, its `must_contain_any` groups included when it has any: a case with none hashes + as it did before the form existed, and a case moved to it has a new hash. A case changed or removed since the round is set apart: it is not regraded, its records are left as they are, and the summary names it outside every pass rate. A record with no hash predates the hash; it is regraded against the case as it is now, and the summary counts it as unhashed. - **Records**: by default the round goes to `docs/qa/platform-checklist/runs/skill-evals/ROUND/` (git-ignored), or to - `--out`. It holds one `runs/*.json` per turn (verdict, missing and forbidden tokens, the answer, the skills listed + `--out`. It holds one `runs/*.json` per turn (verdict, missing and forbidden tokens, unmet any-of groups, the answer, the skills listed and launched, the skill files read, the served model, the CLI's notional cost and the rate-limit reading), `round.json` (environment, scope and the full per-case scores on both arms) and `summary.md`. The summary has one row per bundle (each arm's pass rate, the with-skill failing cases, and the cases where the no-skill arm scored at least as high) and then diff --git a/packages/qa/scenarios/src/skill-evals/cases.ts b/packages/qa/scenarios/src/skill-evals/cases.ts index e14447cd11a..50222878274 100644 --- a/packages/qa/scenarios/src/skill-evals/cases.ts +++ b/packages/qa/scenarios/src/skill-evals/cases.ts @@ -9,6 +9,10 @@ * { "skill_name": BUNDLE, "evals": [ { "id", "prompt", "expected_output", * "files": [], "assertions": { "must_contain": [..], "must_not_contain": [..] } } ] } * + * `assertions.must_contain_any` is the any-of form beside them: a list of + * groups, each a non-empty list of tokens, and a group is met by any one of + * its tokens (`[["ai:approve", "signed-in session"], ["refused", "403"]]`). + * * A TRIGGER case asks the other question about a skill: was it loaded when * it should be, and left alone when it should not. It is the same entry with * `"should_trigger": true | false` in place of `assertions`, and it is graded @@ -24,7 +28,8 @@ * * The reader is strict, never lenient: a file that does not parse, a case * whose prompt is not a string, an assertion list that is not a list of - * strings, a case with no assertion at all, a trigger case that also carries + * strings, a `must_contain_any` that is not a list of non-empty lists of + * non-empty strings, a case with no assertion at all, a trigger case that also carries * assertions, a `files` entry outside `evals/files/` or missing from it, and a * bundle whose trigger cases are all of one kind (all positive cannot show a * false load; all negative cannot show a missed one) are located refusals — @@ -50,6 +55,8 @@ export interface SkillEvalCase { expectedOutput?: string; mustContain: string[]; mustNotContain: string[]; + /** The `must_contain_any` groups, each met by any one of its tokens; absent ⇒ the case has none. */ + mustContainAny?: string[][]; /** * Set ⇒ a trigger case: graded on whether the with-skill turn loaded the * bundle (`true`: it should; `false`: it should not), on that arm only. Its @@ -84,6 +91,23 @@ export interface SkillEvalCatalog { const isStringList = (v: unknown): v is string[] => Array.isArray(v) && v.every((x) => typeof x === 'string'); +/** + * Why a `must_contain_any` value is refused; `undefined` ⇒ it is a list of + * groups, each a non-empty list of non-empty strings. An empty group can be + * met by no answer, and an empty token is in every answer, so either would + * decide the case whatever was answered. Pure. + */ +export function anyOfProblem(v: unknown): string | undefined { + if (!Array.isArray(v)) return '`assertions.must_contain_any` must be a list of groups, each a non-empty list of strings'; + for (const [i, group] of v.entries()) { + const at = `\`assertions.must_contain_any[${i}]\``; + if (!isStringList(group)) return `${at} is not a list of strings: a group lists the tokens any one of which meets it`; + if (group.length === 0) return `${at} is an empty group: no answer could meet it`; + if (group.includes('')) return `${at} holds an empty token: every answer contains it, so the group would be met by any answer`; + } + return undefined; +} + /** `BUNDLE/FILE_STEM#ID`. */ export const caseKey = (bundle: string, file: string, id: number | string): string => `${bundle}/${file.replace(/\.json$/, '')}#${id}`; @@ -91,15 +115,18 @@ export const caseKey = (bundle: string, file: string, id: number | string): stri * The case as a turn meets it: a hash of the prompt the turn is asked and the * two token lists its answer is graded on (`expected_output` is neither sent * nor graded, so it is left out), and, only when the case has them, its - * trigger kind and its `files` list (names, not contents) — so a behaviour - * case with no files hashes as it did before either existed. Every run record + * trigger kind, its `files` list (names, not contents) and its + * `must_contain_any` groups — so a behaviour case with none of the three + * hashes as it did before any existed, and a case that gains a group, or has + * one edited, hashes anew. Every run record * carries it, so `--regrade` can tell a case reworded since the round from the * case that ran. Pure. */ -export const hashCase = (c: Pick): string => { +export const hashCase = (c: Pick): string => { const extra = { ...(c.shouldTrigger !== undefined ? { shouldTrigger: c.shouldTrigger } : {}), ...(c.files?.length ? { files: c.files } : {}), + ...(c.mustContainAny?.length ? { mustContainAny: c.mustContainAny } : {}), }; const parts: unknown[] = [c.prompt, c.mustContain, c.mustNotContain]; if (Object.keys(extra).length) parts.push(extra); @@ -167,6 +194,7 @@ export function parseEvalFile(bundle: string, file: string, text: string): { cas } let mc: string[] = []; let mnc: string[] = []; + let any: string[][] = []; const trigger = e.should_trigger; if (trigger !== undefined) { if (typeof trigger !== 'boolean') { @@ -183,17 +211,24 @@ export function parseEvalFile(bundle: string, file: string, text: string): { cas refusals.push({ path: at, message: '`assertions` is not an object' }); return; } - const { must_contain: rawMc = [], must_not_contain: rawMnc = [] } = a as Record; + const { must_contain: rawMc = [], must_not_contain: rawMnc = [], must_contain_any: rawAny = [] } = a as Record; if (!isStringList(rawMc) || !isStringList(rawMnc)) { refusals.push({ path: at, message: '`assertions.must_contain` / `must_not_contain` must each be a list of strings' }); return; } - if (rawMc.length + rawMnc.length === 0) { - refusals.push({ path: at, message: 'asserts nothing: a case with no `must_contain` and no `must_not_contain` would pass every answer' }); + const badAny = anyOfProblem(rawAny); + if (badAny) { + refusals.push({ path: at, message: badAny }); + return; + } + const groups = rawAny as string[][]; + if (rawMc.length + rawMnc.length + groups.length === 0) { + refusals.push({ path: at, message: 'asserts nothing: a case with no `must_contain`, no `must_contain_any` and no `must_not_contain` would pass every answer' }); return; } mc = rawMc; mnc = rawMnc; + any = groups; } const key = caseKey(bundle, file, id); if (seen.has(key)) { @@ -210,6 +245,7 @@ export function parseEvalFile(bundle: string, file: string, text: string): { cas ...(typeof e.expected_output === 'string' ? { expectedOutput: e.expected_output } : {}), mustContain: mc, mustNotContain: mnc, + ...(any.length ? { mustContainAny: any } : {}), ...(typeof trigger === 'boolean' ? { shouldTrigger: trigger } : {}), ...(files.length ? { files } : {}), }); diff --git a/packages/qa/scenarios/src/skill-evals/grade.ts b/packages/qa/scenarios/src/skill-evals/grade.ts index 424635aca82..33487785e24 100644 --- a/packages/qa/scenarios/src/skill-evals/grade.ts +++ b/packages/qa/scenarios/src/skill-evals/grade.ts @@ -2,16 +2,24 @@ /** * The grader the cases already declare, applied mechanically: an answer - * passes when every `must_contain` token appears in it and no + * passes when every `must_contain` token appears in it, every + * `must_contain_any` group has at least one of its tokens in it, and no * `must_not_contain` token does. A token is matched as a literal, * case-sensitive substring of the answer text — the tokens are code * spellings (`$icontains`, `engine.find('account'`), where case is meaning. * No model judges an answer, and nothing is normalised. + * + * The any-of form is for a case whose correct answers do not share one + * literal: each group lists the spellings a correct answer may use for one + * thing, and the groups are all required, so `[[a, b], [c]]` reads + * "(`a` or `b`) and `c`". */ export interface GradeAssertions { mustContain: readonly string[]; mustNotContain: readonly string[]; + /** `must_contain_any` groups; absent ⇒ none. */ + mustContainAny?: ReadonlyArray; } export interface GradeResult { @@ -20,12 +28,18 @@ export interface GradeResult { missing: string[]; /** `must_not_contain` tokens the answer carries, in the case's order. */ forbidden: string[]; + /** + * `must_contain_any` groups with none of their tokens in the answer, each + * group whole and in the case's order. Present only when a group is unmet. + */ + unmetAny?: string[][]; } export type Grader = (answer: string, assertions: GradeAssertions) => GradeResult; -export const gradeAnswer: Grader = (answer, { mustContain, mustNotContain }) => { +export const gradeAnswer: Grader = (answer, { mustContain, mustNotContain, mustContainAny = [] }) => { const missing = mustContain.filter((t) => !answer.includes(t)); const forbidden = mustNotContain.filter((t) => answer.includes(t)); - return { pass: missing.length === 0 && forbidden.length === 0, missing, forbidden }; + const unmetAny = mustContainAny.filter((group) => !group.some((t) => answer.includes(t))).map((group) => [...group]); + return { pass: missing.length === 0 && forbidden.length === 0 && unmetAny.length === 0, missing, forbidden, ...(unmetAny.length ? { unmetAny } : {}) }; }; diff --git a/packages/qa/scenarios/src/skill-evals/run.ts b/packages/qa/scenarios/src/skill-evals/run.ts index 5e6484af3a5..aac7be78bc4 100644 --- a/packages/qa/scenarios/src/skill-evals/run.ts +++ b/packages/qa/scenarios/src/skill-evals/run.ts @@ -170,6 +170,8 @@ export interface SkillEvalRunRecord { missing: string[]; /** `must_not_contain` tokens the answer carries. */ forbidden: string[]; + /** `must_contain_any` groups with none of their tokens in the answer; absent ⇒ every group was met, or the case has none. */ + unmetAny?: string[][]; /** The answer graded; absent ⇒ the turn gave none. */ answer?: string; /** Bundles of the catalog the init line listed. */ @@ -228,6 +230,7 @@ export interface Verdict { reason?: string; missing: string[]; forbidden: string[]; + unmetAny?: string[][]; armEvidence?: ArmEvidence; trigger?: TriggerReading; } @@ -306,7 +309,7 @@ export function verdictOf(c: SkillEvalCase, arm: Arm, f: VerdictFacts, catalog: return { verdict: 'error', reason: `no answer to grade: the result line is \`${f.resultSubtype ?? 'absent'}\``, ...none, ...ev }; } const g = grade(f.answer, c); - return { verdict: g.pass ? 'pass' : 'fail', missing: g.missing, forbidden: g.forbidden, ...ev }; + return { verdict: g.pass ? 'pass' : 'fail', missing: g.missing, forbidden: g.forbidden, ...(g.unmetAny?.length ? { unmetAny: g.unmetAny } : {}), ...ev }; } const applyVerdict = (base: T, v: Verdict) => ({ @@ -315,6 +318,7 @@ const applyVerdict = (base: T, v: Verdict) => ({ ...(v.reason ? { reason: v.reason } : {}), missing: v.missing, forbidden: v.forbidden, + ...(v.unmetAny?.length ? { unmetAny: v.unmetAny } : {}), ...(v.armEvidence ? { armEvidence: v.armEvidence } : {}), ...(v.trigger ? { trigger: v.trigger } : {}), }); @@ -386,7 +390,7 @@ export function caseDrift(rec: Pick, c: SkillEva */ export function regradeRecord(rec: SkillEvalRunRecord, c: SkillEvalCase, catalog: CatalogView, grade: Grader = gradeAnswer): SkillEvalRunRecord { if (caseDrift(rec, c) === 'changed') throw new Error(`--regrade: \`${rec.key}\` has changed since the turn ran (record ${rec.caseHash}, now ${hashCase(c)}); a changed case is set apart, never regraded`); - const { reason: _reason, armEvidence: _ev, regradedFrom: _was, trigger: _trigger, ...rest } = rec; + const { reason: _reason, armEvidence: _ev, regradedFrom: _was, trigger: _trigger, unmetAny: _unmetAny, ...rest } = rec; const v = verdictOf(c, rec.arm, { process: rec.process, initSeen: rec.reason !== NO_INIT_LINE, bundlesLoaded: rec.bundlesLoaded, skillsInvoked: rec.skillsInvoked, ...(rec.skillFilesRead ? { skillFilesRead: rec.skillFilesRead } : {}), ...(rec.installed ? { installed: rec.installed } : {}), ...(rec.resultSubtype ? { resultSubtype: rec.resultSubtype } : {}), ...(rec.answer !== undefined ? { answer: rec.answer } : {}) }, catalog, grade); const out = applyVerdict(rest, v); const asRun = rec.regradedFrom ?? rec.verdict; diff --git a/packages/qa/scenarios/src/skill-evals/self-test.ts b/packages/qa/scenarios/src/skill-evals/self-test.ts index 34bb083cb0e..75993bfc0ba 100644 --- a/packages/qa/scenarios/src/skill-evals/self-test.ts +++ b/packages/qa/scenarios/src/skill-evals/self-test.ts @@ -12,17 +12,18 @@ * that passes every answer, say) reds the grader rows, and the suite pins that. */ +import { createHash } from 'node:crypto'; import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { ApiBillingRefusedError } from '../runner/driver.js'; import { armArgs, placeCaseFiles, prepareArmWorkdir } from './arms.js'; -import { loadSkillEvalCatalog, notUserInvocable, parseEvalFile, selectBundles, type SkillEvalCase } from './cases.js'; +import { hashCase, loadSkillEvalCatalog, notUserInvocable, parseEvalFile, selectBundles, type SkillEvalCase } from './cases.js'; import { parseSkillEvalArgs } from './cli.js'; import { type Grader, gradeAnswer } from './grade.js'; import { installedFor, judgeTurn, planRound, preflight, regradeRecords, type SkillEvalRunRecord } from './run.js'; -import { summariseRound } from './summary.js'; +import { renderSummaryMarkdown, summariseRound } from './summary.js'; /** Row label → minimum cases registered. A row is a battery; deleting one must red. */ export const SELF_TEST_BATTERIES = Object.freeze({ @@ -31,6 +32,12 @@ export const SELF_TEST_BATTERIES = Object.freeze({ 'grader: a must_not_contain token present → FAIL, naming it': 1, 'grader: a case-only difference → FAIL (tokens match case-sensitively)': 1, 'grader: an empty answer against a must_contain → FAIL': 1, + 'grader: a must_contain_any group met by its second token → PASS': 1, + 'grader: a must_contain_any group with none of its tokens → FAIL, naming the group': 1, + 'grader: beside a met must_contain_any group, must_contain and must_not_contain decide as before': 1, + 'reader: a must_contain_any that is not a list of non-empty string lists → REFUSED; groups alone are an assertion': 1, + 'hash: a case with no must_contain_any hashes as before the form; a group added or edited → a new hash': 1, + 'summary: an unmet must_contain_any group is named whole in the with-skill missed column': 1, 'reader: a case asserting nothing → REFUSED, never graded': 1, 'reader: a non-string assertion token → REFUSED': 1, 'reader: the catalog under test loads cases with no refusal': 1, @@ -63,7 +70,7 @@ export const SELF_TEST_BATTERIES = Object.freeze({ }); /** The roster's own size, pinned: a deleted row takes its floor with it otherwise. */ -export const SELF_TEST_BATTERY_FLOOR = 34; +export const SELF_TEST_BATTERY_FLOOR = 40; let selfTestReachedVerdict = false; /** Whether the last {@link runSelfTest} reached its verdict line. */ @@ -108,6 +115,9 @@ const stream = (o: { skills: string[]; answer?: string; subtype?: string; invoke const exited = (stdout: string) => ({ stdout, process: { elapsedMs: 1, exit: 0, timedOut: false, timeoutMs: 1000 } }); +/** The fixture case with one any-of group beside its two lists: either operator spelling meets it. */ +const anyOfCase = (over: Partial = {}): SkillEvalCase => fixtureCase({ mustContain: ["engine.find('account'"], mustContainAny: [['$icontains', '$endsWith']], ...over }); + const GOOD = "engine.find('account', { where: { email: { $icontains: '@company.com' } } })"; export function runSelfTest(deps: SelfTestDeps): SelfTestResult { @@ -161,6 +171,78 @@ export function runSelfTest(deps: SelfTestDeps): SelfTestResult { label: 'grader: an empty answer against a must_contain → FAIL', run: () => (grade('', fixtureCase()).pass ? 'an empty answer was graded PASS' : true), }, + { + label: 'grader: a must_contain_any group met by its second token → PASS', + run: () => { + const g = grade(GOOD.replace('$icontains', '$endsWith'), anyOfCase()); + return g.pass && g.unmetAny === undefined ? true : `an answer carrying the group's second token was graded pass=${g.pass} unmetAny=${JSON.stringify(g.unmetAny)}`; + }, + }, + { + label: 'grader: a must_contain_any group with none of its tokens → FAIL, naming the group', + run: () => { + // `$EndsWith` differs from the group's token only in case: the any-of form matches as literally as the all-of one. + const g = grade(GOOD.replace('$icontains', '$EndsWith'), anyOfCase()); + return !g.pass && g.missing.length === 0 && g.forbidden.length === 0 && JSON.stringify(g.unmetAny) === '[["$icontains","$endsWith"]]' + ? true + : `expected FAIL unmetAny [[$icontains, $endsWith]] alone, got pass=${g.pass} missing=[${g.missing.join(', ')}] unmetAny=${JSON.stringify(g.unmetAny)}`; + }, + }, + { + label: 'grader: beside a met must_contain_any group, must_contain and must_not_contain decide as before', + run: () => { + const lacksAllOf = grade("engine.find('contact', { where: { email: { $icontains: 'x' } } })", anyOfCase()); + const carriesForbidden = grade(`${GOOD} // or { $contains: 'x' }`, anyOfCase()); + // Two groups are both required: the second one unmet fails an answer that meets the first. + const secondGroup = grade(GOOD, anyOfCase({ mustContainAny: [['$icontains', '$endsWith'], ['orderBy', 'sort:']] })); + const ok = + !lacksAllOf.pass && lacksAllOf.missing.join() === "engine.find('account'" && lacksAllOf.unmetAny === undefined && + !carriesForbidden.pass && carriesForbidden.forbidden.join() === '$contains:' && carriesForbidden.unmetAny === undefined && + !secondGroup.pass && JSON.stringify(secondGroup.unmetAny) === '[["orderBy","sort:"]]'; + return ok ? true : `got all-of pass=${lacksAllOf.pass} missing=[${lacksAllOf.missing.join(', ')}]; forbidden pass=${carriesForbidden.pass} forbidden=[${carriesForbidden.forbidden.join(', ')}]; second group pass=${secondGroup.pass} unmetAny=${JSON.stringify(secondGroup.unmetAny)}`; + }, + }, + { + label: 'reader: a must_contain_any that is not a list of non-empty string lists → REFUSED; groups alone are an assertion', + run: () => { + const read = (assertions: unknown) => parseEvalFile('demo-skill', 'x.json', JSON.stringify({ evals: [{ id: 1, prompt: 'p', assertions }] })); + const bad = [{ must_contain_any: 'x' }, { must_contain_any: ['x'] }, { must_contain_any: [[]] }, { must_contain_any: [['x', 1]] }, { must_contain_any: [['x', '']] }, { must_contain: ['x'], must_contain_any: [['a'], []] }, { must_contain_any: [] }].map(read); + const notRefused = bad.findIndex((r) => r.cases.length !== 0 || r.refusals.length !== 1); + if (notRefused !== -1) return `malformed must_contain_any #${notRefused} was read as ${bad[notRefused]!.cases.length} case(s), ${bad[notRefused]!.refusals.length} refusal(s)`; + const good = read({ must_contain_any: [['a', 'b'], ['c']] }); + return good.refusals.length === 0 && JSON.stringify(good.cases[0]?.mustContainAny) === '[["a","b"],["c"]]' && good.cases[0]?.mustContain.length === 0 + ? true + : `a case asserting only groups was read as ${good.cases.length} case(s), ${good.refusals.length} refusal(s), groups ${JSON.stringify(good.cases[0]?.mustContainAny)}`; + }, + }, + { + label: 'hash: a case with no must_contain_any hashes as before the form; a group added or edited → a new hash', + run: () => { + const c = fixtureCase(); + // The hash a round recorded before the form gave this case: the prompt and the two lists, nothing else. + const before = `sha256:${createHash('sha256').update(JSON.stringify([c.prompt, c.mustContain, c.mustNotContain])).digest('hex')}`; + const withGroup = hashCase({ ...c, mustContainAny: [['a', 'b']] }); + const edited = hashCase({ ...c, mustContainAny: [['a', 'c']] }); + const was = judge(c, 'with-skill', stream({ skills: ['demo-skill'], answer: GOOD })); + const out = regradeRecords([was], [c.key], [{ ...c, mustContainAny: [['a', 'b']] }], { bundles: ['demo-skill'], unlisted: [] }, grade); + return hashCase(c) === before && hashCase({ ...c, mustContainAny: [] }) === before && withGroup !== before && edited !== withGroup && out.records.length === 0 && out.setApart.changed.join() === c.key + ? true + : `expected the group-less hash unchanged (${hashCase(c) === before}), a group to re-key (${withGroup !== before}), an edit to re-key (${edited !== withGroup}) and the earlier record set apart [${out.setApart.changed.join()}]`; + }, + }, + { + label: 'summary: an unmet must_contain_any group is named whole in the with-skill missed column', + run: () => { + const c = anyOfCase(); + const failing = stream({ skills: ['demo-skill'], answer: "engine.find('account', { where: { email: { $startsWith: 'a' } } })" }); + const recs = [judge(c, 'with-skill', failing), judge(c, 'with-skill', failing), judge(c, 'with-skill', stream({ skills: ['demo-skill'], answer: GOOD }))]; + const s = summariseRound([c], recs, []); + const md = renderSummaryMarkdown(s, { title: 't', lines: [] }); + return recs[0]!.verdict === 'fail' && JSON.stringify(recs[0]!.unmetAny) === '[["$icontains","$endsWith"]]' && recs[2]!.unmetAny === undefined && JSON.stringify(s.cases[0]!.withSkillUnmetAny) === '[["$icontains","$endsWith"]]' && md.includes('(none of: `$icontains` / `$endsWith`)') + ? true + : `got verdict ${recs[0]!.verdict}, record unmetAny ${JSON.stringify(recs[0]!.unmetAny)}, summary ${JSON.stringify(s.cases[0]!.withSkillUnmetAny)}, rendered: ${md.split('\n').find((l) => l.includes(c.key)) ?? 'no row'}`; + }, + }, { label: 'reader: a case asserting nothing → REFUSED, never graded', run: () => { diff --git a/packages/qa/scenarios/src/skill-evals/summary.ts b/packages/qa/scenarios/src/skill-evals/summary.ts index 73725b3b886..fc6e3e1a0a5 100644 --- a/packages/qa/scenarios/src/skill-evals/summary.ts +++ b/packages/qa/scenarios/src/skill-evals/summary.ts @@ -33,6 +33,8 @@ export interface CaseScore { /** Tokens the with-skill arm missed or carried, over its failing turns (deduplicated). */ withSkillMissing: string[]; withSkillForbidden: string[]; + /** `must_contain_any` groups the with-skill arm left unmet, over its failing turns (deduplicated, each group whole). */ + withSkillUnmetAny: string[][]; } export interface BundleSummary { @@ -99,7 +101,7 @@ export function summariseRound( notRun: ReadonlyArray<{ case: SkillEvalCase; arm: Arm }>, ): RoundSummary { const byCase = new Map(); - for (const c of cases) if (c.shouldTrigger === undefined) byCase.set(c.key, { key: c.key, bundle: c.bundle, withSkill: empty(), noSkill: empty(), withSkillMissing: [], withSkillForbidden: [] }); + for (const c of cases) if (c.shouldTrigger === undefined) byCase.set(c.key, { key: c.key, bundle: c.bundle, withSkill: empty(), noSkill: empty(), withSkillMissing: [], withSkillForbidden: [], withSkillUnmetAny: [] }); const byTrigger = new Map(); for (const c of cases) if (c.shouldTrigger !== undefined) byTrigger.set(c.key, { key: c.key, bundle: c.bundle, shouldTrigger: c.shouldTrigger, tally: empty(), loadedBySkillTool: 0, loadedByReadOnly: 0, othersLoaded: {} }); let cost = 0; @@ -123,6 +125,7 @@ export function summariseRound( if (r.arm === 'with-skill' && r.verdict === 'fail') { for (const t of r.missing) if (!s.withSkillMissing.includes(t)) s.withSkillMissing.push(t); for (const t of r.forbidden) if (!s.withSkillForbidden.includes(t)) s.withSkillForbidden.push(t); + for (const g of r.unmetAny ?? []) if (!s.withSkillUnmetAny.some((x) => JSON.stringify(x) === JSON.stringify(g))) s.withSkillUnmetAny.push(g); } } for (const j of notRun) { @@ -211,7 +214,9 @@ export function renderSummaryMarkdown(s: RoundSummary, head: { title: string; li out.push(`| **all** | ${s.cases.length} | ${pct(s.totals.withSkill)} | ${pct(s.totals.noSkill)} | ${s.bundles.reduce((n, b) => n + b.withSkillFailures.length, 0)} | ${s.bundles.reduce((n, b) => n + b.noSkillAtLeastWithSkill.length, 0)} | ${outOf(s.totals.withSkill)} / ${outOf(s.totals.noSkill)} |`); out.push('', '## Per case', '', '| case | with-skill | no-skill | with-skill missed | with-skill carried forbidden |', '|:--|--:|--:|:--|:--|'); for (const c of s.cases) { - out.push(`| ${c.key} | ${pct(c.withSkill)} | ${pct(c.noSkill)} | ${c.withSkillMissing.map(code).join(' ')} | ${c.withSkillForbidden.map(code).join(' ')} |`); + // An unmet any-of group is named whole, after the all-of tokens: `(none of: a / b)`. + const missed = [...c.withSkillMissing.map(code), ...c.withSkillUnmetAny.map((g) => `(none of: ${g.map(code).join(' / ')})`)]; + out.push(`| ${c.key} | ${pct(c.withSkill)} | ${pct(c.noSkill)} | ${missed.join(' ')} | ${c.withSkillForbidden.map(code).join(' ')} |`); } } if (tr.cases.length) { diff --git a/skills/objectstack-ai/evals/skills-tools-knowledge.json b/skills/objectstack-ai/evals/skills-tools-knowledge.json index 4e5fc58b3a5..52e98ef2132 100644 --- a/skills/objectstack-ai/evals/skills-tools-knowledge.json +++ b/skills/objectstack-ai/evals/skills-tools-knowledge.json @@ -57,7 +57,7 @@ "expected_output": "Does not decide on the token: the script may list the queue (`client.ai.pendingActions.list({ status: 'pending' })`), but approving or rejecting an item is the person's own act, done in the app on their signed-in session by the person the assistant call ran as. An API key or token is refused on the decide door, even the person's own, and so is an AI identity; another user's `ai:approve` does not decide the item, and the model's own confirmation does not count. The script reports or notifies the stale items instead; where a second person must approve the write, that is the approvals engine's `held` outcome.", "files": [], "assertions": { - "must_contain": ["signed-in session", "refused"], + "must_contain_any": [["ai:approve", "signed-in session", "refused", "never decides"]], "must_not_contain": ["pendingActions.approve("] } },