Skip to content

Commit a44242e

Browse files
committed
test: re-judge the reverse pins and save fixtures the closed view door moves
STILL_STRIP empties now that the registered view schema is closed; the authoring lint's view divergence pin asserts the refusal instead of the old strip finding; the save-path fixtures that froze a dropped undeclared key now pin its refusal by name. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufziYCUHZQE3MXucvWe9
1 parent efe9bc1 commit a44242e

3 files changed

Lines changed: 108 additions & 47 deletions

File tree

‎packages/metadata-protocol/src/protocol.graft-folded-form-sections.test.ts‎

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,25 @@ async function storedViewBody(name: string, item: unknown): Promise<any> {
148148
return JSON.parse(row!.metadata);
149149
}
150150

151+
/**
152+
* [#26711] Save a view the door refuses: the 422 envelope, NO row written, and
153+
* the `unrecognized_keys` issue the claimed member raised for the undeclared keys.
154+
*/
155+
async function refusedUndeclared(item: Record<string, unknown>): Promise<{ message: string }> {
156+
const { protocol, rows } = makeProtocol();
157+
let err: any;
158+
try {
159+
await (protocol as any).saveMetaItem({ type: 'view', name: item.name as string, item });
160+
} catch (e) { err = e; }
161+
expect(err?.code).toBe('INVALID_METADATA');
162+
expect(err?.status).toBe(422);
163+
expect(Array.from(rows.values()).filter((r) => r.type === 'view')).toHaveLength(0);
164+
const issue = (err.issues as Array<{ code?: string; message: string }>)
165+
.find((i) => i.code === 'unrecognized_keys');
166+
expect(issue, JSON.stringify(err.issues)).toBeDefined();
167+
return { message: issue!.message };
168+
}
169+
151170
/** The one section every fixture below declares, in the authored spelling. */
152171
const SECTION = { label: 'About you', fields: ['name', 'email'] };
153172
const SHARING = { allowAnonymous: true, publicLink: '/forms/contact-us' };
@@ -214,22 +233,23 @@ describe('#7134 the save path persists the folded `sections`, at every depth a f
214233
expect(body).not.toHaveProperty('groups');
215234
});
216235

217-
it('[#20051] the fold and the form overlay\'s declared keys coexist on one save; its undeclared ones do not', async () => {
218-
// Re-judged at stage (iv) of #20051, which stores a view's parsed
219-
// body. The fold is stored, and so is `isDefault`, which the flattened
220-
// FORM overlay declares. `isPinned` and `sortOrder` are the list
221-
// switcher's row state: the form member declares neither and the
222-
// console writes neither on a form row (`VIEW_CONSOLE_ROUND_TRIP_KEYS`
223-
// maps no key to `formOverlay`), so the stored row drops both.
224-
const body = await storedViewBody(
225-
'contact_us',
226-
flatForm({ groups: [SECTION], isPinned: true, isDefault: false, sortOrder: 3 }),
227-
);
236+
it('[#26711] the fold and the form overlay\'s declared keys coexist on one save; its undeclared ones are refused by name', async () => {
237+
// Re-judged twice. At stage (iv) of #20051, which stores a view's parsed
238+
// body, the undeclared keys were dropped from the row on a `200`. Since
239+
// #26711 the form member is closed, so they are refused. The fold is
240+
// stored, and so is `isDefault`, which the flattened FORM overlay
241+
// declares. `isPinned` and `sortOrder` are the list switcher's row
242+
// state: the form member declares neither and the console writes
243+
// neither on a form row (`VIEW_CONSOLE_ROUND_TRIP_KEYS` maps no key to
244+
// `formOverlay`).
245+
const body = await storedViewBody('contact_us', flatForm({ groups: [SECTION], isDefault: false }));
228246
expect(body.sections).toEqual([SECTION]);
229247
expect(body).not.toHaveProperty('groups');
230248
expect(body.isDefault).toBe(false);
231-
expect(body).not.toHaveProperty('isPinned');
232-
expect(body).not.toHaveProperty('sortOrder');
249+
const refusal = await refusedUndeclared(
250+
flatForm({ groups: [SECTION], isPinned: true, isDefault: false, sortOrder: 3 }),
251+
);
252+
expect(refusal.message).toMatch(/^Unrecognized key\(s\) on this inline form view: `isPinned`, `sortOrder`\./);
233253
});
234254
});
235255

