Skip to content
Merged
18 changes: 18 additions & 0 deletions .changeset/33597-persona-grant-checks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@objectstack/scenarios': patch
---

feat(scenarios): the Build half checks each persona's permission set for what the card has that persona read and write

Clause-②: yes (widening) — additive in-process surface of the published `@objectstack/scenarios`, reachable from `./score/full` (`src/score/index.ts` re-exports `scenario-tags.ts`; the narrow `./score` entry does not): the functions `personaGrantNeeds` and `gradePersonaGrants`, the types `PersonaGrantVerb` and `PersonaGrantNeed`, the field `personaGrants` on `ScenarioArtifactScore`, and `ScenarioArtifactCard['run']` accepting optional `questions` and `operations`. `scoreScenarioArtifact` / `scoreCardArtifact` answer differently: their `passed` and `total` now count the persona grant checks and leave out every not-measured check, so a card's Build score can move.
Metadata-protocol: none

`scoreCardArtifact` (and `scoreScenarioArtifact`) gain `personaGrants`: one Build check per persona × object × verb the card implies, named `persona-grant:<persona>:<object>:<verb>`, judged against that persona's own permission set (`<namespace>_<persona id>`, the set the runner signs the persona in with). The needs come from the card alone: a question asked as the persona needs `read` on its object (not when the persona hides that object), an `applied` or `pending_confirmation` operation needs its kind, and an operation refused `PERMISSION_DENIED` must be refused by the set. The grant is read as the platform folds it (`buildEffectiveObjectPermissions`, then `objectPermissionGrants`: edit and delete are read and grant).

- A needed verb passes when the set grants it. A withheld verb that only `pending_confirmation` operations need, where the build declares the card's confirm-gated agent action on that object, is not measured (out of passed and total, never a pass): that action is the route the card designs, and its body writes as the platform.
- A refused write passes when the set grants no verb or locks a field the write names; it is not measured when only a row rule could refuse it, and fails when nothing in the set refuses it.
- A persona whose set the build does not declare fails each of its checks.

Not-measured checks now leave the card score's passed and total.

