diff --git a/.changeset/37851-disabled-holder-own-row-publish-rollback-refused.md b/.changeset/37851-disabled-holder-own-row-publish-rollback-refused.md new file mode 100644 index 00000000000..b22bd2611c9 --- /dev/null +++ b/.changeset/37851-disabled-holder-own-row-publish-rollback-refused.md @@ -0,0 +1,27 @@ +--- +'@objectstack/metadata-protocol': minor +'@objectstack/spec': minor +--- + +fix(metadata-protocol)!: refuse the per-item publish and rollback naming no package of a name only disabled packages hold, with or without a package-less row stored + +Clause-②: no (narrowing) +Metadata-protocol: narrowed +Skills-docs: none — no page under `skills/**` or `content/docs/**` teaches a per-item publish or rollback naming no package over a name only disabled packages hold; the refusal's own sentence names the fix + + + +**BREAKING** for a deployment that publishes or rolls back one metadata item, with no package named, at a name whose every holder is disabled and no package-less row is stored for it: the write is now refused where it answered `200`. Fix: send the same publish or rollback naming the package (`?package=ID`, in process `packageId`) where the refusal says "Name the package this publish is for" or "Name the package this rollback is for"; enable a package that holds the name (`PATCH /api/v1/packages/:id/enable`) where it says "Enable the package that holds …". + +The bare save of such an item already answers `409 RESOURCE_CONFLICT` and writes nothing (a disabled package holds no name). The per-item publish and rollback naming no package asked that judgment only where a package-less row or draft was stored, so they still wrote the disabled package's own row, or stored the package-less row again from its history, and enabling the package again served a body no read had shown. + +Every moved answer, before → after, for a type the registry reads by package, while every holder of the name is disabled, where the ADR-0146 D11 close leaves the write open: + +- `POST /api/v1/meta/:type/:name/publish` whose draft address is the disabled package's own draft (beside a package-less row or with none stored): `200` (the draft promoted into that package's active row) → `409 RESOURCE_CONFLICT`, "Name the package this publish is for, then send it again …", nothing written. The publish naming the package still promotes it. +- `POST /api/v1/meta/:type/:name/rollback` that restores the disabled package's own row: `200` (that row rewritten to the version's body) → `409 RESOURCE_CONFLICT`, "Name the package this rollback is for, then send it again …", nothing written. The rollback naming the package still restores it. +- `POST /api/v1/meta/:type/:name/rollback` with the package-less row's history but no package-less row stored: `200` (a package-less row inserted with the version's body) → `409 RESOURCE_CONFLICT`, "Enable the package that holds …", nothing written. +- The same three through the in-process `publishMetaItem` / `rollbackMetaItem` with no `packageId`. + +Once a holder is enabled again the same publish or rollback answers as before the disable. + +Not moved: a publish or rollback naming a package, with the package enabled or disabled; a publish with no draft at its address, which keeps its `404 NO_DRAFT`; an item the ADR-0146 D11 close covers, which keeps that close's `403 NOT_OVERRIDABLE`; a name no package holds; a name an enabled package holds; every read. Correction to the note `37608-disabled-holder-publish-rollback-refused`, released in `19.0.0-next.1` and left as released: its "Not moved" list says that a rollback of a package-bound row is not moved, and that two writes on an item only disabled packages hold still land, left open for a separate decision (#37851): a publish whose draft address is the disabled package's own draft, and a rollback with no package-less row stored. From this release on, all three are refused as listed above, while the same publish or rollback naming the package, or sent once a holder is enabled again, answers as before. Migration entry `disabled-holder-package-less-row-bare-write-refused` (`@objectstack/spec`) now carries them for the upgrade guide. diff --git a/packages/metadata-protocol/src/protocol-history-and-publish.ts b/packages/metadata-protocol/src/protocol-history-and-publish.ts index 71bbd07a27f..13a159fd7d9 100644 --- a/packages/metadata-protocol/src/protocol-history-and-publish.ts +++ b/packages/metadata-protocol/src/protocol-history-and-publish.ts @@ -903,16 +903,25 @@ export class ProtocolHistoryAndPublishFacet { // packages hold, that draft and that row are their // customization, hidden with them, and the promotion wrote the // active row the next enable serves. Refused with the enable - // as the remedy, nothing written. A promotion of a package's - // own draft into its own row (`key` and `into` that package) - // touches no package-less row and is not asked; nor is a - // publish with no draft, which keeps its `NO_DRAFT`. - if (addressRefusal === undefined && address.kind === 'draft' && (address.key === null || address.into === null)) { + // as the remedy, nothing written. A publish with no draft is + // not asked, and keeps its `NO_DRAFT`. + // + // [#37851 ruling A] …and a promotion of a package's own draft + // into its own row (`key` and `into` that package) is asked + // too, as the bare save of the item is: of a name only + // disabled packages hold it wrote the disabled package's + // active row, which the next enable served. It touches no + // package-less row, so it is asked the judgment's first state + // only ({@link disabledHoldersOnlyRefusal}, the `?package=` + // remedy, which the publish naming that package reaches), + // whatever package-less row is stored beside it. + if (addressRefusal === undefined && address.kind === 'draft') { + const ownDraft = address.key !== null && address.into !== null; const active = await host.packagelessAddress(singularType, request.name, request.member, 'active'); - if (active.unbound || address.drafts.unbound) { + if (ownDraft || active.unbound || address.drafts.unbound) { addressRefusal = packagelessHolderRefusal(host, 'publish', request.type, singularType, request.name, request.member, { candidates: [...new Set([...active.candidates, ...address.drafts.candidates])], - unbound: true, + unbound: !ownDraft, }, 'disabled-holders'); } } diff --git a/packages/metadata-protocol/src/protocol-package-commits.ts b/packages/metadata-protocol/src/protocol-package-commits.ts index 2b2d8a6707e..701311ceb76 100644 --- a/packages/metadata-protocol/src/protocol-package-commits.ts +++ b/packages/metadata-protocol/src/protocol-package-commits.ts @@ -2307,15 +2307,27 @@ export class ProtocolPackageCommitsFacet { // save and the delete ask ({@link packagelessHolderRefusal}, its // disabled-holders judgment only), after the D11 close above, and is // refused with the enable as the remedy, nothing written. - if (request.packageId === undefined && rollbackPackageId === null) { + // + // [#37851 ruling A] Whether or not a package-unbound row is stored + // now: with none stored but its history kept, the restore inserted + // the package-unbound row again, the same customization, so it is + // refused with the same remedy. And a rollback naming no package that + // restores a disabled package's OWN row (the binding read above names + // it) wrote that row, which the next enable served, while the bare + // save of the item is refused: it is asked the judgment's first state + // ({@link disabledHoldersOnlyRefusal}, the `?package=` remedy, which + // the rollback naming that package reaches). + if (request.packageId === undefined) { const active = await host.packagelessAddress(singularType, request.name, member, 'active'); - if (active.unbound) { - const holderRefusal = packagelessHolderRefusal( - host, 'rollback', request.type, singularType, request.name, member, - { candidates: active.candidates, unbound: true }, 'disabled-holders', - ); - if (holderRefusal) throw holderRefusal; - } + const holderRefusal = packagelessHolderRefusal( + host, 'rollback', request.type, singularType, request.name, member, + { + candidates: [...new Set([...active.candidates, ...(rollbackPackageId !== null ? [rollbackPackageId] : [])])], + unbound: rollbackPackageId === null, + }, + 'disabled-holders', + ); + if (holderRefusal) throw holderRefusal; } // [ADR-0146 D2] A rollback of the base's paired `.custom` row is the // pair's declared override, as its save is: it edits no managed item, diff --git a/packages/metadata-protocol/src/protocol-save.ts b/packages/metadata-protocol/src/protocol-save.ts index 8095a8f8cb9..a4c81ef7aec 100644 --- a/packages/metadata-protocol/src/protocol-save.ts +++ b/packages/metadata-protocol/src/protocol-save.ts @@ -3535,8 +3535,12 @@ export async function packagelessRowHeldBaseDraftAddress( * whether or not a row is stored at the address (over none, the delete and * the discard are refused too, not answered the no-op receipt). * [ADR-0150 D3, the 2026-11-26 note] The bare per-item publish and the bare - * per-item rollback ask the second state only (`arms: 'disabled-holders'`), - * after the ADR-0146 D11 close, so they write nothing a disabled holder hides. + * per-item rollback ask the disabled-holders judgment only + * (`arms: 'disabled-holders'`), after the ADR-0146 D11 close, so they write + * nothing a disabled holder hides: [#37851 ruling A] its first state where + * they write a package's own row (the publish of its own draft, the rollback + * of its own row), its second where they write the package-unbound row, + * stored or not. * Asked after {@link servedPackagelessSaveAddress} (a name an enabled and a * disabled package both hold) and after the rows' own refusal (two or more * bindings), so neither answer moves. diff --git a/packages/objectql/src/disabled-holder-packageless-row-doors.test.ts b/packages/objectql/src/disabled-holder-packageless-row-doors.test.ts index ac386dfdae5..f04ceeff133 100644 --- a/packages/objectql/src/disabled-holder-packageless-row-doors.test.ts +++ b/packages/objectql/src/disabled-holder-packageless-row-doors.test.ts @@ -305,22 +305,46 @@ describe('[ADR-0150 D3, the 2026-11-26 note] the per-item publish and the rollba expect(await subjectAt(protocol, 'fr-FR')).toBe('DRAFT fr'); }); - it('publish, the package\'s own draft beside the stored package-less row: promoted into the package\'s row as on `main`, the package-less row byte-identical', async () => { + it.each([['beside the stored package-less row', true], ['with no package-less row stored', false]] as const)('publish, the package\'s own draft %s: refused 409 with the `?package=` remedy, nothing written; the publish naming the package promotes it, the package-less row byte-identical', async (_cell, withRow) => { const stores: Stores = new Map(); const { engine, protocol } = await boot(stores); - await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'SAVED fr') } as any); + if (withRow) await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'SAVED fr') } as any); await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'PKG DRAFT fr'), mode: 'draft', packageId: PKG } as any); engine.registry.disablePackage(PKG); const packageless = () => JSON.stringify(Array.from(stores.get('sys_metadata')?.values() ?? []) .filter((r) => r.name === NAME && (r.package_id ?? null) === null).map((r) => [r.state, r.bundle_member ?? null, r.metadata, r.version])); - const before = packageless(); - // The draft address is the package's own draft, promoted into the - // package's own row: no package-less row is read or written, so the - // judgment is not asked (the answer `main` 56c9cae6 gives). - expect(await protocol.publishMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any)).toMatchObject({ success: true }); - expect(packageless()).toBe(before); + const before = storedRows(stores); + const packagelessBefore = packageless(); + // FROM (`main` 73d5e347): `success: true`, the draft promoted into the + // disabled package's active row, which the next enable serves. + // TO (#37851 ruling A): refused as the bare save of the item is, with + // the `?package=` remedy (the promotion addresses the package's own + // draft and row, which the publish naming the package reaches), and + // nothing is written. + const refused = await refusalOf(protocol.publishMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any)); + expect([refused?.status, refused?.code], String(refused?.message ?? 'no refusal')).toEqual([409, 'RESOURCE_CONFLICT']); + expect(String(refused?.message).startsWith('Name the package this publish is for, then send it again')).toBe(true); + expect(String(refused?.message)).not.toContain(PKG); + expect(storedRows(stores)).toBe(before); + // CONTROL — the remedy: the publish naming the package promotes the + // draft into the package's own row, as on `main`, and leaves the + // package-less row byte-identical. + expect(await protocol.publishMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR', packageId: PKG } as any)).toMatchObject({ success: true }); + expect(packageless()).toBe(packagelessBefore); expect(Array.from(stores.get('sys_metadata')?.values() ?? []) - .filter((r) => r.name === NAME && r.state === 'active').map((r) => r.package_id ?? null).sort()).toEqual([PKG, null].sort()); + .filter((r) => r.name === NAME && r.state === 'active').map((r) => r.package_id ?? null).sort()) + .toEqual((withRow ? [PKG, null] : [PKG]).sort()); + }); + + it('publish, the package\'s own draft, re-enabled: the bare publish promotes it as on `main`', async () => { + const stores: Stores = new Map(); + const { engine, protocol } = await boot(stores); + await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'PKG DRAFT fr'), mode: 'draft', packageId: PKG } as any); + engine.registry.disablePackage(PKG); + expect((await refusalOf(protocol.publishMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any)))?.status).toBe(409); + engine.registry.enablePackage(PKG); + expect(await protocol.publishMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any)).toMatchObject({ success: true }); + expect(await subjectAt(protocol, 'fr-FR')).toBe('PKG DRAFT fr'); }); it('publish with no draft stored, beside the stored package-less row: `NO_DRAFT` as on `main`, nothing written', async () => { @@ -358,4 +382,56 @@ describe('[ADR-0150 D3, the 2026-11-26 note] the per-item publish and the rollba .toMatchObject({ success: true, restoredFromVersion: first }); expect(await subjectAt(protocol, 'fr-FR')).toBe('SAVED fr 1'); }); + + it('rollback with the package-less row\'s history but no row stored: refused 409 with the enable as the remedy, no row inserted; re-enabled, the same rollback restores the version', async () => { + const stores: Stores = new Map(); + const { engine, protocol } = await boot(stores); + await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'SAVED fr 1') } as any); + await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'SAVED fr 2') } as any); + const events = (await protocol.historyMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any)).events; + const first = Math.min(...events.map((e: any) => e.version as number)); + await protocol.deleteMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any); + expect(packagelessRows(stores)).toEqual([]); + engine.registry.disablePackage(PKG); + const before = storedRows(stores); + // FROM (`main` 73d5e347): `success: true`, a new package-unbound + // active row inserted with the first version's body, which the next + // enable serves. TO (#37851 ruling A): refused, the enable as the + // remedy (the restore writes the package-unbound row, the disabled + // holder's customization, which naming the package does not reach), + // and no row is inserted. + const refused = await refusalOf(protocol.rollbackMetaItem({ type: 'email_template', name: NAME, toVersion: first, member: 'fr-FR' } as any)); + expect([refused?.status, refused?.code], String(refused?.message ?? 'no refusal')).toEqual([409, 'RESOURCE_CONFLICT']); + expect(String(refused?.message).startsWith('Enable the package that holds email_template ')).toBe(true); + expect(String(refused?.message)).not.toContain(PKG); + expect(storedRows(stores)).toBe(before); + // CONTROL — re-enabled: nothing is served at the member, and the same rollback restores the version. + engine.registry.enablePackage(PKG); + expect(await subjectAt(protocol, 'fr-FR')).toBeUndefined(); + expect(await protocol.rollbackMetaItem({ type: 'email_template', name: NAME, toVersion: first, member: 'fr-FR' } as any)) + .toMatchObject({ success: true, restoredFromVersion: first }); + expect(await subjectAt(protocol, 'fr-FR')).toBe('SAVED fr 1'); + }); + + it('rollback of the package\'s own row: refused 409 with the `?package=` remedy, nothing written; the rollback naming the package restores the version', async () => { + const stores: Stores = new Map(); + const { engine, protocol } = await boot(stores); + await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'PKG fr 1'), packageId: PKG } as any); + await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'PKG fr 2'), packageId: PKG } as any); + const events = (await protocol.historyMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR', packageId: PKG } as any)).events; + expect(events).toHaveLength(2); + const first = Math.min(...events.map((e: any) => e.version as number)); + engine.registry.disablePackage(PKG); + const before = storedRows(stores); + const refused = await refusalOf(protocol.rollbackMetaItem({ type: 'email_template', name: NAME, toVersion: first, member: 'fr-FR' } as any)); + expect([refused?.status, refused?.code], String(refused?.message ?? 'no refusal')).toEqual([409, 'RESOURCE_CONFLICT']); + expect(String(refused?.message).startsWith('Name the package this rollback is for, then send it again')).toBe(true); + expect(String(refused?.message)).not.toContain(PKG); + expect(storedRows(stores)).toBe(before); + // CONTROL — the remedy: the rollback naming the package restores the package's row, as on `main`. + expect(await protocol.rollbackMetaItem({ type: 'email_template', name: NAME, toVersion: first, member: 'fr-FR', packageId: PKG } as any)) + .toMatchObject({ success: true, restoredFromVersion: first }); + engine.registry.enablePackage(PKG); + expect(await subjectAt(protocol, 'fr-FR')).toBe('PKG fr 1'); + }); }); diff --git a/packages/spec/src/migrations/entries/semantic/19.disabled-holder-package-less-row-bare-write-refused.ts b/packages/spec/src/migrations/entries/semantic/19.disabled-holder-package-less-row-bare-write-refused.ts index b52a180acb7..d168414b5db 100644 --- a/packages/spec/src/migrations/entries/semantic/19.disabled-holder-package-less-row-bare-write-refused.ts +++ b/packages/spec/src/migrations/entries/semantic/19.disabled-holder-package-less-row-bare-write-refused.ts @@ -10,6 +10,9 @@ import type { SemanticMigration } from '../../types.js'; // per-item publish and the per-item rollback naming no package are refused // where the ADR-0146 D11 close leaves them open. Each answered 200 there and // edited, stored, removed, promoted into or restored a row no read served; +// the per-item publish and rollback are refused with no package-less row +// stored too, where they write the disabled package's own row or store the +// package-less row again from its history (#37851 ruling A); // where a code package ships the name, the draft discard over a stored row // with no draft already answered 409, and only its sentence moves. No key is // added, removed or re-shaped and no stored row changes shape, so no tombstone @@ -25,7 +28,9 @@ export const entry: SemanticMigration = { + 'POST /api/v1/meta/TYPE/NAME/rollback, and the in-process publishMetaItem and rollbackMetaItem with no ' + 'packageId), for a name held only by installed packages that are ' + 'disabled, of a type the registry reads by package, while a package-less row or a package-less draft is ' - + 'stored for that name. Where the package-less write onto a packaged item was already closed (ADR-0146 D11: ' + + 'stored for that name (for the publish and the rollback, also with none stored: the publish of the disabled ' + + 'package\'s own draft, the rollback of its own row, and the rollback that stores the package-less row again ' + + 'from its history). Where the package-less write onto a packaged item was already closed (ADR-0146 D11: ' + '403 NOT_OVERRIDABLE for the save, the delete, the publish and the rollback), only the draft discard moves', replacement: 'Enable a package that holds the name (PATCH /api/v1/packages/ID/enable; GET /api/v1/packages shows which ' @@ -36,7 +41,10 @@ export const entry: SemanticMigration = { + 'ADR-0146 D11 close covers (one read-only code package ships it, with a pair, and os migrate ' + 'packageless-overlays would move its row) is the exception this entry does not change: its save, its ' + 'delete, its publish and its rollback naming no package answer that close first, 403 NOT_OVERRIDABLE with that close\'s own remedy, with ' - + 'the package enabled or disabled; there only the draft discard answers this 409.', + + 'the package enabled or disabled; there only the draft discard answers this 409. The publish of the disabled ' + + 'package\'s own draft and the rollback of its own row are the other exception: they address that package\'s ' + + 'own row, so their refusal names ?package= as the fix, as the save with no package-less row stored does, and ' + + 'the publish or rollback naming the package (?package=ID) goes through while it stays disabled.', reason: 'A package-less row stored at a name a package holds is that package\'s customization, never a second item, ' + 'and a disabled package\'s items are withheld from every read that names no package. The writes that name no ' @@ -45,10 +53,10 @@ export const entry: SemanticMigration = { + 'into it and the rollback rewrote it, so enabling the package again served its item without the ' + 'customization, or with a body nobody saw land. The save, the draft save, the delete and the draft discard ' + 'now judge the name\'s holders past a stored package-less row, as they already did with none stored. The ' - + 'publish and the rollback judge them only where they promote the package-less draft or restore the ' - + 'package-less row while one is stored; with none stored they judge no holder, as before, so a publish of ' - + 'the disabled package\'s own draft and a rollback that stores the package-less row again are not refused ' - + 'by this entry. A name no package holds, a package-less row at a name an enabled package holds, and, for ' + + 'publish and the rollback judge them wherever they write: the publish where it promotes the package-less ' + + 'draft or the disabled package\'s own draft, the rollback where it restores the package-less row, stored ' + + 'or not, or the disabled package\'s own row. The two that write the package\'s own row answer the ?package= ' + + 'remedy, as the save with no package-less row stored does. A name no package holds, a package-less row at a name an enabled package holds, and, for ' + 'the save, the draft save, the delete and the draft discard, a name only disabled packages hold with no ' + 'package-less row stored (its refusal keeps the ?package= remedy) answer as before. There is no mechanical ' + 'rewrite: whether the disabled package should be enabled again is a judgement about the deployment.', @@ -58,8 +66,11 @@ export const entry: SemanticMigration = { + '?mode=draft), DELETE /api/v1/meta/TYPE/NAME (and ?state=draft), POST /api/v1/meta/TYPE/NAME/publish and ' + 'POST /api/v1/meta/TYPE/NAME/rollback naming no package answer 409 ' + 'RESOURCE_CONFLICT and leave every stored row of the name byte-identical (the publish where the draft it ' - + 'promotes is the package-less one, the rollback where it restores the package-less row; a publish of a ' - + 'package\'s own draft and a publish with no draft answer as before). Where that close applies, the ' + + 'promotes is the package-less one, the rollback where it restores the package-less row; a publish with no ' + + 'draft answers as before). With no package-less row stored, the publish of a disabled package\'s own draft ' + + 'and the rollback naming no package answer the same 409 and write nothing: the ?package= remedy where they ' + + 'write the package\'s own row, the enable remedy where the rollback would store the package-less row again. ' + + 'Where that close applies, the ' + 'draft discard answers the same 409, and the save, the draft save, the delete, the publish and the rollback ' + 'answer 403 NOT_OVERRIDABLE ' + 'as they did before, storing nothing. Once a holder is enabled again, the read naming no package serves the '