From fc2bf507aca047b7d64bccdd02e07dd8f64d0f30 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 14:43:24 +0000 Subject: [PATCH 1/5] fix(metadata-protocol): a row declared for a package that still ships the name is never another package's moved edit (ADR-0150 D4) --- .../src/protocol-environment-rows.ts | 10 ++-- .../src/protocol-meta-list-reads.ts | 9 +++- .../src/protocol-overlay-merge.ts | 53 +++++++++++++++++-- .../src/protocol-served-overrides.ts | 12 +++-- .../src/suite-moved-overlay.ts | 29 +++++++--- .../package-scoped-exact-qualifier.test.ts | 48 +++++++++++++++++ 6 files changed, 142 insertions(+), 19 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-environment-rows.ts b/packages/metadata-protocol/src/protocol-environment-rows.ts index d38f85a350e..490779d57bb 100644 --- a/packages/metadata-protocol/src/protocol-environment-rows.ts +++ b/packages/metadata-protocol/src/protocol-environment-rows.ts @@ -51,6 +51,7 @@ import { overlayMemberWhere } from './migrations/overlay-index.js'; import type { ObjectStackProtocolImplementation } from './protocol.js'; import { rowMatchesOverlayWhere, servedOverlayRowCandidates } from './protocol.js'; import { holdsServedOverlayCandidate } from './protocol-overlay-merge.js'; +import type { ShipsName } from './suite-moved-overlay.js'; import { installedManifestsOfEngine } from './installed-manifests.js'; /** @@ -122,10 +123,13 @@ export async function findServedOverlayRow( const installed = installedManifestsOfEngine(this.engine); // [#31593] The code packages that ship the item, read once, when a // moved edit of it can be a candidate (`suite-moved-overlay.ts`). + // [#32606] Two grains: the item (its member) for the address's package, + // the name (any member) for the former owner ({@link ShipsName}). let shippers: ReadonlySet | undefined; - const ships = (packageId: string): boolean => { - shippers ??= shippingPackageIds(this.shippedArtifactsOf(args.type, args.name, undefined, args.member)); - return shippers.has(packageId); + let nameShippers: ReadonlySet | undefined; + const ships: ShipsName = { + item: (packageId) => (shippers ??= shippingPackageIds(this.shippedArtifactsOf(args.type, args.name, undefined, args.member))).has(packageId), + name: (packageId) => (nameShippers ??= shippingPackageIds(this.shippedArtifactsOf(args.type, args.name))).has(packageId), }; for (const candidate of servedOverlayRowCandidates({ packageId: args.packageId, servedOverride: args.servedOverride, installed, ships })) { const type = candidate.spelling === 'canonical' ? args.type : other; diff --git a/packages/metadata-protocol/src/protocol-meta-list-reads.ts b/packages/metadata-protocol/src/protocol-meta-list-reads.ts index 0066a37abca..be4a3d90d67 100644 --- a/packages/metadata-protocol/src/protocol-meta-list-reads.ts +++ b/packages/metadata-protocol/src/protocol-meta-list-reads.ts @@ -194,6 +194,11 @@ export async function readFlattenedMetaItems(host: Pick() : undefined; + // [#32606] A moved edit's former owner is asked whether it ships any + // member of the name over the registry the list serves, not over the + // merge's base items, which a scoped list draws from one package alone. + const shipsName = (name: string, shipper: string): boolean => + shippingPackageIds(host.shippedArtifactsOf(request.type, name)).has(shipper); try { // [#21442] The row set this read consults — the overlay cache // included — is {@link readActiveOverlayRows}, and each row is @@ -294,7 +299,7 @@ export async function readFlattenedMetaItems(host: Pick { if (data && typeof data === 'object') (data as any)._draft = true; return data; - }, unseated, { servedOverride, installed }); + }, unseated, { servedOverride, installed, shipsName }); } } catch (error) { // [#5532] Same rule as the active-overlay read above. Serving diff --git a/packages/metadata-protocol/src/protocol-overlay-merge.ts b/packages/metadata-protocol/src/protocol-overlay-merge.ts index c8ee1383c13..cdb50f9af4e 100644 --- a/packages/metadata-protocol/src/protocol-overlay-merge.ts +++ b/packages/metadata-protocol/src/protocol-overlay-merge.ts @@ -385,6 +385,14 @@ export function mergePackageAwareOverlay( * ({@link servedOverlayRowCandidates}). */ readonly installed: InstalledManifestLookup; + /** + * [#32606] Whether `packageId` ships any member of `name` in the + * registry the list serves, the grain a moved edit's former owner + * is asked at ({@link ShipsName}). The merge also reads its own + * base items; a list scoped to one package names this, since the + * former owner's items are not among its base items. + */ + readonly shipsName?: (name: string, packageId: string) => boolean; } = {}, ): unknown[] { // Per-SLOT, layer-ordered contributions; `pkg: undefined` = package-less. @@ -397,13 +405,43 @@ export function mergePackageAwareOverlay( const disc = itemDiscriminator(type, item); return disc === undefined ? String(name) : `${String(name)}\u0000${disc}`; }; - const push = (slot: string, pkg: string | undefined, item: any, stored?: StoredRowPlace, standIn?: boolean) => { + // [#32606] The name each slot is of, so a slot's name grain reads its + // sibling members' slots too. + const slotName = new Map(); + const slotOfList = new WeakMap(); + const push = (slot: string, pkg: string | undefined, item: any, stored?: StoredRowPlace, standIn?: boolean, name?: unknown) => { let list = buckets.get(slot); - if (!list) { buckets.set(slot, (list = [])); order.push(slot); } + if (!list) { buckets.set(slot, (list = [])); order.push(slot); slotOfList.set(list, slot); } + if (typeof name === 'string' && !slotName.has(slot)) slotName.set(slot, name); const c: Contribution = stored ? { pkg, item, stored } : { pkg, item }; if (standIn) c.standIn = true; list.push(c); }; + // [#32606] The code packages that ship any member of the name `list`'s + // slot is of: the lower-layer contributions of every slot of that name, + // read once after every contribution is in. + let byName: Map> | undefined; + const nameShippersOf = (list: readonly Contribution[]): ReadonlySet => { + if (byName === undefined) { + byName = new Map(); + for (const [slot, l] of buckets) { + const name = slotName.get(slot); + if (name === undefined) continue; + const set = byName.get(name) ?? new Set(); + for (const c of l) if (c.stored === undefined && !c.standIn && c.pkg !== undefined) set.add(c.pkg); + byName.set(name, set); + } + } + const name = slotName.get(slotOfList.get(list) ?? ''); + return (name === undefined ? undefined : byName.get(name)) ?? new Set(); + }; + // …and the caller's reading of the registry, for a list whose base items + // are one package's alone (a list scoped to the package): the former + // owner's members are not among them. + const nameShippedBy = (list: readonly Contribution[], packageId: string): boolean => { + const name = slotName.get(slotOfList.get(list) ?? ''); + return name !== undefined && options.installed !== undefined && options.shipsName?.(name, packageId) === true; + }; // [#21804] The stored row the served-row resolution picks for package // `real` among a slot's contributions: the first candidate of // {@link servedOverlayRowCandidates} that one of the rows sits at. @@ -418,7 +456,12 @@ export function mergePackageAwareOverlay( const shippers = new Set(list .filter((c) => c.stored === undefined && !c.standIn && c.pkg !== undefined) .map((c) => c.pkg as string)); - const ships = (packageId: string): boolean => shippers.has(packageId); + // [#32606] …and the code packages that ship ANY member of the slot's + // name, the grain a former owner is asked at ({@link ShipsName}). + const ships: ShipsName = { + item: (packageId) => shippers.has(packageId), + name: (packageId) => nameShippersOf(list).has(packageId) || nameShippedBy(list, packageId), + }; for (const candidate of servedOverlayRowCandidates(options.installed !== undefined ? { packageId: real, servedOverride: options.servedOverride, installed: options.installed, ships } : { packageId: real })) { @@ -448,7 +491,7 @@ export function mergePackageAwareOverlay( const itemName = listSlotNameOf(canonicalType, item); if (itemName !== undefined) { push(slotOf(item, itemName), (item._packageId ?? undefined) as string | undefined, item, - undefined, unseated?.has(item)); + undefined, unseated?.has(item), itemName); } } for (const { data, packageId, stored, standIn } of records) { @@ -486,7 +529,7 @@ export function mergePackageAwareOverlay( // package's slot below. A record that is not a stored row (a caller's // item, slotted by its own `_packageId`) enters as it is. const bound = stored ? withRowBinding(body, packageId) : body; - push(slot, packageId, transform ? transform(bound, prev) : bound, stored, standIn); + push(slot, packageId, transform ? transform(bound, prev) : bound, stored, standIn, bodyName); } const out: unknown[] = []; diff --git a/packages/metadata-protocol/src/protocol-served-overrides.ts b/packages/metadata-protocol/src/protocol-served-overrides.ts index 0b23b796057..00541edf1bb 100644 --- a/packages/metadata-protocol/src/protocol-served-overrides.ts +++ b/packages/metadata-protocol/src/protocol-served-overrides.ts @@ -80,7 +80,7 @@ import { storedRowDocument } from './item-lock.js'; import type { ObjectStackProtocolImplementation } from './protocol.js'; import { holdsServedOverlayCandidate, servedOverlayRowCandidates } from './protocol-overlay-merge.js'; import { shippingPackageIds } from './protocol-environment-rows.js'; -import { isMovedOverrideRowOf } from './suite-moved-overlay.js'; +import { isMovedOverrideRowOf, type ShipsName } from './suite-moved-overlay.js'; import { installedManifestsOfEngine } from './installed-manifests.js'; /** The class members {@link listServedOverrides} reads, typed as the class declares them. */ @@ -160,9 +160,15 @@ export async function listServedOverrides( // The code packages that ship the item, read once per item and only // when a moved edit is in question (the by-name read's own reading). let shippers: ReadonlySet | undefined; + let nameShippers: ReadonlySet | undefined; const shippersOf = (): ReadonlySet => (shippers ??= shippingPackageIds(this.shippedArtifactsOf(type, name, undefined, member))); - const ships = (packageId: string): boolean => shippersOf().has(packageId); + // [#32606] The item's grain for the address's package, the name's for + // a former owner (`ShipsName`). + const ships: ShipsName = { + item: (packageId) => shippersOf().has(packageId), + name: (packageId) => (nameShippers ??= shippingPackageIds(this.shippedArtifactsOf(type, name))).has(packageId), + }; let served: any; for (const candidate of servedOverlayRowCandidates({ packageId: base, servedOverride: true, installed, ships })) { // Only the pair's candidates: the base's own row, the @@ -176,7 +182,7 @@ export async function listServedOverrides( // A declared override the base no longer ships, which a package // shipping the item now holds as its moved edit, is that // package's: listed there, never also here. - if (candidate.moved === undefined && !ships(base) + if (candidate.moved === undefined && !ships.item(base) && [...shippersOf()].some((now) => now !== base && isMovedOverrideRowOf(served, now, installed, ships))) { served = undefined; } diff --git a/packages/metadata-protocol/src/suite-moved-overlay.ts b/packages/metadata-protocol/src/suite-moved-overlay.ts index 05cc47b2871..a5ec1de56bf 100644 --- a/packages/metadata-protocol/src/suite-moved-overlay.ts +++ b/packages/metadata-protocol/src/suite-moved-overlay.ts @@ -77,11 +77,28 @@ import { storedRowDocument } from './item-lock.js'; import { isServedOverrideRowOf, type ServedOverrideRow } from './served-override.js'; /** - * Whether a code package ships the item being read (its type, name and - * bundle member) in the registry the read serves: the caller's reading, - * from the shipped artifacts it already weighs for the address. + * Which code packages ship the item being read, in the registry the read + * serves: the caller's reading, from the shipped artifacts it already weighs + * for the address. Two grains, because the two packages a move names are + * asked different questions: + * + * - `item`: whether a package ships the item itself (its type, name and + * bundle member). The address's package must, to be the item's owner now. + * - `name`: whether a package ships ANY member of the name. [#32606] The + * former owner is asked at this grain: a package that still ships the name + * still holds it (ADR-0150 D3), so a row declaring it, or bound to it, is + * that package's own edit, served at its address (an added member's + * declared override, #28802), never another package's moved edit as well. + * Asked at the member's grain, a bundle addition that ships only the + * member (`fr-FR` beside the former owner's `en-US`) took the row as its + * own: one row served at two packages' addresses (red line 2). + * + * For a type that is not a bundle the two answer alike. */ -export type ShipsName = (packageId: string) => boolean; +export interface ShipsName { + readonly item: (packageId: string) => boolean; + readonly name: (packageId: string) => boolean; +} /** The row's body as a plain object, or `undefined` when it is not one. */ function documentOf(row: ServedOverrideRow): Record | undefined { @@ -139,7 +156,7 @@ export function isMovedOverrideRowOf( if (declaration === null || typeof declaration !== 'object' || Array.isArray(declaration)) return false; const former = (declaration as { package?: unknown }).package; if (typeof former !== 'string' || former === '' || former === base) return false; - if (!ships(base) || ships(former)) return false; + if (!ships.item(base) || ships.name(former)) return false; if (installed(former) !== undefined && !ofOneApp(former, base, installed)) return false; // THE predicate, asked of the row as if its declaration named `base`. const asBase = { ...body, overrides: { ...(declaration as object), package: base } }; @@ -172,7 +189,7 @@ export function isMovedBaseRowOf( const former = row.package_id; if (typeof former !== 'string' || former === '' || former === base || isCustomizationPackage(former)) return false; if (!overridableType(row.type)) return false; - if (!ships(base) || ships(former)) return false; + if (!ships.item(base) || ships.name(former)) return false; if (!ofOneApp(former, base, installed)) return false; const body = documentOf(row); return body !== undefined && !('overrides' in body); diff --git a/packages/objectql/src/package-scoped-exact-qualifier.test.ts b/packages/objectql/src/package-scoped-exact-qualifier.test.ts index c88dd3d415a..324ea9326d3 100644 --- a/packages/objectql/src/package-scoped-exact-qualifier.test.ts +++ b/packages/objectql/src/package-scoped-exact-qualifier.test.ts @@ -972,6 +972,54 @@ describe('[#31699 F2] a pair member row two holders could own is refused on both expect(labelOf(await read(PAIR, 'fr-FR'))).toBe('pair fr-FR'); }); + // [#32606] A row of the App's pair declaring X is X's (its declared + // override of an added member, #28802), served at X's address and in X's + // lists. The moved-edit rule (#31593, `isMovedOverrideRowOf`) asked + // whether X still ships the item at the MEMBER's grain, so beside an + // addition Z that ships the row's locale (`fr-FR`) while X ships only + // `en-US`, it read the row as an edit that moved from X to Z: Z's exact + // address, Z's list and the execution list a send resolved to Z reads all + // served the row declared for X, stamped Z, while the registry answers + // Z's own. One row at two packages' addresses (red line 2). X ships the + // name, so it is still the row's holder: the former owner is asked at the + // name's grain, and Z answers its own member everywhere. + const declaredForX = () => { + pairRow({ overrides: { package: X } }); + registry.registerItem('email_template', { + name: 'welcome', label: 'pair fr-FR', locale: 'fr-FR', subject: 'pair fr-FR', bodyHtml: '

