From 498ef19ff733bd906f003eda225583a040e2ec1b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 16:20:24 +0000 Subject: [PATCH 01/10] wip: measure the dependent-only member cell Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01J8VVAj3FYe91JCMQZPS88h --- .../metadata-protocol/src/protocol-save.ts | 24 +- ...e-save-dependent-only-member-35524.test.ts | 245 ++++++++++++++++++ 2 files changed, 265 insertions(+), 4 deletions(-) create mode 100644 packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts diff --git a/packages/metadata-protocol/src/protocol-save.ts b/packages/metadata-protocol/src/protocol-save.ts index 14dd06ccaa6..7f5fc3e0277 100644 --- a/packages/metadata-protocol/src/protocol-save.ts +++ b/packages/metadata-protocol/src/protocol-save.ts @@ -869,7 +869,16 @@ export class ProtocolSaveFacet { host, 'save', request.type, writeType, request.name, itemDiscriminator(writeType, request.item), address, ); if (holderRefusal) throw holderRefusal; - if (address.packageId !== null) request = { ...request, packageId: address.packageId }; + // [#35524] …and a named non-canonical member only a dependent + // holds, where the read naming no package takes the row-held + // base's address: the base's row, as the save naming the base + // writes it ({@link packagelessRowHeldBaseAddress}), never the + // dependent's row the read does not serve there. + const base = address.candidates.length === 1 + ? await packagelessRowHeldBaseAddress(host, writeType, request.name, member) + : undefined; + const resolved = base ?? address.packageId; + if (resolved !== null) request = { ...request, packageId: resolved }; } } @@ -901,8 +910,11 @@ export class ProtocolSaveFacet { // draft save's inherited package (the named-base rule and the late // override re-judgment): the base is judged exactly as the save // naming it is, an id no installed package has refused `422`. + // [#35524] …and the same where the active rows at the member are bound + // to the one dependent whose addition the read naming no package does + // not serve (it takes the base's address there): the base's draft. let followedBase: string | undefined; - if (draftAddress?.kind === 'ambiguous') { + if (draftAddress !== undefined && (draftAddress.kind === 'ambiguous' || draftAddress.into !== null)) { const base = await packagelessRowHeldBaseAddress( host, singularType, request.name, itemDiscriminator(singularType, request.item), ); @@ -3285,9 +3297,13 @@ export async function packagelessRowHeldBaseAddress( return undefined; } const address = await host.packagelessAddress(singular, name, member, 'active', activeRows); - if (address.candidates.length < 2 || address.unbound) return undefined; + if (address.candidates.length === 0 || address.unbound) return undefined; const base = await rowHeldBaseAddressOf(host, singular, name, member, activeRows); - return base !== undefined && address.candidates.includes(base) ? base : undefined; + if (base === undefined) return undefined; + // [#35524] Two or more holders at the member: the base is one of them. One + // holder: a dependent's addition the base holds no row of, where the read + // takes the base's address (`rowHeldBaseAddressOf`'s S1-guarded arm). + return address.candidates.includes(base) === address.candidates.length > 1 ? base : undefined; } /** diff --git a/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts b/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts new file mode 100644 index 00000000000..4d1e572ae7b --- /dev/null +++ b/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts @@ -0,0 +1,245 @@ +// MEASURE (temporary): the cell on main before any change. +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; +import { mkdtempSync, rmSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { ObjectKernel, type Plugin, type PluginContext } from '@objectstack/core'; +import { MetadataPlugin } from '@objectstack/metadata'; +import { ObjectQL, ObjectQLPlugin } from '@objectstack/objectql'; +import { SqlDriver } from '@objectstack/driver-sql'; +import { resolveThrownHttpError } from '@objectstack/types'; +import type { EngineQueryOptions } from '@objectstack/spec/data'; +import { HttpDispatcher } from '../http-dispatcher.js'; + +const CALLER = { userId: 'u_dep_member', tenantId: 'org_qa', isSystem: true, positions: [], permissions: [], systemPermissions: ['manage_metadata'] }; +const A = 'com.qa.depmemberbase'; +const D = 'com.qa.depmemberaddon'; +const U = 'com.qa.depmemberother'; +const WA = 'com.qa.authoredbase'; +const WD = 'com.qa.authoredaddon'; +const WU = 'com.qa.authoredother'; + +interface ManifestDoor { register(artifact: unknown): Promise | void } +interface Booted { kernel: ObjectKernel; engine: ObjectQL; root: string; protocol: any } + +const template = (locale: string, subject: string) => ({ label: subject, locale, subject, bodyHtml: `

${subject}

