Repository navigation
Commit d9be915
fix(approvals): a reject carries its reason at the approvals route, decide, the SDK and the inbox (#35741)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D62xGLMbyWJaMEVnAMEjTK1)_
Fixes #35719
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: follow-up #35772 —
packages/spec/src/contracts/approval-service.ts,
packages/plugins/plugin-approvals/src/sys-approval-request.object.ts,
content/docs/automation/approvals.mdx,
docs/qa/platform-checklist/areas/approvals.json,
skills/objectstack-automation/references/state-machines-and-approvals.md
## 维护者速读
- 用户能看到什么变化:审批人在审批收件箱驳回(单条、批量、快捷键)时必须填写理由,理由为空时驳回按钮不可点;通过 SDK
或审批接口驳回而不带理由(或理由不是文字),会被拒绝。
- 为什么做:落实"驳回必须附理由"的要求。动作入口那一半已由另一个 PR 完成并已合入(审批驳回动作的理由改为必填),本 PR
补上审批接口、SDK 和收件箱。
- 出错会怎样:不带理由的驳回会被拒绝并提示缺少理由,审批单保持待处理;系统自动驳回(超时升级、退回次数超限)不受影响;可直接撤回本 PR。
- 要你做什么:这次收窄按新规则需要维护者批准后才能合并(由席位请审)。
## What changes
A reject now always carries its reason on the doors that #35716 left
open. #35716 (merged as `03bce5c2`) is the action-door half: it makes
`approval_reject`'s `comment` param required at the REST action door,
MCP `run_action` and the console param dialog.
- **Service (`@objectstack/plugin-approvals`).**
`ApprovalService.decide()` refuses a reject whose `comment` is missing,
`null`, empty or whitespace-only, or is not a string, before anything is
read or written. The refusal is the action-param refusal, judged by the
same rules over the same `textarea` param (`validateActionParams` from
`@objectstack/spec/ui`): `400 VALIDATION_ERROR` with `Invalid action
params: Action param "comment" is required`, or, for a number, boolean,
array or object, `Invalid action params: Action param "comment"
(textarea): Invalid input: expected string, received number` (or
`boolean`, `array`, `object`), the action door's `invalid_shape`. Every
human door reaches `decide()`: `POST
/api/v1/approvals/requests/:id/reject`, the SDK, and the action door,
which forwards to that route. The route needs no edit. Its error handler
answers a thrown refusal that declares `status` + `code` at its own
status, in the nested ADR-0112 envelope. An approve keeps its comment
optional.
- **System rejects keep working.** The SLA sweep's `auto_reject` calls
the private `decideAndResume` with `comment: 'SLA escalation'`. The
revision-limit auto-reject in `revise` writes its own reject row.
Neither passes through `decide()`. The email action link
(`redeemActionToken`) does pass through, with its fixed text `'Via
action link'`, so it keeps working.
- **SDK (`@objectstack/client`).** `client.approvals.reject(requestId,
decision)` now requires `decision` and its `comment: string` at the type
level. `approve` is unchanged.
- **Console inbox (`@object-ui/console`, `@object-ui/i18n`).** The row
Reject confirmation, the bulk Reject confirmation and the `r` key (which
opens the row confirmation) keep Reject disabled until the reason is
non-blank. The box is no longer labelled optional:
`approvalsInbox.comment` drops "(optional)" in all eleven locale packs.
Approve takes no reason, as before.
- **Remaining leg:** the email action-link reject records the fixed text
`'Via action link'`, and its confirm page has no reason field. That is
follow-up #35722.
Changesets: `@objectstack/plugin-approvals` patch and
`@objectstack/client` patch, each with a BREAKING banner, the ADR-0087
`not-required (no-migration-prescription)` marker and a caller fix line;
`@object-ui/console` + `@object-ui/i18n` patch in `ui/.changeset/`.
## Tests
<details><summary>Unit and UI pins (new or rewritten)</summary>
- `plugin-approvals/src/approval-service.test.ts`: `decide` with a
reject whose comment is `undefined` / `''` / whitespace / `null` throws
`status 400`, `code VALIDATION_ERROR` and the action door's sentence;
`0` / `false` / `[]` / `{}` throw the same code and status with the
exact `(textarea): Invalid input: expected string, received …` sentence.
The request stays `pending`, no reject row is written and no resume
happens. CONTROL: a reject with a reason finalizes `rejected` and
records the comment. Approve without a comment is already pinned by the
resume test above it.
- `qa/dogfood/test/approval-override-composite-pin.dogfood.test.ts`
(real boot, real route): `{}`, `''`, whitespace and `null` each answer
`[400, 'VALIDATION_ERROR']` and the body names `comment`; `0`, `false`,
`[]` and `{}` each answer `[400, 'VALIDATION_ERROR']` with `Action param
"comment" (textarea): `; and the request stays pending with no decision
row. CONTROL: a reject with `'Over budget.'` answers 200, `rejected`,
and its decision row carries the comment. The fixture's existing reject
(line 359) now sends a reason. Its assertions are unchanged.
- `client/src/client.test.ts`: the reject body carries `comment`. Two
`@ts-expect-error` lines prove the type refuses `reject(id)` and
`reject(id, { actorId })`. The test-typecheck ledger holds 0 errors, so
both directives bite.
- `ApprovalsInboxPage.rejectReasonSelfSubmitted-27520.test.tsx`: the old
"left empty, the reject carries no comment" case is replaced by its
opposite. Reject is disabled when the box is empty or whitespace,
enabled once it has text, the `r` key opens the same empty, disabled
confirmation, and no reject call is made. The bulk case asserts the
confirmation is disabled for empty and whitespace before it sends the
reason. The phone-width test reads the new label.
- Existing plugin-approvals tests that rejected through `decide()` with
no comment (20 call sites in 13 files) now pass `comment: 'Over
budget.'`. No assertion was loosened.
</details>
<details><summary>Ablation (fix committed first;
`scripts/ablation-replace.mjs`, restore proven blob == HEAD and git diff
HEAD empty)</summary>
- `approval-service.ts` anchor `if (issues.length > 0) {` changed to `if
(false && issues.length > 0) {` (x1 to x0; blob e28c59b to
cf6d72bc66f4): the decide refusal pin goes red (`expected [ undefined,
undefined ] to deeply equal [ 400, 'VALIDATION_ERROR' ]`), and the
CONTROL pin stays green. plugin-approvals tests import the service from
`src`, so there is no dist leg.
- `approval-service.ts` type key: `[{ name: 'comment', required: true,
type: 'textarea' }]` changed to `[{ name: 'comment', required: true }]`
(x1 to x0; blob 4c675f1 to f1b91d352beb): the decide refusal pin
goes red at its first non-string row (`0: expected [ undefined,
undefined ] to deeply equal [ 400, 'VALIDATION_ERROR' ]`), and the
CONTROL stays green. Restored to the HEAD blob 4c675f1.
- `ApprovalsInboxPage.tsx` row `disabled={!rejectComment.trim()}`
changed to `disabled={false}`: the row pin goes red (1 failed, 6
passed). The bulk `disabled={!bulkRejectComment.trim()}` changed to
`disabled={false}`: the bulk pin goes red (1 failed, 6 passed). Both
were restored to the HEAD blob 52f0397.
</details>
## Verification
Two-minute check: open the Console approvals inbox as an approver and
press Reject on a pending row. The Reject button in the dialog stays
disabled until you type a reason. Then `curl -X POST
.../api/v1/approvals/requests/ID/reject -d '{}'` answers `400` with
`VALIDATION_ERROR` and `Action param "comment" is required`.
Local readings at head `9f0c3e9e6e` (objectstack, with main merged,
#35716 included): plugin-approvals `vitest run` 124 files / 1775 tests
passed; plugin-approvals and client `typecheck` exit 0 (test-typecheck
ledgers held); client `client.test.ts` 222 passed; the two dogfood
approval files 9 passed; showcase `expense-approval-write-back` 6
passed; console inbox files 18 / 95 passed; ui `vitest run scripts/` 171
files / 5092 passed. `dispatch-gates --commands`: 87 derived, 87 run,
all exit 0 (`--ran`: 0 NOT-MEASURED, 0 UNRUN). `overlap-check`: VERDICT
clean. Full dogfood battery at `9f0c3e9e6e`: 482 passed / 3 skipped
files, 4096 passed / 68 skipped tests, no failures. The console
`type-check` is NOT MEASURED locally (the unbuilt `@object-ui/*` closure
gives only module-resolution errors); `Type Check UI` runs it.
## Acceptance notes
- **Ordering.** The reason check runs before the request is read. A
reasonless reject on an id the caller cannot see therefore answers 400,
not 404. That is the action door's order (the param contract before the
subject load), and it leaks nothing about existence.
- **Deferred texts: #35772 widens them.** #35716 has merged
(`03bce5c2`), and these files stay outside this PR's File surface.
#35772 widens #35716's action-scoped sentence ("A reject through
`approval_reject` always carries its reason") in
`sys-approval-request.object.ts`, `approvals.mdx` and `approvals.json`
to cover the approvals route and the SDK. It also makes the spec
contract docblock on `IApprovalService.decide` /
`ApprovalDecisionInput.comment`
(`packages/spec/src/contracts/approval-service.ts`) say that a reject
requires a non-blank string comment, and updates
`skills/objectstack-automation/references/state-machines-and-approvals.md`.
- `ui/e2e/approvals-inbox-phone.spec.ts` builds a hand-written static
markup fixture for a layout measurement, and that fixture still says
"Comment (optional)". It does not render the component, so the
measurement is unaffected. It is left for the inbox's lane.
- **A surface extension, declared here.** The first full dogfood
battery, at `f75dc2fa1d`, found one more stale fixture outside the claim
amendment's list:
`approval-pending-approver-record-read.dogfood.test.ts`. Its `decide`
helper posted `{}` to the reject route and now got `400
VALIDATION_ERROR`. Its reject now sends `{ comment: 'Over budget.' }`,
and its assertions are unchanged. This is the os-dev rule for a red
caused by this change: the stale fixture is fixed in the same PR. That
run's wire body confirmed the envelope as
`{"success":false,"error":{"code":"VALIDATION_ERROR","message":"Invalid
action params: Action param \"comment\" is required"}}`.
- **A second surface extension, declared here.**
`examples/app-showcase/test/expense-approval-write-back.test.ts`: its
`decide` helper now sends a reason on reject (CI Test Core 9/10 red at
`117828962d` on the reasonless reject, green at `a8f6d0bf37`). No
assertion changed.
- The dogfood route pin sits in the existing approvals-route harness
(`approval-override-composite-pin`), which is the claim amendment's
dogfood file. It is two `it` cases in that harness's routes `describe`,
not a new boot.
- Session: https://claude.ai/code/session_016WV4czKnDE6hsyXQzB9wB2
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- signed: repo:objectstack#4 · os-elon-musk ·
session_016WV4czKnDE6hsyXQzB9wB2 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent ccded86 commit d9be915
36 files changed
Lines changed: 215 additions & 61 deletions
File tree
- .changeset
- examples/app-showcase/test
- packages
- client/src
- plugins/plugin-approvals/src
- qa/dogfood/test
- ui
- .changeset
- apps/console/src/pages/system
- packages/i18n/src/locales
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
| 135 | + | |
| 136 | + | |
136 | 137 | | |
137 | 138 | | |
138 | 139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
768 | 768 | | |
769 | 769 | | |
770 | 770 | | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
771 | 780 | | |
772 | 781 | | |
773 | 782 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7059 | 7059 | | |
7060 | 7060 | | |
7061 | 7061 | | |
7062 | | - | |
| 7062 | + | |
| 7063 | + | |
7063 | 7064 | | |
7064 | | - | |
| 7065 | + | |
7065 | 7066 | | |
7066 | 7067 | | |
7067 | 7068 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
313 | | - | |
| 313 | + | |
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
218 | | - | |
| 218 | + | |
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1415 | 1415 | | |
1416 | 1416 | | |
1417 | 1417 | | |
1418 | | - | |
| 1418 | + | |
1419 | 1419 | | |
1420 | 1420 | | |
1421 | 1421 | | |
1422 | 1422 | | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
1423 | 1462 | | |
1424 | 1463 | | |
1425 | 1464 | | |
| |||
1726 | 1765 | | |
1727 | 1766 | | |
1728 | 1767 | | |
1729 | | - | |
| 1768 | + | |
1730 | 1769 | | |
1731 | 1770 | | |
1732 | 1771 | | |
| |||
2799 | 2838 | | |
2800 | 2839 | | |
2801 | 2840 | | |
2802 | | - | |
| 2841 | + | |
2803 | 2842 | | |
2804 | 2843 | | |
2805 | 2844 | | |
| |||
6603 | 6642 | | |
6604 | 6643 | | |
6605 | 6644 | | |
6606 | | - | |
| 6645 | + | |
6607 | 6646 | | |
6608 | 6647 | | |
6609 | 6648 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
6481 | 6482 | | |
6482 | 6483 | | |
6483 | 6484 | | |
| 6485 | + | |
| 6486 | + | |
| 6487 | + | |
| 6488 | + | |
| 6489 | + | |
| 6490 | + | |
| 6491 | + | |
| 6492 | + | |
| 6493 | + | |
| 6494 | + | |
6484 | 6495 | | |
6485 | 6496 | | |
6486 | 6497 | | |
6487 | 6498 | | |
6488 | 6499 | | |
6489 | 6500 | | |
| 6501 | + | |
| 6502 | + | |
| 6503 | + | |
| 6504 | + | |
| 6505 | + | |
| 6506 | + | |
| 6507 | + | |
| 6508 | + | |
| 6509 | + | |
6490 | 6510 | | |
6491 | 6511 | | |
6492 | 6512 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
513 | 513 | | |
514 | 514 | | |
515 | 515 | | |
516 | | - | |
| 516 | + | |
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
| |||
0 commit comments