Skip to content

Commit c980b18

Browse files
committed
test(objectql, dogfood): pin the picklist's by-name read by package, and its changeset
Claude-Session: https://claude.ai/code/session_01ADHkmPVZExCQQ1dwRy6Cbp Co-authored-by: Claude <noreply@anthropic.com>
1 parent ae2a7b3 commit c980b18

3 files changed

Lines changed: 151 additions & 5 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@objectstack/objectql': patch
3+
---
4+
5+
fix(objectql)!: the by-name picklist read answers by package — a bare read of a name two packages hold is refused naming both, and a qualified read reaches only its own holder (ADR-0150 D3)
6+
7+
Clause-②: no (narrowing)
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) no metadata shape, schema, stored row or registered node type changes: the change is which picklist a by-name read answers, the stored metadata is read exactly as before, so there is nothing for `objectstack migrate meta` to rewrite -->
11+
12+
The picklist joins the types whose by-name readers consult `(package, name)`, so `GET /api/v1/meta/picklist/:name`, its qualified forms and the metadata service's by-name read go through the one package-scoped resolver. A select field's `picklist:` is unchanged: it already resolves in its own package. A name one package holds is served exactly as before at the bare address and at its holder's qualified addresses.
13+
14+
**BREAKING** for answers that served one package's list for an address that does not name it (first-party count: 0 — no first-party package ships a picklist name another package also ships, and nothing first-party reads a picklist at a package that does not hold it):
15+
16+
1. A bare `GET /meta/picklist/:name` of a name two packages hold served the first registered. It is now `409 RESOURCE_CONFLICT` naming both. Phase 1's install door already refuses the second holder, so only a deployment that booted with the clash (and was warned at boot) holds it.
17+
2. A qualified read that names a package not holding the name — `/meta/picklist/<namespace>/:name`, `?package=<id>`, or `/meta/picklist/_env/:name` when only a package holds it — answered `200` with another package's list. It is now `409 RESOURCE_CONFLICT` naming the holder.
18+
19+
The fix for each:
20+
21+
- FROM a bare read of a two-holder name TO `?package=<id>` or `/meta/picklist/<namespace>/:name`.
22+
- FROM a qualified read naming a non-holder TO the holder's own namespace (the refusal names it), or the bare address without a qualifier.

‎packages/objectql/src/package-scoped-e8-readers.test.ts‎

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const P = 'com.acme.caller';
4949

5050
/** The nine types this card wires, as the registry spells them. */
5151
const E8_TYPES = ['app', 'page', 'dashboard', 'report', 'book', 'analytics_cube', 'tool', 'skill', 'agent'] as const;
52+
/** The types wired since, each by its own card: the picklist's bare read (#32070). */
53+
const WIRED_SINCE = ['picklist'] as const;
5254
/** Of them, the ones phase 1's one-holder refusal does not cover: two package holders can exist today. */
5355
const UNCOVERED = E8_TYPES.filter((t) => !(BARE_NAME_REGISTRY_TYPES as readonly string[]).includes(t));
5456

