Repository navigation
Commit 86f2afe
fix(metadata-protocol)!: refuse a searchFields override naming no field instead of reading it as absent (#27670)
domain:server#2 · os-sales · session_01L6bhgUCizoYWQVJWjhdR6F
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuPMZ8BHWtPf6nBTp51qSM64)_
Fixes #27484
Clause-②: no (narrowing) — the data doors (`GET /data/:object`, `POST
/data/:object/query`, `GET /data/:object/export`, and every other caller
of `findData`) refuse a `searchFields` value that names no field, which
they answered 200 over the default search set before. Nothing is
widened.
Metadata-protocol: none
Skills-docs: none — `skills/objectstack-query/SKILL.md` already teaches
"Omit it to search the object's declared `searchableFields`", and no
skill emits an empty override; the two docs pages that list the search
refusals are updated here (`content/docs/api/data-api.mdx`,
`content/docs/data-modeling/queries.mdx`).
## 维护者速读
- **改了什么**:查询里写了 `$searchFields` 却一个字段都没给(空串、只有逗号、空数组,或对象形
`search.fields` 为空)时,数据接口现在回 400 `VALIDATION_ERROR` 并点名参数,跟 `$select=`
一样;导出接口同样拒收。
-
**为什么改**:以前这种值被当成“没写”,搜索悄悄扫了对象的全部默认搜索字段,调用方本想收窄范围,结果拿到更宽的结果,界面上看不出任何异常。
- **风险与回滚**:只影响发了空 `searchFields` 的 API 调用方(Console
与自带视图插件都只在至少有一个字段时才发);引擎直接调用不变。回滚 = revert 本 PR。
-
**先看**:`packages/metadata-protocol/src/protocol-query-validation.ts`(拒收那一段)、`packages/rest/src/data-action-routes.ts`(export
不再把空值当缺省)、`packages/objectql/src/query-expression-conformance.test.ts`(有意翻转的钉子)。
- **两分钟验证**:`pnpm --filter @objectstack/rest exec vitest run
src/data-empty-search-fields-door.test.ts`,预期 4 个用例全过(列表、POST、导出三个门回
400,对照组照旧)。
- **需要你做的**:无,席位落地(进队前欠一次契约复核)。
## What changes
- **`assertSearchFieldsAreSearchable`**
(`metadata-protocol/src/protocol-query-validation.ts`): an override that
names no field used to `return` (read as ABSENT); it now throws `400
VALIDATION_ERROR` with `param` set to the caller's spelling and the
message `Query parameter 'PARAM' names no field; got VALUE. …` — the
envelope `projectionFieldsValue` gives `$select` (#26644). It covers the
standalone slot in every spelling (`$searchFields`, `searchFields`,
string or array) and the object-form `search.fields`, because the gate
is the one place both reach. It runs before the field-map lookup, so a
registry-less host refuses too. Absent stays absent: the door calls the
gate only when a value was sent. On the list and query doors the refusal
holds with or without a `search` term: `GET
/data/:object?$searchFields=` alone answered 200 before and is 400 now,
as a non-empty override naming an unknown field already was; the export
route alone still ignores `searchFields` sent without `search`.
- **`quotedQueryValue`** (`metadata-protocol/src/protocol.ts`): exported
from the module (not from the package index) so the gate quotes the
refused value exactly as the projection refusal does. One word in the
hot file, beside `projectionFieldsValue`; no other line of `protocol.ts`
moves.
- **Export route** (`rest/src/data-action-routes.ts`): `searchFields=`
and `searchFields=,` are kept as the empty list instead of being
dropped, so `findData`'s gate refuses them on this route too. The route
still ignores `searchFields` sent without `search`, as before.
- **Two pins flipped on purpose** (triage ruling 6500648325, option A):
- `objectql/src/query-expression-conformance.test.ts` — "an empty
override is ABSENT, not malformed" becomes "an override naming no field
is refused, not read as absent": `''`, `','`, `' , '`, `[]`,
`$searchFields: ''`, and object-form `fields: []` / `''` each answer
`400 VALIDATION_ERROR` naming the slot; a search with no override still
answers the default scan.
- `objectql/src/engine-search-empty-set.test.ts` — the junction leg `{
search: 'Dune', searchFields: '' }` now asserts the door's refusal
(`VALIDATION_ERROR`, `param: 'searchFields'`) and keeps its point: no
`lib_loan` read, so no silent widening to every row. The other two legs
still assert the engine's junction refusal unchanged.
- Why both flip: both pins drive
`ObjectStackProtocolImplementation#findData`, the same door `GET
/data/:object` hands `req.query` to, so refusing at that door and
keeping them could not both hold (dev report 6499580381, ruling
6500648325).
- **New door pin** `rest/src/data-empty-search-fields-door.test.ts`:
real `RestServer` → `findData` → `ObjectQL` → sqlite. GET list
(`$searchFields=`, `=,`, `= , `, unprefixed `searchFields=`), POST query
(`searchFields: []`, object-form `fields: []`) and the csv export
(`searchFields=`, `=,`) each answer 400 `VALIDATION_ERROR` naming the
spelling, with zero reads of the object; controls (named override
narrows, absent scans the default set, on all three doors) unchanged.
- Docs: the refusal table in `content/docs/api/data-api.mdx` and the
search callout in `content/docs/data-modeling/queries.mdx` name the new
answer.
- Changeset `.changeset/27484-blank-search-fields-refused.md` (`patch`
on `@objectstack/metadata-protocol` and `@objectstack/rest`, BREAKING
banner, ADR-0087 `not-required`).
## Tests
Head `f0e6671a` (merge of `origin/main` b761968 onto `e995818e`); the
full package runs and the dogfood battery ran on `e995818e`, the same
diff before the merge.
<details><summary>Package suites and typecheck (e995818)</summary>
- `pnpm --filter @objectstack/metadata-protocol test` :: exit 0 · Test
Files 279 passed, 4 skipped (283) · Tests 21781 passed, 26 skipped
- `pnpm --filter @objectstack/objectql test` :: exit 0 · Test Files 487
passed (487) · Tests 9149 passed
- `pnpm --filter @objectstack/rest test` :: exit 0 · Test Files 336
passed (336) · Tests 6591 passed, 326 skipped
- `pnpm --filter PKG typecheck` for each of the three :: exit 0 (×3)
- `pnpm lint` :: exit 0
</details>
<details><summary>Re-run on the merged head f0e6671</summary>
- rebuilt `metadata-protocol`, `objectql`, `rest`;
`query-expression-conformance.test.ts` +
`engine-search-empty-set.test.ts`: 207/207;
`data-empty-search-fields-door.test.ts` + `export-integration.test.ts` +
`data-empty-projection-count-door.test.ts`: 35/35; `pnpm --filter
@objectstack/metadata-protocol test`: 21781 passed, 26 skipped.
</details>
<details><summary>Ablation (both legs red, then restored to the HEAD
blob)</summary>
- Gate leg: `node scripts/ablation-replace.mjs --file
packages/metadata-protocol/src/protocol-query-validation.ts --anchor '
if (names.length === 0) {' --replacement " if ((globalThis as
any).ABLATE_27484 === 'refuse' && names.length === 0) {"` — anchor 1 →
0, blob 1d6fa7d → 1e8d9b9a; rebuilt; `ablation-dist-preflight.mjs
@objectstack/metadata-protocol ABLATE_27484` hit in `dist/index.js` and
`dist/index.cjs`. Red: `query-expression-conformance` "an override
naming no field is refused" (promise resolved instead of rejecting),
`engine-search-empty-set` junction leg (got the engine's `has no
searchable` refusal instead of `VALIDATION_ERROR`), and 3 of 4 in
`data-empty-search-fields-door.test.ts` (GET list, POST query, export
each answered 200 with all 3 rows). Restored: blob after == HEAD
1d6fa7d, `git diff HEAD` empty; rebuilt; preflight `--absent` clean
over 24 built files, tree clean.
- Export leg (gate intact): `--file
packages/rest/src/data-action-routes.ts --anchor " if (typeof
q.searchFields === 'string') {"` → the old `q.searchFields.length > 0`
guard. Red: the export case only (`searchFields=""` answered 200);
GET/POST/control stayed green. Restored: blob == HEAD 87b3e97, `git
diff HEAD` empty.
</details>
<details><summary>Dogfood battery (e995818)</summary>
`pnpm exec turbo run build --filter='@objectstack/dogfood^...'` then
`pnpm --filter @objectstack/dogfood test` under `os-verify-lock.sh`, no
shard, no path: `VERDICT command-exit 0` · Test Files 351 passed, 3
skipped (354) · Tests 2822 passed, 20 skipped (2842) · no failures.
</details>
## Acceptance notes
- Branch `claude/project-thread-jmw8xb` is the card thread's
harness-pinned branch, named in claim 6499488942; it carries no issue
number.
- The export route's json format writes its opening `[` before the first
`findData`, so a `findData` refusal there (this one, and the existing
`searchFields=nope` one) lands as a truncated json stream rather than a
clean 400; csv and xlsx answer the envelope. Not changed here; filed as
#27682.
- The published declarations still admit the value this door refuses:
`QueryTransportParamsSchema.$searchFields`,
`EngineQueryOptionsSchema.searchFields`, `QuerySchema.searchFields` and
`FullTextSearchSchema.fields` accept `''` and `[]`. So on `POST
/data/:object/query` the sibling `select: []` is the body schema's `400
VALIDATION_FAILED` while `searchFields: []` is the gate's `400
VALIDATION_ERROR`. Narrowing the declarations (and the engine question)
is follow-up #27683.
- `engine.find()` / `engine.count()` called directly still read an empty
`searchFields` as absent (the engine posture;
`protocol-record-reads.ts`'s palette sweep never sends an empty one).
- Producers checked: `ui/packages/data-objectstack`, `plugin-list`
`ListView.tsx`, `plugin-kanban`, `plugin-gantt` all send `$searchFields`
/ `searchFields` only when the list has at least one entry.
- Hot file: the only open PR touching
`metadata-protocol/src/protocol.ts` is #27535; `git merge-tree
--write-tree HEAD` against its head 585e619 is clean. No open PR
touches the other changed files.
## Verification
Local subset, head `f0e6671a`: `node scripts/pm/dispatch-gates.mjs
--commands --repo objectstack-ai/objectstack` derived 93 families; every
one run with its exit code captured before any pipe, all 93 `exit 0`
(`check:type-check-debt` under `os-verify-lock.sh`). `--ran` reconcile:
"93 derived, 93 run, 0 NOT-MEASURED, 0 UNRUN". The same 93 were also all
`exit 0` on `e995818e` before the merge. Two families answered exit 3 on
the first pass and were re-run after their prerequisite, not read as a
verdict: `check-plugin-teardown-shape.mjs --self-test` (pinned fixture
commit fetched) and `check:dual-build-cjs-loads` / `spec
check:skill-examples` (seven dists built). CI-run families: see this
PR's check-runs.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(not touched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: n/a.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English (the maintainer summary
block is the dispatch contract's Chinese section).
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L6bhgTgHg75Rd5XFiwbUZh)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L6bhgTgHg75Rd5XFiwbUZh
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 69991ff commit 86f2afe
9 files changed
Lines changed: 287 additions & 20 deletions
File tree
- .changeset
- content/docs
- api
- data-modeling
- packages
- metadata-protocol/src
- objectql/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 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
540 | 540 | | |
541 | 541 | | |
542 | 542 | | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
547 | 549 | | |
548 | 550 | | |
549 | 551 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
874 | 874 | | |
875 | 875 | | |
876 | 876 | | |
877 | | - | |
878 | | - | |
879 | | - | |
880 | | - | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
881 | 897 | | |
882 | 898 | | |
883 | 899 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4641 | 4641 | | |
4642 | 4642 | | |
4643 | 4643 | | |
4644 | | - | |
| 4644 | + | |
| 4645 | + | |
| 4646 | + | |
4645 | 4647 | | |
4646 | | - | |
| 4648 | + | |
4647 | 4649 | | |
4648 | 4650 | | |
4649 | 4651 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
| 229 | + | |
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
233 | 242 | | |
234 | 243 | | |
235 | 244 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2271 | 2271 | | |
2272 | 2272 | | |
2273 | 2273 | | |
2274 | | - | |
2275 | | - | |
2276 | | - | |
2277 | | - | |
2278 | | - | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
| 2289 | + | |
| 2290 | + | |
| 2291 | + | |
| 2292 | + | |
2279 | 2293 | | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
2280 | 2297 | | |
2281 | 2298 | | |
2282 | 2299 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1190 | 1190 | | |
1191 | 1191 | | |
1192 | 1192 | | |
1193 | | - | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
1194 | 1201 | | |
1195 | | - | |
| 1202 | + | |
1196 | 1203 | | |
1197 | 1204 | | |
1198 | 1205 | | |
1199 | 1206 | | |
1200 | | - | |
1201 | 1207 | | |
1202 | 1208 | | |
1203 | 1209 | | |
| |||
0 commit comments