Repository navigation
Commit f848e37
fix(rest): POST /api/v1/batch answers a request-schema refusal with fields[] (#35277)
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgRuogP8Tp8XyFXLc92Bxvo6)_
Fixes #34863
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:`POST /api/v1/batch`(跨对象批量)请求体不合 schema 时,400 VALIDATION_FAILED
的回答从原样透出 zod `issues` 改为 ADR-0114 的 `fields[]`(`{ field, code, message
}`),与同文件的单对象批量入口一致。
- 为什么改:客户端(含 `@objectstack/client` 的 `err.fields`)在这一个入口拿不到字段级错误,只能解析
zod 内部结构;ADR-0114 D3 要求 zod 在边界映射、不透传。
- 风险与回滚:只影响这一个拒收分支的回答体,成功路径与状态码不变;`issues`
键从该回答中移除(实测无客户端、SDK、测试或文档读取它)。回滚即还原 `batch-routes.ts` 一处 hunk。
- 先看:`packages/rest/src/batch-routes.ts` 第 308–322
行(唯一行为改动);`packages/rest/src/cross-object-batch-request-refusal-fields.test.ts`;`.changeset/34863-cross-object-batch-refusal-fields.md`。
- 两分钟验证:`pnpm --filter @objectstack/rest exec vitest run --maxWorkers=2
src/cross-object-batch-request-refusal-fields.test.ts`,预期 3 passed;以管理员
`POST /api/v1/batch` 发 `{"operations":"x"}`,预期 400 且回答带
`fields:[{field:'operations',code:'invalid_type',…}]`、不再带 `issues`。
- 需要你做的:无,席位落地。
## What changes
- `packages/rest/src/batch-routes.ts`: the cross-object batch door's
request-schema refusal now maps the `CrossObjectBatchRequestSchema`
failure through `zodIssuesToFields(issues, input)`, the same mapper
every per-object batch door in this file already uses
(`/data/:object/batch`, `createMany`, `updateMany`, `deleteMany`).
Status (400) and `code` (`VALIDATION_FAILED`) and `error` text are
unchanged.
- `issues` dropped, not kept beside `fields`. Measured readers: no
`packages/client` source reads `issues` off a batch refusal,
`CrossObjectBatchResponseSchema` is the success shape only, no test or
doc page names the batch refusal's `issues`, and every `body.issues`
reader in `packages/rest` tests is a metadata-save route (422
INVALID_METADATA), not `/batch`. Keeping it would pass Zod through at
the boundary, which ADR-0114 D3 forbids.
- Changeset: `@objectstack/rest` patch, with the migration sentence
(`issues[i].path` reads as `fields[i].field`).
- Envelope position (#9559) untouched.
## Tests
New
`packages/rest/src/cross-object-batch-request-refusal-fields.test.ts`,
three cases: the card's two bodies (`{"operations":"x"}` gives
`operations`/`invalid_type`; `{}` gives `operations`/`required`) plus an
operation missing its object (`operations.0.object`/`required`). Each
asserts status 400, `code` VALIDATION_FAILED, every `fields` element
parses against `FieldErrorSchema`, no `issues` key, and no engine write
or transaction reached.
<details><summary>Red leg: the pin against the pre-fix source (commit
e8383f1 version of batch-routes.ts), restored after</summary>
```text
mutation landed: fields-mapping count=1 raw-issues count=1
× a non-array `operations` is an `invalid_type` on `operations`
× an empty body names `operations` as `required`
× an operation missing its object is located at its index
AssertionError: {"error":"Invalid batch request","code":"VALIDATION_FAILED","issues":[{"expected":"array","code":"invalid_type","path":["operations"],"message":"Invalid input: expected array, received string"}]}
Test Files 1 failed (1)
Tests 3 failed (3)
os-verify-lock: VERDICT command-exit 1
restored: git diff HEAD empty, hash 208dc1a == HEAD blob
```
The red body is the card's reproduction byte for byte (raw zod `issues`,
no `fields`).
</details>
<details><summary>Green leg and the package suite</summary>
```text
src/cross-object-batch-request-refusal-fields.test.ts
Test Files 1 passed (1)
Tests 3 passed (3)
os-verify-lock: VERDICT command-exit 0
pnpm --filter @objectstack/rest test
Test Files 420 passed (420)
Tests 8619 passed | 350 skipped (8969)
os-verify-lock: VERDICT command-exit 0
pnpm --filter @objectstack/rest typecheck
check:test-typecheck: OK — @objectstack/rest's test layer compiles under packages/rest/tsconfig.test.json
os-verify-lock: VERDICT command-exit 0
```
</details>
## Acceptance notes
- Clause-② no, measured: after `pnpm --filter '@objectstack/rest^...'
build` and `pnpm --filter @objectstack/rest build`,
`packages/rest/dist/index.d.ts` contains neither `Invalid batch request`
nor `VALIDATION_FAILED` (the literal lives only in `dist/index.js`); the
refusal body is an untyped `res.json` literal, and
`@objectstack/spec/api` exports no cross-object batch error schema.
Nothing exported widens or narrows.
- No out-of-scope findings.
## Verification
All readings below are at head `05e98ac3f5` (the final commit; a merge
of origin/main into the branch, no file of this diff touched by it).
overlap-check: `VERDICT clean exit 0` (merges cleanly with origin/main).
`node scripts/check-platform-checklist.mjs --changed-from origin/main`
not owed: no exported symbol renamed or removed.
<details><summary>Local gate subset (dispatch-gates --commands,
reconciled with --ran)</summary>
```text
node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0
node scripts/check-adr-0087-registration.mjs --self-test :: exit 0
node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0
node scripts/check-closing-keyword-parity.mjs :: exit 0
node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0
node scripts/check-comment-mask-adoption.mjs :: exit 0
node scripts/check-comment-mask-adoption.mjs --self-test :: exit 0
node scripts/check-comment-mask-corpus.mjs :: exit 0
node scripts/check-dts-emitted.mjs --self-test :: exit 0
node scripts/check-empty-changeset.mjs --base origin/main :: exit 0
node scripts/check-empty-changeset.mjs --self-test :: exit 0
node scripts/check-issue-citations.mjs :: exit 0
node scripts/check-plugin-teardown-shape.mjs :: exit 0
node scripts/check-plugin-teardown-shape.mjs --self-test :: exit 0
node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0
node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0
node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0
node scripts/ci/snapshot-next.mjs --self-test :: exit 0
node scripts/docs-audit/check-affected-docs.mjs :: exit 0
node scripts/docs-audit/check-drift-comment.mjs :: exit 0
node scripts/pm/check-governed-queue-guard.mjs --self-test :: exit 0
node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0
node scripts/release-pending-publish.mjs --self-test :: exit 0
pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0
pnpm --filter @objectstack/spec run check:error-code-provenance :: exit 0
pnpm check:adr-anchors :: exit 0
pnpm check:adr-symbol-anchors :: exit 0
pnpm check:changeset-gate-self-tests :: exit 0
pnpm check:ci-filter-parity :: exit 0
pnpm check:closed-ceremony-text :: exit 0
pnpm check:cross-package-test-inputs :: exit 0
pnpm check:dispatcher-error-vocabulary :: exit 0
pnpm check:doc-authoring :: exit 0
pnpm check:driver-memory-census :: exit 0
pnpm check:dts-closure :: exit 0
pnpm check:dual-build-cjs-loads :: exit 3
pnpm check:engine-double-contract :: exit 0
pnpm check:error-status-conformance :: exit 0
pnpm check:gitlink-declared :: exit 0
pnpm check:issue-citations :: exit 0
pnpm check:keyed-text-bounds :: exit 0
pnpm check:lean-entry-closure :: exit 0
pnpm check:logger-receiver-detach :: exit 0
pnpm check:meta-type-normalized :: exit 0
pnpm check:nul-bytes :: exit 0
pnpm check:object-def-param-keys :: exit 0
pnpm check:objectql-double-limit :: exit 0
pnpm check:optional-error-sink :: exit 0
pnpm check:org-identifier :: exit 0
pnpm check:page-declaration-shape :: exit 0
pnpm check:platform-object-tenancy-census :: exit 0
pnpm check:published-files :: exit 0
pnpm check:query-options-erasure :: exit 0
pnpm check:refd-timer-probe :: exit 0
pnpm check:registry-log-declared :: exit 0
pnpm check:rest-log-spy-declared :: exit 0
pnpm check:route-envelope :: exit 0
pnpm check:slot-lookup :: exit 0
pnpm check:sourcemap-no-sources-content :: exit 0
pnpm check:system-context-census :: exit 0
pnpm check:test-source-alias :: exit 0
pnpm check:tier-file-adoption :: exit 0
pnpm check:type-check-coverage :: exit 0
pnpm check:type-check-debt :: exit 0
pnpm check:undeclared-dep-imports :: exit 0
pnpm check:vouch-for-reference-callers :: exit 0
pnpm check:watch-hint-literal :: exit 0
pnpm check:where-matcher :: exit 0
dispatch-gates --ran: 68 derived famil(ies) accounted for, 67 run, 1 NOT-MEASURED (check:dual-build-cjs-loads exit 3 PREREQUISITE NOT MET: it reads every package's dist/ and only the rest closure is built here; CI's lint run measures it)
```
</details>
`test:repo`, the integration tiers and the whole-farm families are CI's;
their check-runs are the verdict.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me)_
<!-- signed: repo:objectstack#5 · os-bill ·
session_01Utp6CZiaBg6rk7dpy1s9Me -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 4026c44 commit f848e37
3 files changed
Lines changed: 135 additions & 2 deletions
File tree
- .changeset
- packages/rest/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
311 | | - | |
| 311 | + | |
| 312 | + | |
312 | 313 | | |
313 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
314 | 322 | | |
315 | 323 | | |
316 | 324 | | |
| |||
| 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 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
0 commit comments