diff --git a/.changeset/33210-packageless-row-two-holders.md b/.changeset/33210-packageless-row-two-holders.md new file mode 100644 index 00000000000..806b520d43b --- /dev/null +++ b/.changeset/33210-packageless-row-two-holders.md @@ -0,0 +1,23 @@ +--- +'@objectstack/metadata-protocol': patch +'@objectstack/spec': patch +--- + +fix(metadata-protocol)!: the bare item read refuses a package-less row beside two packages' rows, and reads a row-held base at its dependent's added member (ADR-0150 D3, red line 2) + +Clause-②: no (narrowing) +Metadata-protocol: none +Skills-docs: none — `skills/objectstack-platform/SKILL.md` (the ADR-0146 paragraph) and `content/docs/concepts/metadata-lifecycle.mdx` teach that a locale a dependent adds under a base's name is served only under its own `?package=`, and that the read naming no package answers `404` for it. Both sentences were true only for a base that ships the name, and are now true for a row-held base too, at a dependent's named locale other than the canonical one, however many dependents each add one. Nothing in `skills/**` or `content/docs/**` teaches what the read naming no package answers for a package-less row beside two packages' rows. No taught sentence moves. + + + +**BREAKING**: two answers of the `/meta` item read that names no package move from served to refused. Name the package (`?package=`) to read the row, as before. + +**Every moved answer, before → after.** Both transports (`RestServer` and the runtime `HttpDispatcher`), every save order, both registration orders, and on the runtime dispatcher before and after a reboot. First-party count 0: no first-party app stores either shape. + +- **A package-less row beside two packages' rows of a name no package ships** (packages E and F each store a row of `dash`, and a package-less row of `dash` is stored too). The plain read `GET /meta/dashboard/dash`, `GET /meta/dashboard/dash/published` and the execution read move FROM the row stored first (E's, F's or the package-less one) TO `409 RESOURCE_CONFLICT` naming E and F in `details.candidates`. `GET /meta/dashboard/dash/layers` already refused it, and still does with the package-less writes' sentence. The package-less row is never served in their place: it is a customization of a name it cannot say whose (red line 2). After a reboot, the registry's environment item of such a name is the bare slot's entry, the row hydrated last. With rows bound to two or more packages beside it, that entry no longer counts as the environment's own item. +- **A member that only a dependent's addition holds, over a base that holds the name only as stored rows** (base A stores `welcome` in `en-US`, dependent D, which declares A, stores `fr-FR`, and no package ships `welcome`). `GET /meta/email_template/welcome?member=fr-FR`, `GET /meta/email_template/welcome/layers?member=fr-FR` and the execution read at `fr-FR` move FROM D's row (200) TO `404 RESOURCE_NOT_FOUND`. That is the answer the same reads already gave when A ships `welcome`: a bundle addition holds no name, so the read takes the base's address, which holds no `fr-FR`. Each dependent is judged against its own declared dependencies, so with a second dependent D2 storing `de-DE` the reads at `fr-FR` and at `de-DE` both answer `404`, in either registration order. A dependent that also stores a member the base stores (D storing `en-US` as well as `fr-FR`) is still an addition, as the registry judges it (a member held only as stored rows is no clash), so its `fr-FR` answers `404` too. + +**Not moved.** One package's row beside a package-less row is that package's, served on every bare door in both save orders, before and after a reboot. Each exact address (`?package=E`, `?package=F`, `?package=D&member=fr-FR`) serves its own row. The base's own member (`?member=en-US`) is the base's; where the dependent stores it too over a row-held base, the read there refuses naming both, as before. The read naming no member (the canonical member, `GET /meta/email_template/welcome` and `/published`) is not moved, even where a dependent stores the canonical member over a row-held base that holds only another one. A name with a disabled holder keeps its own judgment (#32354), and a package-less row beside a disabled holder leaves the read as it was (that shape, with the plain read following save order while `/layers` refuses, is #34440). The canonical member of a shipped base that holds only another member answers differently before and after a restart (#34441); this change does not move it. The writes do not move: in the first shape the save naming no package was already refused `409 RESOURCE_CONFLICT` naming E and F, writing nothing, and still is, so it now agrees with the read. A save that edits a package-unbound row while the read refuses is another shape, two enabled packages that ship the name with no package's row stored (#34348, decision open); this change does not move it either. + +The ADR-0087 entry `row-held-base-addition-bare-read-at-base` registers the second move. The first is the narrowing `two-row-holders-bare-read-refused` already registers: two or more enabled packages hold the name only as stored rows. That entry's `reason` now says how the holders are judged: by the packages the rows are bound to at the member read, with the registry's holders only helping recognise a customization pair. diff --git a/packages/metadata-protocol/src/protocol-meta-item-face.ts b/packages/metadata-protocol/src/protocol-meta-item-face.ts index 27fbaabc3eb..03a8198a1fa 100644 --- a/packages/metadata-protocol/src/protocol-meta-item-face.ts +++ b/packages/metadata-protocol/src/protocol-meta-item-face.ts @@ -43,11 +43,11 @@ import type { ObjectStackProtocolImplementation } from './protocol.js'; import { shippingPackageIds } from './protocol-environment-rows.js'; import { bundleMemberDiscriminator, resolveBundleMemberSelector } from './protocol-bundle-members.js'; import { installedManifestsOfEngine } from './installed-manifests.js'; -import { pairsOf } from '@objectstack/metadata-core'; +import { packageDependencyClosure, pairsOf, type PackageClosureRegistry } from '@objectstack/metadata-core'; import { disabledExactAddressHolder } from './protocol-exact-qualifier.js'; import type { PrereadActiveRows } from './protocol-meta-item-reads.js'; import { PLURAL_TO_SINGULAR } from '@objectstack/spec/shared'; -import { overlayMemberWhere } from './migrations/overlay-index.js'; +import { overlayMemberValue, overlayMemberWhere } from './migrations/overlay-index.js'; import { isServedOverrideRowOf } from './served-override.js'; import { isActionWithheldByDisabledPackage, @@ -274,7 +274,12 @@ const SERVED_HOLDER_JUDGED_ELSEWHERE: ReadonlySet = new Set(['object', ' * it: {@link servedHolderAddressOf} and `packagelessContentPackage` judge * it), and when no package-less row and no * environment item is stored (a customization of no one holder, judged as - * before). Then the holders are the registry's served holders and the + * before). [#33210] On the item face (`options.refuseWithoutDisabled`) a + * package-less row, or the registry's environment item, beside rows bound to + * two or more packages with no disabled package among them is judged with + * those rows instead ({@link storedRowHoldersRefusal}), so it is refused + * naming them; beside one holder, none, or a disabled holder the read is left + * as it was. Then the holders are the registry's served holders and the * packages the active rows are bound to, less every disabled package: * * - one → `{ kind: 'served' }`, read at its address, as the registry's @@ -332,9 +337,9 @@ export async function servedRowHolderOf( return undefined; } if ([...shippingPackageIds(host.shippedArtifactsOf(type, name, undefined, member))].some((id) => !disabled(id))) return undefined; - if (typeof registry.getEnvironmentScopedItem === 'function' && registry.getEnvironmentScopedItem(type, name, member) !== undefined) { - return undefined; - } + const environmentItem = typeof registry.getEnvironmentScopedItem === 'function' + && registry.getEnvironmentScopedItem(type, name, member) !== undefined; + if (environmentItem && options.refuseWithoutDisabled !== true) return undefined; // The item's active rows, read once: every row binds a holder, and only // the rows the reads serve make a served one (S4). An unprovisioned store // holds no row. @@ -346,10 +351,21 @@ export async function servedRowHolderOf( activeRows = []; } const rows = await host.packagelessAddress(type, name, member, 'active', activeRows); - if (rows.unbound) return undefined; + // [#33210, ADR-0150 D3] The registry's environment item of a name no + // package ships is the bare slot's entry, the row hydrated last: after a + // reboot that is the package-less row whenever it was saved last. Beside + // rows bound to two or more packages it is no environment item but a + // customization of a name it cannot say whose, judged with them below, so + // the answer follows no save order. Otherwise the environment's own item + // leaves the read as it was. + if (environmentItem && !(rows.unbound && rows.candidates.length > 1)) return undefined; const every: readonly string[] = registry.packageScopedHoldersOf(type, name, null, { includeDisabledPackages: true }) ?? []; const anyDisabled = [...every, ...rows.candidates].some(disabled); + // [#33210] The no-disabled arm judges a package-less row itself + // ({@link storedRowHoldersRefusal}); beside a disabled holder it leaves + // the read as it was. if (!anyDisabled) return options.refuseWithoutDisabled === true ? storedRowHoldersRefusal(host, type, name, member, every, activeRows, rows.candidates) : undefined; + if (rows.unbound) return undefined; const installed = installedManifestsOfEngine(host.engine); const pairRow = (row: { package_id?: unknown }): boolean => typeof row.package_id === 'string' && every.some((holder) => pairsOf(holder, installed).includes(row.package_id as string)); @@ -406,7 +422,13 @@ const STORED_ROW_HOLDERS_REFUSAL: unique symbol = Symbol.for('objectstack.metada * ({@link ObjectStackProtocolImplementation.declinesStoredRow}) and a row of a * customization pair of another package the rows or the registry name * (`pairsOf`), which is that package's customization, never a holder of its - * own. An unbound package-less row among them leaves the read as it was. + * own. + * + * [#33210, ADR-0150 red line 2] A package-less row among them is no holder + * and no tie-break: beside two or more holders the read is refused naming + * them, as `/layers` refuses the same rows (`packagelessLayeredReadRefusal`), + * where it served a row by store order; beside one holder or none it leaves + * the read as it was. */ async function storedRowHoldersRefusal( host: ServedRowHost, @@ -423,7 +445,13 @@ async function storedRowHoldersRefusal( && known.some((holder) => holder !== row.package_id && pairsOf(holder, installed).includes(row.package_id as string)); const holding = await host.packagelessAddress(type, name, member, 'active', activeRows.filter((row) => !host.declinesStoredRow(type, name, row) && !pairOfAnother(row))); - if (holding.unbound) return undefined; + // [#33210, ADR-0150 red line 2] A package-less row beside two or more + // holders is a customization of a name it cannot say whose (the + // registry binds it to no package): reading past it still leaves those + // holders, so it is refused naming them below, as `/layers` refuses it, + // and never served in their place. Beside one holder or none it leaves + // the read as it was. + if (holding.unbound && holding.candidates.length < 2) return undefined; // [#32662 scope note (b), ADR-0150 D3] One holder whose rows are its own // and its customization pair's: the read is that holder's, at its address, // as `/published` reads it, so the layer served is its own row in both @@ -572,6 +600,111 @@ export async function declaredMemberOverrideAddressOf( : undefined; } +/** + * [#33210 (c), ADR-0150 D3, #28802 R2] The address a read naming no package + * takes for a bundle member that only a dependent's ADDITION holds, over a + * base that holds the name only as stored rows: that base. The read then + * answers the base's member, which it does not hold (404), as it does when the + * base ships the name, where `packagelessContentPackage` reads the shipper. + * `undefined` leaves the read as it was. + * + * Measured on `main` 66f6638fa4, on a booted kernel, before and after a + * reboot. Base A holds `welcome` in `en-US`, and dependent D, which declares + * A, holds `fr-FR`. When A ships `en-US`, the plain read, `/layers` and the + * execution face at `fr-FR` answered 404. When A holds `en-US` only as a + * stored row, all three served D's row. In both, the registry named A the + * name's one holder (a bundle addition holds no name). The two differed only + * in the grain the base was read at: the shippers at the name, the rows' + * bindings at the member. + * + * Judged at the rows' grain, as the registry judges an addition + * (`isBundleAddition`, read by `packageScopedHoldersOf`). Every active row at + * the member is bound to a package, and none is declined + * ({@link ObjectStackProtocolImplementation.declinesStoredRow}). Each package + * holding members of the name as active rows is judged against its OWN + * declared dependency closure: it is an addition when some other row-holding + * package B is in that closure and it is not in B's. [#33210 contract review + * S2] A member both hold is no clash here: the registry counts a clash only + * at a member either package ships in code (`codeMembersOf`, #33127), and + * this arm runs only for a name no package ships, so a member two packages + * hold only as stored rows never clashes. A dependent that also stores a + * member the base stores (D's `en-US` and `fr-FR` over A's `en-US`) stays an + * addition, as the registry names A the one holder there; the read at the + * shared member is left to the rows' own judgment (A holds a row there). The + * base is the one row-holding package that is no addition; + * the read is moved only when there is exactly one, it holds no row at the + * member, and no package at the member is a customization pair of another + * row-holding package (`pairsOf`: a pair's added member is served on its + * base's address already, #28802 ruling A). So a second dependent adding a + * member of its own (D1 `fr-FR`, D2 `de-DE` over A's `en-US`) leaves A the + * base at each dependent's member, as the registry names A the one holder + * whichever packages are installed, and a dependent of a dependent is an + * addition to it. The arm applies only to a bundled type the registry reads + * by package, for a name no package ships (a shipped name is the shipper's + * already), at a named member other than the canonical one, with no + * environment item at the member and no disabled package among the + * row-holding packages (the served-holder judgment above reads those). + */ +export async function rowHeldBaseAddressOf( + host: ServedRowHost, + type: string, name: string, member: string | undefined, +): Promise { + const registry: any = host.engine?.registry; + if (typeof registry?.readsByPackage !== 'function' || registry.readsByPackage(type) !== true) return undefined; + const singular = PLURAL_TO_SINGULAR[type] ?? type; + // [#33210 contract review S1] A NAMED non-canonical member only. + // `overlayMemberValue` answers null for the canonical member, named or + // not, and the read naming no member addresses it (reachable without + // `?member=` and from `/published`). That mirror is left as it was: with + // a shipped base holding only another member, its answers move across a + // reboot and the read naming no member serves the base's other member, + // so there is no one shipped answer to align it with. + if (typeof overlayMemberValue(singular, member) !== 'string') return undefined; + if (shippingPackageIds(host.shippedArtifactsOf(type, name)).size > 0) return undefined; + if (typeof registry.getEnvironmentScopedItem === 'function' && registry.getEnvironmentScopedItem(type, name, member) !== undefined) { + return undefined; + } + let activeRows: Awaited>; + try { + activeRows = await host.readItemActiveRows(type, name); + } catch (error) { + host.rethrowUnlessMetadataStoreUnprovisioned(error, 'sys_metadata'); + activeRows = []; + } + const rows = activeRows.filter((row) => rowMatchesOverlayWhere(row, { type: singular, name, state: 'active' })); + const memberWhere = { type: singular, name, state: 'active', ...overlayMemberWhere(singular, member) }; + const atMember = rows.filter((row) => rowMatchesOverlayWhere(row, memberWhere)); + const packageOf = (row: { package_id?: unknown }): string | undefined => + typeof row.package_id === 'string' && row.package_id !== '' ? row.package_id : undefined; + if (atMember.length === 0 || atMember.some((row) => packageOf(row) === undefined || host.declinesStoredRow(type, name, row))) { + return undefined; + } + const holders = [...new Set(rows + .filter((row) => !host.declinesStoredRow(type, name, row)) + .map(packageOf) + .filter((id): id is string => id !== undefined))]; + if (typeof registry.isPackageDisabled === 'function' && holders.some((id) => registry.isPackageDisabled(id) === true)) { + return undefined; + } + const closure = (id: string): readonly string[] => packageDependencyClosure(id, registry as PackageClosureRegistry)?.dependencies ?? []; + // [#33210 contract review M1] Each package against its own closure, as + // `isBundleAddition` judges it: an addition to ANY other holder it + // declares, never to one base every package must share. [S2] No member + // clashes: no package ships the name here, and the registry's clash is + // a member shipped in code (`codeMembersOf`), never one held only as + // stored rows. + const isAdditionTo = (id: string, other: string): boolean => other !== id + && closure(id).includes(other) && !closure(other).includes(id); + const bases = holders.filter((id) => !holders.some((other) => isAdditionTo(id, other))); + if (bases.length !== 1) return undefined; + const [base] = bases; + const additions = new Set(atMember.map((row) => packageOf(row)!)); + if (additions.has(base)) return undefined; + const installed = installedManifestsOfEngine(host.engine); + const isPairOfAHolder = (id: string): boolean => holders.some((other) => other !== id && pairsOf(other, installed).includes(id)); + return [...additions].some(isPairOfAHolder) ? undefined : base; +} + /** The body of `ObjectStackProtocolImplementation#readMetaItemFace`; the method's docblock there is its contract. */ export async function readMetaItemFace( this: Pick & ServedRowHost, @@ -612,10 +745,16 @@ export async function readMetaItemFace( // [#32849] …and a member whose one shipper's declared override is stored // is read at that shipper ({@link declaredMemberOverrideAddressOf}). const member = request.packageId ? undefined : resolveBundleMemberSelector(request.type, request.member); + // [#33210 (c)] …and a member only a dependent's addition holds, over a + // base holding the name only as stored rows, is read at that base + // ({@link rowHeldBaseAddressOf}), as it is when the base ships the name. const servedAddress = request.packageId ? undefined : await servedAddressOf(judgeHost, request.type, request.name, member, { refuseWithoutDisabled: true }) - ?? (request.state === 'draft' ? undefined : await declaredMemberOverrideAddressOf(judgeHost, request.type, request.name, member)); + ?? (request.state === 'draft' + ? undefined + : await declaredMemberOverrideAddressOf(judgeHost, request.type, request.name, member) + ?? await rowHeldBaseAddressOf(judgeHost, request.type, request.name, member)); const answer = await this.readMetaItem(servedAddress === undefined ? request : { ...request, packageId: servedAddress }, { face, ...(activeRows !== undefined ? { activeRows } : {}) }); // [#28877] The served read of an `action` also withholds one that launches // into a disabled package, as the served list does. diff --git a/packages/metadata-protocol/src/protocol-meta-layered-reads.ts b/packages/metadata-protocol/src/protocol-meta-layered-reads.ts index 70eb6082836..f69964ba224 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 { declaredMemberOverrideAddressOf, isAnotherHoldersCopy, servedAddressJudgment } from './protocol-meta-item-face.js'; +import { declaredMemberOverrideAddressOf, isAnotherHoldersCopy, rowHeldBaseAddressOf, 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. */ @@ -223,9 +223,12 @@ export async function getMetaItemLayered(host: Pick { }, 60_000); }); +/** + * [#33210, ADR-0150 D3 red line 2] A package-less row beside two enabled + * packages' rows of a name no package ships: three rows and no one holder. + * The read naming no package refuses 409 naming both packages, as `/layers` + * does, in every save order, and never serves the package-less row in their + * place; `/published` and the execution face take the plain read's refusal, + * and each exact address serves its own row. CONTROL: one package's row + * beside a package-less row has one holder and is served on every bare door + * as before. + * + * FROM (`main` 5a755791a9, measured before the fix): the plain read, + * `/published` and the execution face served a row by store order (the + * package-less row's arm of the judgment left the read as it was), while + * `/layers` refused 409 naming both. + */ +describe('[#33210] RestServer: a package-less row beside two enabled row holders and no shipper', () => { + const THIRD_PKG = 'app.third_demo'; + const label = (pkg: string | null) => (pkg === OTHER_PKG ? 'healthy row' : pkg === THIRD_PKG ? 'third row' : 'package-less row'); + const lay = (host: ReturnType, name: string, pkg: string | null) => (host.protocol as any).engine.insert('sys_metadata', { + type: 'dashboard', name, package_id: pkg, state: 'active', scope: 'platform', strategy: 'merge', version: 1, + metadata: JSON.stringify({ name, label: label(pkg), widgets: [] }), + }); + const WRITES_SENTENCE = 'Name the package this layered read is for'; + const messageOf = (body: any): string => String(body?.error?.message ?? body?.message ?? body?.error ?? ''); + const install = (host: ReturnType) => { + for (const pkg of [OTHER_PKG, THIRD_PKG]) host.registry.installPackage({ id: pkg, name: pkg, version: '1.0.0' } as any, 'code'); + }; + const tagOf = (pkg: string | null) => pkg ?? 'package-less'; + const SAVE_ORDERS: ReadonlyArray = [ + [null, OTHER_PKG, THIRD_PKG], [null, THIRD_PKG, OTHER_PKG], + [OTHER_PKG, null, THIRD_PKG], [THIRD_PKG, null, OTHER_PKG], + [OTHER_PKG, THIRD_PKG, null], [THIRD_PKG, OTHER_PKG, null], + ]; + + it.each(SAVE_ORDERS.map((saved) => [saved.map(tagOf).join(' then '), saved] as const))( + 'saved %s: the plain read, /layers, /published and the execution face refuse naming both packages', + async (_order, saved) => { + const host = setup(); + install(host); + for (const pkg of saved) await lay(host, 'three_rows_dash', pkg); + const read = await host.plain('dashboard', 'three_rows_dash'); + expect([read.status, read.body?.code], JSON.stringify(read.body)).toEqual([409, 'RESOURCE_CONFLICT']); + expect([...(read.body?.details?.candidates ?? [])].map((c: any) => c.packageId).sort(), JSON.stringify(read.body)) + .toEqual([OTHER_PKG, THIRD_PKG].sort()); + const layers = await host.layers('dashboard', 'three_rows_dash'); + const published = await host.published('dashboard', 'three_rows_dash'); + // [#33210 L1-b R3] Each door's refusal is pinned by its status AND + // its code (ADR-0112), as the runtime helper pins them. + for (const [door, answer] of [['plain', read], ['layers', layers], ['published', published]] as const) { + expect([door, answer.status, answer.body?.code ?? answer.body?.error?.code], JSON.stringify(answer.body)) + .toEqual([door, 409, 'RESOURCE_CONFLICT']); + for (const pkg of [OTHER_PKG, THIRD_PKG]) expect(JSON.stringify(answer.body)).toContain(pkg); + expect(JSON.stringify(answer.body)).not.toMatch(/(healthy|third|package-less) row/); + } + // `/layers` answers the package-less writes' own refusal (#28337), as on `main`. + expect(messageOf(layers.body).startsWith(WRITES_SENTENCE), JSON.stringify(layers.body)).toBe(true); + await expect(host.protocol.getMetaItemForExecution({ type: 'dashboard', name: 'three_rows_dash' })) + .rejects.toMatchObject({ code: 'RESOURCE_CONFLICT', httpStatus: 409 }); + for (const pkg of [OTHER_PKG, THIRD_PKG]) { + const exact = await host.plainWith('dashboard', 'three_rows_dash', { package: pkg }); + expect([exact.status, exact.body?.item?.label], JSON.stringify(exact.body)).toEqual([200, label(pkg)]); + } + }, 60_000); + + it.each([ + ['the package-less row saved first', [null, OTHER_PKG]], + ['the package\'s row saved first', [OTHER_PKG, null]], + ] as const)('CONTROL, %s: one package\'s row beside a package-less row is served on every bare door as before', async (_order, saved) => { + const host = setup(); + install(host); + for (const pkg of saved) await lay(host, 'one_holder_dash', pkg); + const read = await host.plain('dashboard', 'one_holder_dash'); + expect([read.status, read.body?.item?.label, read.body?.packageId], JSON.stringify(read.body)).toEqual([200, 'healthy row', OTHER_PKG]); + const layers = await host.layers('dashboard', 'one_holder_dash'); + expect([layers.status, layers.body?.effective?.label], JSON.stringify(layers.body)).toEqual([200, 'healthy row']); + const published = await host.published('dashboard', 'one_holder_dash'); + expect([published.status, published.body?.label], JSON.stringify(published.body)).toEqual([200, 'healthy row']); + const executed: any = await host.protocol.getMetaItemForExecution({ type: 'dashboard', name: 'one_holder_dash' }); + expect(executed?.item?.label).toBe('healthy row'); + }, 60_000); +}); + /** * [ruling record 6787890900] An object the caller may not read is answered on * every object door exactly as a name with nothing behind it — decided BEFORE diff --git a/packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts b/packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts index 73e665628b8..a86b89cae7d 100644 --- a/packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts +++ b/packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts @@ -439,6 +439,73 @@ describe.each([ await down(booted); } }, 120_000); + + // [#33210, ADR-0150 D3 red line 2] A package-less row beside the two + // packages' rows: three rows and no one holder. The bare doors refuse + // naming both packages in every save order, before and after a reboot, + // and never serve the package-less row in their place. FROM (`main` + // 5a755791a9): the plain read, `/published` and the execution face served + // a row by store order, while `/layers` refused naming both. + it.each([ + { saveOrder: 'package-less, E, F', saved: [null, ROW_E, ROW_F] }, + { saveOrder: 'F, package-less, E', saved: [ROW_F, null, ROW_E] }, + { saveOrder: 'E, F, package-less', saved: [ROW_E, ROW_F, null] }, + ])('[#33210] saved $saveOrder: a package-less row beside them leaves every bare door refusing naming both, before and after a reboot', async ({ saved }) => { + const file = freshFile(); + const expectRefused = async (b: Booted) => { + await expectRefusedNamingBoth(b, 'three_rows_dash'); + for (const door of ['', '/layers', '/published']) { + const answer = await get(b.kernel, `/meta/dashboard/three_rows_dash${door}`); + expect(JSON.stringify(answer.body ?? null), door).not.toContain('package-less row'); + } + }; + let booted = await bootRowKernel(registered, file); + try { + for (const id of saved) await layStoredRow(booted.engine, 'three_rows_dash', id, id === null ? 'package-less row' : `${rowTag(id)} row`); + await expectRefused(booted); + } finally { + await down(booted); + } + booted = await bootRowKernel(registered, file); + try { + await expectRefused(booted); + } finally { + await down(booted); + } + }, 240_000); + + // [#33210] CONTROL: one package's row beside a package-less row has one + // holder, and every bare door serves that package's row in both save + // orders, before and after a reboot, as on `main`. + it.each([ + { saveOrder: 'package-less row first', saved: [null, ROW_E] }, + { saveOrder: 'E\'s row first', saved: [ROW_E, null] }, + ])('[#33210] CONTROL, $saveOrder: one row holder beside a package-less row is served on every bare door as before, before and after a reboot', async ({ saved }) => { + const file = freshFile(); + const expectServed = async (b: Booted) => { + const read = await get(b.kernel, '/meta/dashboard/one_holder_dash'); + expect([read.status, unwrap(read.body)?.item?.label, unwrap(read.body)?.packageId], JSON.stringify(read.body)).toEqual([200, 'enabled row', ROW_E]); + const layers = await get(b.kernel, '/meta/dashboard/one_holder_dash/layers'); + expect([layers.status, unwrap(layers.body)?.effective?.label], JSON.stringify(layers.body)).toEqual([200, 'enabled row']); + const published = await get(b.kernel, '/meta/dashboard/one_holder_dash/published'); + expect([published.status, unwrap(published.body)?.label], JSON.stringify(published.body)).toEqual([200, 'enabled row']); + const executed = await (b.kernel.getService('protocol') as any).getMetaItemForExecution({ type: 'dashboard', name: 'one_holder_dash' }); + expect(executed?.item?.label).toBe('enabled row'); + }; + let booted = await bootRowKernel(registered, file); + try { + for (const id of saved) await layStoredRow(booted.engine, 'one_holder_dash', id, id === null ? 'package-less row' : 'enabled row'); + await expectServed(booted); + } finally { + await down(booted); + } + booted = await bootRowKernel(registered, file); + try { + await expectServed(booted); + } finally { + await down(booted); + } + }, 240_000); }); // --------------------------------------------------------------------------- @@ -447,9 +514,10 @@ describe.each([ // slot. M1: a package's row and its customization pair's undeclared row are // one holder, whichever was saved (and so hydrated) last; the pair is never // named. M2: a dependent's added member over a base that holds the name only -// as a stored row is the dependent's alone at that member (#28802); the -// base's row of another member is no second holder there, and `/layers` does -// not move. Both save orders, before and after a reboot. Measured on this +// as a stored row is no second holder (#28802); the base's row of another +// member is no second holder there either, so nothing is refused. [#33210 (c)] +// The read naming no package reads the base's address there, as for a base +// that ships the name (404). Both save orders, before and after a reboot. Measured on this // branch before the fix (1ab9370442): M1 refused 409 naming the base and its // pair in one save order; M2 refused 409 naming the base and the dependent. // On `main` 89d7bef033 neither refuses, and both answer as below. @@ -542,21 +610,36 @@ describe('[#32607 M1, M2] the no-disabled arm judges holders at the rows\' grain const A = 'com.qa.mailrowbase'; const D = 'com.qa.mailrowaddon'; const template = (locale: string, subject: string) => ({ label: subject, locale, subject, bodyHtml: `

${subject}

` }); + // [#33210 (c), #28802 R2] …and one answer, whether the base holds the + // name as a stored row or ships it: the read naming no package at the + // dependent's added member reads the base's address, which holds no + // `fr-FR` (404), on the plain read, /layers and the execution face; the + // dependent's own address serves its row. FROM (`main` 66f6638fa4): with a + // row-held base all three served the dependent's row (the M2 answer of + // #32607), while with a shipped base all three answered 404. it.each([ - { order: 'A saved first', saved: [A, D] }, - { order: 'D saved first', saved: [D, A] }, - ])('M2, $order: the dependent\'s added `fr-FR` over a row-held base is served as the dependent\'s on the plain read, /layers and the execution face, before and after a reboot', async ({ saved }) => { + { order: 'row-held base, A saved first', ships: false, saved: [A, D] }, + { order: 'row-held base, D saved first', ships: false, saved: [D, A] }, + { order: 'shipped base (CONTROL)', ships: true, saved: [D] }, + ])('M2, $order: the dependent\'s added `fr-FR` answers 404 on the plain read, /layers and the execution face naming no package, and is served at its own address, before and after a reboot', async ({ ships, saved }) => { const file = freshFile(); - const manifests = [appManifest(A), appManifest(D, { dependencies: { [A]: '*' } })]; + const manifests = [ + appManifest(A, ships ? { emailTemplates: [{ name: 'rowmail', ...template('en-US', 'base en') }] } : {}), + appManifest(D, { dependencies: { [A]: '*' } }), + ]; let booted = await bootManifests(manifests, file); const observe = async (b: Booted) => { const read = await get(b.kernel, '/meta/email_template/rowmail', { member: 'fr-FR' }); - expect([read.status, unwrap(read.body)?.item?.subject, unwrap(read.body)?.packageId], JSON.stringify(read.body)).toEqual([200, 'addon fr', D]); + expect([read.status, codeOf(read.body)], JSON.stringify(read.body)).toEqual([404, 'RESOURCE_NOT_FOUND']); const layers = await get(b.kernel, '/meta/email_template/rowmail/layers', { member: 'fr-FR' }); - expect([layers.status, unwrap(layers.body)?.effective?.subject], JSON.stringify(layers.body)).toEqual([200, 'addon fr']); + expect([layers.status, codeOf(layers.body)], JSON.stringify(layers.body)).toEqual([404, 'RESOURCE_NOT_FOUND']); + for (const answer of [read, layers]) expect(JSON.stringify(answer.body ?? null)).not.toContain('addon fr'); // `/published` takes no member selector (400 VALIDATION_ERROR): it reads the canonical member only. const executed = await (b.kernel.getService('protocol') as any).getMetaItemForExecution({ type: 'email_template', name: 'rowmail', member: 'fr-FR' }); - expect(executed?.item?.subject).toBe('addon fr'); + expect(executed?.item ?? null, JSON.stringify(executed ?? null)).toBeNull(); + // The dependent's own address serves its row. + const own = await get(b.kernel, '/meta/email_template/rowmail', { member: 'fr-FR', package: D }); + expect([own.status, unwrap(own.body)?.item?.subject, unwrap(own.body)?.packageId], JSON.stringify(own.body)).toEqual([200, 'addon fr', D]); // CONTROL: the base's own `en-US` stays the base's. const en = await get(b.kernel, '/meta/email_template/rowmail', { member: 'en-US' }); expect([en.status, unwrap(en.body)?.item?.subject], JSON.stringify(en.body)).toEqual([200, 'base en']); @@ -576,6 +659,170 @@ describe('[#32607 M1, M2] the no-disabled arm judges holders at the rows\' grain await down(booted); } }, 240_000); + + // [#33210 contract review M1] Two dependents, each adding a member of its + // own (D1 `fr-FR`, D2 `de-DE`) over A's `en-US`: each dependent is judged + // against its own closure, so A is the base at both members and each + // answers 404 naming no package, as with a shipped base. FROM (head + // b959edb979, `bases.length === 1`): the read at `fr-FR` found A and D2 + // with no row there and served D1's row (200), and likewise at `de-DE`. + const D1 = 'com.qa.mailrowfr'; + const D2 = 'com.qa.mailrowde'; + const ADDED: Record = { + [D1]: { locale: 'fr-FR', subject: 'addon fr' }, + [D2]: { locale: 'de-DE', subject: 'addon de' }, + }; + it.each([ + { order: 'row-held base, registered and saved A, D1, D2', ships: false, registered: [A, D1, D2] }, + { order: 'row-held base, registered and saved D2, D1, A', ships: false, registered: [D2, D1, A] }, + { order: 'shipped base (CONTROL), registered A, D1, D2', ships: true, registered: [A, D1, D2] }, + { order: 'shipped base (CONTROL), registered D2, D1, A', ships: true, registered: [D2, D1, A] }, + ])('M1 two dependents, $order: each dependent\'s added member answers 404 naming no package and is served at its own address, before and after a reboot', async ({ ships, registered }) => { + const file = freshFile(); + const manifestOf = (id: string) => (id === A + ? appManifest(A, ships ? { emailTemplates: [{ name: 'twomail', ...template('en-US', 'base en') }] } : {}) + : appManifest(id, { dependencies: { [A]: '*' } })); + const manifests = registered.map(manifestOf); + let booted = await bootManifests(manifests, file); + const observe = async (b: Booted, leg: string) => { + for (const id of [D1, D2]) { + const { locale, subject } = ADDED[id]; + const where = `${locale}, ${leg}`; + const read = await get(b.kernel, '/meta/email_template/twomail', { member: locale }); + const layers = await get(b.kernel, '/meta/email_template/twomail/layers', { member: locale }); + const executed = await (b.kernel.getService('protocol') as any).getMetaItemForExecution({ type: 'email_template', name: 'twomail', member: locale }); + expect([where, read.status, codeOf(read.body), layers.status, codeOf(layers.body), executed?.item ?? null], JSON.stringify([read.body, layers.body])) + .toEqual([where, 404, 'RESOURCE_NOT_FOUND', 404, 'RESOURCE_NOT_FOUND', null]); + const own = await get(b.kernel, '/meta/email_template/twomail', { member: locale, package: id }); + expect([where, own.status, unwrap(own.body)?.item?.subject, unwrap(own.body)?.packageId], JSON.stringify(own.body)).toEqual([where, 200, subject, id]); + } + // CONTROL: the base's own `en-US` stays the base's. + const en = await get(b.kernel, '/meta/email_template/twomail', { member: 'en-US' }); + expect([leg, en.status, unwrap(en.body)?.item?.subject], JSON.stringify(en.body)).toEqual([leg, 200, 'base en']); + }; + try { + for (const id of registered) { + if (id === A && ships) continue; + await layRow(booted.engine, 'email_template', 'twomail', id, id === A ? template('en-US', 'base en') : template(ADDED[id].locale, ADDED[id].subject)); + } + await observe(booted, 'before a reboot'); + } finally { + await down(booted); + } + booted = await bootManifests(manifests, file); + try { + await observe(booted, 'after a reboot'); + } finally { + await down(booted); + } + }, 240_000); + + // [#33210 contract review S2] A dependent that also stores a member the + // base stores (D's `en-US` and `fr-FR` over A's `en-US`) is still an + // addition: the registry counts a clash only at a member shipped in code + // (#33127), and no package ships this name. So the read naming no package + // at D's `fr-FR` takes A's address (404), as with a shipped base. FROM + // (head 2b9293e63a, any shared member a clash): two bases, and the read at + // `fr-FR` served D's row (200). + it.each([ + { order: 'row-held base, registered and saved A, D', ships: false, registered: [A, D] }, + { order: 'row-held base, registered and saved D, A', ships: false, registered: [D, A] }, + { order: 'shipped base (CONTROL), registered A, D', ships: true, registered: [A, D] }, + { order: 'shipped base (CONTROL), registered D, A', ships: true, registered: [D, A] }, + ])('S2, $order: a dependent storing the base\'s member as well as its own is an addition, and its own member answers 404 naming no package, before and after a reboot', async ({ ships, registered }) => { + const file = freshFile(); + const manifestOf = (id: string) => (id === A + ? appManifest(A, ships ? { emailTemplates: [{ name: 'sharedmail', ...template('en-US', 'base en') }] } : {}) + : appManifest(D, { dependencies: { [A]: '*' } })); + const manifests = registered.map(manifestOf); + let booted = await bootManifests(manifests, file); + const observe = async (b: Booted, leg: string) => { + const read = await get(b.kernel, '/meta/email_template/sharedmail', { member: 'fr-FR' }); + const layers = await get(b.kernel, '/meta/email_template/sharedmail/layers', { member: 'fr-FR' }); + const executed = await (b.kernel.getService('protocol') as any).getMetaItemForExecution({ type: 'email_template', name: 'sharedmail', member: 'fr-FR' }); + expect([leg, read.status, codeOf(read.body), layers.status, codeOf(layers.body), executed?.item ?? null], JSON.stringify([read.body, layers.body])) + .toEqual([leg, 404, 'RESOURCE_NOT_FOUND', 404, 'RESOURCE_NOT_FOUND', null]); + const own = await get(b.kernel, '/meta/email_template/sharedmail', { member: 'fr-FR', package: D }); + expect([leg, own.status, unwrap(own.body)?.item?.subject, unwrap(own.body)?.packageId], JSON.stringify(own.body)).toEqual([leg, 200, 'addon fr', D]); + // The shared member `en-US`, naming no package, is not moved: the + // arm reads only a named non-canonical member. A shipped base serves + // its own `en-US`; over a row-held base A's and D's rows of it are + // two holders, refused naming both, as without this change. + const shared = await get(b.kernel, '/meta/email_template/sharedmail', { member: 'en-US' }); + if (ships) { + expect([leg, shared.status, unwrap(shared.body)?.item?.subject, unwrap(shared.body)?.packageId], JSON.stringify(shared.body)).toEqual([leg, 200, 'base en', A]); + } else { + expect([leg, shared.status, codeOf(shared.body)], JSON.stringify(shared.body)).toEqual([leg, 409, 'RESOURCE_CONFLICT']); + for (const id of [A, D]) expect(JSON.stringify(shared.body), leg).toContain(id); + } + }; + try { + for (const id of registered) { + if (id === A) { + if (!ships) await layRow(booted.engine, 'email_template', 'sharedmail', A, template('en-US', 'base en')); + continue; + } + await layRow(booted.engine, 'email_template', 'sharedmail', D, template('en-US', 'addon en')); + await layRow(booted.engine, 'email_template', 'sharedmail', D, template('fr-FR', 'addon fr')); + } + await observe(booted, 'before a reboot'); + } finally { + await down(booted); + } + booted = await bootManifests(manifests, file); + try { + await observe(booted, 'after a reboot'); + } finally { + await down(booted); + } + }, 240_000); + + // [#33210 contract review S1] The canonical-member mirror is left as it + // was: a dependent's row of the CANONICAL member (`en-US`) over a base that + // holds the name only as a stored row of another member (`fr-FR`). The + // read naming no member addresses the canonical member, and the arm moves + // only a named non-canonical member, so every door serves the dependent's + // row as on `main`, in both save orders, before and after a reboot. FROM + // (head b959edb979, arm unguarded): the read naming no member, `/published`, + // `/layers` and the execution face answered 404 before a reboot, and the + // plain read and the execution face served A's `fr-FR` after it. No + // shipped CONTROL is pinned: with A shipping only `fr-FR`, the read naming + // no member serves A's `fr-FR`, and `/published` and `/layers` move across + // a reboot (200 then 404), so there is no one shipped answer to align with. + it.each([ + { order: 'A saved first', saved: [A, D] }, + { order: 'D saved first', saved: [D, A] }, + ])('S1, $order: a dependent\'s canonical member over a row-held base of another member is served on every door naming no package, before and after a reboot', async ({ saved }) => { + const file = freshFile(); + const manifests = [appManifest(A), appManifest(D, { dependencies: { [A]: '*' } })]; + let booted = await bootManifests(manifests, file); + const observe = async (b: Booted, leg: string) => { + const read = await get(b.kernel, '/meta/email_template/canmail'); + const named = await get(b.kernel, '/meta/email_template/canmail', { member: 'en-US' }); + const layers = await get(b.kernel, '/meta/email_template/canmail/layers'); + const published = await get(b.kernel, '/meta/email_template/canmail/published'); + const executed = await (b.kernel.getService('protocol') as any).getMetaItemForExecution({ type: 'email_template', name: 'canmail' }); + expect([leg, read.status, unwrap(read.body)?.item?.subject, named.status, unwrap(named.body)?.item?.subject, + layers.status, unwrap(layers.body)?.effective?.subject, published.status, unwrap(published.body)?.subject, executed?.item?.subject], + JSON.stringify([read.body, named.body, layers.body, published.body])) + .toEqual([leg, 200, 'addon en', 200, 'addon en', 200, 'addon en', 200, 'addon en', 'addon en']); + // CONTROL: the base's own `fr-FR` stays the base's. + const fr = await get(b.kernel, '/meta/email_template/canmail', { member: 'fr-FR' }); + expect([leg, fr.status, unwrap(fr.body)?.item?.subject], JSON.stringify(fr.body)).toEqual([leg, 200, 'base fr']); + }; + try { + for (const id of saved) await layRow(booted.engine, 'email_template', 'canmail', id, id === A ? template('fr-FR', 'base fr') : template('en-US', 'addon en')); + await observe(booted, 'before a reboot'); + } finally { + await down(booted); + } + booted = await bootManifests(manifests, file); + try { + await observe(booted, 'after a reboot'); + } finally { + await down(booted); + } + }, 240_000); }); // --------------------------------------------------------------------------- diff --git a/packages/spec/src/migrations/entries/semantic/18.row-held-base-addition-bare-read-at-base.ts b/packages/spec/src/migrations/entries/semantic/18.row-held-base-addition-bare-read-at-base.ts new file mode 100644 index 00000000000..df52c5fe32e --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.row-held-base-addition-bare-read-at-base.ts @@ -0,0 +1,41 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// A narrowing of the bare item read, not of any key: #33210 (c) has the read +// that names no package, at a named non-canonical bundle member only a +// dependent's addition holds, read the base's address when the base holds the +// name only as stored rows, as it already does when the base ships the name. +// The rule is #28802 / epic #31527 child R2 (the `packageScopedHoldersOf` +// docblock in objectql's registry: a bundle addition holds no name), judged +// for each dependent against its own declared dependency closure, so a second +// dependent adding a member of its own leaves the base the base. It served the +// dependent's row there. No key is added, removed or re-shaped and no stored +// row changes shape, so no tombstone and no D2 conversion: the dependent's row +// stays at its own address. No relevance question: the move turns on which +// packages' stored rows hold which members of a name, which no question over +// one stack can name. +export const entry: SemanticMigration = { + id: 'row-held-base-addition-bare-read-at-base', + surface: + 'The read of a bundled metadata item that names no package (GET /api/v1/meta/TYPE/NAME?member=MEMBER, ' + + 'GET /api/v1/meta/TYPE/NAME/layers?member=MEMBER, and the execution read of the same member) at a named ' + + 'member other than the canonical one that only dependent packages\' stored rows hold, each an addition to ' + + 'a base package that holds the name only as stored rows of other members, for a name no installed package ' + + 'ships in code. The read naming no member (the canonical member, and GET /api/v1/meta/TYPE/NAME/published) ' + + 'does not move', + replacement: + 'Name the dependent: GET /api/v1/meta/TYPE/NAME?package=DEPENDENT&member=MEMBER serves its row, as before.', + reason: + 'A bundle addition holds no name (the rule the registry applies when it counts a name\'s holders): the read ' + + 'naming no package reads the base\'s address, and when the base ships the name it already answered 404 for ' + + 'a member only a dependent holds. When the base held the name only as stored rows, the same read served the ' + + 'dependent\'s row, because it read the rows bound at the member rather than the base. The two now answer ' + + 'alike, however many dependents each add a member of their own. There is no mechanical rewrite: whether a ' + + 'caller meant the dependent\'s member is a judgement about that caller.', + acceptanceCriteria: + 'For every bundled name a base holds only as stored rows and one or more dependents each extend with a ' + + 'non-canonical member of their own: every caller that reads such a member without ?package= reads it with ' + + '?package=DEPENDENT, which answers the dependent\'s row; the read without ?package= answers 404 for that ' + + 'member, as for a base that ships the name.', +}; diff --git a/packages/spec/src/migrations/entries/semantic/18.two-row-holders-bare-read-refused.ts b/packages/spec/src/migrations/entries/semantic/18.two-row-holders-bare-read-refused.ts index 716f5d234be..fe55814294f 100644 --- a/packages/spec/src/migrations/entries/semantic/18.two-row-holders-bare-read-refused.ts +++ b/packages/spec/src/migrations/entries/semantic/18.two-row-holders-bare-read-refused.ts @@ -23,8 +23,9 @@ export const entry: SemanticMigration = { reason: 'The read naming no package took the row saved first, so the same name answered a different package\'s item ' + 'depending on save order, while GET /api/v1/meta/TYPE/NAME/layers already refused it naming both holders. ' - + 'The read now judges the name\'s holders (the registry\'s holders and the packages its active stored rows ' - + 'are bound to) and refuses two or more as the by-name read refuses two package holders. One holder is served ' + + 'The read now judges the name\'s holders (the packages its active stored rows are bound to at the member read; ' + + 'the registry\'s holders only help recognise a customization pair) and refuses two or more as the by-name read ' + + 'refuses two package holders. One holder is served ' + 'as before. There is no mechanical rewrite: which package\'s row a caller meant is a judgement about that ' + 'caller.', acceptanceCriteria: