Repository navigation
Commit 27c0b20
feat(approvals): platform_admin approver type for a deployment's own packaged flows (#34300)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbCpddLFmKzR39wJWZpkRMCi)_
Fixes #34218
Clause-②: yes (widening)
Metadata-protocol: added
The widening: `ApproverType` accepts a new member, `platform_admin`,
which takes no `value`. Nothing accepted before is refused. The
narrowing that comes with it applies only to the new member: it is
refused outside the running body of a `source: 'code'` package's flow.
## 维护者速读
- 改了什么:审批节点新增审批人类型
`platform_admin`,把一步交给平台管理员处理;"只有该类型能打开平台管理员槽位"这条规则在决策、越权、收件箱各入口实际读取的待审名单上成立;本轮起,请求在开启时记下"由
`platform_admin` 步骤打开了该槽位",各入口只在带此记录的请求上认这个槽位。
- 为什么改:平台自带的流程(cloud#4632 在等)需要平台管理员审批;合同审核 6912724496 与复审 6916583417
要求该规则在各入口读取的名单上、对每一个请求都成立。
-
风险与回滚:只有部署在代码里注册的包的流程能用它,别处一律拒绝开启;含该槽位的请求,组织管理员不能越权代审;不带开启记录的请求上,各入口不认该槽位,存量数据不改写、无需迁移;回滚即撤这个
PR。
- 先看:`approval-service.ts` 的 `pendingSlateOf` 与
`syncApproverIndex`(开启记录与各入口的读法),`approver-address.ts` 的
`pendingSlateAsDoorsRead` 与 `readsAsPlatformAdminAddress`,再看
`stepRunsInArmedBody`。
- 两分钟验证:`pnpm --filter @objectstack/plugin-approvals exec vitest run
src/platform-admin-approver-34218.test.ts`,预期 52 条全过。
- 需要你做的:无,席位落地。
## What changes
- **spec** (`packages/spec/src/automation/approval.zod.ts`):
`ApproverType` gains `platform_admin`. Its value binding is `auto` (no
`value`), it is not org-scoped, and it is in
`NON_AUTHORABLE_APPROVER_TYPES`, so no designer offers it. The
`.describe()` text says who may use it. The generated reference
(`content/docs/references/automation/approval.mdx`) is regenerated.
- **expansion** (`approval-service.ts`, `approver-address.ts`): the type
expands to ONE address slot, `platform_admin:*`. No administrator is
enumerated, no one is notified, and the slot grants no record read.
`slateNamesAPerson` counts it, so `onEmptyApprovers` does not treat the
slate as empty.
- **admission**: `actingAddresses` adds the slot for a caller whose
`platformAdmin` flag is set, and `resolveActor` admits a caller naming
the slot. Both read `hasPlatformAdminStanding(engine, callerId)` from
`@objectstack/core` at that moment, memoized per request context. The
predicate is not re-derived, it has no org scope, and it never reads the
session's posture. A decision records the person (`actor_id`) and the
slot (`acted_as`), in the #21411 shape.
- **only the typed approver opens the slot, on the slate the doors
read** (`approver-address.ts`, `approval-service.ts`): `readStoredSlate`
is the one reading of a stored slate. `readsAsPlatformAdminAddress` and
`withoutPlatformAdminAddress` judge the slot on what that reading
answers, for any entry, text or not: an entry that is not text is judged
as the text the stored slate holds for it. The rule is applied wherever
a slate is resolved or rewritten: each approver entry in
`expandApprovers` (the approvers, the fallback slate, the
administrators' slate, and the tally's legacy re-resolution), an
out-of-office hop in `applyOooDelegation` (the slot stays with its
approver), the SLA hand-over's holders, and `reassignTargetRefusal`
(reassign, and the SLA's literal target), which now judges the slot
first. An entry that resolves to the slot adds nothing and logs one
warning naming the entry. A vote's rewrite of the slate is a subset of
the open-time snapshot, which these rules built.
- **the doors honour the slot only on a request a `platform_admin` step
opened** (`approval-service.ts`, `approver-address.ts`): when a request
opens, its config snapshot records `__platformAdminSlotOpened: true`
exactly when the step names the `platform_admin` type (admitted at node
entry) and the slate holds the slot. Only the open path writes it, and a
key of that name handed in with a step's config is dropped
(`ApprovalNodeConfigSchema` declares none). Every door reads the pending
slate through one reader, `pendingSlateOf` (`pendingSlateAsDoorsRead`),
which keeps the slot only on a request that carries the record: the
served request and its per-viewer flags, the decision, send-back,
comment, hand-off, reminder and override admissions, the action-link
minting, the SLA hand-over, and the approver index behind the inbox
(`syncApproverIndex` on every write that sets the slate, and the rebuild
at plugin start). The stored text is not rewritten.
- **who may name it**: at node entry, `platformAdminApproverRefusal`
reads the armed body's package through `flowPackageOf`
(`armedFlowPackage`), never `packagedFlowOwner`. A registry row with
`source: 'code'` is admitted. A row with any other source is refused.
With no row, the residual-owner reading applies: `residualOwnerSource`
`'code'` admits, and anything else refuses. The fallback slate is
checked the same way. The origin is answered for the body whose step is
being opened: the approval executor hands the node it runs
(`approval-node.ts`), and `stepRunsInArmedBody` opens the step only when
the body armed under the flow's key (the run's slot through
`getFlowSlot`, else the bare name through `getFlow`) holds that node
object. A refusal throws `FORBIDDEN: …` before anything is written.
- **override**: on a request whose pending slate holds
`platform_admin:*`, the #3424 tenant-admin (organization administrator)
override arm is withheld at every override admission: decide, reassign,
recall, and the `viewer.can_override` flag they agree with.
`isOverrideActor` takes the slate from those admissions only (the read
grants pass none), and the slot test is
`slateHoldsPlatformAdminAddress`. The platform-admin override arm and
the system context are unchanged. Override is whole-request, so on a
mixed slate the guard holds for the whole request, and the ordinary slot
holder still decides as a slot holder.
- **moving the slot**: reassigning the platform slot itself needs
platform standing now, the platform override, or the system.
- **save door** (`packages/lint`): `validateApprovalApprovers` takes `{
atSaveDoor }`. The runtime publish gate passes it (`ctx.runtimeWriteType
!== undefined`), and there a `platform_admin` approver, or fallback
approver, is an error, `approval-approver-platform-admin-authored`. `os
lint` and the other CLI commands know the type and refuse nothing. The
rule id is exported from the barrel.
- **docs**: `content/docs/automation/approvals.mdx` gains a "Routing to
the platform administrators" section.
## Tests
`packages/plugins/plugin-approvals/src/platform-admin-approver-34218.test.ts`,
52 tests: real ObjectQL over SQLite, the real
`hasPlatformAdminStanding`, a real package registry with code,
marketplace and authored packages and recorded residual owners, and (for
the origin pins) the real `AutomationEngine`.
- The slot opens and tells no one. A grant admin and the verified
configured owner (no grant row) each find it in the inbox and decide it
as an ordinary approver (`actor_id` the person, `acted_as` the slot, not
an override).
- A member of the request's organization takes no slot. An organization
administrator takes no slot and no override (decide, reassign, recall
refused; `viewer` `{ can_act: false, can_override: false }`); another
organization's administrator cannot decide. Mixed slate: the
organization administrator is withheld whole, the ordinary holder
decides. CONTROLS: the tenant arm is unchanged on a slate without the
slot; the platform override arm is unchanged on it.
- A revoked administrator cannot decide a request opened before the
revocation.
- Refused at node entry, writing nothing: a flow authored in the
environment, an environment override of a host flow, a marketplace
package's flow, an authored package's, an unrecorded package's, a
marketplace residual's, and a fallback slate naming the type. A residual
owner a code door recorded is admitted.
- **Cases 1 to 23: no route but the typed approver opens the slot on the
slate the doors read.** Each case resolves or rewrites a slate on one
route (approver entries of each kind, record values, directory values,
an out-of-office delegation, a fallback slate, the administrators'
slate, a vote, the SLA hand-over, a hand-off target, a queue's members,
an expression yielding a list of people) and asserts, for cases 7 to 23,
every door: the request as served, the inbox after the approver index is
rebuilt from the stored slate, the decision admission for a caller in
platform standing naming the slot, and the override admission (the
tenant arm stands).
- The slot test is total: each entry that is not text is judged as the
text the stored slate holds for it.
- **The doors honour the slot only on a request that records a
`platform_admin` step opened it.** CONTROL: a request a `platform_admin`
step opened records it, and every door reads the slot (served, listed
for a platform administrator, the tenant arm withheld, decided under the
slot). A request whose snapshot carries no record, its stored slate
unchanged: no door reads the slot (served without it, not listed,
decision under it refused, the tenant arm stands), and its people decide
as before. On such a request, a vote that rewrites the slate indexes no
slot for the inbox. A step's config cannot carry the record: the spec
schema refuses the key, and the open path drops it.
- The platform's place on a mixed slate moves only for a platform
administrator or the system.
- **The origin is answered for the body whose step is being opened, on
the real flow engine:** a real run of a code package's flow opens on the
slot, the origin read through the run's slot (`getFlowSlot`); on that
read and on the bare read (`getFlow`), the armed body's own step opens
and a step the armed body does not hold is refused, writing nothing. The
stand-in pins for the same rule stay.
- The save door refuses the type; `os lint` refuses nothing. CONTROL: a
`user` approver opens as before and the platform administrator takes no
slot on it.
Ablations (each through `scripts/ablation-replace.mjs` on the pin file,
source-imported so no dist leg; every leg restored to the HEAD blob with
`git diff HEAD` empty, and no marker left):
- On head 5c86710, in one lock hold after the typecheck:
- (S3 doors) `pendingSlateAsDoorsRead` keeping the slot without the
record: `Tests 2 failed | 50 passed (52)`, the two requests without the
record, e.g. `AssertionError: expected { Object (served, listed, ...) }
to deeply equal { served: [ 'u_alice' ], …(2) }`. The CONTROL stays
green.
- (S3 index) `syncApproverIndex` indexing the slot without the record:
`Tests 1 failed | 51 passed (52)`, the vote on a request without the
record, `AssertionError: expected [ …(6) ] to not include 'areq_…'`.
- (S3 record) the open path keeping a record handed in with the config:
`Tests 1 failed | 51 passed (52)`, `AssertionError: expected {
approvers: [ { …(2) } ], …(2) } to not have property
"__platformAdminSlotOpened"`.
- (N7) the slot test without the text coercion: `Tests 1 failed | 51
passed (52)`, the totality pin.
- (S2) `stepRunsInArmedBody` answering yes without asking the armed
body: `Tests 4 failed | 48 passed (52)`, the real-engine slot read and
bare read and the two stand-in pins, e.g. `AssertionError: promise
resolved "{ …(25) }" instead of rejecting`.
- On head 275b45c: (M1) `readsAsPlatformAdminAddress` reverted to the
earlier judgement of the slot: `Tests 15 failed | 30 passed (45)`,
exactly cases 7 to 21, e.g. case 21 `AssertionError: promise resolved "{
request: { …(31) } }" instead of rejecting`.
Earlier rounds' ablations (standing check, decision-only standing check,
source gate, tenant-arm guard, save door both ways) are recorded in the
dev report on the card at 21dd241 and in the hand-off; their anchors
are unchanged on this head.
## Fix rounds
- Round 1 (`8cb89ac5` to `084419d6`): the type, its one slot, admission
by live platform standing, the origin gate at node entry, the save door,
pins and docs.
- Round 2 (`5282972a`, `cffa4a47`, seat ruling Q1 = B): the tenant-admin
override is withheld from a request whose slate holds the platform slot,
a mixed slate whole.
- Round 3 (`0a0baffc` to `ba113a3f`, ruling 6904694980 point 2 as
amended by 6904772436, hand-off 6912407414): only the typed approver
opens the slot on the resolved slate, and the origin is answered for the
body whose step is being opened.
- Round 4 (`275b45c8`, contract review 6912724496): the rule holds on
the slate the decision, override and inbox doors read, for every way a
slate is resolved or rewritten; the origin rule is pinned on the real
flow engine, on both reads.
- Round 5 (`f1a021ef`, `5c867107`, contract review delta 6916583417):
the doors honour the slot only on a request that records a
`platform_admin` step opened it; the slot test is total for entries that
are not text; pins for a queue and an expression yielding a list of
people.
## Acceptance notes
- **The slot stands in for the card's "pending approvers" wording.** The
request stores one address, `platform_admin:*`, as its pending approver,
the way `position:NAME` is stored. The administrators are never listed
onto it.
- **Spelling `platform_admin:*`, not bare `platform_admin`.** The
readers tell an address from a person by the colon, so a bare word would
read as a user id. The `*` says it names no one.
- **Organization administrators (seat ruling Q1 = B).** They take no
slot, and the #3424 tenant-admin override is withheld from any request
whose slate holds `platform_admin:*`, a mixed slate whole. The
platform-admin override arm is unchanged. The type is new, so no served
answer moves.
- **Requests without the record.** The doors honour the platform slot
only on a request that records a `platform_admin` step opened it. A
pending request without that record keeps its stored text as it is, so
nothing is migrated: no door reads the slot on it, and its other
approvers, and the override arms as on `main`, decide it.
- **Inputs accepted on `main` whose behaviour moves (rule-level):** an
approver entry, out-of-office delegate, SLA target or hand-off target
that resolves to the platform slot now adds nothing to the slate (a
hand-off or SLA target is refused, and the slate stays). On `main` such
an entry left a literal on the slate that no acting path admitted, so no
request could be decided through it.
- **Inbox reads**: one extra `resolveUserAuthzGrants` read per caller
per request context, memoized. The server inbox listing still applies
the caller's active-organization wall (nit N3, for the cloud lane to
confirm before cloud#4632 relies on it).
- A `value` on `platform_admin` is ignored, not refused.
- **Follow-ups, not built here:** nit N3 (above) is #34409; nit N6 (a
deployment where nobody has platform standing opens the step on a slot
nobody can take, and nothing warns) and the slot's raw display label
(nit N4) are #34410.
- **Files beyond the claim's literal list, ratified within the
surface:** `approver-address.ts`,
`packages/lint/src/authoring-rules.ts`, `packages/lint/src/index.ts`
(seat ruling Q2 = A), and `approval-node.ts` (hand-off 6912407414).
- **cloud#4632 consumes this.** The cloud lane was asked to confirm that
its packaging registers as `source: 'code'`. A marketplace or authored
registration is refused at node entry by design.
## Verification
<details><summary>Commands and verdicts for head 5c86710</summary>
- `pnpm --filter @objectstack/plugin-approvals typecheck` (includes
`check:test-typecheck`): exit 0.
- `pnpm --filter @objectstack/plugin-approvals test`: Test Files 121
passed (121), Tests 1704 passed (1704). The pin file alone: Tests 52
passed (52).
- Both ran in one verify-lock hold on 5c86710, the suite after every
ablation leg was restored (`git diff HEAD` empty, no marker in either
file).
- `dispatch-gates --commands`: 118 derived (the same list as on
275b45c); all 118 run, each exit 0. `--ran` reconciliation: 118
derived, 118 run, 0 NOT-MEASURED, 0 UNRUN.
- `dispatch-gates --tier`: exit 0, no path-derived mandate; clause-②
suspect surface `approval.zod.ts`, as declared. Changed lines 1570,
under the 3000 threshold.
- CI on 5c86710: 68 check-runs, 56 success, 10 skipped, 2 failure:
`Test Core (3/8)` and its aggregate `Test Core`. The one failing test is
`@objectstack/mcp` `src/mcp-file-tools.test.ts` "out of CPU budget on
the worker: the pages read so far, truncated, with the budget note, as
in-process", a 30 ms CPU-budget read on a worker pool that read no page
(`content: 'none'`). It is not this PR's: `@objectstack/mcp`'s workspace
dependency closure (16 packages) does not include
`@objectstack/plugin-approvals`, the only package this round changed;
the same shard passed on 275b45c; and the file passes on 5c86710
locally (Tests 47 passed (47)). A rerun of that job is the seat's call.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01FEkQ5kgF3mo9f7LXuv5hac
<!-- signed: repo:objectstack#1 · os-project-manager ·
session_01FEkQ5kgF3mo9f7LXuv5hac -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 18194fb commit 27c0b20
11 files changed
Lines changed: 1518 additions & 52 deletions
File tree
- .changeset
- content/docs
- automation
- references/automation
- packages
- lint/src
- plugins/plugin-approvals/src
- spec/src/automation
| 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 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
433 | 433 | | |
434 | 434 | | |
435 | 435 | | |
436 | | - | |
437 | | - | |
438 | | - | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
439 | 440 | | |
440 | 441 | | |
441 | 442 | | |
| |||
454 | 455 | | |
455 | 456 | | |
456 | 457 | | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
457 | 503 | | |
458 | 504 | | |
459 | 505 | | |
| |||
913 | 959 | | |
914 | 960 | | |
915 | 961 | | |
916 | | - | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
917 | 965 | | |
918 | 966 | | |
919 | 967 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
| 128 | + | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| 142 | + | |
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
367 | 373 | | |
368 | 374 | | |
369 | 375 | | |
| |||
1638 | 1644 | | |
1639 | 1645 | | |
1640 | 1646 | | |
1641 | | - | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
1642 | 1651 | | |
1643 | 1652 | | |
1644 | 1653 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
| 341 | + | |
341 | 342 | | |
342 | | - | |
| 343 | + | |
343 | 344 | | |
344 | 345 | | |
345 | 346 | | |
| |||
0 commit comments