From 97c999c62021b13f3282452e2582a95cff9875d5 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 20:23:30 +0000 Subject: [PATCH 1/3] fix(metadata-protocol): a pair held as booted code keeps its own item in itself A `.custom` pair registered as code is read-only, so the census reads it at a `base` address and sent its own item to the pair door, which refuses a pair of a pair. 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, and a stored `form` row there is kept. A rest pin also takes the contested-slot hold onto a store that enforces one active row per slot. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01ADHkmQrGTjSRSiwWSe6AhK --- .../protocol-stored-form-migration.test.ts | 29 +++++++++++ .../src/protocol-stored-form-migration.ts | 8 ++++ .../public-form-two-type-withdrawal.test.ts | 48 +++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/packages/metadata-protocol/src/protocol-stored-form-migration.test.ts b/packages/metadata-protocol/src/protocol-stored-form-migration.test.ts index ca55b0ed9b0..5c589147378 100644 --- a/packages/metadata-protocol/src/protocol-stored-form-migration.test.ts +++ b/packages/metadata-protocol/src/protocol-stored-form-migration.test.ts @@ -327,6 +327,35 @@ 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 }], + ]); + }); + 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[1] & {}, StoredFormAddress][] = [ diff --git a/packages/metadata-protocol/src/protocol-stored-form-migration.ts b/packages/metadata-protocol/src/protocol-stored-form-migration.ts index b3b36c0a543..43b518ea72c 100644 --- a/packages/metadata-protocol/src/protocol-stored-form-migration.ts +++ b/packages/metadata-protocol/src/protocol-stored-form-migration.ts @@ -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' @@ -1491,6 +1493,12 @@ 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 }; + // A pair held as booted code is read-only, so it is read at a `base` + // address: its own item is still the pair's own `form` row. 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). + const pairedBase = address.kind === 'base' && address.packageId === base ? customizationBasePackageId(base) : null; + if (pairedBase !== null) return { kind: 'pair_form', base: pairedBase, pair: base }; 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); diff --git a/packages/rest/src/public-form-two-type-withdrawal.test.ts b/packages/rest/src/public-form-two-type-withdrawal.test.ts index 7ca5961761f..cbf713e084d 100644 --- a/packages/rest/src/public-form-two-type-withdrawal.test.ts +++ b/packages/rest/src/public-form-two-type-withdrawal.test.ts @@ -1419,6 +1419,54 @@ 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('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 => { const b = await boot(ships, { canRollBack: false }); From 5a6cb826667a953ee5e059099d23e6bd94750cfe Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 20:27:05 +0000 Subject: [PATCH 2/3] chore(changeset): the census reads a pair held as booted code as a pair Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01ADHkmQrGTjSRSiwWSe6AhK --- .changeset/37111-stored-forms-booted-pair.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .changeset/37111-stored-forms-booted-pair.md diff --git a/.changeset/37111-stored-forms-booted-pair.md b/.changeset/37111-stored-forms-booted-pair.md new file mode 100644 index 00000000000..aa6254bac52 --- /dev/null +++ b/.changeset/37111-stored-forms-booted-pair.md @@ -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. From 0a1bb19fd87ebef78ae3f1592d457c8d4c8ba89b Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 21:23:42 +0000 Subject: [PATCH 3/3] fix(metadata-protocol): a booted pair that ships the form's name reads its own row as the pair's own A `.custom` pair held as booted code that ships a form's name itself took the other destination route, which still read the pair from the address kind and asked the pair door for a pair of the pair: its own old-shape row held the upgrade, and its stored `form` row read as a hold. Both routes now read the pair by what its package is; the store's seal is still read first. The operator page says a row of such a pair stays in it as its own form. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01ADHkmQrGTjSRSiwWSe6AhK --- .changeset/37111-stored-forms-booted-pair.md | 2 +- .../docs/deployment/stored-forms-upgrade.mdx | 2 +- .../protocol-stored-form-migration.test.ts | 29 +++++++++++++++++++ .../src/protocol-stored-form-migration.ts | 24 +++++++++++---- .../public-form-two-type-withdrawal.test.ts | 20 +++++++++++++ 5 files changed, 69 insertions(+), 8 deletions(-) diff --git a/.changeset/37111-stored-forms-booted-pair.md b/.changeset/37111-stored-forms-booted-pair.md index aa6254bac52..420d204ceb2 100644 --- a/.changeset/37111-stored-forms-booted-pair.md +++ b/.changeset/37111-stored-forms-booted-pair.md @@ -7,4 +7,4 @@ fix(metadata-protocol): the stored-form census reads a `.custom` pair held as bo 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. +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. diff --git a/content/docs/deployment/stored-forms-upgrade.mdx b/content/docs/deployment/stored-forms-upgrade.mdx index 4e3d63b6bd3..ae2ac87caa2 100644 --- a/content/docs/deployment/stored-forms-upgrade.mdx +++ b/content/docs/deployment/stored-forms-upgrade.mdx @@ -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. | diff --git a/packages/metadata-protocol/src/protocol-stored-form-migration.test.ts b/packages/metadata-protocol/src/protocol-stored-form-migration.test.ts index 5c589147378..13b0442f0bf 100644 --- a/packages/metadata-protocol/src/protocol-stored-form-migration.test.ts +++ b/packages/metadata-protocol/src/protocol-stored-form-migration.test.ts @@ -347,6 +347,35 @@ describe('[ADR-0159 D7] planStoredForms — one outcome per form and address', ( [{ 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 => ({ 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, diff --git a/packages/metadata-protocol/src/protocol-stored-form-migration.ts b/packages/metadata-protocol/src/protocol-stored-form-migration.ts index 43b518ea72c..c3a6509f9b9 100644 --- a/packages/metadata-protocol/src/protocol-stored-form-migration.ts +++ b/packages/metadata-protocol/src/protocol-stored-form-migration.ts @@ -1472,11 +1472,27 @@ function holdOf(fix: Extract): DestinationReading function destinationOf(address: StoredFormAddress, input: Pick): 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 @@ -1493,12 +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 }; - // A pair held as booted code is read-only, so it is read at a `base` - // address: its own item is still the pair's own `form` row. 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). - const pairedBase = address.kind === 'base' && address.packageId === base ? customizationBasePackageId(base) : null; - if (pairedBase !== null) return { kind: 'pair_form', base: pairedBase, pair: base }; + 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); diff --git a/packages/rest/src/public-form-two-type-withdrawal.test.ts b/packages/rest/src/public-form-two-type-withdrawal.test.ts index cbf713e084d..4d61f07d49c 100644 --- a/packages/rest/src/public-form-two-type-withdrawal.test.ts +++ b/packages/rest/src/public-form-two-type-withdrawal.test.ts @@ -1438,6 +1438,26 @@ describe('[ADR-0159 D7] the stored-form ceremony\'s --apply through both doors', 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();