Skip to content

Commit d9be915

Browse files
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
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/plugin-approvals': patch
3+
---
4+
5+
fix(approvals): a reject through the approvals route or `IApprovalService.decide` requires a reason
6+
7+
Clause-②: no (narrowing)
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export changes shape. What moves is one runtime check in this plugin's decide(): a reject without a non-blank string comment is refused. No stored row, registry key or authored value changes, so there is nothing for a migration to rewrite and no tombstone. -->
11+
12+
**BREAKING** for a caller of `POST /api/v1/approvals/requests/:id/reject`, or of `IApprovalService.decide()` with `decision: 'reject'`, that sends no `comment`, an empty or whitespace-only one, or one that is not a string: the call used to reject the request and is now refused before anything is read or written. It ships `patch` because it is a non-protocol breaking change (AGENTS.md Post-Task Checklist step 3): nothing a metadata author writes changes, so `Metadata-protocol` is `none`.
13+
14+
The refusal is the one the `approval_reject` action door gives, judged by the same rules over the same `textarea` param: `400 VALIDATION_ERROR` with `Invalid action params: Action param "comment" is required` for an absent, `null`, empty or whitespace-only value, and `Invalid action params: Action param "comment" (textarea): …` for a value that is not a string (a number, a boolean, an array or an object). The request stays pending. A reject with a reason runs as before, and an approve keeps its comment optional. The platform's own rejects keep working: the SLA escalation's `auto_reject` and the revision-limit auto-reject do not pass through `decide()`, and the email action link records its fixed text. The email action link still records no reason the approver typed; that is a separate follow-up.
15+
16+
Fix for a caller: send the reason as `comment` in the reject body (`{ "comment": "Over budget." }`).
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/client': patch
3+
---
4+
5+
fix(client): `client.approvals.reject` requires the decision and its `comment`
6+
7+
Clause-②: no (narrowing)
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) No spec key or authored value changes. What moves is the parameter type of one SDK method: the decision argument and its comment member become required, matching the approvals route, which now refuses a reject without a reason. No stored row changes, so there is nothing for a migration to rewrite. -->
11+
12+
**BREAKING** for TypeScript callers of `client.approvals.reject(requestId)` or `client.approvals.reject(requestId, { actorId })`: the decision argument and its `comment` are now required, so those calls no longer compile. At runtime the approvals route refuses a reject without a non-blank reason with `400 VALIDATION_ERROR`. It ships `patch` because it is a non-protocol breaking change (AGENTS.md Post-Task Checklist step 3). `client.approvals.approve` is unchanged; its comment stays optional.
13+
14+
Fix for a caller: pass the reason, `client.approvals.reject(requestId, { comment: 'Over budget.' })`.

‎examples/app-showcase/test/expense-approval-write-back.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ async function statusOf(booted: Booted, id: string): Promise<string> {
132132
}
133133

134134
async function decide(booted: Booted, requestId: string, decision: 'approve' | 'reject', actorId: string) {
135-
return booted.approvals.decide(requestId, { decision, actorId }, SYSTEM_CTX);
135+
// A reject carries its reason: `decide()` refuses one without it.
136+
return booted.approvals.decide(requestId, { decision, actorId, ...(decision === 'reject' ? { comment: 'Over budget.' } : {}) }, SYSTEM_CTX);
136137
}
137138

138139
/** The pre-fix shape: the outcome arms go straight to bare `end` nodes. */

‎packages/client/src/client.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,15 @@ describe('Approvals namespace (ADR-0019)', () => {
768768
const [url, opts] = fetchMock.mock.calls[0];
769769
expect(url).toContain('/api/v1/approvals/requests/req-1/reject');
770770
expect(opts.method).toBe('POST');
771+
expect(JSON.parse(opts.body).comment).toBe('Missing fields');
772+
// A reject carries its reason: the decision and its `comment` are required.
773+
const typeOnly = () => {
774+
// @ts-expect-error — no decision, so no reason
775+
void client.approvals.reject('req-1');
776+
// @ts-expect-error — a decision without its reason
777+
void client.approvals.reject('req-1', { actorId: 'user-1' });
778+
};
779+
void typeOnly;
771780
});
772781