@@ -69,6 +71,8 @@ const install = (id: string, deps: string[] = []) => registry.installPackage(man
6971
const body = (type: string, name: string, tag: string): Record<string, unknown> =>
7072
type === 'skill'
7173
? { name, label: `${tag} skill`, description: `${tag} skill`, instructions: tag, tools: [] }
74+
: type === 'picklist'
75+
? { name, label: `${tag} picklist`, options: [{ label: `${tag} one`, value: `${tag}_one` }] }
7276
: type === 'agent'
7377
? { name, label: `${tag} agent`, role: tag, instructions: tag }
7478
: { name, label: `${tag} ${type}` };
@@ -114,9 +118,9 @@ beforeEach(() => {
114118
install(B);
115119
});
116120

117-
describe('E8 wires exactly the nine types, every one of them package-scoped', () => {
118-
it('PACKAGE_SCOPED_READ_TYPES is the card\'s nine, each one R addresses by package', () => {
119-
expect([...PACKAGE_SCOPED_READ_TYPES].sort()).toEqual([...E8_TYPES].sort());
121+
describe('E8 wires the nine types, and later cards their own, every one of them package-scoped', () => {
122+
it('PACKAGE_SCOPED_READ_TYPES is the card\'s nine plus the types wired since, each one R addresses by package', () => {
123+
expect([...PACKAGE_SCOPED_READ_TYPES].sort()).toEqual([...E8_TYPES, ...WIRED_SINCE].sort());
120124
for (const type of PACKAGE_SCOPED_READ_TYPES) expect(isPackageScopedType(type), type).toBe(true);
121125
});
122126
});
@@ -265,3 +269,63 @@ describe('the types E8 does not wire keep the legacy read', () => {
265269
expect(labelOf(await facade.get('flow', 'onboard', P))).toBe('alpha flow');
266270
});
267271
});
272+
273+
/**
274+
* #32070 (a reader epic #31527's child B for the data family needs first): the
275+
* bare `GET /meta/picklist/NAME` read answers by ADR-0150 D3. A field's
276+
* `picklist:` already resolves by its referrer's package (child E6,
277+
* `engine-picklist.test.ts`) and does not read through here.
278+
*
279+
* Two holders exist only on a deployment that booted with the clash (phase 1's
280+
* install door refuses the second; the cold boot warns): here the registry is
281+
* never sealed, so both packages hold the name.
282+
*/
283+
describe('#32070 — the picklist\'s by-name read answers by package (ADR-0150 D3)', () => {
284+
const solo = () => {
285+
ship('picklist', 'tone', A);
286+
return registry.getItem('picklist', 'tone');
287+
};
288+
289+
it('CONTROL: one holder is served as before — the bare read, both faces, the exact qualifier, the facade', async () => {
290+
const before = solo();
291+
expect(labelOf(before)).toBe('alpha picklist');
292+
const bare = (await protocol.getMetaItem({ type: 'picklist', name: 'tone' }))?.item;
293+
const exact = (await protocol.getMetaItem({ type: 'picklist', name: 'tone', packageId: A }))?.item;
294+
expect(bare).toEqual(exact);
295+
expect(labelOf(bare)).toBe('alpha picklist');
296+
expect((bare as { options?: unknown }).options).toEqual((before as { options?: unknown }).options);
297+
expect(labelOf((await protocol.getMetaItemForExecution({ type: 'picklist', name: 'tone' }))?.item)).toBe('alpha picklist');
298+
expect(await facade.get('picklist', 'tone')).toBe(before);
299+
expect(facade.getEntry('picklist', 'tone')).toBe(before);
300+
expect(await facade.get('picklist', 'tone', A)).toBe(before);
301+
});
302+
303+
it('CONTROL: zero holders stays not-found, and the environment\'s own list is served to a caller with no package', async () => {
304+
expect((await protocol.getMetaItem({ type: 'picklist', name: 'nothing' }))?.item).toBeUndefined();
305+
envItem('picklist', 'local');
306+
expect(labelOf((await protocol.getMetaItem({ type: 'picklist', name: 'local' }))?.item)).toBe('env picklist');
307+
});
308+
309+
it('two holders: the bare read refuses naming both (both faces, the facade), never the first registered', async () => {
310+
ship('picklist', 'tone', A);
311+
ship('picklist', 'tone', B);
312+
await expectRefusal(() => protocol.getMetaItem({ type: 'picklist', name: 'tone' }), 'ambiguous-in-environment', [A, B]);
313+
await expectRefusal(() => protocol.getMetaItemForExecution({ type: 'picklist', name: 'tone' }), 'ambiguous-in-environment', [A, B]);
314+
await expectRefusal(() => facade.get('picklist', 'tone'), 'ambiguous-in-environment', [A, B]);
315+
expect(await facade.exists('picklist', 'tone')).toBe(true);
316+
});
317+
318+
it('two holders: each package caller and each exact qualifier reaches its own list', async () => {
319+
ship('picklist', 'tone', A);
320+
ship('picklist', 'tone', B);
321+
expect(labelOf(await facade.get('picklist', 'tone', A))).toBe('alpha picklist');
322+
expect(labelOf(await facade.get('picklist', 'tone', B))).toBe('beta picklist');
323+
expect(labelOf((await protocol.getMetaItem({ type: 'picklist', name: 'tone', packageId: A }))?.item)).toBe('alpha picklist');
324+
expect(labelOf((await protocol.getMetaItem({ type: 'picklist', name: 'tone', packageId: B }))?.item)).toBe('beta picklist');
325+
});
326+
327+
it('the exact qualifier of a package that does not hold the name is refused naming the holder, never another package\'s list', async () => {
328+
solo();
329+
await expectRefusal(() => protocol.getMetaItem({ type: 'picklist', name: 'tone', packageId: B }), 'not-held-by-qualifier', [A]);
330+
});
331+
});

‎packages/qa/dogfood/test/bare-name-one-holder.dogfood.test.ts‎

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
// holders and the rename, and installs nothing;
1919
// - the same door refusing a package that redeclares the showcase's own
2020
// mapping and dataset names, naming the showcase;
21-
// - CONTROL: a package declaring fresh names installs.
21+
// - CONTROL: a package declaring fresh names installs;
22+
// - [#32070] the picklist's by-name read on that clash answers by ADR-0150
23+
// D3: the bare `GET /meta/picklist/NAME` is 409 naming both holders, each
24+
// qualified address reaches its own list, a qualifier that does not hold
25+
// the name is refused, and each field still serves its own package's
26+
// options (child E6). CONTROL: a name one package holds is served as
27+
// before at the bare and the holder's addresses.
2228

2329
import { mkdtempSync, rmSync } from 'node:fs';
2430
import { tmpdir } from 'node:os';
@@ -37,6 +43,8 @@ const SHOWCASE_DATASET = 'showcase_task_metrics';
3743
const PICKLIST = 'qa_shared_status';
3844
const MAPPING = 'qa_shared_mapping';
3945
const DATASET = 'qa_shared_dataset';
46+
/** A picklist only `alpha` holds: the one-holder CONTROL. */
47+
const SOLO_PICKLIST = 'qa_alpha_status';
4048

4149
const picklist = (p: string, name = PICKLIST) => ({
4250
name, label: `${p} status`, options: [{ label: `${p} one`, value: `${p}_one` }],
@@ -66,7 +74,7 @@ function bootPackage(p: 'alpha' | 'beta') {
6674
},
6775
},
6876
],
69-
picklists: [picklist(p)],
77+
picklists: [picklist(p), ...(p === 'alpha' ? [picklist(p, SOLO_PICKLIST)] : [])],
7078
mappings: [mapping(p)],
7179
datasets: [dataset(p)],
7280
} as never);
@@ -187,6 +195,58 @@ describe('one package holder per picklist, mapping and dataset name, on a booted
187195
expect(await packageIds(), 'the package list is unchanged').toEqual(before);
188196
});
189197

