Repository navigation
Commit 2dc69d7
fix(plugin-approvals): a user approver naming no account expands to nobody and takes onEmptyApprovers (#27749)
domain:server#2 · os-sales · session_01L6bhgUCizoYWQVJWjhdR6F
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuPMZ8BHWtPf6nBTp51qSM64)_
Fixes #27397
Clause-②: no
Metadata-protocol: none
Skills-docs: none — no `skills/**` text describes a `user` approver's
resolution; the one docs page that did
(`content/docs/automation/approvals.mdx`, two sentences that this change
makes false) is corrected here
## 维护者速读
- **改了什么**:`user` 类型审批人现在会先查目录(`sys_user`,按 id
或邮箱)。查不到这个账号时,它和部门、团队、岗位这些图类型一样:打同一条 `expanded to nobody`
警告,不占槽位。名单因此变空时,走节点的 `onEmptyApprovers`,默认是 `admin_rescue`。
- **为什么改**:以前写错的用户
id,或者已经删掉的账号,会作为一个谁都处理不了的幽灵槽位开出审批单。没有日志,也没有转交管理员,这张单子会永远挂着。
- **风险与回滚**:低。只有 `sys_user`
读成功、而且确实没有这一行时才丢槽位:读失败时保留原槽位;被封禁的账号、别的组织目录里的人、以及 OOO 委托到真实代理人的情况都不变。回滚就是
revert 这个 PR。
- **先看**:`packages/plugins/plugin-approvals/src/approval-service.ts` 的
`resolveApproverSpec` 里 `type === 'user'`
分支和共用的警告分支;`admin-rescue-named-slate.integration.test.ts` 新增的
describe;`approval-service.test.ts` 的 `ROUTED_USERS` 与
`putAccounts`(夹具改动)。
- **两分钟验证**:`pnpm --filter @objectstack/plugin-approvals exec vitest run
src/admin-rescue-named-slate.integration.test.ts`,预期 22/22 通过,其中包含 "a
`user` approver naming no user expands to nobody" 这一组。
- **需要你做的**:无,席位落地。
## What changes
- **The `user` approver branch** in `resolveApproverSpec`. A `user`
value is now asked of the directory through the predicate the reassign
door already uses (`reassignTargetRefusal`). That predicate looks for a
`sys_user` row carrying the id, or the email for an email-shaped value.
It is asked with no organization, so its tenancy screen does not run:
`user` is directory-less, and ADR-0105 D9 leaves it untouched (the
existing `approver-cross-org` pin holds that). When no account carries
the value, the branch falls through to the graph types' existing warning
(same text, now reached for `user` too) and returns no slot. A slate it
leaves empty reaches the node's `onEmptyApprovers` by the existing path;
there is no new branch and no new warning text.
- **What counts as "no such user"**: a successful `sys_user` read that
returns no row. These cases still keep the slot:
- a **banned** account. The team and department expansions do not read
the flag either; I measured this on `expandTeamUsers` and
`expandBusinessUnitUsers`.
- a **failed read**. A failed read proves nothing, which is this file's
fail-open posture on addressing paths. A new unit pin covers it.
- a value spelled as a `TYPE:VALUE` literal. `slateNamesAPerson` already
reads that as naming no one.
- **Checked after OOO delegation**: the check asks about the slot the
route ends on. A removed account whose out-of-office delegation names a
live delegate still routes to the delegate (the existing #24065
notification-body pin).
- **A mixed slate** (one real user plus one phantom) keeps the real one,
drops only the phantom, and logs the warning once for the phantom. That
is the same per-entry warning a graph entry beside a person logs.
- **Docs**: `content/docs/automation/approvals.mdx` said that a `user`
entry never resolves to nobody. Two sentences are corrected.
- **Fixtures**: the unit doubles started with an empty `sys_user`, so
every `user` approver in them was a phantom by the new rule. They now
start with the accounts each suite routes to (`ROUTED_USERS`, plus
`putAccounts` where a test writes a named row). Three dogfood fixtures
used an address deliberately carried by no account: `CO_APPROVER` (two
of them) and `DEPARTED_APPROVER`. Each pin now signs that address up as
an account that never acts, so the scene each pin measures is unchanged.
The test-typecheck ledger shrinks by two, because a replaced test took
two pre-existing errors with it.
## Tests
The PIN is through the real `ApprovalService.openNodeRequest` on a real
ObjectQL plus SqlDriver, with real administrators. It is a new describe
in `admin-rescue-named-slate.integration.test.ts`:
- a `user` approver naming `usr_does_not_exist` takes the default
`admin_rescue` route. The request opens on `u_admin` and `u_owner`, and
they are told. `approver 'user:usr_does_not_exist' expanded to nobody`
is logged once, and the routing line is logged once. `pending_approvers`
holds no `usr_does_not_exist`, and `admin_rescue:abandoned` is `[]`.
- a mixed list `[u_alice, usr_does_not_exist]` opens on `['u_alice']`
alone, with the phantom's warning logged once and no administrator
routing.
- an email that no account carries is dropped. An email that an account
carries keeps its slot.
- CONTROL: a real user keeps the slot, with no expanded-to-nobody line.
A person of another organization's directory keeps the slot too
(ADR-0105 D9).
The unit pins are in `approval-service.test.ts`. The old "stays quiet
for `user`" test, which pinned the phantom slot, is replaced by three
tests:
- the warning and its meta, with no slot;
- a control in which a real account stays quiet;
- a failed `sys_user` read keeps the slot.
<details><summary>Red first, then green</summary>
Before the fix, the new describe at base `a75ddba1` gave 4 failed and 17
passed (21):
`expected [ 'usr_does_not_exist' ] to deeply equal [ 'u_admin',
'u_owner' ]` · `expected [ 'u_alice', 'usr_does_not_exist' ] to deeply
equal [ 'u_alice' ]` · the email leg · (and the other-org leg, which was
later turned into the D9 control).
At final head ``10a61cc4``, with the closure rebuilt after the
`origin/main` merge, the run under the verify lock gave:
`pnpm --filter @objectstack/plugin-approvals exec vitest run`: Test
Files 105 passed (105), Tests 1338 passed (1338).
`pnpm --filter @objectstack/plugin-approvals typecheck`: exit 0,
`check:test-typecheck: OK` (8 files / 321 errors / 27 pinned
signatures).
`pnpm --filter @objectstack/http-conformance exec vitest run
src/hono-approvals-act.conformance.test.ts`: 4/4. It covers an
unregistered `sys_user`: the read throws and the slot is kept.
</details>
<details><summary>Ablations (scripts/ablation-replace.mjs; the suite
reads src, so no dist leg)</summary>
1. `if (refusal === undefined) return routed;` was replaced with `return
routed;`, which removes the existence check. Result: 4 failed and 405
passed (409). The failures were the three integration legs and the unit
warning pin, for example `expected [ 'usr_does_not_exist' ] to deeply
equal [ 'u_admin', 'u_owner' ]`. The controls stayed green. The restore
was checked: blob `ae44df7ffede` == HEAD, and `git diff HEAD` was empty.
2. `if (GRAPH_APPROVER_TYPES.has(type) || type === 'user') {` was
replaced with `if (GRAPH_APPROVER_TYPES.has(type)) {`, which removes the
shared warning. Result: 3 failed and 406 passed (409): `expected [] to
have a length of 1 but got +0` (twice) and `no warning for user:
expected undefined to be truthy`. The restore was checked: blob == HEAD,
and `git diff HEAD` was empty.
</details>
## Acceptance notes
- Out of scope, and not fixed here: `type: 'field'` has the same
unchecked shape. A record field holding a user id that no account
carries opens a phantom slot in the same way (`resolveApproverSpec`, the
`field` branch, `csvSplit(record[value])` straight to
`applyOooDelegation`). Not filed by this PR; it is named in the report
for the seat.
- Out of scope, and not fixed here: a delegation's `delegate_id` is not
existence-checked either. An OOO hop to a removed account would open a
phantom slot the same way. Noted, not filed.
- `examples/app-showcase` `approver-bindings.flow.ts` carries `{ type:
'user', value: '' }` on an `obsolete` flow. If that flow ever runs, it
now logs `approver 'user:' expanded to nobody`, where before it was
silent. The empty slot was already dropped before this change.
- The dogfood battery does not run on pull requests (its `if:` excludes
them), so the dogfood fixture edits are verified by the local run below,
not by CI on this PR.
## Verification
<details><summary>Gates on `10a61cc4`</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 94 command(s) on `10a61cc4`. I ran
every one at that head and captured each exit code before any pipe:
**94/94 exit 0**.
`dispatch-gates --ran`: `Run reconciliation — 94 derived, 94 run, 0
NOT-MEASURED, 0 UNRUN` · `a DERIVED zero — all 94 recorded an exit code
and none of them is 3`.
I also ran these locally, outside the derived set:
- eslint `--no-inline-config` over `packages/plugins/plugin-approvals`
and the six dogfood files: exit 0.
- the package test suite and typecheck (above).
- the http-conformance approvals pin.
- the nine approval dogfood files that open `user` approvers
(override-composite, my-pending-position, position-address-readers,
admin-rescue-slate, notification-body, pending-approver-record-read,
record-lock-read, sla-reassign-target-resolves,
seed-ownership-claim-dispatch). Run under the verify lock after building
the dogfood closure: Test Files 9 passed (9), Tests 9 passed (9).
`merge-tree` against the three open PRs that touch
`packages/qa/dogfood/test/` (#27713, #27667, #27649) shows no conflict
on any file this PR changes.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L6bhgUCizoYWQVJWjhdR6F)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L6bhgUCizoYWQVJWjhdR6F
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent b2b4972 commit 2dc69d7
24 files changed
Lines changed: 307 additions & 53 deletions
File tree
- .changeset
- content/docs/automation
- packages
- plugins/plugin-approvals
- src
- qa/dogfood/test
- fixtures
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | | - | |
324 | | - | |
| 323 | + | |
| 324 | + | |
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
| |||
422 | 422 | | |
423 | 423 | | |
424 | 424 | | |
425 | | - | |
426 | | - | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
427 | 429 | | |
428 | 430 | | |
429 | 431 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
74 | 81 | | |
75 | 82 | | |
76 | | - | |
| 83 | + | |
77 | 84 | | |
78 | 85 | | |
79 | 86 | | |
| |||
253 | 260 | | |
254 | 261 | | |
255 | 262 | | |
256 | | - | |
| 263 | + | |
257 | 264 | | |
258 | 265 | | |
259 | 266 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
294 | 345 | | |
295 | 346 | | |
296 | 347 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
35 | 42 | | |
36 | 43 | | |
37 | | - | |
| 44 | + | |
38 | 45 | | |
39 | 46 | | |
40 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
14 | 21 | | |
15 | 22 | | |
16 | 23 | | |
| |||
23 | 30 | | |
24 | 31 | | |
25 | 32 | | |
26 | | - | |
| 33 | + | |
27 | 34 | | |
28 | 35 | | |
29 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
27 | 34 | | |
28 | 35 | | |
29 | | - | |
| 36 | + | |
30 | 37 | | |
31 | 38 | | |
32 | 39 | | |
| |||
103 | 110 | | |
104 | 111 | | |
105 | 112 | | |
106 | | - | |
| 113 | + | |
107 | 114 | | |
108 | 115 | | |
109 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
37 | 44 | | |
38 | 45 | | |
39 | | - | |
| 46 | + | |
40 | 47 | | |
41 | 48 | | |
42 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
36 | 43 | | |
37 | 44 | | |
38 | | - | |
| 45 | + | |
39 | 46 | | |
40 | 47 | | |
41 | 48 | | |
| |||
0 commit comments