Skip to content

Commit 3693644

Browse files
feat(scenarios): check each persona's permission set against what the card has it read and write (#33630)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoHnY9LA8HUaCTtrGYLcCo2G)_ 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) and, for `personaGrants`, from `./runner` through `BuildHalf.score`: 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. `./runner`'s `runRecord` lists each persona grant check in the first build's evidence. Metadata-protocol: none Part-of #33597 (the card stays open for its done-when 2 card-fix round, seat record 6889635350) ## 维护者速读 - 改了什么:场景卡 Build 评分新增 `persona-grant:<persona>:<object>:<verb>` 检查,按卡片本身推出每个角色该读、该写、该被拒的对象权限,拿去比对构建出的该角色权限集。 - 为什么改:首轮实跑 project_with_tasks 的 contractor 权限集只读,任务增删改全部 403,而 Build 分仍是 30/30;这次让 Build 分在构建阶段就把它记成 32/34。 - 风险与回滚:只改 `@objectstack/scenarios` 的评分(`scenario-tags.ts` 加测试和文档,另在 runner 的 `scorecard.ts` 证据列表加一行,席位在审查后纳入本 PR),不碰 schema、卡片 JSON;回滚即 revert 本 PR。 - 先看:`packages/qa/scenarios/src/score/scenario-tags.ts` 的 `personaGrantNeeds` 与 `gradePersonaGrants`,以及下方“九个录制构建前后对比”表。 - 两分钟验证:`pnpm --filter @objectstack/scenarios exec vitest run test/score/scenario-tags.test.ts test/score/scenario-cards.test.ts`(111 项全绿)。 - 需要你做的:无须裁决;下方 Acceptance notes 列出了不能追溯到 prompt 的授权,由 #33597 下一轮修卡处理(本 PR 合并后不关卡)。 ## What changes `scoreCardArtifact` / `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 set (`<namespace>_<persona id>`, the name the runner's `permissionSetName` signs the persona in with). **What the card implies, from the card alone** (`personaGrantNeeds`): - a question asked as a persona (`questions[].personas`) needs `read` on its object, unless the persona hides that whole object (`hidden.objects`): such a persona declines, it reads nothing; - an operation with outcome `applied` or `pending_confirmation` needs its kind (`create` / `update` / `delete`) on its object, for `actingAs`; - an operation refused `PERMISSION_DENIED` must be refused by that persona's set; any other refusal (`VALIDATION_FAILED`) implies nothing about the grant. **How a check is judged** (`gradePersonaGrants`). The grant is the platform's own answer: the set is folded by `@objectstack/core`'s `buildEffectiveObjectPermissions` (the map `/auth/me/permissions` serves, the `'*'` wildcard included where the object's `access.default` lets it cover), then asked through the spec's `objectPermissionGrants` (edit and delete are read ∧ grant, as the enforcement door folds them). No model judge, no network. - Needed: passes when the set grants the verb. If the same persona, object and verb is also refused elsewhere on the card (requisition_to_receipt's department manager approves level one and is refused the finance level), the needed check is the only check, and its detail names the refusal "refused by a row or a field, not the grant". - Needed, withheld, on the card's confirm-gated route: **not measured**, never a pass (fork 2 below). - Refused only (option B, seat comment 6888060472): passes when the set grants no verb, or locks a field the write names (an entry with no `when`, not editable, no Modify All vote to override it; the platform answers the same 403 from plugin-security's field-level write step). It is **not measured** when only a row rule could refuse it (an applying write row policy or a row-conditioned field entry), 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`, as `CheckResult.notMeasured` already promises. Files: `packages/qa/scenarios/src/score/scenario-tags.ts`, its tests (`test/score/scenario-tags.test.ts`, `test/score/scenario-cards.test.ts`), `packages/qa/scenarios/README.md`, `docs/qa/scenarios/README.md` (a **Grants.** bullet under "Build checks trace to the prompt"), one changeset, and one line in `src/runner/scorecard.ts` (`runRecord`'s build evidence) with its pin in `test/runner/orchestrate.test.ts` — the order kept `src/runner/**` off-limits until #33625 merged; the seat took that follow-up (review#2 N4) into this PR after it did. None of the other paths the order puts off-limits (`src/schema.ts`, `scenario-run-grade.ts`, `scenario-operation-grade.ts`, `score/index.ts`, `docs/qa/scenarios/*.json`) and no `packages/spec` or governed path is touched. ## Why The first live run of project_with_tasks built a contractor set that reads tasks only; every task write the card gives the contractor came back 403, and the Build half still scored 30/30, because nothing compared the sets against what the card has each persona do. The prompt already asks for it (`packages/qa/scenarios/src/runner/prompts.ts`): > People: declare one permission set per person below, named exactly as shown, granting what that role needs on the app’s objects and nothing it must not see. The runner signs each person in as a user holding only that set. ### Fork 1: a `PERMISSION_DENIED` refusal is not only an absent grant The platform answers 403 `PERMISSION_DENIED` for an object verb it does not grant, a field the set does not let the caller edit, and a row its policy refuses. The seat ruled option B (seat comment 6888060472): a refused write passes on an absent grant or a field lock on a field it names, is not measured when only a row rule could refuse it, and fails when nothing refuses it. ### Fork 2: a write the card routes through a confirm-gated action Ruling A on #31999 item 9 (record 6764953017), quoted: > A probe that meets the build's own lock (a write the build locked and routed through an action, refused 403 PERMISSION_DENIED) scores the platform half **not measured**: out of numerator and denominator, with the reason written on the scorecard. Never a pass. The three model-built crm builds withhold the sdr's raw contact delete and route it through the card's confirm-gated `delete_contact` action (an action body runs elevated; the MCP/REST action door gates only on `requiredPermissions`). The seat first carried ruling A to the Build side as (ii): a withheld write verb on an object where the build declares the card's agent action is not measured. Measured, (ii) erased the target defect: every control card declares an agent action for each write it asks, and the r1 project build declares all three (`demoproject_create_task`, `demoproject_set_task_status`, `demoproject_delete_task`), so r1 would have scored 32/32. The seat then ruled **(ii-a)**, which replaces (ii), with this reasoning: - the prompt asks the set to grant "what that role needs" for "a user holding only that set", while agent actions are ones an agent "may call" (`prompts.ts`: "Business actions an AI agent may call (expose each to AI; ask before acting where marked)"). They are an optional route, so an `applied` write stays measured against the grant; - the one route the card designs as **the** route is the confirm-gated action for a `pending_confirmation` operation ("ask before acting"). Only there does a missing raw verb count as not measured, with the action named, never a pass. The rule as built: a write verb the set withholds that only `pending_confirmation` operations need, where the card's agent action on that object has `confirm: true` and the build declares it there by name. ### Nine recorded builds, before → after Each recorded build was rebuilt from its recorded source against the published 18.4.0 install (`objectstack build`, exit 0 each) and scored with `scoreCardArtifact` over the namespaced card. "Before" is the Build score without the persona grant checks. | Build | Before | (ii) as first ruled | After, (ii-a) | Persona grant checks that do not pass | |:--|:--|:--|:--|:--| | r1 crm_account_with_contacts | 20/21 | 26/27 | **26/27** | none | | r1 invoice_with_line_items | 32/32 | 40/40 | **40/40** | none | | r1 project_with_tasks | 30/30 | 32/32 | **32/34** | contractor task create (fail), update (fail): the target defect; delete not measured (`demoproject_delete_task`) | | haiku crm | 22/22 | 27/27 | **27/27** | sdr contact delete not measured (`democrm_delete_contact`) | | opus crm | 22/22 | 27/27 | **27/27** | sdr contact delete not measured (`democrm_delete_contact`) | | sonnet crm | 20/21 | 25/26 | **25/26** | sdr contact delete not measured (`democrm_delete_contact`) | | haiku invoice | 31/31 | 39/39 | **39/39** | none | | opus invoice | 31/31 | 39/39 | **39/39** | none | | sonnet invoice | 31/31 | 39/39 | **39/39** | none | The literal reading (i) would fail the sdr delete on all three model crm builds (27/28, 27/28, 25/27). The r1 invoice run's 403 on the sales_rep's line create is not an object-grant gap: the set grants create. #33596 records that `add_line`'s declared values omit the required `unit_price`. These checks read field entries only for writes the card refuses, so that gap is not visible as a Build finding here, and this PR does not widen into it. ## Verification Run from the worktree at head `0b8737ea` (after merging `origin/main` at `6e287974`), with the package closure built (`turbo run build --filter='./packages/**' --filter='@objectstack/dogfood^...'`, exit 0). Head `ead8d70a` after it changes only the changeset's `Clause-②` line (to the widening above); `check-empty-changeset` and `check-changeset-no-major` re-ran on it, exit 0. - `pnpm --filter @objectstack/scenarios test` — 32 files, 720 passed. `tsc --noEmit` exit 0. Root eslint (`--no-inline-config`) on the three changed source/test files exit 0. Of those, `test/score/` is 198 passed: `scenario-tags.test.ts` pins, on the real `project_with_tasks` and `requisition_to_receipt` cards: - derivation (one need per persona × object × verb; nothing from a question about a hidden object; `VALIDATION_FAILED` derives nothing); - a grant present (all pass); a grant missing (the read-only contractor of the first live run: create, update and delete fail, with the detail `contractor grants no create on task, which operation add_task needs`); - a grant the card refuses: absent (pass), granted with nothing refusing (fail), a field lock (pass; a lock on another field and a Modify All override fail), only a row rule (not measured, `total` down by one); - fork 2 (ii-a): the withheld delete beside the build's confirm-gated `delete_task` is not measured with the action named, `total` down by one; with the card action not confirm-gated, or the delete applied outright, it fails; the withheld update stays failed beside `set_task_status`; - edit/delete fold read ∧ grant; the `'*'` wildcard covers a public object and not a private one; the namespaced set name, and a missing set failing every check. - `scenario-cards.test.ts`: the crm control's completed build scores 1; removing the sdr's contact edit or giving the partner user account edit scores lower; removing the sdr's contact delete keeps 1 with `total` and `passed` one lower (the confirm-gated route). - Ablations through `node scripts/ablation-replace.mjs` (each restored to the HEAD blob, `git diff HEAD` empty): forcing `granted` to `true` turned 6 persona tests red; deleting the field-lock return turned the field-lock pin red; deleting the `confirm === true` condition turned 4 red; deleting the `pending_confirmation`-only condition turned the applied-delete pin red. - Derived gates: `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` listed 63; each ran with `</dev/null`, all `:: exit 0`; `--ran` reconciliation: 63 derived, 63 run, 0 NOT-MEASURED, 0 UNRUN. ## Acceptance notes - **Grants that do not trace to the prompt.** The control cards' prompts state no persona writes; the write grants rest on the role name alone: crm sdr contact create/update/delete, invoice sales_rep invoice_line create/delete and invoice update, invoice warehouse_staff invoice update (refused), project contractor task create/update/delete. Starter cards trace, except leave_balances hr_officer leave_request delete (not in the prose). Card fixes are separate cards. - **Questions asked as a persona who hides the object** derive no read (the persona declines): crm partner_user/account, project client_viewer/task, order_to_cash sales_rep/payment, travel finance_officer/trip_request, asset employee/depreciation_entry. Whether each card means "declines" there is a card question, not this check's. - **isDefault, scratch vs template.** The checks judge the persona's own set only, as the data contract says ("holding only that set"). In scratch mode `os serve` also hands an `isDefault` set to every member (`appSecurityPluginOptions`); in template mode a package-level `isDefault` is a suggestion only. A build that grants through an `isDefault` set would run in scratch and fail here; that gap is reported, not closed. - **Done here at the seat's word (was a follow-up):** the runner scorecard's evidence list (`packages/qa/scenarios/src/runner/scorecard.ts`, `runRecord`) adds `...m.build.score.personaGrants` (head `279ac14b`), pinned in `test/runner/orchestrate.test.ts`; the tally already counted them. - Assignee and reviewer steps were skipped by order (relay draft, no reviewers). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L9qibxF3yXjruc2fxomWA5 <!-- signed: epic:#33595#1 · os-tesla · session_01L9qiby1cctpVpRbJzjccvY --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f21d980 commit 3693644

8 files changed

Lines changed: 548 additions & 34 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
---
4+
5+
feat(scenarios): the Build half checks each persona's permission set for what the card has that persona read and write
6+
7+
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.
8+
Metadata-protocol: none
9+
10+
`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).
11+
12+
- 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.
13+
- 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.
14+
- A persona whose set the build does not declare fails each of its checks.
15+
16+
Not-measured checks now leave the card score's passed and total.
17+
18+
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`.

‎docs/qa/scenarios/README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,15 @@ for not guessing a name.
279279
minimum option counts, dashboards and app navigation targets. The iterate prompt does the
280280
same for `iterate.expectDelta`. A card therefore picks its dashboard names knowing the build
281281
is told them.
282+
- **Grants.** The Build half checks each persona's permission set for what the card has that
283+
persona do (`persona-grant:<persona>:<object>:<verb>`): `read` on the object of each question
284+
it answers, the kind of each write it applies or confirms, and a refusal of each write the card
285+
refuses it with `PERMISSION_DENIED` (no grant, or a field it may not edit). A write the card
286+
has wait on confirmation may instead go through the card's confirm-gated agent action: when
287+
the set withholds the verb and the build declares that action, the check is not measured. The prompt names
288+
the set and the persona's role; the questions and operations stay out of it, so the role the
289+
card's prose gives a persona must already imply its reads and writes. A grant it does not imply
290+
is a card fix, never a sentence added to the prompt.
282291
- **Tags.** A capability tag whose check reads something the seed does not show is asked for
283292
in the card's prose: `records-forms.master-detail-inline-edit` names the detail edited inline
284293
on its master, in every language the prompt carries.

‎packages/qa/scenarios/README.md‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ computed truths and declared outcomes:
4949
```ts
5050
import { gradeCardAnswer, gradeCardOperation, scoreCardArtifact } from '@objectstack/scenarios/score/full';
5151

52-
scoreCardArtifact(card, artifact); // a built dist/objectstack.json: expect, tags, agent actions
52+
scoreCardArtifact(card, artifact); // a built dist/objectstack.json: expect, tags, agent actions, persona grants
5353
gradeCardOperation(card, 'remove_ben', observed); // an observed write against its declared outcome
5454
gradeCardAnswer(card, { question: 'account_count', persona: 'sdr', turn }); // an agent's answer
5555
```
@@ -59,7 +59,24 @@ gradeCardAnswer(card, { question: 'account_count', persona: 'sdr', turn }); // a
5959
- `scenario-tags.ts` — the capability-tag checks and the agent-action exposure check (each
6060
declared action exists on its object, carries `ai.exposed: true`, and carries
6161
`ai.requiresConfirmation: true` where the card says `confirm`; a missing action fails, never
62-
skipped).
62+
skipped), and the persona grant checks (`gradePersonaGrants`): one Build check per persona ×
63+
object × verb the card implies, `persona-grant:<persona>:<object>:<verb>`, against that
64+
persona's own set (`<namespace>_<persona id>`). A question asked as the persona needs `read` on
65+
its object (not when the persona hides that object: it declines), and an `applied` or
66+
`pending_confirmation` operation needs its kind; each passes when the set grants the verb, read
67+
as the platform folds it (`buildEffectiveObjectPermissions`, a `'*'` wildcard included where
68+
`access.default` lets it cover the object, then `objectPermissionGrants`). An operation refused
69+
`PERMISSION_DENIED` passes when the set refuses it: no verb, or a field the write names locked
70+
(not editable, no `when`); it is not measured, out of passed and total, when only a row rule
71+
could refuse it (a write row policy, a row-conditioned field entry), and fails when nothing in
72+
the set does. The same persona, object and verb also needed elsewhere yields the needed check
73+
alone: the refusal is a row's or a field's, not the grant's. A persona whose set the build does
74+
not declare fails each of its checks. One needed write is not measured, never a pass: a verb the
75+
set withholds that only `pending_confirmation` operations need, where the build declares the
76+
card's confirm-gated agent action (`confirm: true`) on that object. That action is the route the
77+
card designs for a write that asks first, and its body writes as the platform, so whether the
78+
write goes through it is the run's to observe (ruling A on #31999 item 9, carried to the Build
79+
side). An `applied` write stays measured against the grant, whatever actions the build adds.
6380
- `scenario-operation-grade.ts` — an observed write against `applied` / `refused` /
6481
`pending_confirmation`; a fact the observation does not carry fails. The operation the
6582
card's `write_validation` guardrail names is graded in two halves: the agent half (its write

‎packages/qa/scenarios/src/runner/scorecard.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ export function runRecord(meta: RunRecordMeta, cardRun: CardRun): Record<string,
421421
const iterateOut = firstOut ?? (m.iterate?.build.notMeasured ? `not run: the iterate build was not measured (${m.iterate.build.notMeasured})` : undefined);
422422
const buildNote = (b: HalfScores['build']) => (b?.notMeasuredReason ? `not measured: ${b.notMeasuredReason}` : b ? cell(b) : '');
423423
const halves: Array<[string, Tally | undefined, string | undefined, unknown[], string]> = [
424-
['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)],
424+
['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)],
425425
['run-ask', s.first.ask, m.run?.error, m.run?.questions ?? [], s.first.ask ? cell(s.first.ask) : (firstOut ?? '')],
426426
['run-operations', s.first.operations, m.run?.error, m.run?.operations ?? [], s.first.operations ? cell(s.first.operations) : (firstOut ?? '')],
427427
['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 ?? '')],

0 commit comments

Comments
 (0)