The run record's build evidence (`./runner`, `runRecord`) lists each persona grant check beside the Build's other checks, so a failing one is named with its detail and a not-measured one with its reason. `personaGrants` also reaches `./runner` through `BuildHalf.score`.
9 changes: 9 additions & 0 deletions docs/qa/scenarios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ for not guessing a name.
minimum option counts, dashboards and app navigation targets. The iterate prompt does the
same for `iterate.expectDelta`. A card therefore picks its dashboard names knowing the build
is told them.
- **Grants.** The Build half checks each persona's permission set for what the card has that
persona do (`persona-grant:<persona>:<object>:<verb>`): `read` on the object of each question
it answers, the kind of each write it applies or confirms, and a refusal of each write the card
refuses it with `PERMISSION_DENIED` (no grant, or a field it may not edit). A write the card
has wait on confirmation may instead go through the card's confirm-gated agent action: when
the set withholds the verb and the build declares that action, the check is not measured. The prompt names
the set and the persona's role; the questions and operations stay out of it, so the role the
card's prose gives a persona must already imply its reads and writes. A grant it does not imply
is a card fix, never a sentence added to the prompt.
- **Tags.** A capability tag whose check reads something the seed does not show is asked for
in the card's prose: `records-forms.master-detail-inline-edit` names the detail edited inline
on its master, in every language the prompt carries.
Expand Down
21 changes: 19 additions & 2 deletions packages/qa/scenarios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ computed truths and declared outcomes:
```ts
import { gradeCardAnswer, gradeCardOperation, scoreCardArtifact } from '@objectstack/scenarios/score/full';

scoreCardArtifact(card, artifact); // a built dist/objectstack.json: expect, tags, agent actions
scoreCardArtifact(card, artifact); // a built dist/objectstack.json: expect, tags, agent actions, persona grants
gradeCardOperation(card, 'remove_ben', observed); // an observed write against its declared outcome
gradeCardAnswer(card, { question: 'account_count', persona: 'sdr', turn }); // an agent's answer
```
Expand All @@ -59,7 +59,24 @@ gradeCardAnswer(card, { question: 'account_count', persona: 'sdr', turn }); // a
- `scenario-tags.ts` — the capability-tag checks and the agent-action exposure check (each
declared action exists on its object, carries `ai.exposed: true`, and carries
`ai.requiresConfirmation: true` where the card says `confirm`; a missing action fails, never
skipped).
skipped), and the persona grant checks (`gradePersonaGrants`): one Build check per persona ×
object × verb the card implies, `persona-grant:<persona>:<object>:<verb>`, against that
persona's own set (`<namespace>_<persona id>`). A question asked as the persona needs `read` on
its object (not when the persona hides that object: it declines), and an `applied` or
`pending_confirmation` operation needs its kind; each passes when the set grants the verb, read
as the platform folds it (`buildEffectiveObjectPermissions`, a `'*'` wildcard included where
`access.default` lets it cover the object, then `objectPermissionGrants`). An operation refused
`PERMISSION_DENIED` passes when the set refuses it: no verb, or a field the write names locked
(not editable, no `when`); it is not measured, out of passed and total, when only a row rule
could refuse it (a write row policy, a row-conditioned field entry), and fails when nothing in
the set does. The same persona, object and verb also needed elsewhere yields the needed check
alone: the refusal is a row's or a field's, not the grant's. A persona whose set the build does
not declare fails each of its checks. One needed write is not measured, never a pass: a verb the
set withholds that only `pending_confirmation` operations need, where the build declares the
card's confirm-gated agent action (`confirm: true`) on that object. That action is the route the
card designs for a write that asks first, and its body writes as the platform, so whether the
write goes through it is the run's to observe (ruling A on #31999 item 9, carried to the Build
side). An `applied` write stays measured against the grant, whatever actions the build adds.
- `scenario-operation-grade.ts` — an observed write against `applied` / `refused` /
`pending_confirmation`; a fact the observation does not carry fails. The operation the
card's `write_validation` guardrail names is graded in two halves: the agent half (its write
Expand Down
2 changes: 1 addition & 1 deletion packages/qa/scenarios/src/runner/scorecard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export function runRecord(meta: RunRecordMeta, cardRun: CardRun): Record<string,
const iterateOut = firstOut ?? (m.iterate?.build.notMeasured ? `not run: the iterate build was not measured (${m.iterate.build.notMeasured})` : undefined);
const buildNote = (b: HalfScores['build']) => (b?.notMeasuredReason ? `not measured: ${b.notMeasuredReason}` : b ? cell(b) : '');
const halves: Array<[string, Tally | undefined, string | undefined, unknown[], string]> = [
['build', s.first.build, m.build?.error, m.build?.score ? [...m.build.score.expect.checks, ...m.build.score.tags.flatMap((t) => t.checks), ...m.build.score.agentActions, ...m.build.score.naming] : [], buildNote(s.first.build)],
['build', s.first.build, m.build?.error, m.build?.score ? [...m.build.score.expect.checks, ...m.build.score.tags.flatMap((t) => t.checks), ...m.build.score.agentActions, ...m.build.score.personaGrants, ...m.build.score.naming] : [], buildNote(s.first.build)],
['run-ask', s.first.ask, m.run?.error, m.run?.questions ?? [], s.first.ask ? cell(s.first.ask) : (firstOut ?? '')],
['run-operations', s.first.operations, m.run?.error, m.run?.operations ?? [], s.first.operations ? cell(s.first.operations) : (firstOut ?? '')],
['iterate-build', s.iterate?.build, m.iterate?.build.error, m.iterate?.build.score ? [...m.iterate.build.score.expect.checks, ...m.iterate.build.score.naming] : [], s.iterate?.build ? buildNote(s.iterate.build) : (firstOut ?? '')],
Expand Down
Loading
Loading