Skip to content

Commit 469499e

Browse files
committed
test(ui): re-point the cbp master oracle legs to the optional master
Under ADR-0055 §1 as amended (ruling A), the spec reads an object's only master_detail that is not required as an optional master: a cbp object whose lone master_detail omits `required` now parses, as required: false. Five app-shell tests used that shape as a refused control. - Four control legs (object-fields-io, ObjectFieldInspector, ObjectSettingsPanel, PackageOwdOverviewPanel save): the shape parses with required: false before Studio writes required: true, and with required: true after. - Two display-agreement rows (owd-sharing deriveMasterObject, PackageOwdOverviewPanel shapes): the omitted row records that the parse admits it while the reader names no master, as the runtime does for an unparsed object. Test-only; Studio source unchanged. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cxZsyeZedvM4Ea8Ahs
1 parent fd6d188 commit 469499e

5 files changed

Lines changed: 87 additions & 29 deletions

File tree

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.cbpRequiredMaster-12326.test.tsx‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
*
88
* Since `@objectstack/spec` 18 (objectstack#23100, ADR-0055 §1) such an object
99
* derives its master from exactly one `master_detail` declared
10-
* `required: true`; the save door refuses any other value. The installed
11-
* spec's `ObjectSchema` is the oracle for the object each edit leaves behind.
10+
* `required: true`. Since ADR-0055 §1 as amended (objectstack#30905 ruling A)
11+
* the spec also reads an object's only `master_detail` that is not required as
12+
* an OPTIONAL master, whose rows may name none; the designer keeps writing
13+
* `required: true`, so the master it shows is one every row names. The
14+
* installed spec's `ObjectSchema` is the oracle for the object each edit
15+
* leaves behind.
1216
*/
1317

1418
import '@testing-library/jest-dom/vitest';
@@ -104,13 +108,19 @@ describe('ObjectFieldInspector — a controlled_by_parent master is required, lo
104108
},
105109
'account',
106110
);
107-
expect(ObjectSchema.safeParse(object()).success).toBe(false);
111+
// The control leg: as stored, the spec reads this master as optional —
112+
// it parses, as `required: false`.
113+
const before = ObjectSchema.safeParse(object());
114+
expect(before.success).toBe(true);
115+
expect((before.data?.fields as Record<string, { required?: boolean }>).account.required).toBe(false);
108116
expect(requiredBox()).not.toBeChecked();
109117
expect(requiredBox()).toBeEnabled();
110118
fireEvent.click(requiredBox());
111119
expect(field().required).toBe(true);
112120
expect(requiredBox()).toBeDisabled();
113-
expect(ObjectSchema.safeParse(object()).success).toBe(true);
121+
const after = ObjectSchema.safeParse(object());
122+
expect(after.success).toBe(true);
123+
expect((after.data?.fields as Record<string, { required?: boolean }>).account.required).toBe(true);
114124
});
115125

