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/37111-stored-forms-booted-pair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/metadata-protocol': patch
---

fix(metadata-protocol): the stored-form census reads a `.custom` pair held as booted code as a pair (ADR-0159 D7)

Clause-②: no
Metadata-protocol: none

A paired customization package registered as code is read-only, so the census read it at a read-only package's address and asked the pair door for a pair of it, which a pair never has: the pair's own old-shape form held the upgrade with that refusal. The census now reads the pair by what its package is. The pair's own old-shape row moves into the pair's own `form` row, as it does in a pair the door created, and a stored `form` row already there is kept, whether or not the pair's code ships the form's name; where the pair ships it as a sealed `form` item, the store's seal is the hold.
2 changes: 1 addition & 1 deletion content/docs/deployment/stored-forms-upgrade.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ package of your own, or the environment itself when no package ships it.
| Outcome | What the upgrade does |
|---|---|
| **kept** | The form is already stored as a form. The rows the server serves behind it at that package fold into it. |
| **moves** | The row moves to a form row, with its body as written: into the package's paired `.custom` package as a declared override for a read-only package, into the package itself for a writable one, or into the environment. An override already stored in a `.custom` package keeps its package and the version it is based on. A row bound to a read-only package that ships no form of that name, or an override of a package that ships none, moves into that package's `.custom` package as a form of its own, with no override declared; its public address answers as it does today. Where the server today serves such a row at one other package's address, it moves as a row of that package does, into that package's `.custom` package as a declared override. The rows the server serves behind the moved row at that package fold into it. |
| **moves** | The row moves to a form row, with its body as written: into the package's paired `.custom` package as a declared override for a read-only package, into the package itself for a writable one, or into the environment. An override already stored in a `.custom` package keeps its package and the version it is based on. A row bound to a read-only package that ships no form of that name, or an override of a package that ships none, moves into that package's `.custom` package as a form of its own, with no override declared; its public address answers as it does today. A row of a `.custom` package that the deployment holds as code stays in that package as its own form, whether or not the package ships that name. Where the server today serves such a row at one other package's address, it moves as a row of that package does, into that package's `.custom` package as a declared override. The rows the server serves behind the moved row at that package fold into it. |
| **will be removed** | The row is an internal record form: a create or edit form with no public link that no action opens, over nothing that has a link. New and Edit follow the object's field groups instead, and the report says whether the object declares any. A row bound to no package is read at every package that ships its form: it is removed only when it is an internal record form at each of them, and moves at each of them otherwise. An older row behind the removed one goes with it, unless another package serves that row: the report then names it as not removed, with what happens to it there. |
| **left in place** | Nothing moves. The row served for the name carries no form (a list stored over it, alone or with older form rows behind it), or an internal record form is served ahead of a row with a public link and is not removed because of it. Every row of the name stays as stored, and the address keeps answering as it does today. Where another package serves that row with a public link and would move it, the row holds the upgrade at every one of those packages instead: both rows stay. Both rows stay as stored at every other package too: where either stands behind a row another package would move or remove, that move or removal holds the upgrade instead of folding or removing it. When the row served is one whose form content cannot be read, the form waits on that row, which holds the upgrade (below). A form no door serves today is left in place by the upgrade too, whatever package its row is bound to: the server serves no form of that name at the address the report names, so nothing of it moves, its rows stay as stored there, and the address keeps answering as it does today. A form that is switched off is not one of these: the server serves it closed, and it moves with its switch. |
| **holds the upgrade** | The row cannot be moved. The report repeats the reason and the action. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,64 @@ describe('[ADR-0159 D7] planStoredForms — one outcome per form and address', (
});
}

