Skip to content

Commit 8b347c0

Browse files
committed
test(runtime): pin the nav kind of the customizations contributions, red on main
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 744211f commit 8b347c0

1 file changed

Lines changed: 131 additions & 10 deletions

File tree

‎packages/runtime/src/domains/packages-customizations.test.ts‎

Lines changed: 131 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ function baseManifest(): Record<string, unknown> {
191191
columns: ['title', 'status', 'due_date'].map((field) => ({ field })),
192192
},
193193
}],
194+
// [#28722] The base's app, with the group other packages contribute into.
195+
apps: [{
196+
name: 'showcase',
197+
label: 'Showcase',
198+
navigation: [{
199+
id: 'showcase_work',
200+
type: 'group',
201+
label: 'Work',
202+
children: [{ id: 'showcase_tasks', type: 'object', label: 'Tasks', objectName: 'showcase_task' }],
203+
}],
204+
}],
194205
};
195206
}
196207

@@ -206,6 +217,11 @@ function otherManifest(): Record<string, unknown> {
206217
sharingModel: 'private',
207218
fields: { body: { name: 'body', label: 'Body', type: 'text' } },
208219
}],
220+
apps: [{
221+
name: 'other_app',
222+
label: 'Other',
223+
navigation: [{ id: 'other_notes', type: 'object', label: 'Notes', objectName: 'other_note' }],
224+
}],
209225
};
210226
}
211227

@@ -507,8 +523,23 @@ const flowOn = (name: string, object: string) => ({
507523
edges: [{ id: 'e1', source: 'start', target: 'end' }],
508524
});
509525

510-
/** A code package registered as the engine registers every manifest: an object extension and flows. */
511-
const registerContributor = (engine: ObjectQL, id: string, fields: readonly string[], flows: ReadonlyArray<ReturnType<typeof flowOn>>) =>
526+
/** One `navigationContributions` entry of a manifest (ADR-0029 D7). */
527+
type NavContribution = { app: string; group?: string; priority?: number; items: Array<Record<string, unknown>> };
528+
529+
/** A url nav item: the smallest item that carries an id. */
530+
const navLink = (id: string) => ({ id, type: 'url', label: id, url: `/${id}` });
531+
532+
/**
533+
* A code package registered as the engine registers every manifest: an object
534+
* extension, flows, and the navigation it contributes to other packages' apps.
535+
*/
536+
const registerContributor = (
537+
engine: ObjectQL,
538+
id: string,
539+
fields: readonly string[],
540+
flows: ReadonlyArray<ReturnType<typeof flowOn>>,
541+
navigationContributions: readonly NavContribution[] = [],
542+
) =>
512543
engine.registerApp({
513544
id,
514545
name: id.split('.').join('-'),
@@ -518,13 +549,16 @@ const registerContributor = (engine: ObjectQL, id: string, fields: readonly stri
518549
fields: Object.fromEntries(fields.map((f) => [f, { name: f, label: f, type: 'text' }])),
519550
}],
520551
flows: [...flows],
552+
navigationContributions: [...navigationContributions],
521553
});
522554

