Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/38753-draft-save-cell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/metadata-protocol': patch
---

fix(metadata-protocol): the draft save naming no package beside a disabled package's rows writes the one enabled holder's draft

Clause-②: no
Metadata-protocol: none

A draft save that names no package, of an item whose stored rows are bound to a disabled package and to the one enabled package that holds the name, now writes that enabled package's draft, as it does when the disabled package is not installed. The disabled package's rows stay as they are. Before, the save was refused `409 RESOURCE_CONFLICT` naming both packages, the disabled one among them, while the read naming no package served the enabled package's item and the publish save wrote its row. The bare delete and draft discard already act at that package's address. Where two or more enabled packages hold the name, the draft save is still refused naming only those packages.
34 changes: 28 additions & 6 deletions packages/metadata-protocol/src/protocol-save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import { overlayMemberValue } from './migrations/overlay-index.js';
import { packagelessContentPackage, shippingPackageIds } from './protocol-environment-rows.js';
import type { StoredOverlayRow } from './item-lock.js';
import { installedManifestsOfEngine } from './installed-manifests.js';
import { soleEnabledRowHolder } from './protocol-enabled-holders.js';
import { packageScopedRefusalOf } from './protocol-meta-item-reads.js';
import { pairsOf } from '@objectstack/metadata-core';
import { BatchRowHealError, canJudgeBatchObjects, isBatchObjectType, readActiveBatchRow, settleBatchObjectRows, undoBatchRowWrite, undoOutcomeForLog, type WrittenBatchRow } from './batch-object-registration.js';
Expand Down Expand Up @@ -946,6 +947,26 @@ export class ProtocolSaveFacet {
followedBase = base;
}
}
// [#38753, ADR-0150 D3/D5, #32354] …or the one ENABLED holder the
// read naming no package counts, where the ambiguous draft address's
// rows are bound to a disabled package beside it
// ({@link soleEnabledRowHolder}): the read serves that holder's item
// and the bare publish save writes its row, so the draft save writes
// its draft, as without the disabled package, and the disabled
// package's rows stay where they are. Followed as the row-held base
// above is, so the two rules below judge the package it inherits.
// FROM (`main` 444dce61): refused `409` naming the disabled package
// and the enabled one.
if (draftAddress?.kind === 'ambiguous') {
const sole = soleEnabledRowHolder(
host, singularType, request.name, itemDiscriminator(singularType, request.item), draftAddress.candidates,
);
if (sole !== undefined) {
request = { ...request, packageId: sole };
draftAddress = undefined;
followedBase = sole;
}
}
// [#34346, ADR-0150 D3/D5] …and an ambiguous draft address whose
// rows are bound to a disabled package too is refused naming the
// holders the read naming no package counts, never the disabled one
Expand Down Expand Up @@ -3643,14 +3664,15 @@ export async function packagelessRowHeldBaseDraftAddress(
* registry without the reads.
*
* [#34346] With two or more ENABLED shippers and a disabled holder, the draft
* save and the delete take their address from the rows, so their refusal of
* rows bound to two or more packages is judged by
* save, the delete and the draft discard take their address from the rows, so
* their refusal of rows bound to two or more packages is judged by
* {@link disabledRowHoldersRefusal}, which never names the disabled package.
*
* Known gap (#38753): with ONE enabled shipper and the rows bound to it and to
* a disabled package, that helper answers `undefined` and the draft save and
* the delete still refuse `409` naming the disabled package, where the read
* serves the enabled shipper and the publish save writes its row.
* [#38753] With ONE enabled holder and the rows bound to it and to a disabled
* package, the draft save, the delete and the draft discard act at that
* holder's address first (`soleEnabledRowHolder`), where the read serves it
* and the publish save writes its row, so none of them reaches that refusal
* or names the disabled package.
*/
export function packagelessHolderRefusal(
host: Pick<ProtocolHost, 'engine' | 'shippedArtifactsOf'>,
Expand Down
41 changes: 38 additions & 3 deletions packages/rest/src/meta-disabled-package-doors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1485,8 +1485,9 @@ describe('[#37915] RestServer: the history naming no package of a name only a di
* and the bare draft discard act at E's address, as without D, and D's rows
* stay byte-unchanged. FROM (`main` 8338d070, measured on this fixture, both
* save orders, D shipping the name in code or not): both refused `409
* RESOURCE_CONFLICT` naming D and E. The bare draft save still refuses
* naming both: its judgment sits in a file this change does not edit.
* RESOURCE_CONFLICT` naming D and E. The bare draft save too writes E's
* draft, as without D; FROM (`main` 444dce61): it refused `409` naming D
* and E.
*/
describe('[#38753] RestServer: the bare delete and draft discard beside a disabled package\'s rows and the one enabled shipper', () => {
const lay = (host: ReturnType<typeof setup>, pkg: string, label: string, state: 'active' | 'draft') => (host.protocol as any).engine.insert('sys_metadata', {
Expand Down Expand Up @@ -1534,7 +1535,31 @@ describe('[#38753] RestServer: the bare delete and draft discard beside a disabl
expect(effects[0].deleted.map((row) => row.split(':').slice(0, 2).join(':'))).toEqual([`active:${OTHER_PKG}`]);
}, 60_000);

it('CONTROL — a second enabled shipper: the bare delete and draft discard still refuse 409 naming the two enabled shippers, never D, and nothing is removed', async () => {
it.each(CELLS)('%s: the bare draft save writes E\'s draft, as without D, never 409 naming D, and D\'s rows stay', async (_label, order, disabledShips) => {
const effects: Array<{ removed: string[]; added: string[] }> = [];
for (const withD of [true, false]) {
const host = await boot(order, withD, disabledShips);
const before = await rowsOf(host);
const saved = await (host.protocol as any).saveMetaItem({
type: 'dashboard', name: 'one_shipper_dash', mode: 'draft',
item: { name: 'one_shipper_dash', label: 'edited draft', widgets: [] },
}).catch((error: any) => ({ refused: `${error?.code}:${error?.status ?? error?.httpStatus}:${error?.message}` }));
expect([withD, saved?.refused], String(saved?.refused)).toEqual([withD, undefined]);
const after = await rowsOf(host);
effects.push({
removed: before.filter((row) => !after.includes(row)),
added: after.filter((row) => !before.includes(row)),
});
// D's rows, both states, byte-unchanged.
expect(after.filter((row) => row.includes(`:${PKG}:`)), 'D\'s rows').toEqual(before.filter((row) => row.includes(`:${PKG}:`)));
}
expect(effects[0], JSON.stringify(effects)).toEqual(effects[1]);
expect(effects[0].removed.map((row) => row.split(':').slice(0, 2).join(':'))).toEqual([`draft:${OTHER_PKG}`]);
expect(effects[0].added.map((row) => row.split(':').slice(0, 2).join(':'))).toEqual([`draft:${OTHER_PKG}`]);
expect(effects[0].added.join('\n')).toContain('edited draft');
}, 60_000);

it('CONTROL — a second enabled shipper: the bare delete, draft discard and draft save still refuse 409 naming the two enabled shippers, never D, and nothing is written', async () => {
const THIRD_PKG = 'app.third_demo';
const host = await boot([PKG, OTHER_PKG], true, true);
host.registry.installPackage({ id: THIRD_PKG, name: THIRD_PKG, version: '1.0.0' } as any, 'code');
Expand All @@ -1547,6 +1572,16 @@ describe('[#38753] RestServer: the bare delete and draft discard beside a disabl
for (const pkg of [OTHER_PKG, THIRD_PKG]) expect(String(refusal?.message)).toContain(pkg);
expect(String(refusal?.message)).not.toContain(PKG);
}
let saveRefusal: any;
try {
await (host.protocol as any).saveMetaItem({
type: 'dashboard', name: 'one_shipper_dash', mode: 'draft',
item: { name: 'one_shipper_dash', label: 'edited draft', widgets: [] },
});
} catch (error) { saveRefusal = error; }
expect([saveRefusal?.code, saveRefusal?.status ?? saveRefusal?.httpStatus], String(saveRefusal?.message)).toEqual(['RESOURCE_CONFLICT', 409]);
for (const pkg of [OTHER_PKG, THIRD_PKG]) expect(String(saveRefusal?.message)).toContain(pkg);
expect(String(saveRefusal?.message)).not.toContain(PKG);
expect(await rowsOf(host)).toEqual(before);
}, 60_000);

Expand Down
Loading