diff --git a/.changeset/32561-exact-read-adopts-pair-row-binding.md b/.changeset/32561-exact-read-adopts-pair-row-binding.md new file mode 100644 index 00000000000..72c131dcc71 --- /dev/null +++ b/.changeset/32561-exact-read-adopts-pair-row-binding.md @@ -0,0 +1,22 @@ +--- +'@objectstack/metadata-protocol': minor +'@objectstack/objectql': minor +--- + +fix(metadata-protocol)!: the exact read (`?package=X`) no longer serves an undeclared App-pair row the registry binds to no package (ADR-0150 D4, red line 2) + +Clause-②: yes (narrowing) — two exact reads that served a row of an App's customization pair now answer the address's own shipped item: `?package=X` for an undeclared pair row of the very bundle member a bundle addition of another package of the App ships, and a package's address for an undeclared pair row while another App's shared pair stores an undeclared row of the name. In both the registry binds the row to no package. First-party packages in either position: 0. The widening is one public method: `SchemaRegistry#overlayRowBinding(type, name, item)`, the registry's binding of a stored row, read-only, which the exact read asks. +Metadata-protocol: narrowed + + + +**BREAKING** for two exact reads, both of an undeclared row of an App's customization pair (`.custom`, a row with no `overrides.package`). An undeclared row that could customize either of two packages' members is not attributed to one of them (red line 2). To keep such a row on the package whose locale it customizes, save it with `overrides.package` naming that package, the package of the App that ships the locale: the save door accepts it (it already prescribes it, refusing `403 NOT_OVERRIDABLE` a new undeclared row of a locale an installed package ships), and `?package=` then serves the row. A row of a locale no package ships stays readable at `?package=.custom`. + +The exact read's owner check (`pairRowOnAddress`) counted the holders after the registry had bound the row, so a bundle addition was no holder there, and it never read another App's pair. The registry (`SchemaRegistry#pairRowBinding`, since #32408) counts an addition that ships the row's member as a second owner, and binds a row whose count would read another shared pair's undeclared row to no package. The exact read now adopts that binding: `SchemaRegistry#overlayRowBinding(type, name, item)`, a new read-only method, answers it over the holders the exact read serves (a disabled package holds no name, ADR-0150 D3), and `pairRowOnAddress` treats an undeclared pair row as no member of an address whose one owner it does not bind the row to. It adds no count of its own. + +What moves (each line FROM → TO), with App A, X a package of A holding an email template's name, Z a package of A depending on X that ships only `fr-FR` of it (a bundle addition), and `A.custom` storing an undeclared `fr-FR` row: + +- `?package=X&member=fr-FR`: FROM the row TO X's own `fr-FR` (none, `404`). X's list and execution list: FROM carrying the row TO leaving it out. Either order: Z installed before the row (reached by a hydrated row; the save door refuses that write `403 NOT_OVERRIDABLE`, prescribing the declaration) or after it (the row saved and published while X alone held the name, then Z installed). `?package=Z` keeps Z's own `fr-FR`; `?package=A.custom` keeps the row. +- `?package=Y` / `?package=P` when App A's pair and App B's pair each store an undeclared row of the name (the registry binds neither): FROM the pair's row TO the package's own item of that member (none). Each pair's own address keeps its row. + +Unchanged: a row declaring its base (`overrides.package`) binds and serves as declared; the App's own address keeps an undeclared row of its own pair (#28390 ruling A); two holders that could own a row still refuse `409` naming both; a row whose one owner the registry binds it to is served there as before; a registry without `overlayRowBinding` keeps the exact read's own count. With one of two holders of the name disabled, the enabled holder's address, list and execution list keep an undeclared row of the pair (#32183, epic ruling R4-A): the adoption counts the served holders, as the exact read does, while the registry's own readers keep counting every holder, so a disable never moves their binding. diff --git a/.changeset/32561-pair-row-exact-read-semantic-entry.md b/.changeset/32561-pair-row-exact-read-semantic-entry.md new file mode 100644 index 00000000000..f229b1c3788 --- /dev/null +++ b/.changeset/32561-pair-row-exact-read-semantic-entry.md @@ -0,0 +1,10 @@ +--- +'@objectstack/spec': patch +--- + +docs(spec): the protocol upgrade guide names the two exact reads #32561 narrows: an undeclared row of an App's customization pair is no member of a package's address when the registry binds it to no package, because another package of the App ships its locale as a bundle addition or another App's shared pair stores an undeclared row of the name + +Clause-②: no +Metadata-protocol: none + +The semantic entry `pair-row-exact-read-no-owner` (`packages/spec/src/migrations/entries/semantic/18.pair-row-exact-read-no-owner.ts`) registers the narrowing `.changeset/32561-exact-read-adopts-pair-row-binding.md` declares (ADR-0087, `adr-0087: registered`). There is no automatic rewrite, because which package's locale a pair row customizes is a judgement about that row. The remedy it names is the one the save door accepts: declare the package that ships the locale (`overrides.package`). It adds no key and no export. diff --git a/packages/metadata-protocol/src/protocol-exact-qualifier.ts b/packages/metadata-protocol/src/protocol-exact-qualifier.ts index 2af562758d8..69054aa926e 100644 --- a/packages/metadata-protocol/src/protocol-exact-qualifier.ts +++ b/packages/metadata-protocol/src/protocol-exact-qualifier.ts @@ -85,6 +85,16 @@ interface ExactQualifierRegistry { getEnvironmentScopedItem(type: string, name: string, member?: string): unknown; getPackageScopedItem(type: string, name: string, packageId: string, member?: string): unknown; getPackage?(id: string): unknown; + /** + * [#32561] The package the registry binds a stored row of `(type, name)` + * to (objectql's `overlayRowBinding`, the one owner rule every registry + * reader asks, counted over the served holders as this read counts them): + * a package id, `null` for the environment's own item, or `undefined` for + * no package. The exact read adopts it for an undeclared pair row + * ({@link pairRowOnAddress}); a registry without it keeps the exact read's + * own count. + */ + overlayRowBinding?(type: string, name: string, item: unknown): string | null | undefined; } /** @@ -422,7 +432,8 @@ export function exactQualifierItem( const bases = [address.packageId, ...address.registryHolders]; if (bases.some((base) => isPairOf(served, base, installed))) { const verdict = pairRowOnAddress(served, item, address.packageId, bases, - registry.packageScopedHoldersOf(request.type, request.name) ?? [], installed); + registry.packageScopedHoldersOf(request.type, request.name) ?? [], installed, + registryRowBinding(registry, request.type, request.name, item)); if (verdict === 'serve') return item; if (verdict !== 'not-member') { throw refusal(request.type, request.name, address.packageId, 'ambiguous-in-closure', @@ -716,7 +727,22 @@ export function pairMemberWithheldAt( const registry = exactQualifierRegistry(host); if (!registry || (registry as { readsByPackage?(type: string): boolean }).readsByPackage?.(type) !== true) return false; return pairRowOnAddress(pairId, item, base, [base], registry.packageScopedHoldersOf(type, name) ?? [], - installedManifestsOfEngine(host.engine)) !== 'serve'; + installedManifestsOfEngine(host.engine), registryRowBinding(registry, type, name, item)) !== 'serve'; +} + +/** + * [#32561] The registry's binding of the stored row `item`, read lazily + * ({@link ExactQualifierRegistry.overlayRowBinding}), or `undefined` when the + * registry does not answer it (the exact read then keeps its own count). + */ +function registryRowBinding( + registry: ExactQualifierRegistry, + type: string, + name: string, + item: unknown, +): (() => string | null | undefined) | undefined { + const read = registry.overlayRowBinding; + return typeof read === 'function' ? () => read.call(registry, type, name, item) : undefined; } /** @@ -735,6 +761,16 @@ export function pairMemberWithheldAt( * - Else two or more holders could own it: refuse, naming every one (F2). * - Else a sole owner that is not one of the address's bases owns it: not * this address's member (S2). + * - [#32561] Else a sole owner the registry does not bind the row to + * (`registryBinding`, the registry's one owner rule: `pairRowBinding` + * counts a bundle addition that ships the row's member as an owner, and + * binds a row whose count would read another shared pair's undeclared row + * to no package) is no owner of it: not this address's member, so the + * address answers its own shipped item (epic ruling, red line 2). The + * exact read adopts the registry's count rather than counting again. Both + * count the served holders (a disabled package holds no name, ADR-0150 + * D3): with one of two holders disabled, the row stays the enabled one's + * member (#32183, epic ruling R4-A). * - Else (the sole owner is a base, or no holder pairs it) it is served. */ export function pairRowOnAddress( @@ -744,6 +780,7 @@ export function pairRowOnAddress( bases: readonly string[], holders: readonly string[], installed: InstalledManifestLookup, + registryBinding?: () => string | null | undefined, ): 'serve' | 'not-member' | { refuse: string[] } { const declared = declaredOverrideBase(item); if (declared !== undefined) return bases.includes(declared) ? 'serve' : 'not-member'; @@ -751,6 +788,7 @@ export function pairRowOnAddress( const owners = pairMemberOwners(pairId, holders, installed, item); if (owners.length > 1) return { refuse: owners }; if (owners.length === 1 && !bases.includes(owners[0]!)) return 'not-member'; + if (owners.length === 1 && registryBinding !== undefined && registryBinding() !== owners[0]) return 'not-member'; return 'serve'; } diff --git a/packages/objectql/src/package-scoped-exact-qualifier.test.ts b/packages/objectql/src/package-scoped-exact-qualifier.test.ts index a2beb50701c..31bec775165 100644 --- a/packages/objectql/src/package-scoped-exact-qualifier.test.ts +++ b/packages/objectql/src/package-scoped-exact-qualifier.test.ts @@ -922,6 +922,182 @@ describe('[#31699 F2] a pair member row two holders could own is refused on both expect([atZ?.item, atZ?.packageId]).toEqual([undefined, X]); }); + describe('[#32561] the exact read adopts the registry\'s binding of an undeclared pair row: no owner\'s row where the registry binds it to no package', () => { + const Z = 'com.acme.zeta'; + const installZ = () => registry.installPackage({ ...(memberOf(Z) as object), dependencies: { [APP]: '^1.0.0', [X]: '^1.0.0' } } as never, 'code'); + const hydratePairRow = () => registry.registerItem('email_template', { + name: 'welcome', label: 'pair fr-FR', locale: 'fr-FR', subject: 'pair fr-FR', bodyHtml: '