198+
describe('[#32070] the picklist\'s by-name read answers by package (ADR-0150 D3)', () => {
199+
const read = async (path: string) => {
200+
const res = await stack.apiAs(admin, 'GET', path);
201+
return { status: res.status, body: (await res.json()) as any };
202+
};
203+
const labelOf = (body: any) => body?.item?.label ?? body?.data?.item?.label;
204+
const sentenceOf = (body: any) => String(typeof body?.error === 'string' ? body.error : body?.error?.message ?? '');
205+
206+
it('the bare read of a name both packages hold is 409 RESOURCE_CONFLICT naming both, never the first registered', async () => {
207+
const { status, body } = await read(`/meta/picklist/${PICKLIST}`);
208+
expect([status, codeOf(body)], JSON.stringify(body)).toEqual([409, 'RESOURCE_CONFLICT']);
209+
expect(sentenceOf(body)).toContain('com.qa.bare.alpha');
210+
expect(sentenceOf(body)).toContain('com.qa.bare.beta');
211+
});
212+
213+
it('each namespace address and each `?package=` reaches its own package\'s list', async () => {
214+
for (const p of ['alpha', 'beta']) {
215+
for (const path of [`/meta/picklist/${p}/${PICKLIST}`, `/meta/picklist/${PICKLIST}?package=com.qa.bare.${p}`]) {
216+
const { status, body } = await read(path);
217+
expect(status, `${path} ${JSON.stringify(body)}`).toBe(200);
218+
expect(labelOf(body), path).toBe(`${p} status`);
219+
}
220+
}
221+
});
222+
223+
it('a qualifier that does not hold the name is refused naming its holder, never served another package\'s list', async () => {
224+
for (const path of [`/meta/picklist/beta/${SOLO_PICKLIST}`, `/meta/picklist/${SOLO_PICKLIST}?package=com.qa.bare.beta`, `/meta/picklist/_env/${SOLO_PICKLIST}`]) {
225+
const { status, body } = await read(path);
226+
expect([status, codeOf(body)], `${path} ${JSON.stringify(body)}`).toEqual([409, 'RESOURCE_CONFLICT']);
227+
expect(sentenceOf(body), path).toContain('com.qa.bare.alpha');
228+
}
229+
});
230+
231+
it('CONTROL: a name one package holds is served at the bare address and at the holder\'s qualified addresses', async () => {
232+
for (const path of [`/meta/picklist/${SOLO_PICKLIST}`, `/meta/picklist/alpha/${SOLO_PICKLIST}`, `/meta/picklist/${SOLO_PICKLIST}?package=com.qa.bare.alpha`]) {
233+
const { status, body } = await read(path);
234+
expect(status, `${path} ${JSON.stringify(body)}`).toBe(200);
235+
expect(labelOf(body), path).toBe('alpha status');
236+
}
237+
});
238+
239+
it('each field still serves its own package\'s options (child E6)', async () => {
240+
for (const p of ['alpha', 'beta']) {
241+
const { status, body } = await read(`/meta/object/${p}_item`);
242+
expect(status).toBe(200);
243+
const object = body?.data ?? body;
244+
const options = object?.fields?.status?.options ?? object?.item?.fields?.status?.options;
245+
expect(options, `${p}_item.status`).toEqual([{ label: `${p} one`, value: `${p}_one` }]);
246+
}
247+
});
248+
});
249+
190250
it('CONTROL — install-local of a package declaring fresh names installs', async () => {
191251
const { status, body } = await installLocal(inline('epsilon', {
192252
picklists: [picklist('epsilon', 'epsilon_status')],

0 commit comments

Comments
 (0)