Skip to content

Commit 8738ca5

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-56mldo
2 parents 1a88a78 + 7dae3b3 commit 8738ca5

5 files changed

Lines changed: 424 additions & 17 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol): a `.custom` pair's published override of a dashboard, report or email template no longer sits in the registry under the base's envelope
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A published override of a base's dashboard, report or email template, saved in the base's `<base>.custom` pair, was registered in the registry's bare slot wearing the BASE's artifact envelope (`_packageId` = the base, `_provenance: 'package'`). The base's per-package layer, which the base's export reads, then listed the override beside the base's own item. Views already stayed out of that slot. The override is now kept out of it for these three types as well, and is still served from its stored row. The by-name read, the effective list and the layered read serve exactly what they served before. The base's per-package layer lists only the base's own item, and the pair's layer lists only the override. A registry read that names the base's item directly answers the base's own item. A row of a package that ships its own artifact of the name keeps its entry as before. Nothing to migrate: a restart re-hydrates the registry under the new rule.

‎packages/metadata-protocol/src/protocol-package-bindings.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,41 @@ function boundPackageOf(packageId: unknown): string | undefined {
296296
return typeof packageId === 'string' && packageId !== '' && packageId !== 'sys_metadata' ? packageId : undefined;
297297
}
298298

299+
/**
300+
* [#29600] The types whose stored row stays out of the registry's bare slot
301+
* when it is bound to a package that ships no artifact of its name while
302+
* another package does: the row would wear the other package's envelope
303+
* there, and the per-package layer would list the copy under that package.
304+
* Every protocol read of these types serves such a row from the row itself
305+
* (the by-name read, both lists, the layered read), so the bare entry served
306+
* no reader the row does not. `view` is not here: it has its own, wider rule
307+
* (#22057, `anotherPackageShips`).
308+
*
309+
* ⛔ A closed list, judged on the canonical type. `page`, `app`, `dataset`,
310+
* `doc` and `book` are left out on purpose: their reads serve a `.custom`
311+
* pair's override FROM the bare entry (the by-name read, the list, and
312+
* `registry.getAllApps`), so they need a row-served path before their bare
313+
* entry can go. `flow` registers with no artifact envelope at all (Regime C,
314+
* #20913), and the boot pull arms its declared override from the bare slot.
315+
*/
316+
const BORROWED_ENVELOPE_DECLINED_TYPES: ReadonlySet<string> = new Set(['dashboard', 'report', 'email_template']);
317+
318+
/**
319+
* [#29600] Whether the hydrator keeps a stored row of `canonicalType`, bound
320+
* to `packageId`, out of the registry's bare slot because `artifact` (the
321+
* envelope it would graft on) is ANOTHER package's: the artifact lookup
322+
* scopes to the row's package and falls back to whichever package ships the
323+
* name. A row of a package that ships its own artifact of the name keeps its
324+
* bare entry with its own envelope (#4624, ADR-0048); a package-less row, and
325+
* a row of a name (or bundle member) no package ships, register as before.
326+
*/
327+
function declinesBorrowedEnvelope(canonicalType: string, packageId: unknown, artifact: unknown): boolean {
328+
if (!BORROWED_ENVELOPE_DECLINED_TYPES.has(canonicalType)) return false;
329+
const bound = boundPackageOf(packageId);
330+
if (bound === undefined || !artifact || typeof artifact !== 'object') return false;
331+
return (artifact as { _packageId?: unknown })._packageId !== bound;
332+
}
333+
299334
/**
300335
* [#16702] ADR-0010 §3.3 — the three protection keys that are READ-SIDE
301336
* DERIVED, and therefore must never be persisted from a caller's body.
@@ -422,6 +457,7 @@ function isShippedViewItem(artifact: unknown): boolean {
422457
export {
423458
boundPackageOf,
424459
bundleMemberOf,
460+
declinesBorrowedEnvelope,
425461
envelopePackageId,
426462
isShippedViewItem,
427463
mergeArtifactProtection,

‎packages/metadata-protocol/src/protocol.ts‎

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ export {
533533
import {
534534
boundPackageOf,
535535
bundleMemberOf,
536+
declinesBorrowedEnvelope,
536537
isShippedViewItem,
537538
mergeArtifactProtection,
538539
stateTenantAuthorship,
@@ -10820,16 +10821,39 @@ export class ObjectStackProtocolImplementation implements
1082010821
* it registered nothing on a save then ([#23298]: a kernel that hydrates
1082110822
* its own store now registers a save as its boot does, by this rule).
1082210823
*
10823-
* ⛔ `view` only, judged on the canonical type. Every other type registers
10824-
* as before: a row bound to one package, of a name two packages ship, holds
10825-
* the bare entry with its own body and its own package's envelope (#4624,
10826-
* ADR-0048, pinned in `objectql`'s `protocol-boot-hydration-scoped.test.ts`).
10824+
* ⛔ This rule is `view` only, judged on the canonical type. Every other type
10825+
* registers as before, save the borrowed-envelope rule below: a row bound
10826+
* to one package, of a name two packages ship, holds the bare entry with
10827+
* its own body and its own package's envelope (#4624, ADR-0048, pinned in
10828+
* `objectql`'s `protocol-boot-hydration-scoped.test.ts`).
1082710829
* Registry readers that name no package read those entries (the declared
1082810830
* security-metadata bootstraps, the action router, the picklist read), and
1082910831
* which body they should see for such a name is not ruled here. A
1083010832
* package-less view row, and a view row of a name only its own package
1083110833
* ships or no package ships, register as before too.
1083210834
*
10835+
* ## [#29600] …and a dashboard, report or email-template row never wears another package's envelope
10836+
*
10837+
* A row of these three types bound to a package that ships no artifact of
10838+
* its name (or bundle member), under a name another package ships, is not
10839+
* registered either ({@link declinesBorrowedEnvelope}). The artifact lookup
10840+
* falls back to the package that ships the name, so the bare entry wore
10841+
* THAT package's envelope (`_packageId`, `_provenance: 'package'`) and the
10842+
* per-package layer listed it as that package's own item: after a `.custom`
10843+
* pair published its declared override of a base's dashboard, the base's
10844+
* layer (and with it the base's export) carried two items of the name.
10845+
* Every protocol read of these types answers such a row from the row
10846+
* itself — the by-name read, the effective list, the layered read and the
10847+
* pair's per-package layer — so they served the same body before and
10848+
* after, measured for each reader. What changes is the registry-direct
10849+
* read of the name, which answers the shipping package's own item.
10850+
*
10851+
* ⛔ Those three types only. A row of a package that ships its own artifact
10852+
* of the name keeps its bare entry (#4624). `page`, `app`, `dataset`, `doc`
10853+
* and `book` still register: their reads serve a pair's override from the
10854+
* bare entry, so it can go only once they serve it from the row. `flow`
10855+
* registers with no artifact envelope (below).
10856+
*
1083310857
* ## [#23233] The entry carries the row's package binding
1083410858
*
1083510859
* The registered body is stamped with the row's package binding as
@@ -10984,6 +11008,12 @@ export class ObjectStackProtocolImplementation implements
1098411008
const artifact = this.lookupArtifactItem(
1098511009
type, (data as any).name, options.packageId ?? undefined, bundleMemberOf(type, data),
1098611010
);
11011+
// [#29600] See the header: a dashboard, report or email-template row
11012+
// bound to a package that ships no artifact of its name, under a name
11013+
// another package ships, is not registered under the bare name, where
11014+
// it would wear that other package's envelope. Its reads answer it from
11015+
// its row. ⛔ Those three types only.
11016+
if (declinesBorrowedEnvelope(canonicalType, options.packageId, artifact)) return true;
1098711017
// [#16702] Say what this row IS before the artifact envelope is grafted
1098811018
// on top of it. Every body reaching this hydrator came out of a
1098911019
// `sys_metadata` write and is therefore tenant-authored by definition
@@ -11821,7 +11851,9 @@ export class ObjectStackProtocolImplementation implements
1182111851
* ships, is not re-registered here: under the bare name it would
1182211852
* answer every package's read of the name. The walk stops there, as
1182311853
* for any baseline found. ⛔ View only, as at the hydration: every
11824-
* other type re-registers as before.
11854+
* other type re-registers as before. [#29600] The hydration's
11855+
* borrowed-envelope rule has no twin here: this limb registers the
11856+
* baseline's own body and grafts no artifact envelope onto it.
1182511857
* 3. [#5079] When NEITHER layer has anything, the deleted row was the
1182611858
* whole item — so the plain-key entry is retired too
1182711859
* ({@link SchemaRegistry.removeOverlayEntry}).

‎packages/objectql/src/environment-overlay-email-locale-restart.test.ts‎

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,12 @@ const T = 'email_template';
401401
const subjectOf = async (protocol: ObjectStackProtocolImplementation, member?: string) =>
402402
((await protocol.getMetaItem({ type: T, name: NAME, ...(member !== undefined ? { member } : {}) })) as any)?.item?.subject;
403403

404-
/** The registry's own entry for one member — what a peer, a send or a bare-name engine read is served. */
404+
/**
405+
* The registry's own entry for one member — what a bare-name engine read is
406+
* served. [#29600] A pair's override of a member the package ships is not
407+
* registered (it is served from its row, which the send reads through the
408+
* execution list), so this answers the package's member there.
409+
*/
405410
const registrySubject = (engine: ObjectQL, member: string) =>
406411
(engine.registry.getItem<any>(T, NAME, undefined, member))?.subject;
407412