p

', _packageId: PAIR, _provenance: 'org', + }, 'name' as never); + /** Each address answers its own shipped item; the pair's own address still serves the row. */ + const expectNoOwnersRow = async () => { + expect(registry.getPackageScopedItem('email_template', 'welcome', X, 'fr-FR'), 'the registry binds it to no package').toBeUndefined(); + expect((await read(X, 'fr-FR'))?.item, '`?package=X`: X ships no fr-FR').toBeUndefined(); + expect(labelOf(await read(Z, 'fr-FR')), '`?package=Z`: Z\'s own fr-FR').toBe('zeta fr-FR'); + expect(labelOf(await read(PAIR, 'fr-FR')), '`?package=A.custom` still serves the row').toBe('pair fr-FR'); + expect(await listed(X), 'X\'s list leaves it out').not.toContain('pair fr-FR'); + expect(await forSend(X), 'X\'s execution list leaves it out').not.toContain('pair fr-FR'); + // CONTROL: X's own member is still its own. + expect(labelOf(await read(X, 'en-US'))).toBe('suitex en-US'); + }; + + it('NARROWING — an undeclared row of the very locale a bundle addition of another package of the App ships, addition installed first (residual 1; BASE at 075fb3188: `?package=X` served the row)', async () => { + installZ(); + tpl('en-US', X); + tpl('fr-FR', Z); + pairRow(); + hydratePairRow(); + await expectNoOwnersRow(); + }); + + it('NARROWING — the same row stored before the addition is installed: once the addition ships the row\'s locale, X\'s address no longer serves it (residual 1, the other order)', async () => { + tpl('en-US', X); + pairRow(); + hydratePairRow(); + expect(labelOf(await read(X, 'fr-FR')), 'CONTROL — before the addition, X is the one owner').toBe('pair fr-FR'); + installZ(); + tpl('fr-FR', Z); + await expectNoOwnersRow(); + }); + + it('CONTROL — a row that declares X keeps X\'s address beside the addition, as declared', async () => { + installZ(); + tpl('en-US', X); + tpl('fr-FR', Z); + 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); + expect(registry.getPackageScopedItem<{ label: string }>('email_template', 'welcome', X, 'fr-FR')?.label).toBe('pair fr-FR'); + expect(labelOf(await read(X, 'fr-FR'))).toBe('pair fr-FR'); + expect(labelOf(await read(PAIR, 'fr-FR'))).toBe('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. + const BAPP = 'com.beta.base'; + const P = 'com.beta.basep'; + const Q = 'com.beta.baseq'; + const U = 'com.acme.suiteu'; + const BPAIR = `${BAPP}.custom`; + const module = (id: string, deps: string[], namespace = id.split('.').pop()!) => registry.installPackage({ + id, name: id, version: '1.0.0', type: 'module', namespace, dependencies: Object.fromEntries(deps.map((d) => [d, '^1.0.0'])), + } as never, 'code'); + registry.installPackage(manifest(BAPP), 'code'); + module(P, [BAPP]); + module(Q, [BAPP, P]); + module(U, [APP, P], 'suite'); + tpl('en-US', P); + tpl('de-DE', Q); + tpl('fr-FR', U); + tpl('it-IT', Y); + const stored = (pairId: string, locale: string, label: string) => { + const body = { name: 'welcome', label, locale, subject: label, bodyHtml: '

p

' }; + rows.push({ id: `row_${label}`, type: 'email_template', name: 'welcome', state: 'active', package_id: pairId, bundle_member: locale, metadata: JSON.stringify(body) }); + registry.registerItem('email_template', { ...body, _packageId: pairId, _provenance: 'org' }, 'name' as never); + }; + stored(BPAIR, 'fr-FR', 'bpair fr-FR'); + stored(PAIR, 'es-ES', 'pair es-ES'); + expect(registry.getPackageScopedItem('email_template', 'welcome', P, 'fr-FR'), 'the registry binds neither row').toBeUndefined(); + expect(registry.getPackageScopedItem('email_template', 'welcome', Y, 'es-ES')).toBeUndefined(); + expect((await read(Y, 'es-ES'))?.item, '`?package=Y`: Y ships no es-ES').toBeUndefined(); + expect((await read(P, 'fr-FR'))?.item, '`?package=P`: P ships no fr-FR').toBeUndefined(); + expect(labelOf(await read(PAIR, 'es-ES')), 'each pair\'s own address still serves its row').toBe('pair es-ES'); + expect(labelOf(await read(BPAIR, 'fr-FR'))).toBe('bpair fr-FR'); + // CONTROL: each holder's own member is still its own. + expect(labelOf(await read(Y, 'it-IT'))).toBe('suitey it-IT'); + expect(labelOf(await read(P, 'en-US'))).toBe('basep en-US'); + }); + + // [#32561 residual 3, epic ruling R4-A] The adoption counts the served + // holders, as the exact read counts its own: a disabled package holds no + // name (ADR-0150 D3). With one of two holders disabled, the undeclared + // row stays the enabled holder's on its address, in its list and in its + // execution list, while the registry's own binding, over every holder, + // binds it to no package (a disable never moves it). Re-enabled, refused + // naming both. Every-holder adoption would withhold it at X: ablation. + it.each([['enabled holder first', [X, Y]], ['disabled holder first', [Y, X]]] as const)('CONTROL — one of the two holders disabled (%s): the enabled holder\'s address keeps the undeclared row the registry binds to no package; re-enabled, refused naming both', async (_order, order) => { + for (const id of order) tpl('en-US', id); + const pairDe = { name: 'welcome', label: 'pair de-DE', locale: 'de-DE', subject: 'pair de-DE', bodyHtml: '

