Skip to content

Commit 36873ee

Browse files
feat(scenarios): a card names the agent action an operation goes through (via) (#36503)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9JpRoUZGqtwqMU5k7b4C58D)_ Part of #36206 (item 3 and the PAY-0044 position land here; the column-total half of item 2 waits on the eval seat's re-score and stays open on the card). Clause-②: yes (widening) Metadata-protocol: none Ruling-ref: 7077801044 (item 3 C, PAY-0044 folded) ## 维护者速读 - 用户能看到什么变化:评测席位跑场景卡时,经理通过卡片自带的审批动作做决定的那一步,搭建分不再因经理没有直接改审批记录的权限而被扣,改记为“未测”;其余用户无感。 - 为什么做:场景库专题(画廊刷新)里请假余额和采购到收货两张卡,搭建正确却被扣分;顺带修正订单到回款卡上一笔付款落在“近 30 天”边界日、导致卡片答案与平台口径不一致的问题。 - 出错会怎样:最坏是某张卡的这一项授权检查被记为“未测”而不是“失败”,只影响评测分数,改动可直接撤回。 - 要你做什么:无。 ## What changes Against `origin/main` 59392ed. | Part | Change | |:--|:--| | Card schema | An operation may carry `via`: the card's own agent action the write is designed to go through. Optional; a card without it reads exactly as before. | | Loader | Refuses a `via` that is not one of the card's `run.agentActions` on the operation's object (the ruled check), and a `via` on a `refused` operation (a refused write has no route; without this the key would be accepted and do nothing). | | Grant grading (`gradePersonaGrants`) | `persona-grant:PERSONA:OBJECT:VERB` is **not measured, never a pass**, when the set withholds the verb AND every operation that needs it has a designed route the build declares: its `via` action, or (unchanged) the card's confirm-gated action for a `pending_confirmation` write. A set that grants the verb still passes. An operation without `via` is graded as today, so one unrouted applied write of the same verb keeps the check measured. The existing confirm-gated branch and its detail text are unchanged; the `no designed route` pin (`start_qa`, non-confirm action, no `via`) stays green. | | Cards | `via: decide_approval_step` on leave_balances `manager_approves_step_one`, requisition_to_receipt `manager_approves_level_one` and travel_expense `manager_approves_step_one`. Not tagged (no measured run yet): asset_lifecycle `manager_approves_scrap`, order_to_cash `approve_discount`. A library pin lists exactly the three tagged operations. | | PAY-0044 | order_to_cash's PAY-0044 moves from 2026-10-01 to 2026-10-02 (bank reference `ACH-1002-058`), the same one-day move PR #36320 gave TK-0091, and the seed rule names the exception. The library pin of last-N-days truths that change under the platform's preset flips to `[]`. `collected_by_team_last_30_days` west becomes 58300 (was 53500; the payment now falls inside the card's 30-day window too). The only other reader of `payment_date` is the collection-call automation check (paid by due + 15 days), which reads the same for INV-1058 either way. | `Clause-②: yes (widening)` reading: `src/index.ts` does `export * from './schema.js'`, so `OperationSchema` and `ScenarioCardSchema` are on the package's `.` entry (`package.json` `exports["."]` maps to `dist/index.*`); `PersonaGrantNeed` (gains `routedVia`) is on `./score` via `export * from './scenario-tags.js'`. **Read first (by risk):** 1. `packages/qa/scenarios/src/score/scenario-tags.ts`: `designedRoutes` and the new branch at the top of `gradePersonaGrants`'s needed path; the old confirm branch must read unchanged when no operation names `via`. 2. `packages/qa/scenarios/src/loader.ts`: the `via` block in the operations loop. 3. `docs/qa/scenarios/order_to_cash.json`: PAY-0044 row and the seed-rule sentence. **Two-minute check:** `pnpm --filter @objectstack/scenarios exec vitest run test/score/scenario-tags.test.ts test/refusals.test.ts test/library.test.ts`, expect all green, including the new `an applied write the card routes through its own action` case. ## Tests - New `scenario-tags.test.ts` case: with the read-only contractor and `start_qa` routed `via set_task_status`, the update check is not measured with the named detail and counts in neither figure; a granting set still passes; a build without the action keeps it measured (fails); the card without `via` fails as before; a second unrouted update keeps it measured. - Three new `refusals.test.ts` rows: an undeclared action, the card's action on another object, a `via` on a refused write. - `library.test.ts`: the tagged-operations pin; the last-N-days pin flipped to `[]`. - `order-to-cash.test.ts`: the `collected_by_team_last_30_days` truth updated to west 58300. <details><summary>Package suite and typecheck (head bb187ca, merged main)</summary> ```text pnpm --filter @objectstack/scenarios typecheck && pnpm --filter @objectstack/scenarios exec vitest run --maxWorkers=2 Test Files 42 passed (42) Tests 1310 passed (1310) os-verify-lock: VERDICT command-exit 0 ``` The package's `typecheck` includes `test/**`. The commit after that one adds only the changeset. </details> <details><summary>Ablations (one-time, restored to HEAD; not left in the tree)</summary> ```text grading: scenario-tags.ts `const via = n.routedVia.filter(...)` -> `const via: string[] = [];` ablation-replace: ok mutation landed: anchor 1 -> 0, blob 7ae784e -> 77cf0c9a74ac x an applied write the card routes through its own action (`via`) ... Tests 1 failed | 101 passed (102) (the confirm-gated / no-designed-route pin stays green) ablation-replace: ok restored: blob == HEAD (7ae784e) and `git diff HEAD` is empty loader: `if (op.via !== undefined) {` -> `if (op.via !== undefined && false) {` ablation-replace: ok mutation landed: anchor 1 -> 0, blob 2d93286 -> 8a1456983646 Tests 3 failed | 118 passed (121) (the three new refusal rows) ablation-replace: ok restored: blob == HEAD (2d93286) and `git diff HEAD` is empty ``` Both subjects resolve from `src/` (relative imports), so no rebuild sat between mutation and run. </details> <details><summary>Derived gate families (head 8eb5896): 68 derived, 66 exit 0, 2 NOT MEASURED</summary> `node scripts/pm/dispatch-gates.mjs --commands` (merge base 59392ed), each run with its exit captured before any pipe, then `--ran` with the codes: "68 derived famil(ies) accounted for — 66 run, 2 NOT-MEASURED (2 DERIVED from a recorded exit 3)". - NOT MEASURED: `pnpm check:dual-build-cjs-loads`, reason: PREREQUISITE NOT MET (reads built output of every package; this worktree built only the scenarios closure). CI's `Lint & Repo Gates` runs it. - NOT MEASURED: `pnpm check:type-check-debt`, reason: its closure build never got a turn on the shared verify lock (queue-timeout, held by another session's dogfood run). The diff touches no tsconfig or typecheck script; the scenarios package typecheck is green above. CI's `Lint & Repo Gates` runs it. - Every other derived family exited 0, including `check:nul-bytes`, `check:cross-package-test-inputs`, `check:published-files`, `check:doc-authoring`, `check:issue-citations` and `check:adr-0087-registration`. - Full dogfood battery: not run (no `!` in the title, no `(narrowing)` arm). </details> ## Acceptance notes - The loader's refusal of `via` on a `refused` operation goes one step past the ruled text (which names only the not-an-action refusal). Reason: grading reads `via` only on writes that need a grant, so on a refused write the key would be accepted and ignored. It is a refusal on a key that is new in this PR; no card writes it. - Not tagged, by the ruling: asset_lifecycle `manager_approves_scrap` (`decide_scrap_request`) and order_to_cash `approve_discount` (`decide_discount_approval`) have the same decide-through-action shape, but no measured run shows the grant check failing there yet. - Item 2b (a decline stating a whole-column total) is not in this PR; it waits on the eval seat's re-score of `september_commission`. ## Verification Item 3 is graded on the next gallery refresh: leave_balances and requisition_to_receipt Build and Iterate should read `persona-grant:dept_manager:approval_step:update` as not measured when the build routes the decision through `decide_approval_step` without granting the update, and as passed when it grants it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmRY38EZf38Yy3zthbY --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6d0089c commit 36873ee

12 files changed

Lines changed: 145 additions & 18 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
---
4+
5+
feat(scenarios): a scenario card names the agent action an operation goes through (`via`)
6+
7+
Clause-②: yes (widening) — `OperationSchema` (exported from the package's `.` entry, and through it `ScenarioCardSchema`) accepts an optional `via`; `PersonaGrantNeed` (the `./score` entry) gains `routedVia`
8+
Metadata-protocol: none
9+
10+
- A card operation may name, as `via`, the card's own agent action the write is designed to go through (one of `run.agentActions` on the operation's object). The loader refuses a `via` that is not such an action, and a `via` on a `refused` operation.
11+
- The Build check `persona-grant:<persona>:<object>:<verb>` is not measured, never a pass, when the persona's set withholds the verb and every operation needing it names a `via` action the build declares (or, as before, waits on confirmation behind the card's confirm-gated action the build declares). A set that grants the verb still passes; an operation without `via` is graded as before.
12+
- leave_balances `manager_approves_step_one`, requisition_to_receipt `manager_approves_level_one` and travel_expense `manager_approves_step_one` name `decide_approval_step` as their route.
13+
- Card data: order_to_cash's PAY-0044 is paid on 2026-10-02, not 2026-10-01, so no payment sits on the day the platform's `last_30_days` preset counts and the card's 30-day window does not (`collected_by_team_last_30_days` west is now 58300).

