diff --git a/.changeset/32849-bare-layered-read-declared-override.md b/.changeset/32849-bare-layered-read-declared-override.md new file mode 100644 index 00000000000..90be42dd06f --- /dev/null +++ b/.changeset/32849-bare-layered-read-declared-override.md @@ -0,0 +1,12 @@ +--- +'@objectstack/metadata-protocol': patch +--- + +fix(metadata-protocol): the layered read naming no package serves an App pair's declared override of a bundle addition's own member as `effective` + +Clause-②: no +Metadata-protocol: none + +An App's customization pair (`.custom`) can store a row that declares `overrides: { package: Z }` for the bundle member a bundle addition Z ships, for example the `fr-FR` locale Z adds to an email template another package of the App ships in `en-US`. The plain read naming no package (`?member=fr-FR`) and `?package=Z&member=fr-FR&layers=true` already served that row. The layered read naming no package (`?member=fr-FR&layers=true`, `getMetaItemLayered` without a package) answered Z's shipped `fr-FR` as `effective`, with no `overlay`, and so disagreed with the read it describes. + +It now reads such a member at the one enabled package that ships it, as the plain read does: `code` is Z's shipped member, `overlay` the pair's row, `effective` the override, and the envelope names Z. The pending draft layer stays the one the strict draft read serves. Nothing else moves: a member two packages ship, a row declaring another package, an undeclared pair row, the environment's own item and a disabled shipper answer as before. No stored row changes shape. diff --git a/packages/metadata-protocol/src/protocol-meta-item-face.ts b/packages/metadata-protocol/src/protocol-meta-item-face.ts index ec8a3e1c1ea..f6bac9b63a7 100644 --- a/packages/metadata-protocol/src/protocol-meta-item-face.ts +++ b/packages/metadata-protocol/src/protocol-meta-item-face.ts @@ -422,9 +422,10 @@ export function isAnotherHoldersCopy(registry: any, type: string, name: string, * another package (the #32606 shape), an undeclared pair row, the * environment's own item, a disabled shipper, and the strict draft read. * The rows are read through `host.readItemActiveRows`, so the read below takes - * them instead of reading them again (#24371). + * them instead of reading them again (#24371). The layered read naming no + * package takes the same address for its layers (`getMetaItemLayered`). */ -async function declaredMemberOverrideAddressOf( +export async function declaredMemberOverrideAddressOf( host: ServedRowHost, type: string, name: string, member: string | undefined, ): Promise { diff --git a/packages/metadata-protocol/src/protocol-meta-layered-reads.ts b/packages/metadata-protocol/src/protocol-meta-layered-reads.ts index 6866306e831..70eb6082836 100644 --- a/packages/metadata-protocol/src/protocol-meta-layered-reads.ts +++ b/packages/metadata-protocol/src/protocol-meta-layered-reads.ts @@ -78,7 +78,7 @@ import { boundPackageOf, withRowBinding } from './protocol-package-bindings.js'; import type { RowlessExpandedView } from './protocol-stored-overlay-types.js'; import { type ServedOverrideRow, isServedOverrideRowOf } from './served-override.js'; import { installedManifestsOfEngine } from './installed-manifests.js'; -import { isAnotherHoldersCopy, servedAddressJudgment } from './protocol-meta-item-face.js'; +import { declaredMemberOverrideAddressOf, isAnotherHoldersCopy, servedAddressJudgment } from './protocol-meta-item-face.js'; import { packagelessAddressAmbiguityRefusal } from './sys-metadata-repository.js'; /** The body of `ObjectStackProtocolImplementation#packagelessLayeredReadRefusal`; the method's docblock there is its contract. */ @@ -216,6 +216,18 @@ export async function getMetaItemLayered(host: Pick` serves, never the + // shipper's own member beside it. The draft layer stays at the address the + // strict draft read takes, which this arm does not move (the plain read + // leaves its strict draft read where it was). + const declaredOverrideAt = request.packageId || judged !== undefined + ? undefined + : await declaredMemberOverrideAddressOf(host, request.type, request.name, resolveBundleMemberSelector(request.type, request.member)); + const draftPackageId = request.packageId; + if (declaredOverrideAt !== undefined) request = { ...request, packageId: declaredOverrideAt }; // [#26699] Ruling 6116165299 (Q2 i), extended to this read by the // option-A ruling on #26649: ONE member of a bundled type, the // selector's or else the canonical one, read exactly as @@ -647,7 +659,7 @@ export async function getMetaItemLayered(host: Pick { + const APP = 'com.acme.suite'; + const X = 'com.acme.suitex'; + const Z = 'com.acme.zeta'; + const PAIR = `${APP}.custom`; + const moduleOf = (id: string, dependencies: Record) => ({ + id, name: id, version: '1.0.0', type: 'module', namespace: id.split('.').pop()!, dependencies, + }) as never; + const installZ = () => registry.installPackage(moduleOf(Z, { [APP]: '^1.0.0', [X]: '^1.0.0' }), 'code'); + const tpl = (locale: string, packageId: string) => registry.registerItem('email_template', { + name: 'welcome', label: `${packageId.split('.').pop()} ${locale}`, locale, + subject: `${packageId.split('.').pop()} ${locale}`, bodyHtml: '

x

', + }, 'name' as never, packageId); + /** A row of the App's pair for `fr-FR`; an active one is hydrated as the boot lays it. */ + const pairRow = (over: Record = {}, state: 'active' | 'draft' = 'active') => { + const body = { name: 'welcome', label: state === 'draft' ? 'pair fr-FR draft' : 'pair fr-FR', locale: 'fr-FR', subject: 'pair fr-FR', bodyHtml: '

p

', ...over }; + rows.push({ id: `row_fr_${state}`, type: 'email_template', name: 'welcome', state, package_id: PAIR, bundle_member: 'fr-FR', metadata: JSON.stringify(body) }); + if (state === 'active') registry.registerItem('email_template', { ...body, _packageId: PAIR, _provenance: 'org' }, 'name' as never); + }; + type Layers = { code?: { label?: string } | null; overlay?: { label?: string } | null; effective?: { label?: string; _packageId?: string } | null; draft?: { label?: string } | null; packageId?: string }; + const layered = (member: string, packageId?: string, withDraft = false) => protocol.getMetaItemLayered({ + type: 'email_template', name: 'welcome', member, ...(packageId ? { packageId } : {}), + } as never, { withDraft } as never) as Promise; + const layersOf = (a: Layers) => [a.code?.label ?? null, a.overlay?.label ?? null, a.effective?.label ?? null, a.packageId]; + + beforeEach(() => { + registry.installPackage(manifest(APP), 'code'); + registry.installPackage(moduleOf(X, { [APP]: '^1.0.0' }), 'code'); + registry.installPackage(manifest(PAIR), 'code'); + }); + + it.each([ + ['addition installed first', () => { installZ(); tpl('en-US', X); tpl('fr-FR', Z); pairRow({ overrides: { package: Z } }); }], + ['row stored first', () => { tpl('en-US', X); pairRow({ overrides: { package: Z } }); installZ(); tpl('fr-FR', Z); }], + ] as const)('the bare layered read of `fr-FR` answers Z\'s layers with the override as `effective` (%s; BASE: `effective` `zeta fr-FR`, no overlay)', async (_order, arrange) => { + arrange(); + const atZ = await layered('fr-FR', Z); + expect(layersOf(atZ), 'CONTROL: `?package=Z&member=fr-FR&layers=true` (UNCHANGED)').toEqual(['zeta fr-FR', 'pair fr-FR', 'pair fr-FR', Z]); + expect(await protocol.packagelessLayeredReadRefusal({ type: 'email_template', name: 'welcome', member: 'fr-FR' } as never), 'the door\'s step 1c refuses nothing').toBeUndefined(); + const bare = await layered('fr-FR'); + expect(layersOf(bare), 'bare `?member=fr-FR&layers=true`').toEqual(['zeta fr-FR', 'pair fr-FR', 'pair fr-FR', Z]); + expect(bare.effective, '`effective` is the document `?package=Z` serves').toEqual(atZ.effective); + expect(labelOf(await protocol.getMetaItem({ type: 'email_template', name: 'welcome', member: 'fr-FR' } as never)), '`effective` is what the plain bare read serves').toBe('pair fr-FR'); + // CONTROL: X's own member is untouched by the override of Z's. + expect(layersOf(await layered('en-US')), 'bare `?member=en-US` (UNCHANGED)').toEqual(['suitex en-US', null, 'suitex en-US', X]); + }); + + it('the draft layer stays the strict draft read\'s, which the arm does not move: the pair\'s pending draft of `fr-FR` (UNCHANGED; at Z\'s address it is no draft)', async () => { + installZ(); tpl('en-US', X); tpl('fr-FR', Z); + pairRow({ overrides: { package: Z } }); + pairRow({ overrides: { package: Z } }, 'draft'); + const strictDraft = labelOf(await protocol.getMetaItem({ type: 'email_template', name: 'welcome', member: 'fr-FR', state: 'draft' } as never)); + expect(strictDraft, 'the plain bare strict draft read').toBe('pair fr-FR draft'); + const bare = await layered('fr-FR', undefined, true); + expect([bare.effective?.label, bare.draft?.label ?? null], 'bare `?member=fr-FR&layers=true` with drafts').toEqual(['pair fr-FR', strictDraft]); + expect((await layered('fr-FR', Z, true)).draft ?? null, 'CONTROL: `?package=Z` reads no draft there (UNCHANGED)').toBeNull(); + }); + + it.each([ + ['no row stored', () => { installZ(); tpl('en-US', X); tpl('fr-FR', Z); }], + ['an undeclared pair row of the locale', () => { installZ(); tpl('en-US', X); tpl('fr-FR', Z); pairRow(); }], + ] as const)('CONTROL — no override of Z declared (%s): the bare layered read answers Z\'s own `fr-FR` and no overlay (UNCHANGED)', async (_order, arrange) => { + arrange(); + expect(layersOf(await layered('fr-FR'))).toEqual(['zeta fr-FR', null, 'zeta fr-FR', Z]); + }); + + it('CONTROL — the row declares X (the #32606 shape): the bare layered read is not moved to Z, and keeps its refusal naming both (UNCHANGED)', async () => { + installZ(); tpl('en-US', X); tpl('fr-FR', Z); + pairRow({ overrides: { package: X } }); + const err = await refusalOf(() => layered('fr-FR')); + expect([err.code, err.status, err.refusal.candidates.map((c) => (c as { packageId?: string }).packageId).sort()]) + .toEqual(['RESOURCE_CONFLICT', 409, [X, Z].sort()]); + }); +}); + /** * [#33817, from #33131 N1] A package X of an App holds the name only through * its own stored row (`package_id` X, hydrated into the bare slot), and that