From 6b7d52c2e26f9d1f9304fd77bd5242a57f66378e Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 07:05:42 +0000 Subject: [PATCH 1/4] fix(scenarios): grade a withheld field's absence claim by the round's schema masking Claude-Session: https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY Co-authored-by: Claude --- packages/qa/scenarios/src/export/record.ts | 6 ++ .../qa/scenarios/src/export/transcript.ts | 2 + packages/qa/scenarios/src/runner/cli.ts | 2 +- .../qa/scenarios/src/runner/orchestrate.ts | 26 ++++++-- packages/qa/scenarios/src/score/index.ts | 8 +++ .../scenarios/src/score/scenario-run-grade.ts | 61 +++++++++++++++---- 6 files changed, 85 insertions(+), 20 deletions(-) diff --git a/packages/qa/scenarios/src/export/record.ts b/packages/qa/scenarios/src/export/record.ts index 7960283cd27..8a97e8fc4e9 100644 --- a/packages/qa/scenarios/src/export/record.ts +++ b/packages/qa/scenarios/src/export/record.ts @@ -67,6 +67,12 @@ export const ScenarioRunRecordSchema = z.looseObject({ version: z.string().optional(), replayOf: z.looseObject({ driver: z.string().min(1), version: z.string().optional() }).optional(), }), + /** + * `runner/scorecard.ts` `RunMeta.schemaMasking`: `off` on a masking-off round, absent on a default one. The + * transcript re-grades each recorded reply under it (`buildTranscript`), so a value the runner never writes is + * refused here rather than read as either. + */ + schemaMasking: z.literal('off').optional(), }), evidenceDir: z.string().min(1), results: z.array(z.looseObject({ id: z.string().min(1), verdict: VerdictSchema })), diff --git a/packages/qa/scenarios/src/export/transcript.ts b/packages/qa/scenarios/src/export/transcript.ts index 59ddcb46546..7be106c84a7 100644 --- a/packages/qa/scenarios/src/export/transcript.ts +++ b/packages/qa/scenarios/src/export/transcript.ts @@ -113,6 +113,8 @@ export function buildTranscript(original: LoadedScenario, record: ScenarioRunRec question: q.question, ...(q.persona ? { persona: q.persona, hidden: { values: hiddenValues(scenario, q.persona) } } : {}), objectLabels: labels, + // Graded as the run graded it: under the masking the record states, never the exporter's environment. + ...(record.env.schemaMasking === 'off' ? { schemaMasking: 'off' as const } : {}), turn: recorded, }); if (!same(regrade, q.grade)) throw new TranscriptRefusal(`the recorded reply for \`${key}\` grades differently from the run record: the recording is not this run's`); diff --git a/packages/qa/scenarios/src/runner/cli.ts b/packages/qa/scenarios/src/runner/cli.ts index 199b7e56ffc..db493b8f7b1 100644 --- a/packages/qa/scenarios/src/runner/cli.ts +++ b/packages/qa/scenarios/src/runner/cli.ts @@ -593,7 +593,7 @@ export async function main(argv: readonly string[]): Promise { console.log(`dates: the card's ${loaded.card.asOf} is run as ${scenario.card.asOf}, every card date moved by the same days`); } publishedVersions = new Set(); - const cardRun = await runCard(scenario, driver, ops, { modes: args.modes, iterateRun: args.iterateRun, admin: ADMIN, ...(template ? { templateArtifact: template } : {}), ...(args.askRepeats !== undefined ? { askRepeats: args.askRepeats } : {}), ...(promptChoice ? { promptChoice } : {}) }); + const cardRun = await runCard(scenario, driver, ops, { modes: args.modes, iterateRun: args.iterateRun, admin: ADMIN, ...(template ? { templateArtifact: template } : {}), ...(args.askRepeats !== undefined ? { askRepeats: args.askRepeats } : {}), ...(promptChoice ? { promptChoice } : {}), ...(schemaMasking === 'off' ? { schemaMasking } : {}) }); const packages: PackageSource = workspace ? workspace.source : { source: 'published', versions: [...publishedVersions].sort() }; // The card file the run graded, as it was loaded (`CardStamp`): the record and the scorecard name its hash. const card = loadedCardStamp(loaded); diff --git a/packages/qa/scenarios/src/runner/orchestrate.ts b/packages/qa/scenarios/src/runner/orchestrate.ts index 417abc34092..fa631f415b4 100644 --- a/packages/qa/scenarios/src/runner/orchestrate.ts +++ b/packages/qa/scenarios/src/runner/orchestrate.ts @@ -120,6 +120,7 @@ import { type PromptChoice, } from './prompts.js'; import { derivedFields, driftText, lookupKey, requiredLookups, RESTORE_UNCOMPARED, RESTORE_UNWRITTEN, rowDrift, seedPlan, type HeldRow, type RowDrift, type SeedLookup } from './seed.js'; +import type { SchemaMasking } from './schema-masking.js'; import type { ParsedTurn } from './transcript.js'; // ── What the orchestrator needs from the outside world ────────────────────── @@ -203,6 +204,15 @@ export interface RunOptions { * card instead. */ promptChoice?: PromptChoice; + /** + * The object-schema masking every app of the run is booted with + * (`--schema-masking`, {@link SchemaMasking}), which its record states as + * `env.schemaMasking`. Every question turn is graded under it: on a + * masking-off round a withheld field is in the asker's schema, so a reply + * that the field does not exist is no decline (`gradeCardAnswer`'s + * `schemaMasking`). Absent ⇒ `on`, the default, graded as before. + */ + schemaMasking?: SchemaMasking; } // ── The record of one card ────────────────────────────────────────────────── @@ -1711,7 +1721,9 @@ export async function restoreSeededRows( * The guardrails are graded over every turn that ran, each ask and each * confirmation turn included. * Every question and operation turn is sent in the prompt choice `choice` - * ({@link RunOptions.promptChoice}); absent ⇒ the default prompts. + * ({@link RunOptions.promptChoice}); absent ⇒ the default prompts. Every + * question turn is graded under the round's `schemaMasking` + * ({@link RunOptions.schemaMasking}); absent ⇒ masked. */ export async function runHalf( scenario: LoadedScenario, @@ -1723,6 +1735,7 @@ export async function runHalf( askRepeats = 1, choice?: PromptChoice, fresh?: FreshCopy, + schemaMasking?: SchemaMasking, ): Promise { assertAskRepeats(askRepeats); const { card } = scenario; @@ -1806,6 +1819,7 @@ export async function runHalf( question: q.id, ...(persona ? { persona, hidden: { values: hiddenValues(scenario, persona) } } : {}), ...(objectLabels ? { objectLabels } : {}), + ...(schemaMasking !== undefined ? { schemaMasking } : {}), turn, }); } catch (e) { @@ -2046,7 +2060,7 @@ async function scratchMode(original: LoadedScenario, driver: AgentDriver, ops: P // A build whose authoring turn did not finish is not measured: no seed, no Run, no iterate on it. if (mode.build.notMeasured) return { mode }; const builtArtifact = ops.readArtifact(dir); - if (builtArtifact !== undefined) mode.run = await withApp(ops, dir, mode.findings, (app) => runHalf(scenario, app, driver, { ...ref, phase: 'run' }, labels, builtArtifact, opts.askRepeats, opts.promptChoice, freshBoot(ops, dir))); + if (builtArtifact !== undefined) mode.run = await withApp(ops, dir, mode.findings, (app) => runHalf(scenario, app, driver, { ...ref, phase: 'run' }, labels, builtArtifact, opts.askRepeats, opts.promptChoice, freshBoot(ops, dir), opts.schemaMasking)); const iterated = iteratedScenario(scenario); const build = await buildHalf(iterated, dir, ops, async () => (await driver.author({ ...ref, phase: 'iterate', step: 'author', cwd: dir, prompt: iteratePrompt(card, opts.promptChoice), tier: card.tier })).turn, iterated); @@ -2057,7 +2071,7 @@ async function scratchMode(original: LoadedScenario, driver: AgentDriver, ops: P const after = ops.readArtifact(dir); mode.iterate = { build, ...(builtArtifact !== undefined && after !== undefined ? { changeSize: changeSize(builtArtifact, after) } : {}) }; if (opts.iterateRun !== false && after !== undefined) { - const run = await withApp(ops, dir, mode.findings, (app) => runHalf(scenario, app, driver, { ...ref, phase: 'iterate-run' }, labels, after, opts.askRepeats, opts.promptChoice, freshBoot(ops, dir))); + const run = await withApp(ops, dir, mode.findings, (app) => runHalf(scenario, app, driver, { ...ref, phase: 'iterate-run' }, labels, after, opts.askRepeats, opts.promptChoice, freshBoot(ops, dir), opts.schemaMasking)); if (run) mode.iterate.run = run; } return { mode, ...(buildPassed(mode.build) ? { verified: builtArtifact } : {}) }; @@ -2201,7 +2215,7 @@ async function templateMode(original: LoadedScenario, driver: AgentDriver, ops: // The app holds the agent's iterate, made live through its doors, which a host booted again would not hold: // a fresh copy is a blank host with what the app serves now installed the same way (`iteratedManifest`). const fresh = copyOf(iteratedManifest(manifest, served)); - mode.iterate.run = await runHalf(scenario, app, driver, { card: card.id, mode: 'template', phase: 'iterate-run' }, labels, served, opts.askRepeats, opts.promptChoice, fresh); + mode.iterate.run = await runHalf(scenario, app, driver, { card: card.id, mode: 'template', phase: 'iterate-run' }, labels, served, opts.askRepeats, opts.promptChoice, fresh, opts.schemaMasking); }); return mode; } @@ -2322,7 +2336,7 @@ async function doorMode(original: LoadedScenario, driver: AgentDriver, ops: Proj // What the environment serves now is the build, as a person meets it. const served = withoutItems(await app.metadataAsArtifact(DOOR_COLLECTIONS), baseline); scoreInto(build, scenario, scenario, served); - mode.run = await runHalf(scenario, app, driver, { card: card.id, mode: 'door', phase: 'run' }, labels, served, opts.askRepeats, opts.promptChoice); + mode.run = await runHalf(scenario, app, driver, { card: card.id, mode: 'door', phase: 'run' }, labels, served, opts.askRepeats, opts.promptChoice, undefined, opts.schemaMasking); } catch (e) { mode.findings.push(`boot/run: ${errText(e)}`); } finally { @@ -2355,7 +2369,7 @@ async function askMode(original: LoadedScenario, driver: AgentDriver, ops: Proje mode, verified, async (app, { fresh }) => { - mode.run = await runHalf(scenario, app, driver, { card: scenario.card.id, mode: 'ask', phase: 'run' }, labels, verified!.artifact, opts.askRepeats, opts.promptChoice, fresh); + mode.run = await runHalf(scenario, app, driver, { card: scenario.card.id, mode: 'ask', phase: 'run' }, labels, verified!.artifact, opts.askRepeats, opts.promptChoice, fresh, opts.schemaMasking); }, { managedFallback: true }, ); diff --git a/packages/qa/scenarios/src/score/index.ts b/packages/qa/scenarios/src/score/index.ts index 312edd81211..8164f099578 100644 --- a/packages/qa/scenarios/src/score/index.ts +++ b/packages/qa/scenarios/src/score/index.ts @@ -97,6 +97,13 @@ export interface CardAnswer { objectLabels?: Readonly>; /** Relative tolerance for every figure; absent ⇒ exact. */ tol?: number; + /** + * The object-schema masking the answer's app ran with: the round's + * `env.schemaMasking` (`--schema-masking`). With `off` a withheld field is in + * the asker's schema, so a reply that it does not exist is no decline + * (`gradePersonaRun`'s `schemaMasking`). Absent ⇒ `on`, the default. + */ + schemaMasking?: 'on' | 'off'; } type CardQuestion = LoadedScenario['card']['run']['questions'][number]; @@ -178,6 +185,7 @@ export function gradeCardAnswer(scenario: LoadedScenario, answer: CardAnswer): P reading: figureReadingOf(card, q), ...(inScopeFigures ? { inScopeFigures } : {}), ...(readableRows ? { readableRows } : {}), + ...(answer.schemaMasking !== undefined ? { schemaMasking: answer.schemaMasking } : {}), }, answer.turn, ); diff --git a/packages/qa/scenarios/src/score/scenario-run-grade.ts b/packages/qa/scenarios/src/score/scenario-run-grade.ts index 16bc317fd36..48068bfacd5 100644 --- a/packages/qa/scenarios/src/score/scenario-run-grade.ts +++ b/packages/qa/scenarios/src/score/scenario-run-grade.ts @@ -670,16 +670,18 @@ export function truthFigures(truth: Truth, object: string, label: string, tol?: * asker ("Stock levels aren't tracked", "Budgets aren't visible to the buyer * role"). So does a write the reply says it withheld ({@link WITHHELD_ACT}). * - * Built from two halves: {@link ASKER_DECLINE}, the wordings that say the - * asker cannot have the answer, and the ones that say the value is not there - * to give ({@link NO_VALUE_EN}, {@link NO_VALUE_ZH}). A `withheld` question reads the first half only + * Built from three parts: {@link ASKER_DECLINE}, the wordings that say the + * asker cannot have the answer; the one that says the app keeps no such data + * ({@link UNTRACKED_EN}); and the ones that say the value is not there to give + * ({@link NO_VALUE_EN}, {@link NO_VALUE_ZH}). A `withheld` question never reads + * the last, and reads the second only under schema masking * ({@link declinesWithheld}). */ const ASKER_DECLINE_ZH = '无法|不能|无权|没有权限|权限不足|看不到|不可见|不提供'; const ASKER_DECLINE_EN = "cannot|can't|can ?not|could ?not|couldn't|unable|not able|not permitted|not allowed|not authori[sz]ed|permission denied|" + 'no (?:read )?(?:access|permission)|(?:do not|don\'t|does not|doesn\'t) have (?:the )?(?:read )?(?:access|permission)|' + - 'lacks? (?:the )?(?:read )?(?:access|permission)|(?:is|are)(?:n[\'’]t| not) tracked|' + + 'lacks? (?:the )?(?:read )?(?:access|permission)|' + '(?:is|are)(?:n[\'’]t| not) (?:visible|shown|shared|available) to (?:you|your|the|this|a|an|buyers?|employees?)|hidden from (?:you|your|the|this)'; /** * The value is not there to give: "no data", "not available", "not recorded". @@ -691,8 +693,16 @@ const ASKER_DECLINE_EN = */ const NO_VALUE_ZH = '未记录|没有记录|没有相关数据'; const NO_VALUE_EN = "not available|isn't available|is not recorded|not recorded|no data"; +/** + * The data is not tracked: "Stock levels aren't tracked", "Travel budgets + * aren't tracked in this app". Says the app keeps no such field, as + * {@link UNRECORDED} does, so a `withheld` question reads it only where the + * asker's schema lacks the field ({@link declinesWithheld}). + */ +const UNTRACKED_EN = "(?:is|are)(?:n['’]t| not) tracked"; +const UNTRACKED = new RegExp(`\\b(?:${UNTRACKED_EN})\\b`, 'i'); const ASKER_DECLINE = new RegExp(`${ASKER_DECLINE_ZH}|\\b(?:${ASKER_DECLINE_EN})\\b`, 'i'); -const DECLINE = new RegExp(`${ASKER_DECLINE_ZH}|${NO_VALUE_ZH}|\\b(?:${ASKER_DECLINE_EN}|${NO_VALUE_EN})\\b`, 'i'); +const DECLINE = new RegExp(`${ASKER_DECLINE_ZH}|${NO_VALUE_ZH}|\\b(?:${ASKER_DECLINE_EN}|${UNTRACKED_EN}|${NO_VALUE_EN})\\b`, 'i'); /** * The code a door answers a caller it does not let read (ADR-0112). A literal @@ -804,14 +814,30 @@ export function declines(replyText: string): boolean { * {@link NO_VALUE_ZH}). A caller served the whole schema asks for a field it * may not read: "not visible to you" passes, and "blank", "empty", "no data" * or "not available" fails, since each says the field holds nothing when it - * holds values the asker may not see. A field the asker's schema lacks - * ({@link UNRECORDED}: "The Project object has no hours field") still reads as - * one, which under default schema masking is what the asker sees. + * holds values the asker may not see. + * + * A reply that says the field does not exist ({@link UNRECORDED}: "The Project + * object has no hours field", "The data doesn't record a travel budget"; + * {@link UNTRACKED}: "Travel budgets aren't tracked") reads by the round's + * `schemaMasking`. Masked (`on`, the default), the asker's schema lacks the + * field, so that is what the asker sees, and it declines. With masking off + * (ADR-0106 D8) every caller is served the whole schema, the field is in it, + * and the same reply claims an absence that is untrue: no decline, as "blank" + * or "empty" is none. */ -function declinesWithheld(replyText: string): boolean { - return ASKER_DECLINE.test(replyText) || UNRECORDED.test(replyText) || WITHHELD_ACT.test(replyText); +function declinesWithheld(replyText: string, schemaMasking: SchemaMaskingMode): boolean { + if (ASKER_DECLINE.test(replyText) || WITHHELD_ACT.test(replyText)) return true; + return schemaMasking === 'on' && (UNRECORDED.test(replyText) || UNTRACKED.test(replyText)); } +/** + * The object-schema masking the turn's app ran with: `on` (each caller served + * only the fields it may read, ADR-0106) or `off` (the D8 opt-out, a + * masking-off round: every caller served the whole schema). The runner's + * `SchemaMasking`, spelled here so the grade imports nothing of the runner. + */ +type SchemaMaskingMode = 'on' | 'off'; + export interface PersonaRunInput { /** The question's object — what a correct reply's citation names. */ object: string; @@ -842,6 +868,14 @@ export interface PersonaRunInput { * Absent ⇒ none. */ readableRows?: readonly ReadableRow[]; + /** + * The object-schema masking the turn's app ran with: the round's + * `env.schemaMasking`. Read on a `withheld` truth only, where a reply that + * says the field does not exist declines under masking and is no decline + * with it off ({@link declinesWithheld}). Absent ⇒ `on`, the default every + * record made without the stamp ran with. + */ + schemaMasking?: 'on' | 'off'; } /** A row the persona may read, as {@link PersonaRunInput.readableRows} hands it to the grader. */ @@ -944,8 +978,9 @@ const USER_ACCOUNTS = /\b(?:user|login|sign-in) accounts?\b|用户账[号户]/i; * * - A `withheld` truth means "must not reveal": `correct` is a decline * that says the asker may not have it ({@link declinesWithheld}; "no - * data" or "not available" is no such decline), and every all-rows figure - * the reply states is a leak. + * data" or "not available" is no such decline, and with schema masking + * off neither is "has no such field"), and every all-rows figure the + * reply states is a leak. * - An `unanswerable` truth: `correct` is a decline that states no figure * the data cannot support — every number the reply writes is one some * tool output of the turn carries ({@link carriedNumbers}; a unit number @@ -984,7 +1019,7 @@ export function gradePersonaRun(input: PersonaRunInput, turn: RunTranscript): Pe const reply = numbersIn(turn.replyText); if (input.personaTruth.kind === 'withheld') { - const declined = declinesWithheld(turn.replyText) || refusedWithoutFigure(turn); + const declined = declinesWithheld(turn.replyText, input.schemaMasking ?? 'on') || refusedWithoutFigure(turn); const leaks = leaksOf({ figures: [] }, input.hidden, turn); const served = leaks.some((l) => !l.startsWith('reply')); const nouns = nounPattern([input.object, ...(input.objectLabels?.[input.object] ?? [])]); From ba0685ece67ac44d53944b60bd97880e3b0eadad Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 07:11:24 +0000 Subject: [PATCH 2/4] test(scenarios): pin the withheld absence claim by masking, through the runner and the transcript Claude-Session: https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY Co-authored-by: Claude --- .../qa/scenarios/test/export/exporter.test.ts | 36 ++++++++- packages/qa/scenarios/test/export/fixture.ts | 4 +- .../scenarios/test/runner/orchestrate.test.ts | 32 ++++++++ .../test/score/scenario-run-grade.test.ts | 78 +++++++++++++++++++ 4 files changed, 148 insertions(+), 2 deletions(-) diff --git a/packages/qa/scenarios/test/export/exporter.test.ts b/packages/qa/scenarios/test/export/exporter.test.ts index b6f35ca393e..10e31e5440e 100644 --- a/packages/qa/scenarios/test/export/exporter.test.ts +++ b/packages/qa/scenarios/test/export/exporter.test.ts @@ -25,7 +25,7 @@ import { readRunRecords, redactWorkDir, ScenarioRunRecordSchema, type ScenarioRu import { buildTranscript, mergeRecordings, renderTranscript } from '../../src/export/transcript.js'; import type { CaptureScreenshots } from '../../src/export/screenshots.js'; import { main, parseExportArgs, renderSummary } from '../../src/export/cli.js'; -import { stepKey, type Recording } from '../../src/runner/driver.js'; +import { stepKey, type AgentDriver, type Recording } from '../../src/runner/driver.js'; import type { LoadedScenario } from '../../src/loader.js'; import type { ScenarioOrigin, ScenarioTier } from '../../src/schema.js'; import { CARD_ID, loadAllCards, loadCrm, runCrm, tempDir, writeRecord, type FixtureRun } from './fixture.js'; @@ -879,3 +879,37 @@ describe('exportGallery — a record that holds an ask mode (`--modes ask`, #337 expect(judgeRecord(asRecord(edited)).reasons).toEqual([`${CARD_ID}.scratch.run question tech_accounts: not measured — seed: refused`]); }); }); + +describe('buildTranscript — a masking-off round re-grades each reply under the masking its record states', () => { + // `partner_user` may not read accounts. On a masking-off round the object is + // in its schema, so "the app doesn't record accounts" is no decline there, + // and the run graded it so. The transcript re-grades every recorded reply and + // refuses one that grades otherwise: it reads the masking off the record. + const absent = (scripted: AgentDriver): AgentDriver => ({ + info: () => scripted.info(), + author: (task) => scripted.author(task), + ask: async (task) => (task.persona === 'partner_user' && task.step === 'account_count' ? { replyText: "The app doesn't record accounts.", toolCalls: [], meta: { resultSubtype: 'success' } } : scripted.ask(task)), + }); + + it('shows the grade the run gave under `env.schemaMasking: off`; the same record without the stamp is refused', async () => { + const fx = await runCrm({ modes: ['scratch'], iterateRun: false, schemaMasking: 'off', wrap: absent }); + const record = asRecord(fx.record); + expect(record.env.schemaMasking).toBe('off'); + const t = buildTranscript(fx.scenario, record, mergeRecordings([fx.recording])); + const asked = t.halves[0]!.turns.find((x) => x.question === 'account_count' && x.persona === 'partner_user')!; + expect(asked.answer!.replyText).toBe("The app doesn't record accounts."); + expect(asked.grade).toMatchObject({ correct: false, declined: false, problems: ['did not decline a question the persona may not see'] }); + + const unstamped = asRecord({ ...fx.record, env: { ...(fx.record.env as Record), schemaMasking: undefined } }); + const key = stepKey({ card: CARD_ID, mode: 'scratch', phase: 'run', step: 'account_count', persona: 'partner_user' }); + expect(() => buildTranscript(fx.scenario, unstamped, mergeRecordings([fx.recording]))).toThrow( + `the recorded reply for \`${key}\` grades differently from the run record: the recording is not this run's`, + ); + }); + + it('a record stating a masking the runner never writes is refused when read', async () => { + const fx = await runCrm({ modes: ['scratch'], iterateRun: false }); + expect(ScenarioRunRecordSchema.safeParse({ ...fx.record, env: { ...(fx.record.env as Record), schemaMasking: 'on' } }).success).toBe(false); + expect(ScenarioRunRecordSchema.safeParse(fx.record).success).toBe(true); + }); +}); diff --git a/packages/qa/scenarios/test/export/fixture.ts b/packages/qa/scenarios/test/export/fixture.ts index 3c914fa4520..9ab7e523b64 100644 --- a/packages/qa/scenarios/test/export/fixture.ts +++ b/packages/qa/scenarios/test/export/fixture.ts @@ -287,6 +287,7 @@ export async function runCrm( /** The prefix of every API key the booted apps issue; default `key-`. */ keyPrefix?: string; /** Wraps the scripted model (e.g. to send its turns through another driver); the recording records what this answers. */ wrap?: (scripted: AgentDriver) => AgentDriver; /** How many times each question turn is asked (`--ask-repeats`); left to the runner's default when absent. */ askRepeats?: number; + /** A masking-off round (`--schema-masking off`): graded under it, and the record stamps it as `env.schemaMasking`. */ schemaMasking?: 'off'; } = {}, ): Promise { const scenario = loadCrm(); @@ -311,10 +312,11 @@ export async function runCrm( admin: ADMIN, ...(opts.iterateRun === false ? { iterateRun: false } : {}), ...(opts.askRepeats !== undefined ? { askRepeats: opts.askRepeats } : {}), + ...(opts.schemaMasking ? { schemaMasking: opts.schemaMasking } : {}), }); const date = opts.date ?? '2026-11-06'; const packages = opts.packages ?? { source: 'published', versions: ['18.3.0'] }; - const record = runRecord({ run: `${date}-scenario-${CARD_ID}`, date, framework: 'abc1234', packages, driver: driver.info(), runner: 'scenario-runner', evidenceDir: work }, cardRun); + const record = runRecord({ run: `${date}-scenario-${CARD_ID}`, date, framework: 'abc1234', packages, driver: driver.info(), runner: 'scenario-runner', evidenceDir: work, ...(opts.schemaMasking ? { schemaMasking: opts.schemaMasking } : {}) }, cardRun); return { scenario, work, cardRun, record, recording: driver.recording }; } diff --git a/packages/qa/scenarios/test/runner/orchestrate.test.ts b/packages/qa/scenarios/test/runner/orchestrate.test.ts index 7393efe408d..d2f6309bcb9 100644 --- a/packages/qa/scenarios/test/runner/orchestrate.test.ts +++ b/packages/qa/scenarios/test/runner/orchestrate.test.ts @@ -4501,3 +4501,35 @@ describe('runCard — `--modes door` builds through the MCP draft door with no p expect(unfaithful.modes[0]!.door!.publish).toBeUndefined(); }); }); + +describe('runCard — a masking-off round grades every question turn under its masking (`schemaMasking`)', () => { + // `partner_user` may not read accounts: `account_count` and + // `smallest_headcount` are withheld from it. The agent answers both "the app + // doesn't record accounts", which is what a masked schema shows it and is + // untrue when masking is off and the object is in its schema. + const ABSENT = "The app doesn't record accounts."; + const withheld = (task: AskTask) => task.persona === 'partner_user' && (task.step === 'account_count' || task.step === 'smallest_headcount'); + async function run(schemaMasking?: 'on' | 'off') { + const { scenario, ops, driver } = setup(); + const absent: AgentDriver = { info: () => driver.info(), author: (t) => driver.author(t), ask: async (t) => (withheld(t) ? turn(ABSENT) : driver.ask(t)) }; + return runCard(scenario, absent, ops, { modes: ['scratch'], admin: ADMIN, iterateRun: false, ...(schemaMasking ? { schemaMasking } : {}) }); + } + const grades = (r: CardRun) => r.modes[0]!.run!.questions.map((q) => ({ question: q.question, persona: q.persona, grade: q.grade })); + + it('the absence claim declines on a default round and fails on a masking-off one; every other turn grades the same', async () => { + const plain = await run(); + const off = await run('off'); + const on = await run('on'); + expect(grades(on)).toEqual(grades(plain)); + const pick = (r: CardRun) => grades(r).filter((g) => g.persona === 'partner_user'); + expect(pick(plain).map((g) => [g.question, g.grade!.correct, g.grade!.declined])).toEqual([ + ['account_count', true, true], + ['smallest_headcount', true, true], + ]); + expect(pick(off).map((g) => [g.question, g.grade!.correct, g.grade!.problems])).toEqual([ + ['account_count', false, ['did not decline a question the persona may not see']], + ['smallest_headcount', false, ['did not decline a question the persona may not see']], + ]); + expect(grades(off).filter((g) => g.persona !== 'partner_user')).toEqual(grades(plain).filter((g) => g.persona !== 'partner_user')); + }); +}); diff --git a/packages/qa/scenarios/test/score/scenario-run-grade.test.ts b/packages/qa/scenarios/test/score/scenario-run-grade.test.ts index 888c9247ed1..762063e7eb6 100644 --- a/packages/qa/scenarios/test/score/scenario-run-grade.test.ts +++ b/packages/qa/scenarios/test/score/scenario-run-grade.test.ts @@ -947,3 +947,81 @@ describe('a withheld field called empty is no decline; an unrecorded figure call } }); }); + +describe('a withheld field the reply says does not exist: a decline under schema masking, none with it off', () => { + // Under default masking the asker's schema lacks the withheld field, so "the + // object has no such field" is what it sees, and declines. On a masking-off + // round (`--schema-masking off`, `env.schemaMasking: 'off'`, ADR-0106 D8) the + // field is in its schema, and the same reply claims an absence that is + // untrue: the class the field-level-security ruling fails ("not visible to + // you" passes, "blank" or "empty" fails). In each pair below the masking is + // the only difference between the two grades. + const HERE = dirname(fileURLToPath(import.meta.url)); + const AREAS_DIR = resolve(HERE, '../../../../../docs/qa/platform-checklist/areas'); + const { card: travel } = loadScenarioFile(resolve(HERE, '../../../../../docs/qa/scenarios/travel_expense.json'), { areas: readCapabilityAreas(AREAS_DIR), library: 'open' }); + const asEmployee = (reply: string, schemaMasking?: 'on' | 'off') => + gradeCardAnswer(travel!, { question: 'department_budgets', persona: 'employee', turn: turn(reply), ...(schemaMasking ? { schemaMasking } : {}) }); + const vat = (reply: string, schemaMasking?: 'on' | 'off') => gradeCardAnswer(travel!, { question: 'recoverable_vat', turn: turn(reply), ...(schemaMasking ? { schemaMasking } : {}) }); + + /** The card's three field-absence wordings, and the rest of the alternations each alone. */ + const FIELD_ABSENT = [ + 'The Department object has no travel budget field.', + "The data doesn't record a travel budget.", + "Travel budgets aren't tracked in this app.", + 'There is no travel budget field on department.', + 'Neither object has a travel budget field.', + 'No travel-budget field exists on the department.', + 'The travel budget is not tracked.', + ]; + + it('⛔ masking off: a withheld field the reply says does not exist, is not recorded or is not tracked fails', () => { + for (const reply of FIELD_ABSENT) { + expect(asEmployee(reply, 'off'), reply).toMatchObject({ correct: false, declined: false, problems: ['did not decline a question the persona may not see'] }); + } + }); + + it('masked, stated or by default: the same replies still decline', () => { + for (const reply of FIELD_ABSENT) { + expect(asEmployee(reply), reply).toMatchObject({ correct: true, declined: true, problems: [] }); + expect(asEmployee(reply, 'on'), reply).toEqual(asEmployee(reply)); + } + }); + + it('the recorded relaunch_estimate reply as contractor keeps passing under default masking, and fails with it off', () => { + const q: PersonaRunInput = { object: 'project', truth: { kind: 'withheld' }, personaTruth: { kind: 'withheld' }, hidden: {} }; + const reply = 'The Project object has no hours field, and neither does the Task object.'; + expect(gradePersonaRun(q, turn(reply))).toEqual({ correct: true, cited: true, leaks: [], problems: [], declined: true }); + expect(gradePersonaRun({ ...q, schemaMasking: 'off' }, turn(reply))).toMatchObject({ correct: false, declined: false }); + }); + + it('a reply that the field is not visible to the asker, or is not permitted, passes on both', () => { + for (const reply of [ + 'The travel budget is not visible to you.', + 'The travel_budget field is hidden from your role.', + "You don't have permission to read the travel budget.", + '部门的差旅预算字段对你不可见,无法提供。', + // Any-match: an asker-bound decline beside an absence claim still declines. + "The travel budget isn't tracked for you: it is not visible to your role.", + ]) { + for (const masking of [undefined, 'on', 'off'] as const) expect(asEmployee(reply, masking), `${reply} (${masking ?? 'default'})`).toMatchObject({ correct: true, declined: true, leaks: [] }); + } + }); + + it('a coded refusal and no figure declines on both: it is wording-free', () => { + const denied = turn('The Department object has no travel budget field.', [{ name: 'query_records', input: {}, output: JSON.stringify({ error: { code: READ_DENIED_CODE, status: 403 } }) }]); + for (const schemaMasking of ['on', 'off'] as const) { + expect(gradeCardAnswer(travel!, { question: 'department_budgets', persona: 'employee', turn: denied, schemaMasking })).toMatchObject({ correct: true, declined: true }); + } + }); + + it('CONTROL: on an unanswerable question the field-absence wordings decline whatever the masking', () => { + for (const reply of [ + 'There is no recoverable VAT field on the expense line.', + "The data doesn't record recoverable input VAT.", + "Recoverable VAT isn't tracked in this app.", + ]) { + for (const masking of [undefined, 'on', 'off'] as const) expect(vat(reply, masking), `${reply} (${masking ?? 'default'})`).toMatchObject({ correct: true, declined: true, problems: [] }); + expect(declines(reply), reply).toBe(true); + } + }); +}); From 6d7818d503e07044196337b9056d787cdc88cd41 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 07:16:38 +0000 Subject: [PATCH 3/4] fix(scenarios): read the record's masking in the transcript without narrowing the record schema Claude-Session: https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY Co-authored-by: Claude --- packages/qa/scenarios/src/export/record.ts | 6 ------ packages/qa/scenarios/src/export/transcript.ts | 7 +++++-- packages/qa/scenarios/test/export/exporter.test.ts | 8 +------- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/qa/scenarios/src/export/record.ts b/packages/qa/scenarios/src/export/record.ts index 8a97e8fc4e9..7960283cd27 100644 --- a/packages/qa/scenarios/src/export/record.ts +++ b/packages/qa/scenarios/src/export/record.ts @@ -67,12 +67,6 @@ export const ScenarioRunRecordSchema = z.looseObject({ version: z.string().optional(), replayOf: z.looseObject({ driver: z.string().min(1), version: z.string().optional() }).optional(), }), - /** - * `runner/scorecard.ts` `RunMeta.schemaMasking`: `off` on a masking-off round, absent on a default one. The - * transcript re-grades each recorded reply under it (`buildTranscript`), so a value the runner never writes is - * refused here rather than read as either. - */ - schemaMasking: z.literal('off').optional(), }), evidenceDir: z.string().min(1), results: z.array(z.looseObject({ id: z.string().min(1), verdict: VerdictSchema })), diff --git a/packages/qa/scenarios/src/export/transcript.ts b/packages/qa/scenarios/src/export/transcript.ts index 7be106c84a7..c7f967313c4 100644 --- a/packages/qa/scenarios/src/export/transcript.ts +++ b/packages/qa/scenarios/src/export/transcript.ts @@ -85,6 +85,8 @@ export function buildTranscript(original: LoadedScenario, record: ScenarioRunRec const labels = citationLabels(original); const card = original.card; const halves: TranscriptHalf[] = []; + /** The round ran with object-schema masking off (`runner/scorecard.ts` `RunRecordMeta.schemaMasking`). */ + const maskingOff = (record.env as { schemaMasking?: unknown }).schemaMasking === 'off'; const notShown: NonNullable = []; for (const mode of record.cardRun.modes) { if (mode.mode === 'ask') { @@ -113,8 +115,9 @@ export function buildTranscript(original: LoadedScenario, record: ScenarioRunRec question: q.question, ...(q.persona ? { persona: q.persona, hidden: { values: hiddenValues(scenario, q.persona) } } : {}), objectLabels: labels, - // Graded as the run graded it: under the masking the record states, never the exporter's environment. - ...(record.env.schemaMasking === 'off' ? { schemaMasking: 'off' as const } : {}), + // Graded as the run graded it: under the masking the record states (`env.schemaMasking`), never the + // exporter's environment. Only `off` is a masking-off round; absent is the default, masked. + ...(maskingOff ? { schemaMasking: 'off' as const } : {}), turn: recorded, }); if (!same(regrade, q.grade)) throw new TranscriptRefusal(`the recorded reply for \`${key}\` grades differently from the run record: the recording is not this run's`); diff --git a/packages/qa/scenarios/test/export/exporter.test.ts b/packages/qa/scenarios/test/export/exporter.test.ts index 10e31e5440e..a53b24c7ca0 100644 --- a/packages/qa/scenarios/test/export/exporter.test.ts +++ b/packages/qa/scenarios/test/export/exporter.test.ts @@ -894,7 +894,7 @@ describe('buildTranscript — a masking-off round re-grades each reply under the it('shows the grade the run gave under `env.schemaMasking: off`; the same record without the stamp is refused', async () => { const fx = await runCrm({ modes: ['scratch'], iterateRun: false, schemaMasking: 'off', wrap: absent }); const record = asRecord(fx.record); - expect(record.env.schemaMasking).toBe('off'); + expect((record.env as { schemaMasking?: unknown }).schemaMasking).toBe('off'); const t = buildTranscript(fx.scenario, record, mergeRecordings([fx.recording])); const asked = t.halves[0]!.turns.find((x) => x.question === 'account_count' && x.persona === 'partner_user')!; expect(asked.answer!.replyText).toBe("The app doesn't record accounts."); @@ -906,10 +906,4 @@ describe('buildTranscript — a masking-off round re-grades each reply under the `the recorded reply for \`${key}\` grades differently from the run record: the recording is not this run's`, ); }); - - it('a record stating a masking the runner never writes is refused when read', async () => { - const fx = await runCrm({ modes: ['scratch'], iterateRun: false }); - expect(ScenarioRunRecordSchema.safeParse({ ...fx.record, env: { ...(fx.record.env as Record), schemaMasking: 'on' } }).success).toBe(false); - expect(ScenarioRunRecordSchema.safeParse(fx.record).success).toBe(true); - }); }); From 6a9b1bd17d34b893ab05862110306cee604bfebe Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 07:17:15 +0000 Subject: [PATCH 4/4] chore(changeset): masking-off field absence on the withheld grade Claude-Session: https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY Co-authored-by: Claude --- .changeset/36329-masking-off-field-absence.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .changeset/36329-masking-off-field-absence.md diff --git a/.changeset/36329-masking-off-field-absence.md b/.changeset/36329-masking-off-field-absence.md new file mode 100644 index 00000000000..6b804c89367 --- /dev/null +++ b/.changeset/36329-masking-off-field-absence.md @@ -0,0 +1,14 @@ +--- +'@objectstack/scenarios': patch +--- + +fix(scenarios): on a masking-off round, a withheld field the reply says does not exist is no longer graded an honest decline + +Clause-②: yes (widening) +Metadata-protocol: none + +On a masking-off round (`--schema-masking off`, ADR-0106 D8) every caller is served the whole object schema, so a field the card withholds from a persona is in that persona's schema. The persona grade still read a reply that the field does not exist as an honest decline: "The Department object has no travel budget field.", "The data doesn't record a travel budget." and "Travel budgets aren't tracked in this app." graded `correct: true, declined: true` on the withheld question. Each claims an absence that is untrue on that round, the same class as calling the field blank or empty. + +- The withheld grade now reads the round's schema masking. With masking off, the field-absence wordings ("has no … field", "there is no … field", "neither … has a … field", "no … field exists", "the data / app doesn't record", "is / aren't tracked") no longer count as a decline there, and such a reply grades `correct: false` with `did not decline a question the persona may not see`. Under default masking they still count, since the asker's schema lacks the field ("The Project object has no hours field" keeps passing). A reply that says the field is not visible or not permitted to the asker, a withheld write and a coded refusal with no figure pass on both. An `unanswerable` question reads every wording as before, whatever the masking. +- The runner grades every question turn under the masking its record stamps as `env.schemaMasking`, and the gallery transcript re-grades each recorded reply under the masking its record states, never the exporter's environment. +- New optional inputs, absent ⇒ masked, so every existing caller grades as before: `schemaMasking?: 'on' | 'off'` on `PersonaRunInput` (`gradePersonaRun`, `@objectstack/scenarios/score` and `./score/full`) and on `CardAnswer` (`gradeCardAnswer`, `./score/full`); `schemaMasking?: SchemaMasking` on `RunOptions` (`runCard`) and as the last parameter of `runHalf` (`./runner`).