You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 65ee4b7
Browse filesBrowse the repository at this point in the historyBrowse files
fix(plugin-approvals)!: the email action-link reject records the reason the approver types (#36695)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBDabPAKG5NwMj6ZcigV2Bbc)_Fixes#35722
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — nothing under `skills/**` teaches the approval
action link or its confirm page (`git grep -i` for "action link",
"approvals/act" and `issueActionTokens` over `skills/` finds nothing)
## 维护者速读
- 审批人从邮件里的"驳回"链接打开确认页时,现在要先填写驳回理由,审批记录里写的是这段理由,不再是固定的"Via action link"。
- 属于"审批收尾"专题:您要求每一次驳回都带理由,邮件链接是最后一个没做到的入口。
- 理由留空提交时,页面原样再问一次并提示必填,链接不会作废,可以填好后再提交;通过链接不受影响,改动可直接撤回。
- 无。
## What changes
`redeemActionToken` (the ADR-0043 action link) decided every reject with
the fixed comment "Via action link", while every other reject door (the
record-page action, MCP `run_action`, the `/reject` route, the SDK)
refuses a reject with no reason. This closes that last door. ADR-0043
names this exact gap under "Non-goals (v1)": "Comment capture on the
confirm page (a decision comment field is a fast follow; the page ships
decision-only)." This PR is that fast follow; the ADR is not edited.
- **Confirm page** (`action-link-pages.ts`). A reject link's page now
carries a required textarea named `comment`, labelled "Reason for
rejecting · 驳回理由", above the button. The approve page is unchanged. The
page copy stays static bilingual (EN · 中文) like every other string on
these session-less pages, which by design have no locale negotiation and
read no translation bundle.
- **Redemption** (`approval-service.ts`). `redeemActionToken(token, {
comment })` records the typed reason as the reject's comment. The reason
is judged by the one rule `decide()` already applies
(`rejectReasonIssues`, extracted from `decide()`: `validateActionParams`
over a required `textarea` param, so missing, blank, whitespace-only or
non-string is refused). A refused reason answers the new outcome
`reason_required` BEFORE the token is consumed: nothing is decided, the
link stays live, and the approver can type a reason and send it again. A
dead link is still checked first and told as before. An approve reads no
field and keeps "Via action link".
- **Both doors, one answer** (`actionRedemptionPage`). The plugin's
self-hosted mount (`approvals-plugin.ts`) and `handleActionPage` now
build the POST answer from one function: decided → result page `200`;
dead link → result page `200` (unchanged); reject with no reason → the
same confirm page again with the refusal "Enter a reason to reject this
request. · 驳回需填写驳回理由。" and `400`. Both read the LAST `comment` field, as
they already read the last `token`.
**The narrowing.** Two populations, one rule. Over HTTP, a POST to
`/api/v1/approvals/act` that redeems a reject token without a reason
used to reject the request; it is now refused with `400`. In process,
the exported `ApprovalService.redeemActionToken(token)` on a reject
token used to decide with "Via action link"; it now takes `input?: {
comment?: unknown }` and, with no reason, returns the new
`ActionTokenOutcome` arm `{ ok: false, reason: 'reason_required',
action: 'reject', request, approverId }` (the type `redeemActionToken`
and `peekActionToken` return) without consuming or deciding. The fix for
an in-process caller: pass `{ comment }` for a reject token and handle
the `reason_required` arm. Declared `Clause-②: no (narrowing)`; the
changeset carries the BREAKING note, both FROM / TO pairs, the fix lines
and the ADR-0087 disposition (`not-required`, no migration prescription:
no stored row, key or authored value moves).
## Tests
- `approval-service.test.ts`: a reject records the typed reason (and no
"Via action link" row); a reject with no input, `{}`, `''`, whitespace,
a number or an array is answered `reason_required` with every token
still unconsumed, the request `pending` and no reject row, then the SAME
link decides once a reason comes; an approve that is sent a `comment`
still records "Via action link".
- `action-page-member.integration.test.ts` (real `ObjectKernel`, real
plugin, SQL driver, real Hono mount), new top-level `describe`: the
reject page has the required field and the approve page none; a reject
POST with no `comment`, an empty one and a whitespace one answers `400`
with exactly the refusal confirm page, decides nothing, and the same
token then decides with the typed reason; parity — both doors answer a
blank reason with byte-equal `400` pages (one token asks both doors,
which itself proves nothing was consumed), a repeated field reads the
last `comment` at both, and both record a typed reason.
- Updated, not weakened: three existing cases in that file posted a
reject token with only `token`; they now post the reason the page asks
for, and the bound-approver case additionally asserts the reject row's
comment is the typed reason and the approve row's is "Via action link".
<details><summary>Local runs (head 1393d97)</summary>
- `pnpm --filter @objectstack/plugin-approvals test` on 1393d97 (clean
tree): Test Files 127 passed (127), Tests 1890 passed (1890); lock
VERDICT command-exit 0.
- `pnpm --filter @objectstack/plugin-approvals typecheck` on 7cbaeef
(1393d97 changes only the changeset): VERDICT command-exit 0;
`check:test-typecheck` OK — approval-service.test.ts back at the
ledger's 182 after the fix round (the first CI round was red at 190: the
new pins read an untyped request id).
- Full dogfood battery on the final head 1393d97, as CI runs it (`pnpm
--filter @objectstack/dogfood test` under the verify lock after the
`@objectstack/dogfood^...` closure build): VERDICT command-exit 0 · Test
Files 487 passed, 3 skipped (490) · Tests 4121 passed, 68 skipped (4189)
· no failures. (An earlier battery on a33c65f read the same counts.)
- Changeset gates re-run on 1393d97 after the contract review's S1
edit: `check-adr-0087-registration`, `check-changeset-no-major`,
`check-empty-changeset`, `check:doc-authoring`, `check:nul-bytes`,
`check:issue-citations` — all exit 0.
- Derived gate families (`node scripts/pm/dispatch-gates.mjs
--commands`): 105 derived, 105 run, every one exit 0; `dispatch-gates
--ran` reconciliation: "105 derived famil(ies) accounted for — 105 run,
0 NOT-MEASURED". 74 ran on 48e3d70, the 31 the docs commit added ran on
a33c65f. Three first answered exit 3 (prerequisite, not a finding) and
were re-run green after the prerequisite: `check-plugin-teardown-shape
--self-test` (after unshallowing `origin/main`), `check:i18n` and
`check:dual-build-cjs-loads` (after a full build).
</details>
## Acceptance notes
- **Docs.** `content/docs/automation/approvals.mdx` said the email
action link "still records the fixed text 'Via action link' instead of
the approver's reason". This PR made that false, so the sentence is
rewritten here (surface amended by the seat on the claim).
- **Translation.** The card asks for the new copy in every locale the
package ships. The action-link pages ship no per-locale copy: they are
session-less and render static EN · 中文 text (file header of
`action-link-pages.ts`), and the new label and refusal follow that
design. The record-page reject (`approval_reject`) already reads
translated labels through the bundles and is untouched.
- **Status choice.** The blank-reason answer is `400`, not `200`:
ADR-0043's "told on the page, never as an error status" governs a dead
link, and this link is live; what was refused is the input, as on the
other reject doors (`400 VALIDATION_ERROR`). A browser still renders the
page.
- **Approve unchanged.** The card's "approve stays optional" is read as:
no reason is required for approve. Adding an optional comment field to
the approve page would be a widening of that door and is not done here.
## Verification
Read first (by risk): `approval-service.ts` `redeemActionToken` (the
reason is judged before the token is consumed), `approval-service.ts`
`actionRedemptionPage`, `approvals-plugin.ts` POST handler.
Two-minute check: `pnpm --filter @objectstack/plugin-approvals exec
vitest run --maxWorkers=2 src/action-page-member.integration.test.ts` —
expect every case green, including the three in "the reject link asks
for a reason".
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufzhBqrB3SGxDwDNYumh)_
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufzhBqrB3SGxDwDNYumh -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(plugin-approvals)!: a reject from the email action link records the reason the approver types on the confirm page, and a reject with no reason is refused on the page
6
+
7
+
Clause-②: no (narrowing)
8
+
Metadata-protocol: none
9
+
Skills-docs: none — nothing under `skills/**` teaches the approval action link or its confirm page (`git grep -i` for "action link", "approvals/act" and `issueActionTokens` over `skills/` finds nothing)
10
+
11
+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped. One exported member moves: `ApprovalService.redeemActionToken` takes an optional reason, and its outcome type gains a `reason_required` arm (both stated below). What moves is the answer the ADR-0043 action page, and that member, give a redemption of a reject link with no reason: no stored row, registry key or authored value changes, so there is nothing for a migration to rewrite and no tombstone. -->
12
+
13
+
**BREAKING** for a caller that POSTs a reject link's token to `/api/v1/approvals/act` (the plugin's self-hosted mount, or the HTTP dispatcher's `/approvals/act` domain through `IApprovalService.handleActionPage`) without a reason, and for code that calls the exported `ApprovalService.redeemActionToken` in process on a reject token without one.
14
+
15
+
- FROM: the confirm page for a reject link had no reason field. A POST carrying only the `token` field rejected the request and recorded the fixed comment "Via action link", while every other reject door (the record-page action, MCP `run_action`, the `/reject` route, the SDK) refused a reject with no reason.
16
+
- TO: the reject confirm page carries a required "Reason for rejecting · 驳回理由" field, posted as `comment`, and the decision records that text as its comment. A POST whose `comment` is missing, blank or not a string (judged by the same rule `ApprovalService.decide()` applies) is answered the same confirm page again with the refusal "Enter a reason to reject this request. · 驳回需填写驳回理由。" and status `400`. Nothing is decided and the token is not consumed, so the approver can type a reason and send the same link again.
17
+
18
+
- In process, FROM: `redeemActionToken(token)` on a live reject token consumed it, rejected the request with the comment "Via action link" and returned `{ ok: true, action: 'reject', … }`.
19
+
- In process, TO: `redeemActionToken(token, input?: { comment?: unknown })`. On a reject token whose `input.comment` is missing, blank or not a string it returns `{ ok: false, reason: 'reason_required', action: 'reject', request, approverId }`, a new arm of the `ActionTokenOutcome` type that `redeemActionToken` and `peekActionToken` return, without consuming the token or deciding. With a reason it decides and records that reason as the comment.
20
+
21
+
**Not moved.** An approve link: its page has no reason field, a POST reads only `token`, and the decision still records "Via action link". A dead link (unknown, expired, used, already decided, handed to someone else) is still told on the result page with `200`, checked before the reason, and a GET still never decides. Both doors still answer the same status and bytes for the same body.
22
+
23
+
The fix for a caller: send the reason in the form's `comment` field with the `token` when redeeming a reject link. In process, pass `{ comment }` as the second argument to `redeemActionToken` for a reject token, and handle the `reason_required` arm where you switch on the outcome's `reason`.
0 commit comments