@@ -258,22 +278,22 @@ describe('#7134 what the save path must NOT change', () => {
258278
expect(await storedViewBody(authored.name, authored)).toEqual(authored);
259279
});
260280

261-
it('[#20051] a form authored with canonical `sections` is stored as authored — no section default, no `sharing.enabled`, no undeclared key', async () => {
281+
it('[#20051] a form authored with canonical `sections` is stored as authored — no section default, no `sharing.enabled`', async () => {
262282
// Re-judged at stage (iv): was "stored byte-identical", with an
263-
// `isPinned` the form member does not declare riding along. The parse
264-
// adds `collapsible` / `collapsed` to the section and `enabled: false`
265-
// to `sharing`; ruling B stores none of them (ADR-0087's `storable`
266-
// rule), and the undeclared `isPinned` is dropped. A section's `columns`
267-
// has no default: undeclared, the parse adds no key (the renderer picks
268-
// the density by available width).
269-
const authored = flatForm({ sections: [SECTION], isPinned: true });
283+
// `isPinned` the form member does not declare riding along, which the
284+
// row then dropped. The parse adds `collapsible` / `collapsed` to the
285+
// section and `enabled: false` to `sharing`; ruling B stores none of
286+
// them (ADR-0087's `storable` rule). A section's `columns` has no
287+
// default: undeclared, the parse adds no key (the renderer picks the
288+
// density by available width). [#26711] The undeclared `isPinned` is
289+
// now refused by name (the test above), so the fixture no longer
290+
// carries it and the row is the body as authored.
291+
const authored = flatForm({ sections: [SECTION] });
270292
const parsed = (ViewMetadataSchema as any).parse(authored);
271293
expect(parsed.sections[0]).toMatchObject({ collapsible: false, collapsed: false });
272294
expect('columns' in parsed.sections[0]).toBe(false);
273295
expect(parsed.sharing.enabled).toBe(false);
274-
const body = await storedViewBody('contact_us', authored);
275-
const { isPinned: _dropped, ...declared } = authored as Record<string, unknown>;
276-
expect(body).toEqual(declared);
296+
expect(await storedViewBody('contact_us', authored)).toEqual(authored);
277297
});
278298

279299
it('GUARD: a LIST overlay is untouched — this walk is form-shaped only', async () => {
@@ -511,7 +531,10 @@ describe('#20186 the save door judges a flattened overlay by the member its view
511531
});
512532

513533
it('a column-less list overlay that names a `type`: 422 at `columns`, with the prescription', async () => {
514-
const issue = at(await refused({ ...LIST, type: 'kanban', groupByField: 'stage' }), 'columns');
534+
// [#26711] The kanban setting goes where the list view declares it: a
535+
// top-level `groupByField` is now refused as an unknown key, before
536+
// the column check runs.
537+
const issue = at(await refused({ ...LIST, type: 'kanban', kanban: { groupByField: 'stage', columns: ['name'] } }), 'columns');
515538
expect(issue.code).toBe('custom');
516539
expect(issue.message).toMatch(/^This list view overlay sets `type` but lists no `columns`\./);
517540
});
@@ -583,9 +606,14 @@ describe('[#20051] stage (iv): a saved view stores the parsed value of every key
583606
expect(stored.sort).toEqual([{ field: 'name', order: 'desc' }]);
584607
});
585608

586-
it('an undeclared key is dropped: the saved-view toolbar toggle\'s `id` / `objectName`, and a form-only `layout`', async () => {
587-
// W6b's shape: `buildPersistedViewBody`'s saved-view branch writes the
588-
// whole tab back, and the tab carries `id` and `objectName`.
609+
it('[#26711] an undeclared key is refused by name: a saved-view tab\'s `id` / `objectName`, and a form-only `layout`', async () => {
610+
// W6b's shape: `buildPersistedViewBody`'s saved-view branch wrote the
611+
// whole tab back, and the tab carried `id` and `objectName`. At stage
612+
// (iv) the row dropped them on a `200`; since #26711 the list member is
613+
// closed and the save is refused, naming each key and pointing the two
614+
// alias spellings at the declared ones. The console no longer writes
615+
// this shape: `buildViewConfigSaveBody` copies only the list view's
616+
// declared keys under the ViewItem envelope.
589617
const declared = {
590618
name: 'crm_lead.my_leads',
591619
object: 'crm_lead',
@@ -596,10 +624,12 @@ describe('[#20051] stage (iv): a saved view stores the parsed value of every key
596624
data: { provider: 'object', object: 'crm_lead' },
597625
isDefault: false,
598626
};
599-
const stored = await storedViewBody(declared.name, {
627+
expect(await storedViewBody(declared.name, declared)).toEqual(declared);
628+
const refusal = await refusedUndeclared({
600629
...declared, id: 'crm_lead.my_leads', objectName: 'crm_lead', layout: 'diagonal',
601630
});
602-
expect(stored).toEqual(declared);
631+
expect(refusal.message).toMatch(/^Unrecognized key\(s\) on this inline list view: `id`, `objectName`, `layout`\./);
632+
expect(refusal.message).toContain('Did you mean `id` → `name`, `objectName` → `object`?');
603633
});
604634

605635
it('a declared key keeps its normalised value', async () => {
@@ -641,7 +671,7 @@ describe('[#20051] stage (iv): a saved view stores the parsed value of every key
641671
it('the persisted body parses to exactly what the save parsed', async () => {
642672
const bodies: Array<Record<string, unknown>> = [
643673
...TOOLBAR_SAVES.map(([, patch]) => ({ ...patch, ...OVERLAY_ID })),
644-
flatForm({ groups: [SECTION], isPinned: true }),
674+
flatForm({ groups: [SECTION], isDefault: true }),
645675
{
646676
name: 'lead.contact_us', object: 'lead', viewKind: 'form', label: 'Contact us',
647677
config: { type: 'simple', data: DATA, sharing: SHARING, groups: [SECTION] },

‎packages/spec/src/kernel/metadata-authoring-lint.test.ts‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,26 @@ describe('coverage derivation (no third hand-written list)', () => {
108108
const registrySchema = getMetadataTypeSchema('view');
109109
expect(registrySchema, 'the registry entry itself must still exist — only the lint stopped reading it')
110110
.toBeDefined();
111-
// The registry schema is still STRIP-mode, which is what makes reading it
112-
// wrong rather than merely redundant: run the walk against it explicitly
113-
// and the old contradicting finding comes straight back. This keeps the
114-
// card's evidence alive — if `ViewMetadataSchema` ever goes strict, this
115-
// assertion fails and the exclusion above needs restating, rather than
116-
// quietly becoming true for a second, unrelated reason.
111+
// The registry schema WAS strip-mode, which is what made reading it wrong
112+
// rather than merely redundant: walked explicitly, it gave the old
113+
// contradicting finding (`views.v1.bogusViewKey`) straight back.
114+
//
115+
// [#26711] `ViewMetadataSchema` closed too: the `view` write door now
116+
// refuses an unknown top-level key on every member, so the explicit walk
117+
// finds nothing — and the parse refuses the key, which is what makes that
118+
// empty answer a graduation and not a walker that broke. The exclusion
119+
// above now holds for both schemas; the card's point (ask the schema the
120+
// parse applies) still stands for the next type that serves two shapes.
117121
expect(
118122
lintUnknownKeysAgainstSchema(registrySchema, VIEW_ENTRY, 'view', 'views.v1').map((f) => f.path),
119-
'ViewMetadataSchema still strips — the divergence this card fixed is real, not stale',
120-
).toEqual(['views.v1.bogusViewKey']);
123+
'ViewMetadataSchema is closed — the walk has nothing to warn about',
124+
).toEqual([]);
125+
const parsed = registrySchema!.safeParse(VIEW_ENTRY);
126+
expect(parsed.success, 'the registry schema REFUSES the key the walk no longer reports').toBe(false);
127+
// The union carries the claimed branch's refusal inside `invalid_union`.
128+
expect(JSON.stringify(parsed.success ? [] : parsed.error.issues)).toContain('"keys":["bogusViewKey"]');
129+
const { bogusViewKey: _bogus, ...clean } = VIEW_ENTRY;
130+
expect(registrySchema!.safeParse(clean).success, 'control: the entry without the key saves').toBe(true);
121131
});
122132

123133
it('excludes the strict types — the parse is already loud there', () => {

‎packages/spec/src/kernel/metadata-type-schemas.test.ts‎

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
* regime C), closed — `SharingRuleSchema` is `.strict()` and an authoring
9393
* surface only. This was the last bump: closed 27 of 28 when the counts were
9494
* replaced by the rule.
95+
* - `STILL_STRIP` emptied on 2026-10-27: `view` closed (#26711). Its open union
96+
* members were the wire shapes, and the reason they stayed open (Studio's
97+
* round-trip keys) had been paid by declaring those keys; see that list's note.
9598
*/
9699

97100
import { describe, expect, it } from 'vitest';
@@ -520,7 +523,20 @@ describe('each bound entry IS its stack collection\'s schema', () => {
520523
* type fails this suite until the list shrinks, so the list cannot outlive the
521524
* debt and start exempting types that no longer need exempting.
522525
*
523-
* ## `view` is the end state, not the last item of debt
526+
* ## `view` closed (#26711) — the "end state" below was a premise, and it moved
527+
*
528+
* The next paragraphs are kept as history. They said `view` would never close,
529+
* because three union members carried Studio's round-trip keys and the save
530+
* persisted the body verbatim. Both halves stopped being true: #20456 declared
531+
* every round-trip key the console writes (`VIEW_CONSOLE_ROUND_TRIP_KEYS`), and
532+
* #20051 made the save store the PARSED body, so an open member no longer kept
533+
* an undeclared key — it answered success and lost it. Closing the three wire
534+
* members then refused nothing the platform writes (measured: every example
535+
* view body, and every view a showcase boot serves, round-tripped through the
536+
* closed door), and `STILL_STRIP` is empty. A new entry still has to answer the
537+
* question below before it is accepted.
538+
*
539+
* ### History: `view` as the end state
524540
*
525541
* Every other registered type is closed and `view` will not be, for a reason
526542
* worth stating so nobody "finishes the job" by force. The registered `view` schema is a UNION
@@ -588,7 +604,7 @@ describe('each bound entry IS its stack collection\'s schema', () => {
588604
* envelope had a layer that could own it. A future entry on this list should be
589605
* asked which of the two it is before it is accepted as permanent.
590606
*/
591-
const STILL_STRIP = new Set<string>(['view']);
607+
const STILL_STRIP = new Set<string>([]);
592608

593609
/** The registered schema's own top-level posture: `.strict()` sets a `never` catchall. */
594610
function topLevelPosture(schema: unknown, depth = 0): 'strict' | 'strip' | null {
@@ -644,12 +660,17 @@ describe('registered-type closure is derived, not tallied', () => {
644660
).toBe('strict');
645661
});
646662

647-
it.each([...STILL_STRIP])('%s is still on the strip list (remove it once closed)', (type) => {
648-
expect(types).toContain(type);
649-
expect(
650-
topLevelPosture(getMetadataTypeSchema(type)),
651-
`'${type}' is now strict — remove it from STILL_STRIP.`,
652-
).toBe('strip');
663+
// One test over the whole list, not one per entry: the list is empty since
664+
// `view` closed (#26711), and the open-set rule below pins that empty set on
665+
// purpose. Kept as the reverse pin for the next exception, if one is accepted.
666+
it('every STILL_STRIP entry is registered and still strips (remove it once closed)', () => {
667+
for (const type of STILL_STRIP) {
668+
expect(types).toContain(type);
669+
expect(
670+
topLevelPosture(getMetadataTypeSchema(type)),
671+
`'${type}' is now strict — remove it from STILL_STRIP.`,
672+
).toBe('strip');
673+
}
653674
});
654675

655676
it('the open set, computed from the registry, IS `STILL_STRIP` — no count to bump', () => {

0 commit comments

Comments
 (0)