p

', overrides: { package: X }, _packageId: PAIR, _provenance: 'org', + }, 'name' as never); + }; + it.each([ + ['addition installed first', () => { installZ(); tpl('en-US', X); tpl('fr-FR', Z); declaredForX(); }], + ['row stored first', () => { tpl('en-US', X); declaredForX(); installZ(); tpl('fr-FR', Z); }], + ] as const)('[#32606] NARROWING — a row declared for X is never served at an addition Z that ships its locale (%s; BASE: Z\'s address, list and execution list served `pair fr-FR` stamped Z)', async (_order, arrange) => { + arrange(); + expect(registry.getPackageScopedItem<{ label: string }>('email_template', 'welcome', Z, 'fr-FR')?.label, 'the registry at Z').toBe('zeta fr-FR'); + const atZ = await read(Z, 'fr-FR'); + expect(labelOf(atZ), '`?package=Z&member=fr-FR`: Z\'s own').toBe('zeta fr-FR'); + expect((atZ as { item?: { _diagnostics?: { valid?: boolean } } })?.item?._diagnostics?.valid, 'Z\'s own item is valid').toBe(true); + expect(await listed(Z), 'Z\'s list').toEqual(['zeta fr-FR']); + expect(await forSend(Z), 'Z\'s execution list').toEqual(['zeta fr-FR']); + // CONTROL: X's address and X's lists serve the row declared for X (UNCHANGED). + expect(labelOf(await read(X, 'fr-FR'))).toBe('pair fr-FR'); + expect(await listed(X)).toEqual(['pair fr-FR', 'suitex en-US']); + expect(await forSend(X)).toEqual(['pair fr-FR', 'suitex en-US']); + expect(labelOf(await read(PAIR, 'fr-FR'))).toBe('pair fr-FR'); + }); + + // [#31593] CONTROL — the moved edit still follows its item: X ships + // nothing of the name any more (no member), so the row declaring X is + // the tenant's edit of the item that moved to Z, served at Z. + it.each([ + ['addition installed first', () => { installZ(); tpl('fr-FR', Z); declaredForX(); }], + ['row stored first', () => { declaredForX(); installZ(); tpl('fr-FR', Z); }], + ] as const)('[#32606] CONTROL — X ships nothing of the name: the row declaring X is the moved edit, served at Z (%s; UNCHANGED)', async (_order, arrange) => { + arrange(); + expect(labelOf(await read(Z, 'fr-FR'))).toBe('pair fr-FR'); + expect(await listed(Z)).toEqual(['pair fr-FR']); + expect(await forSend(Z)).toEqual(['pair fr-FR']); + }); + it('NARROWING — an undeclared row while another App\'s pair stores an undeclared row of the name: neither address serves it, as the registry binds neither (residual 2, contract review F6; BASE at 075fb3188: `?package=Y` served es-ES, `?package=P` fr-FR)', async () => { // App B: P ships en-US, Q (on P) ships de-DE; B's pair stores an undeclared fr-FR row. // App A: U (on A and P, A's namespace) ships fr-FR, Y ships it-IT; A's pair stores an undeclared es-ES row. From 2b2e5b411840f3466b227b0b5dc3fbbfe1b60b07 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 14:45:43 +0000 Subject: [PATCH 2/5] test(objectql): pin a pair row declared for a package that still ships the name at a bundle addition; changesets and ADR-0087 entry --- ...2606-declared-row-not-moved-to-addition.md | 25 +++++++++++++ .../32606-declared-row-semantic-entry.md | 10 ++++++ .../src/suite-moved-overlay.ts | 2 ++ .../package-scoped-exact-qualifier.test.ts | 3 ++ .../18.declared-row-not-moved-to-addition.ts | 36 +++++++++++++++++++ 5 files changed, 76 insertions(+) create mode 100644 .changeset/32606-declared-row-not-moved-to-addition.md create mode 100644 .changeset/32606-declared-row-semantic-entry.md create mode 100644 packages/spec/src/migrations/entries/semantic/18.declared-row-not-moved-to-addition.ts diff --git a/.changeset/32606-declared-row-not-moved-to-addition.md b/.changeset/32606-declared-row-not-moved-to-addition.md new file mode 100644 index 00000000000..e19ad85a829 --- /dev/null +++ b/.changeset/32606-declared-row-not-moved-to-addition.md @@ -0,0 +1,25 @@ +--- +'@objectstack/metadata-protocol': minor +--- + +fix(metadata-protocol)!: a row of an App's `.custom` pair declared for a package that still ships the name is never served at a bundle addition's address as its own item (ADR-0150 D4, #32606) + +Clause-②: no +Metadata-protocol: semantic +Skills-docs: none — `skills/**` and `content/docs/**` teach a declared override served at the package it declares and a tenant's edit following an item that moved between an App's packages (#31593); neither teaches a row declared for one package served at another that still ships nothing of the row's member, so no taught sentence moves. + + + +**BREAKING** for a reader of a bundle addition's member: an App `A` with module packages X and Z, Z depending on A and X; X ships `welcome` in `en-US`, Z ships only `fr-FR` (a bundle addition to X's template), and `A.custom` stores a `fr-FR` row declaring `overrides: { package: X }`. + +The moved-edit rule (#31593, `isMovedOverrideRowOf` / `isMovedBaseRowOf`) serves a row that declares, or is bound to, a former owner of an item at the package that ships the item now. It asked whether the former owner still ships the item at the MEMBER's grain, so X (which ships `en-US`, not `fr-FR`) read as a package that no longer ships it, and Z took the row as its own moved edit. The rule now asks the former owner at the NAME's grain, as its own header states ("the old owner must not ship the name"): X still holds `welcome`, so the row stays X's alone. + +**Every moved answer, before → after.** Both registration orders (Z installed first, the row stored first). First-party count 0: no first-party App stores a pair row declaring one module at a locale another module adds. + +- `GET /meta/email_template/welcome?package=Z&member=fr-FR`: the row declared for X, stamped Z, `_diagnostics.valid: false` → Z's own `fr-FR`, which is what the registry answers at Z (`getPackageScopedItem`). +- `GET /meta/email_template?package=Z` (Z's list) and the execution list a send resolved to Z reads (`getMetaItemsForExecution`): the row declared for X → Z's own `fr-FR`. A send resolved to Z sent X's customization of a member Z ships. +- `listServedOverrides({ packageId: Z })` (the customizations read): the same row is no longer listed under Z. + +**Not moved.** X's address, X's list and X's execution list serve the row declared for X, as before. `?package=A.custom` serves it. The read naming no package keeps its 409 naming both holders. A former owner that ships nothing of the name any more still hands its edit to the package that ships it now (#31593's flat → composed and composed → flat moves, and a member that moved together with its whole bundle), pinned as a CONTROL in both orders. + +The fix for a reader: read the row at the package it declares (`?package=X`). To customize Z's own member, save a row declaring Z. diff --git a/.changeset/32606-declared-row-semantic-entry.md b/.changeset/32606-declared-row-semantic-entry.md new file mode 100644 index 00000000000..ba64534da29 --- /dev/null +++ b/.changeset/32606-declared-row-semantic-entry.md @@ -0,0 +1,10 @@ +--- +'@objectstack/spec': patch +--- + +docs(spec): the protocol upgrade guide names what a bundle addition's address and lists answer for an App pair row declared for a package that still ships the name: the addition's own member (ADR-0150 D4, #32606) + +Clause-②: no +Metadata-protocol: none + +The semantic entry `declared-row-not-moved-to-addition` (`packages/spec/src/migrations/entries/semantic/18.declared-row-not-moved-to-addition.ts`) registers the change `.changeset/32606-declared-row-not-moved-to-addition.md` declares (ADR-0087, `adr-0087: registered`): no automatic rewrite, since every stored row keeps its shape and its binding. It adds no key and no export. diff --git a/packages/metadata-protocol/src/suite-moved-overlay.ts b/packages/metadata-protocol/src/suite-moved-overlay.ts index a5ec1de56bf..ba68dfb7f61 100644 --- a/packages/metadata-protocol/src/suite-moved-overlay.ts +++ b/packages/metadata-protocol/src/suite-moved-overlay.ts @@ -137,6 +137,7 @@ function ofOneApp(a: string, b: string, installed: InstalledManifestLookup): boo * | row (in `app.custom`) declares | base | installed | ships | answer | * |:--|:--|:--|:--|:--| * | `app` | `app.service` | both, `app.service` declares `app` | `app.service` only | `true` (flat → composed) | + * | `X` (a module), member `fr-FR` | `Z` (a bundle addition of `X`'s name) | both | `Z` ships `fr-FR`, `X` ships `en-US` | `false` — `X` still ships the name (#32606) | * | `app.service` | `app` | `app` only | `app` | `true` (composed → flat) | * | `app` | `app` | — | — | `false` — `isServedOverrideRowOf`'s own row | * | `app` | `app.service` | both | both | `false` — `app` still ships it | @@ -174,6 +175,7 @@ export function isMovedOverrideRowOf( * |:--|:--|:--|:--| * | `app` (installed) | `app.service` (declares `app`) | `app.service` only | `true` | * | `app` | `app.service` | both | `false` — `app` still ships it | + * | `X`, member `fr-FR` | `Z` (ships `fr-FR`; `X` ships `en-US`) | `Z` at the member, both at the name | `false` — `X` still ships the name (#32606) | * | `partner.ext` (installed, its own App) | `app.service` | `app.service` | `false` — another App | * | `app.old` (not installed) | `app` | `app` | `false` — no install record names its App | * | `app.custom` | `app.service` | `app.service` | `false` — a pair's row is {@link isMovedOverrideRowOf}'s | diff --git a/packages/objectql/src/package-scoped-exact-qualifier.test.ts b/packages/objectql/src/package-scoped-exact-qualifier.test.ts index 324ea9326d3..b4805d322fb 100644 --- a/packages/objectql/src/package-scoped-exact-qualifier.test.ts +++ b/packages/objectql/src/package-scoped-exact-qualifier.test.ts @@ -1000,6 +1000,8 @@ describe('[#31699 F2] a pair member row two holders could own is refused on both expect((atZ as { item?: { _diagnostics?: { valid?: boolean } } })?.item?._diagnostics?.valid, 'Z\'s own item is valid').toBe(true); expect(await listed(Z), 'Z\'s list').toEqual(['zeta fr-FR']); expect(await forSend(Z), 'Z\'s execution list').toEqual(['zeta fr-FR']); + expect((await protocol.listServedOverrides({ packageId: Z })).map((e) => `${e.name}:${e.member}`), 'Z\'s customizations').toEqual([]); + expect((await protocol.listServedOverrides({ packageId: X })).map((e) => `${e.name}:${e.member}`), 'X\'s customizations').toEqual(['welcome:fr-FR']); // CONTROL: X's address and X's lists serve the row declared for X (UNCHANGED). expect(labelOf(await read(X, 'fr-FR'))).toBe('pair fr-FR'); expect(await listed(X)).toEqual(['pair fr-FR', 'suitex en-US']); @@ -1018,6 +1020,7 @@ describe('[#31699 F2] a pair member row two holders could own is refused on both expect(labelOf(await read(Z, 'fr-FR'))).toBe('pair fr-FR'); expect(await listed(Z)).toEqual(['pair fr-FR']); expect(await forSend(Z)).toEqual(['pair fr-FR']); + expect((await protocol.listServedOverrides({ packageId: Z })).map((e) => `${e.name}:${e.member}`)).toEqual(['welcome:fr-FR']); }); it('NARROWING — an undeclared row while another App\'s pair stores an undeclared row of the name: neither address serves it, as the registry binds neither (residual 2, contract review F6; BASE at 075fb3188: `?package=Y` served es-ES, `?package=P` fr-FR)', async () => { diff --git a/packages/spec/src/migrations/entries/semantic/18.declared-row-not-moved-to-addition.ts b/packages/spec/src/migrations/entries/semantic/18.declared-row-not-moved-to-addition.ts new file mode 100644 index 00000000000..2650a4d100d --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.declared-row-not-moved-to-addition.ts @@ -0,0 +1,36 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// ADR-0150 D4 (#32606): a row of an App's `.custom` pair that declares package X +// is X's while X still ships any member of the name, never also a bundle +// addition Z's "moved edit" because Z ships the row's member and X does not. A +// change of which stored row a read serves at Z, not of any key: no schema key +// moves and no stored row changes shape, so no tombstone and no D2 conversion. +// No relevance question: the moved answer turns on two installed packages of one +// App shipping members of one name, which no question over one stack can name. +export const entry: SemanticMigration = { + id: 'declared-row-not-moved-to-addition', + surface: + 'A bundled item (an email_template locale) that an App\'s .custom pair stores declaring package X ' + + '(overrides: { package: X }) at a member X does not ship, while X ships another member of the name and a ' + + 'bundle addition Z of the same App ships that member: the reads at Z\'s address (GET /api/v1/meta/TYPE/NAME' + + '?package=Z&member=M), Z\'s list (GET /api/v1/meta/TYPE?package=Z), the execution list a send resolved to Z ' + + 'reads, and the customizations read of Z', + replacement: + 'Read the declared row at the package it declares: GET /api/v1/meta/TYPE/NAME?package=X&member=M and X\'s ' + + 'list serve it, as before. To customize Z\'s own member, save a row declaring Z (overrides: { package: Z }).', + reason: + 'The moved-edit rule (#31593) serves a row declaring a former owner at the package that ships the item now, ' + + 'and it asked whether the former owner still ships the item at the member\'s grain. X ships the name (another ' + + 'member), so it still holds it and serves the row at its own address; Z also served it, stamped Z, as its own ' + + 'item: one row at two packages\' addresses (ADR-0150 red line 2). The former owner is now asked at the ' + + 'name\'s grain, so Z serves its own member. A former owner that ships nothing of the name any more still ' + + 'hands its edit on, as before. There is no mechanical rewrite: whether a tenant meant X\'s row for Z is a ' + + 'judgement about that tenant.', + acceptanceCriteria: + 'For every App pair row declaring a package that still ships a member of the name, at a member a bundle ' + + 'addition of the App ships: GET /api/v1/meta/TYPE/NAME?package=ADDITION&member=M and the addition\'s lists ' + + 'answer the addition\'s own member, the declared package\'s address and lists answer the row, and a tenant ' + + 'who wants the addition\'s member customized has saved a row declaring the addition.', +}; From de5009bbb6885827ed8a1a9801a7194c971fb4c5 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 15:18:00 +0000 Subject: [PATCH 3/5] fix(metadata-protocol): the list doors withhold a disabled holder's pair row and a dependent's addition to its bundle (ADR-0150 D3) Claude-Session: https://claude.ai/code/session_016WV4cy1y7UNVbT2QAdmgdn Co-authored-by: Claude --- .../src/protocol-meta-list-reads.ts | 86 ++++++++++++++++++- 1 file changed, 84 insertions(+), 2 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-meta-list-reads.ts b/packages/metadata-protocol/src/protocol-meta-list-reads.ts index be4a3d90d67..01f3d8b02ce 100644 --- a/packages/metadata-protocol/src/protocol-meta-list-reads.ts +++ b/packages/metadata-protocol/src/protocol-meta-list-reads.ts @@ -18,7 +18,7 @@ * not move. */ -import { ITEM_KEY_DISCRIMINATORS, isTenantAuthored, pairsOf } from '@objectstack/metadata-core'; +import { ITEM_KEY_DISCRIMINATORS, isTenantAuthored, packageDependencyClosure, pairsOf } from '@objectstack/metadata-core'; import { PLURAL_TO_SINGULAR, SINGULAR_TO_PLURAL } from '@objectstack/spec/shared'; import { isAggregatedViewContainer } from '@objectstack/spec/ui'; import { @@ -49,7 +49,12 @@ import { storedEntryRow } from './protocol-stored-overlay-types.js'; import { viewIdentityPatch } from './protocol-view-normalization.js'; import { isServedOverrideRowOf, type ServedOverrideRow } from './served-override.js'; import { installedManifestsOfEngine } from './installed-manifests.js'; -import { declinesPackageLessRowAt, packageLessRowWithheld, pairMemberWithheldAt } from './protocol-exact-qualifier.js'; +import { + declinesPackageLessRowAt, + disabledExactAddressHolder, + packageLessRowWithheld, + pairMemberWithheldAt, +} from './protocol-exact-qualifier.js'; /** The body of `ObjectStackProtocolImplementation#getMetaItems`; the method's docblock there is its contract. */ export async function getMetaItems(host: Pick, request: { type: string; packageId?: string; names?: readonly string[]; previewDrafts?: boolean }) { @@ -92,6 +97,68 @@ function decorateListedItem(type: string, item: unknown): unknown { return { ...served, name: (item as { name: string }).name, ...(_diagnostics !== undefined ? { _diagnostics } : {}) }; } +/** + * [#32354, ADR-0150 D3] Whether the effective or execution list withholds an + * item of `name` it serves at `packageId` because the item belongs to a + * disabled holder: a disabled package holds no name, and the list hides what + * the by-name read naming the same address hides, independent of the order + * things were registered or saved. `undefined` (nothing withheld) for a type + * the registry does not read by package, a registry that cannot answer, and + * while no package is disabled, so no list moves then. + * + * - `'address'` (a list scoped to `packageId`): the exact read of the name at + * that address is the disabled package's withheld item + * ({@link disabledExactAddressHolder}: the package is disabled, or it is a + * customization pair whose every base holding the name is). Before, the + * list scoped to a disabled base, or to its pair, listed the pair's row at + * a member the base does not ship while both exact reads answered 404. + * - `'unscoped'` (the list naming no package, `packageId` the item's own + * binding): the same, which leaves out a disabled holder's pair row; and, + * for a bundle (`ITEM_KEY_DISCRIMINATORS`), an addition to a disabled + * holder's bundle: `packageId` holds the name only as an addition (the + * registry's served holders leave it out for every other reader) and each + * holder in its declared dependency closure is disabled. Both were listed, + * so a send naming no package, which reads this list, sent them. The + * dependent's own address keeps serving its addition, as its exact read + * does. + * + * Every holder is read with `includeDisabledPackages`, so a disable never + * promotes a dependent's addition to a holder. Answers are cached per call. + */ +function disabledHolderListing( + host: Pick, + type: string, +): ((name: string, packageId: string, naming: 'address' | 'unscoped') => boolean) | undefined { + const registry: any = host.engine?.registry; + if (typeof registry?.packageScopedHoldersOf !== 'function' || typeof registry.isPackageDisabled !== 'function' + || typeof registry.getAllPackages !== 'function') return undefined; + if (!(registry.getAllPackages() as ReadonlyArray<{ enabled?: unknown; status?: unknown } | undefined>) + .some((pkg) => pkg?.enabled === false || pkg?.status === 'disabled')) return undefined; + const disabled = (id: string): boolean => registry.isPackageDisabled(id) === true; + const isBundle = ITEM_KEY_DISCRIMINATORS[type] !== undefined; + const answers = new Map(); + const judge = (name: string, packageId: string, naming: 'address' | 'unscoped'): boolean => { + if (disabledExactAddressHolder(host, { type, name, packageId }) !== undefined) return true; + if (naming !== 'unscoped' || !isBundle) return false; + const every: readonly string[] = registry.packageScopedHoldersOf(type, name, null, { includeDisabledPackages: true }) ?? []; + if (every.includes(packageId)) return false; + const own: readonly string[] = registry.packageScopedHoldersOf(type, name, packageId, { includeDisabledPackages: true }) ?? []; + if (!own.includes(packageId)) return false; + const reach = new Set(packageDependencyClosure(packageId, registry)?.dependencies ?? []); + const bases = every.filter((holder) => holder !== packageId && reach.has(holder)); + return bases.length > 0 && bases.every(disabled); + }; + return (name, packageId, naming) => { + const key = `${naming}\u0000${packageId}\u0000${name}`; + let answer = answers.get(key); + if (answer === undefined) { + answer = judge(name, packageId, naming); + answers.set(key, answer); + } + return answer; + }; +} + /** The body of `ObjectStackProtocolImplementation#readFlattenedMetaItems`; the method's docblock there is its contract. */ export async function readFlattenedMetaItems(host: Pick, request: { type: string; packageId?: string; names?: readonly string[]; previewDrafts?: boolean }, audience: 'served' | 'execution', @@ -865,6 +932,21 @@ export async function readFlattenedMetaItems(host: Pick !isItemOfDisabledPackage(host.engine.registry, it)); + // [#32354, ADR-0150 D3] …and an item another package carries for a + // disabled holder ({@link disabledHolderListing}): the list scoped to + // a package serves no name its exact read withholds as a disabled + // package's, and the list naming no package leaves out a disabled + // holder's pair row and a dependent's addition to its bundle. + const withheld = disabledHolderListing(host, request.type); + if (withheld) { + items = (items as any[]).filter((it) => { + const itemName = (it as { name?: unknown } | null)?.name; + if (typeof itemName !== 'string') return true; + if (packageId) return !withheld(itemName, packageId, 'address'); + const bound = boundPackageOf((it as { _packageId?: unknown })._packageId); + return bound === undefined || !withheld(itemName, bound, 'unscoped'); + }); + } } // [#28877] …and, on the effective served list, an action that launches // into a disabled package ({@link isActionWithheldByDisabledPackage}), From 570a6d579a43cd8e8568816b73e0e5056223d943 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 15:23:37 +0000 Subject: [PATCH 4/5] test(objectql): pin the list doors beside a disabled holder's pair row and a dependent's addition, both orders Claude-Session: https://claude.ai/code/session_016WV4cy1y7UNVbT2QAdmgdn Co-Authored-By: Claude --- .../package-scoped-exact-qualifier.test.ts | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/packages/objectql/src/package-scoped-exact-qualifier.test.ts b/packages/objectql/src/package-scoped-exact-qualifier.test.ts index b4805d322fb..8a107f41bef 100644 --- a/packages/objectql/src/package-scoped-exact-qualifier.test.ts +++ b/packages/objectql/src/package-scoped-exact-qualifier.test.ts @@ -2461,3 +2461,95 @@ describe('[#32183] an App\'s pair two modules share, one of them disabled', () = expect(JSON.stringify(neither ?? null)).not.toMatch(/(suitex|suitey) dashboard/); }); }); + +/** + * [#32354, ADR-0150 D3, epic note 6820147040] The list doors beside a disabled + * holder: a disabled package holds no name, so no list serves what it carries + * for one. FROM (measured on `2b2e5b41`, both registration orders and both save + * orders): with A disabled, the list naming no package and its execution face + * listed the row A's customization pair stores at a member A does not ship, + * and a dependent's added locale of A's template; the lists scoped to A and to + * A's pair listed the pair's row too, while the exact reads of both addresses + * answered 404. A send naming no package reads that execution list. TO: none + * of them. The dependent's own list keeps its addition, as its exact read + * does, and an enabled holder's lists are unchanged. Re-enabled, as before. + */ +describe('[#32354] the list doors serve nothing a disabled holder\'s pair or dependent carries for it', () => { + const DEP = 'com.acme.dep'; + const tpl = (packageId: string, locale: string) => registry.registerItem('email_template', { + name: 'welcome', label: `${packageId.split('.').pop()} ${locale}`, locale, subject: locale, bodyHtml: '

x

', + }, 'name' as never, packageId); + const pairRow = (name: string, label: string) => rows.push({ + id: `row_${name}`, type: 'email_template', name, state: 'active', package_id: PAIR_A, bundle_member: 'fr-FR', + metadata: JSON.stringify({ name, label, locale: 'fr-FR', subject: label, bodyHtml: '

p

' }), + }); + const labelsOf = async (read: Promise<{ items?: unknown[] }>, name = 'welcome') => ((await read).items ?? []) + .filter((it) => (it as { name?: unknown }).name === name) + .map((it) => (it as { label?: string }).label) + .sort(); + const answers = async () => ({ + list: await labelsOf(protocol.getMetaItems({ type: 'email_template' })), + execution: await labelsOf(protocol.getMetaItemsForExecution({ type: 'email_template' })), + atA: await labelsOf(protocol.getMetaItems({ type: 'email_template', packageId: A })), + executionAtA: await labelsOf(protocol.getMetaItemsForExecution({ type: 'email_template', packageId: A })), + atPair: await labelsOf(protocol.getMetaItems({ type: 'email_template', packageId: PAIR_A })), + atDep: await labelsOf(protocol.getMetaItems({ type: 'email_template', packageId: DEP })), + atB: await labelsOf(protocol.getMetaItems({ type: 'email_template', packageId: B })), + }); + type Answers = Awaited>; + const lists = (unscoped: string[], atA: string[], rest: Pick): Answers => + ({ list: unscoped, execution: unscoped, atA, executionAtA: atA, ...rest }); + + /** `[state, holders, carried, enabled answers, A-disabled answers]`. */ + const STATES: ReadonlyArray<[string, readonly string[], 'pair row' | 'addition', Answers, Answers]> = [ + ['one holder, its pair\'s row', [A], 'pair row', + lists(['alpha en-US', 'pair fr-FR'], ['alpha en-US', 'pair fr-FR'], { atPair: ['pair fr-FR'], atDep: [], atB: [] }), + lists([], [], { atPair: [], atDep: [], atB: [] })], + ['two holders, the disabled one\'s pair\'s row', [A, B], 'pair row', + lists(['alpha en-US', 'beta en-US', 'pair fr-FR'], ['alpha en-US', 'pair fr-FR'], { atPair: ['pair fr-FR'], atDep: [], atB: ['beta en-US'] }), + lists(['beta en-US'], [], { atPair: [], atDep: [], atB: ['beta en-US'] })], + ['one holder, a dependent\'s addition', [A], 'addition', + lists(['alpha en-US', 'dep fr-FR'], ['alpha en-US'], { atPair: [], atDep: ['dep fr-FR'], atB: [] }), + lists([], [], { atPair: [], atDep: ['dep fr-FR'], atB: [] })], + ['two holders, a dependent of the disabled one\'s addition', [A, B], 'addition', + lists(['alpha en-US', 'beta en-US', 'dep fr-FR'], ['alpha en-US'], { atPair: [], atDep: ['dep fr-FR'], atB: ['beta en-US'] }), + lists(['beta en-US'], [], { atPair: [], atDep: ['dep fr-FR'], atB: ['beta en-US'] })], + ]; + const CASES = STATES.flatMap(([state, holders, carried, enabled, disabled]) => + (['as listed', 'reversed'] as const).flatMap((order) => (carried === 'pair row' + ? (['stored first', 'stored last'] as const) + : (['no row'] as const)).map((save) => [state, order, save, holders, carried, enabled, disabled] as const))); + + beforeEach(() => { + registry.installPackage({ ...(manifest(DEP) as object), dependencies: { [A]: '^1.0.0' } } as never, 'code'); + registry.installPackage(manifest(PAIR_A), 'code'); + }); + + it.each(CASES)('%s, registered %s, row %s: A disabled, no list serves what is carried for A; re-enabled, as before', async (_state, order, save, holders, carried, enabled, disabled) => { + if (save === 'stored first') pairRow('welcome', 'pair fr-FR'); + const shipped: Array<[string, string]> = [...holders.map((id): [string, string] => [id, 'en-US']), ...(carried === 'addition' ? [[DEP, 'fr-FR'] as [string, string]] : [])]; + for (const [id, locale] of order === 'reversed' ? [...shipped].reverse() : shipped) tpl(id, locale); + if (save === 'stored last') pairRow('welcome', 'pair fr-FR'); + + // CONTROL — nothing disabled: every list as on FROM. + expect(await answers()).toEqual(enabled); + registry.disablePackage(A); + expect(await answers()).toEqual(disabled); + // Read again, after the first reads hydrated the stored row: the same answers. + expect(await answers()).toEqual(disabled); + registry.enablePackage(A); + expect(await answers()).toEqual(enabled); + }); + + it.each(['as listed', 'reversed'] as const)('CONTROL — registered %s: the pair\'s own item of a name A ships nothing of stays listed while A is disabled, as its by-name read serves it', async (order) => { + const arrange = [() => tpl(A, 'en-US'), () => pairRow('farewell', 'pair own farewell')]; + for (const step of order === 'reversed' ? [...arrange].reverse() : arrange) step(); + registry.disablePackage(A); + expect(labelOf(await protocol.getMetaItem({ type: 'email_template', name: 'farewell', member: 'fr-FR' } as never))).toBe('pair own farewell'); + for (const read of [ + protocol.getMetaItems({ type: 'email_template' }), + protocol.getMetaItemsForExecution({ type: 'email_template' }), + protocol.getMetaItems({ type: 'email_template', packageId: PAIR_A }), + ]) expect(await labelsOf(read, 'farewell')).toEqual(['pair own farewell']); + }); +}); From 27fb3f27c3cbad0e8291b691deee4b9b84ae8236 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 15:32:29 +0000 Subject: [PATCH 5/5] test(rest): pin GET /meta/:type and the send naming no package beside a disabled holder; changeset Claude-Session: https://claude.ai/code/session_016WV4cy1y7UNVbT2QAdmgdn Co-Authored-By: Claude --- .../32354-list-doors-disabled-holder.md | 24 +++++ .../src/meta-disabled-package-doors.test.ts | 90 +++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 .changeset/32354-list-doors-disabled-holder.md diff --git a/.changeset/32354-list-doors-disabled-holder.md b/.changeset/32354-list-doors-disabled-holder.md new file mode 100644 index 00000000000..b92bd1dc8d9 --- /dev/null +++ b/.changeset/32354-list-doors-disabled-holder.md @@ -0,0 +1,24 @@ +--- +'@objectstack/metadata-protocol': patch +--- + +fix(metadata-protocol)!: the metadata lists serve nothing a disabled package's customization pair or a dependent's added bundle member carries for it (ADR-0150 D3, #32354) + +Clause-②: no (narrowing) +Metadata-protocol: none + + + +**BREAKING** for a reader of a metadata list while a package is disabled. A disabled package holds no name (ADR-0150 D3), and the by-name reads already withheld what it carries; three lists still served it, by the order things were registered and saved. Measured over a real `SchemaRegistry`, both registration orders, the pair's row stored before and after: package A ships `welcome` in `en-US`; its pair `A.custom` stores a `fr-FR` row of it, or package DEP (depending on A) ships a `fr-FR` addition to A's template; A is disabled. + +- `GET /meta/email_template` and the execution list (`getMetaItemsForExecution`, no package): the pair's `fr-FR` row and DEP's `fr-FR` addition were listed → not listed, with one holder or beside an enabled second holder of the name. A send naming no package reads this list, so it no longer sends either while A is disabled. +- `GET /meta/email_template?package=A` and its execution list: the pair's `fr-FR` row was listed → `[]`, as `?package=A&member=fr-FR` answers 404. +- `GET /meta/email_template?package=A.custom`: the pair's `fr-FR` row was listed → not listed, as `?package=A.custom&member=fr-FR` answers 404. + +The rule is the exact read's: a list scoped to a package serves no name whose exact read at that package is a disabled package's withheld item; the list naming no package leaves out an item whose own package's address is, and a bundle addition whose every base in its dependency closure is disabled. It applies to every package-scoped type, and only while some package is disabled. + +**Not moved.** With nothing disabled, every list answers as before. DEP's own list (`?package=DEP`) keeps its addition, as its exact read does. An enabled holder's lists, the pair's own item of a name A ships nothing of, and the per-package layer (the package export, which keeps a disabled package's items) answer as before. Re-enabling A restores every list. + +Until the email send door judges the served holders (#32670), a send made from DEP itself reads the list naming no package for this name, so it no longer finds DEP's `fr-FR` while A is disabled. + +The fix for a reader: re-enable the package to list its customization again; a dependent's addition stays readable at the dependent's own address. diff --git a/packages/rest/src/meta-disabled-package-doors.test.ts b/packages/rest/src/meta-disabled-package-doors.test.ts index d959cc39d83..e5b54a932d5 100644 --- a/packages/rest/src/meta-disabled-package-doors.test.ts +++ b/packages/rest/src/meta-disabled-package-doors.test.ts @@ -29,6 +29,7 @@ import { describe, it, expect, vi } from 'vitest'; import { assertEngineDeleteDispatch, assertEngineUpdateDispatch, assertEngineFindOnePredicate } from '@objectstack/metadata-core'; import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol'; import { SchemaRegistry } from '@objectstack/objectql'; +import { createRegistryEmailTemplateLoader } from '@objectstack/plugin-email'; import { RestServer } from './rest-server.js'; const META = '/api/v1/meta'; @@ -693,6 +694,95 @@ describe('[#32354] RestServer: a disabled customization pair and a disabled base }, 60_000); }); +/** + * [#32354, ADR-0150 D3, epic note 6820147040] `GET /meta/:type` beside a + * disabled holder, and the send naming no package that reads its execution + * face. ALPHA ships `welcome` in `en-US`; its pair stores a `fr-FR` row of it + * (or DEP, depending on ALPHA, ships a `fr-FR` addition); ALPHA is disabled. + * FROM: the unscoped list, `?package=ALPHA` and `?package=ALPHA.custom` listed + * the pair's row, the unscoped list listed DEP's addition, and a send naming + * no package sent either. TO: none of them; `?package=DEP` keeps its addition. + */ +describe('[#32354] RestServer: the list doors and the send naming no package beside a disabled holder', () => { + const ALPHA = 'com.qa.alpha'; + const PAIR = `${ALPHA}.custom`; + const DEP = 'com.qa.dep'; + const tpl = (host: ReturnType, packageId: string, locale: string) => host.registry.registerItem('email_template', { + name: 'welcome', label: `${packageId.split('.').pop()} ${locale}`, locale, subject: `${packageId} ${locale}`, bodyHtml: '

x

', + } as any, 'name', packageId); + const pairRow = (host: ReturnType) => (host.protocol as any).engine.insert('sys_metadata', { + type: 'email_template', name: 'welcome', package_id: PAIR, bundle_member: 'fr-FR', state: 'active', scope: 'platform', strategy: 'merge', version: 1, + metadata: JSON.stringify({ name: 'welcome', label: 'pair fr-FR', locale: 'fr-FR', subject: 'pair fr-FR', bodyHtml: '

p

' }), + }); + const list = async (host: ReturnType, query: Record = {}) => { + const route = host.rest.getRoutes().find((r: any) => r.method === 'GET' && r.path === `${META}/:type`); + if (!route) throw new Error('GET /:type is not registered'); + const res = makeRes(); + await route.handler({ method: 'GET', path: `${META}/email_template`, params: { type: 'email_template' }, query, body: {}, headers: {} }, res); + expect(res.statusCode, JSON.stringify(res.body)).toBe(200); + const items: any[] = res.body?.items ?? res.body?.data?.items ?? res.body ?? []; + return items.filter((it) => it?.name === 'welcome').map((it) => it.label as string).sort(); + }; + const answers = async (host: ReturnType) => { + const loader = createRegistryEmailTemplateLoader({ protocol: host.protocol as any, registry: host.registry as any }); + return { + list: await list(host), + atAlpha: await list(host, { package: ALPHA }), + atPair: await list(host, { package: PAIR }), + atDep: await list(host, { package: DEP }), + send: (await loader.load('welcome', 'fr-FR'))?.subject ?? null, + sendFromDep: (await loader.load('welcome', 'fr-FR', { callerPackageId: DEP }))?.subject ?? null, + }; + }; + const CASES = [ + ['the pair\'s row', 'registered first', 'row stored first'], + ['the pair\'s row', 'registered first', 'row stored last'], + ['the pair\'s row', 'registered last', 'row stored first'], + ['the pair\'s row', 'registered last', 'row stored last'], + ['a dependent\'s addition', 'registered first', 'no row'], + ['a dependent\'s addition', 'registered last', 'no row'], + ] as const; + + it.each(CASES)('%s, ALPHA installed and shipped %s, %s: ALPHA disabled, no list and no send naming no package serves it; re-enabled, as before', async (carried, order, save) => { + const host = setup(); + const installs = [() => host.registry.installPackage({ id: ALPHA, name: ALPHA, version: '1.0.0' } as any, 'code'), + () => host.registry.installPackage({ id: DEP, name: DEP, version: '1.0.0', dependencies: { [ALPHA]: '^1' } } as any, 'code')]; + for (const install of order === 'registered first' ? installs : [...installs].reverse()) install(); + host.registry.installPackage({ id: PAIR, name: PAIR, version: '1.0.0', dependencies: { [ALPHA]: '^1' } } as any, 'authored'); + const pair = carried === 'the pair\'s row'; + if (pair && save === 'row stored first') await pairRow(host); + const ships = [() => tpl(host, ALPHA, 'en-US'), ...(pair ? [] : [() => tpl(host, DEP, 'fr-FR')])]; + for (const ship of order === 'registered first' ? ships : [...ships].reverse()) ship(); + if (pair && save === 'row stored last') await pairRow(host); + + const carriedLabel = pair ? 'pair fr-FR' : 'dep fr-FR'; + const carriedSubject = pair ? 'pair fr-FR' : `${DEP} fr-FR`; + const enabled = { + list: ['alpha en-US', carriedLabel].sort(), + atAlpha: pair ? ['alpha en-US', 'pair fr-FR'] : ['alpha en-US'], + atPair: pair ? ['pair fr-FR'] : [], + atDep: pair ? [] : ['dep fr-FR'], + send: carriedSubject, + sendFromDep: carriedSubject, + }; + // CONTROL — nothing disabled: as FROM. + expect(await answers(host)).toEqual(enabled); + host.registry.disablePackage(ALPHA); + expect(await answers(host)).toEqual({ + list: [], + atAlpha: [], + atPair: [], + atDep: pair ? [] : ['dep fr-FR'], + send: null, + // Declared: a send from DEP reads the list naming no package for this + // name until the send door judges the served holders (#32670). + sendFromDep: null, + }); + host.registry.enablePackage(ALPHA); + expect(await answers(host)).toEqual(enabled); + }, 60_000); +}); + /** * [#32607, ADR-0150 D3] With NO package disabled, a name two enabled packages * hold only as stored rows (no package ships it) is refused on every bare door