116126
it('outside controlled_by_parent the box stays free and no reason is shown', () => {

‎ui/packages/app-shell/src/views/metadata-admin/previews/object-fields-io.test.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,11 @@ describe('toFieldNameLoose (prefix-stable — for live keystroke input)', () =>
392392
/**
393393
* objectui#12326 — a master-detail field starts required. Added to a
394394
* `controlled_by_parent` object, it is the one required `master_detail` the
395-
* installed spec derives the master from (ADR-0055 §1); without `required` the
396-
* same object is refused. The spec's `ObjectSchema` is the oracle.
395+
* installed spec derives the master from (ADR-0055 §1). Without `required` the
396+
* spec reads that field as an OPTIONAL master (ADR-0055 §1 as amended,
397+
* objectstack#30905 ruling A: a row may name none), so the `required: true`
398+
* this writes is what keeps every row naming its master. The spec's
399+
* `ObjectSchema` is the oracle.
397400
*/
398401
describe('newField — a master-detail field starts required (objectui#12326)', () => {
399402
const cbpObject = (def: Record<string, unknown>) => ({
@@ -406,9 +409,12 @@ describe('newField — a master-detail field starts required (objectui#12326)',
406409
const { def } = newField('account', 'master_detail');
407410
expect(def.required).toBe(true);
408411
expect(ObjectSchema.safeParse(cbpObject(def)).success).toBe(true);
409-
// The control leg: the same field without `required` is refused.
412+
// The control leg: the same field without `required` is read as an
413+
// optional master — it parses, as `required: false`.
410414
const { required: _omitted, ...withoutRequired } = def;
411-
expect(ObjectSchema.safeParse(cbpObject(withoutRequired)).success).toBe(false);
415+
const control = ObjectSchema.safeParse(cbpObject(withoutRequired));
416+
expect(control.success).toBe(true);
417+
expect((control.data?.fields as Record<string, { required?: boolean }>).account.required).toBe(false);
412418
});
413419

414420
it('leaves every other type without required', () => {

‎ui/packages/app-shell/src/views/studio-design/ObjectSettingsPanel.cbpRequiredMaster-12326.test.tsx‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
*
77
* Since `@objectstack/spec` 18 (objectstack#23100, ADR-0055 §1) a
88
* `controlled_by_parent` object derives its master from exactly one
9-
* `master_detail` field declared `required: true`, and the save door refuses
10-
* any other shape. The designer forces the value: the pick writes
11-
* `required: true` on the master in the same patch. With two or more
12-
* `master_detail` fields it picks none for the author, and shows the spec's own
13-
* refusal, which names the fix.
9+
* `master_detail` field declared `required: true`. Since ADR-0055 §1 as
10+
* amended (objectstack#30905 ruling A) the spec also reads an object's only
11+
* `master_detail` that is not required as an OPTIONAL master, whose rows may
12+
* name none. The designer forces the value: the pick writes `required: true`
13+
* on the master in the same patch, so every row names its master. With two or
14+
* more `master_detail` fields it picks none for the author, and shows the
15+
* spec's own refusal, which names the fix.
1416
*
1517
* The installed spec's `ObjectSchema` is the oracle: the object the patch
1618
* leaves behind is parsed as the save door parses it.
@@ -54,8 +56,11 @@ const TWO_MASTERS = {
5456
describe('ObjectSettingsPanel — controlled_by_parent forces the master required (objectui#12326)', () => {
5557
it('choosing it with one non-required master writes required: true, and the object parses', async () => {
5658
const draft = { name: 'crm_case', sharingModel: 'private', fields: ONE_MASTER };
57-
// The control leg: as the draft stands, switching only the model is refused.
58-
expect(ObjectSchema.safeParse({ ...draft, sharingModel: 'controlled_by_parent' }).success).toBe(false);
59+
// The control leg: as the draft stands, switching only the model leaves an
60+
// optional master — it parses, as `required: false`.
61+
const control = ObjectSchema.safeParse({ ...draft, sharingModel: 'controlled_by_parent' });
62+
expect(control.success).toBe(true);
63+
expect((control.data?.fields as Record<string, { required?: boolean }>).account.required).toBe(false);
5964

6065
const { onPatch } = renderPanel(draft);
6166
await pickSharing(CBP_LABEL);
@@ -69,7 +74,9 @@ describe('ObjectSettingsPanel — controlled_by_parent forces the master require
6974
account: { type: 'master_detail', label: 'Account', reference: 'crm_account', required: true },
7075
},
7176
});
72-
expect(ObjectSchema.safeParse({ ...draft, ...patch }).success).toBe(true);
77+
const parsed = ObjectSchema.safeParse({ ...draft, ...patch });
78+
expect(parsed.success).toBe(true);
79+
expect((parsed.data?.fields as Record<string, { required?: boolean }>).account.required).toBe(true);
7380
});
7481

7582
it('writes only the model when the master is already required', async () => {

‎ui/packages/app-shell/src/views/studio-design/PackageOwdOverviewPanel.cbpRequiredMaster-12326.test.tsx‎

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
* `controlled_by_parent` sets `required: true` on its `master_detail` fields in
1111
* the saved draft, as the per-object Settings tab does. The installed spec's
1212
* `ObjectSchema` is the oracle for the saved body.
13+
*
14+
* ADR-0055 §1 as amended (objectstack#30905 ruling A) adds an OPTIONAL master:
15+
* an object's only `master_detail` declared `required: false`. The parse cannot
16+
* tell an omitted `required` from `false`, so it admits the omitted shape too.
17+
* This overview still names none for an omitted `required`, as the runtime
18+
* does for an object that reaches it unparsed (it reads `required: false`
19+
* literally, never its absence), and that row records the parse's answer
20+
* apart from the master shown.
1321
*/
1422

1523
import '@testing-library/jest-dom/vitest';
@@ -54,9 +62,16 @@ afterEach(cleanup);
5462
const cbp = (fields: Body): Body => ({ name: 'crm_case', label: 'Case', sharingModel: 'controlled_by_parent', fields });
5563

5664
describe('PackageOwdOverviewPanel — the master shown is the one the runtime derives (objectui#12326)', () => {
57-
const SHAPES: Array<[string, Body, string | undefined]> = [
65+
// [label, fields, the master shown, whether the spec parse accepts it when
66+
// that differs from "a master is shown"]
67+
const SHAPES: Array<[string, Body, string | undefined, boolean?]> = [
5868
['one required master', { account: { type: 'master_detail', reference: 'crm_account', required: true } }, 'crm_account'],
59-
['one master without required', { account: { type: 'master_detail', reference: 'crm_account' } }, undefined],
69+
[
70+
'one master without required (the parse reads it as an optional master; no master is shown)',
71+
{ account: { type: 'master_detail', reference: 'crm_account' } },
72+
undefined,
73+
true,
74+
],
6075
[
6176
'two required masters',
6277
{
@@ -67,9 +82,10 @@ describe('PackageOwdOverviewPanel — the master shown is the one the runtime de
6782
],
6883
];
6984

70-
it.each(SHAPES)('%s', async (_label, fields, master) => {
71-
// The oracle: the spec accepts exactly the shapes a master is shown for.
72-
expect(ObjectSchema.safeParse(cbp(fields)).success).toBe(master !== undefined);
85+
it.each(SHAPES)('%s', async (_label, fields, master, parses) => {
86+
// The oracle: the spec accepts the shapes a master is shown for, and the
87+
// one row that says otherwise.
88+
expect(ObjectSchema.safeParse(cbp(fields)).success).toBe(parses ?? master !== undefined);
7389
renderPanel({ crm_case: cbp(fields) });
7490
const cell = await screen.findByTestId('owd-master-crm_case');
7591
expect(cell).toHaveTextContent(
@@ -86,8 +102,11 @@ describe('PackageOwdOverviewPanel — switching a row to controlled_by_parent (o
86102
sharingModel: 'private',
87103
fields: { account: { type: 'master_detail', reference: 'crm_account' } },
88104
};
89-
// The control leg: switching only the model is refused.
90-
expect(ObjectSchema.safeParse({ ...body, sharingModel: 'controlled_by_parent' }).success).toBe(false);
105+
// The control leg: switching only the model leaves an optional master —
106+
// it parses, as `required: false`.
107+
const control = ObjectSchema.safeParse({ ...body, sharingModel: 'controlled_by_parent' });
108+
expect(control.success).toBe(true);
109+
expect((control.data?.fields as Record<string, { required?: boolean }>).account.required).toBe(false);
91110

92111
const { saved } = renderPanel({ crm_case: body });
93112
await screen.findByTestId('owd-row-crm_case');
@@ -103,7 +122,9 @@ describe('PackageOwdOverviewPanel — switching a row to controlled_by_parent (o
103122
await waitFor(() => expect(saved.length).toBe(1));
104123
expect(saved[0].body.sharingModel).toBe('controlled_by_parent');
105124
expect((saved[0].body.fields as Record<string, Body>).account.required).toBe(true);
106-
expect(ObjectSchema.safeParse(saved[0].body).success).toBe(true);
125+
const parsed = ObjectSchema.safeParse(saved[0].body);
126+
expect(parsed.success).toBe(true);
127+
expect((parsed.data?.fields as Record<string, { required?: boolean }>).account.required).toBe(true);
107128
});
108129

109130
it('a row with two master-detail fields shows no master before the save', async () => {

‎ui/packages/app-shell/src/views/studio-design/owd-sharing.test.ts‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,29 @@ describe('owd-sharing — deriveMasterObject', () => {
4646
* the master, and any other shape names none. The installed spec's
4747
* `ObjectSchema` is the oracle for which shapes the platform accepts: every
4848
* shape this reader names a master for parses as a `controlled_by_parent`
49-
* object, and every shape it names none for is refused.
49+
* object, and every shape it names none for is refused, with one exception.
50+
*
51+
* ADR-0055 §1 as amended (objectstack#30905 ruling A) adds an OPTIONAL master:
52+
* an object's only `master_detail` declared `required: false`. The parse cannot
53+
* tell an omitted `required` from `false`, so it admits the omitted shape too,
54+
* while this reader names none for it, as the runtime does for an object that
55+
* reaches it unparsed (it reads `required: false` literally, never its
56+
* absence). That row records the parse's answer apart from the master named.
5057
*/
5158
describe('owd-sharing — deriveMasterObject agrees with the runtime (objectui#12326)', () => {
5259
const asCbp = (fields: Record<string, unknown>) =>
5360
ObjectSchema.safeParse({ name: 'crm_case', sharingModel: 'controlled_by_parent', fields }).success;
5461

55-
const SHAPES: Array<[string, Record<string, unknown>, string | undefined]> = [
62+
// [label, fields, the master named, whether the spec parse accepts it when
63+
// that differs from "a master is named"]
64+
const SHAPES: Array<[string, Record<string, unknown>, string | undefined, boolean?]> = [
5665
['one required master', { account: { type: 'master_detail', reference: 'crm_account', required: true } }, 'crm_account'],
57-
['one master without required', { account: { type: 'master_detail', reference: 'crm_account' } }, undefined],
66+
[
67+
'one master without required (the parse reads it as an optional master; this reader names none)',
68+
{ account: { type: 'master_detail', reference: 'crm_account' } },
69+
undefined,
70+
true,
71+
],
5872
[
5973
'two required masters',
6074
{
@@ -75,9 +89,9 @@ describe('owd-sharing — deriveMasterObject agrees with the runtime (objectui#1
7589
['no relationship field', { subject: { type: 'text' } }, undefined],
7690
];
7791

78-
it.each(SHAPES)('%s', (_label, fields, master) => {
92+
it.each(SHAPES)('%s', (_label, fields, master, parses) => {
7993
expect(deriveMasterObject(fields)).toBe(master);
80-
expect(asCbp(fields)).toBe(master !== undefined);
94+
expect(asCbp(fields)).toBe(parses ?? master !== undefined);
8195
});
8296
});
8397

0 commit comments

Comments
 (0)