Skip to content

Commit f129848

Browse files
fix(metadata-protocol): a form view's unknown field or group is answered on save and publish, and the group finding reaches the read (#29389)
domain:server#2 · os-steve · session_01ADHkmQxwoGb5fSnrFkpxmt <!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9VuKSPKLCdyPe1HVgMCJrsr)_ Fixes #29309 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:表单视图写了对象上不存在的字段或字段分组时,直接保存(非草稿)和发布的应答现在在 `advisories` 里带上 lint 原文警告(`form-field-unknown` / `form-section-group-unknown`);读取的 `_diagnostics.warnings` 也补上了分组那一条。 - 为什么改:MCP / AI 作者只看保存与发布的应答,以前这两处一声不吭,只有之后再读一次才知道字段或整个分区被静默跳过。 - 风险与回滚:只加警告,不拒绝任何保存或发布,`valid` 不变;草稿保存照旧不跑规则。规则现在也读 Studio 存的表单项(`viewKind: 'form'`,分区在 `config` 下),所以 `os validate` / `os build` / `os lint` 对这类表单也会多出同样的警告。回滚即还原本 PR,无数据迁移。 - 先看:`packages/lint/src/validate-form-layout.ts`(表单项 `config` 这一级的遍历),`packages/lint/src/authoring-rules.ts`(`validateFormLayout` 登记项改为 `runtimeTypes: ['view']`),`packages/metadata-protocol/src/metadata-diagnostics.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`,预期 10 个用例全绿;在 main 上新增的用例 4 个红(对照组绿)。 - 需要你做的:无,席位落地。 ## What changes - **Save and publish answers** (`packages/lint/src/authoring-rules.ts`): the `validateFormLayout` registration moves from `CLI_ONLY` + `RUNTIME_NEEDS_FULL_SNAPSHOT` to `CLI_AND_RUNTIME` + `runtimeTypes: ['view']`. - **The form item rung** (`packages/lint/src/validate-form-layout.ts`, the view walk only, per claim amendment 6579089637): the rule also walks a `viewKind: 'form'` item's `config` sections, the shape Studio saves (`{ name, object, viewKind: 'form', config }`), binding `config.data.object` first and the item's `object` otherwise. Rule ids, messages, hints and severity are unchanged. A list item's `config` is not walked. The rung lives in this rule, not in the shared `view-walk.ts`, so the other walkers' verdicts do not move. The CLI commands see the same rung, so a stack carrying a form item is judged there too. The rule is advisory, so an active save and a publish of a view whose form names an unknown field or an undeclared field group land as before and answer both findings in `advisories` (rule id, message, hint, `severity: 'warning'`). - **The read** (`packages/metadata-protocol/src/metadata-diagnostics.ts`): `withFormLayoutWarnings` lets `form-section-group-unknown` through beside `form-field-unknown`, with the lint's own message (one spelling). Its own `config` adapter (`formLayoutSubject`, from #29196) is retired: the rule now reads the served item as it is, the same walk the gate runs, and the read's paths (`config.sections.0.fields.1`) are unchanged. ### The measurement the card asked for (the snapshot at the real doors) Read and then measured on a real showcase boot (`pnpm dev --fresh`, this branch's build): | door | runs the registry? | objects in the snapshot | result | |---|---|---|---| | `PUT /meta/view/X` (active save) | yes | `registry.listItems('object')` = `getAllObjects` → `resolveObject` (overlay + every extender folded, the shape `getObject` serves), plus stored rows folded by `foldStoredCollection` | container form naming `loyalty_tier` (a `showcase_account` extension field), `no_such_field` and group `no_such_group`: two advisories, the extension field not reported | | `POST /meta/view/X/publish` | yes | same | `no_such_field` answered as a warning, publish not refused | | `PUT /meta/view/X?mode=draft` | no (#4463 D1: no rule gates a draft) | none handed to any rule | no advisory, by contract; the draft read carries the warnings (#29196) | | runtime-authored object (stored row only) | yes | stored half | form on it: its real fields known, `nope_field` reported | | control | yes | same | form naming `name` + `loyalty_tier`: no advisory | | Studio form item, before the rung | yes | same | `PUT /meta/view/showcase_account.probe_e` (`viewKind: 'form'`, `no_such_field` under `config`): no advisory, the read warned. This is what the rung closes; pinned below. | So the objects are present, extensions and stored rows included, on both doors that run rules. No door hands the rule a snapshot without them. ### No double report on the read The read carries no runtime advisory: the draft read folds the publish verdict's refusals only (`withPublishVerdict`), and these findings are never refusals. Pinned: the active read after an active save carries each finding once. ## Tests `packages/metadata-protocol/src/protocol.form-layout-diagnostics.test.ts` (the #29196 file and harness, no new engine double), four new cases: 1. a section naming an undeclared field group reads with the lint warning, draft and active (half 2); 2. an active save naming an unknown field and an unknown group answers both as warnings with the lint's rule/message/hint, and the active read carries each once (half 1); 3. a draft save carries no advisory (D1), and its publish answers `form-field-unknown` as a warning and is not refused (half 1); 4. control: real fields (an extension field among them) and a declared group answer no advisory and read `{ valid: true }`; 5. a Studio form item naming an unknown field: an active save and a publish answer it as a warning, and its read carries it once at `config.sections.0.fields.1`; 6. control: a form item naming only real fields (an extension field among them) answers no advisory. `packages/lint/src/validate-form-layout.test.ts`, four new cases: a form item's unknown field and undeclared group, found at `views[0].config…` with `where` `· config`; the config's own `data.object` binding wins over the item's `object`; control: real fields and a declared group are clean; control: a list item's `config` is not walked. Red first: cases 1-3 red on `origin/main` `57cde8cb` (control green); after the round-1 fix, case 5 and the two lint finding cases red on `9226d33b` (both controls green). **Forced test edits**, named: - `protocol.form-layout-diagnostics.test.ts`: the stub registry's `listItems('object')` now lists the served (merged) object rather than the authored one. Both real registry reads go through `resolveObject`; the old stub answered a shape no registry answers and would have invented a phantom on the extension field. The fixture object also declares one `fieldGroups` entry. - `runtime-gate.test.ts` (three lists), `authoring-rule-wiring.test.ts` (one), `runtime-gate.page-visibility-predicate-writes.test.ts` (one): the `view` write's rule list gains `validateFormLayout` after `validateReferenceIntegrity`. ## Acceptance notes - Advisory paths at the gate are stack-shaped (`views[0].formViews.edit.sections[0].fields[2]`, `views[0].config.sections[0].fields[1]`), as every runtime-gate advisory is; the read's warnings stay item-relative. - A `?mode=draft` save runs no registry rule (#4463 D1), so it answers no form-layout advisory; its read and its publish do. Left as it is by the seat. - An object outside the write's package closure is not in the snapshot; both checks skip an unknown object, so such a form is not judged rather than misjudged. - Cost: no new read. The rule walks the objects the gate already gathers; the view read path loses an adapter and gains nothing. ## Verification Head: `6266ec85` (merge of `origin/main` `7f277a86` into the rung commit `eb7ddbb4`). All runs below on `6266ec85` unless marked. - Round 1 red first on `origin/main` `57cde8cb`: `Tests 3 failed | 5 passed (8)` (cases 1-3; control green). - Round 2 red first on `9226d33b` (new pins, rule unchanged): `validate-form-layout.test.ts` `Tests 2 failed | 34 passed (36)`, `protocol.form-layout-diagnostics.test.ts` `Tests 1 failed | 9 passed (10)` (case 5; both controls green). - Green on `eb7ddbb4`: `36 passed (36)`, `10 passed (10)`. - Ablation 1 (registration back to `CLI_ONLY`, lint rebuilt, preflight marker in 4 built files): cases 2 and 3 red; restored, preflight `--absent` exit 0. - Ablation 2 (read filter back to `form-field-unknown` only): cases 1 and 2 red; restored. - Ablation 3 (the `config` rung removed, lint rebuilt, preflight marker in 4 built files): lint `2 failed | 34 passed`; door `3 failed | 7 passed` (the #29196 read pin, case 1 and case 5: the read has no adapter now, so it depends on the rung too); restored, `git diff HEAD` empty, rebuilt, preflight `--absent` exit 0. - Real showcase boot measurements: see the table above. <details><summary>Package suites and typecheck (head 6266ec8, under the verify lock)</summary> - `turbo run build --filter='./packages/**'` exit 0; `pnpm --filter @objectstack/spec check:generated` exit 0 - `pnpm --filter @objectstack/lint test` → exit 0, `Test Files 189 passed (189)`, `Tests 7834 passed (7834)` - `pnpm --filter @objectstack/lint typecheck` → exit 0 - `pnpm --filter @objectstack/metadata-protocol test` → exit 0, `Test Files 304 passed | 4 skipped (308)`, `Tests 22161 passed | 26 skipped (22187)` - `pnpm --filter @objectstack/metadata-protocol typecheck` → exit 0 </details> <details><summary>Derived gates: 61 derived, 61 run, 0 NOT-MEASURED, 0 UNRUN (dispatch-gates --ran, head 6266ec8)</summary> ``` node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-adoption.mjs :: exit 0 node scripts/check-comment-mask-adoption.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-dts-emitted.mjs --self-test :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 node scripts/check-issue-citations.mjs :: exit 0 node scripts/check-plugin-teardown-shape.mjs :: exit 0 node scripts/check-plugin-teardown-shape.mjs --self-test :: exit 0 node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0 node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0 node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0 node scripts/docs-audit/check-affected-docs.mjs :: exit 0 node scripts/docs-audit/check-drift-comment.mjs :: exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0 node scripts/release-pending-publish.mjs --self-test :: exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 pnpm check:ci-filter-parity :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:dispatcher-error-vocabulary :: exit 0 pnpm check:doc-authoring :: exit 0 pnpm check:docs-transcript-drift :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:dts-closure :: exit 0 pnpm check:dual-build-cjs-loads :: exit 0 pnpm check:durability-log-level :: exit 0 pnpm check:engine-double-contract :: exit 0 pnpm check:error-code-casing :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:issue-citations :: exit 0 pnpm check:keyed-text-bounds :: exit 0 pnpm check:lean-entry-closure :: exit 0 pnpm check:logger-receiver-detach :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:objectql-double-limit :: exit 0 pnpm check:org-identifier :: exit 0 pnpm check:page-declaration-shape :: exit 0 pnpm check:platform-object-tenancy-census :: exit 0 pnpm check:pm-changeset-deadline-census :: exit 0 pnpm check:published-files :: exit 0 pnpm check:query-options-erasure :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:registry-log-declared :: exit 0 pnpm check:rest-log-spy-declared :: exit 0 pnpm check:slot-lookup :: exit 0 pnpm check:sourcemap-no-sources-content :: exit 0 pnpm check:system-context-census :: exit 0 pnpm check:test-source-alias :: exit 0 pnpm check:tier-file-adoption :: exit 0 pnpm check:type-check-coverage :: exit 0 pnpm check:type-check-debt :: exit 0 pnpm check:undeclared-dep-imports :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm check:where-matcher :: exit 0 ``` Package lint: root eslint `--no-inline-config` on `packages/lint` and `packages/metadata-protocol` → exit 0. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmQ25mz3PUm6CpePgB3)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4138ce8 commit f129848

