Skip to content

Commit 5f99582

Browse files
fix(metadata-protocol)!: a package commit's plan and revert address the committing package's own row; a deleted row's restore asks the package-less close (#29797)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ86dqPUQ7umCq81TqWVdRR92)_ Fixes #29414 domain:server#5 · os-warren · session_01JQwxbZ5jYNfPGLvPV8LYRe Clause-②: no (narrowing) Metadata-protocol: none Skills-docs: none needed — `skills/objectstack-platform/SKILL.md` already says the package-less save, reset and rollback of a movable row are refused once movable (D11), and places every customization of an installed base in its paired `.custom`; nothing it says becomes false. > **Freeze:** the #27737 freeze (6594835694) lifted when #29788 merged as 339f63d; main 0e4b0fa was merged at 7a6e6cd, clean, with the protocol.ts hunks at their symbols. The later §3b freeze (6599581744) was lifted at 6599690891 before any §3b work began. Head f74094f merges main at c5ddbea, clean. ## 维护者速读 - 改了什么:包提交的撤销计划(`publish-drafts` 记录的 `existedBefore`/`prevVersion`)只读发布包自己的那一行;按提交撤销(`POST /packages/:id/commits/:commitId/revert`,整包回滚经它)的删除与恢复两支都只针对提交所属包自己的行。恢复绑定恒为提交所属包:该包的行已删时 `restoreVersion` 按所述包重建,本门永不写无包行;只读基础包自身的提交由 #29390 的具名基础关闭拒掉。恢复写入基础包的 `.custom` 配对行时,经 `restoreWriteFor`(与逐项回滚共用的同一推导)由覆盖写入闸判定;未声明覆盖的版本逐项拒绝(`NOT_OVERRIDABLE`),不写任何东西。 - 为什么改:实测 main 上,基础包旧行旁边的 `.custom` 配对包首次发布,被记成"编辑了基础行的版本 10";撤销这次提交时去找基础行,被 #29390 的关闭拒掉,配对包的覆盖仍在服务、撤销答 `success:false`。另一路:基础行删除后撤销其编辑提交,会插入一条无包行(#28576 关闭的那种写入)。 - 风险与回滚:只改提交门的寻址与恢复写入判定;删除行后撤销从"静默写无包行"变为按提交所属包重建或逐项拒绝(收窄,故 `Clause-②: no (narrowing)`)。回滚即撤销本 PR。 - 先看:`packages/metadata-protocol/src/protocol.ts` 的 `revertCommit`(`commitPackageId`、`restoreWriteFor`)、`publishPackageDrafts` 计划读、`sys-metadata-repository.ts` 的 `restoreVersion` 新增 `packageId`。 - 两分钟验证:`pnpm --filter @objectstack/metadata-protocol exec vitest run src/protocol.named-base-overlay-write.test.ts`,预期 28 个全过。 - 需要你做的:无,席位落地。 ## What changes - **The plan names the publishing package's row.** `publishPackageDrafts` reads each item's pre-publish active row with `package_id: request.packageId`. Every draft it promotes is listed under that package and promoted into that package's row, so another package's row of the name is not the item's pre-publish state. - **Both revert limbs name the committing package's row.** `revertCommit` reads `commitPackageId` off the commit row and states it on the soft-remove limb's read and delete, and on the restore limb's read and `restoreVersion`. A pair creation commit beside a row bound to its read-only base now removes the pair's row, and the base row is served again. - **The restore binding is always the committing package.** `SysMetadataRepository.restoreVersion` takes `packageId` (a local extension, as on `delete`). When stated, it writes that package's row, and creates it again when it is gone. When omitted, behaviour is unchanged. This door therefore never writes a package-less row. A read-only base's own commit whose row is gone is refused by the #29390 named-base close. - **M1: a restore into the base's paired `.custom` row is judged by the override write gate** through `restoreWriteFor`, the derivation the per-item rollback now shares. A version declaring no override (a legacy plan naming the base row's version) is refused per item with `NOT_OVERRIDABLE`, and nothing is written. - **Spec entry text.** The `packageless-overlay-write-closed` entry names the two commit doors (`POST /api/v1/packages/:id/commits/:commitId/revert` and `POST /api/v1/packages/:id/rollback`). It is a text change only, with no new id or key, per claim amendment 6596154325. - **Fixtures.** Seven suites seeded a package's commit over package-less rows, or served a commit row with no `package_id`, a shape no publish produces. Each now binds its rows to the commit's package, with no assertion changed. The publish audit harness arms its rival write on the second package-scoped read of the name. The objectql `protocol-publish-package-drafts.test.ts` capture-read pins (:159, :209) gain `package_id: 'app.edu'`, the plan read's new scope (52e2569). ## Tests - Red first through the real door (`packages/qa/dogfood/test/package-commit-revert-path-package.dogfood.test.ts`, booted showcase, `origin/main` 7dae3b3): the pair-beside-base case failed on the plan (`items: [{ existedBefore: true, prevVersion: 10 }]`), and the deleted-row case failed (`success: true`, the package-less row written). - Unit (`src/protocol.named-base-overlay-write.test.ts`) 28/28. The new legacy-pair-commit case is refused `NOT_OVERRIDABLE`, and the pair row stays declared and served. Two new gone-row controls restore into the pair's row and into the writable package's row. The deleted-base-row case asserts the named-base rollback sentence. Those 4 fail with `protocol.ts` and `sys-metadata-repository.ts` restored from 55837b7 (4 failed, 24 passed) and pass with the rework. - Dogfood `package-commit-revert-path-package` 12/12. ## Acceptance notes - **`rollbackMetaItem` shares the addressing defect (measured, not fixed here; filed as #29848).** The per-item rollback beside a base-bound row and the pair's override answers `403 NOT_OVERRIDABLE` naming the base row. - **`commitPackageId` is an unchecked read** (`const commitPackageId: string = row.package_id` on an `any` row whose column is `required: false`). No producer or door reaches a package-less commit row: the one writer always stamps it, and both REST doors refuse a row whose package is not the path's. Only an in-process `revertCommit({ commitId })` on a hand-made row could pass `null`. Recorded by the contract review as should-fix S1 and accepted at this landing. ## Verification <details><summary>Local gates (head f74094f, tree identical to af63aa9f)</summary> - Build, plus the full suites of metadata-protocol, objectql, rest, runtime, metadata, service-automation, service-datasource, lint and client: all exit 0 under os-verify-lock. - `pnpm --filter @objectstack/metadata-protocol typecheck`: exit 0. - Spec: `check:generated`, migrations, `check:spec-changes`, `check:upgrade-guide`: exit 0. - `dispatch-gates --commands`: 84 run, 0 NOT MEASURED in the `--ran` reconciliation. - `pnpm lint`: exit 0. - Full dogfood battery on f74094f: Test Files 407 passed, 3 skipped; Tests 3362 passed, 28 skipped; 0 failures (35m03s, os-verify-lock VERDICT command-exit 0). Report addendum on #29414: 6600686902. - CI check-runs on f74094f: 64 in total, 55 success, 9 skipped, 0 failed. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbZ5jYNfPGLvPV8LYRe)_ <!-- signed: domain:server#5 · os-warren · session_01JQwxbZUR3xvHyDPCjNL5P4 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1bb9536 commit 5f99582

