Skip to content

Commit f9d3a78

Browse files
committed
test(spec): pin the view write door's unknown-key refusal; re-judge the fixtures that froze the strip
Claude-Session: https://claude.ai/code/session_01WGufziYCUHZQE3MXucvWe9 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 82f060c commit f9d3a78

9 files changed

Lines changed: 215 additions & 49 deletions

‎packages/spec/src/ui/view-authoring-wire-split.test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,13 @@ describe('the wire door accepts what the platform itself writes', () => {
228228
).toBe(false);
229229
});
230230

231-
it('an undeclared aux key still rides on the wire member (`.strip()`, as before)', () => {
232-
accept(ViewMetadataSchema, { ...RECORD, someFutureStudioAuxKey: 1 });
231+
// [#26711] It used to ride through `.strip()` and was not stored: the save
232+
// stores the parsed body (#20051). A new console key is declared on the
233+
// member with its meaning, as #20456 did, or it is refused here by name.
234+
it('an undeclared aux key is refused by name on the wire member', () => {
235+
const issues = reject(ViewMetadataSchema, { ...RECORD, someFutureStudioAuxKey: 1 });
236+
expect(issues).toContain('"code":"unrecognized_keys"');
237+
expect(issues).toContain('someFutureStudioAuxKey');
233238
});
234239

235240
// ── the acceptance criteria named in the scope addendum ──────────────────

‎packages/spec/src/ui/view-filter-rule-wire-id.test.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,19 @@ describe('why the flattened member could not rescue this block', () => {
201201
// assertions about the fix. Remove the decoration strip from the wire door
202202
// and case 3/3 above goes red while these two stay green: that gap is still
203203
// the finding, now pointing at the mechanism instead of the posture.
204-
it('the flattened member re-opens the TOP level: an unknown aux key rides along', () => {
204+
// [#26711] The member's TOP level is closed now too, so an unknown aux key is
205+
// refused there. The point this block makes is unchanged: a top-level
206+
// posture, open or closed, never reached the nested rows, and only the
207+
// decoration strip before the parse lets the console's row ids through.
208+
it('the flattened member judges its TOP level: an unknown aux key is refused', () => {
205209
expect(
206210
ViewMetadataSchema.safeParse({ ...OVERLAY_BASE, someStudioAuxKey: 1 }).success,
207-
).toBe(true);
211+
).toBe(false);
208212
});
209213

210-
it('…but a still-CLOSED nested block rejects through that same member', () => {
211-
// `emptyState` was closed at 批 18 and stays closed. The top level rides,
212-
// the nested block does not: `.strip()` re-opened one level, not the tree.
214+
it('…and a CLOSED nested block rejects through that same member', () => {
215+
// `emptyState` was closed at 批 18 and stays closed. Its posture is its
216+
// own: when the member's top level was `.strip()`ped it still refused.
213217
expect(
214218
ViewMetadataSchema.safeParse({
215219
...OVERLAY_BASE,

‎packages/spec/src/ui/view-metadata-schema.test.ts‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,16 @@ describe('ViewMetadataSchema — genuine validation across the three runtime sha
267267
// an expanded ViewItem always carries both — so a console PUT on a REAL
268268
// view arrives bound, exactly as spelled here. The precondition-inertness
269269
// claim is asserted separately below on the bare, baseline-less shapes.
270+
//
271+
// [#26711] The filter-only overlay is a LIST overlay: `filter` is a list
272+
// key. Spelled `viewKind: 'form'` it was accepted only because the form
273+
// member `.strip()`ped the filter unread, so the save stored a form overlay
274+
// without it; the form member now refuses `filter` by name.
270275
it.each([
271276
['a pin PUT with no stored item to merge', { isPinned: true, object: 'crm_lead', viewKind: 'list' }],
272277
['a switcher-reorder PUT', { sortOrder: 3, object: 'crm_lead', viewKind: 'list' }],
273278
['a column-only overlay', { columns: ['name'], object: 'crm_lead', viewKind: 'list' }],
274-
['a filter-only overlay', { filter: [{ field: 'name', operator: 'contains', value: 'x' }], object: 'crm_lead', viewKind: 'form' }],
279+
['a filter-only overlay', { filter: [{ field: 'name', operator: 'contains', value: 'x' }], object: 'crm_lead', viewKind: 'list' }],
275280
['an order-only overlay', { order: 2, object: 'crm_lead', viewKind: 'form' }],
276281
['a renamed view that still carries its config', { label: 'New name', columns: ['name'], object: 'crm_lead', viewKind: 'list' }],
277282
])('leaves %s alone', (_label, body) => {
@@ -384,14 +389,20 @@ describe('ViewMetadataSchema — genuine validation across the three runtime sha
384389
expect(ViewMetadataSchema.safeParse({ groupByField: 'stage' }).success).toBe(false);
385390
});
386391

387-
it('does NOT close the arms — `.strip()` round-tripping is untouched', () => {
388-
// The ruling on #5599 kept every arm's `.strip()`: a body that speaks the
389-
// vocabulary still carries undeclared aux keys through without a 422.
390-
// This is the deliberate residue of the minimal fix, pinned so a later
391-
// batch cannot mistake it for an oversight. ([#7741] bound form — the
392-
// openness under test is about UNKNOWN keys, not the binding pair.)
392+
it('the arms judge an unknown key themselves — the precondition admits the body, the arm refuses the key', () => {
393+
// The ruling on #5599 kept every arm's `.strip()` while the save stored
394+
// the ORIGINAL body, so undeclared aux keys round-tripped. [#26711] Since
395+
// #20051 the save stores the parsed body and #20456 declared every
396+
// round-trip key, so the strip only dropped a misspelt key in silence;
397+
// the arms are closed. The precondition is unchanged: this body speaks
398+
// the vocabulary (`isPinned`), and the refusal is the arm's, naming the
399+
// key. ([#7741] bound form — the case is about UNKNOWN keys, not the
400+
// binding pair.)
393401
const r = ViewMetadataSchema.safeParse({ isPinned: true, someFutureStudioKey: 'x', object: 'crm_lead', viewKind: 'list' });
394-
expect(r.success).toBe(true);
402+
expect(r.success).toBe(false);
403+
expect(JSON.stringify(r.success ? [] : r.error.issues)).toContain('Unrecognized key(s) on this inline list view: `someFutureStudioKey`');
404+
// …and without the unknown key the same body is accepted.
405+
expect(ViewMetadataSchema.safeParse({ isPinned: true, object: 'crm_lead', viewKind: 'list' }).success).toBe(true);
395406
});
396407
});
397408

‎packages/spec/src/ui/view-overlay-viewkind-arm.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ describe('a column-less list overlay that NAMES a `type` stays refused — at `c
146146
// refused now, and still wrapped as `invalid_union` (the refusal is an
147147
// ABORTING issue, so the list member is not the union's lone survivor).
148148
it.each([
149-
['a kanban config with no columns', { name: 'x', object: 'crm_lead', viewKind: 'list', type: 'kanban', groupByField: 'stage' }],
149+
// [#26711] `groupByField` is spelled under `kanban`: at the top level it is
150+
// an unknown key, refused by name ahead of the `columns` check.
151+
['a kanban config with no columns', { name: 'x', object: 'crm_lead', viewKind: 'list', type: 'kanban', kanban: { groupByField: 'stage', columns: ['name'] } }],
150152
['a grid config with no columns', { ...LIST, type: 'grid', sort: [{ field: 'name', order: 'asc' }] }],
151153
])('%s', (_label, body) => {
152154
const r = refusal(body);

‎packages/spec/src/ui/view-strictness-batch18.test.ts‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,18 @@ describe('批 18 — the shapes left open, and what became of them', () => {
424424
).toBe(true);
425425
});
426426

427-
it('…and the mechanism, which is why a posture flip could NOT have fixed it: `.strip()` does not recurse', () => {
427+
it('…and the mechanism, which is why a posture flip could NOT have fixed it: a top-level posture does not recurse', () => {
428428
// The load-bearing fact for every nested block in this file. A member's
429-
// `.strip()` re-opens the TOP level only, so a nested block closed inside
430-
// `ListViewSchema` is still reached at full strictness through that member.
431-
// #5074's answer is not a deeper strip — it is removing the named
432-
// decoration ahead of the parse. These two assertions are the CONTROLS for
433-
// that claim and must hold whichever way the decorated blocks are written.
429+
// top-level posture reaches the TOP level only, so a nested block closed
430+
// inside `ListViewSchema` is reached at its own strictness through that
431+
// member, whatever the member does. #5074's answer is not a deeper strip —
432+
// it is removing the named decoration ahead of the parse. These two
433+
// assertions are the CONTROLS for that claim and must hold whichever way
434+
// the decorated blocks are written.
434435
const overlay = { type: 'grid', columns: ['name'], name: 'o.default', viewKind: 'list', object: 'o' };
435-
// top level: an unknown aux key rides along, because the member strips.
436-
expect(ViewMetadataSchema.safeParse({ ...overlay, someStudioAuxKey: 1 }).success).toBe(true);
436+
// top level: [#26711] the member is closed, so an unknown aux key is
437+
// refused (it used to `.strip()` and the save dropped the key).
438+
expect(ViewMetadataSchema.safeParse({ ...overlay, someStudioAuxKey: 1 }).success).toBe(false);
437439
// nested: a CLOSED sub-block that is NOT a declared decoration still rejects.
438440
expect(ViewMetadataSchema.safeParse({ ...overlay, emptyState: { title: 'x', notAnEmptyStateKey: 1 } }).success).toBe(false);
439441
});

‎packages/spec/src/ui/view-union-diagnostics.test.ts‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,12 @@ describe('the acceptance face of ViewMetadataSchema — frozen by the diagnostic
257257
* are in the table precisely because a surprising accept is the one a
258258
* refactor silently loses:
259259
*
260-
* - `overlay.badOperator` / `overlay.console*Id` ACCEPT with the payload
260+
* - `overlay.badOperator` / `overlay.console*Id` ACCEPTED with the payload
261261
* stripped to the binding + `{type:'simple'}` — the form overlay does not
262-
* declare `filter`/`sort`, and `.strip()` drops them. Pre-existing,
263-
* load-bearing for Studio's round-trip, and untouched by #7741 (openness
264-
* is about unknown keys; the binding is about required ones).
262+
* declare `filter`/`sort`, and its `.strip()` dropped them. [#26711] The
263+
* form overlay is closed now, so all three moved to REFUSED; the console's
264+
* row ids on a LIST overlay, where `sort` / `filter` are declared, are the
265+
* `overlay.list.console*Id` rows and still ACCEPT with the ids removed.
265266
* - `overlay.list.min` (`{type:'grid'}` alone) REJECTS.
266267
* - `container.empty` REJECTS with `custom`, not `invalid_union`: when
267268
* exactly one branch is non-aborted zod's `handleUnionResults` returns THAT
@@ -292,12 +293,10 @@ describe('the acceptance face of ViewMetadataSchema — frozen by the diagnostic
292293
{ type: 'simple', sections: [SECTION], ...BOUND_FORM }],
293294
['overlay.form.identity', { name: 'x', object: 'crm_lead', viewKind: 'form', type: 'wizard' },
294295
{ type: 'wizard', name: 'x', object: 'crm_lead', viewKind: 'form' }],
295-
['overlay.badOperator', { filter: [{ field: 'name', operator: 'sorta_equals', value: 'x' }], ...BOUND_FORM },
296-
{ type: 'simple', ...BOUND_FORM }],
297-
['overlay.consoleSortId', { sort: [{ id: 'row-1', field: 'name', order: 'asc' }], ...BOUND_FORM },
298-
{ type: 'simple', ...BOUND_FORM }],
299-
['overlay.consoleFilterId', { filter: [{ id: 'row-1', field: 'name', operator: '=', value: 'x' }], ...BOUND_FORM },
300-
{ type: 'simple', ...BOUND_FORM }],
296+
['overlay.list.consoleSortId', { sort: [{ id: 'row-1', field: 'name', order: 'asc' }], ...BOUND_LIST },
297+
{ type: 'grid', sort: [{ field: 'name', order: 'asc' }], ...BOUND_LIST }],
298+
['overlay.list.consoleFilterId', { filter: [{ id: 'row-1', field: 'name', operator: 'equals', value: 'x' }], ...BOUND_LIST },
299+
{ type: 'grid', filter: [{ field: 'name', operator: 'equals', value: 'x' }], ...BOUND_LIST }],
301300
// [#20186] A lean `viewKind: 'list'` PUT is judged by the LIST member now,
302301
// so it parses to a list (`type: 'grid'`). It used to parse to
303302
// `type: 'simple'` — a FORM — because the form member was the one accepting
@@ -329,6 +328,12 @@ describe('the acceptance face of ViewMetadataSchema — frozen by the diagnostic
329328
['overlay.list.aux.retiredHidden', { type: 'grid', columns: ['name'], isDefault: true, order: 2, hidden: false, ...BOUND_LIST }, ['invalid_union']],
330329
['put.hidden', { hidden: true, ...BOUND_FORM }, ['invalid_union']],
331330
['put.owner', { owner: 'usr_7', ...BOUND_LIST }, ['invalid_union']],
331+
// [#26711] Formerly ACCEPTED with `filter` / `sort` stripped by the form
332+
// overlay, which declares neither: the save stored a bare form overlay.
333+
// The member is closed now and refuses both keys by name.
334+
['overlay.badOperator', { filter: [{ field: 'name', operator: 'sorta_equals', value: 'x' }], ...BOUND_FORM }, ['invalid_union']],
335+
['overlay.consoleSortId', { sort: [{ id: 'row-1', field: 'name', order: 'asc' }], ...BOUND_FORM }, ['invalid_union']],
336+
['overlay.consoleFilterId', { filter: [{ id: 'row-1', field: 'name', operator: '=', value: 'x' }], ...BOUND_FORM }, ['invalid_union']],
332337
// [#7741] The corpus's former unbound ACCEPTED entries, each re-measured:
333338
// an overlay that names no `object`/`viewKind` would be stored as a row no
334339
// object-bound read path can serve, so the members now refuse it with the
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #26711 — the `view` write door refuses an unknown TOP-LEVEL key, as the
5+
* object, page and dashboard doors do.
6+
*
7+
* Three of `ViewMetadataSchema`'s four members — the ViewItem record and the
8+
* two flattened overlays — used to `.strip()` their top level. Since the save
9+
* stores the parsed body (#20051), a misspelt or retired key answered success
10+
* and was simply not stored. The container member was already closed.
11+
*
12+
* Pinned per member, because each is closed on its own: the refusal (code,
13+
* key, the member named), a retired key's prescription in both channels the
14+
* protocol has for it, the alias spellings the #20456 census found, and a
15+
* clean body of each shape still saving with what the console writes.
16+
*/
17+
import { describe, expect, it } from 'vitest';
18+
import { z } from 'zod';
19+
20+
import { RETIRED_KEY_UPGRADE_GUIDE_SENTENCE } from '../shared/protocol-upgrade-guide';
21+
import { ViewMetadataSchema, diagnoseViewMetadata, type ViewMetadataBranch } from './view.zod';
22+
23+
const DATA = { provider: 'object', object: 'crm_lead' } as const;
24+
25+
/** One clean body per member the change closed, as the write path delivers it. */
26+
const CLEAN: Record<'viewItem' | 'listOverlay' | 'formOverlay', { body: Record<string, unknown>; surface: string }> = {
27+
viewItem: {
28+
body: {
29+
name: 'crm_lead.mine',
30+
object: 'crm_lead',
31+
viewKind: 'list',
32+
label: 'Mine',
33+
config: { type: 'grid', data: DATA, columns: ['name'] },
34+
isPinned: true,
35+
},
36+
surface: 'this view item record',
37+
},
38+
listOverlay: {
39+
body: { name: 'crm_lead.all', object: 'crm_lead', viewKind: 'list', type: 'grid', columns: ['name'], isPinned: true },
40+
surface: 'this inline list view',
41+
},
42+
formOverlay: {
43+
body: { name: 'crm_lead.edit', object: 'crm_lead', viewKind: 'form', type: 'simple' },
44+
surface: 'this inline form view',
45+
},
46+
};
47+
48+
const MEMBERS = Object.keys(CLEAN) as Array<keyof typeof CLEAN>;
49+
50+
/** The claimed member's issues, read the way Studio and an MCP author get them. */
51+
function refusal(body: unknown): { branch: ViewMetadataBranch | null; issues: readonly z.core.$ZodIssue[] } {
52+
const parsed = ViewMetadataSchema.safeParse(body);
53+
expect(parsed.success, 'expected the write door to refuse this body').toBe(false);
54+
const diagnosis = diagnoseViewMetadata(body);
55+
if (diagnosis.success) throw new Error('diagnoseViewMetadata accepted a body the union refused');
56+
return { branch: diagnosis.branch, issues: diagnosis.issues };
57+
}
58+
59+
describe('a clean body of each closed member still saves', () => {
60+
it.each(MEMBERS)('%s', (member) => {
61+
const r = ViewMetadataSchema.safeParse(CLEAN[member].body);
62+
expect(r.success, JSON.stringify(r.success ? null : r.error.issues)).toBe(true);
63+
expect(diagnoseViewMetadata(CLEAN[member].body)).toMatchObject({ success: true, branch: member });
64+
});
65+
66+
it("the console's row ids are still removed before the parse, not refused", () => {
67+
const r = ViewMetadataSchema.safeParse({
68+
...CLEAN.listOverlay.body,
69+
sort: [{ id: 'row-1', field: 'name', order: 'asc' }],
70+
filter: [{ id: 'row-2', field: 'name', operator: 'equals', value: 'x' }],
71+
});
72+
expect(r.success).toBe(true);
73+
const data = r.data as { sort: unknown[]; filter: unknown[] };
74+
expect(data.sort).toEqual([{ field: 'name', order: 'asc' }]);
75+
expect(data.filter).toEqual([{ field: 'name', operator: 'equals', value: 'x' }]);
76+
});
77+
});
78+
79+
describe('an unknown top-level key is refused by name', () => {
80+
it.each(MEMBERS)('%s', (member) => {
81+
const { branch, issues } = refusal({ ...CLEAN[member].body, zzz_junk_key: true });
82+
expect(branch).toBe(member);
83+
expect(issues).toHaveLength(1);
84+
expect(issues[0]).toMatchObject({ code: 'unrecognized_keys', path: [], keys: ['zzz_junk_key'] });
85+
expect(issues[0]!.message).toMatch(
86+
new RegExp(`^Unrecognized key\\(s\\) on ${CLEAN[member].surface}: \`zzz_junk_key\`\\.`),
87+
);
88+
});
89+
90+
it('the container member was already closed, and still is', () => {
91+
const { branch, issues } = refusal({ object: 'crm_lead', list: { type: 'grid', data: DATA, columns: ['name'] }, zzz_junk_key: true });
92+
expect(branch).toBe('container');
93+
expect(issues[0]).toMatchObject({ code: 'unrecognized_keys', keys: ['zzz_junk_key'] });
94+
});
95+
});
96+
97+
describe("a retired key gets the prescription its retirement kit gives it", () => {
98+
// `striped` was retired with the list view's other display keys, and its kit
99+
// has aged out (ADR-0087, amendment 2026-10-26): the refusal names the key and
100+
// points at the protocol upgrade guide, which holds its prescription now.
101+
// Before this change the overlay door answered success and dropped it.
102+
it.each(['listOverlay', 'viewItem'] as const)('`striped` (aged out) on %s: named, with the upgrade guide', (member) => {
103+
const { branch, issues } = refusal({ ...CLEAN[member].body, striped: true });
104+
expect(branch).toBe(member);
105+
expect(issues[0]).toMatchObject({ code: 'unrecognized_keys', keys: ['striped'] });
106+
expect(issues[0]!.message).toContain(RETIRED_KEY_UPGRADE_GUIDE_SENTENCE);
107+
});
108+
109+
// `filterableFields` still has its live tombstone on the list view shape, so
110+
// the overlay raises its own prescription at the key, and the union lifts it
111+
// to the top-level message an author at `PUT /api/v1/meta/view` reads.
112+
it('`filterableFields` (live tombstone) on the inline list view: its prescription, at the key', () => {
113+
const body = { ...CLEAN.listOverlay.body, filterableFields: ['name'] };
114+
const { branch, issues } = refusal(body);
115+
expect(branch).toBe('listOverlay');
116+
expect(issues[0]).toMatchObject({ code: 'invalid_type', expected: 'never', path: ['filterableFields'] });
117+
const parsed = ViewMetadataSchema.safeParse(body);
118+
expect(parsed.success ? '' : parsed.error.issues[0]!.message).toMatch(/^`view\.list\.filterableFields` was removed in @objectstack\/spec 18/);
119+
});
120+
});
121+
122+
describe('the alias spellings the census found point at the declared key', () => {
123+
it.each(MEMBERS)('`objectName` on %s → `object`', (member) => {
124+
const { issues } = refusal({ ...CLEAN[member].body, objectName: 'crm_lead' });
125+
expect(issues[0]).toMatchObject({ code: 'unrecognized_keys', keys: ['objectName'] });
126+
expect(issues[0]!.message).toContain('Did you mean `objectName` → `object`?');
127+
});
128+
129+
it.each(MEMBERS)('a top-level `id` on %s → `name`', (member) => {
130+
const { issues } = refusal({ ...CLEAN[member].body, id: 'crm_lead.mine' });
131+
expect(issues[0]).toMatchObject({ code: 'unrecognized_keys', keys: ['id'] });
132+
expect(issues[0]!.message).toContain('Did you mean `id` → `name`?');
133+
});
134+
});

0 commit comments

Comments
 (0)