9 files changed

Lines changed: 328 additions & 37 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@objectstack/lint': patch
3+
'@objectstack/metadata-protocol': patch
4+
---
5+
6+
Clause-②: no
7+
Metadata-protocol: none
8+
9+
A form view whose section names a field its object does not have, or a field group the object does not declare, now hears about it when it is saved and published, not only on a later read.
10+
11+
- `validateFormLayout` runs at the runtime publish gate for `view` writes (`runtimeTypes: ['view']`). An active save and a publish of such a view answer `form-field-unknown` / `form-section-group-unknown` in the response's `advisories`, with the lint's own message and hint. They are warnings: the write lands, nothing is refused. A draft save still runs no authoring rule; its read carries the warnings.
12+
- The rule now also reads a stored form item's `config` (`{ name, object, viewKind: 'form', config }`, the shape Studio saves), so a Studio-authored form is judged on save, on publish and by `os validate` / `os build` / `os lint` alike, at `config.sections…` paths. A list item's `config` is not walked.
13+
- The `/meta` view read now carries `form-section-group-unknown` in `_diagnostics.warnings` beside `form-field-unknown`, with the same message the lint prints. `valid` stays the schema's answer.

‎packages/lint/src/authoring-rule-wiring.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ describe('authoring-rule registry wiring (#4409)', () => {
511511
'validateStackExpressions',
512512
'validatePresetComparands',
513513
'validateReferenceIntegrity',
514+
// #29309 — a form section naming an unknown field or field group.
515+
'validateFormLayout',
514516
// #25650 — a form open to anonymous intake declaring a file field.
515517
'validatePublicFormFileFields',
516518
// #28005 — a thank-you panel naming a field the engine does not generate.

‎packages/lint/src/authoring-rules.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,14 +1606,28 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
16061606
// `validate-form-layout.ts`'s module note carries the measurement.
16071607
// Pure structured-metadata walk (no lazy dependency), so wiring it to all
16081608
// three costs nothing measurable.
1609+
//
1610+
// [#29309] Runtime publish gate: a `view` write's snapshot carries `objects`
1611+
// as context, and the rule reads nothing else beside the written view — the
1612+
// bound object's fields and its `fieldGroups`. Measured at the two doors
1613+
// that run this registry (an active save, a publish): the universe is the
1614+
// registry's merged objects (`getAllObjects`, the overlay and every extender
1615+
// folded on, the shape `getObject` serves) with the stored rows folded on by
1616+
// the read API's own merge, so an extension field is known and no phantom is
1617+
// reported. So RUNTIME_NEEDS_FULL_SNAPSHOT no longer held here. Advisory,
1618+
// so both findings ride back on the 2xx `advisories` and nothing is refused.
1619+
// An object outside the write's package closure is not in the snapshot and
1620+
// the rule then judges that form not at all (both checks skip an unknown
1621+
// object), never reports it. `object` is not declared, for the reason the
1622+
// file-field rule below gives.
16091623
{
16101624
name: 'validateFormLayout',
16111625
tier: 'advisory',
16121626
input: 'parsed',
16131627
commands: ALL,
16141628
source: 'packages/lint/src/validate-form-layout.ts',
1615-
surfaces: CLI_ONLY,
1616-
surfaceReason: RUNTIME_NEEDS_FULL_SNAPSHOT,
1629+
surfaces: CLI_AND_RUNTIME,
1630+
runtimeTypes: ['view'],
16171631
run: (stack) => validateFormLayout(stack),
16181632
},
16191633
// Ruling C on #25572 (#25650) — a form open to anonymous intake that

‎packages/lint/src/runtime-gate.page-visibility-predicate-writes.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ describe('#24491 — the page door gives the build\'s visibility-predicate verdi
205205
'validateStackExpressions',
206206
'validatePresetComparands',
207207
'validateReferenceIntegrity',
208+
'validateFormLayout',
208209
'validatePublicFormFileFields',
209210
'validateThankYouRecordFields',
210211
...FAMILY,

‎packages/lint/src/runtime-gate.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ describe('the views[] visibility-predicate family at the runtime publish gate (#
339339
// (`validateSearchableFields` / `validateSortableFields`) on the
340340
// per-write snapshot — see `runtime-gate.view-writes.test.ts`.
341341
'validateReferenceIntegrity',
342+
// #29309 — a form section naming an unknown field or field group;
343+
// advisory, against the same `objects` context.
344+
'validateFormLayout',
342345
// #25650 — a form open to anonymous intake declaring a file field;
343346
// the snapshot's `objects` context carries the field types it reads.
344347
'validatePublicFormFileFields',
@@ -545,6 +548,7 @@ describe('the views[] visibility-predicate family at the runtime publish gate (#
545548
'validateStackExpressions', // #24798 — its bulk `confirmText` pass alone, clean here
546549
'validatePresetComparands', // #8793 — dispatched for `view`, clean here
547550
'validateReferenceIntegrity', // #9313 — its two list-view field members, clean here
551+
'validateFormLayout', // #29309 — a form's field and group references, clean here
548552
'validatePublicFormFileFields', // #25650 — a public form's file fields, clean here
549553
'validateThankYouRecordFields', // #28005 — a thank-you panel's named fields, clean here
550554
'validateVisibilityPredicates',
@@ -642,6 +646,7 @@ describe('the publish gate judges a schema-bound form at its own layer (#7815)',
642646
'validateStackExpressions', // #24798 — its bulk `confirmText` pass alone, clean here
643647
'validatePresetComparands', // #8793 — dispatched for `view`, clean here
644648
'validateReferenceIntegrity', // #9313 — its two list-view field members, clean here
649+
'validateFormLayout', // #29309 — a form's field and group references, clean here
645650
'validatePublicFormFileFields', // #25650 — a public form's file fields, clean here
646651
'validateThankYouRecordFields', // #28005 — a thank-you panel's named fields, clean here
647652
'validateVisibilityPredicates',

‎packages/lint/src/validate-form-layout.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,52 @@ describe('#16168 — falls back to the container list binding', () => {
612612
// [#22161] Slice 21: the `fix:` line of `form-section-group-unknown` is one
613613
// remedy line. It names the nearest declared group ("Did you mean") instead of
614614
// echoing the object's whole group list, and how a section inherits a group's
615+
// [#29309] A stored form ViewItem — `{ name, object, viewKind: 'form', config }`,
616+
// the shape Studio saves through `PUT /meta/view` — keeps its form under
617+
// `config`. The view walk read only the container rungs, so the runtime publish
618+
// gate (which hands the rule the written body as authored) judged such a form
619+
// not at all. Same two findings, located under `config`.
620+
describe('#29309 — a form ViewItem\'s `config` rung', () => {
621+
const formItem = (config: AnyRec, patch: AnyRec = {}) => ({
622+
objects: groupedObjects,
623+
views: [{ name: 'contract.edit', object: 'contract', viewKind: 'form', config, ...patch }],
624+
});
625+
626+
it('flags an unknown field and an undeclared group in `config.sections`, at the `config` path', () => {
627+
const findings = validateFormLayout(formItem({
628+
type: 'simple',
629+
sections: [{ name: 'main', fields: ['name', 'no_such_field'] }, { group: 'no_such_group' }],
630+
}));
631+
expect(findings.map((f) => [f.rule, f.path, f.where])).toEqual([
632+
[FORM_SECTION_GROUP_UNKNOWN, 'views[0].config.sections[1].group', 'view "contract.edit" · config'],
633+
[FORM_FIELD_UNKNOWN, 'views[0].config.sections[0].fields[1]', 'view "contract.edit" · config'],
634+
]);
635+
expect(findings.every((f) => f.severity === 'warning')).toBe(true);
636+
});
637+
638+
it('honors the config\'s own `data.object` binding over the item\'s `object`', () => {
639+
const findings = validateFormLayout(formItem(
640+
{ data: { provider: 'object', object: 'contract' }, sections: [{ fields: ['nope'] }] },
641+
{ object: 'not_an_object' },
642+
));
643+
expect(findings.map((f) => f.rule)).toEqual([FORM_FIELD_UNKNOWN]);
644+
});
645+
646+
it('control: a form item naming only real fields and a declared group is clean', () => {
647+
expect(validateFormLayout(formItem({
648+
type: 'simple',
649+
sections: [{ name: 'main', fields: ['name', 'amount'] }, { group: 'basics' }],
650+
}))).toEqual([]);
651+
});
652+
653+
it('control: a LIST item\'s `config` is not a form and is not walked', () => {
654+
expect(validateFormLayout(formItem(
655+
{ type: 'grid', sections: [{ fields: ['no_such_field'] }] },
656+
{ viewKind: 'list' },
657+
))).toEqual([]);
658+
});
659+
});
660+
615661
// members is the id's `os explain` entry.
616662
describe('[#22161] one-line fix — form-section-group-unknown', () => {
617663
it('a misspelt group key names the nearest declared group', () => {

‎packages/lint/src/validate-form-layout.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
*
4949
* Scope: every form view reachable from a `views[]` entry — the entry itself
5050
* when it IS a bare form view, plus the container's default `form` and each
51-
* `formViews.<key>`, through the shared `view-walk.ts` ladder (#6381; see
51+
* `formViews.<key>`, plus [#29309] a form ViewItem's `config`, through the
52+
* shared `view-walk.ts` ladder (#6381; see
5253
* {@link formViewSites} for why reading only the first shape left the rules
5354
* reporting clean on real app metadata, #6251). Forms embedded inside page
5455
* component trees are a follow-up — the walk deliberately stays shallow so it
@@ -164,7 +165,21 @@ export function validateFormLayout(stack: AnyRec): FormLayoutFinding[] {
164165
// carries for its own sites.
165166
const listBinding = isRec(view.list) ? viewObjectName(view.list) ?? containerObject : undefined;
166167

167-
for (const site of formViewSites(view, viewPath)) {
168+
// [#29309] A stored form ViewItem (`{ name, object, viewKind: 'form',
169+
// config }`, the shape Studio saves through `PUT /meta/view`) keeps its form
170+
// under `config`, a rung the shared container walk does not carry. Read
171+
// here, beside the container rungs: the runtime publish gate hands this
172+
// rule the written body as authored, so without this rung a Studio form was
173+
// judged on no save and no publish. Keyed on `viewKind: 'form'` only — a
174+
// list item's `config` is a list view and carries no sections. The rung is
175+
// this rule's, not `view-walk.ts`'s: adding it there would change the
176+
// verdicts of the other walkers, which a fix here may not do.
177+
const sites: Array<{ view: AnyRec; path: string; surface: string }> = formViewSites(view, viewPath);
178+
if (view.viewKind === 'form' && isRec(view.config)) {
179+
sites.push({ view: view.config, path: `${viewPath}.config`, surface: 'config' });
180+
}
181+
182+
for (const site of sites) {
168183
// A sub-container declares its own binding (`form.data.object`) and
169184
// otherwise inherits the container's, then the container's list-bound
170185
// object as a last resort (#16168) — the resolution order every other

‎packages/metadata-protocol/src/metadata-diagnostics.ts‎

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -433,14 +433,25 @@ export function withPublishVerdict(
433433

434434
// ---------------------------------------------------------------------------
435435
// [#29196] The lint's `form-field-unknown` on a served view's `_diagnostics`
436+
// [#29309] …and its sibling `form-section-group-unknown`
436437
// ---------------------------------------------------------------------------
437438
//
438439
// A form section naming a field its object does not have is Zod-valid, so the
439440
// schema verdict above reads `valid: true`, and the renderer skips the field.
440441
// `validateFormLayout` (`@objectstack/lint`) is the rule that says so, and it
441442
// ran only in the CLI. The view read now runs that rule on the body it serves
442443
// and puts each `form-field-unknown` finding in `_diagnostics.warnings`, with
443-
// the rule's own message: one spelling, no second rule.
444+
// the rule's own message: one spelling, no second rule. [#29309] The rule's
445+
// other finding, `form-section-group-unknown` (a section's `group` names a
446+
// field group the object does not declare, so the whole section renders
447+
// nothing), is the same silent skip and travels the same way. The objects the
448+
// lookup answers carry their `fieldGroups`, which is all that finding reads.
449+
//
450+
// Save and publish answer both findings as `advisories` on their own: the
451+
// rule is crossed to the runtime gate (`runtimeTypes: ['view']` in
452+
// `@objectstack/lint`'s `AUTHORING_RULES`). That is not a second report on
453+
// this read: the read carries no runtime advisory, only the publish verdict's
454+
// refusals (`withPublishVerdict`), and these findings are never refusals.
444455
//
445456
// A WARNING, never an error: the spec's `MetadataValidationResult` calls
446457
// warnings non-blocking, `valid` stays the schema's answer, and neither a save
@@ -458,17 +469,21 @@ export function withPublishVerdict(
458469
// rule: the kernel boot path reaches `@objectstack/lint` only through its
459470
// `/runtime` entry, and a view read is where this one is first needed.
460471

461-
/** The two names this pass reads from `@objectstack/lint`. */
472+
/** The names this pass reads from `@objectstack/lint`. */
462473
interface FormLayoutLint {
463474
validateFormLayout: (stack: Record<string, unknown>) => ReadonlyArray<{ rule: string; path: string; message: string }>;
464-
FORM_FIELD_UNKNOWN: string;
475+
/** The rule ids served on the read: `form-field-unknown`, `form-section-group-unknown`. */
476+
servedRules: ReadonlySet<string>;
465477
}
466478

467479
let formLayoutLint: Promise<FormLayoutLint | undefined> | undefined;
468480

469481
function loadFormLayoutLint(): Promise<FormLayoutLint | undefined> {
470482
formLayoutLint ??= import('@objectstack/lint').then(
471-
(lint) => ({ validateFormLayout: lint.validateFormLayout, FORM_FIELD_UNKNOWN: lint.FORM_FIELD_UNKNOWN }),
483+
(lint) => ({
484+
validateFormLayout: lint.validateFormLayout,
485+
servedRules: new Set([lint.FORM_FIELD_UNKNOWN, lint.FORM_SECTION_GROUP_UNKNOWN]),
486+
}),
472487
() => undefined,
473488
);
474489
return formLayoutLint;
@@ -480,21 +495,6 @@ function isRec(value: unknown): value is Rec {
480495
return !!value && typeof value === 'object' && !Array.isArray(value);
481496
}
482497

483-
/**
484-
* The record the lint's view walk reads for one served view body. A stored
485-
* form `ViewItem` (`viewKind: 'form'`) keeps its form under `config`, a rung
486-
* the walk does not descend (it reads `views[]` entries as authored), so it is
487-
* handed over as the container shape the walk does read: the item's `config`
488-
* as the default `form`, bound to the item's `object`. Every other shape (a
489-
* view container, a flattened form overlay) is the walk's own input already.
490-
*/
491-
function formLayoutSubject(view: Rec): { subject: Rec; formKey: 'config' | 'form' } {
492-
if (view.viewKind === 'form' && isRec(view.config)) {
493-
return { subject: { name: view.name, object: view.object, form: view.config }, formKey: 'config' };
494-
}
495-
return { subject: view, formKey: 'form' };
496-
}
497-
498498
/** Every object name the body spells (`object` / `objectName`), at any depth. */
499499
function spelledObjectNames(value: unknown, into: Set<string>, depth = 0): Set<string> {
500500
if (depth > 16) return into;
@@ -510,8 +510,8 @@ function spelledObjectNames(value: unknown, into: Set<string>, depth = 0): Set<s
510510
}
511511

512512
/**
513-
* Add the lint's `form-field-unknown` warnings to a served view's
514-
* `_diagnostics`. Returns `served` itself when there is nothing to add.
513+
* Add the lint's `form-field-unknown` and `form-section-group-unknown`
514+
* warnings to a served view's `_diagnostics`. Returns `served` itself when there is nothing to add.
515515
*
516516
* `getObject` is the door's own object lookup; an object it does not answer
517517
* is not judged.
@@ -524,18 +524,20 @@ export async function withFormLayoutWarnings<T>(
524524
if ((PLURAL_TO_SINGULAR[type] ?? type) !== 'view' || !isRec(served) || !getObject) return served;
525525
const lint = await loadFormLayoutLint();
526526
if (!lint) return served;
527-
const { subject, formKey } = formLayoutSubject(served);
527+
// [#29309] The served body is the rule's input as it is: the rule reads a
528+
// form `ViewItem`'s `config` rung itself, the same walk the save and
529+
// publish gate runs, so the read needs no adapter of its own.
528530
const objects: Rec[] = [];
529-
for (const name of spelledObjectNames(subject, new Set())) {
531+
for (const name of spelledObjectNames(served, new Set())) {
530532
const object = getObject(name);
531533
if (isRec(object)) objects.push({ ...object, name });
532534
}
533535
if (objects.length === 0) return served;
534536
const name = typeof served.name === 'string' ? served.name : '';
535-
const warnings = lint.validateFormLayout({ objects, views: [subject] })
536-
.filter((finding) => finding.rule === lint.FORM_FIELD_UNKNOWN)
537+
const warnings = lint.validateFormLayout({ objects, views: [served] })
538+
.filter((finding) => lint.servedRules.has(finding.rule))
537539
.map((finding) => ({
538-
path: itemRelativeIssuePath('view', name, finding.path).replace(/^form(?=\.|$)/, formKey),
540+
path: itemRelativeIssuePath('view', name, finding.path),
539541
message: finding.message,
540542
}));
541543
if (warnings.length === 0) return served;

0 commit comments

Comments
 (0)