p

' }; + rows.push({ id: 'row_de', type: 'email_template', name: 'welcome', state: 'active', package_id: PAIR, bundle_member: 'de-DE', metadata: JSON.stringify(pairDe) }); + registry.registerItem('email_template', { ...pairDe, _packageId: PAIR, _provenance: 'org' }, 'name' as never); + registry.disablePackage(Y); + expect(registry.getPackageScopedItem('email_template', 'welcome', X, 'de-DE'), 'the registry\'s own binding counts every holder').toBeUndefined(); + expect(registry.overlayRowBinding('email_template', 'welcome', { ...pairDe, _packageId: PAIR }), 'the adoption counts the served holders').toBe(X); + expect(labelOf(await read(X, 'de-DE'))).toBe('pair de-DE'); + expect(await listed(X)).toContain('pair de-DE'); + expect(await forSend(X)).toContain('pair de-DE'); + registry.enablePackage(Y); + const err = await refusalOf(() => read(X, 'de-DE')); + expect([err.status, err.refusal.candidates.map((c) => (c as { packageId?: string }).packageId).sort()]).toEqual([409, [X, Y]]); + expect(await listed(X)).not.toContain('pair de-DE'); + }); + + // [#32561 contract review M1] The adoption settles the bundle-addition + // rule over every holder and leaves the disabled ones out afterwards, the + // order `packageScopedHoldersOf` counts the exact read's owner in: a + // disable never promotes a dependent's addition to an owner. Z (on the + // App and on Y) ships only fr-FR, an addition to Y; with Y disabled the + // exact read counts X alone, and the adoption binds the undeclared de-DE + // row to X too, so X keeps it. Z ships no de-DE, so this is not residual + // 1. Settling the rule over the served holders only (Y gone, Z an + // addition to nothing) makes X and Z two owners: X would lose the row. + it.each([['enabled holder first', [X, Y]], ['disabled holder first', [Y, X]]] as const)('CONTROL — one of the two holders disabled is the base of a bundle addition (%s): the addition stays one, so the enabled holder\'s address and lists keep the undeclared row; re-enabled, refused naming both', async (_order, order) => { + registry.installPackage({ ...(memberOf(Z) as object), dependencies: { [APP]: '^1.0.0', [Y]: '^1.0.0' } } as never, 'code'); + for (const id of order) tpl('en-US', id); + tpl('fr-FR', Z); + const pairDe = { name: 'welcome', label: 'pair de-DE', locale: 'de-DE', subject: 'pair de-DE', bodyHtml: '

