Skip to content

Commit f233f22

Browse files
committed
test(metadata-protocol): a form member carries no label or name; enumerate a named variant only where the member's schema declares name
The save door refuses `label` and `name` on a form view, so the probes and the packaged form fixtures carry neither, and the member-kind derivation offers a named variant only for a slot whose own schema declares `name`. Claude-Session: https://claude.ai/code/session_017xfMoEjKUuSh2xYB8sCozp Co-authored-by: Claude <noreply@anthropic.com>
1 parent fbc2b95 commit f233f22

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

‎packages/metadata-protocol/src/view-container-runtime-expansion.test.ts‎

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,9 @@ describe('#21334 a container on another package\'s object never takes that packa
441441
listViews: {
442442
in_progress: { label: 'In Progress', type: 'grid', data, columns: PACKAGED_COLUMNS.slice(0, 4) },
443443
},
444-
form: { label: 'Task Form', type: 'simple', sections: [{ label: 'Main', fields: ['title'] }] },
444+
form: { type: 'simple', sections: [{ label: 'Main', fields: ['title'] }] },
445445
formViews: {
446-
edit: { label: 'Edit Task', type: 'simple', sections: [{ label: 'Edit', fields: ['title', 'status'] }] },
446+
edit: { type: 'tabbed', sections: [{ label: 'Edit', fields: ['title', 'status'] }] },
447447
},
448448
};
449449
const PACKAGED = expandViewContainer(TASK, packagedTaskViews).map((vi) => ({ ...(vi as any) }));
@@ -561,18 +561,29 @@ describe('#21334 a container on another package\'s object never takes that packa
561561
* Every member kind the spec's expander places, derived FROM the expander:
562562
* each top-level key of the container schema is offered a single view and a
563563
* record of views, and a key that yields an expanded item is a member kind.
564-
* A single-view member is enumerated twice — bare, and naming its own key.
565-
* A kind the spec adds later shows up here, and the enumeration below fails
566-
* until it is placed.
564+
* A single-view member is enumerated twice — bare, and naming its own key —
565+
* when its own schema declares `name` (a `list` does; a `form` does not, so
566+
* a named `form` is not authorable). A kind the spec adds later shows up
567+
* here, and the enumeration below fails until it is placed.
567568
*/
568569
function memberKindsOfTheExpander(): string[] {
569-
const slots = Object.keys((ViewSchema as unknown as { shape?: Record<string, unknown> }).shape ?? {});
570+
const shape = (ViewSchema as unknown as { shape?: Record<string, unknown> }).shape ?? {};
571+
const slots = Object.keys(shape);
570572
expect(slots.length, 'the container schema\'s own keys are readable').toBeGreaterThan(0);
573+
const declaresName = (schema: unknown): boolean => {
574+
let s: any = schema;
575+
for (let i = 0; i < 6 && s; i++) {
576+
if (s.shape) return 'name' in s.shape;
577+
s = s._zod?.def?.innerType ?? s._def?.innerType ?? (typeof s.unwrap === 'function' ? s.unwrap() : undefined);
578+
}
579+
return false;
580+
};
571581
const view = { type: 'grid', label: 'probe' };
572582
const kinds: string[] = [];
573583
for (const slot of slots) {
574584
if (expandViewContainer('o', { [slot]: { ...view } }).length > 0) {
575-
kinds.push(slot, `${slot}#named`);
585+
kinds.push(slot);
586+
if (declaresName(shape[slot])) kinds.push(`${slot}#named`);
576587
} else if (expandViewContainer('o', { [slot]: { k: { ...view } } }).some((vi) => vi.name === 'o.k')) {
577588
kinds.push(`${slot}.*`);
578589
}
@@ -582,7 +593,7 @@ describe('#21334 a container on another package\'s object never takes that packa
582593

583594
const OWN = 'os_qa_probe';
584595
const listView = { type: 'grid', columns: ['title', 'status'] };
585-
const formView = { label: 'Probe Form', type: 'simple', sections: [{ label: 'Probe', fields: ['title'] }] };
596+
const formView = { type: 'simple', sections: [{ label: 'Probe', fields: ['title'] }] };
586597
/**
587598
* One case per member kind: a container on `showcase_task` with ONLY that
588599
* member, whose key aims at a name the showcase ships, and the one name the
@@ -599,10 +610,6 @@ describe('#21334 a container on another package\'s object never takes that packa
599610
shadows: `${TASK}.in_progress`, servedAs: `${TASK}.${OWN}.in_progress`,
600611
},
601612
form: { member: { form: formView }, authored: formView, shadows: `${TASK}.form`, servedAs: `${TASK}.${OWN}.form` },
602-
'form#named': {
603-
member: { form: { ...formView, name: 'edit' } }, authored: { ...formView, name: 'edit' },
604-
shadows: `${TASK}.edit`, servedAs: `${TASK}.${OWN}.edit`,
605-
},
606613
'formViews.*': {
607614
member: { formViews: { edit: formView } }, authored: formView,
608615
shadows: `${TASK}.edit`, servedAs: `${TASK}.${OWN}.edit`,

0 commit comments

Comments
 (0)