Repository navigation
Commit 22af9e6
fix(metadata-protocol): search titles a reference-typed nameField by its target's title (#35292)
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgRuogP8Tp8XyFXLc92Bxvo6)_
repo:objectstack#5 · os-bill · session_01Utp6CZiaBg6rk7dpy1s9Me
Fixes #34175
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:全局搜索 / ⌘K 面板里,对象的 `nameField` 是引用字段(lookup / master_detail / user
/ tree)时,命中标题不再显示目标记录的原始 id,而是显示目标记录自己的标题。
- 为什么改:记录页头(`$expand`)和活动时间线早已显示目标名称,只有搜索面板还在显示 id,用户无法分辨命中的是谁。
- 风险与回滚:目标标题按搜索者本人身份读取(对象权限、行级范围、字段级安全全部生效),被拒的读者仍只看到
id;每个被搜对象只多一次批量读取。回滚即 revert 本 PR。
- 先看:`packages/metadata-protocol/src/protocol-record-reads.ts` 的
`readReferenceTitles`(读取身份与拒绝分支),其次同文件 `searchAll` 中 `hitRows` 一段(批量收集
id)。
- 两分钟验证:`pnpm --filter @objectstack/metadata-protocol exec vitest run
src/protocol.search-title-lookup.test.ts`,预期 11 个测试全绿。
- 需要你做的:无,席位落地。
## What changes
`searchAll` → `renderTitle` returned `row[nameField]` as stored. When
the pointer is a reference field, that value is the target record's id,
so the palette titled such a hit by a raw key. Now:
- The per-object sweep collects the pointer's ids from the rows it will
turn into hits and reads the target's ADR-0079 title pointer
(`nameField`, else the deprecated `displayNameField`) in **one**
`find(target, { where: { id: { $in } }, fields: ['id', title], limit })`
per swept object. No N+1 per hit.
- The target is the spec's `referenceTargetOf` answer (the same arbiter
the `$expand` gate and engine ask), so `user` resolves to `sys_user`
with no `reference` declared, and `tree` follows too.
- **The read is the searcher's**: the caller's `context` goes to `find`,
so the target's object gate, row scope and FLS apply as they do to
`$expand`. A reader refused the target keeps the bare id:
- the target's declared exposure does not serve `get`
(`canServeApiOperation`) → not read;
- `canReadObject(target)` false → not read;
- the read throws `PERMISSION_DENIED` → no titles;
- a row outside the row scope, or a title column FLS strips → that id
keeps its value.
- A target read that fails otherwise propagates, the same disposition
the sweep gives a failing record read; a target whose table was never
provisioned titles nothing (`isMissingTableError`).
- The hit's wire shape does not change: `record` still carries the
stored id, no `$expand` on the palette `find`. Only `title` changes.
- No import from plugin-audit (`resolveLookupTitles`); metadata-protocol
sits below it and below objectql.
- The exposure decision is its own small function,
`servesSearchTitleTarget`, and the new reference-target read is
classified as a `decided` read in
`packages/core/src/security/second-object-read-exposure.pin.test.ts`
(`CALLERS`, plus the pinned list of decision functions). That pin reds
any unclassified caller of `referenceTargetOf`. It was red on this PR's
earlier head (Test Core 6/10) and is green now.
## Tests
New
`packages/metadata-protocol/src/protocol.search-title-lookup.test.ts`
(11 cases): the title follows `lookup`, `master_detail` and `user`; one
target read per swept object, as the searcher, `id` + title only; the
wire shape; four refused-reader legs (object refused before the read,
refusal thrown by the read, row scope, FLS strip); exposure without
`get`; an outage propagates with its envelope (`code` + `status`); a
text pointer pays no extra read.
## Acceptance notes
- Measured on `main` first, at d6d9645, with the new test file: the
PIN answered `{ pm_1: 'per_1', pm_2: 'per_2', pm_3: 'per_1' }`, so each
hit was titled by the stored lookup id. 7 of 11 failed on main. The 4
that passed there are the refusal, exposure, wire-shape and control
legs, which hold on main because main never follows the reference.
- The card's named stock producer, `sys_record_share.recipient_id`, is a
**`Field.text`** column (a polymorphic principal id read with
`recipient_type`), not a reference field. So this fix does not change
that object's palette title. Following it needs the
`recipient_type`-keyed directory read the console's `recipient-picker`
face does, which is a separate design. Stock objects with a reference
`nameField` in this repo are `sys_scim_subject` (`searchable: false`)
and `sys_session` (skipped by name prefix), so no stock object reaches
the palette through this path. The reach is app objects, for example
HotCRM's `crm_project_member` behind #34055.
- `referenceNameVisible` (ruling 6574398310) is not served here. A
refused reader keeps the bare id, as the dispatch states. Serving a
refused reader the target's name needs a system-context read, which is a
new disclosure decision and not in this card.
- One hop only: a target whose own title column is itself a reference
shows that column's stored value.
- A multi-valued reference pointer titles each element and joins them
with `, `. When nothing resolves, the value is rendered exactly as
before.
- The `searchAll` method docblock in `protocol.ts` is not edited because
it is outside this claim's file surface. The contract text for the new
read is on `readReferenceTitles` and at the call site.
## Verification
<details><summary>Red leg on main (d6d9645)</summary>
```
× THE PIN — a lookup pointer titles each hit by the target title, not the stored id
AssertionError: expected { pm_1: 'per_1', pm_2: 'per_2', …(1) } to deeply equal { pm_1: 'Ada Lovelace', …(2) }
Tests 7 failed | 4 passed (11)
```
</details>
<details><summary>Green, package suite and typecheck</summary>
Run at bc101ad (source identical to the current head; the later
commit only adds a module-top import to the new test file, re-run green:
`Tests 11 passed (11)` at 7e664c7).
```
pnpm --filter @objectstack/metadata-protocol typecheck -> exit 0 (tsc --listFiles includes the new test file)
pnpm --filter @objectstack/metadata-protocol exec vitest run --maxWorkers=2
Test Files 358 passed | 9 skipped (367)
Tests 23218 passed | 45 skipped (23263)
os-verify-lock: VERDICT command-exit 0
```
</details>
<details><summary>Ablation (committed fix, then mutated, then
restored)</summary>
Deleted `if (canReadObject && !(await canReadObject(target))) return
titles;` with `scripts/ablation-replace.mjs`: anchor 1 to 0, blob
35ced75 to f92c32c63df5. Result: `× REFUSED — an object-level
refusal keeps the bare id, and the target is never read`, `Tests 1
failed | 10 passed (11)`. Restored: blob equals HEAD (35ced75) and
`git diff HEAD` is empty.
</details>
<details><summary>Derived gates and CI</summary>
Final head ff64484. `dispatch-gates --commands` derived 69 families.
All 69 were run locally and every one exited 0. `dispatch-gates --ran`
reported: 69 accounted for, 0 NOT-MEASURED, 0 UNRUN, exit 0. Pre-push
`overlap-check` gave VERDICT clean exit 0.
Along the way:
- `check:test-source-alias` failed on the new test file because it
needed a module-top `import '@objectstack/lint'`. Fixed in 7e664c7.
- `check:lean-entry-closure` first exited 3 because the objectql dist
had not been built. After building objectql it exited 0.
- On 7e664c7, CI `Test Core (6/10)` failed on the core
`second-object-read-exposure` pin because the new caller was not yet
classified. Fixed in ff64484; locally that pin gives `Tests 4 passed
(4)`.
- CI `Test Core (8/10)` hit a 5000 ms timeout in `plugin-security`
`org-admin-assignment-boundary.posture.test.ts`. That file is untouched
here. Locally it gives `Tests 104 passed (104)`, and it is green on
ff64484.
CI check-runs on ff64484: every non-skipped run has
`completed/success`. That includes `Lint & Repo Gates`, `TypeScript Type
Check`, `Test Core` (10/10 shards), `Build Core`, `Governed Surface
Queue Guard`, `Test UI`, `Type Check UI`, `Build & E2E UI`, `Live E2E
UI`, `Dogfood Regression Gate` and `Check Changeset`.
</details>
🤖 Generated with [Claude Code](https://claude.com/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 de8d549 commit 22af9e6
4 files changed
Lines changed: 451 additions & 6 deletions
File tree
- .changeset
- packages
- core/src/security
- metadata-protocol/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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
190 | 198 | | |
191 | 199 | | |
192 | 200 | | |
| |||
559 | 567 | | |
560 | 568 | | |
561 | 569 | | |
| 570 | + | |
562 | 571 | | |
563 | 572 | | |
564 | 573 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
270 | 271 | | |
271 | 272 | | |
272 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 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 | + | |
273 | 376 | | |
274 | 377 | | |
275 | 378 | | |
| |||
437 | 540 | | |
438 | 541 | | |
439 | 542 | | |
440 | | - | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
441 | 556 | | |
442 | 557 | | |
443 | | - | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
444 | 563 | | |
445 | 564 | | |
446 | 565 | | |
| |||
572 | 691 | | |
573 | 692 | | |
574 | 693 | | |
575 | | - | |
576 | | - | |
577 | | - | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
578 | 713 | | |
579 | 714 | | |
580 | 715 | | |
| |||
0 commit comments