Skip to content

Commit 919e71b

Browse files
committed
test(rest): red-first pins for bracketed object/package keys on the /meta list and book tree
Claude-Session: https://claude.ai/code/session_01ADHkmPfJsJeWNxeaZkvyEM Co-authored-by: Claude <noreply@anthropic.com>
1 parent 45e9b2f commit 919e71b

4 files changed

Lines changed: 160 additions & 0 deletions

File tree

‎packages/rest/src/meta-app-publish-gate.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,52 @@ describe('#7566 — `GET /meta/app?id=` narrows the list instead of being droppe
374374
expect(namesFrom(res.body)).toEqual(['all_leads']);
375375
});
376376

377+
// The same class one step down the chain: `?object[]=lead` or
378+
// `?object[0]=lead` reached the view switcher under the key as spelled,
379+
// so the filter, which reads `query.object`, never saw it and the caller
380+
// who asked for one object's views got every view it may see. Refused with
381+
// the bracketed `id`'s answer, naming the key as sent; the dispatcher's
382+
// twin is pinned in `@objectstack/runtime`'s list parity census.
383+
it.each(['object[]', 'object[0]', 'object[name]'])('a BRACKETED view `%s` key is refused with 400 naming it — never every view', async (key) => {
384+
const views = async ({ type: t }: any) =>
385+
String(t ?? '').startsWith('view')
386+
? [{ name: 'all_leads', viewKind: 'list', object: 'lead' }, { name: 'acct_view', viewKind: 'list', object: 'account' }]
387+
: [];
388+
for (const perms of [['studio.access'], ['manage_users'], []]) {
389+
for (const type of ['view', 'views']) {
390+
const { rest, protocol } = setup(perms);
391+
protocol.getMetaItems = vi.fn(views);
392+
const res = await getList(rest, type, { [key]: 'lead' });
393+
394+
expect(res.statusCode, `${type}, caller holding [${perms}]`).toBe(400);
395+
expect(res.body?.code).toBe('VALIDATION_ERROR');
396+
expect(String(res.body?.error)).toBe(
397+
`Query parameter '${key}' names no object; the 'object' filter takes exactly one object name, `
398+
+ `spelled ?object=NAME. The list was not served: a bracketed 'object' key is not a filter. `
399+
+ 'Name one object, or leave the parameter out to list every view you can see.',
400+
);
401+
expect(res.body?.items).toBeUndefined();
402+
expect(Array.isArray(res.body)).toBe(false);
403+
}
404+
}
405+
// A bracketed key beside a plain one is two spellings of one filter.
406+
const { rest, protocol } = setup(['manage_users']);
407+
protocol.getMetaItems = vi.fn(views);
408+
const both = await getList(rest, 'view', { object: 'lead', [key]: 'account' });
409+
expect(both.statusCode).toBe(400);
410+
expect(both.body?.code).toBe('VALIDATION_ERROR');
411+
// Controls: the plain spelling still switches, an absent one lists all.
412+
expect(namesFrom((await getList(rest, 'view', { object: 'lead' })).body)).toEqual(['all_leads']);
413+
expect(namesFrom((await getList(rest, 'view')).body).sort()).toEqual(['acct_view', 'all_leads']);
414+
});
415+
416+
it('a bracketed `object` key on another list type is not read, as no other `object` spelling is (control)', async () => {
417+
const res = await getList(setup(['manage_users']).rest, 'app', { 'object[]': 'lead' });
418+
419+
expect(res.statusCode).toBe(200);
420+
expect(namesFrom(res.body).sort()).toEqual(['account', 'crm']);
421+
});
422+
377423
it('a WHITESPACE id keeps its answer — a value no app is named, so an empty list (#28548 control)', async () => {
378424
const { rest } = setup(['manage_users']);
379425
const res = await getList(rest, 'app', { id: ' ' });

‎packages/rest/src/meta-query-arity-doors.test.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,69 @@ describe('RestServer refuses exactly the names the shared list declares, door by
132132
expect((await drive('state', { from: 'todo' })).status).not.toBe(400);
133133
});
134134
});
135+
136+
/**
137+
* A client that serialises arrays qs-style sends `?package[]=com.acme` or
138+
* `?package[0]=com.acme`. The adapters hand the key through as spelled, so
139+
* `metaItemPackageBinding(query.package)` read no package and the list (and
140+
* the book tree) answered across EVERY package for a request that named one.
141+
* The two doors that read `package` with no closed set refuse it where they
142+
* ask their arity, before any read; every by-name door already refuses the
143+
* key as an unknown name (recognition).
144+
*/
145+
const bracketedPackageMessage = (key: string, served: 'list' | 'tree', unscoped: string): string =>
146+
`Query parameter '${key}' names no package; the 'package' filter takes exactly one package id, `
147+
+ `spelled ?package=ID. The ${served} was not served: a bracketed 'package' key is not a filter. `
148+
+ `Name one package, or leave the parameter out to ${unscoped}.`;
149+
const PACKAGE_DOORS = [
150+
['list', 'list', 'list across every package'],
151+
['book-tree', 'tree', 'read the tree across every package'],
152+
] as const;
153+
154+
describe('a BRACKETED `package` key on the two arity doors that read `package`', () => {
155+
it.each(PACKAGE_DOORS.flatMap(([door, served, unscoped]) =>
156+
['package[]', 'package[0]', 'package[id]'].map((key) => [door, key, served, unscoped] as const)))(
157+
'%s door: `%s` is refused as data, naming the key',
158+
(door, key, served, unscoped) => {
159+
expect(metaQueryArityRefusal(door, { [key]: 'com.acme' })).toEqual({
160+
status: 400,
161+
code: 'VALIDATION_ERROR',
162+
message: bracketedPackageMessage(key, served, unscoped),
163+
rule: 'bracketed-parameter',
164+
});
165+
// Beside a plain `package` it is two spellings of one scope.
166+
expect(metaQueryArityRefusal(door, { package: 'com.acme', [key]: 'com.other' })?.rule)
167+
.toBe('bracketed-parameter');
168+
},
169+
);
170+
171+
it('a repeated plain `package` still answers the multiplicity sentence first', () => {
172+
expect(metaQueryArityRefusal('list', { package: ['a', 'b'], 'package[]': 'c' })?.message)
173+
.toBe(repeatedQueryParamMessage('package', 2));
174+
});
175+
176+
it('is judged only where `package` is read: not on `_drafts`, `state`, or a key that merely starts alike', () => {
177+
expect(metaQueryArityRefusal('drafts', { 'package[]': 'com.acme' })).toBeUndefined();
178+
expect(metaQueryArityRefusal('state', { 'package[]': 'com.acme' })).toBeUndefined();
179+
expect(metaQueryArityRefusal('list', { 'packages[]': 'com.acme', packageId: 'x' })).toBeUndefined();
180+
});
181+
182+
it.each(PACKAGE_DOORS.flatMap(([door, served, unscoped]) =>
183+
['package[]', 'package[0]'].map((key) => [door, key, served, unscoped] as const)))(
184+
'RestServer %s door: `%s` answers the nested 400 before any protocol read',
185+
async (door, key, served, unscoped) => {
186+
const { protocol, status, body } = await drive(door, { [key]: 'com.acme' });
187+
expect(status).toBe(400);
188+
expect(body).toEqual({ error: { code: 'VALIDATION_ERROR', message: bracketedPackageMessage(key, served, unscoped) } });
189+
expect(protocol.getMetaItems).not.toHaveBeenCalled();
190+
},
191+
);
192+
193+
it('RestServer: the plain spelling still scopes, and an absent one reads every package (controls)', async () => {
194+
for (const door of ['list', 'book-tree'] as const) {
195+
expect((await drive(door, { package: 'com.acme' })).protocol.getMetaItems.mock.calls[0][0])
196+
.toMatchObject({ packageId: 'com.acme' });
197+
expect((await drive(door, {})).protocol.getMetaItems.mock.calls[0][0].packageId).toBeUndefined();
198+
}
199+
});
200+
});