describe('③ a pair held as booted code: the pair\'s own item is read by what its package is, not by the address kind', () => {
const booted = { ships: {}, isWritable: (pkg: string) => pkg === WORKSPACE };
it('its old-shape row moves into the pair\'s own `form` row, and the pair door is not asked for a pair of the pair (ablate: read the pair from the address kind)', () => {
const asked: string[] = [];
const census = planStoredForms(input([viewFormRow(PAIR, { enabled: true })], {
...booted,
pairFix: (base) => { asked.push(base); return { ok: false, cause: 'app_author', refusal: 'a pair has no pair of its own' }; },
}));
expect(census.forms.map((f) => [f.address, f.outcome, destinationOf(f)])).toEqual([
[{ kind: 'base', packageId: PAIR }, 'move', { kind: 'pair_form', base: BASE, pair: PAIR }],
]);
expect(asked).toEqual([]);
expect(census.precheck).toMatchObject({ canSwitch: true, holds: [] });
});
it('its stored `form` row is kept where it stands', () => {
const census = planStoredForms(input([formRow(PAIR, { enabled: true })], booted));
expect(census.forms.map((f) => [f.address, f.outcome, destinationOf(f)])).toEqual([
[{ kind: 'base', packageId: PAIR }, 'keep', { kind: 'pair_form', base: BASE, pair: PAIR }],
]);
});
describe('where the pair\'s code ships the name itself (an old-shape form among its items), its own row takes the same destination (ablate: the pair read from the address kind where the pair ships the name)', () => {
// The ensure door refuses a pair of a pair, as `storedFormPairFix` does.
const refuses = (): ReturnType<StoredFormPlanInput['pairFix']> => ({ ok: false, cause: 'app_author', refusal: 'a pair has no pair of its own' });
const ownShips = { ...booted, pairFix: refuses, ships: { [NAME]: [{ packageId: PAIR, writable: false, form: { name: NAME, object: OBJECT, ...sharing(true) } }] } };
it('its old-shape row moves into the pair\'s own `form` row, and the pair door is not asked for a pair of the pair', () => {
const asked: string[] = [];
const census = planStoredForms(input([viewFormRow(PAIR, { enabled: true })], {
...ownShips,
pairFix: (base) => { asked.push(base); return refuses(); },
}));
expect(census.forms.map((f) => [f.address, f.outcome, destinationOf(f)])).toEqual([
[{ kind: 'base', packageId: PAIR }, 'move', { kind: 'pair_form', base: BASE, pair: PAIR }],
]);
expect(asked).toEqual([]);
expect(census.precheck).toMatchObject({ canSwitch: true, holds: [] });
});
it('its stored `form` row is kept where it stands', () => {
const census = planStoredForms(input([formRow(PAIR, { enabled: true })], ownShips));
expect(census.forms.map((f) => [f.address, f.outcome, destinationOf(f)])).toEqual([
[{ kind: 'base', packageId: PAIR }, 'keep', { kind: 'pair_form', base: BASE, pair: PAIR }],
]);
});
it('where the pair ships the name as a sealed `form` item, the hold is the store\'s seal, naming the pair, not the pair door\'s refusal', () => {
const census = planStoredForms(input([viewFormRow(PAIR, { enabled: true })], { ...ownShips, sealedFormShippers: (name) => (name === NAME ? [PAIR] : []) }));
expect(census.forms.map((f) => [f.address, f.outcome])).toEqual([[{ kind: 'base', packageId: PAIR }, 'hold']]);
expect(census.precheck.holds[0]!.refusal).toContain('sealed');
expect(census.precheck.holds[0]!.refusal).toContain(`'${PAIR}'`);
});
});
it('CONTROL: a read-only package that is no pair still moves into its own pair, which the pair door names', () => {
const census = planStoredForms(input([viewFormRow(OTHER, { enabled: true })], {
...booted,
pairFix: (base) => ({ ok: true, pair: `${base}.custom`, basedOn: '2.0.0' }),
}));
expect(census.forms.map((f) => [f.outcome, destinationOf(f)])).toEqual([['move', { kind: 'pair_form', base: OTHER, pair: `${OTHER}.custom` }]]);
});
});