` }); +const appManifest = (id: string, extra: Record = {}) => ({ + id, name: id.split('.').pop(), namespace: id.split('.').pop()!.replace(/[^a-z]/g, ''), version: '1.0.0', type: 'app', objects: [], ...extra, +}); +const MANIFESTS = [ + appManifest(A, { emailTemplates: [{ name: 'shipmail', ...template('en-US', 'base code en') }] }), + appManifest(D, { dependencies: { [A]: '*' } }), + appManifest(U), +]; + +async function boot(file: string): Promise { + const kernel = new ObjectKernel({ logger: { level: 'silent' }, gracefulShutdown: false }); + const root = mkdtempSync(join(tmpdir(), 'os-meta-dep-member-')); + const engine = new ObjectQL(); + engine.registerDriver(new SqlDriver({ client: 'better-sqlite3', connection: { filename: file }, useNullAsDefault: true }) as any, true); + await kernel.use(new MetadataPlugin({ watch: false, rootDir: root })); + await kernel.use(new ObjectQLPlugin({ ql: engine })); + const host: Plugin = { + name: 'qa.dep-member-host', + dependencies: ['com.objectstack.engine.objectql'], + init: async (ctx: PluginContext) => { + for (const manifest of MANIFESTS) await ctx.getService('manifest').register(manifest); + }, + }; + await kernel.use(host); + await kernel.bootstrap(); + await engine.syncSchemas(); + engine.registry.installPackage({ id: WA, name: WA, version: '1.0.0', type: 'app' } as any, 'authored'); + engine.registry.installPackage({ id: WD, name: WD, version: '1.0.0', type: 'app', dependencies: { [WA]: '*' } } as any, 'authored'); + engine.registry.installPackage({ id: WU, name: WU, version: '1.0.0', type: 'app' } as any, 'authored'); + return { kernel, engine, root, protocol: kernel.getService('protocol') }; +} + +const layRow = (engine: ObjectQL, type: string, name: string, packageId: string | null, metadata: Record, state: 'active' | 'draft' = 'active') => engine.insert('sys_metadata', { + type, name, namespace: 'default', package_id: packageId, scope: 'platform', strategy: 'merge', state, version: 1, + ...(type === 'email_template' && metadata.locale !== 'en-US' ? { bundle_member: metadata.locale } : {}), + metadata: JSON.stringify({ name, ...metadata }), +}, { context: { isSystem: true } } as any); +const layCell = async (engine: ObjectQL, name: string, base: string, dependent: string) => { + await layRow(engine, 'email_template', name, base, template('en-US', 'base en')); + await layRow(engine, 'email_template', name, dependent, template('fr-FR', 'addon fr')); +}; +const rowsOf = async (engine: ObjectQL, name: string) => ((await engine.find('sys_metadata', { where: { type: 'email_template', name }, context: { isSystem: true } } satisfies EngineQueryOptions)) as any[]) + .map((row) => { + const body = JSON.parse(String(row.metadata)); + return `${row.state}:${row.package_id ?? null}:${row.bundle_member ?? '-'}:${body.subject ?? body.label}`; + }).sort(); +const codeOf = (body: any): unknown => (body?.error && typeof body.error === 'object' ? body.error.code : body?.code); +const unwrap = (body: any) => body?.data ?? body; +async function dispatch(kernel: ObjectKernel, method: 'GET' | 'PUT', path: string, query: Record = {}, body?: unknown) { + const dispatcher = new HttpDispatcher(kernel as any, undefined, { enforceProjectMembership: false }); + (dispatcher as any).timedResolveExecutionContext = async () => ({ ...CALLER }); + const search = new URLSearchParams(query).toString(); + const raw = new Request(`http://localhost/api/v1${path}${search ? `?${search}` : ''}`, body === undefined + ? { method } + : { method, headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }); + try { + const out: any = await dispatcher.dispatch(method, path, body ?? {}, query, { request: raw } as any, '/api/v1'); + return { status: out.response?.status as number | undefined, body: out.response?.body }; + } catch (e) { + const thrown = resolveThrownHttpError(e); + return { status: thrown.status, body: { error: { code: thrown.code, message: String((e as Error)?.message ?? '') } } }; + } +} +const bareRead = async (b: Booted, name: string, query: Record = {}) => { + const r = await dispatch(b.kernel, 'GET', `/meta/email_template/${name}`, query); + return r.status === 200 ? [200, unwrap(r.body)?.item?.subject, unwrap(r.body)?.packageId ?? null] : [r.status, codeOf(r.body), String(r.body?.error?.message ?? '').slice(0, 400)]; +}; +const settle = (call: Promise): Promise => call.then( + (resolved) => ({ ok: resolved?.success ?? true, message: resolved?.message }), + (error: any) => ({ code: error?.code, status: error?.status ?? error?.httpStatus, message: String(error?.message ?? '').slice(0, 160) }), +); +const putFr = (b: Booted, name: string, subject: string, query: Record = {}) => + dispatch(b.kernel, 'PUT', `/meta/email_template/${name}`, query, { name, ...template('fr-FR', subject) }); +const saveFr = (b: Booted, name: string, subject: string, extra: Record = {}) => + settle(b.protocol.saveMetaItem({ type: 'email_template', name, item: { name, ...template('fr-FR', subject) }, ...extra })); + +describe('MEASURE', () => { + const dirs: string[] = []; + let b: Booted; + beforeAll(async () => { + const dir = mkdtempSync(join(tmpdir(), 'os-meta-dep-member-db-')); + dirs.push(dir); + b = await boot(join(dir, 'meta.sqlite')); + }, 120_000); + afterAll(async () => { await b.kernel.shutdown(); dirs.push(b.root); for (const dir of dirs) rmSync(dir, { recursive: true, force: true }); }); + const out: Record = {}; + afterAll(() => { console.log('MEASURED ' + JSON.stringify(out, null, 1)); }); + + it('measures', async () => { + const fr = { member: 'fr-FR' }; + // 3-step, REST + await layCell(b.engine, 'm1', WA, WD); + out.m1_step1 = await bareRead(b, 'm1', fr); + const put = await putFr(b, 'm1', 'edited fr'); + out.m1_step2 = [put.status, codeOf(put.body), String(put.body?.error?.message ?? '').slice(0, 200)]; + out.m1_rows = await rowsOf(b.engine, 'm1'); + out.m1_step3 = await bareRead(b, 'm1', fr); + out.m1_step3_WD = await bareRead(b, 'm1', { ...fr, package: WD }); + out.m1_step3_WA = await bareRead(b, 'm1', { ...fr, package: WA }); + out.m1_en = await bareRead(b, 'm1'); + const reg: any = b.engine.registry; + out.m1_registry = { holders: reg.packageScopedHoldersOf?.('email_template', 'm1', null, { includeDisabledPackages: true }), env: reg.getEnvironmentScopedItem?.('email_template', 'm1', 'fr-FR') !== undefined }; + // in process bare + await layCell(b.engine, 'm1p', WA, WD); + out.m1p_save = await saveFr(b, 'm1p', 'edited fr'); + out.m1p_rows = await rowsOf(b.engine, 'm1p'); + out.m1p_read = await bareRead(b, 'm1p', fr); + // named WA + await layCell(b.engine, 'm2', WA, WD); + out.m2_save_named = await saveFr(b, 'm2', 'base fr', { packageId: WA }); + out.m2_rows = await rowsOf(b.engine, 'm2'); + out.m2_read = await bareRead(b, 'm2', fr); + out.m2_read_WD = await bareRead(b, 'm2', { ...fr, package: WD }); + await layCell(b.engine, 'm2r', WA, WD); + const putNamed = await putFr(b, 'm2r', 'base fr', { package: WA }); + out.m2r_put_named = [putNamed.status, codeOf(putNamed.body)]; + out.m2r_rows = await rowsOf(b.engine, 'm2r'); + // draft bare / named + await layCell(b.engine, 'm3', WA, WD); + out.m3_draft_bare = await saveFr(b, 'm3', 'drafted fr', { mode: 'draft' }); + out.m3_rows = await rowsOf(b.engine, 'm3'); + const dr = await settle(b.protocol.getMetaItem({ type: 'email_template', name: 'm3', member: 'fr-FR', state: 'draft' }).then((r: any) => ({ success: true, message: `${r?.item?.subject}|${r?.item?._packageId}` }))); + out.m3_draft_read = dr; + out.m3_publish = await settle(b.protocol.publishMetaItem({ type: 'email_template', name: 'm3', member: 'fr-FR' })); + out.m3_rows_after_publish = await rowsOf(b.engine, 'm3'); + out.m3_read_after_publish = await bareRead(b, 'm3', fr); + await layCell(b.engine, 'm3b', WA, WD); + out.m3b_draft_bare = await saveFr(b, 'm3b', 'drafted fr', { mode: 'draft' }); + out.m3b_discard = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name: 'm3b', member: 'fr-FR', state: 'draft' })); + out.m3b_rows = await rowsOf(b.engine, 'm3b'); + await layCell(b.engine, 'm4', WA, WD); + out.m4_draft_named = await saveFr(b, 'm4', 'drafted fr', { mode: 'draft', packageId: WA }); + out.m4_rows = await rowsOf(b.engine, 'm4'); + out.m4_draft_read_named = await settle(b.protocol.getMetaItem({ type: 'email_template', name: 'm4', member: 'fr-FR', state: 'draft', packageId: WA }).then((r: any) => ({ success: true, message: `${r?.item?.subject}|${r?.item?._packageId}` }))); + out.m4_publish_named = await settle(b.protocol.publishMetaItem({ type: 'email_template', name: 'm4', member: 'fr-FR', packageId: WA })); + out.m4_rows_after_publish = await rowsOf(b.engine, 'm4'); + await layCell(b.engine, 'm4b', WA, WD); + out.m4b_draft_named = await saveFr(b, 'm4b', 'drafted fr', { mode: 'draft', packageId: WA }); + out.m4b_discard_named = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name: 'm4b', member: 'fr-FR', state: 'draft', packageId: WA })); + out.m4b_rows = await rowsOf(b.engine, 'm4b'); + // other doors bare at fr-FR + await layCell(b.engine, 'd1', WA, WD); + out.d1_delete = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name: 'd1', member: 'fr-FR' })); + out.d1_rows = await rowsOf(b.engine, 'd1'); + await layCell(b.engine, 'd2', WA, WD); + await layRow(b.engine, 'email_template', 'd2', WD, template('fr-FR', 'addon fr draft'), 'draft'); + out.d2_discard = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name: 'd2', member: 'fr-FR', state: 'draft' })); + out.d2_rows = await rowsOf(b.engine, 'd2'); + await layCell(b.engine, 'd3', WA, WD); + await layRow(b.engine, 'email_template', 'd3', WD, template('fr-FR', 'addon fr draft'), 'draft'); + out.d3_publish = await settle(b.protocol.publishMetaItem({ type: 'email_template', name: 'd3', member: 'fr-FR' })); + out.d3_rows = await rowsOf(b.engine, 'd3'); + await layCell(b.engine, 'd4', WA, WD); + expect((await saveFr(b, 'd4', 'addon fr v2', { packageId: WD })).ok).toBe(true); + const hb = await b.protocol.historyMetaItem({ type: 'email_template', name: 'd4', member: 'fr-FR' }).then((r: any) => ({ events: r?.events?.length, pkg: r?.packageId }), (e: any) => ({ code: e?.code })); + const hWA = await b.protocol.historyMetaItem({ type: 'email_template', name: 'd4', member: 'fr-FR', packageId: WA }).then((r: any) => ({ events: r?.events?.length }), (e: any) => ({ code: e?.code })); + const hWD = await b.protocol.historyMetaItem({ type: 'email_template', name: 'd4', member: 'fr-FR', packageId: WD }).then((r: any) => ({ events: r?.events?.length }), (e: any) => ({ code: e?.code })); + out.d4_history = { bare: hb, WA: hWA, WD: hWD }; + out.d4_diff = await settle(b.protocol.diffMetaItem({ type: 'email_template', name: 'd4', member: 'fr-FR' })); + out.d4_rollback = await settle(b.protocol.rollbackMetaItem({ type: 'email_template', name: 'd4', member: 'fr-FR', toVersion: 1 })); + out.d4_rows = await rowsOf(b.engine, 'd4'); + // controls + await layCell(b.engine, 'c_unrel', WA, WU); + out.c_unrel_read = await bareRead(b, 'c_unrel', fr); + out.c_unrel_save = await saveFr(b, 'c_unrel', 'x'); + out.c_unrel_rows = await rowsOf(b.engine, 'c_unrel'); + await layRow(b.engine, 'email_template', 'c_unrel2', WA, template('en-US', 'a en')); + await layRow(b.engine, 'email_template', 'c_unrel2', WU, template('en-US', 'u en')); + out.c_unrel2_read = await bareRead(b, 'c_unrel2'); + out.c_unrel2_save = await settle(b.protocol.saveMetaItem({ type: 'email_template', name: 'c_unrel2', item: { name: 'c_unrel2', ...template('en-US', 'x') } })); + await layRow(b.engine, 'email_template', 'shipmail', D, template('fr-FR', 'addon fr')); + out.c_ship_read = await bareRead(b, 'shipmail', fr); + out.c_ship_save = await saveFr(b, 'shipmail', 'edited'); + out.c_ship_rows = await rowsOf(b.engine, 'shipmail'); + await layCell(b.engine, 'c_ro', A, D); + out.c_ro_read = await bareRead(b, 'c_ro', fr); + out.c_ro_save = await saveFr(b, 'c_ro', 'edited'); + out.c_ro_save_A = await saveFr(b, 'c_ro', 'edited', { packageId: A }); + out.c_ro_save_D = await saveFr(b, 'c_ro', 'edited', { packageId: D }); + out.c_ro_rows = await rowsOf(b.engine, 'c_ro'); + // canonical member en-US pair (as #35450): bare save writes base + await layRow(b.engine, 'email_template', 'c_can', WA, template('en-US', 'base en')); + await layRow(b.engine, 'email_template', 'c_can', WD, template('en-US', 'addon en')); + await layRow(b.engine, 'email_template', 'c_can', WD, template('fr-FR', 'addon fr')); + out.c_can_save = await settle(b.protocol.saveMetaItem({ type: 'email_template', name: 'c_can', item: { name: 'c_can', ...template('en-US', 'edited en') } })); + out.c_can_rows = await rowsOf(b.engine, 'c_can'); + // S1 mirror: dependent's canonical over base of other member + await layRow(b.engine, 'email_template', 'c_s1', WA, template('fr-FR', 'base fr')); + await layRow(b.engine, 'email_template', 'c_s1', WD, template('en-US', 'addon en')); + out.c_s1_read = await bareRead(b, 'c_s1'); + out.c_s1_save = await settle(b.protocol.saveMetaItem({ type: 'email_template', name: 'c_s1', item: { name: 'c_s1', ...template('en-US', 'edited en') } })); + out.c_s1_rows = await rowsOf(b.engine, 'c_s1'); + }, 120_000); +}); + +describe('MEASURE reboot', () => { + it('measures across reboots', async () => { + const dir = mkdtempSync(join(tmpdir(), 'os-meta-dep-member-db-')); + const file = join(dir, 'meta.sqlite'); + const out: Record = {}; + const fr = { member: 'fr-FR' }; + let b = await boot(file); + await layCell(b.engine, 'r1', WA, WD); + out.a_read_before_reboot = await bareRead(b, 'r1', fr); + await b.kernel.shutdown(); + b = await boot(file); + out.b_read_after_reboot = await bareRead(b, 'r1', fr); + const put = await putFr(b, 'r1', 'edited fr'); + out.c_put = [put.status, codeOf(put.body)]; + out.c_rows = await rowsOf(b.engine, 'r1'); + out.d_read_after_put = await bareRead(b, 'r1', fr); + await b.kernel.shutdown(); + b = await boot(file); + out.e_read_after_second_reboot = await bareRead(b, 'r1', fr); + out.e_read_WA = await bareRead(b, 'r1', { ...fr, package: WA }); + await b.kernel.shutdown(); + rmSync(dir, { recursive: true, force: true }); + console.log('MEASURED-REBOOT ' + JSON.stringify(out, null, 1)); + }, 120_000); +}); From 4e4b842c5449b412f7af9e9f0b1619498fc4b2cb Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 16:24:15 +0000 Subject: [PATCH 02/10] wip: the draft doors' address follows the row-held base at a dependent-only member Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01J8VVAj3FYe91JCMQZPS88h --- .../metadata-protocol/src/protocol-save.ts | 56 +++++++++++++++++-- packages/metadata-protocol/src/protocol.ts | 11 +++- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-save.ts b/packages/metadata-protocol/src/protocol-save.ts index 7f5fc3e0277..0dfbfba7a1d 100644 --- a/packages/metadata-protocol/src/protocol-save.ts +++ b/packages/metadata-protocol/src/protocol-save.ts @@ -3259,18 +3259,28 @@ export function disabledHoldersOnlyRefusal( * that base does, and every dependent's row stays where it is, read and * written at its own `?package=`. * - * Asked only where those doors would refuse naming two or more packages, and - * answered over the item's ACTIVE rows at `member`, as the read judges them: + * Asked where those doors would refuse naming two or more packages, and + * [#35524] by the save (publish and draft mode) and the draft doors' + * address ({@link packagelessRowHeldBaseDraftAddress}) where the rows are + * bound to one package; answered over the item's ACTIVE rows at `member`, as + * the read judges them: * * - the base, when two or more packages hold a row there, none of them * package-less (#33210: a package-less row beside them is a customization * of no one holder, and the refusal stands), and one is the row-held base; - * - `undefined` otherwise, and the door refuses as before: a type with no + * - [#35524] the base, when one dependent holds the only row there, at a + * named non-canonical member the base holds no row of: the read takes the + * base's address there (and answers 404 until the base holds a row), so + * the bare save writes the base's row or draft, as the save naming the + * base does, and the next bare read serves it. The canonical member stays + * the dependent's, as the read serves it (#33210 contract review S1); + * - `undefined` otherwise, and the door answers as before: a type with no * members (#34441 contract review M1: no bundle additions), a name a * package ships, holders with no base relation, a disabled holder (the - * served-holder judgment's), and a member the base holds no row of (the - * read takes the base's address there and answers 404; that cell is not - * moved here). + * served-holder judgment's), and, of the one-holder cell, the base's own + * row. The bare delete, history, diff and rollback ask only with two or + * more holders, so at the one-holder cell they still act on the + * dependent's row. * * FROM (`main` 8596c80eda): each of those doors refused `409 * RESOURCE_CONFLICT` naming the base and the dependent while the read @@ -3306,6 +3316,40 @@ export async function packagelessRowHeldBaseAddress( return address.candidates.includes(base) === address.candidates.length > 1 ? base : undefined; } +/** + * [#35524, epic ruling 6781691009, #34348 ruling (b)] THE DRAFT ADDRESS the + * draft doors naming no package take (the draft save, the strict draft read, + * the per-item publish and the draft discard, through + * `packagelessDraftAddress`), at a named non-canonical member whose active + * rows are bound to one dependent only, where the read naming no package + * takes the row-held base's address ({@link packagelessRowHeldBaseAddress}): + * that base's draft, promoted into the base's row, as the same request naming + * the base addresses it. So the draft a bare draft save writes there is the + * draft the bare draft read, publish and discard act on, and the dependent's + * draft is read, published and discarded at its own `?package=`. + * + * `address` itself otherwise: an ambiguous address (the doors ask + * {@link packagelessRowHeldBaseAddress} for it themselves, #34681), an address + * not bound to a package by the active rows, and every cell that judgment + * declines. + * + * FROM (`main` a73edb3cd7): the bare draft save wrote the dependent's draft + * there and the bare publish promoted it into the dependent's row, while the + * bare read at the member answered 404 (the base's address). + */ +export async function packagelessRowHeldBaseDraftAddress( + host: Pick, + type: string, + name: string, + member: string | undefined, + address: Awaited>, +): Promise>> { + if (address.kind === 'ambiguous' || address.into === null) return address; + const base = await packagelessRowHeldBaseAddress(host, type, name, member); + if (base === undefined) return address; + return { kind: address.drafts.candidates.includes(base) ? 'draft' : 'none', key: base, into: base, drafts: address.drafts }; +} + /** * [ADR-0150 D3/D5 and red line 2] THE HOLDERS a write naming no package * counts before it takes its address from the stored rows' bindings diff --git a/packages/metadata-protocol/src/protocol.ts b/packages/metadata-protocol/src/protocol.ts index 4db04119c5b..4207f831e93 100644 --- a/packages/metadata-protocol/src/protocol.ts +++ b/packages/metadata-protocol/src/protocol.ts @@ -619,7 +619,7 @@ import { ProtocolWriteGatesTables } from './protocol-write-gates-tables.js'; import { ProtocolRegistryHydrationFacet, type ObjectRegistryRefusal, type RegistryHealStop, type RegistryWriteThroughRequest } from './protocol-registry-hydration.js'; import type { HealPackageBinding } from './protocol-heal-binding.js'; // [#29985 codemod] Save refusals, saveMetaItem, saveConflict, migrateStoredMetadata: the members below delegate to its facet, `ProtocolSaveFacet`. -import { ProtocolSaveFacet } from './protocol-save.js'; +import { ProtocolSaveFacet, packagelessRowHeldBaseDraftAddress } from './protocol-save.js'; // [#29985 codemod] History, publish, drafts, publish backfill: the members below delegate to its facet, `ProtocolHistoryAndPublishFacet`. import { ProtocolHistoryAndPublishFacet } from './protocol-history-and-publish.js'; import type { RegistryQuestion } from './registry-question.js'; @@ -7954,7 +7954,7 @@ export class ObjectStackProtocolImplementation implements * under, and `drafts` the bindings of every draft row of the item, which * the doors' receipts name. */ - private packagelessDraftAddress( + private async packagelessDraftAddress( type: string, name: string, /** [#22877] The bundle member the door addresses; omitted, the canonical one. */ @@ -7976,7 +7976,12 @@ export class ObjectStackProtocolImplementation implements getOverlayRepo: (...a) => this.getOverlayRepo(...a), readItemActiveRows: (...a) => this.readItemActiveRows(...a), }; - return packagelessDraftAddress.call(host, type, name, member, body); + // [#35524] …at the draft address the read naming no package takes + // there: the row-held base's, where the member's active rows are + // bound to one dependent only ({@link packagelessRowHeldBaseDraftAddress}). + return packagelessRowHeldBaseDraftAddress( + protocolHost(this), type, name, member, await packagelessDraftAddress.call(host, type, name, member, body), + ); } /** From b7be6fce59cc4b921366ba4fad66cf4e472a6f3e Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 17:28:16 +0000 Subject: [PATCH 03/10] test(runtime): pin the bare save and the draft doors at a member only the dependent holds Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01J8VVAj3FYe91JCMQZPS88h --- ...e-save-dependent-only-member-35524.test.ts | 327 ++++++++++-------- 1 file changed, 190 insertions(+), 137 deletions(-) diff --git a/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts b/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts index 4d1e572ae7b..795779d7a21 100644 --- a/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts +++ b/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts @@ -1,4 +1,41 @@ -// MEASURE (temporary): the cell on main before any change. +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// [#35524, epic ruling 6781691009, #34348 ruling (b), ADR-0150 D3/D5] A +// bundled type's name no package ships, held as stored rows by an authored +// base WA (its `en-US` row) and an authored dependent WD that declares WA (its +// `fr-FR` row, a bundle addition). At the named non-canonical member `fr-FR` +// only WD holds a row, and the read naming no package takes the row-held +// base's address there (#33210 (c), pinned unchanged in +// `meta-disabled-holder-served-stack.test.ts` M1, M2, S2): 404. The write +// naming no package now resolves its address as that read does: the bare +// save (the REST door and in process, publish and draft mode) writes WA's +// row or draft at `fr-FR`, exactly as the save naming WA does, WD's row stays +// byte-unchanged, and the next bare read serves what was saved. The draft +// doors naming no package (the strict draft read, the per-item publish and +// the draft discard) take the same draft address, so the draft a bare draft +// save writes is the one they read, promote and discard; at this cell the +// dependent's own draft is reached at its own `?package=`, as the request +// naming WA answers. Driven on a booted kernel (the real protocol, metadata +// service, registry and `sys_metadata` store). +// +// FROM (`main` a73edb3cd7, measured through these doors): the bare read at +// `fr-FR` answered 404, the bare save answered 200 and rewrote WD's row, and +// the bare read after it answered 404 on a kernel whose registry had hydrated +// both rows at boot, or 409 RESOURCE_CONFLICT (the base's address names WA, +// the registry then named WD the holder) where the rows were stored after +// boot. The bare draft save wrote WD's draft, the bare draft read served it, +// and the bare publish promoted it into WD's row; the bare publish and +// discard of WD's draft promoted or removed it. +// +// Measured beside it, pinned as they read: the canonical member a base and +// its dependent both hold (the #34681 cell) and the canonical member only the +// dependent holds (#33210 contract review S1) keep their writes; two holders +// with no base relation are still refused 409 at a member both hold; a base +// that ships the name in code keeps answering as it does today (the bare read +// 404, the bare save writing the dependent's customization row: not moved by +// this change, see the PR's acceptance notes); a read-only base holding rows +// answers the bare save as `?package=` does. + import { afterAll, beforeAll, describe, expect, it } from 'vitest'; import { mkdtempSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; @@ -92,154 +129,170 @@ const bareRead = async (b: Booted, name: string, query: Record = }; const settle = (call: Promise): Promise => call.then( (resolved) => ({ ok: resolved?.success ?? true, message: resolved?.message }), - (error: any) => ({ code: error?.code, status: error?.status ?? error?.httpStatus, message: String(error?.message ?? '').slice(0, 160) }), + (error: any) => ({ code: error?.code, status: error?.status ?? error?.httpStatus, message: String(error?.message ?? '') }), ); const putFr = (b: Booted, name: string, subject: string, query: Record = {}) => dispatch(b.kernel, 'PUT', `/meta/email_template/${name}`, query, { name, ...template('fr-FR', subject) }); const saveFr = (b: Booted, name: string, subject: string, extra: Record = {}) => settle(b.protocol.saveMetaItem({ type: 'email_template', name, item: { name, ...template('fr-FR', subject) }, ...extra })); -describe('MEASURE', () => { +const fr = { member: 'fr-FR' }; +/** Every stored column of the dependent's `fr-FR` row, for a byte-identity comparison. */ +const dependentRow = async (engine: ObjectQL, name: string, dependent = WD) => JSON.stringify(((await engine.find('sys_metadata', { where: { type: 'email_template', name, package_id: dependent }, context: { isSystem: true } } satisfies EngineQueryOptions)) as any[]) + .filter((row) => row.bundle_member === 'fr-FR')); +/** The rows of `name` with the name blanked, to compare two names' writes. */ +const shapeOf = async (engine: ObjectQL, name: string) => (await rowsOf(engine, name)).map((row) => row.replace(name, 'NAME')); + +describe('[#35524] the bare save at a member only the dependent holds writes the row-held base\'s row the bare read addresses', () => { const dirs: string[] = []; - let b: Booted; - beforeAll(async () => { + afterAll(() => { for (const dir of dirs) rmSync(dir, { recursive: true, force: true }); }); + const freshFile = () => { const dir = mkdtempSync(join(tmpdir(), 'os-meta-dep-member-db-')); dirs.push(dir); - b = await boot(join(dir, 'meta.sqlite')); - }, 120_000); - afterAll(async () => { await b.kernel.shutdown(); dirs.push(b.root); for (const dir of dirs) rmSync(dir, { recursive: true, force: true }); }); - const out: Record = {}; - afterAll(() => { console.log('MEASURED ' + JSON.stringify(out, null, 1)); }); - - it('measures', async () => { - const fr = { member: 'fr-FR' }; - // 3-step, REST - await layCell(b.engine, 'm1', WA, WD); - out.m1_step1 = await bareRead(b, 'm1', fr); - const put = await putFr(b, 'm1', 'edited fr'); - out.m1_step2 = [put.status, codeOf(put.body), String(put.body?.error?.message ?? '').slice(0, 200)]; - out.m1_rows = await rowsOf(b.engine, 'm1'); - out.m1_step3 = await bareRead(b, 'm1', fr); - out.m1_step3_WD = await bareRead(b, 'm1', { ...fr, package: WD }); - out.m1_step3_WA = await bareRead(b, 'm1', { ...fr, package: WA }); - out.m1_en = await bareRead(b, 'm1'); - const reg: any = b.engine.registry; - out.m1_registry = { holders: reg.packageScopedHoldersOf?.('email_template', 'm1', null, { includeDisabledPackages: true }), env: reg.getEnvironmentScopedItem?.('email_template', 'm1', 'fr-FR') !== undefined }; - // in process bare - await layCell(b.engine, 'm1p', WA, WD); - out.m1p_save = await saveFr(b, 'm1p', 'edited fr'); - out.m1p_rows = await rowsOf(b.engine, 'm1p'); - out.m1p_read = await bareRead(b, 'm1p', fr); - // named WA - await layCell(b.engine, 'm2', WA, WD); - out.m2_save_named = await saveFr(b, 'm2', 'base fr', { packageId: WA }); - out.m2_rows = await rowsOf(b.engine, 'm2'); - out.m2_read = await bareRead(b, 'm2', fr); - out.m2_read_WD = await bareRead(b, 'm2', { ...fr, package: WD }); - await layCell(b.engine, 'm2r', WA, WD); - const putNamed = await putFr(b, 'm2r', 'base fr', { package: WA }); - out.m2r_put_named = [putNamed.status, codeOf(putNamed.body)]; - out.m2r_rows = await rowsOf(b.engine, 'm2r'); - // draft bare / named - await layCell(b.engine, 'm3', WA, WD); - out.m3_draft_bare = await saveFr(b, 'm3', 'drafted fr', { mode: 'draft' }); - out.m3_rows = await rowsOf(b.engine, 'm3'); - const dr = await settle(b.protocol.getMetaItem({ type: 'email_template', name: 'm3', member: 'fr-FR', state: 'draft' }).then((r: any) => ({ success: true, message: `${r?.item?.subject}|${r?.item?._packageId}` }))); - out.m3_draft_read = dr; - out.m3_publish = await settle(b.protocol.publishMetaItem({ type: 'email_template', name: 'm3', member: 'fr-FR' })); - out.m3_rows_after_publish = await rowsOf(b.engine, 'm3'); - out.m3_read_after_publish = await bareRead(b, 'm3', fr); - await layCell(b.engine, 'm3b', WA, WD); - out.m3b_draft_bare = await saveFr(b, 'm3b', 'drafted fr', { mode: 'draft' }); - out.m3b_discard = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name: 'm3b', member: 'fr-FR', state: 'draft' })); - out.m3b_rows = await rowsOf(b.engine, 'm3b'); - await layCell(b.engine, 'm4', WA, WD); - out.m4_draft_named = await saveFr(b, 'm4', 'drafted fr', { mode: 'draft', packageId: WA }); - out.m4_rows = await rowsOf(b.engine, 'm4'); - out.m4_draft_read_named = await settle(b.protocol.getMetaItem({ type: 'email_template', name: 'm4', member: 'fr-FR', state: 'draft', packageId: WA }).then((r: any) => ({ success: true, message: `${r?.item?.subject}|${r?.item?._packageId}` }))); - out.m4_publish_named = await settle(b.protocol.publishMetaItem({ type: 'email_template', name: 'm4', member: 'fr-FR', packageId: WA })); - out.m4_rows_after_publish = await rowsOf(b.engine, 'm4'); - await layCell(b.engine, 'm4b', WA, WD); - out.m4b_draft_named = await saveFr(b, 'm4b', 'drafted fr', { mode: 'draft', packageId: WA }); - out.m4b_discard_named = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name: 'm4b', member: 'fr-FR', state: 'draft', packageId: WA })); - out.m4b_rows = await rowsOf(b.engine, 'm4b'); - // other doors bare at fr-FR - await layCell(b.engine, 'd1', WA, WD); - out.d1_delete = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name: 'd1', member: 'fr-FR' })); - out.d1_rows = await rowsOf(b.engine, 'd1'); - await layCell(b.engine, 'd2', WA, WD); - await layRow(b.engine, 'email_template', 'd2', WD, template('fr-FR', 'addon fr draft'), 'draft'); - out.d2_discard = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name: 'd2', member: 'fr-FR', state: 'draft' })); - out.d2_rows = await rowsOf(b.engine, 'd2'); - await layCell(b.engine, 'd3', WA, WD); - await layRow(b.engine, 'email_template', 'd3', WD, template('fr-FR', 'addon fr draft'), 'draft'); - out.d3_publish = await settle(b.protocol.publishMetaItem({ type: 'email_template', name: 'd3', member: 'fr-FR' })); - out.d3_rows = await rowsOf(b.engine, 'd3'); - await layCell(b.engine, 'd4', WA, WD); - expect((await saveFr(b, 'd4', 'addon fr v2', { packageId: WD })).ok).toBe(true); - const hb = await b.protocol.historyMetaItem({ type: 'email_template', name: 'd4', member: 'fr-FR' }).then((r: any) => ({ events: r?.events?.length, pkg: r?.packageId }), (e: any) => ({ code: e?.code })); - const hWA = await b.protocol.historyMetaItem({ type: 'email_template', name: 'd4', member: 'fr-FR', packageId: WA }).then((r: any) => ({ events: r?.events?.length }), (e: any) => ({ code: e?.code })); - const hWD = await b.protocol.historyMetaItem({ type: 'email_template', name: 'd4', member: 'fr-FR', packageId: WD }).then((r: any) => ({ events: r?.events?.length }), (e: any) => ({ code: e?.code })); - out.d4_history = { bare: hb, WA: hWA, WD: hWD }; - out.d4_diff = await settle(b.protocol.diffMetaItem({ type: 'email_template', name: 'd4', member: 'fr-FR' })); - out.d4_rollback = await settle(b.protocol.rollbackMetaItem({ type: 'email_template', name: 'd4', member: 'fr-FR', toVersion: 1 })); - out.d4_rows = await rowsOf(b.engine, 'd4'); - // controls - await layCell(b.engine, 'c_unrel', WA, WU); - out.c_unrel_read = await bareRead(b, 'c_unrel', fr); - out.c_unrel_save = await saveFr(b, 'c_unrel', 'x'); - out.c_unrel_rows = await rowsOf(b.engine, 'c_unrel'); - await layRow(b.engine, 'email_template', 'c_unrel2', WA, template('en-US', 'a en')); - await layRow(b.engine, 'email_template', 'c_unrel2', WU, template('en-US', 'u en')); - out.c_unrel2_read = await bareRead(b, 'c_unrel2'); - out.c_unrel2_save = await settle(b.protocol.saveMetaItem({ type: 'email_template', name: 'c_unrel2', item: { name: 'c_unrel2', ...template('en-US', 'x') } })); - await layRow(b.engine, 'email_template', 'shipmail', D, template('fr-FR', 'addon fr')); - out.c_ship_read = await bareRead(b, 'shipmail', fr); - out.c_ship_save = await saveFr(b, 'shipmail', 'edited'); - out.c_ship_rows = await rowsOf(b.engine, 'shipmail'); - await layCell(b.engine, 'c_ro', A, D); - out.c_ro_read = await bareRead(b, 'c_ro', fr); - out.c_ro_save = await saveFr(b, 'c_ro', 'edited'); - out.c_ro_save_A = await saveFr(b, 'c_ro', 'edited', { packageId: A }); - out.c_ro_save_D = await saveFr(b, 'c_ro', 'edited', { packageId: D }); - out.c_ro_rows = await rowsOf(b.engine, 'c_ro'); - // canonical member en-US pair (as #35450): bare save writes base - await layRow(b.engine, 'email_template', 'c_can', WA, template('en-US', 'base en')); - await layRow(b.engine, 'email_template', 'c_can', WD, template('en-US', 'addon en')); - await layRow(b.engine, 'email_template', 'c_can', WD, template('fr-FR', 'addon fr')); - out.c_can_save = await settle(b.protocol.saveMetaItem({ type: 'email_template', name: 'c_can', item: { name: 'c_can', ...template('en-US', 'edited en') } })); - out.c_can_rows = await rowsOf(b.engine, 'c_can'); - // S1 mirror: dependent's canonical over base of other member - await layRow(b.engine, 'email_template', 'c_s1', WA, template('fr-FR', 'base fr')); - await layRow(b.engine, 'email_template', 'c_s1', WD, template('en-US', 'addon en')); - out.c_s1_read = await bareRead(b, 'c_s1'); - out.c_s1_save = await settle(b.protocol.saveMetaItem({ type: 'email_template', name: 'c_s1', item: { name: 'c_s1', ...template('en-US', 'edited en') } })); - out.c_s1_rows = await rowsOf(b.engine, 'c_s1'); - }, 120_000); -}); + return join(dir, 'meta.sqlite'); + }; + const down = async (b: Booted) => { + if (b.kernel.getState() === 'running') await b.kernel.shutdown(); + dirs.push(b.root); + }; -describe('MEASURE reboot', () => { - it('measures across reboots', async () => { - const dir = mkdtempSync(join(tmpdir(), 'os-meta-dep-member-db-')); - const file = join(dir, 'meta.sqlite'); - const out: Record = {}; - const fr = { member: 'fr-FR' }; + it('the bare save (REST door and in process) writes what ?package= writes, leaves the dependent\'s row byte-unchanged, and the bare read then serves it, before and after a restart', async () => { + const file = freshFile(); let b = await boot(file); - await layCell(b.engine, 'r1', WA, WD); - out.a_read_before_reboot = await bareRead(b, 'r1', fr); - await b.kernel.shutdown(); + try { + for (const name of ['dm_rest', 'dm_proc', 'dm_named']) await layCell(b.engine, name, WA, WD); + } finally { + await down(b); + } + // Booted over the stored rows, so the registry hydrated both packages' rows. b = await boot(file); - out.b_read_after_reboot = await bareRead(b, 'r1', fr); - const put = await putFr(b, 'r1', 'edited fr'); - out.c_put = [put.status, codeOf(put.body)]; - out.c_rows = await rowsOf(b.engine, 'r1'); - out.d_read_after_put = await bareRead(b, 'r1', fr); - await b.kernel.shutdown(); + try { + expect(await bareRead(b, 'dm_rest', fr)).toEqual([404, 'RESOURCE_NOT_FOUND', expect.any(String)]); + const before = await dependentRow(b.engine, 'dm_rest'); + const put = await putFr(b, 'dm_rest', 'edited fr'); + expect(put.status, JSON.stringify(put.body)).toBe(200); + expect(await dependentRow(b.engine, 'dm_rest')).toBe(before); + const proc = await saveFr(b, 'dm_proc', 'edited fr'); + expect(proc.message, JSON.stringify(proc)).toContain(`package=${WA}`); + const named = await saveFr(b, 'dm_named', 'edited fr', { packageId: WA }); + expect(named.ok, JSON.stringify(named)).toBe(true); + const expected = [`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, `active:${WA}:fr-FR:edited fr`]; + for (const name of ['dm_rest', 'dm_proc', 'dm_named']) { + expect([name, ...await rowsOf(b.engine, name)]).toEqual([name, ...expected]); + expect(await bareRead(b, name, fr)).toEqual([200, 'edited fr', WA]); + expect(await bareRead(b, name, { ...fr, package: WD })).toEqual([200, 'addon fr', WD]); + } + expect(await shapeOf(b.engine, 'dm_rest')).toEqual(await shapeOf(b.engine, 'dm_named')); + } finally { + await down(b); + } b = await boot(file); - out.e_read_after_second_reboot = await bareRead(b, 'r1', fr); - out.e_read_WA = await bareRead(b, 'r1', { ...fr, package: WA }); - await b.kernel.shutdown(); - rmSync(dir, { recursive: true, force: true }); - console.log('MEASURED-REBOOT ' + JSON.stringify(out, null, 1)); + try { + expect(await bareRead(b, 'dm_rest', fr)).toEqual([200, 'edited fr', WA]); + } finally { + await down(b); + } }, 120_000); + + describe('one boot', () => { + let b: Booted; + beforeAll(async () => { b = await boot(freshFile()); }, 120_000); + afterAll(async () => { if (b) await down(b); }); + + it('rows stored after boot: the bare save writes the base\'s row and the bare read serves it (it answered 409 after the save)', async () => { + await layCell(b.engine, 'dm_cold', WA, WD); + expect((await bareRead(b, 'dm_cold', fr))[0]).toBe(404); + const put = await putFr(b, 'dm_cold', 'edited fr'); + expect(put.status, JSON.stringify(put.body)).toBe(200); + expect(await rowsOf(b.engine, 'dm_cold')).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, `active:${WA}:fr-FR:edited fr`]); + expect(await bareRead(b, 'dm_cold', fr)).toEqual([200, 'edited fr', WA]); + }); + + it('the bare draft save writes the base\'s draft, as ?package= does; the bare draft read, publish and discard act on that draft', async () => { + await layCell(b.engine, 'dd_bare', WA, WD); + await layCell(b.engine, 'dd_named', WA, WD); + const before = await dependentRow(b.engine, 'dd_bare'); + const bare = await saveFr(b, 'dd_bare', 'drafted fr', { mode: 'draft' }); + const named = await saveFr(b, 'dd_named', 'drafted fr', { mode: 'draft', packageId: WA }); + expect(bare.message, JSON.stringify(bare)).toContain(`package=${WA}`); + expect(named.ok, JSON.stringify(named)).toBe(true); + expect(await rowsOf(b.engine, 'dd_bare')).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, `draft:${WA}:fr-FR:drafted fr`]); + expect(await shapeOf(b.engine, 'dd_bare')).toEqual(await shapeOf(b.engine, 'dd_named')); + expect(await dependentRow(b.engine, 'dd_bare')).toBe(before); + const read = await b.protocol.getMetaItem({ type: 'email_template', name: 'dd_bare', member: 'fr-FR', state: 'draft' }); + expect([read?.item?.subject, read?.item?._packageId]).toEqual(['drafted fr', WA]); + const published = await settle(b.protocol.publishMetaItem({ type: 'email_template', name: 'dd_bare', member: 'fr-FR' })); + expect(published.ok, JSON.stringify(published)).toBe(true); + expect(await rowsOf(b.engine, 'dd_bare')).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, `active:${WA}:fr-FR:drafted fr`]); + expect(await bareRead(b, 'dd_bare', fr)).toEqual([200, 'drafted fr', WA]); + // The discard removes the draft the bare draft save wrote. + await layCell(b.engine, 'dd_discard', WA, WD); + expect((await saveFr(b, 'dd_discard', 'drafted fr', { mode: 'draft' })).ok).toBe(true); + const discarded = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name: 'dd_discard', member: 'fr-FR', state: 'draft' })); + expect(discarded.message, JSON.stringify(discarded)).toContain(`(package=${WA})`); + expect(await rowsOf(b.engine, 'dd_discard')).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`]); + }); + + it('the dependent\'s own draft at the cell: the bare publish and discard answer what ?package= answers, and ?package= reaches it', async () => { + const outcome = (answer: any) => (answer.code !== undefined ? [answer.code, answer.status] : ['ok', answer.ok]); + const seen: Record = {}; + for (const [label, at] of [['bare', {}], ['named', { packageId: WA }]] as const) { + const name = `dd_own_${label}`; + await layCell(b.engine, name, WA, WD); + await layRow(b.engine, 'email_template', name, WD, template('fr-FR', 'addon fr draft'), 'draft'); + const publish = await settle(b.protocol.publishMetaItem({ type: 'email_template', name, member: 'fr-FR', ...at })); + const discard = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name, member: 'fr-FR', state: 'draft', ...at })); + seen[label] = { publish: outcome(publish), discard: outcome(discard), rows: await shapeOf(b.engine, name) }; + } + expect(seen.bare, JSON.stringify(seen)).toEqual(seen.named); + expect(seen.bare).toMatchObject({ rows: [`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, `draft:${WD}:fr-FR:addon fr draft`] }); + const own = await settle(b.protocol.publishMetaItem({ type: 'email_template', name: 'dd_own_bare', member: 'fr-FR', packageId: WD })); + expect(own.ok, JSON.stringify(own)).toBe(true); + expect(await rowsOf(b.engine, 'dd_own_bare')).toEqual([`active:${WD}:fr-FR:addon fr draft`, `active:${WA}:-:base en`]); + }); + + it('a read-only base holding rows: the bare save at the dependent\'s member answers what ?package= answers', async () => { + await layCell(b.engine, 'ro_cell', A, D); + const bare = await saveFr(b, 'ro_cell', 'edited'); + const named = await saveFr(b, 'ro_cell', 'edited', { packageId: A }); + expect([bare.code, bare.status], JSON.stringify(bare)).toEqual(['WRITABLE_PACKAGE_REQUIRED', 422]); + expect([bare.code, bare.status]).toEqual([named.code, named.status]); + expect(bare.message).toContain(`'${A}'`); + expect(await rowsOf(b.engine, 'ro_cell')).toEqual([`active:${D}:fr-FR:addon fr`, `active:${A}:-:base en`]); + }); + + it('CONTROLS: the canonical member keeps its writes, unrelated holders are still refused at a shared member, and a shipped base answers as it did', async () => { + // The #34681 cell: base and dependent both hold the canonical member; the bare save writes the base's row. + await layRow(b.engine, 'email_template', 'c_shared', WA, template('en-US', 'base en')); + await layRow(b.engine, 'email_template', 'c_shared', WD, template('en-US', 'addon en')); + await layRow(b.engine, 'email_template', 'c_shared', WD, template('fr-FR', 'addon fr')); + const shared = await settle(b.protocol.saveMetaItem({ type: 'email_template', name: 'c_shared', item: { name: 'c_shared', ...template('en-US', 'edited en') } })); + expect(shared.message, JSON.stringify(shared)).toContain(`package=${WA}`); + expect(await rowsOf(b.engine, 'c_shared')).toEqual([`active:${WD}:-:addon en`, `active:${WD}:fr-FR:addon fr`, `active:${WA}:-:edited en`]); + // The S1 mirror: the canonical member only the dependent holds is served and written at the dependent. + await layRow(b.engine, 'email_template', 'c_s1', WA, template('fr-FR', 'base fr')); + await layRow(b.engine, 'email_template', 'c_s1', WD, template('en-US', 'addon en')); + expect(await bareRead(b, 'c_s1')).toEqual([200, 'addon en', WD]); + const s1 = await settle(b.protocol.saveMetaItem({ type: 'email_template', name: 'c_s1', item: { name: 'c_s1', ...template('en-US', 'edited en') } })); + expect(s1.message, JSON.stringify(s1)).toContain(`package=${WD}`); + expect(await rowsOf(b.engine, 'c_s1')).toEqual([`active:${WD}:-:edited en`, `active:${WA}:fr-FR:base fr`]); + // Two packages, neither declaring the other, at a member both hold: refused 409 naming both. + await layRow(b.engine, 'email_template', 'c_unrel', WA, template('en-US', 'a en')); + await layRow(b.engine, 'email_template', 'c_unrel', WU, template('en-US', 'u en')); + expect((await bareRead(b, 'c_unrel')).slice(0, 2)).toEqual([409, 'RESOURCE_CONFLICT']); + const unrel = await settle(b.protocol.saveMetaItem({ type: 'email_template', name: 'c_unrel', item: { name: 'c_unrel', ...template('en-US', 'x') } })); + expect([unrel.code, unrel.status], JSON.stringify(unrel)).toEqual(['RESOURCE_CONFLICT', 409]); + for (const id of [WA, WU]) expect(unrel.message).toContain(id); + // …and at a member only one of them holds, that package's row is read and written. + await layCell(b.engine, 'c_unrel_fr', WA, WU); + expect(await bareRead(b, 'c_unrel_fr', fr)).toEqual([200, 'addon fr', WU]); + expect((await saveFr(b, 'c_unrel_fr', 'x')).message).toContain(`package=${WU}`); + // A base that ships the name in code: answered as today (not moved here). + await layRow(b.engine, 'email_template', 'shipmail', D, template('fr-FR', 'addon fr')); + expect((await bareRead(b, 'shipmail', fr))[0]).toBe(404); + const ship = await saveFr(b, 'shipmail', 'edited'); + expect(ship.message, JSON.stringify(ship)).toContain(`package=${D}`); + expect(await rowsOf(b.engine, 'shipmail')).toEqual([`active:${D}:fr-FR:edited`]); + }); + }); }); From f1813eb023b1ba1f6eeb2fbe2640c199e0133a82 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 17:37:30 +0000 Subject: [PATCH 04/10] chore(changeset): the bare save at a dependent-only bundle member follows the row-held base Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01J8VVAj3FYe91JCMQZPS88h --- ...bare-save-follows-base-dependent-member.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .changeset/35524-bare-save-follows-base-dependent-member.md diff --git a/.changeset/35524-bare-save-follows-base-dependent-member.md b/.changeset/35524-bare-save-follows-base-dependent-member.md new file mode 100644 index 00000000000..97915932282 --- /dev/null +++ b/.changeset/35524-bare-save-follows-base-dependent-member.md @@ -0,0 +1,19 @@ +--- +'@objectstack/metadata-protocol': patch +--- + +fix(metadata-protocol)!: a save naming no package, at a bundle member only a dependent package holds, writes the base package's row the read naming no package addresses + +Clause-②: no (narrowing) +Metadata-protocol: none + + + +**BREAKING** for a caller that saves, publishes or discards a bundled type's item (today `email_template`) without naming a package, where an authored base package holds the item's canonical member as a stored row, an authored package that declares the base holds a stored row of another member (for example `fr-FR`), and the base holds no row of that member. The read naming no package already takes the base's address at that member and answers `404`. + +- FROM: the save naming no package (REST `PUT` and in process, `active` mode) rewrote the dependent's row at that member, and the read naming no package then still answered `404` (or `409 RESOURCE_CONFLICT` where the rows had been stored after boot). The `draft` save wrote the dependent's draft; the draft read, per-item publish and draft discard naming no package read, promoted or removed the dependent's draft. +- TO: the save naming no package writes the base's row (or, in `draft` mode, the base's draft) at that member, exactly as the same save naming the base (`?package=BASE`, `packageId: BASE`) does; the dependent's row is left byte-unchanged, and the next read naming no package serves the saved content (`200`). The draft read, per-item publish and draft discard naming no package act on the base's draft there. With only the dependent's draft stored at that member, the per-item publish naming no package answers `404 NO_DRAFT` naming that draft, and the draft discard naming no package discards nothing and says which draft remains, as the same requests naming the base answer. + +**Not moved.** The canonical member (a base and its dependent both holding it, or only the dependent holding it), two packages neither of which declares the other, a base that ships the name in code, and the delete, history, diff and rollback naming no package at this member. + +The fix for a caller: to change the dependent's row or draft at that member, name the dependent (`?package=DEPENDENT` on the REST door, `packageId` in process). From 80f540b64b0d61ba88c6d0ed00f95f786db5ed4c Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 17:49:52 +0000 Subject: [PATCH 05/10] fix(metadata-protocol): keep the protocol facade's draft-address member a forwarding call Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01J8VVAj3FYe91JCMQZPS88h --- packages/metadata-protocol/src/protocol-save.ts | 5 +++-- packages/metadata-protocol/src/protocol.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-save.ts b/packages/metadata-protocol/src/protocol-save.ts index 0dfbfba7a1d..c9d9c3f2268 100644 --- a/packages/metadata-protocol/src/protocol-save.ts +++ b/packages/metadata-protocol/src/protocol-save.ts @@ -3328,7 +3328,7 @@ export async function packagelessRowHeldBaseAddress( * draft the bare draft read, publish and discard act on, and the dependent's * draft is read, published and discarded at its own `?package=`. * - * `address` itself otherwise: an ambiguous address (the doors ask + * `pending` (the draft address the stored rows give) itself otherwise: an ambiguous address (the doors ask * {@link packagelessRowHeldBaseAddress} for it themselves, #34681), an address * not bound to a package by the active rows, and every cell that judgment * declines. @@ -3342,8 +3342,9 @@ export async function packagelessRowHeldBaseDraftAddress( type: string, name: string, member: string | undefined, - address: Awaited>, + pending: ReturnType, ): Promise>> { + const address = await pending; if (address.kind === 'ambiguous' || address.into === null) return address; const base = await packagelessRowHeldBaseAddress(host, type, name, member); if (base === undefined) return address; diff --git a/packages/metadata-protocol/src/protocol.ts b/packages/metadata-protocol/src/protocol.ts index 4207f831e93..c672534b9fe 100644 --- a/packages/metadata-protocol/src/protocol.ts +++ b/packages/metadata-protocol/src/protocol.ts @@ -7954,7 +7954,7 @@ export class ObjectStackProtocolImplementation implements * under, and `drafts` the bindings of every draft row of the item, which * the doors' receipts name. */ - private async packagelessDraftAddress( + private packagelessDraftAddress( type: string, name: string, /** [#22877] The bundle member the door addresses; omitted, the canonical one. */ @@ -7980,7 +7980,7 @@ export class ObjectStackProtocolImplementation implements // there: the row-held base's, where the member's active rows are // bound to one dependent only ({@link packagelessRowHeldBaseDraftAddress}). return packagelessRowHeldBaseDraftAddress( - protocolHost(this), type, name, member, await packagelessDraftAddress.call(host, type, name, member, body), + protocolHost(this), type, name, member, packagelessDraftAddress.call(host, type, name, member, body), ); } From 34972cbdd3b9dd70c9d55ec456fddcf1c09a971c Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 10:43:15 +0000 Subject: [PATCH 06/10] fix(metadata-protocol): keep the package-unbound draft's address at the dependent-only member A bare draft address naming the package-unbound draft (key null) over a member whose active row only the dependent holds is left as main gives it: the bare draft read serves it, the bare publish promotes it into the dependent's row, the bare discard removes it, and the bare draft save adopts it rather than writing a second draft bound to the base. One predicate, draftAddressFollowsRowHeldBase, is asked by the draft doors' address and the draft save's follow. The changeset lists the sub-cell under "Not moved" and its banner names a base holding a row of any other member. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01J8VVAj3FYe91JCMQZPS88h --- ...bare-save-follows-base-dependent-member.md | 4 +-- .../metadata-protocol/src/protocol-save.ts | 33 ++++++++++++++++--- ...e-save-dependent-only-member-35524.test.ts | 29 ++++++++++++++++ 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/.changeset/35524-bare-save-follows-base-dependent-member.md b/.changeset/35524-bare-save-follows-base-dependent-member.md index 97915932282..7bcda353740 100644 --- a/.changeset/35524-bare-save-follows-base-dependent-member.md +++ b/.changeset/35524-bare-save-follows-base-dependent-member.md @@ -9,11 +9,11 @@ Metadata-protocol: none -**BREAKING** for a caller that saves, publishes or discards a bundled type's item (today `email_template`) without naming a package, where an authored base package holds the item's canonical member as a stored row, an authored package that declares the base holds a stored row of another member (for example `fr-FR`), and the base holds no row of that member. The read naming no package already takes the base's address at that member and answers `404`. +**BREAKING** for a caller that saves, publishes or discards a bundled type's item (today `email_template`) without naming a package, where an authored base package holds a stored row of the item at some member (its canonical member, or another one such as `de-DE`), an authored package that declares the base holds a stored row of another, non-canonical member (for example `fr-FR`), and the base holds no row of that member. The read naming no package already takes the base's address at that member and answers `404`. - FROM: the save naming no package (REST `PUT` and in process, `active` mode) rewrote the dependent's row at that member, and the read naming no package then still answered `404` (or `409 RESOURCE_CONFLICT` where the rows had been stored after boot). The `draft` save wrote the dependent's draft; the draft read, per-item publish and draft discard naming no package read, promoted or removed the dependent's draft. - TO: the save naming no package writes the base's row (or, in `draft` mode, the base's draft) at that member, exactly as the same save naming the base (`?package=BASE`, `packageId: BASE`) does; the dependent's row is left byte-unchanged, and the next read naming no package serves the saved content (`200`). The draft read, per-item publish and draft discard naming no package act on the base's draft there. With only the dependent's draft stored at that member, the per-item publish naming no package answers `404 NO_DRAFT` naming that draft, and the draft discard naming no package discards nothing and says which draft remains, as the same requests naming the base answer. -**Not moved.** The canonical member (a base and its dependent both holding it, or only the dependent holding it), two packages neither of which declares the other, a base that ships the name in code, and the delete, history, diff and rollback naming no package at this member. +**Not moved.** The canonical member (a base and its dependent both holding it, or only the dependent holding it), two packages neither of which declares the other, a base that ships the name in code, the delete, history, diff and rollback naming no package at this member, and a package-unbound draft stored at this member with no draft of the dependent beside it (as a draft save naming no package writes it while no package holds the member): the draft read, per-item publish, draft discard and draft save naming no package act on that draft as before (serve it, promote it into the dependent's row, remove it, adopt it into the dependent's draft), and no draft bound to the base is written beside it. The fix for a caller: to change the dependent's row or draft at that member, name the dependent (`?package=DEPENDENT` on the REST door, `packageId` in process). diff --git a/packages/metadata-protocol/src/protocol-save.ts b/packages/metadata-protocol/src/protocol-save.ts index c9d9c3f2268..78610389dd9 100644 --- a/packages/metadata-protocol/src/protocol-save.ts +++ b/packages/metadata-protocol/src/protocol-save.ts @@ -913,8 +913,10 @@ export class ProtocolSaveFacet { // [#35524] …and the same where the active rows at the member are bound // to the one dependent whose addition the read naming no package does // not serve (it takes the base's address there): the base's draft. + // A stored package-unbound draft there keeps its address and is + // adopted, as on `main` (contract review S1). let followedBase: string | undefined; - if (draftAddress !== undefined && (draftAddress.kind === 'ambiguous' || draftAddress.into !== null)) { + if (draftAddress !== undefined && (draftAddress.kind === 'ambiguous' || draftAddressFollowsRowHeldBase(draftAddress))) { const base = await packagelessRowHeldBaseAddress( host, singularType, request.name, itemDiscriminator(singularType, request.item), ); @@ -3316,6 +3318,19 @@ export async function packagelessRowHeldBaseAddress( return address.candidates.includes(base) === address.candidates.length > 1 ? base : undefined; } +/** + * [#35524] Whether a non-ambiguous draft address naming no package is one the + * row-held base's address may replace ({@link packagelessRowHeldBaseAddress}): + * bound to a package by the active rows (`into !== null`), and [contract + * review S1] naming a draft key of a package, not the package-unbound draft + * (`key === null`), which keeps its address. The one predicate the draft + * doors' address ({@link packagelessRowHeldBaseDraftAddress}) and the draft + * save's follow ask, so they cannot part. + */ +export function draftAddressFollowsRowHeldBase(address: { key: string | null; into: string | null }): boolean { + return address.into !== null && address.key !== null; +} + /** * [#35524, epic ruling 6781691009, #34348 ruling (b)] THE DRAFT ADDRESS the * draft doors naming no package take (the draft save, the strict draft read, @@ -3330,8 +3345,18 @@ export async function packagelessRowHeldBaseAddress( * * `pending` (the draft address the stored rows give) itself otherwise: an ambiguous address (the doors ask * {@link packagelessRowHeldBaseAddress} for it themselves, #34681), an address - * not bound to a package by the active rows, and every cell that judgment - * declines. + * not bound to a package by the active rows, every cell that judgment + * declines, and [#35524 contract review S1] an address whose draft is the + * PACKAGE-UNBOUND one (`key === null`: a package-unbound draft stored at the + * member, no draft of the dependent beside it, as a bare draft save at the + * member writes it while no package holds that member). That draft keeps the + * address it has on `main`: the bare draft read serves it, the bare per-item + * publish promotes it into the dependent's row, the bare draft discard + * removes it, and the bare draft save adopts it (the draft save's follow + * declines the same address, {@link draftAddressFollowsRowHeldBase}), never + * a second draft bound to the base beside it. `key`, not `drafts.unbound`: a + * package-unbound draft stored beside the dependent's own draft is not the + * draft the address names (`key` is the dependent's), and that cell moves. * * FROM (`main` a73edb3cd7): the bare draft save wrote the dependent's draft * there and the bare publish promoted it into the dependent's row, while the @@ -3345,7 +3370,7 @@ export async function packagelessRowHeldBaseDraftAddress( pending: ReturnType, ): Promise>> { const address = await pending; - if (address.kind === 'ambiguous' || address.into === null) return address; + if (address.kind === 'ambiguous' || !draftAddressFollowsRowHeldBase(address)) return address; const base = await packagelessRowHeldBaseAddress(host, type, name, member); if (base === undefined) return address; return { kind: address.drafts.candidates.includes(base) ? 'draft' : 'none', key: base, into: base, drafts: address.drafts }; diff --git a/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts b/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts index 795779d7a21..16faf4bd51f 100644 --- a/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts +++ b/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts @@ -251,6 +251,35 @@ describe('[#35524] the bare save at a member only the dependent holds writes the expect(await rowsOf(b.engine, 'dd_own_bare')).toEqual([`active:${WD}:fr-FR:addon fr draft`, `active:${WA}:-:base en`]); }); + it('a package-unbound draft stored at the member (contract review S1): the bare draft read, publish, discard and draft save act on it as on main, never a draft bound to the base', async () => { + // A bare draft save at fr-FR while no package holds that member is + // the package-unbound draft; the dependent's fr-FR row is stored after it. + const lay = async (name: string) => { + await layRow(b.engine, 'email_template', name, WA, template('en-US', 'base en')); + const drafted = await saveFr(b, name, 'unbound fr', { mode: 'draft' }); + expect(drafted.ok, JSON.stringify(drafted)).toBe(true); + await layRow(b.engine, 'email_template', name, WD, template('fr-FR', 'addon fr')); + expect(await rowsOf(b.engine, name)).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, 'draft:null:fr-FR:unbound fr']); + }; + await lay('ud_read'); + const read = await b.protocol.getMetaItem({ type: 'email_template', name: 'ud_read', member: 'fr-FR', state: 'draft' }); + expect([read?.item?.subject, read?.item?._packageId ?? null]).toEqual(['unbound fr', null]); + // The bare draft save adopts the package-unbound draft into the + // package its active row is bound to, as on main: one draft, none + // bound to the base. + const saved = await saveFr(b, 'ud_read', 'unbound fr again', { mode: 'draft' }); + expect(saved.ok, JSON.stringify(saved)).toBe(true); + expect(await rowsOf(b.engine, 'ud_read')).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, `draft:${WD}:fr-FR:unbound fr again`]); + await lay('ud_publish'); + const published = await settle(b.protocol.publishMetaItem({ type: 'email_template', name: 'ud_publish', member: 'fr-FR' })); + expect(published.ok, JSON.stringify(published)).toBe(true); + expect(await rowsOf(b.engine, 'ud_publish')).toEqual([`active:${WD}:fr-FR:unbound fr`, `active:${WA}:-:base en`]); + await lay('ud_discard'); + const discarded = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name: 'ud_discard', member: 'fr-FR', state: 'draft' })); + expect(discarded.ok, JSON.stringify(discarded)).toBe(true); + expect(await rowsOf(b.engine, 'ud_discard')).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`]); + }); + it('a read-only base holding rows: the bare save at the dependent\'s member answers what ?package= answers', async () => { await layCell(b.engine, 'ro_cell', A, D); const bare = await saveFr(b, 'ro_cell', 'edited'); From ae5ffb36abc2af6bed6d48da355d4b9f2f82c6ed Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 10:45:17 +0000 Subject: [PATCH 07/10] test(runtime): one pin per bare draft door over the package-unbound draft at the dependent-only member Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01J8VVAj3FYe91JCMQZPS88h --- ...e-save-dependent-only-member-35524.test.ts | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts b/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts index 16faf4bd51f..9836e40e3bc 100644 --- a/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts +++ b/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts @@ -251,7 +251,7 @@ describe('[#35524] the bare save at a member only the dependent holds writes the expect(await rowsOf(b.engine, 'dd_own_bare')).toEqual([`active:${WD}:fr-FR:addon fr draft`, `active:${WA}:-:base en`]); }); - it('a package-unbound draft stored at the member (contract review S1): the bare draft read, publish, discard and draft save act on it as on main, never a draft bound to the base', async () => { + describe('a package-unbound draft stored at the member (contract review S1): the bare draft doors act on it as on main, never a draft bound to the base', () => { // A bare draft save at fr-FR while no package holds that member is // the package-unbound draft; the dependent's fr-FR row is stored after it. const lay = async (name: string) => { @@ -261,23 +261,33 @@ describe('[#35524] the bare save at a member only the dependent holds writes the await layRow(b.engine, 'email_template', name, WD, template('fr-FR', 'addon fr')); expect(await rowsOf(b.engine, name)).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, 'draft:null:fr-FR:unbound fr']); }; - await lay('ud_read'); - const read = await b.protocol.getMetaItem({ type: 'email_template', name: 'ud_read', member: 'fr-FR', state: 'draft' }); - expect([read?.item?.subject, read?.item?._packageId ?? null]).toEqual(['unbound fr', null]); - // The bare draft save adopts the package-unbound draft into the - // package its active row is bound to, as on main: one draft, none - // bound to the base. - const saved = await saveFr(b, 'ud_read', 'unbound fr again', { mode: 'draft' }); - expect(saved.ok, JSON.stringify(saved)).toBe(true); - expect(await rowsOf(b.engine, 'ud_read')).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, `draft:${WD}:fr-FR:unbound fr again`]); - await lay('ud_publish'); - const published = await settle(b.protocol.publishMetaItem({ type: 'email_template', name: 'ud_publish', member: 'fr-FR' })); - expect(published.ok, JSON.stringify(published)).toBe(true); - expect(await rowsOf(b.engine, 'ud_publish')).toEqual([`active:${WD}:fr-FR:unbound fr`, `active:${WA}:-:base en`]); - await lay('ud_discard'); - const discarded = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name: 'ud_discard', member: 'fr-FR', state: 'draft' })); - expect(discarded.ok, JSON.stringify(discarded)).toBe(true); - expect(await rowsOf(b.engine, 'ud_discard')).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`]); + + it('the bare draft read serves it', async () => { + await lay('ud_read'); + const read = await b.protocol.getMetaItem({ type: 'email_template', name: 'ud_read', member: 'fr-FR', state: 'draft' }); + expect([read?.item?.subject, read?.item?._packageId ?? null]).toEqual(['unbound fr', null]); + }); + + it('the bare draft save adopts it into the package its active row is bound to: one draft, none bound to the base', async () => { + await lay('ud_save'); + const saved = await saveFr(b, 'ud_save', 'unbound fr again', { mode: 'draft' }); + expect(saved.ok, JSON.stringify(saved)).toBe(true); + expect(await rowsOf(b.engine, 'ud_save')).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, `draft:${WD}:fr-FR:unbound fr again`]); + }); + + it('the bare per-item publish promotes it into the dependent\'s row', async () => { + await lay('ud_publish'); + const published = await settle(b.protocol.publishMetaItem({ type: 'email_template', name: 'ud_publish', member: 'fr-FR' })); + expect(published.ok, JSON.stringify(published)).toBe(true); + expect(await rowsOf(b.engine, 'ud_publish')).toEqual([`active:${WD}:fr-FR:unbound fr`, `active:${WA}:-:base en`]); + }); + + it('the bare draft discard removes it', async () => { + await lay('ud_discard'); + const discarded = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name: 'ud_discard', member: 'fr-FR', state: 'draft' })); + expect(discarded.ok, JSON.stringify(discarded)).toBe(true); + expect(await rowsOf(b.engine, 'ud_discard')).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`]); + }); }); it('a read-only base holding rows: the bare save at the dependent\'s member answers what ?package= answers', async () => { From 9cab3d7532bef5ec24ab82a46c4c00d47f72c38f Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 12:40:15 +0000 Subject: [PATCH 08/10] fix(metadata-protocol): move the package-unbound draft at the dependent-only member to the base's draft address The bare draft doors and the draft save's follow take the row-held base's draft address over a stored package-unbound draft too, so the bare draft save writes the base's draft (the package-unbound draft untouched) and the bare draft read reads back what was saved. The bare draft discard with no base draft answers the receipt the discard naming the base answers, naming the package-unbound draft still stored. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01J8VVAj3FYe91JCMQZPS88h --- .../src/protocol-diff-delete-load.ts | 22 +++++- .../metadata-protocol/src/protocol-save.ts | 70 ++++++++++++------- 2 files changed, 63 insertions(+), 29 deletions(-) diff --git a/packages/metadata-protocol/src/protocol-diff-delete-load.ts b/packages/metadata-protocol/src/protocol-diff-delete-load.ts index 5918215eaf7..1c2294d6482 100644 --- a/packages/metadata-protocol/src/protocol-diff-delete-load.ts +++ b/packages/metadata-protocol/src/protocol-diff-delete-load.ts @@ -789,13 +789,29 @@ export class ProtocolDiffDeleteLoadFacet { // below nor its "already at artifact default" / "nothing to // delete" claim holds. A delete naming none never lands here: // it addresses a row the read above found. - if (!current && request.packageId != null && (rowsAtAddress.candidates.length > 0 || rowsAtAddress.unbound)) { + // + // [#35524, epic ruling 6781691009, contract review S2 option + // (b)] …and a draft discard naming no package at the row-held + // base's draft address over a stored package-unbound draft + // ({@link packagelessRowHeldBaseDraftAddress}): it addresses the + // base's draft, as the discard naming the base does, so with no + // base draft it answers that discard's receipt, naming the + // package-unbound draft still stored, never "No pending draft" + // while one is. Only that address is `none` with a + // package-unbound draft stored: `packagelessDraftAddress` makes + // a stored package-unbound draft the address itself (`draft`, + // key `null`) wherever it does not move to a base. + const receiptPackageId = request.packageId + ?? (draftAddress?.kind === 'none' && draftAddress.into !== null && rowsAtAddress.unbound + ? draftAddress.into + : null); + if (!current && receiptPackageId != null && (rowsAtAddress.candidates.length > 0 || rowsAtAddress.unbound)) { return { success: true, reset: false, message: targetState === 'draft' - ? `No pending draft of ${request.type}/${request.name} is bound to package '${request.packageId}', so nothing was discarded: ${remainingRowsPhrase(rowsAtAddress.candidates, rowsAtAddress.unbound, 'draft')}.` - : `No row of ${request.type}/${request.name} is bound to package '${request.packageId}', so nothing was deleted: ${remainingRowsPhrase(rowsAtAddress.candidates, rowsAtAddress.unbound, 'row')}.`, + ? `No pending draft of ${request.type}/${request.name} is bound to package '${receiptPackageId}', so nothing was discarded: ${remainingRowsPhrase(rowsAtAddress.candidates, rowsAtAddress.unbound, 'draft')}.` + : `No row of ${request.type}/${request.name} is bound to package '${receiptPackageId}', so nothing was deleted: ${remainingRowsPhrase(rowsAtAddress.candidates, rowsAtAddress.unbound, 'row')}.`, }; } // [#23495] …and a draft discard naming no package, of an item diff --git a/packages/metadata-protocol/src/protocol-save.ts b/packages/metadata-protocol/src/protocol-save.ts index 78610389dd9..2c49e5ac9f3 100644 --- a/packages/metadata-protocol/src/protocol-save.ts +++ b/packages/metadata-protocol/src/protocol-save.ts @@ -912,9 +912,13 @@ export class ProtocolSaveFacet { // naming it is, an id no installed package has refused `422`. // [#35524] …and the same where the active rows at the member are bound // to the one dependent whose addition the read naming no package does - // not serve (it takes the base's address there): the base's draft. - // A stored package-unbound draft there keeps its address and is - // adopted, as on `main` (contract review S1). + // not serve (it takes the base's address there): the base's draft, + // also over a stored package-unbound draft there (epic ruling + // 6781691009, contract review S2 option (b)). The named base is passed + // down, so the repository's orphan-draft adoption (a save naming no + // package) does not run: the package-unbound draft stays untouched, as + // the save naming the base leaves it, and the draft the next bare + // draft read, publish and discard reach is the one written here. let followedBase: string | undefined; if (draftAddress !== undefined && (draftAddress.kind === 'ambiguous' || draftAddressFollowsRowHeldBase(draftAddress))) { const base = await packagelessRowHeldBaseAddress( @@ -3321,14 +3325,21 @@ export async function packagelessRowHeldBaseAddress( /** * [#35524] Whether a non-ambiguous draft address naming no package is one the * row-held base's address may replace ({@link packagelessRowHeldBaseAddress}): - * bound to a package by the active rows (`into !== null`), and [contract - * review S1] naming a draft key of a package, not the package-unbound draft - * (`key === null`), which keeps its address. The one predicate the draft - * doors' address ({@link packagelessRowHeldBaseDraftAddress}) and the draft - * save's follow ask, so they cannot part. + * bound to a package by the active rows (`into !== null`), whatever draft it + * names, the dependent's or [contract review S2 option (b)] the + * package-unbound one (`key === null`). Epic ruling 6781691009, "a write + * resolves its address exactly as the read at the same address resolves it": + * the read naming no package takes the base's address at that member however + * the drafts there are stored, so the draft save and the other draft doors + * take it too. Keeping the package-unbound draft's own address there (the + * contract review S1 option (a) this replaces) let the bare draft save adopt + * that draft into the dependent, after which the bare draft read missed the + * draft just saved. The one predicate the draft doors' address + * ({@link packagelessRowHeldBaseDraftAddress}) and the draft save's follow + * ask, so they cannot part. */ -export function draftAddressFollowsRowHeldBase(address: { key: string | null; into: string | null }): boolean { - return address.into !== null && address.key !== null; +export function draftAddressFollowsRowHeldBase(address: { into: string | null }): boolean { + return address.into !== null; } /** @@ -3343,24 +3354,31 @@ export function draftAddressFollowsRowHeldBase(address: { key: string | null; in * draft the bare draft read, publish and discard act on, and the dependent's * draft is read, published and discarded at its own `?package=`. * - * `pending` (the draft address the stored rows give) itself otherwise: an ambiguous address (the doors ask - * {@link packagelessRowHeldBaseAddress} for it themselves, #34681), an address - * not bound to a package by the active rows, every cell that judgment - * declines, and [#35524 contract review S1] an address whose draft is the - * PACKAGE-UNBOUND one (`key === null`: a package-unbound draft stored at the - * member, no draft of the dependent beside it, as a bare draft save at the - * member writes it while no package holds that member). That draft keeps the - * address it has on `main`: the bare draft read serves it, the bare per-item - * publish promotes it into the dependent's row, the bare draft discard - * removes it, and the bare draft save adopts it (the draft save's follow - * declines the same address, {@link draftAddressFollowsRowHeldBase}), never - * a second draft bound to the base beside it. `key`, not `drafts.unbound`: a - * package-unbound draft stored beside the dependent's own draft is not the - * draft the address names (`key` is the dependent's), and that cell moves. + * [#35524 contract review S2 option (b), epic ruling 6781691009] That + * includes a PACKAGE-UNBOUND draft stored at the member (`key === null`: no + * draft of the dependent beside it, as a bare draft save at the member writes + * it while no package holds that member): the address is still the base's + * (`none` until the base holds a draft there), because the read naming no + * package takes the base's address there however the drafts are stored. So + * the bare draft save writes the base's draft (the package-unbound draft is + * left untouched, as the save naming the base leaves it), the bare draft read + * reads back what it saved, the bare per-item publish promotes the base's + * draft, and the bare draft discard with no base draft answers as the discard + * naming the base does, naming the remaining package-unbound draft + * (`protocol-diff-delete-load.ts`). No bare draft door at this member acts + * on the package-unbound draft any more, exactly as no door naming the base + * does; the discard's receipt names it as still stored. + * + * `pending` (the draft address the stored rows give) itself otherwise: an + * ambiguous address (the doors ask {@link packagelessRowHeldBaseAddress} for + * it themselves, #34681), an address not bound to a package by the active + * rows ({@link draftAddressFollowsRowHeldBase}), and every cell that judgment + * declines. * * FROM (`main` a73edb3cd7): the bare draft save wrote the dependent's draft - * there and the bare publish promoted it into the dependent's row, while the - * bare read at the member answered 404 (the base's address). + * there (or adopted a stored package-unbound draft into the dependent) and + * the bare publish promoted it into the dependent's row, while the bare read + * at the member answered 404 (the base's address). */ export async function packagelessRowHeldBaseDraftAddress( host: Pick, From 4f232bf2d850411ba8c5ef85bc3b3769e35a4740 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 12:40:15 +0000 Subject: [PATCH 09/10] test(runtime): pin the bare draft doors over the package-unbound draft at the base's draft address The changeset moves that sub-cell from "Not moved" into its FROM/TO. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01J8VVAj3FYe91JCMQZPS88h --- ...bare-save-follows-base-dependent-member.md | 4 +- ...e-save-dependent-only-member-35524.test.ts | 84 ++++++++++++++----- 2 files changed, 65 insertions(+), 23 deletions(-) diff --git a/.changeset/35524-bare-save-follows-base-dependent-member.md b/.changeset/35524-bare-save-follows-base-dependent-member.md index 7bcda353740..27c7dbb6e7a 100644 --- a/.changeset/35524-bare-save-follows-base-dependent-member.md +++ b/.changeset/35524-bare-save-follows-base-dependent-member.md @@ -13,7 +13,9 @@ Metadata-protocol: none - FROM: the save naming no package (REST `PUT` and in process, `active` mode) rewrote the dependent's row at that member, and the read naming no package then still answered `404` (or `409 RESOURCE_CONFLICT` where the rows had been stored after boot). The `draft` save wrote the dependent's draft; the draft read, per-item publish and draft discard naming no package read, promoted or removed the dependent's draft. - TO: the save naming no package writes the base's row (or, in `draft` mode, the base's draft) at that member, exactly as the same save naming the base (`?package=BASE`, `packageId: BASE`) does; the dependent's row is left byte-unchanged, and the next read naming no package serves the saved content (`200`). The draft read, per-item publish and draft discard naming no package act on the base's draft there. With only the dependent's draft stored at that member, the per-item publish naming no package answers `404 NO_DRAFT` naming that draft, and the draft discard naming no package discards nothing and says which draft remains, as the same requests naming the base answer. +- FROM, a package-unbound draft stored at that member (as a `draft` save naming no package writes it while no package holds the member) with no draft of the dependent beside it: the draft read naming no package served that draft, the per-item publish naming no package promoted it into the dependent's row, the draft discard naming no package removed it, and the `draft` save naming no package adopted it into the dependent's draft, after which the draft doors naming no package still acted on it. +- TO, at that sub-cell: the `draft` save naming no package writes the base's draft beside the package-unbound one and leaves the package-unbound draft untouched, as the save naming the base does; the draft read naming no package then reads back what was saved; the per-item publish naming no package promotes the base's draft into the base's row; a second `draft` save naming no package updates the base's draft (no second draft). With no base draft stored, the per-item publish naming no package answers `404 NO_DRAFT` and the draft discard naming no package discards nothing and names the package-unbound draft as still stored, exactly as the same requests naming the base answer. No door naming no package acts on the package-unbound draft at that member any more, as no door naming the base does. -**Not moved.** The canonical member (a base and its dependent both holding it, or only the dependent holding it), two packages neither of which declares the other, a base that ships the name in code, the delete, history, diff and rollback naming no package at this member, and a package-unbound draft stored at this member with no draft of the dependent beside it (as a draft save naming no package writes it while no package holds the member): the draft read, per-item publish, draft discard and draft save naming no package act on that draft as before (serve it, promote it into the dependent's row, remove it, adopt it into the dependent's draft), and no draft bound to the base is written beside it. +**Not moved.** The canonical member (a base and its dependent both holding it, or only the dependent holding it), two packages neither of which declares the other, a base that ships the name in code, and the delete, history, diff and rollback naming no package at this member. The fix for a caller: to change the dependent's row or draft at that member, name the dependent (`?package=DEPENDENT` on the REST door, `packageId` in process). diff --git a/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts b/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts index 9836e40e3bc..f30414c249c 100644 --- a/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts +++ b/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts @@ -15,8 +15,13 @@ // the draft discard) take the same draft address, so the draft a bare draft // save writes is the one they read, promote and discard; at this cell the // dependent's own draft is reached at its own `?package=`, as the request -// naming WA answers. Driven on a booted kernel (the real protocol, metadata -// service, registry and `sys_metadata` store). +// naming WA answers. A package-unbound draft stored at `fr-FR` before WD's +// row moves too (contract review S2 option (b)): the bare draft save writes +// WA's draft beside it and leaves it untouched, the bare draft read reads back +// what was saved, the bare publish promotes WA's draft, and with no WA draft +// the bare publish and discard answer as `?package=WA` does. Driven on a +// booted kernel (the real protocol, metadata service, registry and +// `sys_metadata` store). // // FROM (`main` a73edb3cd7, measured through these doors): the bare read at // `fr-FR` answered 404, the bare save answered 200 and rewrote WD's row, and @@ -25,7 +30,9 @@ // the registry then named WD the holder) where the rows were stored after // boot. The bare draft save wrote WD's draft, the bare draft read served it, // and the bare publish promoted it into WD's row; the bare publish and -// discard of WD's draft promoted or removed it. +// discard of WD's draft promoted or removed it. Over a stored package-unbound +// draft, the bare draft doors served, promoted (into WD's row) or removed it, +// and the bare draft save adopted it into WD's draft. // // Measured beside it, pinned as they read: the canonical member a base and // its dependent both hold (the #34681 cell) and the canonical member only the @@ -251,7 +258,7 @@ describe('[#35524] the bare save at a member only the dependent holds writes the expect(await rowsOf(b.engine, 'dd_own_bare')).toEqual([`active:${WD}:fr-FR:addon fr draft`, `active:${WA}:-:base en`]); }); - describe('a package-unbound draft stored at the member (contract review S1): the bare draft doors act on it as on main, never a draft bound to the base', () => { + describe('a package-unbound draft stored at the member (contract review S2 option (b)): the bare draft doors take the base\'s draft address, as ?package= does', () => { // A bare draft save at fr-FR while no package holds that member is // the package-unbound draft; the dependent's fr-FR row is stored after it. const lay = async (name: string) => { @@ -261,32 +268,65 @@ describe('[#35524] the bare save at a member only the dependent holds writes the await layRow(b.engine, 'email_template', name, WD, template('fr-FR', 'addon fr')); expect(await rowsOf(b.engine, name)).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, 'draft:null:fr-FR:unbound fr']); }; + const draftRead = async (name: string, extra: Record = {}) => { + const read = await b.protocol.getMetaItem({ type: 'email_template', name, member: 'fr-FR', state: 'draft', ...extra }); + return [read?.item?.subject, read?.item?._packageId ?? null]; + }; + const discardOf = (name: string, extra: Record = {}) => b.protocol.deleteMetaItem({ type: 'email_template', name, member: 'fr-FR', state: 'draft', ...extra }).then( + (r: any) => ({ success: r?.success, reset: r?.reset, message: String(r?.message ?? '').replaceAll(name, 'NAME') }), + (e: any) => ({ code: e?.code, status: e?.status ?? e?.httpStatus }), + ); - it('the bare draft read serves it', async () => { - await lay('ud_read'); - const read = await b.protocol.getMetaItem({ type: 'email_template', name: 'ud_read', member: 'fr-FR', state: 'draft' }); - expect([read?.item?.subject, read?.item?._packageId ?? null]).toEqual(['unbound fr', null]); - }); - - it('the bare draft save adopts it into the package its active row is bound to: one draft, none bound to the base', async () => { + it('the bare draft save writes the base\'s draft beside the package-unbound one (untouched), and the bare draft read reads back what it saved', async () => { await lay('ud_save'); - const saved = await saveFr(b, 'ud_save', 'unbound fr again', { mode: 'draft' }); + await lay('ud_save_named'); + const saved = await saveFr(b, 'ud_save', 'saved fr', { mode: 'draft' }); + const named = await saveFr(b, 'ud_save_named', 'saved fr', { mode: 'draft', packageId: WA }); expect(saved.ok, JSON.stringify(saved)).toBe(true); - expect(await rowsOf(b.engine, 'ud_save')).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, `draft:${WD}:fr-FR:unbound fr again`]); + expect(named.ok, JSON.stringify(named)).toBe(true); + expect(await rowsOf(b.engine, 'ud_save')).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, `draft:${WA}:fr-FR:saved fr`, 'draft:null:fr-FR:unbound fr']); + expect(await shapeOf(b.engine, 'ud_save')).toEqual(await shapeOf(b.engine, 'ud_save_named')); + expect(await draftRead('ud_save')).toEqual(['saved fr', WA]); + expect(await draftRead('ud_save')).toEqual(await draftRead('ud_save', { packageId: WA })); }); - it('the bare per-item publish promotes it into the dependent\'s row', async () => { - await lay('ud_publish'); - const published = await settle(b.protocol.publishMetaItem({ type: 'email_template', name: 'ud_publish', member: 'fr-FR' })); - expect(published.ok, JSON.stringify(published)).toBe(true); - expect(await rowsOf(b.engine, 'ud_publish')).toEqual([`active:${WD}:fr-FR:unbound fr`, `active:${WA}:-:base en`]); + it('the bare per-item publish after that save promotes the base\'s draft, as ?package= does', async () => { + const seen: Record = {}; + for (const [label, at] of [['bare', {}], ['named', { packageId: WA }]] as const) { + const name = `ud_publish_${label}`; + await lay(name); + expect((await saveFr(b, name, 'saved fr', { mode: 'draft' })).ok).toBe(true); + const published = await settle(b.protocol.publishMetaItem({ type: 'email_template', name, member: 'fr-FR', ...at })); + seen[label] = { published: published.code !== undefined ? [published.code, published.status] : ['ok', published.ok], rows: await shapeOf(b.engine, name) }; + } + expect(seen.bare, JSON.stringify(seen)).toEqual(seen.named); + expect(seen.bare).toEqual({ published: ['ok', true], rows: [`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, `active:${WA}:fr-FR:saved fr`, 'draft:null:fr-FR:unbound fr'] }); + expect(await bareRead(b, 'ud_publish_bare', fr)).toEqual([200, 'saved fr', WA]); }); - it('the bare draft discard removes it', async () => { + it('with no base draft, the bare per-item publish and draft discard answer as the requests naming the base do, the discard naming the package-unbound draft still stored', async () => { await lay('ud_discard'); - const discarded = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name: 'ud_discard', member: 'fr-FR', state: 'draft' })); - expect(discarded.ok, JSON.stringify(discarded)).toBe(true); - expect(await rowsOf(b.engine, 'ud_discard')).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`]); + await lay('ud_discard_named'); + const publishOf = (name: string, extra: Record = {}) => settle(b.protocol.publishMetaItem({ type: 'email_template', name, member: 'fr-FR', ...extra })) + .then((r: any) => [r.code, r.status]); + const barePublish = await publishOf('ud_discard'); + expect(barePublish).toEqual(await publishOf('ud_discard_named', { packageId: WA })); + expect(barePublish).toEqual(['NO_DRAFT', 404]); + const bare = await discardOf('ud_discard'); + const named = await discardOf('ud_discard_named', { packageId: WA }); + expect(bare).toEqual(named); + expect([bare.success, bare.reset]).toEqual([true, false]); + expect(await rowsOf(b.engine, 'ud_discard')).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, 'draft:null:fr-FR:unbound fr']); + expect(await shapeOf(b.engine, 'ud_discard')).toEqual(await shapeOf(b.engine, 'ud_discard_named')); + }); + + it('a second bare draft save updates the base\'s draft and writes no second draft', async () => { + await lay('ud_resave'); + expect((await saveFr(b, 'ud_resave', 'saved fr', { mode: 'draft' })).ok).toBe(true); + const again = await saveFr(b, 'ud_resave', 'saved fr again', { mode: 'draft' }); + expect(again.ok, JSON.stringify(again)).toBe(true); + expect(await rowsOf(b.engine, 'ud_resave')).toEqual([`active:${WD}:fr-FR:addon fr`, `active:${WA}:-:base en`, `draft:${WA}:fr-FR:saved fr again`, 'draft:null:fr-FR:unbound fr']); + expect(await draftRead('ud_resave')).toEqual(['saved fr again', WA]); }); }); From 344fc148d28a5cbbb1ad4ba7cddcdca97d372a17 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 13:53:13 +0000 Subject: [PATCH 10/10] docs(metadata-protocol): say the bare draft read still serves the package-unbound draft with no base draft Measured: with no base draft at the member, the draft read naming no package and the one naming the base both serve the package-unbound draft. The wrapper's docblock and the changeset said no door acted on it; the pin now holds the bare read equal to the named one. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01J8VVAj3FYe91JCMQZPS88h --- .../35524-bare-save-follows-base-dependent-member.md | 2 +- packages/metadata-protocol/src/protocol-save.ts | 7 ++++--- .../meta-bare-save-dependent-only-member-35524.test.ts | 7 +++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.changeset/35524-bare-save-follows-base-dependent-member.md b/.changeset/35524-bare-save-follows-base-dependent-member.md index 27c7dbb6e7a..7107298b491 100644 --- a/.changeset/35524-bare-save-follows-base-dependent-member.md +++ b/.changeset/35524-bare-save-follows-base-dependent-member.md @@ -14,7 +14,7 @@ Metadata-protocol: none - FROM: the save naming no package (REST `PUT` and in process, `active` mode) rewrote the dependent's row at that member, and the read naming no package then still answered `404` (or `409 RESOURCE_CONFLICT` where the rows had been stored after boot). The `draft` save wrote the dependent's draft; the draft read, per-item publish and draft discard naming no package read, promoted or removed the dependent's draft. - TO: the save naming no package writes the base's row (or, in `draft` mode, the base's draft) at that member, exactly as the same save naming the base (`?package=BASE`, `packageId: BASE`) does; the dependent's row is left byte-unchanged, and the next read naming no package serves the saved content (`200`). The draft read, per-item publish and draft discard naming no package act on the base's draft there. With only the dependent's draft stored at that member, the per-item publish naming no package answers `404 NO_DRAFT` naming that draft, and the draft discard naming no package discards nothing and says which draft remains, as the same requests naming the base answer. - FROM, a package-unbound draft stored at that member (as a `draft` save naming no package writes it while no package holds the member) with no draft of the dependent beside it: the draft read naming no package served that draft, the per-item publish naming no package promoted it into the dependent's row, the draft discard naming no package removed it, and the `draft` save naming no package adopted it into the dependent's draft, after which the draft doors naming no package still acted on it. -- TO, at that sub-cell: the `draft` save naming no package writes the base's draft beside the package-unbound one and leaves the package-unbound draft untouched, as the save naming the base does; the draft read naming no package then reads back what was saved; the per-item publish naming no package promotes the base's draft into the base's row; a second `draft` save naming no package updates the base's draft (no second draft). With no base draft stored, the per-item publish naming no package answers `404 NO_DRAFT` and the draft discard naming no package discards nothing and names the package-unbound draft as still stored, exactly as the same requests naming the base answer. No door naming no package acts on the package-unbound draft at that member any more, as no door naming the base does. +- TO, at that sub-cell: the `draft` save naming no package writes the base's draft beside the package-unbound one and leaves the package-unbound draft untouched, as the save naming the base does; the draft read naming no package then reads back what was saved; the per-item publish naming no package promotes the base's draft into the base's row; a second `draft` save naming no package updates the base's draft (no second draft). With no base draft stored, the per-item publish naming no package answers `404 NO_DRAFT` and the draft discard naming no package discards nothing and names the package-unbound draft as still stored, exactly as the same requests naming the base answer. With no base draft stored, the draft read naming no package still serves the package-unbound draft, as the draft read naming the base does; once the base's draft is saved, both read the base's draft. **Not moved.** The canonical member (a base and its dependent both holding it, or only the dependent holding it), two packages neither of which declares the other, a base that ships the name in code, and the delete, history, diff and rollback naming no package at this member. diff --git a/packages/metadata-protocol/src/protocol-save.ts b/packages/metadata-protocol/src/protocol-save.ts index 2c49e5ac9f3..6c4d09bb3b0 100644 --- a/packages/metadata-protocol/src/protocol-save.ts +++ b/packages/metadata-protocol/src/protocol-save.ts @@ -3365,9 +3365,10 @@ export function draftAddressFollowsRowHeldBase(address: { into: string | null }) * reads back what it saved, the bare per-item publish promotes the base's * draft, and the bare draft discard with no base draft answers as the discard * naming the base does, naming the remaining package-unbound draft - * (`protocol-diff-delete-load.ts`). No bare draft door at this member acts - * on the package-unbound draft any more, exactly as no door naming the base - * does; the discard's receipt names it as still stored. + * (`protocol-diff-delete-load.ts`). With no base draft there, the bare draft + * read still serves the package-unbound draft, as the draft read naming the + * base does, while the bare publish and discard leave it stored, as the + * requests naming the base do. * * `pending` (the draft address the stored rows give) itself otherwise: an * ambiguous address (the doors ask {@link packagelessRowHeldBaseAddress} for diff --git a/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts b/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts index f30414c249c..d7f37580b79 100644 --- a/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts +++ b/packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts @@ -19,7 +19,7 @@ // row moves too (contract review S2 option (b)): the bare draft save writes // WA's draft beside it and leaves it untouched, the bare draft read reads back // what was saved, the bare publish promotes WA's draft, and with no WA draft -// the bare publish and discard answer as `?package=WA` does. Driven on a +// the bare draft read, publish and discard answer as `?package=WA` does. Driven on a // booted kernel (the real protocol, metadata service, registry and // `sys_metadata` store). // @@ -304,11 +304,14 @@ describe('[#35524] the bare save at a member only the dependent holds writes the expect(await bareRead(b, 'ud_publish_bare', fr)).toEqual([200, 'saved fr', WA]); }); - it('with no base draft, the bare per-item publish and draft discard answer as the requests naming the base do, the discard naming the package-unbound draft still stored', async () => { + it('with no base draft, the bare draft read, per-item publish and draft discard answer as the requests naming the base do, the discard naming the package-unbound draft still stored', async () => { await lay('ud_discard'); await lay('ud_discard_named'); const publishOf = (name: string, extra: Record = {}) => settle(b.protocol.publishMetaItem({ type: 'email_template', name, member: 'fr-FR', ...extra })) .then((r: any) => [r.code, r.status]); + // The draft read with no base draft serves the package-unbound draft, bare as named. + expect(await draftRead('ud_discard')).toEqual(await draftRead('ud_discard_named', { packageId: WA })); + expect(await draftRead('ud_discard')).toEqual(['unbound fr', null]); const barePublish = await publishOf('ud_discard'); expect(barePublish).toEqual(await publishOf('ud_discard_named', { packageId: WA })); expect(barePublish).toEqual(['NO_DRAFT', 404]);