Repository navigation
Commit 3693644
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
- .changeset
- docs/qa/scenarios
- packages/qa/scenarios
- src
- runner
- score
- test
- runner
- score
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
282 | 291 | | |
283 | 292 | | |
284 | 293 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
63 | 80 | | |
64 | 81 | | |
65 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
424 | | - | |
| 424 | + | |
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
| |||
0 commit comments