Skip to content

Commit 9e4773d

Browse files
committed
fix(metadata-protocol)!: a commit revert restoring a row bound to the read-only base is refused per item, naming the pair
revertCommit's restore limb (and rollbackToPackageCommit through it) now asks the named-base close on the binding the restore writes, as rollbackMetaItem does, with the same rollback sentence. The item lands in failed[] (NOT_OVERRIDABLE) with nothing written; the soft-remove limb stays open. Claude-Session: https://claude.ai/code/session_01ADHkmTKKCrTrtA7H6oSj28 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7f277a8 commit 9e4773d

5 files changed

Lines changed: 245 additions & 12 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol)!: a commit revert or package rollback that would restore a row bound to an installed read-only package onto its view, dashboard, report, translation or email template is refused per item, naming the base's `.custom` pair
6+
7+
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 row bound to an installed read-only package (`<base>`) itself, on an item of the five overlay types that package ships, where the customization can be written into the base's paired `<base>.custom` instead; they rewrote that row before. The per-item rollback of the same row has refused it since `named-base-overlay-write-closed`.
8+
9+
Metadata-protocol: none
10+
11+
Skills-docs: none needed — `skills/objectstack-platform/SKILL.md` places every customization of an installed base in its paired `.custom`, declaring `overrides`, and says nothing about reverting a commit recorded against the base itself; nothing it says becomes false.
12+
13+
<!-- 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). This change closes the commit doors' restore onto a row bound to the read-only base, the third write that still landed such a row after the save, publish and per-item rollback naming the base were closed, onto the same TO. No stored row is rewritten or moved, so `objectstack migrate meta` has nothing new to do. The entry's surface names the package-less write only; widening its text is a `packages/spec` edit this change does not make. -->
14+
15+
**BREAKING** write narrowing at the commit doors (`@objectstack/metadata-protocol`), shipped as `patch` (`Metadata-protocol: none`).
16+
17+
### Migration: FROM → TO
18+
19+
FROM, undoing a commit that the installed package `com.acme.crm` recorded before the write naming it was closed (a customization published into the package itself), where the commit edited the customization:
20+
21+
```http
22+
POST /api/v1/packages/com.acme.crm/commits/cmt_123/revert
23+
```
24+
25+
It now answers `200` with `success: false`, and the item in `failed[]` with `code: NOT_OVERRIDABLE` and the sentence the per-item rollback gives; nothing is written. TO, write the version you want back into the base's paired `.custom`, declaring what it overrides (the pair's declared override is served over the row bound to the base):
26+
27+
```http
28+
PUT /api/v1/meta/view/account_list?package=com.acme.crm.custom
29+
{ "name": "account_list", "label": "My accounts", "overrides": { "package": "com.acme.crm", "basedOn": "1.4.0" } }
30+
```
31+
32+
Or remove the row bound to the base (`DELETE /api/v1/meta/view/account_list?package=com.acme.crm`) to serve the package's own document again.
33+
34+
- **Now refused, per item.** The restore of a commit item into a row bound to the read-only base itself, of a `view`, `dashboard`, `report`, `translation` or `email_template` that the base ships, where the pair can be ensured (the base has a namespace and a SemVer version) and the override write gate admits the declared body into it. The commit's other items still revert, and the revert is still recorded. `POST /api/v1/packages/<base>/rollback` reports each refused item in its `failed[]` (`success: false`) and continues through the remaining commits.
35+
- **Still open.** The revert of an item the commit created: it removes the row bound to the base, which writes nothing and is the one way to clear such a row (as a delete naming the base is). Every revert whose restore lands in a row of the pair, a writable package or no package, and every restore the pair could not take (a base whose pair cannot be ensured, a base with no version, an `email_template` locale the base does not ship).

