diff --git a/.changeset/32613-two-holder-override-slots.md b/.changeset/32613-two-holder-override-slots.md new file mode 100644 index 00000000000..58f39ee27e5 --- /dev/null +++ b/.changeset/32613-two-holder-override-slots.md @@ -0,0 +1,22 @@ +--- +'@objectstack/metadata-protocol': patch +--- + +fix(metadata-protocol)!: when two packages ship one flow or action name and each has its declared `.custom` override, every read, the lists and the boot pull use each override in its own package's slot, in any registration order (ADR-0150 D4) + +Clause-②: no (narrowing) — the env-wide lists stop serving the extra entries they served before: for a name two or more packages ship, each with a declared `.custom` override, the entry under the override's pair slot (stamped with the name's first shipper) is no longer listed. For an action name, the package that registered second no longer serves its shipped action in place of its own declared override: ADR-0150 D4 binds each `.custom` override to the package it customizes (rows "registry overlay slot" and R16), so the decline it replaces was never the contract. First-party callers that read those entries: 0. +Metadata-protocol: none + + + +**BREAKING** for a caller that read the env-wide flow or action list (`GET /meta/flow`, `GET /meta/action`, `getMetaItemsForExecution`) and used an entry stamped with one package that carried another package's declared override. Such an entry is no longer listed. Read each package's override from its own entry, or by its package (`?package=ID`). Nothing in the workspace reads those entries. + +Two packages ship a flow or an action of the same name. Each has a declared override in its own `.custom` pair. Before this fix, three places got this wrong. + +- **The lists.** These are the served list (`GET /meta/flow`, `GET /meta/action`, naming no package) and the execution view (`getMetaItemsForExecution`, which the automation engine arms from). They listed each override a second time, under its pair's slot. The name's first registered shipper stamped its own package on that extra entry. For a flow, alpha first gave `alpha:OVR-A` twice, `alpha:OVR-B` and `beta:OVR-B`. Beta first gave `alpha:OVR-A`, `beta:OVR-A` and `beta:OVR-B` twice. So one package's override was listed under the other package. An action listed the first package's override twice the same way. Now each override is listed once, as its own package's item: exactly `alpha:OVR-A` and `beta:OVR-B`, in either order. With the first registered package disabled, the lists also kept the disabled package's override; now they list the enabled package's override alone, whichever package is disabled. When only one package ships the name, the pair's slot was already dropped, so that case is unchanged. +- **An action's override.** The reads judged an action's stored row as a declared override against the name's first registered shipper only. So the second package's declared override was declined at its own address (`?package=`, plain and layered), in its served-overrides list, in the served list and in the execution view, all of which served that package's shipped action instead. Alpha first, the lists gave `alpha:OVR-A` twice and `beta:SHIPPED-beta`. Beta first, they gave `alpha:SHIPPED-alpha` and `beta:OVR-B` twice. With the first package disabled, the enabled package's override was still declined. Now each package's address and both lists serve its own override: exactly `alpha:OVR-A` and `beta:OVR-B`, in either order. A flow was already judged against every shipper. +- **The boot pull.** The hydration decides which stored row holds a flow name's bare registry slot. It judged a row as a declared override against the first holder only. So the second holder's override counted as a plain stored row. If a package-less row was read after it, that row took the slot and the override was lost. The automation boot pull then armed that holder's shipped flow until `kernel:ready` re-armed from the protocol's view. A record change in that window ran the wrong body. Now a row is judged against every package that ships the name, and each override is armed in its own package's slot from the first pull. + +Only flow and action move. For the six sealed types (page, app, dataset, doc, book, mapping), a second holder's declared override is still judged against the name's first registered shipper, and for every other overlay type the env-wide list keeps the pair's entry, as before. Those, and what a registry reader gets for each holder of an action name, are carried to #33131. + +No door refuses a request it answered before, and no key, value or stored shape changes. The flow's by-name reads (`?package=`) already answered each package's own override and are unchanged. diff --git a/packages/metadata-protocol/src/protocol-lock-state.ts b/packages/metadata-protocol/src/protocol-lock-state.ts index acf1cdc16b7..b6bc2c5d458 100644 --- a/packages/metadata-protocol/src/protocol-lock-state.ts +++ b/packages/metadata-protocol/src/protocol-lock-state.ts @@ -151,19 +151,26 @@ export function declinesStoredRow( this: Pick, type: string, name: unknown, row?: ServedOverrideRow): boolean { const installed = installedManifestsOfEngine(this.engine); + // [ADR-0150 D4, #31696, #32613] Whether `row` is the declared override of + // a package that ships `(type, name)`, judged against EVERY such package: + // two packages' items of one name are two items, each with its own + // declared override, so the read serves each in its package's slot — + // never only the override of whichever shipper the by-name lookup happens + // to find first (the first holder to register), which made the answer + // depend on registration order (red line 2). + // Used for a flow and an action only (the six sealed types below keep the + // single-owner judgment). + // No row, no override: the shippers are not read for a name-only question. + const servedOverrideOfAShipper = (shippedType: string, shippedName: string): boolean => row !== undefined && row !== null + && (isServedOverrideRowOf(row, this.packagedArtifactOwner({ type: shippedType, name: shippedName }), installed) + || [...shippingPackageIds(this.shippedArtifactsOf(shippedType, shippedName))] + .some((shipper) => isServedOverrideRowOf(row, shipper, installed))); if (this.isShippedFlowName(type, name)) { // [#28412, ADR-0146 D9 item 1] …except the one row that IS the // packaged flow now: the shipping package's declared override, judged // on the row's own `package_id` and body by the one served-override // predicate. Every other stored row of the name stays declined. - // [ADR-0150 D4, #31696] Judged against EVERY package that ships the - // name: two packages' flows of one name are two items, each with its - // own declared override, so the read serves each in its package's - // slot — never only the override of whichever shipper the by-name - // lookup happens to find first. - if (isServedOverrideRowOf(row, this.packagedArtifactOwner({ type: 'flow', name: name as string }), installed)) return false; - return ![...shippingPackageIds(this.shippedArtifactsOf('flow', name as string))] - .some((shipper) => isServedOverrideRowOf(row, shipper, installed)); + return !servedOverrideOfAShipper('flow', name as string); } if (typeof name !== 'string' || name === '') return false; if (this.isDeclaredCodeDatasource(type, name)) return true; @@ -177,7 +184,18 @@ export function declinesStoredRow( // way: its declared override is served over the base's name from its // row, so the layered read's `effective` and a by-name read answered by // the metadata service see it as the registry's readers do. - return !((servesSealedOverrideRow(type) || canonicalMetaType(type) === 'action') + // [#32613] …for an `action`, against every package that ships the name, + // as the flow's above: with two holders of an action name, the second + // holder's declared override was judged against the first's package and + // declined at its own address, in the served list and in the execution + // view, so which holder's override ran depended on which package + // registered first. + if (canonicalMetaType(type) === 'action') return !servedOverrideOfAShipper(type, name); + // The six sealed types keep the single-owner judgment (the name's first + // registered shipper) here: moving them to every shipper changes what a + // read naming no package answers for each of them, which is measured and + // pinned on its own follow-up card (#33131), not by this change. + return !(servesSealedOverrideRow(type) && isServedOverrideRowOf(row, this.packagedArtifactOwner({ type, name }), installed)); } diff --git a/packages/metadata-protocol/src/protocol-meta-list-reads.ts b/packages/metadata-protocol/src/protocol-meta-list-reads.ts index e19d988df50..36449512c49 100644 --- a/packages/metadata-protocol/src/protocol-meta-list-reads.ts +++ b/packages/metadata-protocol/src/protocol-meta-list-reads.ts @@ -32,7 +32,7 @@ import { isActionWithheldByDisabledPackage, isItemOfDisabledPackage, } from './protocol-authoring-refusals.js'; -import { soleShippingPackage } from './protocol-environment-rows.js'; +import { shippingPackageIds } from './protocol-environment-rows.js'; import type { ProtocolHost } from './protocol-host.js'; import { canonicalizeMetaRequestType } from './protocol-meta-type-schema.js'; import { mergePackageAwareOverlay, servedViewExpansion, withoutServedRowName } from './protocol-overlay-merge.js'; @@ -92,6 +92,15 @@ function decorateListedItem(type: string, item: unknown): unknown { return { ...served, name: (item as { name: string }).name, ...(_diagnostics !== undefined ? { _diagnostics } : {}) }; } +/** + * [#32613] The types whose env-wide list drops a two-shipper override's pair + * slot: the two whose answer, for a name two or more packages ship, each with + * its declared override, is measured and pinned (each override once, in its + * own package's slot, in either registration order). Any other type of such a + * name keeps its pair's entry, as before. + */ +const TWO_HOLDER_PAIR_SLOT_TYPES: ReadonlySet = new Set(['flow', 'action']); + /** The body of `ObjectStackProtocolImplementation#readFlattenedMetaItems`; the method's docblock there is its contract. */ export async function readFlattenedMetaItems(host: Pick, request: { type: string; packageId?: string; names?: readonly string[]; previewDrafts?: boolean }, audience: 'served' | 'execution', @@ -780,19 +789,44 @@ export async function readFlattenedMetaItems(host: Pick(); + const shippersOf = new Map>(); items = (items as any[]).filter((it) => { const itemName = it?.name; const bound = boundPackageOf(it?._packageId); if (typeof itemName !== 'string' || bound === undefined) return true; - if (!soleShipperOf.has(itemName)) { - soleShipperOf.set(itemName, soleShippingPackage(host.shippedArtifactsOf(request.type, itemName, typeShipping))); + if (!shippersOf.has(itemName)) { + shippersOf.set(itemName, shippingPackageIds(host.shippedArtifactsOf(request.type, itemName, typeShipping))); + } + const shippers = shippersOf.get(itemName)!; + if (shippers.has(bound)) return true; + if (shippers.size > 1) { + // Scoped to the two types whose two-holder answer is measured + // and pinned (flow, action); every other type keeps the item + // as before, carried to its own follow-up card (#33131). + if (!TWO_HOLDER_PAIR_SLOT_TYPES.has(PLURAL_TO_SINGULAR[request.type] ?? request.type)) return true; + return ![...shippers].some((shipper) => + isServedOverrideRowOf({ type: request.type, package_id: bound, metadata: it }, shipper, installed)); } - const soleShipper = soleShipperOf.get(itemName); - if (soleShipper === undefined || soleShipper === bound) return true; + if (shippers.size === 0) return true; + const [soleShipper] = shippers; return isBundle && host.baseServesBundleMember(request.type, itemName, soleShipper, it, typeShipping); }); } diff --git a/packages/metadata-protocol/src/protocol-registry-hydration.ts b/packages/metadata-protocol/src/protocol-registry-hydration.ts index 3f8d3a46731..3d568f9ac16 100644 --- a/packages/metadata-protocol/src/protocol-registry-hydration.ts +++ b/packages/metadata-protocol/src/protocol-registry-hydration.ts @@ -37,6 +37,7 @@ import { PLURAL_TO_SINGULAR } from '@objectstack/spec/shared'; import { expandViewContainer, isAggregatedViewContainer } from '@objectstack/spec/ui'; import { bindStoredRow } from './stored-row-binding.js'; import { incomingTakesStoredFlowSlot } from './stored-flow-slot.js'; +import { shippingPackageIds } from './protocol-environment-rows.js'; import { OBJECT_EXTENSION_TYPE } from './protocol-object-extension-item.js'; import { canonicalMetaType } from './protocol-meta-type-schema.js'; import { remainingRowsPhrase } from './protocol-authoring-refusals.js'; @@ -537,7 +538,7 @@ export class ProtocolRegistryHydrationFacet { * anything the static map does not carry, so a runtime kind the platform * has never heard of can never trip this gate. */ - static async hydrateOverlayIntoRegistry(host: Pick, type: string, + static async hydrateOverlayIntoRegistry(host: Pick, type: string, data: unknown, options: HydrationOptions,): Promise { // [#9111] See the header: the mint door asserts, the caller folds. @@ -663,8 +664,16 @@ export class ProtocolRegistryHydrationFacet { const held = typeof registry.getItem === 'function' ? registry.getItem(type, String((data as any).name)) : undefined; - const owner = host.packagedArtifactOwner({ type, name: String((data as any).name) }); - if (!incomingTakesStoredFlowSlot(held, registered, owner, installedManifestsOf(registry))) return true; + // [#32613, ADR-0150 D4] …judged against EVERY package that ships + // the name, each by its own pair, never only the bare-name owner + // (the first holder to register): a second holder's declared + // override is its package's override too, and a package-less row + // read after it no longer drops it from the boot pull. + const name = String((data as any).name); + const shippers = new Set(shippingPackageIds(host.shippedArtifactsOf(type, name))); + const owner = host.packagedArtifactOwner({ type, name }); + if (typeof owner === 'string' && owner !== '') shippers.add(owner); + if (!incomingTakesStoredFlowSlot(held, registered, shippers, installedManifestsOf(registry))) return true; } registry.registerItem(type, registered, 'name' as any); await host.hydrateExpandedViewItems(type, data, options); diff --git a/packages/metadata-protocol/src/stored-flow-slot.test.ts b/packages/metadata-protocol/src/stored-flow-slot.test.ts index cb77e935b00..3bde1db0d07 100644 --- a/packages/metadata-protocol/src/stored-flow-slot.test.ts +++ b/packages/metadata-protocol/src/stored-flow-slot.test.ts @@ -87,3 +87,46 @@ describe('[#28717] the declared override keeps the bare slot of its shipped flow expect(shadowedStoredRowsOf({ ...held })).toEqual([]); }); }); + +/** + * [#32613, ADR-0150 D4] A name two packages ship, each with its declared + * override in its own pair: an override is judged against every shipper, so + * neither holder's override is ever read as a plain stored row. + */ +describe('[#32613] two packages ship the name: each holder\'s declared override is an override', () => { + const OTHER = 'com.acme.other'; + const SHIPPERS = [BASE, OTHER]; + const otherOverride = () => + bindStoredRow(body('OTHER OVERRIDE', { overrides: { package: OTHER, basedOn: '1.0.0' } }), `${OTHER}.custom`); + + it('the second holder\'s override keeps the slot over a package-less row read after it, and carries it', () => { + const held = otherOverride(); + expect(incomingTakesStoredFlowSlot(held, legacy(), SHIPPERS, NOTHING_INSTALLED)).toBe(false); + expect(labels(shadowedStoredRowsOf(held))).toEqual(['LEGACY']); + }); + + it('FROM: judged against the first holder alone, the package-less row took the slot and dropped it', () => { + const held = otherOverride(); + const incoming = legacy(); + expect(incomingTakesStoredFlowSlot(held, incoming, BASE, NOTHING_INSTALLED)).toBe(true); + expect(shadowedStoredRowsOf(incoming)).toEqual([]); + }); + + it('two holders\' overrides: whichever is read last takes the slot and carries the other, in either order', () => { + for (const [first, second] of [[override, otherOverride], [otherOverride, override]] as const) { + const held = first(); + const incoming = second(); + expect(incomingTakesStoredFlowSlot(held, incoming, SHIPPERS, NOTHING_INSTALLED)).toBe(true); + expect(labels(shadowedStoredRowsOf(incoming))).toEqual([(held as { label: string }).label]); + // …and a package-less row read after both keeps neither from the slot's body. + expect(incomingTakesStoredFlowSlot(incoming, legacy(), SHIPPERS, NOTHING_INSTALLED)).toBe(false); + expect(labels([incoming, ...shadowedStoredRowsOf(incoming)]).sort()) + .toEqual([(incoming as { label: string }).label, (held as { label: string }).label, 'LEGACY'].sort()); + } + }); + + it('CONTROL: a pair row declaring a package that does not ship the name is no override', () => { + const stranger = bindStoredRow(body('STRANGER', { overrides: { package: 'com.acme.none', basedOn: '1.0.0' } }), 'com.acme.none.custom'); + expect(incomingTakesStoredFlowSlot(stranger, legacy(), SHIPPERS, NOTHING_INSTALLED)).toBe(true); + }); +}); diff --git a/packages/metadata-protocol/src/stored-flow-slot.ts b/packages/metadata-protocol/src/stored-flow-slot.ts index c08bc22bb9d..863072adc1e 100644 --- a/packages/metadata-protocol/src/stored-flow-slot.ts +++ b/packages/metadata-protocol/src/stored-flow-slot.ts @@ -23,6 +23,19 @@ * read again (same binding) always replaces itself, so a re-save of the * override, declared or not, is what the slot holds. * + * ## A name two or more packages ship (#32613, ADR-0150 D4) + * + * A row is a declared override when it declares the override of ANY package + * that ships the name, each judged by its own pair, as `declinesStoredRow` + * judges it (#31696). Before, it was judged against the bare-name owner + * alone, the first holder to register: the second holder's declared override + * read as a plain stored row, so a package-less row read after it took the + * slot and dropped it, and the boot pull armed that holder's shipped body + * until `kernel:ready` re-armed from the protocol's view. Under two holders + * the slot is transport only: the pull reads the slot's body and every row + * carried on it ({@link shadowedStoredRowsOf}), and ranks each in its own + * package's slot, so which override the bare slot holds decides nothing. + * * ## The row that loses the slot is kept, stored and shadowed * * It is not deleted and not migrated: `flow` has `allowEnvironmentOverlay: @@ -82,14 +95,15 @@ export function shadowedStoredRowsOf(item: unknown): readonly object[] { /** * Settle the bare slot of one flow name between the row it `held` and the * stored row now `incoming`, both bound by {@link storedRowBindingOf}, for the - * name's shipping package `basePackageId` (the loader's set's owner, or none). - * Returns `true` when `incoming` takes the slot, `false` when the held + * packages that ship the name, `shippingPackages` (the loader's set's owner + * and [#32613] every other package that ships it; none for a name no package + * ships). Returns `true` when `incoming` takes the slot, `false` when the held * declared override keeps it. Records the row that loses on the one that wins. */ export function incomingTakesStoredFlowSlot( held: unknown, incoming: unknown, - basePackageId: unknown, + shippingPackages: string | Iterable | undefined, installed: InstalledManifestLookup, ): boolean { const heldBinding = storedRowBindingOf(held); @@ -102,8 +116,9 @@ export function incomingTakesStoredFlowSlot( carryShadowed(held, incoming); return true; } - const isOverride = (item: unknown, binding: string | null | undefined) => - isServedOverrideRowOf({ type: 'flow', package_id: binding ?? null, metadata: item }, basePackageId, installed); + const shippers = typeof shippingPackages === 'string' ? [shippingPackages] : [...(shippingPackages ?? [])]; + const isOverride = (item: unknown, binding: string | null | undefined) => shippers.some((shipper) => + isServedOverrideRowOf({ type: 'flow', package_id: binding ?? null, metadata: item }, shipper, installed)); const incomingIsOverride = isOverride(incoming, incomingBinding); if (!incomingIsOverride && isOverride(held, heldBinding)) { carryShadowed(held, held, incoming); diff --git a/packages/objectql/src/protocol-flow-custom-override.test.ts b/packages/objectql/src/protocol-flow-custom-override.test.ts index e0db1841319..5df93a9caab 100644 --- a/packages/objectql/src/protocol-flow-custom-override.test.ts +++ b/packages/objectql/src/protocol-flow-custom-override.test.ts @@ -387,6 +387,188 @@ describe('[#28412, #30062] the pair-row removal admits every open type', () => { * Every other stored row of the name stays unserved, and an override that * widens who may run the action is refused (ADR-0066 D4). */ +/** + * [#32613, ADR-0150 D4, epic #31527 red line 2] Two packages ship one name, and + * each has its declared override in its own `.custom` pair. Naming no package, + * the served list and the execution view (what the automation engine arms + * from) list each package's override once, in that package's own slot, + * whichever package registered first. Before, the pair's own slot of each + * override was listed beside its base's: a name one package ships narrows it + * away, a name two ship did not, and the pair's slot was enveloped by the + * name's first shipper — alpha first, `alpha:OVR-A` twice and `alpha:OVR-B` + * beside `beta:OVR-B`; beta first, `beta:OVR-A` beside the right two. + */ +describe('[#32613] two packages ship one name, each with its declared override: each listed once, in its own slot', () => { + const ALPHA = 'com.probe.alpha'; + const BETA = 'com.probe.beta'; + const SHARED_ACTION = 'shared_close'; + const sharedAction = (label: string, extra: Record = {}) => ({ + name: SHARED_ACTION, label, type: 'script', body: { language: 'js', source: `return { ran: '${label}' };` }, ...extra, + }); + const app = (id: string, ns: string) => ({ + id, name: ns, version: '1.0.0', namespace: ns, type: 'app', + objects: [{ name: `${ns}_task`, label: 'Task', sharingModel: 'private', fields: { title: { name: 'title', label: 'title', type: 'text' } } }], + flows: [flowBody(`SHIPPED-${ns}`)], + actions: [sharedAction(`SHIPPED-${ns}`)], + }); + /** The shipping apps registered in `order` (`ALPHA` and `BETA`, or `ALPHA` alone), each pair installed. */ + async function bootHolders(order: readonly string[]) { + const engine = new ObjectQL(); + const { driver } = makeMemoryDriver(); + engine.registerDriver(driver, true); + await engine.init(); + engine.registry.registerObject(sysMetadataObject, 'test-package'); + for (const o of [SysMetadataHistoryObject, SysMetadataAuditObject, SysMetadataCommitObject]) { + engine.registry.registerObject(o as any, 'test-package'); + } + for (const id of order) engine.registerApp(app(id, id === ALPHA ? 'alpha' : 'beta')); + const protocol = new ObjectStackProtocolImplementation(engine, () => new Map(), undefined); + for (const base of order) { + const ns = base === ALPHA ? 'alpha' : 'beta'; + await (protocol as any).installPackage({ + manifest: { id: `${base}.custom`, name: `${ns}-custom`, version: '0.1.0', type: 'app', namespace: `${ns}_custom`, dependencies: { [base]: '^1' } }, + }); + } + return protocol; + } + /** Each base's declared override, saved and published through the save door into its own pair. */ + async function overrideEach(protocol: ObjectStackProtocolImplementation, type: 'flow' | 'action', bases: readonly string[]) { + for (const base of bases) { + const label = base === ALPHA ? 'OVR-A' : 'OVR-B'; + const declared = { overrides: { package: base, basedOn: '1.0.0' } }; + const item = type === 'flow' ? flowBody(label, declared) : sharedAction(label, declared); + const name = type === 'flow' ? FLOW : SHARED_ACTION; + await protocol.saveMetaItem({ type, name, item, mode: 'draft', packageId: `${base}.custom` } as any); + await protocol.publishMetaItem({ type, name, packageId: `${base}.custom` } as any); + } + } + const entries = async (protocol: ObjectStackProtocolImplementation, type: 'flow' | 'action', face: 'served' | 'execution') => { + const res: any = face === 'served' + ? await protocol.getMetaItems({ type }) + : await (protocol as any).getMetaItemsForExecution({ type }); + const name = type === 'flow' ? FLOW : SHARED_ACTION; + return (res.items as any[]).filter((i) => i?.name === name).map((i) => `${i._packageId}:${i.label}`).sort(); + }; + + for (const order of [[ALPHA, BETA], [BETA, ALPHA]] as const) { + const first = order[0] === ALPHA ? 'alpha' : 'beta'; + it(`flow, ${first} registered first: exactly alpha:OVR-A and beta:OVR-B, served and executed`, async () => { + const protocol = await bootHolders(order); + await overrideEach(protocol, 'flow', [ALPHA, BETA]); + for (const face of ['served', 'execution'] as const) { + expect(await entries(protocol, 'flow', face), face).toEqual([`${ALPHA}:OVR-A`, `${BETA}:OVR-B`]); + } + // The by-name reads naming each package agree with each slot. + expect((await read(protocol, ALPHA)).label).toBe('OVR-A'); + expect((await read(protocol, BETA)).label).toBe('OVR-B'); + }); + + it(`action, ${first} registered first: exactly alpha:OVR-A and beta:OVR-B, served, executed and at each address`, async () => { + const protocol = await bootHolders(order); + await overrideEach(protocol, 'action', [ALPHA, BETA]); + for (const face of ['served', 'execution'] as const) { + expect(await entries(protocol, 'action', face), face).toEqual([`${ALPHA}:OVR-A`, `${BETA}:OVR-B`]); + } + // The by-name read and the layered read naming each package serve + // that package's own override, and each base lists its own. FROM: + // the second package to register was judged against the first's + // package and declined everywhere (`beta:SHIPPED-beta` beside + // `alpha:OVR-A` with alpha first; `alpha:SHIPPED-alpha` beside + // `beta:OVR-B` with beta first). + const p: any = protocol; + for (const [pkg, label] of [[ALPHA, 'OVR-A'], [BETA, 'OVR-B']] as const) { + expect((await p.getMetaItem({ type: 'action', name: SHARED_ACTION, packageId: pkg })).item.label, pkg).toBe(label); + const layers = await p.getMetaItemLayered({ type: 'action', name: SHARED_ACTION, packageId: pkg }); + expect(layers.effective?.label, `${pkg} layered effective`).toBe(label); + expect((await p.listServedOverrides({ packageId: pkg })).map((e: any) => `${e.type}:${e.name}`), `${pkg} served overrides`) + .toEqual([`action:${SHARED_ACTION}`]); + } + }); + + // Mixed (review n1): two holders, only one with a declared override. + // Flow: the overridden holder's override and the other holder's + // shipped body, each once, in its own slot, whichever holder is + // overridden. Action: the overridden holder's override is listed in + // its own slot and served at its own address. The other holder's list + // slot is NOT pinned here: when the second holder to register is the + // overridden one, the first holder's slot lists that override too, on + // `main` as on this change (the registry face: the hydrator registers + // the override row under the bare name wearing the first shipper's + // envelope), carried to #33131. + it(`flow and action, ${first} registered first, one holder overridden: its override in its own slot`, async () => { + for (const [overridden, other] of [[ALPHA, BETA], [BETA, ALPHA]] as const) { + const protocol = await bootHolders(order); + const p: any = protocol; + const label = overridden === ALPHA ? 'OVR-A' : 'OVR-B'; + const shipped = `SHIPPED-${other === ALPHA ? 'alpha' : 'beta'}`; + for (const type of ['flow', 'action'] as const) { + await overrideEach(protocol, type, [overridden]); + const name = type === 'flow' ? FLOW : SHARED_ACTION; + for (const face of ['served', 'execution'] as const) { + const listed = await entries(protocol, type, face); + if (type === 'flow') { + expect(listed, `${type} ${face}, ${overridden} overridden`).toEqual([`${overridden}:${label}`, `${other}:${shipped}`].sort()); + } else { + expect(listed.filter((e) => e.startsWith(`${overridden}:`)), `${type} ${face}, ${overridden} overridden`).toEqual([`${overridden}:${label}`]); + } + } + expect((await p.getMetaItem({ type, name, packageId: overridden })).item.label, `${type} at ${overridden}`).toBe(label); + if (type === 'flow') { + expect((await p.getMetaItem({ type, name, packageId: other })).item.label, `${type} at ${other}`).toBe(shipped); + } + } + } + }); + + // The served holder set (#32497): with one holder disabled, the + // enabled holder's override is the one listed and served at its + // address, whichever holder is disabled (the first to register, which + // the by-name lookup names, included); re-enabled, each holder's own. + it(`flow and action, ${first} registered first, one holder disabled then re-enabled: the enabled holder's own override`, async () => { + const protocol = await bootHolders(order); + const registry = (protocol as any).engine.registry; + const p: any = protocol; + for (const type of ['flow', 'action'] as const) await overrideEach(protocol, type, [ALPHA, BETA]); + const byName = async (type: 'flow' | 'action', pkg: string) => (await p.getMetaItem({ + type, name: type === 'flow' ? FLOW : SHARED_ACTION, packageId: pkg, + })).item.label; + for (const [disabled, enabled, label] of [[BETA, ALPHA, 'OVR-A'], [ALPHA, BETA, 'OVR-B']] as const) { + registry.disablePackage(disabled); + for (const type of ['flow', 'action'] as const) { + for (const face of ['served', 'execution'] as const) { + expect(await entries(protocol, type, face), `${type} ${face}, ${disabled} disabled`).toEqual([`${enabled}:${label}`]); + } + expect(await byName(type, enabled), `${type} at ${enabled}, ${disabled} disabled`).toBe(label); + } + registry.enablePackage(disabled); + for (const type of ['flow', 'action'] as const) { + for (const face of ['served', 'execution'] as const) { + expect(await entries(protocol, type, face), `${type} ${face}, re-enabled`).toEqual([`${ALPHA}:OVR-A`, `${BETA}:OVR-B`]); + } + } + } + }); + } + + it('CONTROL: one package ships the name, with its declared override: listed once, as before', async () => { + const protocol = await bootHolders([ALPHA]); + await overrideEach(protocol, 'flow', [ALPHA]); + await overrideEach(protocol, 'action', [ALPHA]); + for (const face of ['served', 'execution'] as const) { + expect(await entries(protocol, 'flow', face), face).toEqual([`${ALPHA}:OVR-A`]); + expect(await entries(protocol, 'action', face), face).toEqual([`${ALPHA}:OVR-A`]); + } + }); + + it('CONTROL: two packages ship the name and neither is overridden: each shipped body, once', async () => { + const protocol = await bootHolders([ALPHA, BETA]); + for (const face of ['served', 'execution'] as const) { + expect(await entries(protocol, 'flow', face), face).toEqual([`${ALPHA}:SHIPPED-alpha`, `${BETA}:SHIPPED-beta`]); + expect(await entries(protocol, 'action', face), face).toEqual([`${ALPHA}:SHIPPED-alpha`, `${BETA}:SHIPPED-beta`]); + } + }); +}); + describe('[#30065] a declared .custom action override is the packaged action, at every door', () => { const OBJ = 'showcase_task'; async function bootWithLedger() { diff --git a/packages/services/service-automation/src/flow-declared-override-first-boot-pull.integration.test.ts b/packages/services/service-automation/src/flow-declared-override-first-boot-pull.integration.test.ts index 30d593515f5..173caa883d4 100644 --- a/packages/services/service-automation/src/flow-declared-override-first-boot-pull.integration.test.ts +++ b/packages/services/service-automation/src/flow-declared-override-first-boot-pull.integration.test.ts @@ -108,10 +108,20 @@ const otherStack = () => */ type Second = 'none' | 'before' | 'after' | 'installed-after' | 'installed-both' | 'installed-both-reversed'; -type Row = 'override' | 'legacy'; +type Row = 'override' | 'legacy' | 'other-override'; const storedRow = (row: Row) => - row === 'override' + // [#32613] OTHER's declared override, in OTHER's own pair. + row === 'other-override' + ? { + id: 'meta_other_override', + name: FLOW, + type: 'flow', + state: 'active', + package_id: `${OTHER}.custom`, + metadata: JSON.stringify(ticketFlow('OTHER-OVERRIDE', { overrides: { package: OTHER, basedOn: '1.0.0' } })), + } + : row === 'override' ? { id: 'meta_override', name: FLOW, @@ -418,6 +428,36 @@ describe('[#31696] a name a second package also ships: each package\'s flow is a expect(overlay[0][1]).toMatchObject({ flow: FLOW, holders: [BASE, OTHER].sort() }); }); + /** + * [#32613] Each package's declared override, in its own pair, beside a + * package-less row read after it: the boot pull arms each holder's + * override in that holder's slot, whichever package registers first (and + * so owns the bare name). Before, an override was judged against the + * bare-name owner alone, so the other holder's override read as a plain + * stored row: the package-less row read after it took the bare slot and + * dropped it, and the pull armed that holder's shipped body until + * `kernel:ready` re-armed from the protocol's view. + */ + const OVERRIDES: ReadonlyArray = [ + [['other-override', 'legacy'], 'after', 'BASE', 'OTHER-OVERRIDE'], + [['override', 'legacy'], 'before', 'OVERRIDE', 'OTHER'], + [['override', 'other-override'], 'before', 'OVERRIDE', 'OTHER-OVERRIDE'], + [['other-override', 'override'], 'after', 'OVERRIDE', 'OTHER-OVERRIDE'], + [['override', 'other-override', 'legacy'], 'before', 'OVERRIDE', 'OTHER-OVERRIDE'], + [['other-override', 'override', 'legacy'], 'after', 'OVERRIDE', 'OTHER-OVERRIDE'], + ]; + for (const [rows, second, baseLabel, otherLabel] of OVERRIDES) { + it(`[#32613] rows ${rows.join(' then ')}, the second package registered ${second}: each holder's own body at the pull`, async () => { + let armedAtPull: unknown = 'unread'; + const { automation, refusals } = await measuredBoot(rows, async (_ql, engine) => { + armedAtPull = labels(engine); + }, second); + expect(armedAtPull).toEqual({ [BASE]: baseLabel, [OTHER]: otherLabel }); + expect(labels(automation)).toEqual({ [BASE]: baseLabel, [OTHER]: otherLabel }); + expect(refusals).toEqual([]); + }); + } + /** * [M2] A package-less disable row read by a boot that reassembles the clash (pull, ledger read, then the * `kernel:ready` rehydrate): the first package to register is not the row's owner, so it binds to neither.