‎packages/runtime/src/domains/dispatcher-query-arity.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,38 @@ describe('[#23214] /meta — the four arity doors, over the list both transports
211211
expect(protocol.getMetaItems.mock.calls[0][0]).toMatchObject({ packageId: 'com.acme' });
212212
});
213213
});
214+
215+
// A qs-style array spelling (`?package[]=`, `?package[0]=`) reached the
216+
// binding under the key as sent, so it read no package and the list and
217+
// the tree answered across every package. Refused at the same arity step,
218+
// with `RestServer`'s code and sentence, before any read.
219+
describe('a BRACKETED `package` key on the list and the book tree', () => {
220+
it.each([
221+
['/meta/view', 'package[]', 'list', 'list across every package'],
222+
['/meta/view', 'package[0]', 'list', 'list across every package'],
223+
['/meta/book/handbook/tree', 'package[]', 'tree', 'read the tree across every package'],
224+
['/meta/book/handbook/tree', 'package[0]', 'tree', 'read the tree across every package'],
225+
])('GET %s?%s=… is refused before any read', async (path, key, served, unscoped) => {
226+
const { dispatcher, protocol } = boot();
227+
const answer = await get(dispatcher, path, { [key]: 'com.acme' });
228+
expect(answer.status, JSON.stringify(answer)).toBe(400);
229+
expect(answer.body?.error?.code).toBe('VALIDATION_ERROR');
230+
expect(answer.body?.error?.message).toBe(
231+
`Query parameter '${key}' names no package; the 'package' filter takes exactly one package id, `
232+
+ `spelled ?package=ID. The ${served} was not served: a bracketed 'package' key is not a filter. `
233+
+ `Name one package, or leave the parameter out to ${unscoped}.`,
234+
);
235+
expect(protocol.getMetaItems).not.toHaveBeenCalled();
236+
});
237+
238+
it('a bracketed view `object` key is refused by the list chain, never every view', async () => {
239+
const { dispatcher } = boot();
240+
const answer = await get(dispatcher, '/meta/view', { 'object[]': 'task' });
241+
expect(answer.status, JSON.stringify(answer)).toBe(400);
242+
expect(answer.body?.error?.code).toBe('VALIDATION_ERROR');
243+
expect(answer.body?.error?.message).toMatch(/^Query parameter 'object\[\]' names no object/);
244+
});
245+
});
214246
});
215247