14 files changed

Lines changed: 432 additions & 48 deletions
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
'@objectstack/spec': patch
4+
---
5+
6+
fix(metadata-protocol)!: a package commit's revert plan and its revert address the committing package's own row, and a restore into a `.custom` pair's row is judged by the override write gate
7+
8+
Clause-②: no (narrowing) — the commit revert (`POST /api/v1/packages/:id/commits/:commitId/revert`) and the package rollback (`POST /api/v1/packages/:id/rollback`) no longer restore a stored version into a `<base>.custom` pair's row unless the version declares the override the pair's save requires, and no longer restore into another package's row of the name, or into a package-less row, when the committing package's own row was deleted since: they restore into the committing package's row, so a commit of an installed read-only package itself whose row is gone is refused by the close naming the pair. They restored into whichever row of the name the store returned first, or inserted a package-less row, before.
9+
10+
Metadata-protocol: none
11+
12+
Skills-docs: none needed — `skills/objectstack-platform/SKILL.md` places every customization of an installed base in its paired `.custom`, declaring `overrides`, and says a pair row is honoured only when declared; nothing it says becomes false.
13+
14+
<!-- adr-0087: not-required (already-registered packageless-overlay-write-closed) That entry, unreleased and shipping in the same release, already prescribes this change's TO for every customization of an installed package: write it into the base's paired `<base>.custom` with `PUT /api/v1/meta/<type>/<name>?package=<base>.custom` and the `overrides` declaration (its replacement), because the customization lives there (its reason, ADR-0146 D1, D2, D11). Its surface and reason now name the commit doors as further addresses of the rollback it closes (text only, no new id). No stored row is rewritten or moved, so `objectstack migrate meta` has nothing new to do. -->
15+
16+
**BREAKING** write narrowing at the commit doors (`@objectstack/metadata-protocol`), shipped as `patch` (`Metadata-protocol: none`). `@objectstack/spec` carries the text widening of the `packageless-overlay-write-closed` upgrade entry.
17+
18+
The plan a package publish records (`POST /api/v1/packages/:id/publish-drafts`, the commit's `existedBefore` and `prevVersion` per item) now reads the publishing package's own active row, and the revert removes or restores that row only. Before, both read any package's active row of the name: the first publish of a `<base>.custom` pair's declared override beside a row bound to the base (stored before the write naming the base was closed) was recorded as an edit of the base row's version, and its revert addressed the base row and was refused there instead of removing the pair's row. It now removes the pair's row, and the row bound to the base is served again.
19+
20+
A pair commit recorded before this change beside such a row still names the base row's version as the pair's pre-commit state. Its revert now restores into the pair's own row, so the restored body meets the override write gate exactly as the pair's per-item rollback does: the base row's body declares no override, so the item is refused per item (`403 NOT_OVERRIDABLE`, the save door's sentence) and the pair's declared row stays as it is.
21+
22+
### Migration: FROM → TO
23+
24+
FROM, undoing a pair commit recorded before this change beside a row bound to the installed package `com.acme.crm`:
25+
26+
```http
27+
POST /api/v1/packages/com.acme.crm.custom/commits/cmt_123/revert
28+
```
29+
30+
It answers `200` with `success: false`, and the item in `failed[]` with `code: NOT_OVERRIDABLE`; nothing is written. TO, write the version you want into the pair, declaring what it overrides, or remove the pair's row to serve what is under it:
31+
32+
```http
33+
PUT /api/v1/meta/view/account_list?package=com.acme.crm.custom
34+
{ "name": "account_list", "label": "My accounts", "overrides": { "package": "com.acme.crm", "basedOn": "1.4.0" } }
35+
36+
DELETE /api/v1/meta/view/account_list?package=com.acme.crm.custom
37+
```
38+
39+
FROM, undoing a commit of `com.acme.crm` itself (recorded before the write naming it was closed) that edited a customization whose row was deleted since: the restore wrote a package-less row. It now restores into the row bound to `com.acme.crm`, which the close refuses (`NOT_OVERRIDABLE`, the rollback sentence naming the pair); TO, the same `PUT …?package=com.acme.crm.custom` with the `overrides` declaration.
40+
41+
- **Now refused, per item.** A restore into a `<base>.custom` pair's row of a version that does not declare the override the pair's save requires (the override write gate). A restore of a commit of a read-only package itself into its row bound to the package, now also when that row was deleted since (the close naming the pair). The commit's other items still revert, and `POST /api/v1/packages/<id>/rollback` reports each refused item in its `failed[]` and continues.
42+
- **Now restored into the committing package's row.** A commit whose row was deleted since, of a writable package or of the pair (a declared version): the row is created again under that package, never as a package-less row.
43+
- **Still open.** Every restore into a row the committing package holds that the gate admits (a writable package's in place, the pair's declared version in place), and every removal.