describe('a form no door serves today is left in place by the upgrade, whatever package its row is bound to (ablate: the census read of the form served today, at the address each plan is made at)', () => {
const unservedAt = (at: string | undefined) => (name: string, packageId: string | undefined) => !(name === NAME && packageId === at);
const shapes: readonly [string, StoredFormPlace, Parameters<typeof input>[1] & {}, StoredFormAddress][] = [
Expand Down
20 changes: 20 additions & 0 deletions packages/metadata-protocol/src/protocol-stored-form-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,8 @@ export function planStoredForms(input: StoredFormPlanInput): StoredFormCensus {
: destinationOf(address, input);
const atDestination = first!.place.type === 'form' && (
standsIn !== undefined
// The pair's own `form` row, in a pair held as booted code (③).
|| (destination.kind === 'pair_form' && first!.overrideOf === undefined && first!.place.packageId === destination.pair)
|| (address.kind === 'base'
? first!.overrideOf === address.packageId
: address.kind === 'package'
Expand Down Expand Up @@ -1470,11 +1472,27 @@ function holdOf(fix: Extract<PairFixReading, { ok: false }>): DestinationReading
function destinationOf(address: StoredFormAddress, input: Pick<StoredFormPlanInput, 'pairFix'>): DestinationReading {
if (address.kind === 'package') return { kind: 'package_form', packageId: address.packageId };
if (address.kind === 'environment') return { kind: 'environment_form' };
// A pair held as booted code that ships the name itself: the row read at
// it is the pair's own, whatever the pair ships (③).
const ownForm = bootedPairForm(address.packageId);
if (ownForm !== undefined) return ownForm;
const fix = input.pairFix(address.packageId);
if (!fix.ok) return holdOf(fix);
return { kind: 'pair_override', base: address.packageId, pair: fix.pair, basedOn: fix.basedOn };
}

/**
* (③) A pair held as booted code is read-only, so it is read at a `base`
* address; the row read there is still the pair's own, and its destination is
* the pair's own `form` row, whether or not the pair's code ships the name.
* The pair is read by what its package is, not by the address kind, and the
* pair door is never asked for a pair of a pair (ADR-0146 D3).
*/
function bootedPairForm(packageId: string): DestinationReading | undefined {
const base = customizationBasePackageId(packageId);
return base === null ? undefined : { kind: 'pair_form', base, pair: packageId };
}

/**
* [maintainer ruling 7250977204] The pair's own `form` item, for a row bound
* to a package that ships no form of the name: a row bound to the read-only
Expand All @@ -1491,6 +1509,8 @@ function pairFormDestination(
): DestinationReading {
if (ownPair !== undefined) return { kind: 'pair_form', base, pair: ownPair };
if (address.kind === 'package') return { kind: 'pair_form', base, pair: address.packageId };
const ownForm = address.kind === 'base' && address.packageId === base ? bootedPairForm(base) : undefined;
if (ownForm !== undefined) return ownForm;
const fix = input.pairFix(base);
// [N14] The pair's own item declares no `basedOn`: a base that records no version holds no such move.
if (!fix.ok) return fix.pairWithoutBasedOn !== undefined ? { kind: 'pair_form', base, pair: fix.pairWithoutBasedOn } : holdOf(fix);
Expand Down
68 changes: 68 additions & 0 deletions packages/rest/src/public-form-two-type-withdrawal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,74 @@ describe('[ADR-0159 D7] the stored-form ceremony\'s --apply through both doors',
});
}

it('③ a pair held as booted code: its own old-shape row moves into the pair\'s own `form` row, the pair door is not asked, and both doors answer the same before and after (ablate: read the pair from the address kind)', async () => {
const b = await booted({});
b.engine.registerApp({ id: PAIR, name: 'forms37086custom', version: '1.0.0', namespace: 'ftt_custom', dependencies: { [BASE]: '^1.0.0' } } as any);
await b.engine.syncSchemas();
await b.seedRow('view', NAME, PAIR, viewItem(true));
const doors = async () => [answered(await b.get()), answered(await b.post())];
const answers = await doors();
expect(answers[0]![0]).toBe(200);
const result = await apply(b);
expect(result.census.forms.filter((f: any) => f.form === NAME).map((f: any) => [f.address, f.outcome, f.destination])).toEqual([
[{ kind: 'base', packageId: PAIR }, 'move', { kind: 'pair_form', base: BASE, pair: PAIR }],
]);
expect(result).toMatchObject({ applied: true, pairsEnsured: [] });
expect(result.written.map((w: any) => [w.row.type, w.row.packageId])).toEqual([['form', PAIR]]);
expect(await activeBodies(b, 'form', NAME, PAIR)).toEqual([expect.not.objectContaining({ overrides: expect.anything() })]);
expect(await rawRows(b, 'view', NAME, PAIR)).toEqual([]);
expect(await doors()).toEqual(answers);
});

it('③ a pair held as booted code that ships the name itself: its own old-shape row over the pair\'s own form moves into the pair\'s own `form` row, the pair door is not asked, and both doors answer the same before and after (ablate: the pair read from the address kind where the pair ships the name)', async () => {
const b = await booted({});
b.engine.registerApp({ id: PAIR, name: 'forms37086custom', version: '1.0.0', namespace: 'ftt_custom', dependencies: { [BASE]: '^1.0.0' }, views: [container(true)] } as any);
await b.engine.syncSchemas();
// The pair's stored row withdraws the form its own code ships open.
await b.seedRow('view', NAME, PAIR, viewItem(false));
const doors = async () => [answered(await b.get()), answered(await b.post())];
const answers = await doors();
expect(answers[0]![0]).not.toBe(200);
const result = await apply(b);
expect(result.census.forms.filter((f: any) => f.form === NAME).map((f: any) => [f.address, f.outcome, f.destination])).toEqual([
[{ kind: 'base', packageId: PAIR }, 'move', { kind: 'pair_form', base: BASE, pair: PAIR }],
]);
expect(result).toMatchObject({ applied: true, pairsEnsured: [] });
expect(result.written.map((w: any) => [w.row.type, w.row.packageId])).toEqual([['form', PAIR]]);
expect(await activeBodies(b, 'form', NAME, PAIR)).toEqual([expect.not.objectContaining({ overrides: expect.anything() })]);
expect(await rawRows(b, 'view', NAME, PAIR)).toEqual([]);
expect(await doors()).toEqual(answers);
});

it('step 7 of ruling record 7265816895, one slot, one row, on a store that enforces it: the store refuses a second active row in a pair\'s slot; with the pair\'s own `form` row beside a row planned into that pair, the census holds both, --apply writes nothing, and the slot keeps its one row byte-equal (ablate: the hold of a pair slot two plans claim)', async () => {
const b = await booted({});
await (b.protocol as any).ensureOverlayIndex();
await b.install(PAIR);
await b.seedRow('form', NAME, PAIR, formItem(true));
const now = new Date().toISOString();
await expect(b.engine.insert('sys_metadata', {
id: 'second_in_slot', type: 'form', name: NAME, package_id: PAIR, state: 'active', metadata: JSON.stringify(formItem(false)),
checksum: hashSpec(formItem(false), 'form'), version: 1, created_at: now, updated_at: now,
}, { context: { isSystem: true } })).rejects.toThrow(/unique/i);
await b.seedRow('view', NAME, BASE, viewItem(false));
const slot = await rawRows(b, 'form', NAME, PAIR);
expect(slot).toHaveLength(1);
const before = await allRows(b);
const doors = async () => [answered(await b.get()), answered(await b.post())];
const answers = await doors();
const result = await apply(b);
const plans = result.census.forms.filter((f: any) => f.form === NAME).map((f: any) => [f.address, f.outcome, f.cause ?? null]);
expect(plans).toHaveLength(2);
expect(plans).toEqual(expect.arrayContaining([
[{ kind: 'base', packageId: BASE }, 'hold', 'app_author'],
[{ kind: 'package', packageId: PAIR }, 'hold', 'app_author'],
]));
expect(result).toMatchObject({ applied: false, written: [], removed: [], rowsChanged: [], pairsEnsured: [] });
expect(await rawRows(b, 'form', NAME, PAIR)).toEqual(slot);
expect(await allRows(b)).toBe(before);
expect(await doors()).toEqual(answers);
});

describe('on a database that cannot roll back a transaction, --apply is refused before anything is written', () => {
const bootedNoRollBack = async (ships: { forms?: unknown[]; views?: unknown[] }): Promise<Booted> => {
const b = await boot(ships, { canRollBack: false });
Expand Down
Loading