Skip to content

Commit 0b87f12

Browse files
fix(metadata-protocol)!: refuse the bare publish and rollback of a name only disabled packages hold, with or without a package-less row (#37851) (#37948)
repo:objectstack#3 · os-tesla · session_01L9qibyUSf2nKJWW6qBemSU <!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoHpXeKaibCgzF7LxhhjHxMf)_ Fixes #37851 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 ## 维护者速读 - 包停用后,不指明包的单项发布和回滚以前还能写进去(发布写进停用包自己的行,回滚把已删的无包定制重新插回来),现在和保存一样被拒绝,什么都不写。 - 这是 #37851 裁定 A 「两处都拒绝」的实现,外加裁定要求先测的第三格(停用包自有行的裸回滚):实测在 main 上也落地,所以一并拒绝。 - 写包自己的行的两种(发布自有草稿、回滚自有行)提示"指明包"(`?package=`),指明包后照常写;会把无包行插回来的回滚提示"先启用包"。指明包的写、读、启用后的行为都不变;本改动可整体撤回。 - 无 ## What changes Ruling A on #37851 (comment 7216539589, maintainer 「两处都拒绝」): the per-item publish and rollback naming no package refuse a name only disabled packages hold, as the bare save does, whether or not a package-less row is stored. PR #37818 made both doors ask the disabled-holders judgment only where they read or write a package-unbound row that is already stored; three cells were left writing. - **Cell (a), per-item publish of the disabled package's own draft** (`promoteDraftForPublish`, `packages/metadata-protocol/src/protocol-history-and-publish.ts`): where no package is named and the draft address is the package's own draft (`key` and `into` that package), the door now asks `packagelessHolderRefusal` (`arms: 'disabled-holders'`) with `unbound: false`. Over a name only disabled packages hold it answers `disabledHoldersOnlyRefusal` (verb `publish`): `409 RESOURCE_CONFLICT`, "Name the package this publish is for, then send it again …", the bare save's own sentence there. That holds whether or not a package-less row is stored beside it, because the promotion never touches that row and the publish naming the package reaches the draft. This flips the control pin #37818 added (its line 320). - **Cell (b), per-item rollback with the package-less row's history but no row stored** (`rollbackMetaItemUnaudited`, `packages/metadata-protocol/src/protocol-package-commits.ts`): the `active.unbound` precondition is dropped. Where the restore writes the package-unbound row (`rollbackPackageId === null`), stored or not, the door answers `disabledHoldersCustomizationRefusal` (verb `rollback`): `409 RESOURCE_CONFLICT`, "Enable the package that holds …". The restore would have inserted the package-unbound row again, which is the disabled holder's customization. - **Cell (c), per-item rollback of the disabled package's own row** (same door): measured first, as the ruling asks. On `main` 73d5e34 it answered `success: true` and restored the row (pin below, red on main). Refused in this PR as (a) is: `unbound: false`, `disabledHoldersOnlyRefusal` (verb `rollback`), and the rollback naming the package still restores it. The rollback's candidate set is the active rows' bindings plus the restore's binding, so a `.custom` pair of a disabled base is judged the way the save judges it. The judgment returns `undefined` with any enabled holder, so every answer over an enabled package is unchanged. The `packagelessHolderRefusal` docblock now says which state each door asks. Also in this PR: - **Migration entry** `disabled-holder-package-less-row-bare-write-refused` (spec, pending release): the surface, replacement, reason and acceptance criteria name the three cells and their two remedies. The `reason` sentence L2 S1 on #37818 required ("with none stored they judge no holder … not refused by this entry") is replaced with what the doors now do. - **New changeset** `.changeset/37851-disabled-holder-own-row-publish-rollback-refused.md`: `minor` for metadata-protocol and spec, BREAKING scoped to the three cells, ADR-0087 `not-required (already-registered disabled-holder-package-less-row-bare-write-refused)`. Its "Not moved" paragraph also carries the correction to the 37608 note (next bullet). - **No edit to the released note** `.changeset/pre/37608-disabled-holder-publish-rollback-refused.md`. The release PR #37661 (`19.0.0-next.1`) consumed it, so this PR keeps `main`'s blob byte for byte (seat ruling, Option B, comment 7222609810). Its "Not moved" list still names these three cells as landing; the #37851 changeset above states the correction, and whether to edit the pre/ text before GA is the release owner's call. `Check Changeset` is green. - ADR-0150 D3 note wording (`docs/adr/**`) is not in this diff; the seat carries it to the ADR checklist, per the ruling. ## Tests `packages/objectql/src/disabled-holder-packageless-row-doors.test.ts`, inside the `describe` #37818 added (same fixture: `com.acme.mail` ships `email_template` `acme.welcome` in en-US / zh-CN; `fr-FR` is a member it never ships, the cell the D11 close leaves open): - publish, the package's own draft, `it.each` over beside the stored package-less row (the flipped :320 control) and with no package-less row stored: refused 409 with the `?package=` sentence, no package named, every stored row byte-identical. CONTROL: the publish naming the package promotes it, the package-less row byte-identical. - CONTROL: publish of the package's own draft, re-enabled: the bare publish promotes it as on `main`. - rollback with the package-less row's history but no row stored (saved twice, deleted, then disabled): refused 409 with the enable sentence, no row inserted. CONTROL: re-enabled, the same rollback restores the version. - rollback of the package's own row (saved twice with `packageId`, then disabled): refused 409 with the `?package=` sentence, nothing written. CONTROL: the rollback naming the package restores it; re-enabled, it is served. <details><summary>Measurement, reach on main, fix</summary> - **Served-stack measurement before the ruling** (real `RestServer` routes over the real ObjectQL engine and protocol, in-memory driver, this fixture, `origin/main` 0a3ea67): recorded on the card, comment 7216513948. Bare `PUT` answered `409 RESOURCE_CONFLICT`; bare `POST /publish` and bare `POST /rollback` answered `200` and wrote. - **Reach on `main` 73d5e34** (pins committed first as 1217b6a, run against main's `metadata-protocol` build): `Tests 5 failed | 9 passed (14)`. The four refusal pins and the re-enabled publish control failed with `no refusal: expected [ undefined, undefined ] to deeply equal [ 409, 'RESOURCE_CONFLICT' ]`; that includes cell (c), so the ruling's third cell lands on `main`. - **Fix** (42bb7de, metadata-protocol rebuilt): `Tests 14 passed (14)`. </details> ## Verification Local, at head 0480711 on `origin/main` 73d5e34, each run through `os-verify-lock`: | Run | Result | |---|---| | `pnpm --filter @objectstack/metadata-protocol test` | `Test Files 372 passed \| 9 skipped (381)`, `Tests 23598 passed \| 45 skipped (23643)`, exit 0 | | `pnpm --filter @objectstack/objectql test` | `Test Files 642 passed (642)`, `Tests 14535 passed (14535)`, exit 0 | | `pnpm --filter @objectstack/rest test` | `Test Files 432 passed (432)`, `Tests 8972 passed \| 351 skipped (9323)`, exit 0 | | `typecheck` metadata-protocol, objectql | exit 0 | | spec `vitest run src/migrations` | `Tests 206 passed (206)` | | Derived gate families (`dispatch-gates.mjs --commands`, 98 commands) | 95 exit 0 (spec `check:api-surface`, `check:browser-reachable-entries`, `check:dual-source-exports`, `check:entry-nameability`, `check:exported-any` and cli `migrate-meta-engine-guidance.test.ts` green after a spec + cli rebuild). `check-empty-changeset` was red at this head on the then-DELIBERATE CORRECTION of the 37608 note; that edit is gone at `c488ff99` (Option B) and `Check Changeset` is green there | NOT MEASURED locally: `check:dual-build-cjs-loads`, reason: it needs every package's `dist/` (no `adapters/hono`, `apps/account` build here); CI's Lint & Repo Gates runs it. `check-plugin-teardown-shape --self-test`, reason: shallow clone cannot reach its pinned fixture commit; checker-health only. Dogfood battery at the final head `c488ff99`, under `os-verify-lock` (card comment 7223157350): closure build exit 0; spec `check:generated` 14 of 14 up to date; pin file 14 of 14 passed; dogfood 490 test files passed (3 skipped), 4144 tests passed (68 skipped). CI at `c488ff99`: 58 success, 11 skipped, none red. ## Acceptance notes - The enable sentence says "the row stored for it under no package is that package's customization". In cell (b) no such row is stored at the moment of the refusal; its history is, and the restore would store it. The ruling names that sentence for (b), so this PR keeps it unchanged. - In-process `publishMetaItem` with `packageId: null` present (#37818 record N1) still takes the named branch; unchanged here. --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibz3J6vDGdnFpMq3hkm)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8b47659 commit 0b87f12

6 files changed

Lines changed: 173 additions & 34 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
'@objectstack/metadata-protocol': minor
3+
'@objectstack/spec': minor
4+
---
5+
6+
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
7+
8+
Clause-②: no (narrowing)
9+
Metadata-protocol: narrowed
10+
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
11+
12+
<!-- adr-0087: not-required (already-registered disabled-holder-package-less-row-bare-write-refused) the entry the six other writes of this narrowing registered now names these three cells too -->
13+
14+
**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 …".
15+
16+
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.
17+
18+
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:
19+
20+
- `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.
21+
- `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.
22+
- `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.
23+
- The same three through the in-process `publishMetaItem` / `rollbackMetaItem` with no `packageId`.
24+
25+
Once a holder is enabled again the same publish or rollback answers as before the disable.
26+
27+
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.

‎packages/metadata-protocol/src/protocol-history-and-publish.ts‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -903,16 +903,25 @@ export class ProtocolHistoryAndPublishFacet {
903903
// packages hold, that draft and that row are their
904904
// customization, hidden with them, and the promotion wrote the
905905
// active row the next enable serves. Refused with the enable
906-
// as the remedy, nothing written. A promotion of a package's
907-
// own draft into its own row (`key` and `into` that package)
908-
// touches no package-less row and is not asked; nor is a
909-
// publish with no draft, which keeps its `NO_DRAFT`.
910-
if (addressRefusal === undefined && address.kind === 'draft' && (address.key === null || address.into === null)) {
906+
// as the remedy, nothing written. A publish with no draft is
907+
// not asked, and keeps its `NO_DRAFT`.
908+
//
909+
// [#37851 ruling A] …and a promotion of a package's own draft
910+
// into its own row (`key` and `into` that package) is asked
911+
// too, as the bare save of the item is: of a name only
912+
// disabled packages hold it wrote the disabled package's
913+
// active row, which the next enable served. It touches no
914+
// package-less row, so it is asked the judgment's first state
915+
// only ({@link disabledHoldersOnlyRefusal}, the `?package=`
916+
// remedy, which the publish naming that package reaches),
917+
// whatever package-less row is stored beside it.
918+
if (addressRefusal === undefined && address.kind === 'draft') {
919+
const ownDraft = address.key !== null && address.into !== null;
911920
const active = await host.packagelessAddress(singularType, request.name, request.member, 'active');
912-
if (active.unbound || address.drafts.unbound) {
921+
if (ownDraft || active.unbound || address.drafts.unbound) {
913922
addressRefusal = packagelessHolderRefusal(host, 'publish', request.type, singularType, request.name, request.member, {
914923
candidates: [...new Set([...active.candidates, ...address.drafts.candidates])],
915-
unbound: true,
924+
unbound: !ownDraft,
916925
}, 'disabled-holders');
917926
}
918927
}

‎packages/metadata-protocol/src/protocol-package-commits.ts‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,15 +2307,27 @@ export class ProtocolPackageCommitsFacet {
23072307
// save and the delete ask ({@link packagelessHolderRefusal}, its
23082308
// disabled-holders judgment only), after the D11 close above, and is
23092309
// refused with the enable as the remedy, nothing written.
2310-
if (request.packageId === undefined && rollbackPackageId === null) {
2310+
//
2311+
// [#37851 ruling A] Whether or not a package-unbound row is stored
2312+
// now: with none stored but its history kept, the restore inserted
2313+
// the package-unbound row again, the same customization, so it is
2314+
// refused with the same remedy. And a rollback naming no package that
2315+
// restores a disabled package's OWN row (the binding read above names
2316+
// it) wrote that row, which the next enable served, while the bare
2317+
// save of the item is refused: it is asked the judgment's first state
2318+
// ({@link disabledHoldersOnlyRefusal}, the `?package=` remedy, which
2319+
// the rollback naming that package reaches).
2320+
if (request.packageId === undefined) {
23112321
const active = await host.packagelessAddress(singularType, request.name, member, 'active');
2312-
if (active.unbound) {
2313-
const holderRefusal = packagelessHolderRefusal(
2314-
host, 'rollback', request.type, singularType, request.name, member,
2315-
{ candidates: active.candidates, unbound: true }, 'disabled-holders',
2316-
);
2317-
if (holderRefusal) throw holderRefusal;
2318-
}
2322+
const holderRefusal = packagelessHolderRefusal(
2323+
host, 'rollback', request.type, singularType, request.name, member,
2324+
{
2325+
candidates: [...new Set([...active.candidates, ...(rollbackPackageId !== null ? [rollbackPackageId] : [])])],
2326+
unbound: rollbackPackageId === null,
2327+
},
2328+
'disabled-holders',
2329+
);
2330+
if (holderRefusal) throw holderRefusal;
23192331
}
23202332
// [ADR-0146 D2] A rollback of the base's paired `.custom` row is the
23212333
// pair's declared override, as its save is: it edits no managed item,

‎packages/metadata-protocol/src/protocol-save.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3535,8 +3535,12 @@ export async function packagelessRowHeldBaseDraftAddress(
35353535
* whether or not a row is stored at the address (over none, the delete and
35363536
* the discard are refused too, not answered the no-op receipt).
35373537
* [ADR-0150 D3, the 2026-11-26 note] The bare per-item publish and the bare
3538-
* per-item rollback ask the second state only (`arms: 'disabled-holders'`),
3539-
* after the ADR-0146 D11 close, so they write nothing a disabled holder hides.
3538+
* per-item rollback ask the disabled-holders judgment only
3539+
* (`arms: 'disabled-holders'`), after the ADR-0146 D11 close, so they write
3540+
* nothing a disabled holder hides: [#37851 ruling A] its first state where
3541+
* they write a package's own row (the publish of its own draft, the rollback
3542+
* of its own row), its second where they write the package-unbound row,
3543+
* stored or not.
35403544
* Asked after {@link servedPackagelessSaveAddress} (a name an enabled and a
35413545
* disabled package both hold) and after the rows' own refusal (two or more
35423546
* bindings), so neither answer moves.

‎packages/objectql/src/disabled-holder-packageless-row-doors.test.ts‎

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,22 +305,46 @@ describe('[ADR-0150 D3, the 2026-11-26 note] the per-item publish and the rollba
305305
expect(await subjectAt(protocol, 'fr-FR')).toBe('DRAFT fr');
306306
});
307307

308-
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 () => {
308+
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) => {
309309
const stores: Stores = new Map();
310310
const { engine, protocol } = await boot(stores);
311-
await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'SAVED fr') } as any);
311+
if (withRow) await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'SAVED fr') } as any);
312312
await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'PKG DRAFT fr'), mode: 'draft', packageId: PKG } as any);
313313
engine.registry.disablePackage(PKG);
314314
const packageless = () => JSON.stringify(Array.from(stores.get('sys_metadata')?.values() ?? [])
315315
.filter((r) => r.name === NAME && (r.package_id ?? null) === null).map((r) => [r.state, r.bundle_member ?? null, r.metadata, r.version]));
316-
const before = packageless();
317-
// The draft address is the package's own draft, promoted into the
318-
// package's own row: no package-less row is read or written, so the
319-
// judgment is not asked (the answer `main` 56c9cae6 gives).
320-
expect(await protocol.publishMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any)).toMatchObject({ success: true });
321-
expect(packageless()).toBe(before);
316+
const before = storedRows(stores);
317+
const packagelessBefore = packageless();
318+
// FROM (`main` 73d5e347): `success: true`, the draft promoted into the
319+
// disabled package's active row, which the next enable serves.
320+
// TO (#37851 ruling A): refused as the bare save of the item is, with
321+
// the `?package=` remedy (the promotion addresses the package's own
322+
// draft and row, which the publish naming the package reaches), and
323+
// nothing is written.
324+
const refused = await refusalOf(protocol.publishMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any));
325+
expect([refused?.status, refused?.code], String(refused?.message ?? 'no refusal')).toEqual([409, 'RESOURCE_CONFLICT']);
326+
expect(String(refused?.message).startsWith('Name the package this publish is for, then send it again')).toBe(true);
327+
expect(String(refused?.message)).not.toContain(PKG);
328+
expect(storedRows(stores)).toBe(before);
329+
// CONTROL — the remedy: the publish naming the package promotes the
330+
// draft into the package's own row, as on `main`, and leaves the
331+
// package-less row byte-identical.
332+
expect(await protocol.publishMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR', packageId: PKG } as any)).toMatchObject({ success: true });
333+
expect(packageless()).toBe(packagelessBefore);
322334
expect(Array.from(stores.get('sys_metadata')?.values() ?? [])
323-
.filter((r) => r.name === NAME && r.state === 'active').map((r) => r.package_id ?? null).sort()).toEqual([PKG, null].sort());
335+
.filter((r) => r.name === NAME && r.state === 'active').map((r) => r.package_id ?? null).sort())
336+
.toEqual((withRow ? [PKG, null] : [PKG]).sort());
337+
});
338+
339+
it('publish, the package\'s own draft, re-enabled: the bare publish promotes it as on `main`', async () => {
340+
const stores: Stores = new Map();
341+
const { engine, protocol } = await boot(stores);
342+
await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'PKG DRAFT fr'), mode: 'draft', packageId: PKG } as any);
343+
engine.registry.disablePackage(PKG);
344+
expect((await refusalOf(protocol.publishMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any)))?.status).toBe(409);
345+
engine.registry.enablePackage(PKG);
346+
expect(await protocol.publishMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any)).toMatchObject({ success: true });
347+
expect(await subjectAt(protocol, 'fr-FR')).toBe('PKG DRAFT fr');
324348
});
325349

326350
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
358382
.toMatchObject({ success: true, restoredFromVersion: first });
359383
expect(await subjectAt(protocol, 'fr-FR')).toBe('SAVED fr 1');
360384
});
385+
386+
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 () => {
387+
const stores: Stores = new Map();
388+
const { engine, protocol } = await boot(stores);
389+
await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'SAVED fr 1') } as any);
390+
await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'SAVED fr 2') } as any);
391+
const events = (await protocol.historyMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any)).events;
392+
const first = Math.min(...events.map((e: any) => e.version as number));
393+
await protocol.deleteMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR' } as any);
394+
expect(packagelessRows(stores)).toEqual([]);
395+
engine.registry.disablePackage(PKG);
396+
const before = storedRows(stores);
397+
// FROM (`main` 73d5e347): `success: true`, a new package-unbound
398+
// active row inserted with the first version's body, which the next
399+
// enable serves. TO (#37851 ruling A): refused, the enable as the
400+
// remedy (the restore writes the package-unbound row, the disabled
401+
// holder's customization, which naming the package does not reach),
402+
// and no row is inserted.
403+
const refused = await refusalOf(protocol.rollbackMetaItem({ type: 'email_template', name: NAME, toVersion: first, member: 'fr-FR' } as any));
404+
expect([refused?.status, refused?.code], String(refused?.message ?? 'no refusal')).toEqual([409, 'RESOURCE_CONFLICT']);
405+
expect(String(refused?.message).startsWith('Enable the package that holds email_template ')).toBe(true);
406+
expect(String(refused?.message)).not.toContain(PKG);
407+
expect(storedRows(stores)).toBe(before);
408+
// CONTROL — re-enabled: nothing is served at the member, and the same rollback restores the version.
409+
engine.registry.enablePackage(PKG);
410+
expect(await subjectAt(protocol, 'fr-FR')).toBeUndefined();
411+
expect(await protocol.rollbackMetaItem({ type: 'email_template', name: NAME, toVersion: first, member: 'fr-FR' } as any))
412+
.toMatchObject({ success: true, restoredFromVersion: first });
413+
expect(await subjectAt(protocol, 'fr-FR')).toBe('SAVED fr 1');
414+
});
415+
416+
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 () => {
417+
const stores: Stores = new Map();
418+
const { engine, protocol } = await boot(stores);
419+
await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'PKG fr 1'), packageId: PKG } as any);
420+
await protocol.saveMetaItem({ type: 'email_template', name: NAME, item: template('fr-FR', 'PKG fr 2'), packageId: PKG } as any);
421+
const events = (await protocol.historyMetaItem({ type: 'email_template', name: NAME, member: 'fr-FR', packageId: PKG } as any)).events;
422+
expect(events).toHaveLength(2);
423+
const first = Math.min(...events.map((e: any) => e.version as number));
424+
engine.registry.disablePackage(PKG);
425+
const before = storedRows(stores);
426+
const refused = await refusalOf(protocol.rollbackMetaItem({ type: 'email_template', name: NAME, toVersion: first, member: 'fr-FR' } as any));
427+
expect([refused?.status, refused?.code], String(refused?.message ?? 'no refusal')).toEqual([409, 'RESOURCE_CONFLICT']);
428+
expect(String(refused?.message).startsWith('Name the package this rollback is for, then send it again')).toBe(true);
429+
expect(String(refused?.message)).not.toContain(PKG);
430+
expect(storedRows(stores)).toBe(before);
431+
// CONTROL — the remedy: the rollback naming the package restores the package's row, as on `main`.
432+
expect(await protocol.rollbackMetaItem({ type: 'email_template', name: NAME, toVersion: first, member: 'fr-FR', packageId: PKG } as any))
433+
.toMatchObject({ success: true, restoredFromVersion: first });
434+
engine.registry.enablePackage(PKG);
435+
expect(await subjectAt(protocol, 'fr-FR')).toBe('PKG fr 1');
436+
});
361437
});

0 commit comments

Comments
 (0)