diff --git a/.changeset/34452-same-name-bare-reads.md b/.changeset/34452-same-name-bare-reads.md new file mode 100644 index 00000000000..89d5735f4cc --- /dev/null +++ b/.changeset/34452-same-name-bare-reads.md @@ -0,0 +1,19 @@ +--- +'@objectstack/metadata-protocol': patch +'@objectstack/spec': patch +--- + +fix(metadata-protocol)!: the reads that name no package give one answer per name: the environment's doc entry first, and a disabled holder read as absent + +Clause-②: no (narrowing) +Metadata-protocol: none + + + +**BREAKING** for a caller that reads a shared name without naming a package, shipped as `patch`: no key an author writes changes (`Metadata-protocol: none`). Three reads that named no package answered by registration or save order, or disagreed with the registry's own read of the same name; each now gives one answer. Naming the package (`?package=ID`, or `packageId` in process) reads that package's item exactly as before. + +- **A doc the environment stores beside one enabled package's doc of the same name** (#34452, ruling 6942962369). FROM `GET /api/v1/meta/doc/NAME`, `/layers` and `/published` serving the package's doc while the registry and the metadata facade served the environment's own entry, TO every read that names no package serving the environment's entry, as it already did beside two or more holders. `?package=ID` still reads the package's doc. Known deviation, tracked in #38659: the plain read naming no package serves the entry under a holder's envelope (`_packageId` that holder, `_provenance: package`, lock `full`), as it already did beside two or more holders. +- **The in-process layered read of a doc two or more enabled packages hold, with no environment entry** (#34190). FROM the layered read naming no package serving the layers of the package registered last, TO a `409 RESOURCE_CONFLICT` rejection naming each holder in `refusal.candidates`, as the item read and every HTTP door already answered. +- **A package-less row beside a disabled package's row and enabled packages' rows of a name no enabled package ships** (#34440). FROM the plain read and the execution read following save order, `/published` serving the package-less row, `/layers` refusing with the disabled package among the candidates, and one save order answering 404 (every bare door answered 404 when the disabled package held the name in code alone beside two or more enabled packages' rows), TO the answer the reads give without the disabled holder: two or more enabled holders refused `409 RESOURCE_CONFLICT` naming exactly them in `details.candidates`, one enabled holder served, in every save order and after a restart. `?package=` of the disabled package still answers 404. + +The fix for a caller that relied on the old answer: name the package it means. `os migrate meta --from 18` lists both entries. diff --git a/packages/metadata-protocol/src/protocol-meta-item-face.ts b/packages/metadata-protocol/src/protocol-meta-item-face.ts index 960ea88d718..206d8ae1935 100644 --- a/packages/metadata-protocol/src/protocol-meta-item-face.ts +++ b/packages/metadata-protocol/src/protocol-meta-item-face.ts @@ -273,14 +273,18 @@ const SERVED_HOLDER_JUDGED_ELSEWHERE: ReadonlySet = new Set(['object', ' * package ships no code item of the name (otherwise the shipped item is the * name's, ADR-0048 §3.3, and a row of another package never stands in for * 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). [#33210] On the item face (`options.refuseWithoutDisabled`) a + * it). [#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 + * naming them; beside one holder or none the read is left as it was. + * [#34440] Beside rows bound to two or more packages, with a disabled holder + * of the name (its own stored row among them, or the name in its code alone: + * contract review S4), it is judged below with those rows on every door, as + * the item face judges it with no disabled holder: a package-less row is no + * holder and no tie-break. Beside one bound package or none 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 @@ -306,8 +310,7 @@ const SERVED_HOLDER_JUDGED_ELSEWHERE: ReadonlySet = new Set(['object', ' * package's address, so it makes that package no holder here: counted, it * re-addressed the read to an address that serves nothing, and two of them * were refused naming two such addresses. It still counts toward whether a - * disabled package holds the name, and an unbound one still leaves the read - * as it was. + * disabled package holds the name. * * [#32354 contract review N2, #32408] Nor does a row bound to a holder's * customization pair (`pairsOf`): a pair row is bound over every holder it @@ -340,7 +343,11 @@ export async function servedRowHolderOf( if ([...shippingPackageIds(host.shippedArtifactsOf(type, name, undefined, member))].some((id) => !disabled(id))) return undefined; const environmentItem = typeof registry.getEnvironmentScopedItem === 'function' && registry.getEnvironmentScopedItem(type, name, member) !== undefined; - if (environmentItem && options.refuseWithoutDisabled !== true) return undefined; + // [#34440] Not left as it was here when a package is disabled: the + // environment item may be a package-less row beside rows bound to two or + // more packages, a disabled one among them, which is judged below over + // the served set on every door (the plain read's face, `/layers`'s + // refusal and the save door alike). // 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. @@ -363,10 +370,20 @@ export async function servedRowHolderOf( 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. + // ({@link storedRowHoldersRefusal}). if (!anyDisabled) return options.refuseWithoutDisabled === true ? storedRowHoldersRefusal(host, type, name, member, every, activeRows, rows.candidates) : undefined; - if (rows.unbound) return undefined; + // [#34440 contract review S2] Beside rows bound to one package or none, a + // package-less row leaves the read as it was, as its twin + // {@link storedRowHoldersRefusal} leaves it (`holding.unbound` with fewer + // than two candidates): whether the bare slot holds an environment item + // then moves no answer. + if (rows.unbound && rows.candidates.length < 2) return undefined; + // [#34440, ADR-0150 D3] Beside a disabled holder a package-less row is + // judged over the served set as it is with no disabled holder (#33210): + // two or more served holders are refused naming only them, one is served + // at its address, so every bare door gives the answer it gives when the + // disabled holder is absent. Left as it was, the read followed save + // order (one order answered 404) and `/layers` named the disabled package. 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)); diff --git a/packages/metadata-protocol/src/protocol-meta-item-reads.ts b/packages/metadata-protocol/src/protocol-meta-item-reads.ts index e143df965b1..ac8a8b5c414 100644 --- a/packages/metadata-protocol/src/protocol-meta-item-reads.ts +++ b/packages/metadata-protocol/src/protocol-meta-item-reads.ts @@ -340,13 +340,18 @@ export async function judgeBareActionRead( * slot (a stamp-less registration, or a hydrated or saved row stamped with * the store's sentinel) exempts the name: it is the environment's own item, * which answers first, as the registry and `MetadataFacade.get` serve it. - * That entry is returned when two or more enabled packages hold the name, + * That entry is returned when one or more enabled packages hold the name, * because the layers must then serve it: the MetadataService keeps a doc by - * name alone, so its copy is the holder registered last, and it answered - * first ({@link bareDocServiceCopyDisplacesEntry}). + * name alone, so its copy is a holder's (the one registered last), and it + * answered first ({@link bareDocServiceCopyDisplacesEntry}). * - * @returns the environment's entry beside two or more enabled holders, else - * `undefined` (no such entry, or a name one package or none holds). + * [#34452, ruling 6942962369] Beside ONE enabled holder too: the + * environment's own item answers first whatever number of packages hold the + * name, so the bare doors agree with the registry and `MetadataFacade.get`. + * They served the one holder's doc while those two served the entry. + * + * @returns the environment's entry beside one or more enabled holders, else + * `undefined` (no such entry, or a name no enabled package holds). * @throws {PackageScopedNameRefusedError} two or more enabled package holders. */ export function refuseAmbiguousBareDocRead(host: Pick, name: string, member: string | undefined): unknown { @@ -357,9 +362,9 @@ export function refuseAmbiguousBareDocRead(host: Pick, n if (typeof registry?.resolveItem !== 'function') return undefined; const answer = registry.resolveItem('doc', name, null, member); // The registry's answer naming no package is the exempting entry (or a - // name one package or none holds, which the count below leaves alone). + // name no enabled package holds, which the count below leaves alone). if (answer === undefined || answer === null || storedItemPackageId(answer) !== undefined) return undefined; - return (registry.packageScopedHoldersOf?.('doc', name) ?? []).length >= 2 ? answer : undefined; + return (registry.packageScopedHoldersOf?.('doc', name) ?? []).length >= 1 ? answer : undefined; } /** @@ -1372,8 +1377,8 @@ export async function readMetaItem(host: Pick { + const THIRD_PKG = 'app.third_demo'; + const label = (pkg: string | null) => (pkg === OTHER_PKG ? 'healthy row' : pkg === THIRD_PKG ? 'third row' : pkg === PKG ? 'disabled 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 ORDERS = [['disabled first', [PKG, OTHER_PKG, THIRD_PKG]], ['enabled first', [OTHER_PKG, THIRD_PKG, PKG]]] as const; + const tagOf = (pkg: string | null) => (pkg === null ? 'package-less' : label(pkg).split(' ')[0]); + const candidatesOf = (body: any) => [...(body?.details?.candidates ?? body?.error?.details?.candidates ?? [])].map((c: any) => c.packageId).sort(); + const noTrace = (answers: ReadonlyArray<{ body: unknown }>) => { + for (const answer of answers) { + const text = JSON.stringify(answer.body ?? null); + expect(text).not.toMatch(/(disabled|package-less) row/); + expect(text).not.toContain(PKG); + } + }; + const boot = async (packages: readonly string[], name: string, saved: readonly (string | null)[]) => { + const host = setup(); + for (const pkg of packages) host.registry.installPackage({ id: pkg, name: pkg, version: '1.0.0' } as any, 'code'); + for (const pkg of saved) await lay(host, name, pkg); + host.registry.disablePackage(PKG); + return host; + }; + + const TWO: ReadonlyArray = [ + [OTHER_PKG, THIRD_PKG, PKG, null], [null, PKG, THIRD_PKG, OTHER_PKG], [PKG, null, OTHER_PKG, THIRD_PKG], + ]; + it.each(ORDERS.flatMap(([order, packages]) => TWO.map((saved) => [`${order}, saved ${saved.map(tagOf).join(' then ')}`, packages, saved] as const)))( + '%s: two enabled holders are refused on every bare door naming exactly them', + async (_label, packages, saved) => { + const host = await boot(packages, 'pl_two_dash', saved); + const read = await host.plain('dashboard', 'pl_two_dash'); + const layers = await host.layers('dashboard', 'pl_two_dash'); + const published = await host.published('dashboard', 'pl_two_dash'); + 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(candidatesOf(read.body), JSON.stringify(read.body)).toEqual([OTHER_PKG, THIRD_PKG].sort()); + expect(candidatesOf(layers.body), JSON.stringify(layers.body)).toEqual([OTHER_PKG, THIRD_PKG].sort()); + noTrace([read, layers, published]); + const executed = await host.protocol.getMetaItemForExecution({ type: 'dashboard', name: 'pl_two_dash' }).then( + () => 'served', + (error: any) => [error?.code, error?.httpStatus, [...(error?.refusal?.candidates ?? [])].map((c: any) => c.packageId).sort()], + ); + expect(executed).toEqual(['RESOURCE_CONFLICT', 409, [OTHER_PKG, THIRD_PKG].sort()]); + for (const pkg of [OTHER_PKG, THIRD_PKG]) { + const exact = await host.plainWith('dashboard', 'pl_two_dash', { package: pkg }); + expect([exact.status, exact.body?.item?.label], JSON.stringify(exact.body)).toEqual([200, label(pkg)]); + } + const withheld = await host.plainWith('dashboard', 'pl_two_dash', { package: PKG }); + expect(withheld.status, JSON.stringify(withheld.body)).toBe(404); + }, 60_000); + + const ONE: ReadonlyArray = [ + [OTHER_PKG, PKG, null], [null, OTHER_PKG, PKG], [PKG, null, OTHER_PKG], + ]; + it.each(ORDERS.flatMap(([order, packages]) => ONE.map((saved) => [`${order}, saved ${saved.map(tagOf).join(' then ')}`, packages, saved] as const)))( + '%s: one enabled holder is served on every bare door, and none names the disabled package', + async (_label, packages, saved) => { + const host = await boot(packages, 'pl_one_dash', saved); + const read = await host.plain('dashboard', 'pl_one_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', 'pl_one_dash'); + expect([layers.status, layers.body?.effective?.label], JSON.stringify(layers.body)).toEqual([200, 'healthy row']); + const published = await host.published('dashboard', 'pl_one_dash'); + expect([published.status, published.body?.label], JSON.stringify(published.body)).toEqual([200, 'healthy row']); + noTrace([read, layers, published]); + const executed: any = await host.protocol.getMetaItemForExecution({ type: 'dashboard', name: 'pl_one_dash' }); + expect(executed?.item?.label).toBe('healthy row'); + const withheld = await host.plainWith('dashboard', 'pl_one_dash', { package: PKG }); + expect(withheld.status, JSON.stringify(withheld.body)).toBe(404); + }, 60_000); + + // [#34440 contract review S4] The disabled package may hold the name in + // code alone: beside two enabled packages' rows and a package-less row the + // judgment runs as it does beside its stored row, and every bare door + // refuses naming exactly the two enabled packages, whichever saves first. + it.each(ORDERS.flatMap(([order, packages]) => [[OTHER_PKG, THIRD_PKG, null], [null, THIRD_PKG, OTHER_PKG]].map((saved) => [`${order}, saved ${saved.map(tagOf).join(' then ')}`, packages, saved] as const)))( + '%s: two enabled holders beside a disabled code holder are refused on every bare door naming exactly them', + async (_label, packages, saved) => { + const host = setup(); + for (const pkg of packages) host.registry.installPackage({ id: pkg, name: pkg, version: '1.0.0' } as any, 'code'); + host.registry.registerItem('dashboard', { name: 'pl_s4_dash', label: 'disabled code', widgets: [] } as any, 'name', PKG); + for (const pkg of saved) await lay(host, 'pl_s4_dash', pkg); + host.registry.disablePackage(PKG); + const read = await host.plain('dashboard', 'pl_s4_dash'); + const layers = await host.layers('dashboard', 'pl_s4_dash'); + const published = await host.published('dashboard', 'pl_s4_dash'); + 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(candidatesOf(read.body), JSON.stringify(read.body)).toEqual([OTHER_PKG, THIRD_PKG].sort()); + expect(candidatesOf(layers.body), JSON.stringify(layers.body)).toEqual([OTHER_PKG, THIRD_PKG].sort()); + noTrace([read, layers, published]); + }, 60_000); + + // [#34440 contract review S2] CONTROL: beside rows bound to ONE package (an + // enabled package's row and a package-less row), with the disabled package + // holding the name only as code, the read is left as it was on `main`: + // every bare door answers 404, with or without an environment item in the + // registry's bare slot. The judgment above is the one beside rows bound to + // two or more packages. (With the guard removed these doors served the + // enabled package's row, a move outside the declared surface.) + it.each(ORDERS)('CONTROL %s: one bound package beside a disabled code holder is left as it was, whatever the bare slot holds', async (_order, packages) => { + for (const environmentItem of [false, true]) { + const host = setup(); + for (const pkg of packages) host.registry.installPackage({ id: pkg, name: pkg, version: '1.0.0' } as any, 'code'); + host.registry.registerItem('dashboard', { name: 'pl_s2_dash', label: 'disabled code', widgets: [] } as any, 'name', PKG); + for (const pkg of [OTHER_PKG, null]) await lay(host, 'pl_s2_dash', pkg); + if (environmentItem) host.registry.registerItem('dashboard', { name: 'pl_s2_dash', label: 'package-less row', widgets: [] } as any, 'name'); + host.registry.disablePackage(PKG); + const read = await host.plain('dashboard', 'pl_s2_dash'); + const layers = await host.layers('dashboard', 'pl_s2_dash'); + const published = await host.published('dashboard', 'pl_s2_dash'); + expect([environmentItem, read.status, layers.status, published.status], JSON.stringify([read.body, layers.body, published.body])) + .toEqual([environmentItem, 404, 404, 404]); + } + }, 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/rest/src/meta-item-history-routes.ts b/packages/rest/src/meta-item-history-routes.ts index f2515823b83..f8e689c36d0 100644 --- a/packages/rest/src/meta-item-history-routes.ts +++ b/packages/rest/src/meta-item-history-routes.ts @@ -1529,7 +1529,7 @@ export function registerMetaItemPublishedRoute(this: MetaItemPublishedRouteHost, } // [#34248, ruling 6893582352] …and a bare doc's package copy // where the layered read's code layer is the environment's - // own package-less entry (two enabled holders beside it): + // own package-less entry (one or more enabled holders beside it, #34452): // that entry answers first, never the holder registered last. const codeStamp = (publishedCode as { _packageId?: unknown } | null | undefined)?._packageId; if (canonicalMetaUrlType(type) === 'doc' && publishedCode != null && (typeof codeStamp !== 'string' || codeStamp === '' || codeStamp === 'sys_metadata') diff --git a/packages/runtime/src/domains/meta-disabled-holder-artifact-door.test.ts b/packages/runtime/src/domains/meta-disabled-holder-artifact-door.test.ts index 0dca2b70f3a..256eaae3774 100644 --- a/packages/runtime/src/domains/meta-disabled-holder-artifact-door.test.ts +++ b/packages/runtime/src/domains/meta-disabled-holder-artifact-door.test.ts @@ -27,7 +27,7 @@ import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { ObjectKernel } from '@objectstack/core'; import { MetadataPlugin, type MetadataManager } from '@objectstack/metadata'; -import { ObjectQL, ObjectQLPlugin } from '@objectstack/objectql'; +import { MetadataFacade, ObjectQL, ObjectQLPlugin } from '@objectstack/objectql'; import { SqlDriver } from '@objectstack/driver-sql'; import { RestServer } from '@objectstack/rest'; import { resolveThrownHttpError } from '@objectstack/types'; @@ -325,27 +325,87 @@ describe.each([ } }); - // [review S1] Measured, unresolved: the environment's entry answers first - // only beside two or more enabled holders (#34248's acceptance). Beside - // one holder, the registry (and so `MetadataFacade.get`) answers a - // stamp-less bare entry while the bare doors keep the holder's doc, as on - // main. Declared in the changeset; a second holder flips the doors to the - // entry (the #34248 pins below). - it.runIf(ships.length === 1)('[measured, unresolved] one holder beside a stamp-less bare entry: the bare doors serve the holder\'s doc on both transports while the registry answers the entry', async () => { - const label = `${ships[0]!.split('.').pop()} doc`; + // [#34452, ruling 6942962369] The environment's own item answers first + // beside ONE enabled holder too, as beside two (#34248): the bare doors + // serve a package-less entry in the registry's bare slot, agreeing with + // the registry and `MetadataFacade.get`, never the holder's doc; the + // holder's own address still reads its doc. FROM (origin/main 7213177e, + // measured on this rig, both orders): every bare door, both transports, + // served the holder's doc while the registry and the facade answered the + // entry (pinned here as `[measured, unresolved]` by #34347). + const withBareDocEntry = async (entry: Record, body: () => Promise) => { const bareSlot = (booted!.engine.registry as unknown as { metadata: Map> }).metadata.get('doc')!; const before = bareSlot.has('shared_doc') ? { held: bareSlot.get('shared_doc') } : undefined; - booted!.engine.registry.registerItem('doc', { name: 'shared_doc', label: 'bare entry', content: '# bare' } as never, 'name' as never); + booted!.engine.registry.registerItem('doc', { name: 'shared_doc', content: '# bare', ...entry } as never, 'name' as never); try { - expect((booted!.engine.registry.resolveItem('doc', 'shared_doc', null) as { label?: string } | undefined)?.label).toBe('bare entry'); - for (const answer of await bareDoors(booted!, 'doc', 'shared_doc')) { - const served = answer.door.endsWith('/layers') ? answer.body?.effective?.label : (answer.body?.item ?? answer.body)?.label; - expect([answer.status, served, answer.door], JSON.stringify(answer.body)).toEqual([200, label, answer.door]); - } + await body(); } finally { if (before) bareSlot.set('shared_doc', before.held); else bareSlot.delete('shared_doc'); } + }; + /** The registry and the facade, each naming no package: the readers the bare doors agree with. */ + const registryReaders = async () => [ + (booted!.engine.registry.resolveItem('doc', 'shared_doc', null) as { label?: string } | undefined)?.label, + (await new MetadataFacade(booted!.engine.registry).get('doc', 'shared_doc') as { label?: string } | undefined)?.label, + ]; + /** Each bare door's answer: the plain read and `/published` the item, `/layers` its code, overlay and effective layers. */ + const bareDoorLabels = async () => (await bareDoors(booted!, 'doc', 'shared_doc')).map((answer) => [ + answer.door, answer.status, + ...(answer.door.endsWith('/layers') + ? [answer.body?.code?.label, answer.body?.overlay?.label, answer.body?.effective?.label] + : [(answer.body?.item ?? answer.body)?.label]), + ]); + const expectHolderAddressReadsOwnDoc = async () => { + const holder = ships[0]!; + for (const answer of await exactDocAndLayers(booted!, holder)) { + const served = answer.door.includes('/layers') + ? [answer.body?.code?.label, answer.body?.effective?.label] + : [(answer.body?.item ?? answer.body)?.label]; + const label = `${holder.split('.').pop()} doc`; + expect([answer.status, ...served, answer.door], JSON.stringify(answer.body)).toEqual([200, ...served.map(() => label), answer.door]); + } + }; + + it.runIf(ships.length === 1)('[#34452] one holder beside a stamp-less bare entry: the plain read, /layers (the entry as code and effective) and /published serve the entry on both transports, as the registry and MetadataFacade.get do; the holder\'s address reads its own doc', async () => { + await withBareDocEntry({ label: 'bare entry' }, async () => { + expect(await registryReaders()).toEqual(['bare entry', 'bare entry']); + for (const [door, status, ...served] of await bareDoorLabels()) { + const want = String(door).endsWith('/layers') ? ['bare entry', undefined, 'bare entry'] : ['bare entry']; + expect([door, status, ...served]).toEqual([door, 200, ...want]); + } + await expectHolderAddressReadsOwnDoc(); + }); + // The entry gone: the holder's doc again (the CONTROL above). + for (const [door, status, ...served] of await bareDoorLabels()) { + expect([door, status, served.at(-1)]).toEqual([door, 200, `${ships[0]!.split('.').pop()} doc`]); + } + }); + + // [#34452 acceptance 4] The hydrated package-less row the hydrator lays + // when it reads the row before the holder's artifact (the stored row and, + // in the bare slot, a tenant-authored body with no `_packageId`): the row + // answers first, as beside two holders (#34248): no code layer, the row as + // overlay and effective. FROM (origin/main 7213177e, measured): the bare + // doors served the holder's doc (`/layers` the row as overlay over the + // holder's effective doc) while the registry and the facade answered the row. + it.runIf(ships.length === 1)('[#34452] one holder beside a hydrated package-less row: the plain read, /layers (no code layer, the row as overlay and effective) and /published serve the row on both transports, as the registry and MetadataFacade.get do; the holder\'s address reads its own doc', async () => { + await booted!.engine.insert('sys_metadata', { + type: 'doc', name: 'shared_doc', namespace: 'default', package_id: null, scope: 'platform', strategy: 'merge', state: 'active', version: 1, + metadata: JSON.stringify({ name: 'shared_doc', label: 'environment doc', content: '# env' }), + }, { context: { isSystem: true } } as any); + try { + await withBareDocEntry({ label: 'environment doc', content: '# env', _provenance: 'org' }, async () => { + expect(await registryReaders()).toEqual(['environment doc', 'environment doc']); + for (const [door, status, ...served] of await bareDoorLabels()) { + const want = String(door).endsWith('/layers') ? [undefined, 'environment doc', 'environment doc'] : ['environment doc']; + expect([door, status, ...served]).toEqual([door, 200, ...want]); + } + await expectHolderAddressReadsOwnDoc(); + }); + } finally { + await booted!.engine.delete('sys_metadata', { where: { type: 'doc', name: 'shared_doc' }, multi: true, context: { isSystem: true } } as any); + } }); it('CONTROL: each holder\'s address answers its own doc on the plain read and /layers (code and effective), both transports', async () => { @@ -433,6 +493,25 @@ describe.each([ await expectExactReadsOwnDoc(); }); + // [#34190, ADR-0150 D3/D5] In process, the layered read naming no package + // refuses as the plain read does, naming both holders with candidates. + // FROM (origin/main 7213177e, measured on this rig, both orders): + // `getMetaItemLayered({ type: 'doc', name })` answered 200 with the layers + // of the holder the metadata service registered last while `getMetaItem` + // refused 409; the doors refused only because they ask the plain read. + it('[#34190] in process: getMetaItemLayered naming no package refuses 409 naming both, as getMetaItem does; naming each holder reads its own layers', async () => { + const protocol = booted!.kernel.getService('protocol'); + for (const read of [() => protocol.getMetaItem({ type: 'doc', name: 'shared_doc' }), () => protocol.getMetaItemLayered({ type: 'doc', name: 'shared_doc' })]) { + const refusal = await read().then((resolved: unknown) => ({ resolved }), (error: unknown) => error as any); + expect([refusal?.code, refusal?.status], JSON.stringify(refusal?.resolved ?? String(refusal?.message))).toEqual(['RESOURCE_CONFLICT', 409]); + expect((refusal?.refusal?.candidates ?? []).map((c: { packageId?: string }) => c.packageId).sort()).toEqual([ALPHA, BETA].sort()); + } + for (const [packageId, label] of [[ALPHA, 'alpha doc'], [BETA, 'beta doc']] as const) { + const layers = await protocol.getMetaItemLayered({ type: 'doc', name: 'shared_doc', packageId }); + expect([layers?.code?.label, layers?.effective?.label]).toEqual([label, label]); + } + }); + /** Each bare door's answer: the plain read and `/published` the item, `/layers` its code, overlay and effective layers. */ const expectBareDoorsServe = async (expected: { item: string; code: string | undefined; overlay: string | undefined }) => { for (const answer of await bareDoors(booted!, 'doc', 'shared_doc')) { 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 cbd40aa26b3..ae16d23c8b4 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 @@ -508,6 +508,122 @@ describe.each([ }, 240_000); }); +// --------------------------------------------------------------------------- +// [#34440, ADR-0150 D3] A package-less row beside the rows of a disabled +// holder and of enabled ones: every bare door gives the answer it gives when +// the disabled holder is absent (#33210). Two enabled holders are refused +// naming exactly them, never the disabled one, and the package-less row is +// never served in their place; one enabled holder is served. Every save +// order, both registration orders, before and after a reboot. +// +// Measured on `main` 7213177e (the card's re-measure): with E, F and D rows +// and a package-less row, the plain read and the execution read followed save +// order, `/published` served the package-less row and `/layers` refused 409 +// naming E, D and F; with E and D rows and a package-less row, the answer +// followed save order, and the order D, package-less, E answered 404 on every +// bare door. The CONTROL without a package-less row is the ruling-Q2 test +// above (409 naming E and F). +// --------------------------------------------------------------------------- + +describe.each([ + { regOrder: 'disabled first', registered: [ROW_D, ROW_E, ROW_F] }, + { regOrder: 'enabled first', registered: [ROW_E, ROW_F, ROW_D] }, +])('[#34440] a package-less row beside a disabled holder\'s row, packages registered $regOrder', ({ registered }) => { + const roots: string[] = []; + afterAll(() => { for (const dir of roots) rmSync(dir, { recursive: true, force: true }); }); + const freshFile = () => { + const dir = mkdtempSync(join(tmpdir(), 'os-meta-pl-disabled-db-')); + roots.push(dir); + return join(dir, 'meta.sqlite'); + }; + const down = async (booted: Booted) => { + if (booted.kernel.getState() === 'running') await booted.kernel.shutdown(); + roots.push(booted.root); + }; + const label = (id: string | null) => (id === null ? 'package-less row' : `${rowTag(id)} row`); + const noTrace = (answers: ReadonlyArray<{ body: unknown }>, door: string) => { + noDisabledTrace(answers); + for (const answer of answers) expect(JSON.stringify(answer.body ?? null), door).not.toContain('package-less row'); + }; + const expectExactAddresses = async (b: Booted, name: string, enabled: readonly string[]) => { + for (const id of enabled) { + const exact = await get(b.kernel, `/meta/dashboard/${name}`, { package: id }); + expect([exact.status, unwrap(exact.body)?.item?.label], JSON.stringify(exact.body)).toEqual([200, label(id)]); + } + const withheld = await get(b.kernel, `/meta/dashboard/${name}`, { package: ROW_D }); + expect([withheld.status, codeOf(withheld.body)], JSON.stringify(withheld.body)).toEqual([404, 'RESOURCE_NOT_FOUND']); + }; + const candidatesOf = (body: any) => [...(body?.error?.details?.candidates ?? [])].map((c: any) => c.packageId).sort(); + + const expectRefusedNamingEnabled = async (b: Booted, name: string) => { + const read = await get(b.kernel, `/meta/dashboard/${name}`); + expect([read.status, codeOf(read.body)], JSON.stringify(read.body)).toEqual([409, 'RESOURCE_CONFLICT']); + expect(candidatesOf(read.body), JSON.stringify(read.body)).toEqual([ROW_E, ROW_F].sort()); + const layers = await get(b.kernel, `/meta/dashboard/${name}/layers`); + expect([layers.status, codeOf(layers.body)], JSON.stringify(layers.body)).toEqual([409, 'RESOURCE_CONFLICT']); + expect(candidatesOf(layers.body), JSON.stringify(layers.body)).toEqual([ROW_E, ROW_F].sort()); + const published = await get(b.kernel, `/meta/dashboard/${name}/published`); + expect([published.status, codeOf(published.body)], JSON.stringify(published.body)).toEqual([409, 'RESOURCE_CONFLICT']); + for (const id of [ROW_E, ROW_F]) expect(JSON.stringify(published.body)).toContain(id); + noTrace([read, layers, published], name); + const protocol: any = b.kernel.getService('protocol'); + const executed = await protocol.getMetaItemForExecution({ type: 'dashboard', name }).then( + (answer: unknown) => ({ answer }), + (error: any) => ({ error: { code: error?.code, httpStatus: error?.httpStatus, candidates: [...(error?.refusal?.candidates ?? [])].map((c: any) => c.packageId).sort() } }), + ); + expect(executed).toEqual({ error: { code: 'RESOURCE_CONFLICT', httpStatus: 409, candidates: [ROW_E, ROW_F].sort() } }); + await expectExactAddresses(b, name, [ROW_E, ROW_F]); + }; + + const expectServedEnabled = async (b: Booted, name: string) => { + const read = await get(b.kernel, `/meta/dashboard/${name}`); + 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/${name}/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/${name}/published`); + expect([published.status, unwrap(published.body)?.label], JSON.stringify(published.body)).toEqual([200, 'enabled row']); + noDisabledTrace([read, layers, published]); + const executed = await (b.kernel.getService('protocol') as any).getMetaItemForExecution({ type: 'dashboard', name }); + expect(executed?.item?.label).toBe('enabled row'); + await expectExactAddresses(b, name, [ROW_E]); + }; + + const run = async (name: string, saved: ReadonlyArray, expectAnswer: (b: Booted, name: string) => Promise) => { + const file = freshFile(); + let booted = await bootRowKernel(registered, file); + try { + for (const id of saved) await layStoredRow(booted.engine, name, id, label(id)); + booted.engine.registry.disablePackage(ROW_D); + await expectAnswer(booted, name); + } finally { + await down(booted); + } + booted = await bootRowKernel(registered, file); + try { + booted.engine.registry.disablePackage(ROW_D); + await expectAnswer(booted, name); + } finally { + await down(booted); + } + }; + + it.each([ + { saveOrder: 'E, F, D, package-less', saved: [ROW_E, ROW_F, ROW_D, null] }, + { saveOrder: 'package-less, D, F, E', saved: [null, ROW_D, ROW_F, ROW_E] }, + { saveOrder: 'D, package-less, E, F', saved: [ROW_D, null, ROW_E, ROW_F] }, + ])('two enabled holders, saved $saveOrder: every bare door refuses naming exactly E and F, before and after a reboot', async ({ saved }) => { + await run('pl_two_dash', saved, expectRefusedNamingEnabled); + }, 240_000); + + it.each([ + { saveOrder: 'E, D, package-less', saved: [ROW_E, ROW_D, null] }, + { saveOrder: 'package-less, E, D', saved: [null, ROW_E, ROW_D] }, + { saveOrder: 'D, package-less, E', saved: [ROW_D, null, ROW_E] }, + ])('one enabled holder, saved $saveOrder: every bare door serves E\'s row and none names D, before and after a reboot', async ({ saved }) => { + await run('pl_one_dash', saved, expectServedEnabled); + }, 240_000); +}); + // --------------------------------------------------------------------------- // [#32607 contract review M1, M2, n1] The no-disabled arm judges a name's // holders at the rows' grain alone, never united with the registry's one bare diff --git a/packages/runtime/src/domains/meta.ts b/packages/runtime/src/domains/meta.ts index 2f5ca071175..2ce0b60ea27 100644 --- a/packages/runtime/src/domains/meta.ts +++ b/packages/runtime/src/domains/meta.ts @@ -1740,7 +1740,7 @@ export async function handleMetadataRequest(deps: DomainHandlerDeps, path: strin if (mixedOwner !== undefined && typeof stamp === 'string' && stamp !== mixedOwner && mixedHolders.includes(stamp)) return publishedCode; // [#34248, ruling 6893582352] …and a bare doc's package copy where // the layered read's code layer is the environment's own - // package-less entry (two enabled holders beside it): that entry + // package-less entry (one or more enabled holders beside it, #34452): that entry // answers first, never the holder registered last. const codeStamp = (publishedCode as { _packageId?: unknown } | null | undefined)?._packageId; return publishedType === 'doc' && publishedCode != null && (typeof codeStamp !== 'string' || codeStamp === '' || codeStamp === 'sys_metadata') diff --git a/packages/spec/src/migrations/entries/semantic/19.disabled-holder-package-less-row-bare-read-judged-as-absent.ts b/packages/spec/src/migrations/entries/semantic/19.disabled-holder-package-less-row-bare-read-judged-as-absent.ts new file mode 100644 index 00000000000..f7074c9a3bc --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/19.disabled-holder-package-less-row-bare-read-judged-as-absent.ts @@ -0,0 +1,48 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// A narrowing (and, in one save order, a widening) of the bare item read, not +// of any key: ADR-0150 D3 (#34440) has the read that names no package judge a +// package-less row beside a disabled holder's row over the served holders, +// giving the answer it gives when the disabled holder is absent (#33210, +// entry two-row-holders-bare-read-refused): two or more enabled holders are +// refused naming exactly them, one is served. The answer followed save order +// there (the package-less row, one holder's row, or 404), and the layered +// read's refusal named the disabled package. The disabled holder may hold the +// name as a stored row, or in code alone beside two or more enabled packages' +// rows, where every bare door answered 404 (contract review S4 on #38640, +// measured). No key is added, removed or +// re-shaped and no stored row changes shape, so no tombstone and no D2 +// conversion. No relevance question: the move turns on which installed +// packages are disabled, which no question over one stack can name. +export const entry: SemanticMigration = { + id: 'disabled-holder-package-less-row-bare-read-judged-as-absent', + surface: + 'The read of a metadata item that names no package (GET /api/v1/meta/TYPE/NAME, ' + + 'GET /api/v1/meta/TYPE/NAME/layers, GET /api/v1/meta/TYPE/NAME/published, and the execution read of the same ' + + 'name) of a type the registry reads by package, for a name no enabled package ships in code, held as stored ' + + 'rows by one or more enabled packages and held by a disabled package while a package-less row of the name is ' + + 'stored: the disabled package holding it as a stored row, or in code alone beside the stored rows of two or ' + + 'more enabled packages', + replacement: + 'Name the package: GET /api/v1/meta/TYPE/NAME?package=PACKAGE serves that enabled package\'s row. Beside two ' + + 'or more enabled holders the read that names no package answers 409 RESOURCE_CONFLICT (reason ' + + 'ambiguous-in-environment) naming exactly those holders in details.candidates, never the disabled package and ' + + 'never the package-less row; beside one it serves that holder\'s row, in every save order.', + reason: + 'A disabled package holds no name (ADR-0150 D3), so a name it shares with enabled packages must read as it reads ' + + 'without it. Beside a package-less row the judgment left the read as it was: the plain read and the execution ' + + 'read served whichever row was stored first, GET /api/v1/meta/TYPE/NAME/published served the package-less row, ' + + 'GET /api/v1/meta/TYPE/NAME/layers refused naming the disabled package too, and one enabled holder saved after ' + + 'the disabled one and the package-less row answered 404; with the disabled package holding the name in code ' + + 'alone beside two or more enabled packages\' rows, every read that names no package answered 404. The read now judges that row as it does with no ' + + 'disabled holder: a package-less row is no holder and no tie-break. There is no mechanical rewrite: which ' + + 'package\'s row a caller meant is a judgement about that caller.', + acceptanceCriteria: + 'For every such name while its disabled holder stays disabled: with two or more enabled holders every read ' + + 'that names no package answers 409 RESOURCE_CONFLICT naming exactly the enabled holders in ' + + 'details.candidates, and each ?package=PACKAGE read of an enabled holder answers its own row; with one enabled ' + + 'holder every read that names no package answers that holder\'s row; GET /api/v1/meta/TYPE/NAME?package=ID of ' + + 'the disabled package answers 404, in every save order and after a restart.', +}; diff --git a/packages/spec/src/migrations/entries/semantic/19.doc-bare-read-environment-entry-first.ts b/packages/spec/src/migrations/entries/semantic/19.doc-bare-read-environment-entry-first.ts new file mode 100644 index 00000000000..985a8f5b58b --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/19.doc-bare-read-environment-entry-first.ts @@ -0,0 +1,49 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// A change of answer of the doc reads that name no package, not of any key: +// ruling 6942962369 (#34452) has the environment's own package-less doc entry +// answer first whatever number of enabled packages hold the same name, and +// the reads agree with the registry's own read of the name. Beside ONE holder +// the doors served that holder's doc, while the registry and the facade read +// served the environment's entry; beside two or more they already served the +// entry. And with no such entry the in-process layered read of a doc two or +// more enabled packages hold (#34190) refuses as the plain read does, where it +// served the holder registered last. No key is added, removed or re-shaped +// and no stored row changes shape, so no tombstone and no D2 conversion. No +// relevance question: the move turns on which installed packages hold a name, +// which no question over one stack can name. The known envelope deviation the +// acceptance names is carried by #38659 (the printed guidance names no tracker). +export const entry: SemanticMigration = { + id: 'doc-bare-read-environment-entry-first', + surface: + 'The read of a doc that names no package (GET /api/v1/meta/doc/NAME, GET /api/v1/meta/doc/NAME/layers, ' + + 'GET /api/v1/meta/doc/NAME/published, and the in-process item read and layered read with no packageId) for a ' + + 'name one enabled package holds while the environment stores its own package-less doc of the same name ' + + '(a doc registered with no package, or a package-less sys_metadata row once it is hydrated or saved into ' + + 'the registry\'s bare slot; a row only the store holds is no such entry); and the in-process layered read ' + + 'with no packageId of a doc two or more enabled packages hold with no such entry', + replacement: + 'To read the package\'s doc, name the package: GET /api/v1/meta/doc/NAME?package=PACKAGE (and the in-process ' + + 'reads with packageId) serve that package\'s own doc, beside the environment\'s entry or not. To read the ' + + 'environment\'s entry, name no package. An in-process layered read that names no package of a doc two or more ' + + 'enabled packages hold now rejects with 409 RESOURCE_CONFLICT naming each holder in refusal.candidates, as the ' + + 'item read and every HTTP door already did; name the package there too.', + reason: + 'The environment\'s own item answers first whatever number of packages hold the same name, and reads and writes ' + + 'give the same answer (ruling 6942962369). Beside one holder the doors that name no package served the ' + + 'holder\'s doc while the registry and the metadata facade served the environment\'s entry, so the same name ' + + 'answered two different docs depending on which reader asked; beside two or more holders the doors already ' + + 'served the entry. The in-process layered read swallowed the refusal the item read gives two holders and served ' + + 'the holder registered last, so its answer followed registration order. There is no mechanical rewrite: which ' + + 'doc a caller meant is a judgement about that caller.', + acceptanceCriteria: + 'For every doc name the environment stores a package-less entry of and one or more enabled packages hold: every ' + + 'read that names no package answers the environment\'s entry, and GET /api/v1/meta/doc/NAME?package=PACKAGE ' + + 'answers that package\'s doc. For every doc name two or more enabled packages hold with no such entry: every ' + + 'read that names no package, the in-process layered read included, answers 409 RESOURCE_CONFLICT naming each ' + + 'holder, and each read naming a holder answers its own doc. Known deviation, carried by a follow-up card: the plain read ' + + 'naming no package serves the environment\'s entry under a holder\'s envelope (`_packageId` that holder, ' + + '`_provenance` `package`), as it already did beside two or more holders; the content served is the entry\'s.', +};