p

' }; + rows.push({ id: 'row_de', type: 'email_template', name: 'welcome', state: 'active', package_id: PAIR, bundle_member: 'de-DE', metadata: JSON.stringify(pairDe) }); + registry.registerItem('email_template', { ...pairDe, _packageId: PAIR, _provenance: 'org' }, 'name' as never); + registry.disablePackage(Y); + expect(registry.packageScopedHoldersOf('email_template', 'welcome'), 'the exact read\'s owner count: Z stays an addition to Y').toEqual([X]); + expect(registry.overlayRowBinding('email_template', 'welcome', { ...pairDe, _packageId: PAIR }), 'the adoption counts as the exact read does').toBe(X); + expect(labelOf(await read(X, 'de-DE'))).toBe('pair de-DE'); + expect(await listed(X)).toContain('pair de-DE'); + expect(await forSend(X)).toContain('pair de-DE'); + expect(labelOf(await read(Z, 'fr-FR')), 'CONTROL: Z\'s own fr-FR').toBe('zeta fr-FR'); + registry.enablePackage(Y); + const err = await refusalOf(() => read(X, 'de-DE')); + expect([err.status, err.refusal.candidates.map((c) => (c as { packageId?: string }).packageId).sort()]).toEqual([409, [X, Y]]); + expect(await listed(X)).not.toContain('pair de-DE'); + }); + + // [#32561 contract review n1] The adoption counts the holders as + // `packageScopedHoldersOf` counts the exact read's owner: every composite + // slot, then the package a bare-slot entry binds to. X holding the name + // only through its own stored row (a row with `package_id` X hydrated + // into the bare slot, no composite slot) is still X's holding, so the + // App's undeclared de-DE pair row is X's member on X's address, as on + // main. Counting composite slots only leaves X out, the row binds to the + // pair, and X's address would lose it: ablation. + for (const holding of ['its own stored row in the bare slot', 'CONTROL: its composite slot'] as const) { + it.each([['holding first', true], ['pair row first', false]] as const)(`${holding === 'CONTROL: its composite slot' ? 'CONTROL' : 'UNCHANGED'} — X holds the name through ${holding} (%s): X's address and lists keep the App's undeclared pair row`, async (_order, holdingFirst) => { + const xEn = { name: 'welcome', label: 'suitex en-US', locale: 'en-US', subject: 'suitex en-US', bodyHtml: '