@@ -445,21 +450,25 @@ describe('the by-name doors address ONE member by the selector (#22877, stage 2)
445450
it('DELETE by member: resetting zh-CN removes its row only, and the en-US overlay stays served — the registry included', async () => {
446451
const stores = new Map<string, Map<string, Record<string, unknown>>>();
447452
const { engine, protocol } = await bootWithBothSaved(stores);
448-
expect(registrySubject(engine, 'en-US')).toBe('ADMIN en');
449-
expect(registrySubject(engine, 'zh-CN')).toBe('ADMIN zh');
453+
expect(await servedSubjects(protocol)).toEqual({ 'en-US': 'ADMIN en', 'zh-CN': 'ADMIN zh' });
454+
// [#29600] The pair's override of a member the package ships is served
455+
// from its row and never registered under the package's envelope: the
456+
// registry's entry is the package's own member.
457+
expect(registrySubject(engine, 'en-US')).toBe('PKG en');
458+
expect(registrySubject(engine, 'zh-CN')).toBe('PKG zh');
450459

451460
expect(await protocol.deleteMetaItem({ type: T, name: NAME, member: 'zh-CN' })).toMatchObject({ success: true, reset: true });
452461
expect(overlayRows(stores).map((r) => r.bundle_member ?? null)).toEqual([null]);
453462
// The reset member is back on the package wording; the other member's
454-
// overlay is still the registry's entry — not swept with the group.
463+
// overlay is still served — not swept with the group.
455464
expect(registrySubject(engine, 'zh-CN')).toBe('PKG zh');
456-
expect(registrySubject(engine, 'en-US')).toBe('ADMIN en');
465+
expect(await subjectOf(protocol, 'en-US')).toBe('ADMIN en');
457466
expect(await servedSubjects(protocol)).toEqual({ 'en-US': 'ADMIN en', 'zh-CN': 'PKG zh' });
458467
expect(await subjectOf(protocol, 'zh-CN')).toBe('PKG zh');
459468

460469
const after = await boot(stores);
461470
expect(await servedSubjects(after.protocol)).toEqual({ 'en-US': 'ADMIN en', 'zh-CN': 'PKG zh' });
462-
expect(registrySubject(after.engine, 'en-US')).toBe('ADMIN en');
471+
expect(await subjectOf(after.protocol, 'en-US')).toBe('ADMIN en');
463472
});
464473

465474
it('DELETE by member of a member NO artifact ships: its overlay leaves the registry, and the canonical overlay stays', async () => {
@@ -479,7 +488,10 @@ describe('the by-name doors address ONE member by the selector (#22877, stage 2)
479488

480489
expect(await protocol.deleteMetaItem({ type: T, name: DIGEST, member: 'zh-CN' })).toMatchObject({ success: true, reset: true });
481490
expect(digestEntry('zh-CN')).toBeUndefined();
482-
expect(digestEntry('en-US')).toBe('ADMIN digest en');
491+
// [#29600] The canonical member's override (a member the package
492+
// ships) is served from its row; the registry holds the package's.
493+
expect(((await protocol.getMetaItem({ type: T, name: DIGEST, member: 'en-US' })) as any)?.item?.subject).toBe('ADMIN digest en');
494+
expect(digestEntry('en-US')).toBe('PKG digest en');
483495
const listed: any = await protocol.getMetaItemsForExecution({ type: T });
484496
const digest = (listed?.items ?? []).filter((it: any) => it?.name === DIGEST).map((it: any) => `${it.locale}:${it.subject}`);
485497
expect(digest).toEqual(['en-US:ADMIN digest en']);
@@ -491,7 +503,8 @@ describe('the by-name doors address ONE member by the selector (#22877, stage 2)
491503
expect(await protocol.deleteMetaItem({ type: T, name: NAME })).toMatchObject({ success: true, reset: true });
492504
expect(overlayRows(stores).map((r) => r.bundle_member)).toEqual(['zh-CN']);
493505
expect(registrySubject(engine, 'en-US')).toBe('PKG en');
494-
expect(registrySubject(engine, 'zh-CN')).toBe('ADMIN zh');
506+
// [#29600] The zh-CN override stays served, from its row.
507+
expect(await subjectOf(protocol, 'zh-CN')).toBe('ADMIN zh');
495508
expect(await subjectOf(protocol)).toBe('PKG en');
496509
});
497510

@@ -739,12 +752,18 @@ describe('the package-batch doors and the cluster fan-out carry the member (#228
739752

740753
await writer.protocol.saveMetaItem({ type: T, name: NAME, item: template('en-US', 'ADMIN en') });
741754
await writer.protocol.saveMetaItem({ type: T, name: NAME, item: template('zh-CN', 'ADMIN zh') });
742-
await vi.waitFor(() => expect(registrySubject(peer.engine, 'zh-CN')).toBe('ADMIN zh'));
743-
expect(registrySubject(peer.engine, 'en-US')).toBe('ADMIN en');
755+
// [#29600] A pair's override of a shipped member is served from its
756+
// row and never enters the registry, so the peer converges on its
757+
// served read, and its registry keeps the package's own members.
758+
await vi.waitFor(async () => expect(await subjectOf(peer.protocol, 'zh-CN')).toBe('ADMIN zh'));
759+
expect(await subjectOf(peer.protocol, 'en-US')).toBe('ADMIN en');
760+
expect(registrySubject(peer.engine, 'zh-CN')).toBe('PKG zh');
761+
expect(registrySubject(peer.engine, 'en-US')).toBe('PKG en');
744762

745763
await writer.protocol.deleteMetaItem({ type: T, name: NAME, member: 'zh-CN' });
746-
await vi.waitFor(() => expect(registrySubject(peer.engine, 'zh-CN')).toBe('PKG zh'));
747-
expect(registrySubject(peer.engine, 'en-US')).toBe('ADMIN en');
764+
await vi.waitFor(async () => expect(await subjectOf(peer.protocol, 'zh-CN')).toBe('PKG zh'));
765+
expect(await subjectOf(peer.protocol, 'en-US')).toBe('ADMIN en');
766+
expect(registrySubject(peer.engine, 'zh-CN')).toBe('PKG zh');
748767
});
749768
});
750769

0 commit comments

Comments
 (0)