Repository navigation
Commit 121640b
fix(plugin-email)!: a non-string subject, text or html is the caller's VALIDATION_FAILED, refused before the transport (#32210)
Fixes #32108
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no published skill or doc page teaches the send
body's field types; `SendEmailInput` already declares `subject`, `text`
and `html` as strings, and this change only makes the runtime refuse
what that type excluded.
## 维护者速读
- 改了什么:`POST /api/v1/email/send`(以及 `IEmailService.send` /
`sendInline`)遇到非字符串的 `subject`、`text` 或 `html` 时,在写投递行、调用传输之前直接拒收,返回 400
`VALIDATION_FAILED`,并点名出错字段。
- 为什么改:以前 `html: 123` 返回 200 `status: failed` 加一段 Node 流错误;`subject:
{a:1}` 会真的发出主题为 `[object Object]` 的邮件。调用方写错的输入被伪装成投递失败或静默发出。
-
风险与回滚:收紧(BREAKING):以前被强转发出的数字主题现在会被拒收。一方生产者(模板发送、消息中心邮件通道、设置页测试邮件)全部传字符串,实测
0 处受影响。`undefined` / `null` 仍按“未提供”处理,行为不变。回滚即还原 `normalizeMessage`
里三行调用。
- 先看:`packages/plugins/plugin-email/src/email-service.ts` 的
`assertTextField` 与 `normalizeMessage`
开头三行;`packages/rest/src/email-send-display-name.test.ts` 末尾新增的 describe。
- 两分钟验证:`pnpm --filter @objectstack/rest exec vitest run --maxWorkers=2
src/email-send-display-name.test.ts`,预期 24 个用例全绿,其中 3 个新拒收用例断言 400 +
`VALIDATION_FAILED` + 点名字段。
- 需要你做的:无,席位落地。
## What changes
`normalizeMessage` (`@objectstack/plugin-email`) now type-checks the
message's three text fields before anything else reads them. A
`subject`, `text` or `html` that is present but not a string is refused
with `VALIDATION_FAILED: FIELD must be a string, not KIND`, naming the
field. This is the same throw shape `formatCallerAddress` uses for a
malformed recipient, so the REST door's existing catch maps it to `400
{code: VALIDATION_FAILED, error}` with no change to
`packages/rest/src/email-routes.ts`. That is the same answer the door
already gives for `to: []` and for a display name of 42.
The refusal happens before any `sys_email` delivery row or transport
call. As with every other pre-delivery refusal, `recordRejectedMessage`
still writes one `failed` rejection row with `attempt_count: 0`.
`undefined` and `null` are absence, not a wrong type, and keep today's
behaviour, now pinned: no subject is still `subject is required`; a
`null` or absent `text` beside a string `html` (and the reverse) still
sends; `text: ''` with `html: ''` is still `at least one of text or html
is required`.
Landing point: `normalizeMessage`, as the claim expected. The door's 400
for `to` comes from this same function, so there is no second validator
to extend.
First-party producers measured, none sending a non-string `subject` /
`text` / `html` (count: **0**):
- `EmailService.sendTemplate` forwards `RenderedEmailTemplate` fields,
which the contract types as strings.
- `service-messaging` `email-channel.ts`: the template arm goes through
`sendTemplate`; the notification arm forwards `renderNotification`
output, built with `String(...)`.
- The `mail/test` settings action (`email-plugin.ts`, `sendInline`)
passes literals.
- Two sites pass caller data through rather than producing it: the REST
door (the caller's JSON, which this fixes) and the legacy
`email.send.async` queue arm (raw payloads from pre-queue producers
outside the workspace).
## Tests
- `packages/plugins/plugin-email/src/email-service.test.ts`, a new
top-level describe:
- Six refusal cases (`html: 123`, `text: {a:1}`, `subject: {a:1}`,
`subject: 42`, `html` as an array beside a string `text`, `text: 0`
beside a string `html`), each asserting the `VALIDATION_FAILED: ` prefix
and that the reason opens with the named field.
- `EmailService.send` refuses before the transport is called and records
the rejection row without a `body_html`.
- Controls: string fields still normalize, and null/absent bodies keep
their presence-check answers.
- `packages/rest/src/email-send-display-name.test.ts`, a new top-level
describe in the existing real-plugin door harness (real
`EmailServicePlugin`, real Hono transport):
- `html: 123`, `text: {a:1}` and `subject: {a:1}` each answer status
400, `code: VALIDATION_FAILED`, with an `error` that opens with the
named field, and leave exactly one `failed` rejection row.
- CONTROL: a string subject and body answer 200 `sent`, and so does a
`null` `text` beside a string `html`.
## Acceptance notes
- The rejection row used to record an object `subject` as `[object
Object]`, and a subject whose `toString` is not callable turned the
refusal into a 500. Both are fixed in this PR by commit `8eb56764`
(contract review F1): `recordRejectedMessage` records `subject` only
when it is a string, else `(none)`, as the body columns already did.
Pinned at the door and in the service test.
- The ablation of the `subject` leg first ran against a version of the
fix that had also re-spelled the subject read without `String()`. That
mutant answered 500 rather than reproducing the shipped 200, so the
spelling was put back (commit `f4f4c918`) and the leg re-run; that
re-run's output is below.
## Verification
Round-0 readings were taken on head `fa2f882f`; round-1 readings (the F1
fix) are on `8eb56764` (dev report on #32108, comment 6774515672),
unless a block says otherwise.
<details><summary>Dogfood battery (owed by the narrowing arm), green on
the final head</summary>
Dependency closure built (`turbo run build
--filter='@objectstack/dogfood^...'`, 70/70), then under the shared lock
`pnpm --filter @objectstack/dogfood test` (no `OS_TEST_SHARD`, no path):
```text
Test Files 446 passed | 3 skipped (449)
Tests 3704 passed | 42 skipped (3746)
os-verify-lock: VERDICT command-exit 0 · held the lock 2164s (36m04s)
```
</details>
<details><summary>Ablation: each field's check deleted alone, both pin
files red on exactly that field, restored by blob hash</summary>
Run through `node scripts/ablation-replace.mjs --delete` (the anchor
must hit exactly once, verified on disk, then restored and checked
against the HEAD blob). One leg per field, each running both pin files.
Both suites resolve `@objectstack/plugin-email` from `src/` (the
plugin's own relative import, and the rest vitest alias), so no `dist/`
rebuild is involved.
```text
leg html (head 0836ade): anchor x1 -> x0, blob 3924900 -> d28f3b94a2dc
plugin-email: Tests 3 failed | 48 passed (51) -- html as a number; html as an array; EmailService.send refuses before transport ("promise resolved instead of rejecting")
rest door: Tests 1 failed | 23 passed (24) -- html: 123 -> AssertionError: expected 200 to be 400
restored: blob == HEAD (3924900), git diff HEAD empty
leg text (head 0836ade): anchor x1 -> x0, blob 3924900 -> 5b9a6dfab299
plugin-email: Tests 2 failed | 49 passed (51) -- text as an object; text: 0 beside a string html
rest door: Tests 1 failed | 23 passed (24) -- text: {a:1} -> AssertionError: expected 200 to be 400
restored: blob == HEAD, git diff HEAD empty
leg subject (head f4f4c91, the shipped subject spelling): anchor x1 -> x0, blob 5b68c37 -> 118f8de94e56
plugin-email: Tests 2 failed | 49 passed (51) -- subject as an object; subject as a number
rest door: Tests 1 failed | 23 passed (24) -- subject: {a:1} -> AssertionError: expected 200 to be 400
restored: blob == HEAD (5b68c37), git diff HEAD empty
```
The html and text legs ran on `0836ade6`, which differs from `f4f4c918`
only in the subject read line, so their readings stand.
</details>
<details><summary>Local gates: 64 derived, 63 measured green, 1 NOT
MEASURED</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack`: 64 families from 4 paths vs merge base
`0f7389cca`. Every command was run on `fa2f882f`, with the exit code
captured before any pipe, then reconciled:
```text
Run reconciliation -- 64 derived, 63 run, 1 NOT-MEASURED, 0 UNRUN.
NOT-MEASURED: pnpm check:dual-build-cjs-loads [exit 3 -- PREREQUISITE NOT MET: reads every package's dist/, 51 unbuilt here]
```
- `node scripts/check-plugin-teardown-shape.mjs --self-test` first
exited 3: its positive control is pinned to commit `621a4876`, which
this shallow clone lacked. After a depth-1 fetch of that commit it
passed: `48 cases pass`.
- Package suites under the shared lock:
- `@objectstack/plugin-email`: `typecheck` (tsc plus
`check:test-typecheck`: 0 errors) and `test`: `Test Files 51 passed
(51)`, `Tests 843 passed (843)`.
- `@objectstack/rest`: `typecheck` (test layer compiles, 0 errors) and
`test`: `Test Files 400 passed (400)`, `Tests 7672 passed | 332 skipped
(8004)`.
- `eslint --no-inline-config` on the three changed `.ts` files: exit 0,
no findings. The repo-wide `pnpm lint` is left to CI's lint run.
- Control-byte scan over the four changed files: 0 hits.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_012dn2Ae4fomvXPZ2AioCpY4)_
<!-- signed: domain:server#5 · os-bob · session_012dn2Ae4fomvXPZ2AioCpY4
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent 327ef0f commit 121640b
4 files changed
Lines changed: 203 additions & 2 deletions
File tree
- .changeset
- packages
- plugins/plugin-email/src
- rest/src
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
124 | 204 | | |
125 | 205 | | |
126 | 206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
347 | 382 | | |
348 | 383 | | |
349 | 384 | | |
| 385 | + | |
350 | 386 | | |
351 | 387 | | |
352 | 388 | | |
| |||
358 | 394 | | |
359 | 395 | | |
360 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
361 | 400 | | |
362 | 401 | | |
363 | 402 | | |
| |||
1005 | 1044 | | |
1006 | 1045 | | |
1007 | 1046 | | |
1008 | | - | |
| 1047 | + | |
1009 | 1048 | | |
1010 | 1049 | | |
1011 | 1050 | | |
| |||
1043 | 1082 | | |
1044 | 1083 | | |
1045 | 1084 | | |
1046 | | - | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
1047 | 1091 | | |
1048 | 1092 | | |
1049 | 1093 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
0 commit comments