523555
/**
524-
* The card's fixture (#28722): the base ships a flow on its object, the pair
525-
* extends that object and carries a flow on it, and a third code package
526-
* extends the same object with a field and ships a flow on it — plus a flow
527-
* on an object the base does not own.
556+
* The card's fixture (#28722): the base ships a flow on its object and an app,
557+
* the pair extends that object, carries a flow on it and contributes a nav
558+
* item to the base's app, and a third code package extends the same object
559+
* with a field, ships a flow on it and contributes a nav item into the base
560+
* app's group — plus a flow on an object the base does not own. The base
561+
* contributing to its own app is the base's item, not a contribution.
528562
*/
529563
async function contributedFixture() {
530564
const booted = await boot();
@@ -533,21 +567,30 @@ async function contributedFixture() {
533567
await install(protocol, PAIR);
534568
extend(engine, PAIR, 'showcase_task', { fields: { region__c: { name: 'region__c', label: 'Region', type: 'text' } } });
535569
engine.registry.registerItem('flow', flowOn('showcase_task_region_notify', 'showcase_task'), 'name', PAIR);
536-
registerContributor(engine, THIRD, ['acme_sync_id'], [flowOn('acme_task_sync', 'showcase_task'), flowOn('acme_note_sync', 'other_note')]);
570+
engine.registry.registerAppNavContribution({ app: 'showcase', items: [navLink('showcase_region_board')] }, PAIR);
571+
engine.registry.registerAppNavContribution({ app: 'showcase', group: 'showcase_work', items: [navLink('showcase_inbox')] }, BASE);
572+
registerContributor(
573+
engine,
574+
THIRD,
575+
['acme_sync_id'],
576+
[flowOn('acme_task_sync', 'showcase_task'), flowOn('acme_note_sync', 'other_note')],
577+
[{ app: 'showcase', group: 'showcase_work', items: [navLink('acme_sync_log')] }],
578+
);
537579
return booted;
538580
}
539581

540582
describe('[#28722] GET /packages/:id/customizations — the fields and flows other packages contribute to a base', () => {
541-
it('names the third package for its extension field and its flow, and names neither the base nor the pair', async () => {
583+
it('names the third package for its extension field, its flow and its nav item, and names neither the base nor the pair', async () => {
542584
const { dispatcher } = await contributedFixture();
543585
const r = await customizations(dispatcher, BASE);
544586
expect(r.response?.status).toBe(200);
545587
const data = r.response?.body?.data;
546588
expect(data.contributions).toEqual([
547589
{ kind: 'field', object: 'showcase_task', name: 'acme_sync_id', packageId: THIRD },
548590
{ kind: 'flow', object: 'showcase_task', name: 'acme_task_sync', packageId: THIRD },
591+
{ kind: 'nav', app: 'showcase', group: 'showcase_work', name: 'acme_sync_log', packageId: THIRD },
549592
]);
550-
expect(data.counts.contributions).toBe(2);
593+
expect(data.counts.contributions).toBe(3);
551594
// The pair's member stays where N-15 serves it, and is not a contribution.
552595
expect(data.extensions).toEqual([{ object: 'showcase_task', kind: 'field', name: 'region__c' }]);
553596
const parsed = GetPackageCustomizationsResponseSchema.safeParse(data);
@@ -571,7 +614,7 @@ describe('[#28722] GET /packages/:id/customizations — the fields and flows oth
571614
engine.registry.registerItem('flow', { ...flowOn('showcase_task_local', 'showcase_task'), _packageId: 'sys_metadata' } as any);
572615
engine.registry.registerItem('flow', { ...flowOn('showcase_task_org', 'showcase_task'), _packageId: THIRD, _provenance: 'org' } as any);
573616
const { contributions } = (await customizations(dispatcher, BASE)).response?.body?.data;
574-
expect(contributions.map((c: any) => `${c.kind}:${c.name}`)).toEqual(['field:acme_sync_id', 'flow:acme_task_sync']);
617+
expect(contributions.map((c: any) => `${c.kind}:${c.name}`)).toEqual(['field:acme_sync_id', 'flow:acme_task_sync', 'nav:acme_sync_log']);
575618
});
576619

577620
it('reads a field\'s stamp and a flow\'s stamp the same way: each stamp lists both kinds or neither', async () => {
@@ -608,3 +651,81 @@ describe('[#28722] GET /packages/:id/customizations — the fields and flows oth
608651
expect(data.counts.contributions).toBe(1);
609652
});
610653
});
654+
655+
/** Every nav item id of a folded navigation tree, depth first. */
656+
const navIds = (items: unknown): string[] => (Array.isArray(items) ? items : []).flatMap((item: any) => [
657+
...(typeof item?.id === 'string' ? [item.id] : []),
658+
...navIds(item?.children),
659+
]);
660+
661+
describe('[#28722] GET /packages/:id/customizations — the navigation items other packages contribute to a base\'s app', () => {
662+
/** The `nav` entries of the base's answer. */
663+
const navOf = async (dispatcher: HttpDispatcher, id = BASE) =>
664+
((await customizations(dispatcher, id)).response?.body?.data.contributions as any[]).filter((c) => c.kind === 'nav');
665+
666+
it('lists one entry per item a contribution declares with an id, naming its group, the no-group entries first', async () => {
667+
const { dispatcher, engine } = await contributedFixture();
668+
registerContributor(engine, FOURTH, [], [], [
669+
// A top-level contribution: a link, a separator with no id (no
670+
// `name` to give, so not an entry), and a group whose child rides
671+
// inside it and is not an entry of its own.
672+
{ app: 'showcase', items: [
673+
navLink('partner_home'),
674+
{ type: 'separator' },
675+
{ id: 'partner_tools', type: 'group', label: 'Tools', children: [navLink('partner_tool_a')] },
676+
] },
677+
// A group the app does not declare: still named, though the fold
678+
// appends the item at the app's top level.
679+
{ app: 'showcase', group: 'showcase_missing', items: [navLink('partner_help')] },
680+
]);
681+
expect(await navOf(dispatcher)).toEqual([
682+
{ kind: 'nav', app: 'showcase', name: 'partner_home', packageId: FOURTH },
683+
{ kind: 'nav', app: 'showcase', name: 'partner_tools', packageId: FOURTH },
684+
{ kind: 'nav', app: 'showcase', group: 'showcase_missing', name: 'partner_help', packageId: FOURTH },
685+
{ kind: 'nav', app: 'showcase', group: 'showcase_work', name: 'acme_sync_log', packageId: THIRD },
686+
]);
687+
const { data } = (await customizations(dispatcher, BASE)).response?.body ?? {};
688+
expect(data.contributions.slice(0, 2).map((c: any) => c.kind), 'the field and flow entries come first').toEqual(['field', 'flow']);
689+
const parsed = GetPackageCustomizationsResponseSchema.safeParse(data);
690+
expect(parsed.success, JSON.stringify(parsed.error?.issues)).toBe(true);
691+
});
692+
693+
it('a disabled package\'s contributions are not listed, as the fold drops them, and re-enabling restores them', async () => {
694+
const { dispatcher, engine } = await contributedFixture();
695+
registerContributor(engine, FOURTH, [], [], [{ app: 'showcase', items: [navLink('partner_home')] }]);
696+
// AGREEMENT with the fold: the listed names are the served app's ids
697+
// that neither the base nor its pair put there.
698+
const ownIds = new Set(['showcase_work', 'showcase_tasks', 'showcase_inbox', 'showcase_region_board']);
699+
const servedContributed = () => navIds(engine.registry.getApp('showcase')?.navigation).filter((id) => !ownIds.has(id)).sort();
700+
const listed = async () => (await navOf(dispatcher)).map((c) => c.name).sort();
701+
702+
expect(await listed()).toEqual(['acme_sync_log', 'partner_home']);
703+
expect(servedContributed()).toEqual(await listed());
704+
705+
expect(engine.registry.disablePackage(FOURTH), 'precondition: disabled').toBeTruthy();
706+
expect(await listed()).toEqual(['acme_sync_log']);
707+
expect(servedContributed()).toEqual(await listed());
708+
709+
expect(engine.registry.enablePackage(FOURTH), 'precondition: enabled').toBeTruthy();
710+
expect(await listed()).toEqual(['acme_sync_log', 'partner_home']);
711+
});
712+
713+
it('a contribution to an app the base does not own is not the base\'s: it is the owning base\'s, or nobody\'s', async () => {
714+
const { dispatcher, engine } = await contributedFixture();
715+
registerContributor(engine, FOURTH, [], [], [
716+
{ app: 'other_app', items: [navLink('partner_notes_report')] },
717+
{ app: 'ghost_app', items: [navLink('partner_ghost')] },
718+
]);
719+
expect((await navOf(dispatcher)).map((c) => c.name)).toEqual(['acme_sync_log']);
720+
expect(await navOf(dispatcher, OTHER)).toEqual([
721+
{ kind: 'nav', app: 'other_app', name: 'partner_notes_report', packageId: FOURTH },
722+
]);
723+
});
724+
725+
it('a contribution with no code package behind it is the environment\'s, not a package\'s', async () => {
726+
const { dispatcher, engine } = await contributedFixture();
727+
engine.registry.registerAppNavContribution({ app: 'showcase', items: [navLink('unstamped_link')] });
728+
engine.registry.registerAppNavContribution({ app: 'showcase', items: [navLink('sentinel_link')] }, 'sys_metadata');
729+
expect((await navOf(dispatcher)).map((c) => c.name)).toEqual(['acme_sync_log']);
730+
});
731+
});

0 commit comments

Comments
 (0)