Repository navigation
Commit dd9921e
fix(rest)!: clone refuses a body that carries overrides beside other top-level keys (#27934)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DHZ7P4hcXjQQUXjv2w7ACfa)_
Fixes #27669
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no skill teaches the clone door's body shapes, and
`content/docs/api/data-api.mdx` describes only the two accepted shapes,
which are unchanged
## 维护者速读
- **改了什么**:克隆接口 `POST /data/OBJ/ID/clone` 的请求体若同时带 `overrides` 和其它顶层键(例如
`{"overrides":{"name":"Copy"},"status":"draft"}`),现在返回 400,不再只读
`overrides`、悄悄丢掉 `status` 并返回 201。
- **为什么改**:调用方以为两个值都生效了,实际只生效一半;与 #27489 修过的「静默丢弃」同一类。
- **风险与回滚**:风险是混用两种请求体形状、曾「侥幸成功」的调用方现在收到 400;单独的
`{"overrides":{...}}`、不带 `overrides` 键的裸字段表、`{}`、无 body
行为不变。回滚即删掉克隆处理器里的这一段守卫。
- **先看**:`packages/rest/src/data-action-routes.ts`(克隆处理器的 `strays`
守卫)、`packages/rest/src/clone-overrides-refusal.test.ts`(新的 `[#27669]`
一组)。
- **两分钟验证**:`pnpm --filter @objectstack/rest exec vitest run
src/clone-overrides-refusal.test.ts`,预期 19 条全部通过。
- **需要你做的**:无,席位复核与合同复审后落地。
## What changes
- **The guard.** In the clone handler of
`packages/rest/src/data-action-routes.ts`, when the body is a field map
that carries `overrides` (the nested shape), any other top-level key is
a stray. One or more strays answer `400` through the same
nested-envelope writer #27659 uses (`sendEnvelopeError`, `error.code:
'VALIDATION_ERROR'`), before `cloneData` is called. The message names
each stray key, names both accepted shapes (`{ "overrides": {...} }` or
a bare field map), and tells a caller whose record has a real field
named `overrides` to nest it: `{ "overrides": { "overrides": ... } }`.
That is the triage ruling; no new shape is added.
- **Order.** The stray check runs before the #27489 non-object check, so
`{"overrides":"x","status":"draft"}` is refused for its stray key first;
both are `400 VALIDATION_ERROR` before `cloneData`.
- **Unchanged.** The nested shape alone, a bare field map with no
`overrides` key, `{}`, a bare `null` body and no body clone exactly as
before. The SDK's `data.clone` sends only the nested shape.
- **Changeset.** `@objectstack/rest` patch, BREAKING banner, the
ADR-0087 disposition `not-required (no-migration-prescription)` and the
remedy, modelled on #27659's.
## Tests
`packages/rest/src/clone-overrides-refusal.test.ts` (the #27659 harness,
real `HonoHttpServer`) gains a `[#27669]` block:
- Refusal: one stray key, two stray keys, and an empty `overrides` with
a stray key. Each asserts `400`, `VALIDATION_ERROR`, every stray key
named, both shapes named, the nested-`overrides` prescription, and that
`cloneData` was never called.
- Preservation: `{"overrides":{"overrides":"x","name":"Copy"}}` answers
`201` and `cloneData` receives `{ overrides: 'x', name: 'Copy' }`.
- The existing 15 #27489 cases are untouched and green.
## Verification
<details><summary>Pin on main, then the fix, then an ablation</summary>
- Pin first: the `[#27669]` block was committed alone on top of `main`
`b13a1ed3` (commit `b276331d`). `vitest run
src/clone-overrides-refusal.test.ts`: 3 failed, 16 passed, each
`expected 201 to be 400`.
- With the fix (`e2d1eb18`): 19 passed (19).
- Ablation through `node scripts/ablation-replace.mjs`, anchor `if
(strays.length > 0) {` replaced by `if (strays.length < 0) {`: anchor 1
→ 0, blob `327a925b243e` → `71a31169d8a4`; result 3 failed, 16 passed.
Restored: blob after restore `327a925b243e` == HEAD, `git diff HEAD`
empty. The test imports `./rest-server` from `src/`, so no `dist/` leg
applies.
</details>
<details><summary>Package tests and typecheck: @objectstack/rest green
at the final head</summary>
- At `9d859e3a` (after one merge of `origin/main`, install and closure
rebuild): `pnpm --filter @objectstack/rest test` exit 0, Test Files 348
passed (348), Tests 6754 passed and 332 skipped.
- `pnpm --filter @objectstack/rest typecheck` at `e2d1eb18`: exit 0,
`check:test-typecheck` OK with 0 files / 0 errors in the debt ledger.
</details>
<details><summary>Derived gate families: 59 derived, 58 exit 0, 1 NOT
MEASURED; pnpm lint exit 0</summary>
- `node scripts/pm/dispatch-gates.mjs --commands` derived 59 commands at
`e2d1eb18`, each run with its exit code captured before any pipe. 58
exited 0 (`check-plugin-teardown-shape --self-test` after fetching its
pinned commit into the shallow clone).
- `pnpm check:dual-build-cjs-loads` exited 3, PREREQUISITE NOT MET (it
needs every package's `dist/`): NOT MEASURED locally; CI's `Build Core`
job runs it.
- `--ran` reconciliation: 59 derived famil(ies) accounted for.
- `pnpm lint`: exit 0.
- The merge of `origin/main` changed none of this PR's three files'
other regions; `data-action-routes.ts` auto-merged.
</details>
<details><summary>Dogfood battery (owed by the narrowing arm): green at
the final head</summary>
- At `9d859e3a`: `pnpm turbo run build
--filter='@objectstack/dogfood^...'` then `pnpm --filter
@objectstack/dogfood test`, exit 0. Test Files 357 passed, 3 skipped
(360). Tests 2875 passed, 20 skipped (2895). Not run under
`os-verify-lock` (one worktree on this box).
- An earlier full run at `e2d1eb18` (before the merge) had 4 failures,
none on the clone door: three were the stale hook-abort pins tracked as
#27806 (fixed on `main` by #27878), and one was
`platform-app-object-entry-views.test.ts` naming `sys_exchange_rate`.
All four pass at `9d859e3a`.
</details>
## Reviewer notes
- Contract review is owed (narrowing) and is arranged by the seat.
- Serial note: PR #27795 and the #27728/#27729 work edit other regions
of the same file; this diff stays inside the clone handler.
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4czA6HpNWK4YvhLTw3x)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4czA6HpNWK4YvhLTw3x
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent bacb3e6 commit dd9921e
3 files changed
Lines changed: 68 additions & 1 deletion
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 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
377 | | - | |
| 377 | + | |
| 378 | + | |
378 | 379 | | |
379 | 380 | | |
380 | 381 | | |
| |||
397 | 398 | | |
398 | 399 | | |
399 | 400 | | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
400 | 416 | | |
401 | 417 | | |
402 | 418 | | |
| |||
0 commit comments