Skip to content

Commit 3d5933a

Browse files
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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol): the layered read of a form view naming a field its object lacks now carries the form-field-unknown warning
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`GET /api/v1/meta/view/NAME?layers=true` judged its `_diagnostics` with the schema alone, so a published form view whose section names a missing field (or an undeclared field group) read `{ valid: true }` there, while `GET /api/v1/meta/view/NAME` of the same view carried the lint's warning. Studio's item editor reads the layered answer when no draft is pending, so the author of a published form view saw no warning.
11+
12+
The layered read now runs the same form-layout pass on its `effective` body that the single-item read runs, against the object the registry serves for each name the view spells. The warnings land at the same paths, and `valid` stays the schema's answer. A form naming only real fields still reads `{ valid: true }`.

‎packages/metadata-protocol/src/protocol-meta-layered-reads.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
storedRowDocument,
4141
withItemLockFamily,
4242
} from './item-lock.js';
43-
import { type MetadataDiagnostics, computeMetadataDiagnostics } from './metadata-diagnostics.js';
43+
import { type MetadataDiagnostics, computeMetadataDiagnostics, withFormLayoutWarnings } from './metadata-diagnostics.js';
4444
import { redactMetadataItem } from './metadata-redaction.js';
4545
import { overlayMemberWhere } from './migrations/overlay-index.js';
4646
import {
@@ -507,10 +507,24 @@ export async function getMetaItemLayered(host: Pick<ProtocolHost, 'artifactLockL
507507
itemLock,
508508
);
509509

510-
const _diagnostics =
510+
const schemaDiagnostics =
511511
effective !== null && effective !== undefined
512512
? computeMetadataDiagnostics(request.type, effective)
513513
: undefined;
514+
// [#29435] …plus the form-layout warnings `getMetaItem` serves for the
515+
// same effective body ({@link withFormLayoutWarnings}: `form-field-unknown`
516+
// and `form-section-group-unknown`, judged against the object the registry
517+
// serves for each name the view spells). Warnings only, so `valid` stays
518+
// the schema's answer. This door has no execution face: it is the
519+
// `?layers=true` authoring read, the one Studio's item editor takes when
520+
// no draft is pending, so the pass runs unconditionally here.
521+
const _diagnostics = effective !== null && typeof effective === 'object' && !Array.isArray(effective)
522+
? (await withFormLayoutWarnings(
523+
request.type,
524+
{ ...(effective as Record<string, unknown>), _diagnostics: schemaDiagnostics },
525+
(name) => host.engine?.registry?.getObject?.(name),
526+
))._diagnostics as MetadataDiagnostics | undefined
527+
: schemaDiagnostics;
514528

515529
// ADR-0010 — surface lock/provenance flags so the Studio editor
516530
// can render the correct affordances without a second round trip.

‎packages/metadata-protocol/src/protocol.form-layout-diagnostics.test.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ function makeStubEngine() {
168168
listItems: (type: string) => (type === 'object' ? [servedTask] : []),
169169
// The read path's resolver: the SERVED object, extensions folded on.
170170
getObject: (name: string) => (name === 'task' ? servedTask : undefined),
171+
// [#29435] The layered read's code layer: no package ships these
172+
// views, so every one is a stored row with no code layer.
173+
getItem: () => undefined,
171174
getPackage: (id: string) => (id === PKG ? { manifest: { id: PKG } } : undefined),
172175
},
173176
};
@@ -454,3 +457,56 @@ describe('a form ViewItem is judged on save and publish too (#29309)', () => {
454457
expect(await readDiagnostics(protocol, item.name, 'active')).toEqual({ valid: true });
455458
});
456459
});
460+
461+
// ---------------------------------------------------------------------------
462+
// #29435 — the layered read (`?layers=true`) of the same form view.
463+
//
464+
// Measured on `origin/main` `7dae3b3c` before the fix: `getMetaItemLayered`
465+
// computed its `_diagnostics` with `computeMetadataDiagnostics` alone, so a
466+
// published form view naming `no_such_field` read `{ valid: true }` there
467+
// while `getMetaItem` of the same item carried the `form-field-unknown`
468+
// warning. Studio's Interfaces pillar and item editor read the layered answer
469+
// when no draft is pending.
470+
// ---------------------------------------------------------------------------
471+
472+
async function readLayeredDiagnostics(protocol: ObjectStackProtocolImplementation, name: string) {
473+
const read: any = await protocol.getMetaItemLayered({ type: 'view', name, packageId: PKG });
474+
return read._diagnostics as Diagnostics;
475+
}
476+
477+
describe('the layered read of a form view carries the same form-layout warnings (#29435)', () => {
478+
let warn: ReturnType<typeof vi.spyOn>;
479+
beforeEach(() => {
480+
warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
481+
});
482+
afterEach(() => {
483+
warn.mockRestore();
484+
});
485+
486+
it('a published form view naming an unknown field warns at the same path as getMetaItem', async () => {
487+
const { engine } = makeStubEngine();
488+
const protocol = new ObjectStackProtocolImplementation(engine);
489+
const item = formItem('task.form', 'task', ['title', 'no_such_field']);
490+
const expected = lintMessages(item, servedTask);
491+
expect(expected).toHaveLength(1);
492+
493+
await (protocol as any).saveMetaItem({ type: 'view', name: item.name, item, packageId: PKG, mode: 'draft' });
494+
await protocol.publishMetaItem({ type: 'view', name: item.name, packageId: PKG } as any);
495+
496+
const single = await readDiagnostics(protocol, item.name, 'active');
497+
const layered = await readLayeredDiagnostics(protocol, item.name);
498+
expect(layered).toEqual({ valid: true, warnings: [{ path: 'config.sections.0.fields.1', message: expected[0] }] });
499+
expect(layered).toEqual(single);
500+
});
501+
502+
it('control: a published form naming only real fields (an extension field among them) reads { valid: true } with no warnings', async () => {
503+
const { engine } = makeStubEngine();
504+
const protocol = new ObjectStackProtocolImplementation(engine);
505+
const item = formItem('task.form', 'task', ['title', 'status', 'region__c']);
506+
507+
await (protocol as any).saveMetaItem({ type: 'view', name: item.name, item, packageId: PKG, mode: 'draft' });
508+
await protocol.publishMetaItem({ type: 'view', name: item.name, packageId: PKG } as any);
509+
510+
expect(await readLayeredDiagnostics(protocol, item.name)).toEqual({ valid: true });
511+
});
512+
});

0 commit comments

Comments
 (0)