‎packages/metadata-protocol/src/protocol.extension-field-suffix.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,15 @@ async function attempt<T>(run: () => Promise<T>): Promise<{ result: T | null; er
306306

307307
afterEach(() => vi.restoreAllMocks());
308308

309-
const commitRow = (items: unknown[]) => ({
309+
/**
310+
* [#29414] `packageId` — the package the commit is recorded for, which a
311+
* revert addresses the rows of; omitted, no `package_id` (the package-less
312+
* rows those cases seed).
313+
*/
314+
const commitRow = (items: unknown[], packageId?: string) => ({
310315
id: 'c1',
311316
commit_id: 'c1',
317+
...(packageId !== undefined ? { package_id: packageId } : {}),
312318
organization_id: null,
313319
operation: 'apply',
314320
message: 'the commit under revert',
@@ -457,7 +463,7 @@ describe('[ADR-0146 D10] the restore doors refuse a stored version carrying a `_
457463
it('revertCommit\'s restore limb reports it in failed[] with the envelope\'s code; nothing is written', async () => {
458464
const h = makeProtocol();
459465
const before = await threeVersionsWithFieldResidueAtV2(h, BOUND);
460-
h.serveCommit(commitRow([{ type: 'object', name: 'probe_ticket', existedBefore: true, prevVersion: 2 }]));
466+
h.serveCommit(commitRow([{ type: 'object', name: 'probe_ticket', existedBefore: true, prevVersion: 2 }], BOUND));
461467
vi.spyOn(console, 'warn').mockImplementation(() => {});
462468

463469
const res = await h.protocol.revertCommit({ commitId: 'c1' });

‎packages/metadata-protocol/src/protocol.item-name-every-door.test.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,15 @@ async function threeVersionsWithResidueAtV2(h: Harness) {
391391
return { historyBefore: h.historyRows.length, activeBefore: JSON.stringify(stored(h, 'dashboard')) };
392392
}
393393

394-
const commitRow = (items: unknown[]) => ({
394+
/**
395+
* [#29414] `packageId` — the package the commit is recorded for, which a
396+
* revert addresses the rows of; omitted, no `package_id` (the package-less
397+
* rows those cases seed).
398+
*/
399+
const commitRow = (items: unknown[], packageId?: string) => ({
395400
id: 'c1',
396401
commit_id: 'c1',
402+
...(packageId !== undefined ? { package_id: packageId } : {}),
397403
organization_id: null,
398404
operation: 'apply',
399405
message: 'the commit under revert',
@@ -794,7 +800,7 @@ describe('[ADR-0086 D3] the restore doors refuse a stored version whose body `pa
794800
it('revertCommit\'s restore limb reports a disagreeing version in failed[] with the envelope\'s code; nothing is written', async () => {
795801
const h = makeProtocol();
796802
const before = await threeSetVersionsWithOwnerResidueAtV2(h, BOUND, OTHER);
797-
h.serveCommit(commitRow([{ type: 'permission', name: 'probe_member', existedBefore: true, prevVersion: 2 }]));
803+
h.serveCommit(commitRow([{ type: 'permission', name: 'probe_member', existedBefore: true, prevVersion: 2 }], BOUND));
798804
vi.spyOn(console, 'warn').mockImplementation(() => {});
799805

800806
const res = await h.protocol.revertCommit({ commitId: 'c1' });
@@ -812,7 +818,7 @@ describe('[ADR-0086 D3] the restore doors refuse a stored version whose body `pa
812818
it('CONTROL: revertCommit\'s restore limb restores a version whose body agrees with the binding', async () => {
813819
const h = makeProtocol();
814820
await threeSetVersionsWithOwnerResidueAtV2(h, BOUND, BOUND);
815-
h.serveCommit(commitRow([{ type: 'permission', name: 'probe_member', existedBefore: true, prevVersion: 2 }]));
821+
h.serveCommit(commitRow([{ type: 'permission', name: 'probe_member', existedBefore: true, prevVersion: 2 }], BOUND));
816822

817823
const res = await h.protocol.revertCommit({ commitId: 'c1' });
818824

‎packages/metadata-protocol/src/protocol.named-base-overlay-write.test.ts‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,4 +476,119 @@ describe('the commit doors: restoring a row bound to the base is closed, removin
476476
expect(rows(VIEW.type, VIEW.name)).toEqual([{ package_id: PAIR, state: 'active', label: 'PairFirst' }]);
477477
expect((await protocol.getMetaItem({ type: VIEW.type, name: VIEW.name })).item.label).toBe('PairFirst');
478478
});
479+
480+
// [#29414] The plan and both revert limbs address the committing package's
481+
// own row. Before, each read any package's active row, so the pair's
482+
// commit beside a row bound to the base addressed the base row.
483+
const planOf = async (protocol: any, packageId: string, commitId: string) =>
484+
((await protocol.listCommits({ packageId })) as Array<{ id: string; items: unknown[] }>).find((c) => c.id === commitId)?.items;
485+
486+
it('[#29414] the pair\'s first commit beside a row bound to the base records a create, and its revert removes the pair row; the base row is served again', async () => {
487+
const { protocol, rows } = makeProtocol();
488+
await intoBaseBeforeClose(protocol, 'BaseRow');
489+
const created = await publishCommit(protocol, PAIR, declared('PairFirst'));
490+
expect(await planOf(protocol, PAIR, created)).toEqual([
491+
expect.objectContaining({ type: VIEW.type, name: VIEW.name, existedBefore: false, prevVersion: null }),
492+
]);
493+
494+
tick();
495+
const result = await protocol.revertCommit({ commitId: created, packageId: PAIR, actor: 'admin' });
496+
497+
expect(result).toMatchObject({ success: true, revertedCount: 1, failed: [], reverted: [{ type: VIEW.type, name: VIEW.name, action: 'removed' }] });
498+
expect(rows(VIEW.type, VIEW.name)).toEqual([{ package_id: BASE, state: 'active', label: 'BaseRow' }]);
499+
expect((await protocol.getMetaItem({ type: VIEW.type, name: VIEW.name })).item.label).toBe('BaseRow');
500+
});
501+
502+
it('[#29414] the pair\'s edit commit beside a row bound to the base restores the pair\'s own row; the base row is untouched', async () => {
503+
const { protocol, rows } = makeProtocol();
504+
await intoBaseBeforeClose(protocol, 'BaseRow');
505+
await publishCommit(protocol, PAIR, declared('PairFirst'));
506+
const edit = await publishCommit(protocol, PAIR, declared('PairSecond'));
507+
expect(await planOf(protocol, PAIR, edit)).toEqual([
508+
expect.objectContaining({ type: VIEW.type, name: VIEW.name, existedBefore: true }),
509+
]);
510+
511+
tick();
512+
const result = await protocol.revertCommit({ commitId: edit, packageId: PAIR, actor: 'admin' });
513+
514+
expect(result).toMatchObject({ success: true, revertedCount: 1, failed: [], reverted: [{ type: VIEW.type, name: VIEW.name, action: 'restored' }] });
515+
expect(rows(VIEW.type, VIEW.name)).toEqual([
516+
{ package_id: BASE, state: 'active', label: 'BaseRow' },
517+
{ package_id: PAIR, state: 'active', label: 'PairFirst' },
518+
]);
519+
});
520+
521+
it('[#29414] a revert of the base\'s edit commit whose row was since deleted restores into the base\'s own row, so the named-base close refuses it; nothing is written', async () => {
522+
const { protocol, rows } = makeProtocol();
523+
await intoBaseBeforeClose(protocol, 'First');
524+
const edit = await intoBaseBeforeClose(protocol, 'Second');
525+
expect(await protocol.deleteMetaItem({ type: VIEW.type, name: VIEW.name, packageId: BASE })).toMatchObject({ success: true });
526+
expect(rows(VIEW.type, VIEW.name)).toEqual([]);
527+
528+
tick();
529+
const result = await protocol.revertCommit({ commitId: edit, packageId: BASE, actor: 'admin' });
530+
531+
expect(result).toMatchObject({ success: false, revertedCount: 0, failedCount: 1, reverted: [] });
532+
expect(result.failed).toEqual([expect.objectContaining({ type: VIEW.type, name: VIEW.name, code: 'NOT_OVERRIDABLE' })]);
533+
expectClosedSentence(result.failed[0].error, VIEW.type, VIEW.name, 'rollback');
534+
expect(rows(VIEW.type, VIEW.name)).toEqual([]);
535+
expect((await protocol.getMetaItem({ type: VIEW.type, name: VIEW.name })).item.label).toBe(PACKAGED);
536+
});
537+
538+
it('[#29414] a pair commit recorded before #29414 beside a row bound to the base names the base row\'s version: its revert is refused by the override write gate, and the pair\'s declared row is unchanged', async () => {
539+
const { protocol, rows } = makeProtocol();
540+
await intoBaseBeforeClose(protocol, 'BaseRow');
541+
const created = await publishCommit(protocol, PAIR, declared('PairFirst'));
542+
// The plan such a commit recorded before #29414: the base row's version, read off any package's row.
543+
const engine = protocol.engine;
544+
const baseVersion = (await engine.findOne('sys_metadata', { where: { type: VIEW.type, name: VIEW.name, state: 'active', package_id: BASE } })).version;
545+
expect(typeof baseVersion).toBe('number');
546+
await engine.update('sys_metadata_commit', {
547+
items: JSON.stringify([{ type: VIEW.type, name: VIEW.name, existedBefore: true, prevVersion: baseVersion }]),
548+
}, { where: { id: created } });
549+
expect(await planOf(protocol, PAIR, created)).toEqual([
550+
expect.objectContaining({ existedBefore: true, prevVersion: baseVersion }),
551+
]);
552+
553+
tick();
554+
const result = await protocol.revertCommit({ commitId: created, packageId: PAIR, actor: 'admin' });
555+
556+
expect(result).toMatchObject({ success: false, revertedCount: 0, failedCount: 1, reverted: [] });
557+
expect(result.failed).toEqual([expect.objectContaining({ type: VIEW.type, name: VIEW.name, code: 'NOT_OVERRIDABLE' })]);
558+
expect(rows(VIEW.type, VIEW.name)).toEqual([
559+
{ package_id: BASE, state: 'active', label: 'BaseRow' },
560+
{ package_id: PAIR, state: 'active', label: 'PairFirst' },
561+
]);
562+
const pairRow = await engine.findOne('sys_metadata', { where: { type: VIEW.type, name: VIEW.name, state: 'active', package_id: PAIR } });
563+
expect(JSON.parse(pairRow.metadata).overrides).toEqual({ package: BASE, basedOn: BASE_VERSION });
564+
expect((await protocol.getMetaItem({ type: VIEW.type, name: VIEW.name })).item.label).toBe('PairFirst');
565+
});
566+
567+
it('[#29414] CONTROL: the pair\'s edit commit whose row was since deleted restores the pair\'s declared row again', async () => {
568+
const { protocol, rows } = makeProtocol();
569+
await publishCommit(protocol, PAIR, declared('PairFirst'));
570+
const edit = await publishCommit(protocol, PAIR, declared('PairSecond'));
571+
expect(await protocol.deleteMetaItem({ type: VIEW.type, name: VIEW.name, packageId: PAIR })).toMatchObject({ success: true });
572+
expect(rows(VIEW.type, VIEW.name)).toEqual([]);
573+
574+
tick();
575+
const result = await protocol.revertCommit({ commitId: edit, packageId: PAIR, actor: 'admin' });
576+
577+
expect(result).toMatchObject({ success: true, revertedCount: 1, failed: [], reverted: [{ type: VIEW.type, name: VIEW.name, action: 'restored' }] });
578+
expect(rows(VIEW.type, VIEW.name)).toEqual([{ package_id: PAIR, state: 'active', label: 'PairFirst' }]);
579+
expect((await protocol.getMetaItem({ type: VIEW.type, name: VIEW.name })).item.label).toBe('PairFirst');
580+
});
581+
582+
it('[#29414] CONTROL: a writable package\'s edit commit whose row was since deleted restores into that package\'s row, never a package-less one', async () => {
583+
const { protocol, rows } = makeProtocol();
584+
await publishCommit(protocol, WRITABLE, VIEW.body('First'));
585+
const edit = await publishCommit(protocol, WRITABLE, VIEW.body('Second'));
586+
expect(await protocol.deleteMetaItem({ type: VIEW.type, name: VIEW.name, packageId: WRITABLE })).toMatchObject({ success: true });
587+
588+
tick();
589+
const result = await protocol.revertCommit({ commitId: edit, packageId: WRITABLE, actor: 'admin' });
590+
591+
expect(result).toMatchObject({ success: true, revertedCount: 1, failed: [], reverted: [{ type: VIEW.type, name: VIEW.name, action: 'restored' }] });
592+
expect(rows(VIEW.type, VIEW.name)).toEqual([{ package_id: WRITABLE, state: 'active', label: 'First' }]);
593+
});
479594
});

‎packages/metadata-protocol/src/protocol.package-publish-audit-rows.test.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ type Harness = {
175175
* between the two reads `promoteDraft` makes (`get` for the parent version,
176176
* then `put`'s own read inside its transaction), which is exactly the
177177
* 409 `METADATA_CONFLICT` the repository raises. Scoped to package-scoped
178-
* active reads so the pre-flight `commitItems` scan — which reads active
179-
* rows WITHOUT a `package_id` — does not consume the one-shot.
178+
* active reads, and armed on the SECOND one of the name: [#29414] the
179+
* pre-flight `commitItems` scan reads the publishing package's active row
180+
* too (it read any package's before), and it runs before the promotion,
181+
* so it must not consume the one-shot.
180182
*/
181183
faults: { failMetadataWriteFor?: string; advanceActiveOnRead?: string };
182184
/** Audit rows that LANDED and were not rolled back. */
@@ -191,6 +193,8 @@ type Harness = {
191193

192194
function makeStubEngine(opts: { failAudit?: boolean } = {}): Harness {
193195
const faults: { failMetadataWriteFor?: string; advanceActiveOnRead?: string } = {};
196+
/** [#29414] The names whose pre-flight plan read has passed (see `advanceActiveOnRead`). */
197+
const planReadPassed = new Set<string>();
194198
const rows = new Map<string, Row>();
195199
const historyRows: HistoryRow[] = [];
196200
const commitRows: any[] = [];
@@ -244,6 +248,10 @@ function makeStubEngine(opts: { failAudit?: boolean } = {}): Harness {
244248
if (faults.advanceActiveOnRead === hit.row.name
245249
&& opts2.where?.state === 'active'
246250
&& 'package_id' in (opts2.where ?? {})) {
251+
if (!planReadPassed.has(hit.row.name)) {
252+
planReadPassed.add(hit.row.name);
253+
return hit.row;
254+
}
247255
delete faults.advanceActiveOnRead;
248256
const asItStood = { ...hit.row };
249257
hit.row.checksum = 'sha256:advanced_by_a_rival';

‎packages/metadata-protocol/src/protocol.recovery-doors-emit-mutation.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ function matchesWhere(r: Row, where: Record<string, unknown>): boolean {
161161
}
162162

163163
/** One `sys_metadata_commit` row in the driver's snake_case wire shape. */
164+
/** [#29414] Recorded for `PKG`, the package the rows below are bound to: a commit's revert addresses its own package's rows. */
164165
const commitRow = (items: unknown[]) => ({
165166
id: 'c1',
166167
commit_id: 'c1',
168+
package_id: PKG,
167169
organization_id: null,
168170
operation: 'apply',
169171
message: 'the commit under revert',

‎packages/metadata-protocol/src/protocol.recovery-doors-mutation-projector.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,11 @@ function matchesWhere(r: Row, where: Record<string, unknown>): boolean {
126126
}
127127

128128
/** One `sys_metadata_commit` row in the driver's snake_case wire shape. */
129+
/** [#29414] Recorded for `PKG`, the package the rows below are bound to: a commit's revert addresses its own package's rows. */
129130
const commitRow = (items: unknown[]) => ({
130131
id: 'c1',
131132
commit_id: 'c1',
133+
package_id: PKG,
132134
organization_id: null,
133135
operation: 'apply',
134136
message: 'the commit under revert',

0 commit comments

Comments
 (0)