x

' }; + const pairDe = { name: 'welcome', label: 'pair de-DE', locale: 'de-DE', subject: 'pair de-DE', bodyHtml: '

p

' }; + const registerHolding = () => { + if (holding === 'CONTROL: its composite slot') { tpl('en-US', X); return; } + rows.push({ id: 'row_x', type: 'email_template', name: 'welcome', state: 'active', package_id: X, bundle_member: 'en-US', metadata: JSON.stringify(xEn) }); + registry.registerItem('email_template', { ...xEn, _packageId: X, _provenance: 'org' }, 'name' as never); + }; + const registerPairRow = () => { + rows.push({ id: 'row_de', type: 'email_template', name: 'welcome', state: 'active', package_id: PAIR, bundle_member: 'de-DE', metadata: JSON.stringify(pairDe) }); + registry.registerItem('email_template', { ...pairDe, _packageId: PAIR, _provenance: 'org' }, 'name' as never); + }; + if (holdingFirst) { registerHolding(); registerPairRow(); } else { registerPairRow(); registerHolding(); } + expect(registry.overlayRowBinding('email_template', 'welcome', { ...pairDe, _packageId: PAIR }), 'the adoption counts X as the exact read does').toBe(X); + expect(labelOf(await read(X, 'de-DE'))).toBe('pair de-DE'); + expect(labelOf(await read(X, 'en-US'))).toBe('suitex en-US'); + // The lists are pinned for the composite slot only: with X holding through its stored row alone, X's + // lists leave the row out on main and here alike (the list door's own count, outside this card). + if (holding === 'CONTROL: its composite slot') { + expect(await listed(X)).toContain('pair de-DE'); + expect(await forSend(X)).toContain('pair de-DE'); + } + }); + } + + }); + it('a sole owner keeps its member: another package of the pair does not serve it (delta review S2; through the doors the qualifier refuses the non-holder first)', async () => { tpl('en-US', X); pairRow(); diff --git a/packages/objectql/src/package-scoped-resolver.test.ts b/packages/objectql/src/package-scoped-resolver.test.ts index cca41eed5af..95d9396d0d1 100644 --- a/packages/objectql/src/package-scoped-resolver.test.ts +++ b/packages/objectql/src/package-scoped-resolver.test.ts @@ -730,7 +730,7 @@ describe('[#32408] every overlay-slot reader binds an App pair\'s row as the exa ...body('email_template', 'welcome', 'bpair'), locale: 'fr-FR', _packageId: `${B}.custom`, _provenance: 'org', }, 'name' as never); pairRow('email_template', 'welcome', 'pair', undefined, 'es-ES'); - // Each pair's row would wait on the other pair's count, so neither binds (the exact read serves both: #32561). + // Each pair's row would wait on the other pair's count, so neither binds (the exact read adopts this, #32561: `package-scoped-exact-qualifier.test.ts`). expect(registry.getPackageScopedItem('email_template', 'welcome', P, 'fr-FR')).toBeUndefined(); expect([templateOf(U, 'es-ES'), templateOf(Y, 'es-ES')]).toEqual([undefined, undefined]); expect(registry.getEnvironmentScopedItem('email_template', 'welcome', 'es-ES')).toBeUndefined(); diff --git a/packages/objectql/src/registry.ts b/packages/objectql/src/registry.ts index 02a3f42de46..a9eb9996f9f 100644 --- a/packages/objectql/src/registry.ts +++ b/packages/objectql/src/registry.ts @@ -9116,6 +9116,58 @@ export class SchemaRegistry { return stamped; } + /** + * [#32561] The package a stored row `item` of `(type, name)` binds to, read + * by the one rule every overlay-slot reader asks ({@link overlaySlotBinding}, + * {@link pairRowBinding} for a customization pair's row), over the holders + * the exact read serves: a package id, `null` for the environment's own + * item, or `undefined` for no package. The exact read (`pairRowOnAddress`, + * `@objectstack/metadata-protocol`) adopts it for an undeclared pair row, so + * `?package=X` never serves a row this binds to no package: one a bundle + * addition that ships the row's member could own too, or one whose count + * would read another shared pair's undeclared row (epic ruling on #32561, + * red line 2). Read-only. + * + * A disabled package holds no name (ADR-0150 D3, as + * {@link packageScopedHoldersOf} counts by default), so it is left out of + * this count, as the exact read leaves it out of its own: with one of two + * holders disabled, the enabled one's address keeps the row (#32183, epic + * ruling R4-A). It is left out in the order {@link packageScopedHoldersOf} + * uses: the pair's owners are the served holders it customizes, but the + * bundle-addition rule ({@link ownersHoldingAName}) is settled over EVERY + * holder, so a disable never promotes a dependent's addition to an owner + * (a package that adds only to a disabled holder's bundle stays an + * addition, as the exact read counts it). The holders are the ones + * {@link packageScopedHoldersOf} counts: every composite slot, then the + * package a bare-slot entry binds to, so a package holding the name only + * through its own stored row is a holder here too. {@link overlaySlotBinding} + * itself counts every holder, so a disable never moves the binding the + * registry's own readers answer. + */ + overlayRowBinding(type: string, name: string, item: unknown): string | null | undefined { + const collection = this.metadata.get(type); + if (!collection) return undefined; + const composite = new Set(this.compositeHoldersOf(collection, name)); + const servedComposite = new Set([...composite].filter((id) => !this.isPackageDisabled(id))); + const stamped = (item as { _packageId?: unknown } | null | undefined)?._packageId; + if (typeof stamped === 'string' && stamped !== '' && stamped !== 'sys_metadata' && !composite.has(stamped)) { + const holders = new Set(composite); + for (const { item: entry } of this.bareSlotEntriesOf(type, collection, name)) { + const bound = this.overlaySlotBinding(type, entry, name, collection, composite); + if (typeof bound === 'string') holders.add(bound); + } + // The pair's own rows bind to it when no composite slot pairs it; it holds no name of its own here. + const served = new Set([...holders].filter((id) => id !== stamped && !this.isPackageDisabled(id))); + const settled = this.settledPairRowBinding(stamped, item, served); + if (Array.isArray(settled)) { + const named = this.ownersHoldingAName(type, name, collection, settled as readonly string[], item, composite, stamped); + return named.length === 1 ? named[0] : undefined; + } + if (settled !== NOT_A_PAIR_ROW_OF_A_HOLDER) return settled as string | undefined; + } + return this.overlaySlotBinding(type, item, name, collection, servedComposite); + } + /** * [ADR-0150 D4, epic ruling 6761802819 on #31699 F2, #32408] The holder a * customization pair's row `item` (stored under `pairId`, which holds no @@ -9148,14 +9200,17 @@ export class SchemaRegistry { * it naming both). A row that declares an addition's package as its base is * still that package's. When the count would read an undeclared row of * another shared pair (a binding that waits on that pair's own count), the - * row binds to no package (epic seat 1's ruling; #32561 carries the shapes - * where the exact read answers otherwise). + * row binds to no package (epic seat 1's ruling). The exact read adopts + * this binding ({@link overlayRowBinding}, #32561), so it never serves such + * a row on a package's address. * * Every holder is counted, a disabled one included (`composite` is the * holder set before {@link packageScopedHoldersOf} filters the served * ones): a binding never moves with a reversible disable (ADR-0150 D3, * #32183). The exact read counts the served holders, so with one of two - * owners disabled it serves a row this binds to no package (#32561). + * owners disabled it serves a row this binds to no package: it adopts this + * binding over the served holders only ({@link overlayRowBinding}, #32561), + * as the enabled holder's address keeps the row (epic ruling R4-A). * * {@link NOT_A_PAIR_ROW_OF_A_HOLDER} when no holder of the name is a package * `pairId` customizes: the row keeps the per-package reading of @@ -9205,11 +9260,11 @@ export class SchemaRegistry { * declaring the holder, an App's own pair row (#28390 ruling A), a * per-package pair's row, the holder's own stored row. The undeclared rows * of `pairId`, the pair this arm decides, are left out, since the members - * they add are what it answers (the accepted residual, #32561). An + * they add are what it answers (the exact read adopts the answer, #32561). An * undeclared row of ANOTHER shared pair would make this count wait on that * pair's, which may wait on this one: then `owners` is answered whole, so - * the row binds to no package (never a guess; epic seat 1's ruling, the - * shapes where the exact read answers otherwise carried by #32561). An + * the row binds to no package (never a guess; epic seat 1's ruling, which + * the exact read adopts, #32561). An * addition that ships the member `row` is ITS member too, so it stays an * owner: the row may customize that package's member, and two owners bind * it to no package. `owners` unchanged for a type that is no bundle, or with diff --git a/packages/spec/src/migrations/entries/semantic/18.pair-row-exact-read-no-owner.ts b/packages/spec/src/migrations/entries/semantic/18.pair-row-exact-read-no-owner.ts new file mode 100644 index 00000000000..396058d732f --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.pair-row-exact-read-no-owner.ts @@ -0,0 +1,40 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// A narrowing of two exact reads, not of any key: ADR-0150 D4 (#32561) has +// the exact read (`?package=`) adopt the registry's binding of an undeclared +// row of an App's customization pair, so a row the registry binds to no +// package (it may customize either of two packages' members, red line 2) is +// no member of either package's address. No key is added, removed or +// re-shaped and no stored row changes shape, so no tombstone and no D2 +// conversion: whose member a row customizes is the author's judgement. No +// relevance question: the move turns on what installed packages and stored +// pair rows hold, which no question over one stack can name. +export const entry: SemanticMigration = { + id: 'pair-row-exact-read-no-owner', + surface: + 'The exact read of an email template member (GET /api/v1/meta/email_template/NAME?package=X&member=LOCALE, and ' + + 'the lists scoped to X) stored as a row of the App\'s customization pair (APP.custom) that declares no base ' + + '(no overrides.package), when another package of the App ships that locale as a bundle addition to X\'s ' + + 'template, or another App\'s shared pair stores an undeclared row of the same name', + replacement: + 'Save the row declaring the package whose shipped locale it customizes: overrides.package naming the package ' + + 'of the App that ships that locale (the save door already prescribes this for a new row of a locale an ' + + 'installed package ships); ?package=THAT_PACKAGE then serves the row. A row of a locale no package ships ' + + 'stays readable at ?package=APP.custom.', + reason: + 'The exact read used to count the holders after the registry had bound the row, so a bundle addition was no ' + + 'holder there and another App\'s pair was never read: ?package=X served an undeclared pair row of locale L ' + + 'although a package of the App ships L as an addition, so the row may as well customize that package\'s L. ' + + 'The registry binds such a row to no package (never a guess), and the exact read now adopts that binding, ' + + 'counted over the holders it serves: X\'s address answers X\'s own L (none), the addition\'s address its own ' + + 'L, and the pair\'s address the row. There is no mechanical rewrite: which package\'s locale a pair row ' + + 'customizes is a judgement about that row.', + acceptanceCriteria: + 'For every row of an App\'s pair that declares no base (read them with ' + + 'GET /api/v1/meta/email_template/NAME?package=APP.custom) whose locale a package of the App ships as an ' + + 'addition: after saving it with overrides.package naming that package, ' + + 'GET /api/v1/meta/email_template/NAME?package=THAT_PACKAGE&member=LOCALE answers the row, and ' + + 'GET /api/v1/meta/email_template/NAME?package=X&member=LOCALE answers X\'s own locale or 404, never the row.', +};