773782
it('should list the action audit trail', async () => {

‎packages/client/src/index.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7059,9 +7059,10 @@ export class ObjectStackClient {
70597059

70607060
/**
70617061
* Record a reject decision on a request. Resumes the owning flow run down
7062-
* the `reject` edge.
7062+
* the `reject` edge. A reject carries its reason: `comment` is required,
7063+
* and a blank one is refused with `400 VALIDATION_ERROR`.
70637064
*/
7064-
reject: async (requestId: string, decision?: { actorId?: string; comment?: string; attachments?: string[] }): Promise<ApprovalDecisionResult> => {
7065+
reject: async (requestId: string, decision: { actorId?: string; comment: string; attachments?: string[] }): Promise<ApprovalDecisionResult> => {
70657066
const route = this.getRoute('approvals');
70667067
const res = await this.fetch(`${this.baseUrl}${route}/requests/${encodeURIComponent(requestId)}/reject`, {
70677068
method: 'POST',

‎packages/plugins/plugin-approvals/src/approval-decision-outcome-notification.integration.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ describe('the decision that ends an approval tells its submitter (approval.appro
310310

311311
it('a rejection at the first step ends the process, so it tells the submitter', async () => {
312312
const step1 = await submit('deal_ladder', 'vetoed', 5000);
313-
await svc.decide(step1.id, { decision: 'reject', actorId: 'u_mgr' }, asUser('u_mgr'));
313+
await svc.decide(step1.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u_mgr' }, asUser('u_mgr'));
314314
expect(await pendingOn('D_vetoed')).toBeUndefined();
315315
expect(outcomesAbout(step1.id).map((e) => [e.topic, e.audience])).toEqual([['approval.rejected', ['u_sub']]]);
316316
});

‎packages/plugins/plugin-approvals/src/approval-node.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('Approval node bridge (ADR-0019)', () => {
215215
await automation.execute('deal_approval', { object: 'crm_deal', record: { id: 'd1' } });
216216
const request = (await fake.find('sys_approval_request', { where: { status: 'pending' } }))[0];
217217

218-
const out = await service.decide(request.id, { decision: 'reject', actorId: 'u1' }, SYSTEM_CTX);
218+
const out = await service.decide(request.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u1' }, SYSTEM_CTX);
219219

220220
expect(out).toMatchObject({ finalized: true, decision: 'reject', resumed: true });
221221
expect(marks).toEqual(['on_rejected']);

‎packages/plugins/plugin-approvals/src/approval-service.test.ts‎

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,11 +1415,50 @@ describe('ApprovalService (node era)', () => {
14151415

14161416
it('decide: finalizes even when no automation is attached (resumed=false)', async () => {
14171417
const req = await svc.openNodeRequest(openInput(['u9']), CTX);
1418-
const out = await svc.decide(req.id, { decision: 'reject', actorId: 'u9' }, SYS);
1418+
const out = await svc.decide(req.id, { decision: 'reject', actorId: 'u9', comment: 'Over budget.' }, SYS);
14191419
expect(out.finalized).toBe(true);
14201420
expect(out.resumed).toBe(false);
14211421
});
14221422

1423+
// ── a reject carries its reason ─────────────────────────────────
1424+
//
1425+
// The `approval_reject` action door's refusal, at the member every human
1426+
// door reaches: the same code, status and sentence, nothing read or written.
1427+
1428+
it('decide: refuses a reject whose comment is missing, empty, blank, null or not a string, and leaves the request pending', async () => {
1429+
const resumed: any[] = [];
1430+
svc.attachAutomation({ async resume(runId) { resumed.push(runId); } });
1431+
const req: any = await svc.openNodeRequest(openInput(['u9']), CTX);
1432+
for (const comment of [undefined, '', ' ', null]) {
1433+
const err: any = await svc.decide(req.id, { decision: 'reject', actorId: 'u9', comment } as any, SYS)
1434+
.then(() => undefined, (e) => e);
1435+
expect([err?.status, err?.code], String(comment)).toEqual([400, 'VALIDATION_ERROR']);
1436+
expect(err.message).toBe('Invalid action params: Action param "comment" is required');
1437+
}
1438+
// Not a string is no reason either: the door's `textarea` value shape refuses it.
1439+
for (const [comment, received] of [[0, 'number'], [false, 'boolean'], [[], 'array'], [{}, 'object']] as const) {
1440+
const err: any = await svc.decide(req.id, { decision: 'reject', actorId: 'u9', comment } as any, SYS)
1441+
.then(() => undefined, (e) => e);
1442+
expect([err?.status, err?.code], JSON.stringify(comment)).toEqual([400, 'VALIDATION_ERROR']);
1443+
expect(err.message).toBe(
1444+
`Invalid action params: Action param "comment" (textarea): Invalid input: expected string, received ${received}`,
1445+
);
1446+
}
1447+
const [row] = await engine.find('sys_approval_request', { where: { id: req.id } });
1448+
expect(row.status).toBe('pending');
1449+
expect((engine._tables['sys_approval_action'] ?? []).filter((a: any) => a.request_id === req.id && a.action === 'reject')).toEqual([]);
1450+
expect(resumed).toEqual([]);
1451+
});
1452+
1453+
// An approve keeps its comment optional: the resume test above approves with none.
1454+
it('decide: CONTROL — a reject with its reason is recorded with it', async () => {
1455+
const req: any = await svc.openNodeRequest(openInput(['u9']), CTX);
1456+
const out = await svc.decide(req.id, { decision: 'reject', actorId: 'u9', comment: 'Over budget.' }, SYS);
1457+
expect([out.finalized, out.request.status]).toEqual([true, 'rejected']);
1458+
expect((engine._tables['sys_approval_action'] ?? []).find((a: any) => a.request_id === req.id && a.action === 'reject')?.comment)
1459+
.toBe('Over budget.');
1460+
});
1461+
14231462
// ── #4420: a REPORTED resume failure is a failure ────────────────
14241463
//
14251464
// The engine answers a lost run with `{ success: false }` rather than by
@@ -1726,7 +1765,7 @@ describe('ApprovalService (node era)', () => {
17261765

17271766
it('reject: names the record, the way the inbox row\'s inline Reject does', async () => {
17281767
const id = await openRequestId(openInput(['u9']), CTX);
1729-
const out = await svc.decide(id, { decision: 'reject', actorId: 'u9' }, SYS);
1768+
const out = await svc.decide(id, { decision: 'reject', comment: 'Over budget.', actorId: 'u9' }, SYS);
17301769
expect(out.request.status).toBe('rejected');
17311770
expect(named('approval_reject', out)).toBe('Rejected "Acme Renewal"');
17321771
});
@@ -2799,7 +2838,7 @@ describe('ApprovalService — admin override (#3424)', () => {
27992838

28002839
it('a platform admin can reject a stuck request', async () => {
28012840
const req = await svc.openNodeRequest(stuckInput(), CTX);
2802-
const out = await svc.decide(req.id, { decision: 'reject', actorId: 'root' }, PLATFORM_ADMIN);
2841+
const out = await svc.decide(req.id, { decision: 'reject', comment: 'Over budget.', actorId: 'root' }, PLATFORM_ADMIN);
28032842
expect(out.finalized).toBe(true);
28042843
expect(out.request.status).toBe('rejected');
28052844
});
@@ -6603,7 +6642,7 @@ describe('in-band transitions finalise before they resume (#3456 invariant)', ()
66036642

66046643
it('decide(reject) finalises before resuming', async () => {
66056644
const req = await open();
6606-
await svc.decide(req.id, { decision: 'reject', actorId: 'u9' }, SYS);
6645+
await svc.decide(req.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u9' }, SYS);
66076646
expectCleanHandoffs();
66086647
});
66096648

‎packages/plugins/plugin-approvals/src/approval-service.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import {
6868
canServeApiOperation, isFileIdToken, referenceTargetOf, SINGLE_OPTION_TYPES, MULTI_OPTION_TYPES,
6969
} from '@objectstack/spec/data';
7070
import type { EnableLike, ObjectCapabilitiesParsed } from '@objectstack/spec/data';
71+
import { validateActionParams } from '@objectstack/spec/ui';
7172
// [#11993] The SANCTIONED renderer for OPERATION-level refusal copy. The
7273
// Operation Message Catalog is the ONE seat for these sentences — its own
7374
// header bars both a package-local string table and a second rendering
@@ -6481,12 +6482,31 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
64816482
* [#24753] A decision that ends the approval process tells the submitter its
64826483
* outcome (`approval.approved` / `approval.rejected`,
64836484
* {@link ApprovalService.notifyDecisionOutcome}).
6485+
*
6486+
* A reject carries its reason: a missing or blank `comment`, or one that is
6487+
* not a string, is refused before anything is read or written —
6488+
* `400 VALIDATION_ERROR` with the sentence the `approval_reject` action door
6489+
* answers, judged by the same rules (`validateActionParams` over the
6490+
* `textarea` param that action declares). Every human door reaches this
6491+
* member (the REST route, the SDK, the action door that forwards to the
6492+
* route, the action link with its fixed text). The SLA sweep's auto-reject
6493+
* calls `decideAndResume` and the revision-limit reject writes its own row,
6494+
* so neither passes through here. An approve keeps its comment optional.
64846495
*/
64856496
async decide(
64866497
requestId: string,
64876498
input: ApprovalDecisionInput,
64886499
context: ExecutionContext,
64896500
): Promise<ApprovalDecisionResult> {
6501+
if (input?.decision === 'reject') {
6502+
const issues = validateActionParams([{ name: 'comment', required: true, type: 'textarea' }], { comment: input.comment });
6503+
if (issues.length > 0) {
6504+
throw Object.assign(
6505+
new Error(`Invalid action params: ${issues.map((i) => i.message).join('; ')}`),
6506+
{ status: 400, code: 'VALIDATION_ERROR' },
6507+
);
6508+
}
6509+
}
64906510
return this.decideAndResume(requestId, input, context, 'outcome');
64916511
}
64926512

‎packages/plugins/plugin-approvals/src/approval-tenant-positions-name-authority.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ describe('[ADR-0131 D1] under a walled posture, a request with no organization i
513513
try {
514514
switch (door) {
515515
case 'approve': await svc.decide(id, { decision: 'approve', actorId } as any, ctx); break;
516-
case 'reject': await svc.decide(id, { decision: 'reject', actorId } as any, ctx); break;
516+
case 'reject': await svc.decide(id, { decision: 'reject', comment: 'Over budget.', actorId } as any, ctx); break;
517517
case 'recall': await svc.recall(id, { actorId } as any, ctx); break;
518518
case 'reassign': await svc.reassign(id, { actorId, to: 'usr_target' }, ctx); break;
519519
case 'sendBack': await svc.sendBack(id, { actorId, comment: 'please revise' } as any, ctx); break;

0 commit comments

Comments
 (0)