‎packages/metadata-protocol/src/protocol-packaged-base-refusal.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,14 @@ function closedOverlayWriteError(message: string): Error {
295295

296296
/**
297297
* The writes {@link namedBaseOverlayWriteRefusal} judges: the three that land
298-
* a row bound to the base. ⛔ Not `delete`: removing a row bound to the base
299-
* writes nothing, and it is the one way to clear such a row stored before the
300-
* close — `os migrate packageless-overlays` reads package-less rows only, so
301-
* it never moves one. The removal serves the base's own document again, or
302-
* the pair's declared override where one exists (it is served over the row).
298+
* a row bound to the base. `rollback` is every restore of a stored version:
299+
* the per-item rollback and [#29390] a commit revert's restore limb (and the
300+
* package rollback through it), one sentence for both. ⛔ Not `delete`:
301+
* removing a row bound to the base writes nothing, and it is the one way to
302+
* clear such a row stored before the close — `os migrate packageless-overlays`
303+
* reads package-less rows only, so it never moves one. The removal serves the
304+
* base's own document again, or the pair's declared override where one exists
305+
* (it is served over the row).
303306
*/
304307
export type NamedBaseWriteOperation = Exclude<PackagelessWriteOperation, 'delete'>;
305308

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

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* Refusals are asserted as the envelope an HTTP boundary answers with
3636
* (`resolveThrownHttpError`).
3737
*/
38-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
38+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3939
import { assertEngineDeleteDispatch, assertEngineFindOnePredicate, assertEngineUpdateDispatch } from '@objectstack/metadata-core';
4040
import { resolveThrownHttpError } from '@objectstack/types';
4141
import { ObjectStackProtocolImplementation } from './protocol.js';
@@ -206,6 +206,7 @@ beforeEach(() => {
206206
afterEach(() => {
207207
ObjectStackProtocolImplementation.resetEnvWritableCache();
208208
resetEnvWritableMetadataTypes();
209+
vi.useRealTimers();
209210
});
210211

211212
describe('a write naming the read-only base itself is closed: its customization lands in the pair (ADR-0146 D1, D11)', () => {
@@ -362,3 +363,115 @@ describe('CONTROLS: the writes the close leaves open, as on main', () => {
362363
expect(rows(VIEW.type, VIEW.name)).toEqual([]);
363364
});
364365
});
366+
367+
/**
368+
* [#29390] The commit doors. A commit the base recorded before the close (a
369+
* draft naming the base, published by `publishPackageDrafts` with the close
370+
* shadowed on this instance only, which is what a build before #28905 did)
371+
* can carry an item that EDITED the row bound to the base. Its revert restores
372+
* a stored version into that row, so it is refused per item, as the per-item
373+
* rollback of the same row is: the restore limb asks the same close on the
374+
* same key (the binding the restore writes) with the same sentence. An item
375+
* the commit CREATED is reverted by removing the row, which writes nothing and
376+
* stays open.
377+
*/
378+
describe('the commit doors: restoring a row bound to the base is closed, removing one stays open (#29390)', () => {
379+
/** Each commit a second apart, so the package rollback's "strictly newer" reads an order. */
380+
let clock = Date.parse('2026-11-02T00:00:00.000Z');
381+
const tick = () => { clock += 1000; vi.setSystemTime(clock); };
382+
383+
/** Publish `item` into `packageId` as one commit; `beforeClose` shadows the close on this instance only. */
384+
async function publishCommit(protocol: any, packageId: string, item: Record<string, unknown>, beforeClose = false): Promise<string> {
385+
tick();
386+
if (beforeClose) protocol.namedBaseOverlayWriteRefusal = () => null;
387+
try {
388+
const saved = await protocol.saveMetaItem({ type: VIEW.type, name: VIEW.name, item, packageId, mode: 'draft' });
389+
expect(saved).toMatchObject({ success: true });
390+
const published = await protocol.publishPackageDrafts({ packageId });
391+
expect(published, JSON.stringify(published)).toMatchObject({ success: true });
392+
expect(typeof published.commitId).toBe('string');
393+
return published.commitId;
394+
} finally {
395+
if (beforeClose) delete protocol.namedBaseOverlayWriteRefusal;
396+
}
397+
}
398+
const intoBaseBeforeClose = (protocol: any, label: string) => publishCommit(protocol, BASE, VIEW.body(label), true);
399+
const declared = (label: string) => ({ ...VIEW.body(label), overrides: { package: BASE, basedOn: BASE_VERSION } });
400+
401+
beforeEach(() => {
402+
vi.useFakeTimers({ toFake: ['Date'] });
403+
});
404+
405+
it('a revert of the base\'s commit that edited its row is refused per item naming the pair, and nothing is written', async () => {
406+
const { protocol, rows } = makeProtocol();
407+
await intoBaseBeforeClose(protocol, 'First');
408+
const edit = await intoBaseBeforeClose(protocol, 'Second');
409+
// The close is live again on this instance: the save naming the base is refused.
410+
expectClosed(await thrown(() => protocol.saveMetaItem({ type: VIEW.type, name: VIEW.name, item: VIEW.body('After'), packageId: BASE })), VIEW.type, VIEW.name, 'save');
411+
412+
tick();
413+
const result = await protocol.revertCommit({ commitId: edit, packageId: BASE, actor: 'admin' });
414+
415+
expect(result).toMatchObject({ success: false, revertedCount: 0, failedCount: 1, reverted: [] });
416+
expect(result.failed).toEqual([expect.objectContaining({ type: VIEW.type, name: VIEW.name, code: 'NOT_OVERRIDABLE' })]);
417+
expectClosedSentence(result.failed[0].error, VIEW.type, VIEW.name, 'rollback');
418+
expect(rows(VIEW.type, VIEW.name)).toEqual([{ package_id: BASE, state: 'active', label: 'Second' }]);
419+
expect((await protocol.getMetaItem({ type: VIEW.type, name: VIEW.name })).item.label).toBe('Second');
420+
});
421+
422+
it('a package rollback through those commits reports each refused item and continues; the row is unchanged', async () => {
423+
const { protocol, rows } = makeProtocol();
424+
const created = await intoBaseBeforeClose(protocol, 'First');
425+
const second = await intoBaseBeforeClose(protocol, 'Second');
426+
const third = await intoBaseBeforeClose(protocol, 'Third');
427+
428+
tick();
429+
const result = await protocol.rollbackToPackageCommit({ commitId: created, packageId: BASE, actor: 'admin' });
430+
431+
expect(result.success).toBe(false);
432+
expect(result.revertedCommits).toEqual([third, second]);
433+
expect(result.failed.map((f: { commitId: string }) => f.commitId)).toEqual([third, second]);
434+
for (const f of result.failed) {
435+
expect(f.error).toContain(`Item '${VIEW.type}/${VIEW.name}' was not reverted: `);
436+
expectClosedSentence(f.error.slice(f.error.indexOf(': ') + 2), VIEW.type, VIEW.name, 'rollback');
437+
}
438+
expect(rows(VIEW.type, VIEW.name)).toEqual([{ package_id: BASE, state: 'active', label: 'Third' }]);
439+
});
440+
441+
it('CONTROL: a revert of the base\'s commit that created its row removes it (the delete stays open); the base is served again', async () => {
442+
const { protocol, rows } = makeProtocol();
443+
const created = await intoBaseBeforeClose(protocol, 'First');
444+
445+
tick();
446+
const result = await protocol.revertCommit({ commitId: created, packageId: BASE, actor: 'admin' });
447+
448+
expect(result).toMatchObject({ success: true, revertedCount: 1, failed: [], reverted: [{ type: VIEW.type, name: VIEW.name, action: 'removed' }] });
449+
expect(rows(VIEW.type, VIEW.name)).toEqual([]);
450+
expect((await protocol.getMetaItem({ type: VIEW.type, name: VIEW.name })).item.label).toBe(PACKAGED);
451+
});
452+
453+
it('CONTROL: a writable package\'s commit of the same item reverts its row in place', async () => {
454+
const { protocol, rows } = makeProtocol();
455+
await publishCommit(protocol, WRITABLE, VIEW.body('First'));
456+
const edit = await publishCommit(protocol, WRITABLE, VIEW.body('Second'));
457+
458+
tick();
459+
const result = await protocol.revertCommit({ commitId: edit, packageId: WRITABLE, actor: 'admin' });
460+
461+
expect(result).toMatchObject({ success: true, revertedCount: 1, failed: [], reverted: [{ type: VIEW.type, name: VIEW.name, action: 'restored' }] });
462+
expect(rows(VIEW.type, VIEW.name)).toEqual([{ package_id: WRITABLE, state: 'active', label: 'First' }]);
463+
});
464+
465+
it('CONTROL: the pair\'s own commit (no row bound to the base) reverts its row in place', async () => {
466+
const { protocol, rows } = makeProtocol();
467+
await publishCommit(protocol, PAIR, declared('PairFirst'));
468+
const edit = await publishCommit(protocol, PAIR, declared('PairSecond'));
469+
470+
tick();
471+
const result = await protocol.revertCommit({ commitId: edit, packageId: PAIR, actor: 'admin' });
472+
473+
expect(result).toMatchObject({ success: true, revertedCount: 1, failed: [], reverted: [{ type: VIEW.type, name: VIEW.name, action: 'restored' }] });
474+
expect(rows(VIEW.type, VIEW.name)).toEqual([{ package_id: PAIR, state: 'active', label: 'PairFirst' }]);
475+
expect((await protocol.getMetaItem({ type: VIEW.type, name: VIEW.name })).item.label).toBe('PairFirst');
476+
});
477+
});

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22083,6 +22083,15 @@ export class ObjectStackProtocolImplementation implements
2208322083
* performs its promise exactly, and the removal is the one action that
2208422084
* reduces the residue. The measurement and the refuse-vs-decline reasoning
2208522085
* are stated at the gate itself.
22086+
*
22087+
* [#29390, ADR-0146 D1, D11] The restore limb asks the #28905 close
22088+
* ({@link namedBaseOverlayWriteRefusal}) on the binding it writes, as
22089+
* {@link rollbackMetaItem} does: an item whose restore would land in a row
22090+
* bound to the read-only base itself — a commit the base recorded before
22091+
* the write naming it closed — goes into `failed[]` (`NOT_OVERRIDABLE`, the
22092+
* rollback sentence naming the base's `.custom` pair) with nothing written,
22093+
* and {@link rollbackToPackageCommit} reports it per item and continues.
22094+
* The soft-remove limb stays open: removing such a row writes nothing.
2208622095
*/
2208722096
async revertCommit(request: {
2208822097
commitId: string;
@@ -22436,6 +22445,20 @@ export class ObjectStackProtocolImplementation implements
2243622445
// the shape that ends in a `catch {}` swallowing a real outage
2243722446
// (#4867). Per ITEM, because a batch mixes bindings.
2243822447
const restorePackageId = await this.resolveOverlayPackageBinding(it.type, it.name, member);
22448+
// [#29390, ADR-0146 D1, D11] A restore writes the row this
22449+
// binding names, so a restore into a row bound to the
22450+
// read-only base itself (a commit recorded before #28905
22451+
// closed the write naming the base) is refused exactly as
22452+
// {@link rollbackMetaItem} refuses it, on the same key and
22453+
// with the same sentence ({@link namedBaseOverlayWriteRefusal}),
22454+
// into `failed[]` with nothing written. The commit's other
22455+
// items still revert. The soft-remove limb above stays open:
22456+
// removing a row bound to the base writes nothing.
22457+
const namedBase = this.namedBaseOverlayWriteRefusal(
22458+
{ type: PLURAL_TO_SINGULAR[it.type] ?? it.type, name: it.name, packageId: restorePackageId, ...memberOption(member) },
22459+
'rollback',
22460+
);
22461+
if (namedBase) throw namedBase;
2243922462
const restored = await repo.restoreVersion(ref, restoreToVersion, {
2244022463
actor,
2244122464
source: 'protocol.revertCommit',

0 commit comments

Comments
 (0)