Repository navigation
Commit 660e7cd
fix(spec)!: a query where of the wrong kind answers one fields[] entry that names the shapes it takes (#37205)
repo:objectstack#7 · os-alice · session_011y7As5bdhV5T4N9vpjmZzH
Fixes #35500
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no skills/ page names the `query.where` refusal or
its `Invalid input` entries, or reads `fields[]` / `issues[]` by
position or count
## 维护者速读
-
用户能看到什么变化:通过数据接口查询时,如果筛选条件写成了数字、字符串或空值,被拒时只返回一条说明,写清筛选条件应该是条件对象还是筛选数组;不再返回两条一模一样、什么也没说的「输入无效」。
- 为什么做:修的是数据接口查询被拒时原因说不清的问题(上一张同类卡的后续)。主要调用方是通过数据接口写查询的 AI,它看不到原因只能乱猜重试。
-
出错会怎样:按条数或位置读错误清单、或专找那句「输入无效」的调用方会读到不同内容;正常查询不受影响,元数据保存的错误清单在同类嵌套情况下也少一条;不涉及存储数据,撤回这一个
PR 即可恢复。
- 要你做什么:批准或合并这个 PR;它是申报了收窄的破坏性改动,席位不能自己落地。
## What changes
A query's `where` on the data API is `z.union([FilterArraySchema,
DataEngineFilterSchema])`, and both members are unions themselves.
Handed `42`, a string or `null`, each member failed only because the
value was the wrong kind, but the shared branch selection did not read a
member that is a union as a kind mismatch. So it selected both members,
and each emitted its own unexplained `{ field: 'query.where', code:
'invalid_shape', message: 'Invalid input' }`. The caller got two
identical entries and no cause. Measured at `main` `236c8044acb`, after
#37083 had already dropped the explained outer head. #37083 is not
released yet and ships in the same release as this, so a released
client's before is the card's reading at `f6902e950`: three identical
entries for `where: 42`, and five entries (four bare) for the malformed
AST. The changeset's FROM lines are written against that.
- Policy (`packages/spec/src/shared/union-branch-policy.ts`):
`isKindMismatchOnly` now also counts a branch-root `invalid_union` with
zod's bare default message whose every branch is itself
kind-mismatch-only, by the same rule, so depth does not matter. A nested
union that declares its own `error` sentence stays informative. A nested
union with `errors: []` keeps its old reading.
`ZOD_UNION_DEFAULT_MESSAGE` moves into this module, because the
selection now reads it; the mapper re-exports it unchanged for its pin,
and it stays package-internal.
- The same rule in `@objectstack/metadata-protocol`'s copy
(`protocol-metadata-issues.ts`), so the data API's `fields[]`, the
terminal renderer and the four lists `zodIssuesToMetadataIssues` feeds
reach one verdict. Those four are a refused save's `issues[]` (`422
INVALID_METADATA`), a stored item's `_diagnostics.errors`, the
seed-request refusal's `issues`, and the unmanaged-import `400`. This is
what ruling record 7010280743 requires: the two machine lists say the
same thing.
- The cause sentence (`packages/spec/src/data/data-engine.zod.ts`,
`TransportFilterValueSchema`): a value of the wrong kind (not an object
or array) gets one sentence naming both accepted shapes, a condition
object such as `{ "status": "open" }` or a filter array such as
`["status", "=", "open"]`. An array or an object keeps zod's default, so
its located causes speak and the bare head is still dropped in their
favour. It covers every spelling of the slot (`where`, `$filter`,
`filter`, `filters`) for a number, a string or a boolean. `null` is
refused with it only on `where`; the other three spellings are
`.nullable()` and accept `null` as no filter.
- Selection side effect: such a member was one issue long, so under
"fewest issues wins" it could out-rank a sibling member with several
located causes. That sibling is now selected, so in that case a list
gains its located entries where one bare entry stood.
- Changeset: `@objectstack/spec` and `@objectstack/metadata-protocol`
patch, `fix(spec)!`, BREAKING banner, FROM / TO, one ADR-0087 marker
(`not-required (no-migration-prescription)`).
The claim's file surface was widened to the policy layer before this was
built (seat decision, option A of os-dev-report 7146729179; the
amendment is on the card).
## Tests
All readings below are from the shared verify lock on a shared box.
<details><summary>New pins</summary>
- `packages/spec/src/api/zod-issues-to-fields.test.ts`, new describe:
through the real `FindDataRequestSchema`, `42`, a string, `null` and a
boolean each answer exactly one entry, `[['query.where',
'invalid_shape']]`, whose message is not zod's default and names both
shapes. `$filter` answers the same entry at `query.$filter`. The
malformed AST `[['status','=','open'],'and']` answers exactly
`[query.where min_items, query.where.1 invalid_shape 'Invalid input']`.
CONTROL: a filter object, a filter array and a logical filter array
still parse. Plus a synthetic union of bare-kind unions answering one
entry.
- `packages/spec/src/shared/union-branch-policy.parity.test.ts`: a new
corpus fixture (renderer and wire agree pair for pair), the recursion, a
sentence-carrying nested union staying informative, and `errors: []`
keeping its reading. `ZOD_UNION_DEFAULT_MESSAGE` was added to the
package-internal roster.
-
`packages/metadata-protocol/src/union-branch-policy.cross-package-parity.test.ts`:
two section-2 fixtures, a synthetic nested bare-kinds union and the real
query door with `where: 42`. All three walks give the same paths and
messages. `ZOD_UNION_DEFAULT_MESSAGE` was added to the section-1 symbol
roster.
- `packages/metadata-protocol/src/protocol.save-union-issues.test.ts`:
the envelope walk says the nested bare-kinds union once, a
sentence-carrying member is still heard, and a CONTROL member with a
located cause is still expanded.
- `packages/rest/src/zod-union-fields.test.ts`, new top-level describe,
which runs the real `POST /api/v1/data/:object/query` route over
ObjectQL, SqlDriver (sqlite) and the metadata protocol. For `42`, a
string and `null`: `400`, `code: 'VALIDATION_FAILED'`, exactly
`[['query.where', 'invalid_shape']]` with the shape sentence, and the
driver is never read. For the malformed AST: `400 VALIDATION_FAILED`
with `fields` equal to the two entries above, and no read. CONTROL: a
filter object and a filter array are served `200` with the right rows.
The new pins assert the `field`, `code`, status and entry count exactly.
They check the sentence by the two shapes it names (`condition object`,
`filter array`), not by its full wording.
</details>
<details><summary>Package suites (head 2af665d, before the merge of
origin/main)</summary>
- `pnpm --filter @objectstack/spec exec vitest run --maxWorkers=2`: Test
Files 983 passed (983); Tests 29875 passed, 1 todo. VERDICT command-exit
0.
- `pnpm --filter @objectstack/metadata-protocol test`: Test Files 369
passed, 9 skipped (378); Tests 23394 passed, 45 skipped. VERDICT
command-exit 0.
- `pnpm --filter @objectstack/rest test`: Test Files 429 passed (429);
Tests 8823 passed, 351 skipped. VERDICT command-exit 0. The first
attempt got exit 99 (no lock turn, NOT MEASURED) and was re-run on the
same slot.
- `typecheck` for spec, metadata-protocol and rest: VERDICT command-exit
0.
</details>
<details><summary>Final head 16f479c (merges of origin/main up to
3b4f0b9; the branch's delta against main is exactly the 10 files
above)</summary>
- The dogfood closure was rebuilt (`pnpm --filter
'@objectstack/dogfood^...' build`, VERDICT command-exit 0). `pnpm
--filter @objectstack/spec check:generated`: exit 0, no artifact moved.
- Affected files re-run: spec 2 files 56/56, metadata-protocol 2 files
64/64, rest 1 file 23/23. VERDICT command-exit 0.
</details>
<details><summary>Ablation (one time, not kept)</summary>
- Mutation through `scripts/ablation-replace.mjs` in
`union-branch-policy.ts`: the anchor `||
isKindMismatchOnlyUnion(issue)),` was replaced by a marker comment,
which turns the nested rule off. Anchor 1 to 0, marker 0 to 1, blob
`8f72bb114a75` to `c2e73abc2818`.
- Mutated leg, `zod-issues-to-fields.test.ts` and
`union-branch-policy.parity.test.ts`: Test Files 2 failed (2); Tests 10
failed, 46 passed (56). The failures were every door case (`42`, string,
`null`, boolean, `$filter`, malformed AST), the synthetic nested union,
the new parity fixture, "both walks say the union once" and "the rule
recurses". The sentence-carrying and `errors: []` pins stay green under
the mutation, as expected: they pin the rule's edges, not the rule.
- Restore proven by blob: after restore it equals the HEAD blob
`8f72bb114a75`, and `git diff HEAD` is empty. Restored leg: 2 files,
56/56 passed.
- Scope: both suites import `src` relatively, so they need no rebuild.
The metadata-protocol and rest pins resolve `@objectstack/spec` through
`dist/` and were not ablated.
</details>
## Acceptance notes
- Renderer: `formatZodError` / the CLI take the same rule, because they
share the policy. A wrong-kind `where` prints one line, not one per
member.
- Positional reader: `readDeclaredQueryNumber` (`rest-server.ts`) reads
`fields[0]?.message`. A declared number schema has no nested bare-kinds
union, so it does not move.
- Docs: `content/docs/api/error-handling-server.mdx` already says a bare
union entry is "kept only when nothing does", and that stays true, so it
is not edited.
- Noted, not fixed (same door, different defect): `query.$filter: {
"$and": 42 }` answers `field: 'query.where.$and'`, `code: 'required'`.
The value is present, and the field names the folded slot, not the one
the caller sent. Reported to the seat for filing.
- Read first, by risk: `packages/spec/src/shared/union-branch-policy.ts`
(`isKindMismatchOnlyUnion`), then `TransportFilterValueSchema` in
`data-engine.zod.ts`, then
`union-branch-policy.cross-package-parity.test.ts` section 2.
- Two-minute check: `pnpm --filter @objectstack/spec exec vitest run
--maxWorkers=2 src/api/zod-issues-to-fields.test.ts`. Every test should
be green, including the describe "a wrong-typed query where answers one
entry that names the shapes".
- A contract-tier review is owed: this is a declared narrowing.
## Verification
<details><summary>Rework round (changeset prose only), head
ecc795b</summary>
- Seat REWORK 7152541028, items 1 to 4: the FROM lines now give the
released behaviour, `null` is scoped to `where`, the four metadata lists
and their readers are named in the BREAKING banner, and the out-ranking
effect is stated. The contract review PASS 7152531147 at `16f479c57d6`
read no code finding, and this round changes no code: the delta from
that head is `.changeset/where-wrong-kind-one-entry.md` alone. No
generated reference reads a changeset, so no `Regen-provenance:` line is
needed.
- `node scripts/check-adr-0087-registration.mjs`: exit 0.
- Gate sweep at `ecc795b1905`: `dispatch-gates --commands --repo
objectstack-ai/objectstack` derived 89 families; `--ran` gave 88 run, 1
NOT-MEASURED (`pnpm check:dual-build-cjs-loads`, exit 3, PREREQUISITE
NOT MET: this fresh worktree built only the dogfood closure; CI runs it
in `Build Core`), 0 UNRUN.
- Dogfood battery re-pinned on `ecc795b1905`, because the seat's L1
checklist pins `dogfood_battery` to the PR head, whatever the delta.
`pnpm --filter @objectstack/dogfood test` ran as its own command under
the verify lock: `VERDICT command-exit 0 · held the lock 2403s`, Test
Files 487 passed, 3 skipped (490); Tests 4128 passed, 68 skipped (4196);
0 failed.
</details>
<details><summary>Gate sweep: dispatch-gates --commands, 89 families,
head 16f479c</summary>
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 89 families. Each was run with its
exit code recorded before any pipe. `--ran`: 89 derived, 89 run, 0
NOT-MEASURED, 0 UNRUN, exit 0.
- Extra: `pnpm check:error-code-casing` exit 0 and `node
scripts/check-adr-0087-registration.mjs` exit 0 (one declared-breaking
changeset, disposition `not-required (no-migration-prescription)`).
- `test:repo` was not run locally; CI owns it.
</details>
<details><summary>Dogfood battery (narrowing arm), head
16f479c</summary>
- `pnpm --filter @objectstack/dogfood test` as its own command under the
shared verify lock: full battery, no shard, no path, run after building
the dogfood closure. `os-verify-lock: VERDICT command-exit 0 · held the
lock 2197s`. Test Files 487 passed, 3 skipped (490); Tests 4128 passed,
68 skipped (4196); 0 failed.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_011y7As5bdhV5T4N9vpjmZzH)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent d7f299c commit 660e7cd
10 files changed
Lines changed: 414 additions & 19 deletions
File tree
- .changeset
- packages
- metadata-protocol/src
- rest/src
- spec/src
- api
- data
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
140 | 151 | | |
141 | 152 | | |
142 | 153 | | |
143 | 154 | | |
144 | 155 | | |
145 | | - | |
| 156 | + | |
| 157 | + | |
146 | 158 | | |
147 | 159 | | |
148 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
149 | 170 | | |
150 | 171 | | |
151 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
672 | 672 | | |
673 | 673 | | |
674 | 674 | | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
317 | 334 | | |
318 | 335 | | |
319 | 336 | | |
320 | | - | |
| 337 | + | |
321 | 338 | | |
322 | 339 | | |
323 | 340 | | |
| |||
326 | 343 | | |
327 | 344 | | |
328 | 345 | | |
| 346 | + | |
329 | 347 | | |
330 | 348 | | |
331 | 349 | | |
| |||
422 | 440 | | |
423 | 441 | | |
424 | 442 | | |
425 | | - | |
| 443 | + | |
426 | 444 | | |
427 | 445 | | |
428 | 446 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
6 | 10 | | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
332 | 333 | | |
333 | 334 | | |
334 | 335 | | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 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 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
0 commit comments