Skip to content
13 changes: 13 additions & 0 deletions .changeset/36206-gallery-refresh-scorer-card-defects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@objectstack/scenarios': patch
---

fix(scenarios): scorer and card fixes from the 18.6.0 gallery refresh

Clause-②: yes (widening) — new exports `confirmTurnMetNoConfirmationService` and `SEED_POSTURE` on the `./runner` entry
Metadata-protocol: none

- The confirmed write of a `pending_confirmation` operation is not measured, never failed, when the first turn's write already met `428 ACTION_CONFIRMATION_REQUIRED` with `reason: no_confirmation_service` and the confirmation turn sends no write on the object: the agent remembered that the route cannot apply on that server. A confirmation turn that does write is graded as before. New export: `confirmTurnMetNoConfirmationService(firstMet, turn, object)`.
- A decline of an `unanswerable` question may state the sum or the difference of two figures the turn's tool outputs carry, when the reply writes both of them too ("45.5 + 9 = 54.5 days", "249 comments, 20 internal, so 229"). A derived figure whose operands the reply leaves out, a product, a figure derived from a derived figure and a zero from two equal figures still fail.
- Card data: requisition_to_receipt seeds `supplier.rating` as `grade_a` / `grade_b` / `grade_c` (a single-choice value is a lowercase identifier, so `A` / `B` / `C` refused every supplier row and the purchase orders, lines and receipts beneath them); travel_expense's step `as_118_2` is decided on the card's `asOf` (2026-10-31), not after it; service_desk's TK-0091 opens on 2026-10-02, so no urgent or high ticket sits on the day the platform's `last_30_days` preset counts and the card's 30-day window does not (`urgent_high_last_30_days` is now 9); and service_desk's prompt asks for the report and the computed value its Build half grades.
- The build prompt's data contract says how the seed loads: through the platform's seed path as established facts, where every validation rule and hook but the state machine's entry check runs and no record-triggered flow fires, so a derived field must be a formula or an expression computed when written. New export: `SEED_POSTURE`.
12 changes: 6 additions & 6 deletions docs/qa/scenarios/requisition_to_receipt.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@
{"id": "e18", "name": "Adam Wright", "department": "dep_exec", "title": "General manager", "email": "adam.wright@example.com"}
],
"supplier": [
{"id": "s01", "name": "Bluepeak Electronics", "category": "it_hardware", "rating": "A", "payment_terms": "net_30", "bank_account": "6217 0000 0000 0101"},
{"id": "s02", "name": "Cedar Office Supply", "category": "office_supplies", "rating": "B", "payment_terms": "net_30", "bank_account": "6217 0000 0000 0102"},
{"id": "s03", "name": "Harbor Facilities Co.", "category": "facilities", "rating": "A", "payment_terms": "net_60", "bank_account": "6217 0000 0000 0103"},
{"id": "s04", "name": "Summit Advisory Group", "category": "services", "rating": "B", "payment_terms": "net_60", "bank_account": "6217 0000 0000 0104"},
{"id": "s05", "name": "Granite Systems", "category": "it_hardware", "rating": "A", "payment_terms": "net_30", "bank_account": "6217 0000 0000 0105"},
{"id": "s06", "name": "Maple Print Works", "category": "office_supplies", "rating": "C", "payment_terms": "net_30", "bank_account": "6217 0000 0000 0106"}
{"id": "s01", "name": "Bluepeak Electronics", "category": "it_hardware", "rating": "grade_a", "payment_terms": "net_30", "bank_account": "6217 0000 0000 0101"},
{"id": "s02", "name": "Cedar Office Supply", "category": "office_supplies", "rating": "grade_b", "payment_terms": "net_30", "bank_account": "6217 0000 0000 0102"},
{"id": "s03", "name": "Harbor Facilities Co.", "category": "facilities", "rating": "grade_a", "payment_terms": "net_60", "bank_account": "6217 0000 0000 0103"},
{"id": "s04", "name": "Summit Advisory Group", "category": "services", "rating": "grade_b", "payment_terms": "net_60", "bank_account": "6217 0000 0000 0104"},
{"id": "s05", "name": "Granite Systems", "category": "it_hardware", "rating": "grade_a", "payment_terms": "net_30", "bank_account": "6217 0000 0000 0105"},
{"id": "s06", "name": "Maple Print Works", "category": "office_supplies", "rating": "grade_c", "payment_terms": "net_30", "bank_account": "6217 0000 0000 0106"}
],
"purchase_requisition": [
{"id": "r001", "name": "PR-0001", "requester": "e01", "request_date": "2026-07-01", "category": "office_supplies", "description": "Printer paper for the office", "total_amount": 1200, "approval_levels": 1, "status": "received"},
Expand Down
14 changes: 7 additions & 7 deletions docs/qa/scenarios/service_desk.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/qa/scenarios/travel_expense.json
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@
{"id": "as_116_2", "claim": "c116", "step": 2, "approver": "e13", "decision": "pending", "decided_on": null, "comment": null},
{"id": "as_117_1", "claim": "c117", "step": 1, "approver": "e14", "decision": "rejected", "decided_on": "2026-10-29", "comment": "Trip purpose does not match the approved request."},
{"id": "as_118_1", "claim": "c118", "step": 1, "approver": "e09", "decision": "approved", "decided_on": "2026-10-30", "comment": null},
{"id": "as_118_2", "claim": "c118", "step": 2, "approver": "e13", "decision": "approved", "decided_on": "2026-11-02", "comment": null}
{"id": "as_118_2", "claim": "c118", "step": 2, "approver": "e13", "decision": "approved", "decided_on": "2026-10-31", "comment": null}
]
},
"questions": [
Expand Down
21 changes: 20 additions & 1 deletion packages/qa/scenarios/src/runner/orchestrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,28 @@ export const confirmationAmbiguous = 'the ask matches more than one row and the
* Why a confirmed write is not measured on a server with no pending-confirmation service: the action door answered
* the turn's confirm-gated call `428 ACTION_CONFIRMATION_REQUIRED`, `details.reason: 'no_confirmation_service'`, and
* on such a server it answers every such call so, whatever the agent sends. The ask (the first turn) is graded as before.
* The same holds when the FIRST turn's call met that answer and the confirmation turn sent no write on the object: the
* agent already learned the route cannot apply, so not retrying it is no failure ({@link confirmTurnMetNoConfirmationService}).
*/
const noConfirmationService = 'the action door has no pending-confirmation service on this server (428 ACTION_CONFIRMATION_REQUIRED, reason no_confirmation_service), so no agent can apply the confirmed write';

/**
* Whether the confirmation turn of a `pending_confirmation` operation meets the server with no pending-confirmation
* service ({@link noConfirmationService}), so its confirmed write is not measured. Either:
*
* - a write call on the operation's object in the confirmation turn met `428 ACTION_CONFIRMATION_REQUIRED`,
* reason `no_confirmation_service`; or
* - the first turn's write call met that answer (`firstMet`, the first turn's
* `OperationObservation.metNoConfirmationService`) and the confirmation turn sent no write call on the
* object at all: the agent remembered the route cannot apply here and did not retry it.
*
* A confirmation turn that does write after a first-turn 428 is graded on its own, as any other.
*/
export function confirmTurnMetNoConfirmationService(firstMet: boolean, second: Pick<ParsedTurn, 'toolCalls'>, object: string): boolean {
const writes = writeCallsOn(second, object);
return writes.some((c) => metNoConfirmationService(c.output)) || (firstMet && writes.length === 0);
}

export interface RunHalf {
personas: Array<Omit<PersonaAccount, 'apiKey'>>;
seed: {
Expand Down Expand Up @@ -1967,7 +1986,7 @@ export async function runHalf(
const afterConfirm = (await app.listRows(op.object)).rows as Row[];
confirmed.observation = observeConfirmedWrite(op, second, beforeConfirm, afterConfirm, clockDates(startedConfirm, new Date()));
confirmed.grade = gradeConfirmedWrite(op, confirmed.observation, card.asOf !== undefined ? { asOf: card.asOf } : {});
if (writeCallsOn(second, op.object).some((c) => metNoConfirmationService(c.output))) confirmed.notMeasured = noConfirmationService;
if (confirmTurnMetNoConfirmationService(res.observation.metNoConfirmationService === true, second, op.object)) confirmed.notMeasured = noConfirmationService;
}
} catch (e) {
confirmed.error = errText(e);
Expand Down
23 changes: 22 additions & 1 deletion packages/qa/scenarios/src/runner/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,17 +443,38 @@ const CONFIRM_FIRST_LOCK =
'so a plain record update cannot make that change while those people’s other changes to the same fields still land; ' +
'an action that deletes its row locks nothing, and those people keep their delete right';

/**
* How the runner loads the seed, as the build must expect it: through the
* platform's own seed path (`seedApp` in `orchestrate.ts`), not the data API a
* person writes through. The rows are established facts: the state machine's
* entry check is skipped, every other validation rule and hook judges each
* row, and no record-triggered flow fires on it. So a field a build derives
* with an after-save flow stays empty on every loaded row (asset_lifecycle's
* department scoping fields left a manager seeing none of the department's
* rows), and a rule that judges a row against a total the loaded rows already
* count (a payment against its invoice's balance) refuses the history.
*/
export const SEED_POSTURE =
'The rows are loaded through the platform’s seed path as established facts, not as new records entering their lifecycle: ' +
'each row is still judged by every validation rule and hook except the state machine’s entry check, and no record-triggered flow fires on it. ' +
'So a value derived from other fields or rows (a department copied from a related row to scope access, an amount, a flag) must be a formula or a field computed by an expression when written, ' +
'never set by a record-triggered flow, or every loaded row keeps it empty. ' +
'And a loaded row is already counted in the stored totals of the rows it relates to (a payment in its invoice’s balance), ' +
'so a validation rule must not refuse it by comparing it with such a total.';

/** The runner's contract, appended to every build prompt. */
export function dataContract(card: Card): string {
const lines: string[] = [];
lines.push('## What the app will be loaded with and used by');
lines.push('');
lines.push(
'After you finish, a test runner loads the rows below through the data API and signs each person in. ' +
'After you finish, a test runner loads the rows below and signs each person in. ' +
'Use these object and field machine names exactly (lookup values are the `id` of the referenced row), ' +
'and make every value shown valid for its field. The object names already carry this app’s namespace prefix.',
);
lines.push('');
lines.push(SEED_POSTURE);
lines.push('');
lines.push(namingRule(card));
lines.push('');
lines.push('```json');
Expand Down
33 changes: 29 additions & 4 deletions packages/qa/scenarios/src/score/scenario-run-grade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,29 @@ function rowCounts(calls: readonly RunToolCall[]): Set<number> {
return out;
}

/**
* Which of the numbers `written` (as {@link writtenNumbers} reads a reply) the
* data supports: each one some value in `served` holds, or the sum or the
* difference of two OTHER numbers the same reply writes that `served` holds
* ("45.5 days of annual leave and 9 unpaid, 54.5 in all"; "249 tickets, 20
* with no reply, so 229"). The operands must stand in the reply itself, so a
* derived figure is one a reader can check against the served ones, never a
* number that merely happens to equal the sum of two values somewhere in the
* outputs. A difference of two equal figures (a zero) supports nothing: the reply
* writing one figure twice derives no zero from the data. One step only: a figure
* derived from a derived figure is not supported,
* and neither is a product, a ratio or a sum of a column the reply does not write
* out. The cost: an invented figure that happens to equal the sum or difference
* of two served figures the reply writes is not caught.
*/
function supportedNumbers(written: readonly number[][], served: ReadonlySet<number>): boolean[] {
const operands = written.map((values) => values.filter((n) => served.has(n)));
const same = (a: number, b: number) => Math.abs(a - b) <= 1e-6 * Math.max(1, Math.abs(b));
const derived = (n: number, at: number) =>
operands.some((as, i) => i !== at && as.some((a) => operands.some((bs, j) => j !== at && j !== i && bs.some((b) => same(a + b, n) || (!same(a, b) && same(a - b, n))))));
return written.map((values, at) => operands[at]!.length > 0 || values.some((n) => derived(n, at)));
}

function isBag(v: unknown): v is Record<string, unknown> {
return typeof v === 'object' && v !== null && !Array.isArray(v);
}
Expand Down Expand Up @@ -908,10 +931,12 @@ const USER_ACCOUNTS = /\b(?:user|login|sign-in) accounts?\b|用户账[号户]/i;
* - 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
* is carried when either of its readings is), or a count of the rows
* one returned, overall or per field value ({@link rowCounts}). So a
* is carried when either of its readings is), a count of the rows
* one returned, overall or per field value ({@link rowCounts}), or the
* sum or difference of two such numbers the reply also writes
* ({@link supportedNumbers}). So a
* decline that shows the rows it checked ("no tax rate field; INV-002
* totals 120", "30 laptops, 23 in use") is correct, and one that guesses
* totals 120", "30 laptops, 23 in use", "45.5 + 9 = 54.5 days") is correct, and one that guesses
* ("it is probably 13%", "about 12 expire under a 3-year term") is not,
* in any wording. The cost: an invented figure equal to a number some
* tool output happens to carry or count (0, 1 and small counts are
Expand Down Expand Up @@ -966,7 +991,7 @@ export function gradePersonaRun(input: PersonaRunInput, turn: RunTranscript): Pe

if (input.personaTruth.kind === 'unanswerable') {
const carried = new Set([...carriedNumbers(turn.toolCalls), ...rowCounts(turn.toolCalls)]);
const supported = writtenNumbers(turn.replyText).every((values) => values.some((n) => carried.has(n)));
const supported = supportedNumbers(writtenNumbers(turn.replyText), carried).every(Boolean);
return {
correct: declined && supported,
cited: true,
Expand Down
81 changes: 80 additions & 1 deletion packages/qa/scenarios/test/library.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, it } from 'vitest';

import { formatRefusal, loadScenarios, readCapabilityAreas, type Truth } from '../src/index.js';
import { SelectOptionSchema } from '@objectstack/spec/data';

import { formatRefusal, loadScenarios, readCapabilityAreas, truthsOver, type Truth } from '../src/index.js';
import { promptLanguageGaps } from '../src/runner/prompts.js';

const HERE = dirname(fileURLToPath(import.meta.url));
Expand Down Expand Up @@ -160,6 +162,83 @@ describe('the open scenario library (docs/qa/scenarios)', () => {
});
}

it('every seed value of a single-choice field the card asks for is a valid option value', () => {
// An option value is a lowercase machine identifier (`SelectOptionSchema.value`), so a build
// can only declare options the platform accepts; a seed value no option can hold is refused,
// with every row that looks it up (requisition_to_receipt's `supplier.rating` "A"/"B"/"C").
const invalid: string[] = [];
for (const { card } of result.cards) {
for (const { object, field } of card.expect.selectFields ?? []) {
for (const row of card.run.seed[object] ?? []) {
const v = row[field];
if (v === null || v === undefined) continue;
if (!SelectOptionSchema.safeParse({ label: String(v), value: v }).success) invalid.push(`${card.id}: ${object}.${field} = ${JSON.stringify(v)}`);
}
}
}
expect(invalid).toEqual([]);
});

it('a seed row dated after the card\'s asOf is a plan (a due, start, end or expected date), never a fact the card treats as done', () => {
// travel_expense's step `as_118_2` was decided 2026-11-02, after its asOf 2026-10-31: the agent
// rightly refused to pay a claim over a future-dated approval. Each card's future-dated fields, pinned.
const future: Record<string, string[]> = {};
for (const { card } of result.cards) {
if (card.asOf === undefined) continue;
const fields = new Set<string>();
for (const [object, rows] of Object.entries(card.run.seed)) {
for (const row of rows) {
for (const [field, v] of Object.entries(row)) {
if (typeof v === 'string' && /^\d{4}-\d{2}-\d{2}/.test(v) && v.slice(0, 10) > card.asOf) fields.add(`${object}.${field}`);
}
}
}
if (fields.size > 0) future[card.id] = [...fields].sort();
}
expect(future).toEqual({
asset_lifecycle: ['checkout.due_on'],
leave_balances: ['leave_day.leave_date', 'leave_request.end_date', 'leave_request.start_date'],
order_to_cash: ['invoice.due_date'],
requisition_to_receipt: ['purchase_order.expected_date'],
travel_expense: ['trip_request.end_date', 'trip_request.start_date'],
});
});

it('a last-N-days truth counts no row on the extra day the platform\'s preset adds (last_30_days spans 31 days ending on asOf)', () => {
// The card's `last_days` window is the N days ending on asOf; the platform's
// `last_N_days` preset runs from N days before asOf, one day more. A row on that
// day makes an app that uses the preset answer differently from the card.
const ambiguous: string[] = [];
for (const loaded of result.cards) {
const widened = structuredClone(loaded.card);
const ids: string[] = [];
for (const q of widened.run.questions) {
for (const f of 'filter' in q.truth ? (q.truth.filter ?? []) : []) {
if (f.op === 'in_window' && typeof f.value === 'object' && f.value !== null && 'kind' in f.value && f.value.kind === 'last_days') {
f.value = { kind: 'last_days', days: f.value.days + 1 };
ids.push(q.id);
}
}
}
if (ids.length === 0) continue;
const wide = truthsOver(widened, loaded.card.run.seed);
for (const id of [...new Set(ids)]) {
if (JSON.stringify([wide.truths[id], wide.personaTruths[id]]) !== JSON.stringify([loaded.truths[id], loaded.personaTruths[id]])) ambiguous.push(`${loaded.card.id}/${id}`);
}
}
// order_to_cash's PAY-0044 (2026-10-01) is the one left: the same defect, outside this change's cards.
expect(ambiguous).toEqual(['order_to_cash/collected_by_team_last_30_days']);
});

it('every card tagged for a report asks for one in its detailed prompt, in both languages', () => {
// The Build check `dashboards.report` grades a report the prompt never asked for otherwise.
const silent = result.cards
.filter(({ card }) => card.capabilities.includes('dashboards.report'))
.filter(({ card }) => !/\breport\b/i.test(card.prompt.detailed.en ?? '') || !/报表/.test(card.prompt.detailed.zh ?? ''))
.map(({ card }) => card.id);
expect(silent).toEqual([]);
});

it('reads the capability areas from the checklist tree', () => {
// A closed set read from disk, not a list kept here: the assertion is only
// that it is non-trivial and holds an area every seed card uses.
Expand Down
Loading
Loading