Repository navigation
Commit aeac74b
fix(metadata-protocol): a form view naming a field its object lacks reads with the lint's form-field-unknown warning (#29307)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9MP94x2mHLb3VMeZqcfx4Es)_
Fixes #29196
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:表单视图的分区里写了对象上不存在的字段时,`/meta` 读取(已发布、草稿、草稿预览)的
`_diagnostics.warnings` 现在会带上 lint 规则 `form-field-unknown`
的原文警告,定位到具体字段引用。
- 为什么改:这种表单以前保存、发布、读取都显示 `valid: true`,作者完全不知道字段被静默跳过;规则早就有,只是只在 CLI 里跑。
- 风险与回滚:只加警告,不改 `valid`、不拒绝保存或发布;列表读取不受影响。回滚即还原本 PR,无数据迁移。
-
先看:`packages/metadata-protocol/src/metadata-diagnostics.ts`(`withFormLayoutWarnings`,ViewItem
的 `config`
适配与对象查找),`packages/metadata-protocol/src/protocol.ts`(读取出口的三处接线),`packages/metadata-protocol/src/protocol.form-layout-diagnostics.test.ts`。
- 两分钟验证:`pnpm --filter @objectstack/metadata-protocol exec vitest run
src/protocol.form-layout-diagnostics.test.ts`,预期 4 个用例全绿;在 main 上同一命令有 2
个红。
- 需要你做的:无,席位落地。
## What changes
`validateFormLayout` (`@objectstack/lint`) reports a form section field
the bound object does not have as `form-field-unknown` ("is silently
skipped and never renders on the form"). It ran only in the CLI, so the
meta door served such a view with `_diagnostics: { valid: true }`.
- **`withFormLayoutWarnings`** (new, `metadata-diagnostics.ts`): runs
`validateFormLayout` on the served view body and appends each
`form-field-unknown` finding to `_diagnostics.warnings` as the spec's `{
path, message }`, with the rule's own message and an item-relative path.
`valid` and `errors` are left as they were.
- A stored form `ViewItem` (`viewKind: 'form'`) keeps its form under
`config`, a rung the lint's view walk does not descend. It is handed to
the rule as the container shape the walk reads (`{ name, object, form:
config }`), and the finding's `form.` path is mapped back to `config.`
(QA's reproduction reads `config.sections.0.fields.1`). Containers and
flattened form overlays are the walk's own input already.
- The object universe is the door's own lookup:
`registry.getObject(name)` (the served object, extensions folded on) for
each object name the body spells. A name it cannot resolve is left out,
so that form is not judged and gets no warning.
- `@objectstack/lint` is imported lazily from its root on the first view
read, the way `build-probes.ts` loads `validateObjectFieldRefs`. The
kernel boot path still reaches the package only through `/runtime`.
- **`readMetaItem`** (`protocol.ts`): the pass runs at every served exit
of the single-item read: the active read (after the ADR-0047 reference
merge, which rebuilds `_diagnostics` from its errors), the strict draft
read, and the draft-preview arm (both through `serveDraft`, before the
#26707 publish verdict is folded in). The execution face serves no
`_diagnostics` and is untouched. `getMetaItems` (the list read) is
untouched.
Which attach site the served read uses:
`@objectstack/metadata-protocol`'s `readMetaItem`
(`decorateMetadataItem` plus the view reference merge). The card's
`packages/metadata/src/metadata-manager.ts` is not on that path.
## Tests
- New
`packages/metadata-protocol/src/protocol.form-layout-diagnostics.test.ts`,
through the protocol's own save, publish and read (the methods `PUT
/meta/view/NAME?mode=draft`, `POST .../publish` and `GET` call), with
the stub engine shape of `protocol.draft-publish-verdict.test.ts`:
1. QA's ViewItem body: the draft saves, its read carries the warning,
the publish is not refused, and the active read carries the same
warning. The message is compared against `validateFormLayout` run in the
same test.
2. A view container's `formViews.edit` is judged and located under its
own key.
3. Control: a form naming only fields the served object has (one of them
only on the served object, not the authored one) reads exactly `{ valid:
true }`, draft and active.
4. A form whose object does not resolve reads exactly `{ valid: true }`.
- Forced edit: `scripts/engine-double-contract.pinned.json` gains the
new file's three engine-double rows (`check:engine-double-contract`'s
own `--write`).
## Acceptance notes
- The warning carries no rule id on the read wire:
`MetadataValidationResultSchema.warnings` entries are `{ path, message
}` in the spec, the shape the read's other derived warnings already use.
Carrying `code` is a spec widening, left as an open question in the card
report.
- The save and publish responses' `advisories` do not carry this
finding: `validateFormLayout` is CLI-only on the runtime publish surface
in the lint registry. Crossing it is a registry decision, left as an
open question.
- `form-section-group-unknown`, the rule's sibling finding, is not
surfaced at the door (this card names `form-field-unknown` only).
- The layered read (`?layers=true`) `_diagnostics` stays schema-only, as
it already is for the ADR-0047 reference errors.
- Studio: `ResourceEditPage` already renders `_diagnostics.warnings`
with their paths. The form designer canvas has no reader of them; named
as a `domain:ui` follow-up in the card report.
- Cost: about 25 µs per single view read (2000 reads of a 6-section,
36-field form against a 40-field object, measured in-process). The list
read pays nothing.
## Verification
Head `1560285c` (main merged at `eed73a39`). Every run below goes
through `scripts/pm/os-verify-lock.sh`; each line quotes the run's own
verdict.
<details><summary>Red first on main (104cd1a, test only)</summary>
`vitest run src/protocol.form-layout-diagnostics.test.ts`: `Tests 2
failed | 2 passed (4)`. Failing: the ViewItem case at the draft read
(`expected { valid: true } to deeply equal { valid: true, warnings: [ {
…(2) } ] }`) and the container case (`expected undefined to deeply equal
[ { …(2) } ]`). The two controls passed.
</details>
<details><summary>Green on the fix</summary>
- The pin: `Tests 4 passed (4)`.
- `pnpm --filter @objectstack/metadata-protocol typecheck && pnpm
--filter @objectstack/metadata-protocol test` on `1560285c`: `VERDICT
command-exit 0`, `Test Files 301 passed | 4 skipped (305)`, `Tests 22111
passed | 26 skipped (22137)`.
- eslint (`eslint.js packages/metadata-protocol --no-inline-config`):
exit 0.
</details>
<details><summary>Ablations (scripts/ablation-replace.mjs, each restored
to the HEAD blob with an empty git diff HEAD)</summary>
Run on `42185878`, the fix before the two main merges; neither merge
touched `readMetaItem` or `metadata-diagnostics.ts`.
- A, the active-exit call deleted from `readMetaItem`: `Tests 1 failed |
3 passed`, the ViewItem case red at the active read.
- B, an unresolvable object name given an empty field set instead of
being left out: `Tests 1 failed | 3 passed`, the unresolvable-object
case red.
- C, the lookup switched from `registry.getObject` to the authored
`listItems('object')`: `Tests 1 failed | 3 passed`, the served-object
control red (`region__c` reported).
</details>
<details><summary>Gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` on `1560285c`: 70 commands, all exit 0
(after a full `turbo run build --filter='./packages/**'`). `--ran`
reconciliation: `70 derived famil(ies) accounted for — 70 run, 0
NOT-MEASURED (a DERIVED zero)`.
</details>
No `!` in the title and no `(narrowing)` arm, so the full dogfood
battery is not owed.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmQM9W8oVztX5XNAQaN)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent a2fcede commit aeac74b
5 files changed
Lines changed: 425 additions & 2 deletions
File tree
- .changeset
- packages/metadata-protocol/src
- scripts
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
431 | 431 | | |
432 | 432 | | |
433 | 433 | | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 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 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
434 | 550 | | |
435 | 551 | | |
436 | 552 | | |
| |||
0 commit comments