Repository navigation
Commit 3d5933a
fix(metadata-protocol): the layered read of a form view naming a field its object lacks carries the form-field-unknown warning (#29683)
<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ811zUetuVLmmG85oB1QY7WM)_
Fixes #29435
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:分层读取(`GET /api/v1/meta/view/NAME?layers=true`)现在对 `effective`
跑与单项读取相同的表单布局检查,表单视图引用对象不存在的字段时,`_diagnostics.warnings` 带上
`form-field-unknown` 警告。
- 为什么改:Studio 的界面栏目和元数据编辑器在没有草稿时读分层结果;已发布、无草稿的表单视图此前显示 `valid:
true`,作者看不到警告,字段在运行时被静默跳过。
- 风险与回滚:只追加警告,`valid` 仍取 schema 的结论;非 view 类型原样返回。回滚即还原本 PR,无迁移。
- 先看:`packages/metadata-protocol/src/protocol-meta-layered-reads.ts` 中
`_diagnostics` 的计算(约 L510),以及测试文件末尾的 #29435 一节。
- 两分钟验证:`pnpm --filter @objectstack/metadata-protocol exec vitest run
src/protocol.form-layout-diagnostics.test.ts`,预期 12 个测试全绿。
- 需要你做的:无,席位落地
## What changes
`getMetaItemLayered`
(`packages/metadata-protocol/src/protocol-meta-layered-reads.ts`)
computed `_diagnostics` with `computeMetadataDiagnostics(request.type,
effective)` alone, which is schema-only. `getMetaItem` adds the lint's
form-layout warnings through `withFormLayoutWarnings` (#29196, #29309).
So a published form view whose section names `no_such_field` read `{
valid: true }` on the layered read while the single-item read of the
same body warned.
The layered read now runs `withFormLayoutWarnings` on `effective`, with
the schema verdict as the prior `_diagnostics`. The object lookup is the
same one `getMetaItem` uses (`host.engine.registry.getObject`, the
served object with its extensions folded on). It covers
`form-field-unknown` and `form-section-group-unknown`, at the same
item-relative paths. Warnings only, so `valid` stays the schema's
answer. A non-view type, or a body that is not a record, gets back
exactly the schema verdict.
The pass runs before redaction and before `servedLockState`, where the
schema verdict already ran, so it judges the same raw `effective` body.
Execution-context exemption: `serveFormLayout` skips the pass on the
execution face (`opts.face === 'execution'`). `getMetaItemLayered` has
no face parameter and no execution caller; it is the `?layers=true`
authoring read. So there is no execution leg to exempt, and the pass
runs unconditionally. Stated in the code comment.
Files (3, +84 / -2):
- `packages/metadata-protocol/src/protocol-meta-layered-reads.ts`: the
pass, one import.
-
`packages/metadata-protocol/src/protocol.form-layout-diagnostics.test.ts`:
a new `describe` at the end, plus `getItem: () => undefined` on the stub
registry (the layered read's code-layer lookup; no package ships these
views). The pins sit in the same file as the #29196 pins rather than a
new file beside it, so they reuse its stub engine instead of copying 150
lines of harness.
- `.changeset/29435-layered-read-form-layout-warnings.md`: patch for
`@objectstack/metadata-protocol`.
No `packages/spec` hunk. The response shape is unchanged:
`_diagnostics.warnings` already exists on `MetadataDiagnostics`.
## Tests
Two new tests in `protocol.form-layout-diagnostics.test.ts`:
1. A published form view naming `no_such_field`:
`getMetaItemLayered(...)._diagnostics` equals `{ valid: true, warnings:
[{ path: 'config.sections.0.fields.1', message }] }`, with the message
taken from `validateFormLayout` run in the test, and equals
`getMetaItem`'s `item._diagnostics` for the same item.
2. Control: a published form naming only real fields, `region__c` (an
extension field) among them, reads exactly `{ valid: true }`.
Red first on `7dae3b3c` (fix not applied): test 1 failed with `expected
{ valid: true } to deeply equal { valid: true, warnings: [ … ] }`, test
2 passed. With the fix: 12/12.
Ablation (`node scripts/ablation-replace.mjs`, fix committed first at
`7349766e`): the anchor `const _diagnostics = effective !== null &&
typeof effective === 'object'` was replaced with `false && …` (anchor 1
→ 0, blob `fdc7bda8` → `1bc73586`). Test 1 red, 11 green. Restored: blob
equals HEAD `fdc7bda8`, `git diff HEAD` empty. The test imports
`./protocol.js` from `src`, so no `dist/` leg applies.
## Acceptance notes
- The card asks for the pins "beside"
`protocol.form-layout-diagnostics.test.ts`; they are inside it, for the
harness reason above.
- No out-of-scope finding.
## Verification
<details><summary>Package suite and typecheck</summary>
`pnpm --filter @objectstack/metadata-protocol test`: Test Files 308
passed, 4 skipped (312); Tests 22264 passed, 26 skipped (22290). `pnpm
--filter @objectstack/metadata-protocol typecheck`: `tsc --noEmit` exit
0 (the tsconfig excludes only `node_modules` and `dist`, so the test
file is checked).
</details>
<details><summary>Derived gates and lint</summary>
Run on head `7349766e`. `node scripts/pm/dispatch-gates.mjs --commands`
derived 59 commands from the 3-path change set. All 59 recorded `exit
0`, plus `pnpm lint` exit 0.
Three exited 3 (PREREQUISITE NOT MET) on the first pass and were re-run
after supplying the prerequisite, all then exit 0:
- `node scripts/check-plugin-teardown-shape.mjs --self-test`: the pinned
positive-control commit `621a4876` was outside the shallow clone;
fetched that one commit.
- `pnpm check:lean-entry-closure`: needed `packages/objectql/dist`;
built `@objectstack/objectql`.
- `pnpm check:dual-build-cjs-loads`: needed every published package's
`dist/`; built the workspace (117 tasks, 78 cached). 115 require entry
points across 70 packages load.
`dispatch-gates --ran`: 59 derived, 59 run, 0 NOT-MEASURED, 0 UNRUN
(`pnpm lint` recorded outside the derivation). CI-only families
(type-check lanes, Build Core, Test Core shards) are left to this PR's
check-runs.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01JQwxbXJ2AjZ1uaAswCJcq1)_
Co-authored-by: Claude <noreply@anthropic.com>1 parent 1c1a5d4 commit 3d5933a
3 files changed
Lines changed: 84 additions & 2 deletions
File tree
- .changeset
- packages/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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
507 | 507 | | |
508 | 508 | | |
509 | 509 | | |
510 | | - | |
| 510 | + | |
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
514 | 528 | | |
515 | 529 | | |
516 | 530 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
171 | 174 | | |
172 | 175 | | |
173 | 176 | | |
| |||
454 | 457 | | |
455 | 458 | | |
456 | 459 | | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
0 commit comments