216248
describe('[#23214] GET /ui/view/:object — `?type=` is one view type, read only when the path names none', () => {

‎packages/runtime/src/domains/meta-list-projection-parity.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,18 @@ const PARAM_PROBES: ReadonlyArray<{ label: string; param?: string; query: Record
533533
{ label: '?object=nope', param: 'object', query: { object: 'nope' } },
534534
// [#28548] …and so is an EMPTY view object.
535535
{ label: '?object= (empty)', param: 'object', query: { object: '' } },
536+
// …and a BRACKETED view `object` key, never read as no filter.
537+
{ label: '?object[]=lead', param: 'object', query: { 'object[]': 'lead' } },
538+
{ label: '?object[0]=lead', param: 'object', query: { 'object[0]': 'lead' } },
536539
{ label: '?include=content', param: 'include', query: { include: 'content' } },
537540
// [#25333] The position list's opt-in description.
538541
{ label: '?include=grants', param: 'include', query: { include: 'grants' } },
539542
{ label: '?locale=zh-CN', param: 'locale', query: { locale: 'zh-CN' } },
540543
{ label: 'Accept-Language: zh-CN', query: {}, headers: { 'accept-language': 'zh-CN' } },
541544
{ label: '?package=crm', param: 'package', query: { package: 'crm' } },
545+
// A BRACKETED `package` key is refused at the list's arity step, never
546+
// read as every package.
547+
{ label: '?package[]=crm', param: 'package', query: { 'package[]': 'crm' } },
542548
{ label: '?preview=draft', param: 'preview', query: { preview: 'draft' } },
543549
// [#20408] The switch's value is compared case-insensitively on `RestServer`.
544550
{ label: '?preview=DRAFT', param: 'preview', query: { preview: 'DRAFT' } },
@@ -697,6 +703,10 @@ describe('[#20320] row A: the reference moves — each probe changes RestServer\
697703
expect((await read('/meta/views', { object: 'nope' })).items).toEqual([]);
698704
const blankObject = await read('/meta/views', { object: '' });
699705
expect({ status: blankObject.status, code: blankObject.code, items: blankObject.items }).toEqual({ status: 400, code: 'VALIDATION_ERROR', items: undefined });
706+
const bracketedObject = await read('/meta/view', { 'object[]': 'lead' });
707+
expect({ status: bracketedObject.status, code: bracketedObject.code, items: bracketedObject.items }).toEqual({ status: 400, code: 'VALIDATION_ERROR', items: undefined });
708+
const bracketedPackage = await read('/meta/view', { 'package[]': 'crm' });
709+
expect({ status: bracketedPackage.status, code: bracketedPackage.code, items: bracketedPackage.items }).toEqual({ status: 400, code: 'VALIDATION_ERROR', items: undefined });
700710
const docs = await read('/meta/docs');
701711
expect(text(docs)).not.toContain('Welcome aboard.');
702712
expect(text(await read('/meta/docs', { include: 'content' }))).toContain(DOC_SECRET);
@@ -871,6 +881,8 @@ const ITEM_PROBES: ReadonlyArray<{ label: string; param?: string; query: Record<
871881
{ label: '?preview=draft', param: 'preview', query: { preview: 'draft' } },
872882
{ label: '?preview=DRAFT', param: 'preview', query: { preview: 'DRAFT' } },
873883
{ label: '?package=crm', param: 'package', query: { package: 'crm' } },
884+
// A BRACKETED `package` key: an unknown name to the item read's closed set.
885+
{ label: '?package[]=crm', param: 'package', query: { 'package[]': 'crm' } },
874886
{ label: '?locale=zh-CN', param: 'locale', query: { locale: 'zh-CN' } },
875887
{ label: 'Accept-Language: zh-CN', query: {}, headers: { 'accept-language': 'zh-CN' } },
876888
// [#20478] The layered view's deprecated spelling — any non-empty value —
@@ -909,6 +921,8 @@ const TREE_CELLS: readonly string[] = ['admin_guide', 'help_center', 'public_gui
909921
const TREE_PROBES: ReadonlyArray<{ label: string; param?: string; query: Record<string, string>; headers?: Record<string, string> }> = [
910922
{ label: '(none)', query: {} },
911923
{ label: '?package=crm', param: 'package', query: { package: 'crm' } },
924+
// A BRACKETED `package` key is refused at the tree's arity step.
925+
{ label: '?package[]=crm', param: 'package', query: { 'package[]': 'crm' } },
912926
{ label: '?locale=zh-CN', param: 'locale', query: { locale: 'zh-CN' } },
913927
{ label: 'Accept-Language: zh-CN', query: {}, headers: { 'accept-language': 'zh-CN' } },
914928
];
@@ -923,6 +937,8 @@ const TREE_CALLERS = ['holder', 'non-holder', 'builder', 'anonymous'] as const s
923937
const LAYERS_PROBES: ReadonlyArray<{ label: string; param?: string; query: Record<string, string>; headers?: Record<string, string> }> = [
924938
{ label: '(none)', query: {} },
925939
{ label: '?package=crm', param: 'package', query: { package: 'crm' } },
940+
// A BRACKETED `package` key: an unknown name to the layered view's closed set.
941+
{ label: '?package[]=crm', param: 'package', query: { 'package[]': 'crm' } },
926942
{ label: 'Accept-Language: zh-CN', query: {}, headers: { 'accept-language': 'zh-CN' } },
927943
];
928944
const LAYERS_PARAM_AXIS = new Set(LAYERS_PROBES.map((p) => p.param).filter((p): p is string => !!p));

0 commit comments

Comments
 (0)