‎docs/qa/scenarios/leave_balances.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@
918918
"target": "as_102_1",
919919
"values": {"decision": "approved", "decided_on": "2026-09-30"},
920920
"actingAs": "dept_manager",
921+
"via": "decide_approval_step",
921922
"outcome": {
922923
"kind": "applied",
923924
"state": [

‎docs/qa/scenarios/order_to_cash.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$comment": "Seed rule (so every truth can be worked by hand), as of 2026-10-31: account a(k), k = 1..12, is owned by rep [e02, e03, e04, e06, e07, e08][(k-1) mod 6] (team east: e02-e04 under manager e01; team west: e06-e08 under e05) on net_45 terms when k mod 4 = 0, else net_30. Order i = 1..120 is for a((i-1) mod 12 + 1), owned by that account's owner, dated 2026-07..10 day ((i-1) mod 30)+1 (i 1-30 July, 31-60 August, 61-90 September, 91-120 October), with two lines: hardware p((i-1) mod 3 + 1) x (10 + 5(i mod 5)) at list price, 20% off when i mod 10 = 0, and service p(4 + i mod 3) x (1 + i mod 4) at list price. A line discount above 10% routes the order to the owner's manager (`approver`; `approved_on` the next day once approved). Status: i 1-90 cancelled when i mod 20 = 13, else fulfilled; i 91-120 by i mod 10: 1-3 fulfilled, 4, 5 and 9 confirmed, 6-7 draft, 8 cancelled, 0 pending_approval. A fulfilled order is invoiced 7 days after its order date as INV-(1000+i), due after the account's terms. Payments as of asOf: Harbor Foods (a05) has paid nothing; Ironwood Labs (a09) pays half on the due date; Cedar Logistics (a02) pays in full 20 days after the due date; every other account pays in full 3 days before it; method by k mod 3: 0 wire, 1 ach, 2 check. Activities: one touchpoint per account per month on day 30 - 2k by the owner (July meeting, August call, September email, October call), plus a collection_call by e09 on the day an invoice is 15 days past due when it is not fully paid by then.",
2+
"$comment": "Seed rule (so every truth can be worked by hand), as of 2026-10-31: account a(k), k = 1..12, is owned by rep [e02, e03, e04, e06, e07, e08][(k-1) mod 6] (team east: e02-e04 under manager e01; team west: e06-e08 under e05) on net_45 terms when k mod 4 = 0, else net_30. Order i = 1..120 is for a((i-1) mod 12 + 1), owned by that account's owner, dated 2026-07..10 day ((i-1) mod 30)+1 (i 1-30 July, 31-60 August, 61-90 September, 91-120 October), with two lines: hardware p((i-1) mod 3 + 1) x (10 + 5(i mod 5)) at list price, 20% off when i mod 10 = 0, and service p(4 + i mod 3) x (1 + i mod 4) at list price. A line discount above 10% routes the order to the owner's manager (`approver`; `approved_on` the next day once approved). Status: i 1-90 cancelled when i mod 20 = 13, else fulfilled; i 91-120 by i mod 10: 1-3 fulfilled, 4, 5 and 9 confirmed, 6-7 draft, 8 cancelled, 0 pending_approval. A fulfilled order is invoiced 7 days after its order date as INV-(1000+i), due after the account's terms. Payments as of asOf: Harbor Foods (a05) has paid nothing; Ironwood Labs (a09) pays half on the due date; Cedar Logistics (a02) pays in full 20 days after the due date; every other account pays in full 3 days before it, except PAY-0044 (INV-1058, due 2026-10-04), paid 2026-10-02 so no payment sits on 2026-10-01, the day the platform's last_30_days preset (31 days ending on asOf) counts and the card's 30-day window does not; method by k mod 3: 0 wire, 1 ach, 2 check. Activities: one touchpoint per account per month on day 30 - 2k by the owner (July meeting, August call, September email, October call), plus a collection_call by e09 on the day an invoice is 15 days past due when it is not fully paid by then.",
33
"id": "order_to_cash",
44
"code": "order",
55
"tier": "starter",
@@ -634,7 +634,7 @@
634634
{"id": "pay041", "name": "PAY-0041", "invoice": "inv054", "amount": 3600, "payment_date": "2026-09-27", "method": "wire", "bank_reference": "WT-0927-054"},
635635
{"id": "pay042", "name": "PAY-0042", "invoice": "inv040", "amount": 1560, "payment_date": "2026-09-28", "method": "ach", "bank_reference": "ACH-0928-040"},
636636
{"id": "pay043", "name": "PAY-0043", "invoice": "inv055", "amount": 3600, "payment_date": "2026-09-28", "method": "ach", "bank_reference": "ACH-0928-055"},
637-
{"id": "pay044", "name": "PAY-0044", "invoice": "inv058", "amount": 4800, "payment_date": "2026-10-01", "method": "ach", "bank_reference": "ACH-1001-058"},
637+
{"id": "pay044", "name": "PAY-0044", "invoice": "inv058", "amount": 4800, "payment_date": "2026-10-02", "method": "ach", "bank_reference": "ACH-1002-058"},
638638
{"id": "pay045", "name": "PAY-0045", "invoice": "inv044", "amount": 8400, "payment_date": "2026-10-02", "method": "check", "bank_reference": "CHK-1002-044"},
639639
{"id": "pay046", "name": "PAY-0046", "invoice": "inv059", "amount": 11100, "payment_date": "2026-10-02", "method": "check", "bank_reference": "CHK-1002-059"},
640640
{"id": "pay047", "name": "PAY-0047", "invoice": "inv057", "amount": 1200, "payment_date": "2026-10-03", "method": "wire", "bank_reference": "WT-1003-057"},

‎docs/qa/scenarios/requisition_to_receipt.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@
940940
"target": "as_111_1",
941941
"values": {"decision": "approved", "decided_on": "2026-10-31"},
942942
"actingAs": "dept_manager",
943+
"via": "decide_approval_step",
943944
"outcome": {
944945
"kind": "applied",
945946
"state": [

‎docs/qa/scenarios/travel_expense.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@
10761076
"target": "as_111_1",
10771077
"values": {"decision": "approved", "decided_on": "2026-10-31"},
10781078
"actingAs": "dept_manager",
1079+
"via": "decide_approval_step",
10791080
"outcome": {
10801081
"kind": "applied",
10811082
"state": [

‎packages/qa/scenarios/src/loader.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,13 @@ function checkCard(
925925
checkRef(op.object, field, value, [...at, 'values', field]);
926926
}
927927
if (!personas.has(op.actingAs)) refuse([...at, 'actingAs'], `no persona \`${op.actingAs}\``);
928+
if (op.via !== undefined) {
929+
if (op.outcome.kind === 'refused') {
930+
refuse([...at, 'via'], `a \`refused\` write goes through no route: \`via\` names the agent action an applied or confirmation-gated write is designed to go through`);
931+
} else if (!(run.agentActions ?? []).some((a) => a.name === op.via && a.object === op.object)) {
932+
refuse([...at, 'via'], `\`${op.via}\` is not one of the card's \`run.agentActions\` on \`${op.object}\``);
933+
}
934+
}
928935
const actor = run.personas.find((p) => p.id === op.actingAs);
929936
if (actor !== undefined) checkReach(op, actor, at);
930937
const out = op.outcome;

‎packages/qa/scenarios/src/schema.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,16 @@ export const OperationSchema = z
526526
values: z.record(MachineNameSchema, ScalarSchema).optional(),
527527
/** The persona the agent acts for. */
528528
actingAs: MachineNameSchema,
529+
/**
530+
* The card's own agent action this write is designed to go through
531+
* (`run.agentActions[].name`, on this operation's object; the loader holds
532+
* that). An action body writes as the platform, so a build may withhold
533+
* the verb from the persona's set and route the write through it: the
534+
* Build grant check then leaves the write to the run, never a pass
535+
* (`gradePersonaGrants` in `score/scenario-tags.ts`). Absent ⇒ the write
536+
* is measured against the persona's grant. A `refused` write takes none.
537+
*/
538+
via: MachineNameSchema.optional(),
529539
outcome: OutcomeSchema,
530540
})
531541
.superRefine((op, ctx) => {

‎packages/qa/scenarios/src/score/scenario-tags.ts‎

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,8 @@ export interface PersonaGrantNeed {
928928
requiredBy: string[];
929929
/** The operations among those whose outcome is `pending_confirmation`: the write waits on a person's confirmation. */
930930
awaitingConfirmation: string[];
931+
/** The operations among those that name the card's agent action they go through (`via`), each with that action. */
932+
routedVia: Array<{ operation: string; action: string }>;
931933
/** The writes the card declares refused `PERMISSION_DENIED`, each with the fields it names. */
932934
refusedBy: Array<{ operation: string; fields: string[] }>;
933935
}
@@ -941,7 +943,8 @@ export interface PersonaGrantNeed {
941943
* persona that must not read the object declines the question, it reads
942944
* nothing;
943945
* - an operation whose outcome is `applied` or `pending_confirmation` needs
944-
* its kind on its object, for the persona it acts as;
946+
* its kind on its object, for the persona it acts as; one that names the
947+
* card's agent action it goes through (`via`) is recorded with it;
945948
* - an operation refused `PERMISSION_DENIED` must be refused by that
946949
* persona's set. Any other refusal (`VALIDATION_FAILED`) implies nothing
947950
* about the grant.
@@ -951,7 +954,7 @@ export function personaGrantNeeds(card: ScenarioArtifactCard): PersonaGrantNeed[
951954
const need = (persona: string, object: string, verb: PersonaGrantVerb): PersonaGrantNeed => {
952955
const key = `${persona}:${object}:${verb}`;
953956
let n = needs.get(key);
954-
if (!n) needs.set(key, (n = { persona, object, verb, requiredBy: [], awaitingConfirmation: [], refusedBy: [] }));
957+
if (!n) needs.set(key, (n = { persona, object, verb, requiredBy: [], awaitingConfirmation: [], routedVia: [], refusedBy: [] }));
955958
return n;
956959
};
957960
const hidesObject = new Map(card.run.personas.map((p) => [p.id, new Set(p.hidden.objects ?? [])]));
@@ -967,6 +970,7 @@ export function personaGrantNeeds(card: ScenarioArtifactCard): PersonaGrantNeed[
967970
const n = need(op.actingAs, op.object, op.kind);
968971
n.requiredBy.push(`operation ${op.id}`);
969972
if (outcome.kind === 'pending_confirmation') n.awaitingConfirmation.push(op.id);
973+
if (op.via !== undefined) n.routedVia.push({ operation: op.id, action: op.via });
970974
} else if (outcome.code === 'PERMISSION_DENIED') {
971975
need(op.actingAs, op.object, op.kind).refusedBy.push({ operation: op.id, fields: Object.keys(op.values ?? {}) });
972976
}
@@ -1028,15 +1032,40 @@ function writeRefusalRoute(
10281032
* build may withhold a write the card has wait on a person's confirmation from
10291033
* the persona's set and route it through such an action: the lock and the
10301034
* door ruling A on #31999 item 9 accepts on the Run side, here offered by the
1031-
* card itself. Only the confirm-gated door counts: a write the card applies
1032-
* outright stays measured against the grant, whatever actions the build adds.
1035+
* card itself. For a write the card applies outright only the action the
1036+
* operation names as its route (`via`) counts ({@link designedRoutes}):
1037+
* without one it stays measured against the grant, whatever actions the
1038+
* build adds.
10331039
*/
10341040
function confirmGatedRoutes(facts: ArtifactFacts, card: ScenarioArtifactCard, object: string): string[] {
10351041
return (card.run.agentActions ?? [])
1036-
.filter((a) => a.confirm === true && a.object === object && facts.actions.some((x) => x.object === object && x.action.name === a.name))
1042+
.filter((a) => a.confirm === true && a.object === object && buildDeclaresAction(facts, object, a.name))
10371043
.map((a) => a.name);
10381044
}
10391045

1046+
/** Whether the build declares an action named `name` on `object`. */
1047+
function buildDeclaresAction(facts: ArtifactFacts, object: string, name: string): boolean {
1048+
return facts.actions.some((x) => x.object === object && x.action.name === name);
1049+
}
1050+
1051+
/**
1052+
* Each write the need's grant is withheld from, with the routes the card
1053+
* designs for it that the build declares: the agent action the operation
1054+
* names (`via`, any `confirm`) and, for a write that waits on confirmation,
1055+
* the card's confirm-gated actions ({@link confirmGatedRoutes}). `undefined`
1056+
* when one write has no such route: the grant is then measured. The card's
1057+
* other actions on the object are no route, whatever the build declares.
1058+
*/
1059+
function designedRoutes(facts: ArtifactFacts, card: ScenarioArtifactCard, n: PersonaGrantNeed): Array<{ operation: string; via: string[]; confirm: string[] }> | undefined {
1060+
const confirm = confirmGatedRoutes(facts, card, n.object);
1061+
const routes = n.requiredBy.map((r) => {
1062+
const operation = r.replace(/^operation /, '');
1063+
const via = n.routedVia.filter((v) => v.operation === operation && buildDeclaresAction(facts, n.object, v.action)).map((v) => v.action);
1064+
return { operation, via, confirm: n.awaitingConfirmation.includes(operation) ? confirm : [] };
1065+
});
1066+
return routes.every((r) => r.via.length > 0 || r.confirm.length > 0) ? routes : undefined;
1067+
}
1068+
10401069
/**
10411070
* One Build check per persona × object × verb the card implies
10421071
* ({@link personaGrantNeeds}), named `persona-grant:<persona>:<object>:<verb>`,
@@ -1056,10 +1085,13 @@ function confirmGatedRoutes(facts: ArtifactFacts, card: ScenarioArtifactCard, ob
10561085
* set grants the verb. A refused write of the same persona, object and verb
10571086
* beside it is refused by a row or a field, not the grant; it is named in
10581087
* the detail and judged no further. One exception, not measured and never
1059-
* a pass: a write verb the set withholds that only `pending_confirmation`
1060-
* operations need, where the card's confirm-gated agent action on the
1061-
* object is declared by the build ({@link confirmGatedRoutes}) — the route
1062-
* the card itself designs for a write that asks before acting.
1088+
* a pass: a write verb the set withholds where every operation needing it
1089+
* has a route the card designs and the build declares
1090+
* ({@link designedRoutes}) — the agent action the operation names as its
1091+
* route (`via`), or, for a `pending_confirmation` operation, the card's
1092+
* confirm-gated agent action on the object ({@link confirmGatedRoutes}).
1093+
* An operation without `via` is graded as before: an applied write stays
1094+
* measured whatever actions the build adds.
10631095
* - Refused `PERMISSION_DENIED` only: passes when the set refuses every such
10641096
* write — it grants no verb, or it locks a field each write names
10651097
* ({@link writeRefusalRoute}). When only a row rule could refuse one, the
@@ -1086,8 +1118,18 @@ export function gradePersonaGrants(facts: ArtifactFacts, card: ScenarioArtifactC
10861118

10871119
if (n.requiredBy.length > 0) {
10881120
const beside = refused.length > 0 ? `; ${refused.join(', ')} is refused by a row or a field, not the grant` : '';
1089-
const onlyAwaiting = n.awaitingConfirmation.length === n.requiredBy.length;
1090-
const routed = granted || n.verb === 'read' || !onlyAwaiting ? [] : confirmGatedRoutes(facts, card, n.object);
1121+
const routes = granted || n.verb === 'read' ? undefined : designedRoutes(facts, card, n);
1122+
if (routes !== undefined && routes.some((r) => r.via.length > 0)) {
1123+
const through = routes.map((r) => `operation ${r.operation} through ${[...new Set([...r.via, ...r.confirm])].join(' or ')}`);
1124+
return {
1125+
check: name,
1126+
pass: false,
1127+
notMeasured:
1128+
`${setName} grants no ${n.verb} on ${n.object}, and the build declares the card's agent action each write names as its route (\`via\`) ` +
1129+
`or its confirm-gated one, a door that writes as the platform: whether ${through.join(', ')} goes through it is the run's to observe`,
1130+
};
1131+
}
1132+
const routed = routes === undefined ? [] : routes[0]!.confirm;
10911133
if (routed.length > 0) {
10921134
return {
10931135
check: name,

‎packages/qa/scenarios/test/library.test.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,21 @@ describe('the open scenario library (docs/qa/scenarios)', () => {
226226
if (JSON.stringify([wide.truths[id], wide.personaTruths[id]]) !== JSON.stringify([loaded.truths[id], loaded.personaTruths[id]])) ambiguous.push(`${loaded.card.id}/${id}`);
227227
}
228228
}
229-
// order_to_cash's PAY-0044 (2026-10-01) is the one left: the same defect, outside this change's cards.
230-
expect(ambiguous).toEqual(['order_to_cash/collected_by_team_last_30_days']);
229+
expect(ambiguous).toEqual([]);
230+
});
231+
232+
it('names its decide action as the route (`via`) of each manager approval the card decides through it, and only those', () => {
233+
// The Build grant check leaves these writes to the run when the set withholds the verb and the build
234+
// declares the action. asset_lifecycle manager_approves_scrap and order_to_cash approve_discount have
235+
// the same shape but no measured run behind them, so they stay measured until one exists.
236+
const routed = result.cards.flatMap(({ card }) =>
237+
card.run.operations.filter((o) => o.via !== undefined).map((o) => `${card.id}/${o.id} via ${o.via}`),
238+
);
239+
expect(routed.sort()).toEqual([
240+
'leave_balances/manager_approves_step_one via decide_approval_step',
241+
'requisition_to_receipt/manager_approves_level_one via decide_approval_step',
242+
'travel_expense/manager_approves_step_one via decide_approval_step',
243+
]);
231244
});
232245

233246
it('every card tagged for a report asks for one in its detailed prompt, in both languages', () => {

‎packages/qa/scenarios/test/order-to-cash.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ const EXPECTED_TRUTHS: Record<string, Truth> = {
7070
// 59950. The fourth, a08, has 44950: no tie at the cut-off.
7171
top_accounts_billed: ranking(['a02', 62350], ['a11', 60200], ['a05', 59950]),
7272
// Payments dated 2026-10-02..31. East: a01 5400, a02 21350, a03 9200,
73-
// a07 10800, a08 20200, a09 3800. West: a04 7200, a06 5600, a10 6960,
74-
// a11 28300, a12 5440 (Harbor Foods paid nothing).
75-
collected_by_team_last_30_days: groups(['east', 70750], ['west', 53500]),
73+
// a07 10800, a08 20200, a09 3800. West: a04 7200, a06 5600, a10 11760
74+
// (PAY-0044 on 2026-10-02 included), a11 28300, a12 5440 (Harbor Foods paid nothing).
75+
collected_by_team_last_30_days: groups(['east', 70750], ['west', 58300]),
7676
// The 104 confirmed or fulfilled orders. Subscription is p5, the service line
7777
// when i mod 3 = 1: 40 such orders carry 100 units (1 + i mod 4 cycles
7878
// 2, 1, 4, 3); the 6 not counted (13, 73, 97, 100, 106, 118) carry 13, so

0 commit comments

Comments
 (0)