Skip to content

Commit 7ca2d4c

Browse files
committed
fix(runtime): the contributions read asks one stamp question of a field and of a flow
Both kinds now attribute through codePackageOf: a code package's stamp (isCodeArtifactBody), never the base's nor its pair's. The spec docblock states exactly what the list carries and where the pair's items are instead. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8196881 commit 7ca2d4c

3 files changed

Lines changed: 60 additions & 14 deletions

File tree

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,33 @@ describe('[#28722] GET /packages/:id/customizations — the fields and flows oth
574574
expect(contributions.map((c: any) => `${c.kind}:${c.name}`)).toEqual(['field:acme_sync_id', 'flow:acme_task_sync']);
575575
});
576576

577+
it('reads a field\'s stamp and a flow\'s stamp the same way: each stamp lists both kinds or neither', async () => {
578+
const { dispatcher, engine } = await boot();
579+
// One field extension and one flow per stamp, on the base's object.
580+
// A code package's stamp is a contribution; the package-less
581+
// `sys_metadata` sentinel and a tenant-authored body wearing a real
582+
// package's id are the environment's, whichever kind carries them.
583+
const stamps = [
584+
{ tag: 'code', packageId: THIRD, body: {} },
585+
{ tag: 'sentinel', packageId: 'sys_metadata', body: {} },
586+
{ tag: 'tenant', packageId: FOURTH, body: { _provenance: 'org' } },
587+
] as const;
588+
for (const { tag, packageId, body } of stamps) {
589+
extend(engine, packageId, 'showcase_task', { ...body, fields: { [`${tag}_field`]: { name: `${tag}_field`, label: tag, type: 'text' } } });
590+
engine.registry.registerItem('flow', { ...flowOn(`${tag}_flow`, 'showcase_task'), _packageId: packageId, ...body } as any);
591+
}
592+
const { contributions } = (await customizations(dispatcher, BASE)).response?.body?.data;
593+
const listedTags = (kind: string) => contributions
594+
.filter((c: any) => c.kind === kind)
595+
.map((c: any) => c.name.replace(/_(field|flow)$/, ''))
596+
.sort();
597+
expect(listedTags('field')).toEqual(listedTags('flow'));
598+
expect(contributions).toEqual([
599+
{ kind: 'field', object: 'showcase_task', name: 'code_field', packageId: THIRD },
600+
{ kind: 'flow', object: 'showcase_task', name: 'code_flow', packageId: THIRD },
601+
]);
602+
});
603+
577604
it('another base\'s read lists what is contributed to its own objects only', async () => {
578605
const { dispatcher } = await contributedFixture();
579606
const data = (await customizations(dispatcher, OTHER)).response?.body?.data;

‎packages/runtime/src/domains/packages.ts‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3205,10 +3205,15 @@ async function readPackageCustomizations(
32053205
* - **flow** — the metadata registry's flows (`listItems('flow')`, which
32063206
* already leaves a disabled package's out), whose `start` node's
32073207
* `config.objectName` is a base-owned object, attributed to the package
3208-
* stamp the registration put on it when that stamp is a code package's
3209-
* ({@link isCodeArtifactBody}: not the package-less `sys_metadata`
3210-
* sentinel, not a tenant-authored overlay). A flow authored in this
3211-
* environment is the environment's, not a package's, and is not listed.
3208+
* stamp the registration put on it (its `_packageId`).
3209+
*
3210+
* Both kinds ask ONE question of their stamp, {@link codePackageOf}: is it a
3211+
* code package's ({@link isCodeArtifactBody}: not the package-less
3212+
* `sys_metadata` sentinel, not a tenant-authored body), and neither the base
3213+
* nor its pair? Only where the stamp is read differs: the contributor's
3214+
* `packageId` beside its `definition`, or the flow's own `_packageId`. An item
3215+
* authored in this environment is the environment's, not a package's, and is
3216+
* not listed, whichever kind it is.
32123217
*
32133218
* Ordered by object, kind, name and package.
32143219
*/
@@ -3220,8 +3225,14 @@ function readBaseContributions(
32203225
type Contribution = GetPackageCustomizationsResponse['contributions'][number];
32213226
const contributions: Contribution[] = [];
32223227
if (typeof registry?.getAllObjects !== 'function') return contributions;
3223-
const isContributor = (packageId: unknown): packageId is string =>
3224-
typeof packageId === 'string' && packageId !== '' && packageId !== baseId && packageId !== pairId;
3228+
// The one stamp reading both kinds share: the package `packageId` names
3229+
// when `body` is a code package's item and the package is neither the base
3230+
// nor its pair; `undefined` otherwise.
3231+
const codePackageOf = (packageId: unknown, body: unknown): string | undefined => {
3232+
if (typeof packageId !== 'string' || packageId === baseId || packageId === pairId) return undefined;
3233+
const stamped = { _packageId: packageId, _provenance: (body as { _provenance?: unknown } | null | undefined)?._provenance };
3234+
return isCodeArtifactBody(stamped) ? packageId : undefined;
3235+
};
32253236

32263237
const owned = new Set<string>();
32273238
for (const object of registry.getAllObjects(baseId) as Array<{ name?: unknown }>) {
@@ -3231,22 +3242,25 @@ function readBaseContributions(
32313242

32323243
for (const name of owned) {
32333244
for (const contributor of registry.getObjectContributors(name) as Array<{ packageId?: unknown; ownership?: unknown; definition?: any }>) {
3234-
if (contributor.ownership !== 'extend' || !isContributor(contributor.packageId)) continue;
3245+
if (contributor.ownership !== 'extend') continue;
3246+
const packageId = codePackageOf(contributor.packageId, contributor.definition);
3247+
if (packageId === undefined) continue;
32353248
for (const field of Object.keys(contributor.definition?.fields ?? {})) {
3236-
contributions.push({ kind: 'field', object: name, name: field, packageId: contributor.packageId });
3249+
contributions.push({ kind: 'field', object: name, name: field, packageId });
32373250
}
32383251
}
32393252
}
32403253

32413254
if (owned.size > 0 && typeof registry.listItems === 'function') {
32423255
for (const flow of registry.listItems('flow') as Array<{ name?: unknown; nodes?: unknown; _packageId?: unknown }>) {
3243-
if (!isCodeArtifactBody(flow) || !isContributor(flow._packageId) || typeof flow.name !== 'string') continue;
3256+
const packageId = codePackageOf(flow._packageId, flow);
3257+
if (packageId === undefined || typeof flow.name !== 'string') continue;
32443258
const start = Array.isArray(flow.nodes)
32453259
? flow.nodes.find((node: any) => node?.type === 'start')
32463260
: undefined;
32473261
const object = start?.config?.objectName;
32483262
if (typeof object !== 'string' || !owned.has(object)) continue;
3249-
contributions.push({ kind: 'flow', object, name: flow.name, packageId: flow._packageId });
3263+
contributions.push({ kind: 'flow', object, name: flow.name, packageId });
32503264
}
32513265
}
32523266

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,15 @@ export const GetPackageCustomizationsRequestSchema = lazySchema(() => z.object({
350350
* [#28722, ADR-0029 D7 as amended by ADR-0146 D3] Beside the pair's changes,
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
353-
* entry per item, each stamped with the package that contributes it. The
354-
* stamp is on the item, so two packages adding a field of the same name are
355-
* two entries and nothing is joined by name on the client. X's own items and
356-
* the pair's (listed above) are never contributions.
353+
* 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.
357362
*/
358363
export const GetPackageCustomizationsResponseSchema = lazySchema(() => z.object({
359364
packageId: z.string().describe('The base package the customizations are of (the request\'s id).'),

0 commit comments

Comments
 (0)