Skip to content

Commit c73f76b

Browse files
committed
feat(spec): the customizations read's contributions gain a nav kind with a per-kind entry shape
GetPackageCustomizationsResponseSchema.contributions becomes a discriminated union on `kind`: the field/flow entry (on an `object`, accepting exactly what it accepted before) and a nav entry (on an `app`, with an optional `group`, the nav item id as `name`, and `packageId`). The nav arm is declared ahead of its producer and says so with a `[PLANNED — not yet served]` marker, pinned in the test. Claude-Session: https://claude.ai/code/session_01ADHkmQ28WWiNo3u94yGTPb Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2f7977c commit c73f76b

2 files changed

Lines changed: 180 additions & 25 deletions

File tree

‎packages/spec/src/api/package-lifecycle.test.ts‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
PackagePublishResultSchema,
2222
EnsureCustomizationPackageRequestSchema,
2323
EnsureCustomizationPackageResponseSchema,
24+
GetPackageCustomizationsResponseSchema,
2425
} from './package-lifecycle.zod';
2526
import { PackagePublishResultSchema as SystemPackagePublishResultSchema } from '../system/metadata-persistence.zod';
2627

@@ -314,3 +315,106 @@ describe('EnsureCustomizationPackageResponseSchema declares the ensure door\'s a
314315
}
315316
});
316317
});
318+
319+
describe('GetPackageCustomizationsResponseSchema.contributions: the entry shape is per kind (ADR-0029 D7, ADR-0146 D3)', () => {
320+
const CONTRIBUTOR = 'com.example.acme-sync';
321+
const FIELD = { kind: 'field', object: 'crm_account', name: 'acme_sync_id', packageId: CONTRIBUTOR };
322+
const FLOW = { kind: 'flow', object: 'crm_account', name: 'acme_account_sync', packageId: CONTRIBUTOR };
323+
const NAV_IN_GROUP = { kind: 'nav', app: 'crm', group: 'group_service', name: 'nav_acme_sync', packageId: CONTRIBUTOR };
324+
const NAV_TOP_LEVEL = { kind: 'nav', app: 'crm', name: 'nav_acme_console', packageId: CONTRIBUTOR };
325+
326+
/** A whole answer around `contributions`, its count derived the way the producer derives it. */
327+
const answer = (contributions: unknown[]) => ({
328+
packageId: 'com.acme.crm',
329+
overrides: [],
330+
extensions: [],
331+
switchedOff: [],
332+
contributions,
333+
counts: { overrides: 0, extensions: 0, switchedOff: 0, contributions: contributions.length },
334+
});
335+
336+
/** The single issue a refused answer carries, by code and path. */
337+
const refusalOf = (contributions: unknown[]) => {
338+
const result = GetPackageCustomizationsResponseSchema.safeParse(answer(contributions));
339+
expect(result.success).toBe(false);
340+
return result.success ? [] : result.error.issues.map((issue) => ({
341+
code: issue.code,
342+
path: issue.path,
343+
keys: (issue as { keys?: string[] }).keys,
344+
}));
345+
};
346+
347+
it('CONTROL: a field and a flow entry parse and are PRESERVED, exactly as before the nav kind', () => {
348+
const served = answer([FIELD, FLOW]);
349+
const result = GetPackageCustomizationsResponseSchema.safeParse(served);
350+
expect(result.success, JSON.stringify(result.success ? null : result.error.issues)).toBe(true);
351+
if (result.success) expect(result.data).toEqual(served);
352+
});
353+
354+
it('CONTROL: a field entry still requires its `object`', () => {
355+
const { object: _dropped, ...noObject } = FIELD;
356+
expect(refusalOf([noObject])).toEqual([{ code: 'invalid_type', path: ['contributions', 0, 'object'], keys: undefined }]);
357+
});
358+
359+
it('a nav entry naming the group its contribution targets parses and is PRESERVED', () => {
360+
const served = answer([FIELD, NAV_IN_GROUP]);
361+
const result = GetPackageCustomizationsResponseSchema.safeParse(served);
362+
expect(result.success, JSON.stringify(result.success ? null : result.error.issues)).toBe(true);
363+
if (result.success) expect(result.data).toEqual(served);
364+
});
365+
366+
it('a nav entry contributed to the app\'s top level has no group, and none is invented', () => {
367+
const result = GetPackageCustomizationsResponseSchema.safeParse(answer([NAV_TOP_LEVEL]));
368+
expect(result.success, JSON.stringify(result.success ? null : result.error.issues)).toBe(true);
369+
if (result.success) {
370+
expect(result.data.contributions).toEqual([NAV_TOP_LEVEL]);
371+
expect('group' in result.data.contributions[0]).toBe(false);
372+
}
373+
});
374+
375+
it('a nav entry carrying `object` is refused: the nav shape is on an app, never an object', () => {
376+
expect(refusalOf([{ ...NAV_IN_GROUP, object: 'crm_account' }]))
377+
.toEqual([{ code: 'unrecognized_keys', path: ['contributions', 0], keys: ['object'] }]);
378+
});
379+
380+
it('a field or flow entry carrying `app` or `group` is refused: those shapes are on an object', () => {
381+
expect(refusalOf([{ ...FIELD, app: 'crm' }]))
382+
.toEqual([{ code: 'unrecognized_keys', path: ['contributions', 0], keys: ['app'] }]);
383+
expect(refusalOf([{ ...FLOW, group: 'group_service' }]))
384+
.toEqual([{ code: 'unrecognized_keys', path: ['contributions', 0], keys: ['group'] }]);
385+
});
386+
387+
it('a nav entry requires its app, its item id and its package', () => {
388+
for (const key of ['app', 'name', 'packageId'] as const) {
389+
const partial: Record<string, unknown> = { ...NAV_IN_GROUP };
390+
delete partial[key];
391+
expect(refusalOf([partial]), key).toEqual([{ code: 'invalid_type', path: ['contributions', 0, key], keys: undefined }]);
392+
}
393+
});
394+
395+
it('a kind outside field, flow and nav is still refused', () => {
396+
const issues = refusalOf([{ ...FIELD, kind: 'action' }]);
397+
expect(issues).toHaveLength(1);
398+
expect(issues[0]).toMatchObject({ code: 'invalid_union', path: ['contributions', 0, 'kind'] });
399+
});
400+
});
401+
402+
describe('the `nav` kind of `contributions` is declared ahead of its producer (ADR-0049)', () => {
403+
type Described = { description?: string };
404+
const member = (GetPackageCustomizationsResponseSchema as unknown as {
405+
shape: { contributions: Described & { element: { options: Described[] } } };
406+
}).shape.contributions;
407+
const [objectArm, navArm] = member.element.options;
408+
409+
it('the nav arm\'s describe opens with the planned marker and names the ADR, never a tracker id', () => {
410+
expect(navArm.description).toMatch(/^\[PLANNED — not yet served\] /);
411+
expect(navArm.description).toContain('ADR-0049');
412+
expect(navArm.description).not.toMatch(/#\d{3,}/);
413+
});
414+
415+
it('the member and the field / flow arm say the nav kind is not yet served, and the field / flow arm carries no marker', () => {
416+
expect(member.description).toContain('not yet served');
417+
expect(objectArm.description).not.toMatch(/PLANNED/);
418+
expect(member.description).not.toMatch(/#\d{3,}/);
419+
});
420+
});

‎packages/spec/src/api/package-lifecycle.zod.ts‎

Lines changed: 76 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,29 @@ export const GetPackageCustomizationsRequestSchema = lazySchema(() => z.object({
351351
* the same read names what OTHER installed packages bring to X's surface, so
352352
* Studio can draw those items greyed with their source: `contributions`, one
353353
* entry per item, each stamped with the package that contributes it. What is
354-
* listed is exactly two kinds: the fields another package's object extension
355-
* adds to an object X owns, and the flows another package ships whose trigger
356-
* object X owns. The stamp is on the item, so two packages adding a field of
357-
* the same name are two entries and nothing is joined by name on the client.
358-
* Neither X's own items nor its pair's are contributions: a pair item that
359-
* overrides one of X's (a flow included) is in `overrides`, the pair's
360-
* extension members are in `extensions`, and any other pair flow is in no
361-
* list of this answer.
354+
* listed is exactly three kinds: the fields another package's object extension
355+
* adds to an object X owns, the flows another package ships whose trigger
356+
* object X owns, and the navigation items another package's
357+
* `navigationContributions` add to an app X owns. The entry shape is per kind:
358+
* a `field` or `flow` entry names the base-owned `object` it is on; a `nav`
359+
* entry names the base-owned `app` and, when the contribution targets one,
360+
* its `group`, and never an `object`. The stamp is on the item, so two
361+
* packages adding a field of the same name are two entries and nothing is
362+
* joined by name on the client. Neither X's own items nor its pair's are
363+
* contributions: a pair item that overrides one of X's (a flow included) is in
364+
* `overrides`, the pair's extension members are in `extensions`, and any other
365+
* pair flow is in no list of this answer.
366+
*
367+
* [#27928, ruling 6566915346 letter E] DECLARED AHEAD OF ITS PRODUCER
368+
* (ADR-0049): the `nav` kind is declared before the runtime serves it. Until
369+
* the server slice of #28722 (Wanted 3) reads the navigation-contribution
370+
* registry, this read lists no `nav` entry; the `nav` arm's describe opens
371+
* `[PLANNED — not yet served]`, and that slice drops the marker in the change
372+
* that serves the kind. When served, a `nav` entry MUST be read from the same
373+
* `appNavContributions` registry the served app's navigation fold reads
374+
* (ADR-0029 D7), never joined by name; a disabled package's contributions
375+
* MUST NOT be listed, as the fold drops them; and the served app's
376+
* `navigation` stays as declared: no nav item carries a contributor key.
362377
*/
363378
export const GetPackageCustomizationsResponseSchema = lazySchema(() => z.object({
364379
packageId: z.string().describe('The base package the customizations are of (the request\'s id).'),
@@ -403,23 +418,59 @@ export const GetPackageCustomizationsResponseSchema = lazySchema(() => z.object(
403418
'Every activation-ledger row (`sys_metadata_activation`) that records the base as its package and '
404419
+ '`active: false`: the base\'s items this deployment switched off. Ordered by type and name.',
405420
),
406-
contributions: z.array(z.object({
407-
kind: z.enum(['field', 'flow']).describe(
408-
'What is contributed: `field`, a field another package\'s object extension (`objectExtensions`) adds to '
409-
+ 'one of the base\'s objects; `flow`, a flow another package ships whose trigger object (its `start` '
410-
+ 'node\'s `config.objectName`) is one of the base\'s objects.',
411-
),
412-
object: z.string().describe('The base-owned object the item is on: the extended object, or the flow\'s trigger object.'),
413-
name: z.string().describe('The item\'s name: the field name as the extension declares it, or the flow\'s name.'),
414-
packageId: z.string().describe(
415-
'The package that contributes the item: the extension\'s package, or the package the flow is registered '
416-
+ 'under. Never the base and never its `<base>.custom` pair.',
421+
// The entry shape is per kind (#27928, ruling 6566915346 letter E): a
422+
// `field` / `flow` entry is on an `object`, a `nav` entry on an `app`. The
423+
// `field` / `flow` arm accepts exactly what the member's one entry shape
424+
// accepted before the `nav` kind (the CONTROL pins in the test).
425+
contributions: z.array(z.discriminatedUnion('kind', [
426+
z.object({
427+
kind: z.enum(['field', 'flow']).describe(
428+
'What is contributed: `field`, a field another package\'s object extension (`objectExtensions`) adds to '
429+
+ 'one of the base\'s objects; `flow`, a flow another package ships whose trigger object (its `start` '
430+
+ 'node\'s `config.objectName`) is one of the base\'s objects.',
431+
),
432+
object: z.string().describe('The base-owned object the item is on: the extended object, or the flow\'s trigger object.'),
433+
name: z.string().describe('The item\'s name: the field name as the extension declares it, or the flow\'s name.'),
434+
packageId: z.string().describe(
435+
'The package that contributes the item: the extension\'s package, or the package the flow is registered '
436+
+ 'under. Never the base and never its `<base>.custom` pair.',
437+
),
438+
}).strict().describe('A field or flow another package contributes to one of the base\'s objects.'),
439+
// Declared ahead of its producer: the server slice of #28722 (Wanted 3)
440+
// serves this arm and drops the `[PLANNED — not yet served]` marker in the
441+
// same change (the pin is in `package-lifecycle.test.ts`).
442+
z.object({
443+
kind: z.literal('nav').describe(
444+
'What is contributed: `nav`, a navigation item another package\'s `navigationContributions` entry adds '
445+
+ 'to the navigation of an app the base owns.',
446+
),
447+
app: z.string().describe('The base-owned app the item is contributed to: the contribution\'s `app`.'),
448+
group: z.string().optional().describe(
449+
'The group nav item the contribution targets: its `group`, as the contribution declares it. Absent when '
450+
+ 'the contribution targets the app\'s top level. A group the app does not declare is still named here, '
451+
+ 'though the served navigation appends those items at the app\'s top level.',
452+
),
453+
name: z.string().describe('The nav item\'s id, as the contribution\'s `items` declare it.'),
454+
packageId: z.string().describe(
455+
'The package that contributes the item: the package whose `navigationContributions` declares it. Never '
456+
+ 'the base and never its `<base>.custom` pair.',
457+
),
458+
}).strict().describe(
459+
'[PLANNED — not yet served] Declared ahead of its producer (ADR-0049): the read lists no `nav` entry yet. '
460+
+ 'A navigation item another installed package contributes to an app the base owns, one entry per item of '
461+
+ 'the contribution\'s `items` (a contributed group\'s children ride inside it and are not entries of their '
462+
+ 'own), read from the same contribution registry the served app\'s navigation fold reads (ADR-0029 D7). '
463+
+ 'A disabled package\'s contributions are not listed, as the fold drops them.',
417464
),
418-
}).strict()).describe(
419-
'Every field and flow another installed package contributes to the base\'s objects, one entry per item and '
420-
+ 'contributing package: the fields of every object extension of an object the base owns, from any package '
421-
+ 'but the base and its pair, and every flow registered under such a package whose trigger object the base '
422-
+ 'owns (a flow of a disabled package is not served, so not listed). Ordered by object, kind, name and package.',
465+
])).describe(
466+
'Every field, flow and navigation item another installed package contributes to the base, one entry per '
467+
+ 'item and contributing package: the fields of every object extension of an object the base owns, from any '
468+
+ 'package but the base and its pair; every flow registered under such a package whose trigger object the '
469+
+ 'base owns (a flow of a disabled package is not served, so not listed); and, declared ahead of its producer '
470+
+ 'and not yet served, every navigation item such a package contributes to an app the base owns. The entry '
471+
+ 'shape is per `kind`: `object` for `field` and `flow`, `app` and an optional `group` for `nav`. Ordered: '
472+
+ 'the `field` and `flow` entries first, by object, kind, name and package; then the `nav` entries, by app, '
473+
+ 'group (an entry with no group first), name and package.',
423474
),
424475
counts: z.object({
425476
overrides: z.number().int().nonnegative().describe('`overrides.length`.'),
@@ -429,7 +480,7 @@ export const GetPackageCustomizationsResponseSchema = lazySchema(() => z.object(
429480
}).strict().describe('Each list\'s length, derived from the lists in this same answer.'),
430481
}).strict().describe(
431482
'Per-package customization read: overrides, extensions and switched-off items of one installed base, and the '
432-
+ 'fields and flows other packages contribute to it.',
483+
+ 'fields, flows and (not yet served) navigation items other packages contribute to it.',
433484
));
434485

435486
/**

0 commit comments

Comments
 (0)