From 91d7741ca2ce65499c8474e3c54ee7ca437dd764 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 08:45:19 +0000 Subject: [PATCH 01/14] =?UTF-8?q?wip(#39536):=20picklist=5Fextension=20sto?= =?UTF-8?q?red=20item=20=E2=80=94=20spec=20row,=20registry=20replace/withd?= =?UTF-8?q?raw,=20doors,=20syncs,=20export,=20pair=20install?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_01L9qibxE6RdcamcqFHHa7PC Co-authored-by: Claude --- ...tplace-install-local-customization-pair.ts | 16 +- .../src/protocol-authoring-gate.ts | 10 +- .../src/protocol-history-and-publish.ts | 14 + .../src/protocol-meta-type-schema.ts | 4 + .../src/protocol-object-extension-item.ts | 4 + .../src/protocol-picklist-extension-item.ts | 280 ++++++++++++++++++ .../src/protocol-registry-hydration.ts | 41 ++- .../metadata-protocol/src/protocol-save.ts | 17 ++ packages/metadata-protocol/src/protocol.ts | 2 + packages/objectql/src/registry-picklists.ts | 72 +++++ packages/objectql/src/registry-revision.ts | 4 + packages/objectql/src/registry.ts | 56 +++- packages/runtime/src/domains/packages.ts | 10 +- .../spec/src/kernel/customization-package.ts | 4 + .../spec/src/kernel/metadata-plugin.zod.ts | 14 + 15 files changed, 539 insertions(+), 9 deletions(-) create mode 100644 packages/metadata-protocol/src/protocol-picklist-extension-item.ts diff --git a/packages/cloud-connection/src/marketplace-install-local-customization-pair.ts b/packages/cloud-connection/src/marketplace-install-local-customization-pair.ts index e2d706a2a61..73bf7770c72 100644 --- a/packages/cloud-connection/src/marketplace-install-local-customization-pair.ts +++ b/packages/cloud-connection/src/marketplace-install-local-customization-pair.ts @@ -38,6 +38,8 @@ * - `objectExtensions`, each one an `object_extension` item named by the * object it extends (ADR-0146 D10; the export reads the pair back the same * way, `packages/runtime/src/domains/packages.ts`); + * - `picklistExtensions`, each one a `picklist_extension` item named by the + * list it extends (#39536, the same pairing); * - the package's own keys, classified by `UNMANAGED_INSTALL_KEY_DISPOSITIONS` * (`@objectstack/spec/kernel`), the one table of a package body's * non-collection keys: `identity` / `base` keys describe the package, `door` @@ -70,6 +72,14 @@ import { ASSEMBLED_VIEW_ITEMS_KEY, deriveViewContainerObject, isAggregatedViewCo export const PAIR_OBJECT_EXTENSIONS_KEY = 'objectExtensions'; export const PAIR_OBJECT_EXTENSION_TYPE = 'object_extension'; +/** + * [#39536] …and the twin pair for a shared list: a pair's `picklist_extension` + * items travel as its `picklistExtensions`, one entry per target list, each + * named by the list it extends. + */ +export const PAIR_PICKLIST_EXTENSIONS_KEY = 'picklistExtensions'; +export const PAIR_PICKLIST_EXTENSION_TYPE = 'picklist_extension'; + /** One item a pair install writes, in write order. */ export interface PairInstallItem { /** Canonical (singular) metadata type. */ @@ -108,7 +118,7 @@ function loadOrderOf(type: string): number { /** The name an item of `type` is saved under, or `undefined` when it carries none. */ function itemNameOf(type: string, item: Record): string | undefined { - if (type === PAIR_OBJECT_EXTENSION_TYPE) { + if (type === PAIR_OBJECT_EXTENSION_TYPE || type === PAIR_PICKLIST_EXTENSION_TYPE) { return typeof item.extend === 'string' && item.extend !== '' ? item.extend : undefined; } if (type === 'view' && (isAggregatedViewContainer(item) || item.name === undefined)) { @@ -132,7 +142,9 @@ export function planCustomizationPairInstall(body: Record): Pai ? 'view' : key === PAIR_OBJECT_EXTENSIONS_KEY ? PAIR_OBJECT_EXTENSION_TYPE - : (Object.prototype.hasOwnProperty.call(PLURAL_TO_SINGULAR, key) ? PLURAL_TO_SINGULAR[key] : undefined); + : key === PAIR_PICKLIST_EXTENSIONS_KEY + ? PAIR_PICKLIST_EXTENSION_TYPE + : (Object.prototype.hasOwnProperty.call(PLURAL_TO_SINGULAR, key) ? PLURAL_TO_SINGULAR[key] : undefined); if (type === undefined) { if (!unmanagedInstallValueCarries(value)) return; const disposition = Object.prototype.hasOwnProperty.call(UNMANAGED_INSTALL_KEY_DISPOSITIONS, key) diff --git a/packages/metadata-protocol/src/protocol-authoring-gate.ts b/packages/metadata-protocol/src/protocol-authoring-gate.ts index b86d8df6e0d..ddf1a443f59 100644 --- a/packages/metadata-protocol/src/protocol-authoring-gate.ts +++ b/packages/metadata-protocol/src/protocol-authoring-gate.ts @@ -49,6 +49,8 @@ import type { ObjectStackProtocolImplementation } from './protocol.js'; import { permissionSetOwnerBindingRefusal, runtimeHookWithoutBodyRefusal } from './protocol.js'; import { objectBodyExtensionFieldSuffixRefusal } from './protocol-extension-field-suffix.js'; +import { picklistExtensionItemRefusal } from './protocol-picklist-extension-item.js'; +import type { PicklistExtensionRegistry } from './protocol-picklist-extension-item.js'; import { datasourceCredentialsRefSaveRefusal } from './protocol-datasource-credentials-ref.js'; import { storedFlowVerdictBody } from './protocol-flow-save-replay.js'; import { withoutPlatformOrigin } from '@objectstack/metadata'; @@ -125,7 +127,7 @@ export function restoredBodyDerivation( /** The body of `ObjectStackProtocolImplementation#restoredBodyWriter`; the method's docblock there is its contract. */ export function restoredBodyWriter( - this: Pick, + this: Pick, type: string, name: string, binding: string | null, source: string): (historyBody: unknown) => Promise { const derive = this.restoredBodyDerivation(type); return async (historyBody) => { @@ -139,6 +141,12 @@ export function restoredBodyWriter( // [#28574] An `object_extension` version against its address, on the same binding. const extensionRefusal = this.objectExtensionItemRefusal(type, historyBody, name, binding); if (extensionRefusal) throw extensionRefusal; + // [#39536] …and a `picklist_extension` version, against the list as it stands now. + const picklistRefusal = picklistExtensionItemRefusal(PLURAL_TO_SINGULAR[type] ?? type, { + item: historyBody, name, binding, + registry: (this.engine as { registry?: PicklistExtensionRegistry } | undefined)?.registry, + }); + if (picklistRefusal) throw picklistRefusal; // [ADR-0159 card ② items 5 and 7] …and the save door's two `form`-type // refusals: a package-less view whose restored body would store a list // at the name a read-only package authors as a `form` diff --git a/packages/metadata-protocol/src/protocol-history-and-publish.ts b/packages/metadata-protocol/src/protocol-history-and-publish.ts index a7596a37f57..473cc4cd5e7 100644 --- a/packages/metadata-protocol/src/protocol-history-and-publish.ts +++ b/packages/metadata-protocol/src/protocol-history-and-publish.ts @@ -69,6 +69,8 @@ import { historySlotOf, refusePackageSelectorOutsideSlottedTypes } from './proto import { captureStoredExpressionChange, fillStoredExpressionChange, type StoredExpressionFillCapture } from './protocol-stored-expression-fill.js'; import { OBJECT_REGISTRY_REFUSED, reportObjectRegistryRefusal } from './protocol-registry-hydration.js'; import { OBJECT_EXTENSION_TYPE, registrableObjectExtension } from './protocol-object-extension-item.js'; +import { picklistExtensionItemRefusal } from './protocol-picklist-extension-item.js'; +import type { PicklistExtensionRegistry } from './protocol-picklist-extension-item.js'; import { promotedObjectDraftSpecRefusal } from './protocol-promoted-draft-spec-refusal.js'; import { retireOverlayCacheOnRollback } from './meta-overlay-cache.js'; @@ -1217,6 +1219,18 @@ export class ProtocolHistoryAndPublishFacet { ); if (extensionRefusal) throw extensionRefusal; } + // [#39536] …and a `picklist_extension` draft, judged against the list + // as it stands at publish: another package may have added one of its + // values since the draft was saved. See {@link picklistExtensionItemRefusal}. + if (draftForGate) { + const picklistRefusal = picklistExtensionItemRefusal(singularType, { + item: draftForGate.body, + name: request.name, + binding: promoteInto, + registry: (host.engine as { registry?: PicklistExtensionRegistry } | undefined)?.registry, + }); + if (picklistRefusal) throw picklistRefusal; + } // [ADR-0144 D2 and D6, amended; #33593 ruling R1] …and the follow // door the published save of the same body asks (`saveMetaItem`, the // R1 block beside its own `objectExtensionItemRefusal` call): the diff --git a/packages/metadata-protocol/src/protocol-meta-type-schema.ts b/packages/metadata-protocol/src/protocol-meta-type-schema.ts index 75a0adf3b7d..468ff38b314 100644 --- a/packages/metadata-protocol/src/protocol-meta-type-schema.ts +++ b/packages/metadata-protocol/src/protocol-meta-type-schema.ts @@ -36,6 +36,7 @@ import { OBJECT_EXTENSION_ITEM_SCHEMA, OBJECT_EXTENSION_TYPE, } from './protocol-object-extension-item.js'; +import { PICKLIST_EXTENSION_ITEM_SCHEMA, PICKLIST_EXTENSION_TYPE } from './protocol-picklist-extension-item.js'; /** * Canonical Zod schema per metadata type lives in @@ -568,6 +569,9 @@ function resolveOverlaySchema(type: string, _item: unknown): z.ZodTypeAny | null // (the spec ruling on the card), so its schema is bound here, the door's // own resolver: `ObjectExtensionSchema` over the body without its envelope. if (singular === OBJECT_EXTENSION_TYPE) return OBJECT_EXTENSION_ITEM_SCHEMA as unknown as z.ZodTypeAny; + // [#39536] Its twin `picklist_extension`, for the same reason: + // `PicklistExtensionSchema` over the body without its envelope. + if (singular === PICKLIST_EXTENSION_TYPE) return PICKLIST_EXTENSION_ITEM_SCHEMA as unknown as z.ZodTypeAny; return getMetadataTypeSchema(singular) ?? null; } diff --git a/packages/metadata-protocol/src/protocol-object-extension-item.ts b/packages/metadata-protocol/src/protocol-object-extension-item.ts index 45b5fe2572a..e36c0275bdf 100644 --- a/packages/metadata-protocol/src/protocol-object-extension-item.ts +++ b/packages/metadata-protocol/src/protocol-object-extension-item.ts @@ -91,6 +91,10 @@ export function listSlotNameOf(canonicalType: string, item: unknown): unknown { if (!isRecord(item)) return undefined; if ('name' in item) return item.name; if (canonicalType === OBJECT_EXTENSION_TYPE && typeof item.extend === 'string') return item.extend; + // [#39536] …and its twin, a `picklist_extension` body, slotted under the + // list it extends (`PICKLIST_EXTENSION_TYPE`, spelled here to keep this + // module free of an import cycle with `protocol-picklist-extension-item.ts`). + if (canonicalType === 'picklist_extension' && typeof item.extend === 'string') return item.extend; return undefined; } diff --git a/packages/metadata-protocol/src/protocol-picklist-extension-item.ts b/packages/metadata-protocol/src/protocol-picklist-extension-item.ts new file mode 100644 index 00000000000..9e65a16e2cf --- /dev/null +++ b/packages/metadata-protocol/src/protocol-picklist-extension-item.ts @@ -0,0 +1,280 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [#39536, ruling 7406020670; ADR-0146 D2 / D10] A picklist extension is an + * authorable item of a writable package — the twin of the object-extension + * item (`protocol-object-extension-item.ts`). + * + * A code package's `picklistExtensions` are never stored as items of this + * type: the ObjectQL engine's `registerApp` hands each entry to + * `SchemaRegistry.registerPicklistExtension` with the package id. This type's + * items are the stored rows the `/api/v1/meta` doors write: a customer adds a + * value to an installed package's shared list ("one more lead source") in the + * base's paired `.custom` package, with draft, publish, history, rollback, + * delete and export, the way a field is added to the base's object. The row is + * stored under the writing package with the TARGET list's name as its row + * name — one item per package per target list — and its body is + * `PicklistExtensionSchema` as it stands: `extend` and `options`, no `name`. + * + * The ruling's rider: every value such an item adds ends in `__c` + * (`EXTENSION_FIELD_SUFFIX`, the suffix ADR-0146 D10 reserves for a customer's + * extension fields), refused otherwise at the item's doors. The vendor's next + * version can then never ship a value the customer already holds: the registry + * refuses a list registered after an extension added one of its values + * (`assertPicklistValuesDistinct`), so without the suffix the customer's value + * would block the vendor's upgrade. The option `label` stays free text, so a + * user never sees the suffix. + * + * This module holds what the doors ask that is particular to the type: + * + * - {@link picklistExtensionItemRefusal} — the save / publish / restore gate; + * - {@link registrablePicklistExtension} — the parsed body every sync + * registers as the package's contribution + * (`SchemaRegistry.replacePicklistExtension`). + * + * The body's SHAPE is judged by the doors' own schema gate + * (`resolveOverlaySchema` → {@link PICKLIST_EXTENSION_ITEM_SCHEMA}). What the + * gate here adds is the body against its address and the list it extends, + * `VALIDATION_ERROR` / 400, the envelope of the object-extension item's + * refusals. No code is minted. + */ + +import { z } from 'zod'; +import { PicklistExtensionSchema, EXTENSION_FIELD_SUFFIX, isExtensionFieldName } from '@objectstack/spec/data'; +import { withoutProtectionEnvelope } from './protocol-object-extension-item.js'; +import type { MetadataIssueEntry } from './protocol.js'; + +/** The metadata type of a picklist extension item. */ +export const PICKLIST_EXTENSION_TYPE = 'picklist_extension' as const; + +/** The manifest collection a pair's picklist extensions travel in (export and pair install). */ +export const PICKLIST_EXTENSIONS_KEY = 'picklistExtensions' as const; + +/** + * The schema the doors' shape gate judges a `picklist_extension` body by: + * `PicklistExtensionSchema` itself, strict, over the body with the ADR-0010 + * envelope a read or a loader stamps peeled off (as its twin's). + */ +export const PICKLIST_EXTENSION_ITEM_SCHEMA = z.preprocess(withoutProtectionEnvelope, PicklistExtensionSchema); + +const isRecord = (v: unknown): v is Record => + v !== null && typeof v === 'object' && !Array.isArray(v); + +/** One option as the registry reads it. */ +export interface PicklistExtensionOption { + value?: unknown; + label?: unknown; + [key: string]: unknown; +} + +/** The registry members the gate and the syncs read, reached through the engine. */ +export interface PicklistExtensionRegistry { + /** The list's resolved options from a caller package's closure; `undefined` = no list reachable. */ + resolvePicklistOptions?(name: string, callerPackageId?: string | null): PicklistExtensionOption[] | undefined; + /** The refusal a {@link replacePicklistExtension} of this body would throw, without registering it. */ + picklistExtensionReplacementRefusal?(extension: { extend: string; options: readonly PicklistExtensionOption[] }, packageId: string): Error | undefined; + replacePicklistExtension?(extension: { extend: string; options: readonly PicklistExtensionOption[] }, packageId: string): void; + withdrawPicklistExtension?(name: string, packageId: string): boolean; + /** The packages whose stored (`_provenance: 'org'`) extension of `name` is registered. */ + storedPicklistExtenders?(name: string): string[]; +} + +type GateRefusal = Error & { code: 'VALIDATION_ERROR'; status: 400; issues?: MetadataIssueEntry[] }; + +function refusal(message: string, issues?: ReadonlyArray<{ path: string; message: string }>): GateRefusal { + const err = new Error(message) as GateRefusal; + err.code = 'VALIDATION_ERROR'; + err.status = 400; + if (issues !== undefined && issues.length > 0) err.issues = issues.map((i) => ({ ...i, code: 'custom' })); + return err; +} + +/** What a door hands the gate. */ +export interface PicklistExtensionItemSubject { + /** The body as the door will store it. */ + item: unknown; + /** The row name — the extension's target list. */ + name: string; + /** The RESOLVED package the row is written into (the door's `saveWriteBinding`). */ + binding: string | null | undefined; + /** The engine's registry. Absent ⇒ the list checks are not asked. */ + registry: PicklistExtensionRegistry | undefined; +} + +/** + * The save, publish and restore doors' question for one `picklist_extension` + * body, in order. `undefined` = admitted (or not this type). A body whose + * `extend` or `options` is malformed is left to the schema gate, which refuses + * it with the schema's own sentence. + * + * 1. The row is a package's item: a write bound to no package is refused. + * 2. The row name is the target: `extend` equals the name it is filed under. + * 3. Every value the item adds ends in `__c` (the ruling's rider), each one + * located at `options[i].value`. + * 4. The target list is reachable from the written package: its own list or + * the one holder in its declared dependency closure + * (`resolvePicklistOptions` from the package, the resolver every field's + * reference takes), refused naming the dependency to declare. + * 5. Additive only: no value repeats inside the item, and none is a value the + * list or another package's extension already carries — the registry's own + * refusal (`picklistExtensionReplacementRefusal`, the sentence a sync + * would otherwise throw at registration), asked before anything is stored. + * + * Whether the package is writable is the door's own refusal + * (`WRITABLE_PACKAGE_REQUIRED`), asked before any of this. + */ +export function picklistExtensionItemRefusal( + singularType: string, + subject: PicklistExtensionItemSubject, +): Error | undefined { + if (singularType !== PICKLIST_EXTENSION_TYPE) return undefined; + const { item, name, binding, registry } = subject; + if (!isRecord(item)) return undefined; + + // 1. + if (typeof binding !== 'string' || binding === '') { + return refusal( + `Picklist extension '${name}': a picklist extension is an item of a package, and this write names none. ` + + 'Save it into the writable package it belongs to (`?package=`): for a base\'s list, the base\'s ' + + 'paired `.custom` package.', + ); + } + + // 2. + const target = typeof item.extend === 'string' ? item.extend : undefined; + if (target === undefined) return undefined; + if (target !== name) { + const message = `Picklist extension '${name}' extends '${target}': a picklist extension is stored under the ` + + `name of the list it extends. Save it as '${target}', or set \`extend\` to '${name}'.`; + return refusal(message, [{ path: 'extend', message }]); + } + + // 3. + const options = Array.isArray(item.options) ? item.options : []; + const unsuffixed = options + .map((option, index) => ({ option, index })) + .filter(({ option }) => isRecord(option) && typeof option.value === 'string' && !isExtensionFieldName(option.value)); + if (unsuffixed.length > 0) { + const issues = unsuffixed.map(({ option, index }) => { + const value = String((option as Record).value); + return { + path: `options.${index}.value`, + message: `value '${value}' must end in \`${EXTENSION_FIELD_SUFFIX}\` — spell it '${value}${EXTENSION_FIELD_SUFFIX}'`, + }; + }); + const values = unsuffixed.map(({ option }) => `'${String((option as Record).value)}'`).join(', '); + return refusal( + `Picklist extension '${name}': a value a package adds to another package's list ends in ` + + `\`${EXTENSION_FIELD_SUFFIX}\`, so the list's owner can never ship the same value in a later version — ` + + `${values} ${unsuffixed.length === 1 ? 'does' : 'do'} not. Add the suffix to the value; the label stays ` + + 'as users should read it.', + issues, + ); + } + + if (!registry) return undefined; + + // 4. + if (typeof registry.resolvePicklistOptions === 'function' + && registry.resolvePicklistOptions(target, binding) === undefined) { + const message = `Picklist extension '${name}' in package '${binding}': no picklist named '${target}' is ` + + `reachable from the package — neither its own nor one a package it depends on declares. Name a list an ` + + `installed package declares in \`extend\`, and declare that package in \`${binding}\`'s \`dependencies\`.`; + return refusal(message, [{ path: 'extend', message }]); + } + + // 5. + if (typeof registry.picklistExtensionReplacementRefusal === 'function') { + const registrable = { extend: target, options: options.filter(isRecord) as PicklistExtensionOption[] }; + const duplicate = registry.picklistExtensionReplacementRefusal(registrable, binding); + if (duplicate) return refusal(duplicate.message, [{ path: 'options', message: duplicate.message }]); + } + return undefined; +} + +/** + * The body a sync registers for a stored `picklist_extension` row: the parsed + * body (`PicklistExtensionSchema`, its rewrites applied) with the envelope + * peeled off. Throws `INVALID_METADATA` / 422 for a body the schema refuses, + * so each sync's own per-row handling names it. + */ +export function registrablePicklistExtension(body: unknown): { extend: string; options: PicklistExtensionOption[] } { + const parsed = PICKLIST_EXTENSION_ITEM_SCHEMA.safeParse(body); + if (!parsed.success) { + const first = parsed.error.issues[0]; + const err = new Error( + 'stored picklist extension does not parse as PicklistExtensionSchema' + + (first ? ` (${first.path.join('.') || ''}: ${first.message})` : ''), + ) as Error & { code: string; status: number }; + err.code = 'INVALID_METADATA'; + err.status = 422; + throw err; + } + return parsed.data as { extend: string; options: PicklistExtensionOption[] }; +} + +/** + * Register a stored `picklist_extension` row as its package's contribution to + * the list it names, REPLACING the package's prior one + * (`SchemaRegistry.replacePicklistExtension`): a re-publish that drops a value + * drops it. The one call every sync makes — the write-through, the boot + * hydration and the read-side hydration (`protocol-registry-hydration.ts`). A + * row bound to no package is never registered: the doors refuse to write one. + * + * Throws what the parse or the registry refuses, so each caller's own per-row + * handling names the row. + * + * @returns whether the row was registered. + */ +export function registerStoredPicklistExtension( + registry: PicklistExtensionRegistry | undefined, + body: unknown, + packageId: string | null | undefined, +): boolean { + if (typeof packageId !== 'string' || packageId === '') return false; + if (typeof registry?.replacePicklistExtension !== 'function') return false; + registry.replacePicklistExtension(registrablePicklistExtension(body), packageId); + return true; +} + +/** What {@link resyncStoredPicklistExtensions} reads the store with. */ +export interface StoredPicklistExtensionReads { + /** The ACTIVE `picklist_extension` rows of the list, each with its `package_id`. */ + readonly activeRows: () => Promise> | null | undefined>; + /** A row's stored body, its conversions replayed (`convertStoredItem` over the row's document). */ + readonly bodyOf: (row: Record) => unknown; +} + +/** + * After a `picklist_extension` row of the list `name` is deleted: withdraw + * every stored-row contribution to the list whose row is no longer stored + * (`SchemaRegistry.withdrawPicklistExtension`), and re-register the ones that + * are. A code package's manifest entry for the same list is never touched + * (`storedPicklistExtenders` names stored contributions only). A failed read + * throws before anything is withdrawn: an outage is not an absence. + */ +export async function resyncStoredPicklistExtensions( + registry: PicklistExtensionRegistry | undefined, + name: string, + reads: StoredPicklistExtensionReads, +): Promise { + if (typeof registry?.storedPicklistExtenders !== 'function' || typeof registry.withdrawPicklistExtension !== 'function') return; + const rows = await reads.activeRows(); + const stored = new Map>(); + for (const row of rows ?? []) { + const pkg = typeof row.package_id === 'string' && row.package_id !== '' ? row.package_id : undefined; + if (pkg) stored.set(pkg, row); + } + for (const pkg of registry.storedPicklistExtenders(name)) { + if (!stored.has(pkg)) registry.withdrawPicklistExtension(name, pkg); + } + for (const [pkg, row] of stored) { + try { + registerStoredPicklistExtension(registry, reads.bodyOf(row), pkg); + } catch (err: any) { + console.warn( + `[Protocol] picklist extension '${name}' of package '${pkg}' could not be re-registered: ${err?.message ?? err}`, + ); + } + } +} diff --git a/packages/metadata-protocol/src/protocol-registry-hydration.ts b/packages/metadata-protocol/src/protocol-registry-hydration.ts index f4849f0bfa2..f4b7ae1b259 100644 --- a/packages/metadata-protocol/src/protocol-registry-hydration.ts +++ b/packages/metadata-protocol/src/protocol-registry-hydration.ts @@ -41,6 +41,8 @@ import { bindStoredRow } from './stored-row-binding.js'; import { incomingTakesStoredFlowSlot } from './stored-flow-slot.js'; import { shippingPackageIds } from './protocol-environment-rows.js'; import { OBJECT_EXTENSION_TYPE } from './protocol-object-extension-item.js'; +import { PICKLIST_EXTENSION_TYPE, registerStoredPicklistExtension, resyncStoredPicklistExtensions } from './protocol-picklist-extension-item.js'; +import type { PicklistExtensionRegistry } from './protocol-picklist-extension-item.js'; import { canonicalMetaType } from './protocol-meta-type-schema.js'; import { remainingRowsPhrase } from './protocol-authoring-refusals.js'; import { @@ -869,6 +871,13 @@ export class ProtocolRegistryHydrationFacet { if (canonicalType === OBJECT_EXTENSION_TYPE) { return host.registerStoredObjectExtension(data, options.packageId); } + // [#39536] Its twin: a `picklist_extension` row registers as its + // package's contribution to the list it names, never as an item. + if (canonicalType === PICKLIST_EXTENSION_TYPE) { + return registerStoredPicklistExtension( + (host.engine as { registry?: PicklistExtensionRegistry } | undefined)?.registry, data, options.packageId, + ); + } if (!data || typeof data !== 'object' || !('name' in data)) return false; const registry: any = (host.engine as any)?.registry; if (!registry || typeof registry.registerItem !== 'function') return false; @@ -1546,7 +1555,7 @@ export class ProtocolRegistryHydrationFacet { * that throws logs the fault at `warn` and, for a caller that asked, * answers it in the same shape. */ - static async applyRegistryWriteThrough(host: Pick, request: RegistryWriteThroughRequest): Promise { + static async applyRegistryWriteThrough(host: Pick, request: RegistryWriteThroughRequest): Promise { // [#8862] The `|| request.type === 'objects'` limb is GONE — this // branch admitted the plural that {@link applyObjectRegistryMutation} // then consumed. All four call sites of this method fold at their @@ -1594,9 +1603,16 @@ export class ProtocolRegistryHydrationFacet { // kernel-scope-gated, for the `object` branch's own reason — it adds // columns to an env-wide table and fields to every read of it. Best-effort // like every branch here: the row is already persisted. - if (request.type === OBJECT_EXTENSION_TYPE) { + // [#39536] …and its twin, a `picklist_extension` row: its package's + // contribution to an env-wide list, served on every field bound to it. + if (request.type === OBJECT_EXTENSION_TYPE || request.type === PICKLIST_EXTENSION_TYPE) { try { - host.registerStoredObjectExtension(request.item, request.packageId); + if (request.type === PICKLIST_EXTENSION_TYPE) { + registerStoredPicklistExtension( + (host.engine as { registry?: PicklistExtensionRegistry } | undefined)?.registry, + request.item, request.packageId, + ); + } else host.registerStoredObjectExtension(request.item, request.packageId); } catch (err: any) { console.warn( `[Protocol] registry write-through failed for ${request.type}/${request.name}: ${err?.message ?? err}`, @@ -1860,6 +1876,25 @@ export class ProtocolRegistryHydrationFacet { await host.resyncStoredObjectExtensions(name); return; } + // [#39536] Nor has its twin: a `picklist_extension` row is its + // package's contribution to the list, and the rows that remain say + // which stay. + if ((PLURAL_TO_SINGULAR[type] ?? type) === PICKLIST_EXTENSION_TYPE) { + try { + await resyncStoredPicklistExtensions( + (host.engine as { registry?: PicklistExtensionRegistry } | undefined)?.registry, name, { + activeRows: () => host.findEnvironmentRows('sys_metadata', { + where: { type: PICKLIST_EXTENSION_TYPE, name, state: 'active' }, + context: { isSystem: true }, + }), + bodyOf: (row) => host.convertStoredItem(PICKLIST_EXTENSION_TYPE, storedRowDocument(row)), + }, + ); + } catch (error) { + host.rethrowUnlessMetadataStoreUnprovisioned(error, 'sys_metadata'); + } + return; + } try { const registry: any = host.engine.registry; const singular = PLURAL_TO_SINGULAR[type] ?? type; diff --git a/packages/metadata-protocol/src/protocol-save.ts b/packages/metadata-protocol/src/protocol-save.ts index 41868d9be9d..c75748d49e3 100644 --- a/packages/metadata-protocol/src/protocol-save.ts +++ b/packages/metadata-protocol/src/protocol-save.ts @@ -92,6 +92,8 @@ import { packagelessCreateRefusal } from './protocol-packageless-create.js'; import type { ObjectStackProtocolImplementation } from './protocol.js'; import { saveRegistryQuestion } from './registry-question.js'; import { OBJECT_EXTENSION_TYPE, registrableObjectExtension } from './protocol-object-extension-item.js'; +import { PICKLIST_EXTENSION_TYPE, picklistExtensionItemRefusal } from './protocol-picklist-extension-item.js'; +import type { PicklistExtensionRegistry } from './protocol-picklist-extension-item.js'; import { rowHeldBaseAddressOf, servedAddressJudgment } from './protocol-meta-item-face.js'; import { overlayMemberValue } from './migrations/overlay-index.js'; import { packagelessContentPackage, shippingPackageIds } from './protocol-environment-rows.js'; @@ -1483,6 +1485,21 @@ export class ProtocolSaveFacet { } } } + // [#39536] …and a `picklist_extension` body against its address and + // the list it extends, on the same binding and with the same + // envelope: a package's item, its row name its target list, every + // value it adds ending in `__c`, the list reachable from the package + // and no value the list already carries. Draft and publish alike. + // See {@link picklistExtensionItemRefusal}. + if (singularType === PICKLIST_EXTENSION_TYPE) { + const picklistRefusal = picklistExtensionItemRefusal(singularType, { + item: request.item, + name: request.name, + binding: await host.saveWriteBinding(singularType, request, mode), + registry: (host.engine as { registry?: PicklistExtensionRegistry } | undefined)?.registry, + }); + if (picklistRefusal) throw picklistRefusal; + } // [harden] …and a permission set whose NAME another owner already // holds, with `NAMESPACE_CONFLICT` / 422: a set's name is its // identity across the deployment, and a grant resolves it by that diff --git a/packages/metadata-protocol/src/protocol.ts b/packages/metadata-protocol/src/protocol.ts index 8eb1e487635..674cb1b286b 100644 --- a/packages/metadata-protocol/src/protocol.ts +++ b/packages/metadata-protocol/src/protocol.ts @@ -1632,7 +1632,9 @@ export class ObjectStackProtocolImplementation implements */ private restoredBodyWriter(type: string, name: string, binding: string | null, source: string): (historyBody: unknown) => Promise { // [#25467 cut 8] The body moved to `protocol-authoring-gate.ts` (see `AuthoringGateHost`). + const engine = this.engine; const host: ThisParameterType = { + engine, formRestoreRefusal: (...a) => this.formRestoreRefusal(...a), objectExtensionItemRefusal: (...a) => this.objectExtensionItemRefusal(...a), refuseRestoredBodyTheSaveDoorRefuses: (...a) => this.refuseRestoredBodyTheSaveDoorRefuses(...a), diff --git a/packages/objectql/src/registry-picklists.ts b/packages/objectql/src/registry-picklists.ts index 1c9043b187b..8ccf1c8c8be 100644 --- a/packages/objectql/src/registry-picklists.ts +++ b/packages/objectql/src/registry-picklists.ts @@ -84,6 +84,7 @@ export interface PicklistsHost { picklistVocabularySealed: SchemaRegistry['picklistVocabularySealed']; refusePicklistArrival: SchemaRegistry['refusePicklistArrival']; refusePicklistItemArrival: SchemaRegistry['refusePicklistItemArrival']; + registerPicklistExtension: SchemaRegistry['registerPicklistExtension']; registeringPicklistArrival: SchemaRegistry['registeringPicklistArrival']; readonly residualOwnerDependencies: SchemaRegistry['residualOwnerDependencies']; residualOwnerDependenciesOf: SchemaRegistry['residualOwnerDependenciesOf']; @@ -454,6 +455,77 @@ export class PicklistsFacet { return this.resolvePicklistOptions(picklist, first ?? null); } + /** + * The body of `SchemaRegistry#picklistExtensionReplacementRefusal`; the + * method's docblock there is its contract. The additive rule of + * {@link registerPicklistExtension}, asked of a REPLACEMENT of the + * package's own contribution (its current values set aside, as + * {@link replacePicklistExtension} sets them aside), without registering + * anything. + */ + static picklistExtensionReplacementRefusal(this: Pick, extension: { extend: string; options: readonly PicklistOptionLike[] }, packageId: string): Error | undefined { + const target = extension.extend; + const candidate: PicklistContribution = { packageId, kind: 'extension', options: [...(extension.options ?? [])] }; + const others = this.picklistContributions(target).filter( + (c) => !(c.kind === 'extension' && (c.packageId ?? '') === packageId), + ); + const duplicate = findDuplicatePicklistValue([candidate]) ?? findDuplicatePicklistValue([...others, candidate]); + return duplicate ? duplicatePicklistValueError(target, duplicate) : undefined; + } + + /** + * The body of `SchemaRegistry#replacePicklistExtension`; the method's + * docblock there is its contract. The package's own contribution to the + * list is set aside, the new one registered through + * {@link registerPicklistExtension} (every judge it asks, unchanged), and + * the set-aside one put back when that throws, so a refused replacement + * leaves the list as it was. + */ + static replacePicklistExtension(this: Pick, extension: { extend: string; options: readonly PicklistOptionLike[] }, packageId: string): void { + const target = extension.extend; + this.notePicklistExtension(target, packageId); + const byPackage = this.picklistExtensionContributions.get(target); + const prior = byPackage?.get(packageId); + byPackage?.delete(packageId); + try { + this.registerPicklistExtension(extension, packageId); + } catch (err) { + if (prior) { + let now = this.picklistExtensionContributions.get(target); + if (!now) this.picklistExtensionContributions.set(target, now = new Map()); + now.set(packageId, prior); + } else if (byPackage && byPackage.size === 0) { + this.picklistExtensionContributions.delete(target); + } + this.invalidateAll(); + throw err; + } + const entry = this.picklistExtensionContributions.get(target)?.get(packageId); + if (entry) entry.stored = true; + } + + /** + * The body of `SchemaRegistry#withdrawPicklistExtension`; the method's + * docblock there is its contract. + */ + static withdrawPicklistExtension(this: Pick, name: string, packageId: string): boolean { + const byPackage = this.picklistExtensionContributions.get(name); + if (!byPackage?.has(packageId)) return false; + this.notePicklistExtension(name, packageId); + byPackage.delete(packageId); + if (byPackage.size === 0) this.picklistExtensionContributions.delete(name); + this.invalidateAll(); + this.log(`[Registry] Withdrew picklist extension: ${name} from ${packageId}`); + return true; + } + + /** The body of `SchemaRegistry#storedPicklistExtenders`; the method's docblock there is its contract. */ + static storedPicklistExtenders(this: Pick, name: string): string[] { + return [...(this.picklistExtensionContributions.get(name)?.values() ?? [])] + .filter((entry) => entry.stored === true && typeof entry.packageId === 'string') + .map((entry) => entry.packageId as string); + } + /** Drop a package's `picklistExtensions`; `true` when it had any. */ static unregisterPicklistExtensionsByPackage(this: Pick, packageId: string): boolean { let dropped = false; diff --git a/packages/objectql/src/registry-revision.ts b/packages/objectql/src/registry-revision.ts index 6f4ecbbcbe2..3bbca4072b2 100644 --- a/packages/objectql/src/registry-revision.ts +++ b/packages/objectql/src/registry-revision.ts @@ -155,6 +155,10 @@ export const SCHEMA_REGISTRY_METHOD_KINDS: Readonly }>>(); + // `stored`: the contribution is a stored `picklist_extension` row of the + // package ({@link replacePicklistExtension}), not its manifest's entry. + private picklistExtensionContributions = new Map; stored?: boolean }>>(); /** * Package ids that must be installed in a DISABLED state **when they have no @@ -5615,6 +5617,57 @@ export class SchemaRegistry { return PicklistsFacet.registerPicklistExtension.call(picklistsHost.of(this), extension, packageId); } + /** + * [#39536] Replace one package's contribution to a picklist with + * `extension` — the registration of a stored `picklist_extension` row + * (`@objectstack/metadata-protocol`), where a re-publish REPLACES the + * package's values instead of adding to them ({@link registerPicklistExtension} + * merges, for a manifest replay). Every judge {@link registerPicklistExtension} + * asks is asked; a refusal throws and leaves the package's prior + * contribution in place. The contribution is marked stored + * ({@link storedPicklistExtenders}). + */ + replacePicklistExtension( + extension: { extend: string; options: readonly PicklistOptionLike[] }, + packageId: string, + ): void { + return PicklistsFacet.replacePicklistExtension.call(picklistsHost.of(this), extension, packageId); + } + + /** + * [#39536] The refusal {@link replacePicklistExtension} would throw for this + * extension's values — a value repeated inside it, or one the list or + * another package's extension already carries (`INVALID_METADATA`, the + * additive rule's sentence) — without registering anything. `undefined` = + * admitted. The metadata doors ask it before a `picklist_extension` row is + * stored. + */ + picklistExtensionReplacementRefusal( + extension: { extend: string; options: readonly PicklistOptionLike[] }, + packageId: string, + ): Error | undefined { + return PicklistsFacet.picklistExtensionReplacementRefusal.call(picklistsHost.of(this), extension, packageId); + } + + /** + * [#39536] Withdraw one package's contribution to the picklist `name`: the + * deletion of a stored `picklist_extension` row. `true` when there was one. + * A package's manifest entries leave with the package + * ({@link unregisterPicklistExtensionsByPackage}). + */ + withdrawPicklistExtension(name: string, packageId: string): boolean { + return PicklistsFacet.withdrawPicklistExtension.call(picklistsHost.of(this), name, packageId); + } + + /** + * [#39536] The packages whose contribution to the picklist `name` is a + * stored `picklist_extension` row ({@link replacePicklistExtension}), never + * a manifest's `picklistExtensions` entry. + */ + storedPicklistExtenders(name: string): string[] { + return PicklistsFacet.storedPicklistExtenders.call(picklistsHost.of(this), name); + } + /** * The resolved options of a picklist — its own, then every extension's, in * registration order — or `undefined` when the name reaches no list. @@ -6308,6 +6361,7 @@ export class SchemaRegistry { set picklistVocabularySealed(v) { registry.picklistVocabularySealed = v; }, refusePicklistArrival: (...a) => registry.refusePicklistArrival(...a), refusePicklistItemArrival: (...a) => registry.refusePicklistItemArrival(...a), + registerPicklistExtension: (...a) => registry.registerPicklistExtension(...a), registeringPicklistArrival: (...a) => registry.registeringPicklistArrival(...a), get residualOwnerDependencies() { return registry.residualOwnerDependencies; }, residualOwnerDependenciesOf: (...a) => registry.residualOwnerDependenciesOf(...a), diff --git a/packages/runtime/src/domains/packages.ts b/packages/runtime/src/domains/packages.ts index 016ef5cac65..93eacd735a6 100644 --- a/packages/runtime/src/domains/packages.ts +++ b/packages/runtime/src/domains/packages.ts @@ -5199,13 +5199,19 @@ context: HttpProtocolContext, // registering under a type of its own — so the pair is stated here, where // the item is read back out as the collection entry it is. const EXTENSIONS_KEY = 'objectExtensions'; + // [#39536] …and its twin: a package's `picklist_extension` items travel as + // its `picklistExtensions`, the collection a pair install writes back as + // items and `registerApp` hands to the registry. + const PICKLIST_EXTENSIONS_KEY = 'picklistExtensions'; const singularOf = (plural: string): string => - plural === EXTENSIONS_KEY ? 'object_extension' : PLURAL_TO_SINGULAR[plural]; + plural === EXTENSIONS_KEY ? 'object_extension' + : plural === PICKLIST_EXTENSIONS_KEY ? 'picklist_extension' + : PLURAL_TO_SINGULAR[plural]; const manifest: Record = {}; let total = 0; const perPackageLayer = typeof protocol.getMetaItemsPerPackage === 'function'; - for (const plural of [...exportPluralKeys, EXTENSIONS_KEY]) { + for (const plural of [...exportPluralKeys, EXTENSIONS_KEY, PICKLIST_EXTENSIONS_KEY]) { const singular = singularOf(plural); let items: any[] = []; try { diff --git a/packages/spec/src/kernel/customization-package.ts b/packages/spec/src/kernel/customization-package.ts index 08b338934d7..31095ea30d7 100644 --- a/packages/spec/src/kernel/customization-package.ts +++ b/packages/spec/src/kernel/customization-package.ts @@ -346,6 +346,10 @@ export const OVERRIDE_TYPE_CLASSIFICATION = { // package, stored under its target's name — so no declared override // replaces one; a `.custom` pair writes its own (#28574). object_extension: { disposition: 'excluded', basis: 'adr_0146_d10_extended' }, + // A picklist extension is the same mechanism for a shared list: a list is + // extended, never replaced, by an item of the writing package stored under + // the list's name (#39536, ruling 7406020670). + picklist_extension: { disposition: 'excluded', basis: 'adr_0146_d10_extended' }, // ── D6: the security catalog's one-name-per-deployment types ────── permission: securityCatalog, position: securityCatalog, diff --git a/packages/spec/src/kernel/metadata-plugin.zod.ts b/packages/spec/src/kernel/metadata-plugin.zod.ts index d881c792bb6..683f80edd48 100644 --- a/packages/spec/src/kernel/metadata-plugin.zod.ts +++ b/packages/spec/src/kernel/metadata-plugin.zod.ts @@ -93,6 +93,7 @@ export const MetadataTypeSchema = lazySchema(() => z.enum([ 'seed', // Seed/fixture data — runtime-draftable; publishing applies it (SeedSchema) 'mapping', // Import/export field mappings (MappingSchema) — consumed by POST /data/:object/import via mappingName (#2611); promoted to a kind per the ADR-0088 admission test once the consumer landed 'picklist', // Shared option list that select fields reference by name (PicklistSchema) + 'picklist_extension', // Values a package adds to a picklist another package owns (PicklistExtensionSchema; ruling 7406020670 on #39536) // UI Protocol 'view', // List/form views (ViewSchema) @@ -948,6 +949,19 @@ export const DEFAULT_METADATA_TYPE_REGISTRY: MetadataTypeRegistryEntryParsed[] = // adds values through `picklistExtensions`, on the artifact route. // `loadOrder: 8` — before `object` (10), whose fields reference it. { type: 'picklist', label: 'Picklist', description: 'Shared option list that select fields reference by name', filePatterns: ['**/*.picklist.ts', '**/*.picklist.yml', '**/*.picklist.json'], supportsOverlay: false, allowEnvironmentOverlay: false, allowRuntimeCreate: false, supportsVersioning: false, executionPinned: false, loadOrder: 8, domain: 'data' }, + // [#39536, ruling 7406020670] `picklist_extension`: values a package adds to + // a picklist another package owns, stored as an item of the writing package — + // the twin of `object_extension`. A code package's `picklistExtensions` are + // never stored as items of this type: `registerApp` hands each entry to the + // registry. This type's items are the rows the `/api/v1/meta` doors write, so + // a customer adds a value to an installed package's list in the base's paired + // `.custom` package, with draft, publish, history and export. One item per + // package per target list, stored under the list's name; the body is + // `PicklistExtensionSchema` (`extend`, `options`, no `name`), judged by the + // metadata-protocol doors, and every value it adds ends in `__c`. Never + // overlaid: a package changes its own item. `loadOrder: 9` — after + // `picklist` (8), before `object` (10), whose fields resolve the list. + { type: 'picklist_extension', label: 'Picklist Extension', description: 'Values a package adds to a picklist another package owns', filePatterns: ['**/*.picklist-extension.ts'], supportsOverlay: false, allowEnvironmentOverlay: false, allowRuntimeCreate: true, supportsVersioning: true, executionPinned: false, loadOrder: 9, domain: 'data' }, { type: 'mapping', label: 'Import Mapping', description: 'Reusable import/export field mapping (rename + transforms), referenced by name at import', filePatterns: ['**/*.mapping.ts', '**/*.mapping.yml', '**/*.mapping.json'], supportsOverlay: false, allowEnvironmentOverlay: false, allowRuntimeCreate: true, supportsVersioning: true, executionPinned: false, loadOrder: 96, domain: 'data' }, // UI Protocol From 5081b693a0e09ebc6fb6f129a4458c942d3e2d00 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 08:47:20 +0000 Subject: [PATCH 02/14] wip(#39536): runtime item test, pair-planner test, changeset (unrun draft) Claude-Session: https://claude.ai/code/session_01L9qibxE6RdcamcqFHHa7PC Co-authored-by: Claude --- .changeset/39536-picklist-extension-item.md | 21 + ...e-install-local-customization-pair.test.ts | 25 ++ .../meta-picklist-extension-item.test.ts | 369 ++++++++++++++++++ 3 files changed, 415 insertions(+) create mode 100644 .changeset/39536-picklist-extension-item.md create mode 100644 packages/runtime/src/domains/meta-picklist-extension-item.test.ts diff --git a/.changeset/39536-picklist-extension-item.md b/.changeset/39536-picklist-extension-item.md new file mode 100644 index 00000000000..0909ad4f2c3 --- /dev/null +++ b/.changeset/39536-picklist-extension-item.md @@ -0,0 +1,21 @@ +--- +'@objectstack/spec': minor +'@objectstack/objectql': minor +'@objectstack/metadata-protocol': minor +'@objectstack/runtime': minor +'@objectstack/cloud-connection': minor +--- + +feat(spec, metadata-protocol, objectql, runtime, cloud-connection): a customer adds values to an installed package's picklist as a stored `picklist_extension` item of the customization pair + +Clause-②: yes +Metadata-protocol: added + +Who sees it: an administrator of an installed app (for example a CRM) who needs one more value in the vendor's shared option list, such as a new lead source. Until now nothing they could reach stored it: the list belongs to the vendor's package, and the `.custom` pair had no door for `picklistExtensions`. + +- New metadata type `picklist_extension`, the twin of `object_extension`: values a package adds to a picklist another package owns, stored as an item of the writing package under the list's name (one item per package per list). The body is `PicklistExtensionSchema` unchanged (`extend`, `options`). It is saved as a draft, published, versioned, rolled back and deleted through `/api/v1/meta/picklist_extension/?package=` like any item, and classified `excluded` in the override table (a list is extended, never replaced). +- Every value such an item adds must end in `__c` (the suffix reserved for a customer's extension fields). A value without it is refused at the save, publish and restore doors with `VALIDATION_ERROR` / 400 located at `options..value`; the option `label` stays free text. The reason: a vendor version that later ships the same value is refused at upgrade while a customer's extension holds it, so the suffix keeps the vendor's names and the customer's apart. +- The doors also refuse, with `VALIDATION_ERROR` / 400: a write naming no package, a row filed under a name other than its `extend`, a list the package cannot reach (not its own and not declared by a package in its `dependencies`), and a value the list or another package's extension already carries. +- A published item is served at once on every field bound to the list, re-registered at boot, replaced on re-publish (a value dropped from the item leaves the list), and withdrawn when the item is deleted or the package uninstalled. +- `GET /api/v1/packages//export` carries the items as `picklistExtensions`, and `POST /api/v1/marketplace/install-local` of such a pair writes each entry back as a `picklist_extension` item (before, it refused the key). +- `SchemaRegistry` (`@objectstack/objectql`) gains `replacePicklistExtension`, `picklistExtensionReplacementRefusal`, `withdrawPicklistExtension` and `storedPicklistExtenders`. diff --git a/packages/cloud-connection/src/marketplace-install-local-customization-pair.test.ts b/packages/cloud-connection/src/marketplace-install-local-customization-pair.test.ts index 62bcc94f4aa..2dc36ac3791 100644 --- a/packages/cloud-connection/src/marketplace-install-local-customization-pair.test.ts +++ b/packages/cloud-connection/src/marketplace-install-local-customization-pair.test.ts @@ -126,4 +126,29 @@ describe('planCustomizationPairInstall — the items of an exported pair', () => if (plan.ok) return; expect(plan.problems).toEqual(['`objectExtensions[0]` has no name']); }); + + // [#39536] The pair's `picklist_extension` items travel as its + // `picklistExtensions`; the install writes each one back as that item, + // named by the list it extends, before the objects whose fields resolve it. + it('reads a picklist extension as a `picklist_extension` item named by its list', () => { + const entry = { extend: 'lead_source', options: [{ label: 'Trade show', value: 'trade_show__c' }] }; + const plan = planCustomizationPairInstall(exportedPair({ + picklistExtensions: [entry], + objectExtensions: [{ extend: 'showcase_task', fields: { showcase_custom_flag: { type: 'boolean' } } }], + })); + expect(plan.ok, JSON.stringify(plan)).toBe(true); + if (!plan.ok) return; + expect(plan.items.map((i) => [i.type, i.name, i.path]).slice(0, 2)).toEqual([ + ['picklist_extension', 'lead_source', 'picklistExtensions[0]'], + ['object_extension', 'showcase_task', 'objectExtensions[0]'], + ]); + expect(plan.items[0]!.item).toEqual(entry); + }); + + it('refuses a picklist extension that names no list', () => { + const plan = planCustomizationPairInstall(exportedPair({ picklistExtensions: [{ options: [{ label: 'X', value: 'x__c' }] }] })); + expect(plan.ok).toBe(false); + if (plan.ok) return; + expect(plan.problems).toEqual(['`picklistExtensions[0]` has no name']); + }); }); diff --git a/packages/runtime/src/domains/meta-picklist-extension-item.test.ts b/packages/runtime/src/domains/meta-picklist-extension-item.test.ts new file mode 100644 index 00000000000..cdc68c66bf1 --- /dev/null +++ b/packages/runtime/src/domains/meta-picklist-extension-item.test.ts @@ -0,0 +1,369 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [#39536, ruling 7406020670] A picklist extension is an authorable item of a + * writable package — the twin of the object-extension item + * (`meta-object-extension-item.test.ts`): saved and published through the + * doors every item uses, registered as the package's contribution to the list + * it names, withdrawn when the row or the package goes, exported as the + * package's `picklistExtensions`, and every value it adds ends in `__c`. + * + * The business case: a customer of an installed CRM adds the lead source + * "Trade show" to the vendor's shared list. The value is stored in + * `.custom`, served on every field bound to the list, travels with the + * pair's export, and survives the vendor's next version shipping its own + * `trade_show`. + * + * ## The rig + * + * The object-extension item's: better-sqlite3 `:memory:` behind the real + * `ObjectQL` engine, the real `sys_metadata*` objects, a real + * `ObjectStackProtocolImplementation` over its `SchemaRegistry`, and the real + * package export door (`HttpDispatcher`). The base is a code package + * registered through `registerApp`, so its list has a packaged owner; the pair + * and the outside package are installed through the protocol's package door. + * + * Refusals assert the envelope (`code` + `status`), the located key where the + * gate names one, and that no row was left and nothing was registered. + */ + +import { describe, it, expect, beforeAll, afterAll, afterEach } from 'vitest'; +import { mkdtempSync, rmSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { ObjectQL } from '@objectstack/objectql'; +import { SqlDriver } from '@objectstack/driver-sql'; +import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol'; +import { SysMetadata, SysMetadataHistoryObject, SysMetadataAuditObject } from '@objectstack/platform-objects/metadata'; +import { PicklistExtensionSchema } from '@objectstack/spec/data'; +import { HttpDispatcher } from '../http-dispatcher.js'; +// The export door boots the real dispatcher, whose package door reaches +// `import('@objectstack/metadata')`; pay that load during collection, never +// inside a clocked case (check:test-source-alias). +import '@objectstack/metadata'; + +let home: string; +let priorHome: string | undefined; +beforeAll(() => { + priorHome = process.env.OS_HOME; + home = mkdtempSync(join(tmpdir(), 'os-picklist-extension-item-')); + process.env.OS_HOME = home; +}); +afterAll(() => { + if (priorHome === undefined) delete process.env.OS_HOME; + else process.env.OS_HOME = priorHome; + rmSync(home, { recursive: true, force: true }); +}); + +const TEST_PACKAGE_ID = 'objectstack-test'; +const BASE = 'com.acme.crm'; +const PAIR = 'com.acme.crm.custom'; +/** A writable package that does not depend on the base: the list is outside its closure. */ +const OTHER = 'com.acme.other'; +/** A writable package that depends on the base: a second writer the list is reachable from. */ +const PARTNER = 'com.acme.partner'; +const LIST = 'lead_source'; +const TYPE = 'picklist_extension'; + +const baseManifest = (values: readonly string[] = ['web', 'referral'], version = '3.4.1') => ({ + id: BASE, + name: 'crm', + version, + type: 'app', + namespace: 'crm', + picklists: [{ name: LIST, label: 'Lead Source', options: values.map((value) => ({ label: value, value })) }], + objects: [{ + name: 'crm_lead', + label: 'Lead', + fields: { + name: { name: 'name', label: 'Name', type: 'text' }, + source: { name: 'source', label: 'Source', type: 'select', picklist: LIST }, + }, + }], +}); + +/** Studio's 「添加选项」 body: the pair's extension of the vendor's list, its value suffixed. */ +const tradeShow = (values: readonly string[] = ['trade_show__c']) => ({ + extend: LIST, + options: values.map((value) => ({ label: 'Trade show', value })), +}); + +const liveEngines: ObjectQL[] = []; +afterEach(async () => { + while (liveEngines.length) { + try { await liveEngines.pop()?.destroy(); } catch { /* noop */ } + } +}); + +async function freshEngine(): Promise { + const engine = new ObjectQL(); + liveEngines.push(engine); + engine.registerDriver(new SqlDriver({ + client: 'better-sqlite3', + connection: { filename: ':memory:' }, + useNullAsDefault: true, + }), true); + await engine.init(); + engine.registry.registerObject(SysMetadata as any, TEST_PACKAGE_ID); + engine.registry.registerObject(SysMetadataHistoryObject as any, TEST_PACKAGE_ID); + engine.registry.registerObject(SysMetadataAuditObject as any, TEST_PACKAGE_ID); + (engine.registry as unknown as { logLevel: string }).logLevel = 'silent'; + engine.registerApp(baseManifest()); + await engine.syncSchemas(); + return engine; +} + +async function boot() { + const engine = await freshEngine(); + const protocol = new ObjectStackProtocolImplementation(engine as any, () => new Map()); + const p = protocol as any; + await p.installPackage({ + manifest: { id: PAIR, name: 'crm-custom', version: '0.1.0', type: 'app', namespace: 'crm_custom', dependencies: { [BASE]: '^3' } }, + }); + await p.installPackage({ manifest: { id: OTHER, name: 'other', version: '0.1.0', type: 'app', namespace: 'other' } }); + await p.installPackage({ + manifest: { id: PARTNER, name: 'partner', version: '0.1.0', type: 'app', namespace: 'partner', dependencies: { [BASE]: '^3' } }, + }); + + const named: Record = { protocol, objectql: engine }; + const get = (name: string) => named[name] ?? null; + const kernel: any = { context: { getService: get }, getService: get, getServiceAsync: async (name: string) => get(name) }; + const dispatcher = new HttpDispatcher(kernel); + + /** A draft save naming the package, then the per-item publish naming it. */ + const saveAndPublish = async (packageId: string, item: unknown, name = LIST) => { + await p.saveMetaItem({ type: TYPE, name, item, mode: 'draft', packageId }); + return p.publishMetaItem({ type: TYPE, name, packageId }); + }; + /** Every stored row of the type, read back from the store. */ + const rows = async () => ((await engine.find('sys_metadata', { where: { type: TYPE }, context: { isSystem: true } })) ?? []) + .map((r: any) => ({ name: r.name, package_id: r.package_id ?? null, state: r.state })); + /** The list's values, on the registry and on the bound field of the served object. */ + const values = async () => { + const served = (await p.getMetaItem({ type: 'object', name: 'crm_lead' }))?.item; + return { + registry: ((engine.registry as any).resolvePicklistOptions(LIST) ?? []).map((o: any) => o.value), + served: (served?.fields?.source?.options ?? []).map((o: any) => o.value), + }; + }; + const exportOf = async (id: string): Promise> => { + const reader: any = { + request: {}, + executionContext: { userId: 'u_admin', isSystem: false, systemPermissions: ['studio.access'] }, + }; + const r = await dispatcher.handlePackages(`/${encodeURIComponent(id)}/export`, 'GET', undefined, {}, reader); + expect(r.response?.status, JSON.stringify(r.response?.body)).toBe(200); + return r.response?.body?.data; + }; + const refusalOf = async (write: () => Promise) => { + try { + await write(); + } catch (e) { + return e as any; + } + return undefined; + }; + return { engine, protocol: p, saveAndPublish, rows, values, exportOf, refusalOf }; +} + +const VENDOR = ['web', 'referral']; + +describe('[#39536] a writable pair saves and publishes an extension of the base\'s list', () => { + it('the value is served on the bound field and resolved by the registry', async () => { + const rig = await boot(); + await rig.saveAndPublish(PAIR, tradeShow()); + + expect(await rig.values()).toEqual({ + registry: [...VENDOR, 'trade_show__c'], + served: [...VENDOR, 'trade_show__c'], + }); + expect(await rig.rows()).toEqual([{ name: LIST, package_id: PAIR, state: 'active' }]); + }, 60_000); + + it('a draft is not live: the value appears only on publish', async () => { + const rig = await boot(); + await rig.protocol.saveMetaItem({ type: TYPE, name: LIST, item: tradeShow(), mode: 'draft', packageId: PAIR }); + expect((await rig.values()).registry).toEqual(VENDOR); + await rig.protocol.publishMetaItem({ type: TYPE, name: LIST, packageId: PAIR }); + expect((await rig.values()).registry).toEqual([...VENDOR, 'trade_show__c']); + }, 60_000); + + it('a re-publish replaces the package\'s values: a value it drops leaves the list', async () => { + const rig = await boot(); + await rig.saveAndPublish(PAIR, tradeShow(['trade_show__c', 'webinar__c'])); + expect((await rig.values()).registry).toEqual([...VENDOR, 'trade_show__c', 'webinar__c']); + + await rig.saveAndPublish(PAIR, tradeShow(['webinar__c'])); + expect(await rig.values()).toEqual({ registry: [...VENDOR, 'webinar__c'], served: [...VENDOR, 'webinar__c'] }); + }, 60_000); + + it('a rollback restores the earlier version\'s values', async () => { + const rig = await boot(); + await rig.saveAndPublish(PAIR, tradeShow(['trade_show__c'])); + await rig.saveAndPublish(PAIR, tradeShow(['webinar__c'])); + const versions = ((await rig.engine.find('sys_metadata_history', { where: { type: TYPE, name: LIST }, context: { isSystem: true } })) as any[]) + .filter((row) => JSON.stringify(JSON.parse(String(row.metadata)).options).includes('trade_show__c')) + .map((row) => Number(row.version)); + expect(versions.length, 'one stored version carrying trade_show__c').toBeGreaterThanOrEqual(1); + + await rig.protocol.rollbackMetaItem({ type: TYPE, name: LIST, packageId: PAIR, toVersion: Math.min(...versions) }); + expect((await rig.values()).registry).toEqual([...VENDOR, 'trade_show__c']); + }, 60_000); + + it('a boot re-reads the stored row and registers it the same way', async () => { + const rig = await boot(); + await rig.saveAndPublish(PAIR, tradeShow()); + // The registry forgets the contribution, as a fresh process would. + (rig.engine.registry as any).withdrawPicklistExtension(LIST, PAIR); + expect((await rig.values()).registry).toEqual(VENDOR); + + const result = await rig.protocol.loadMetaFromDb(); + expect(result.errors).toBe(0); + expect((await rig.values()).registry).toEqual([...VENDOR, 'trade_show__c']); + }, 60_000); + + it('the vendor\'s next version may ship `trade_show` beside the customer\'s `trade_show__c`', async () => { + const rig = await boot(); + await rig.saveAndPublish(PAIR, tradeShow()); + + rig.engine.registerApp(baseManifest([...VENDOR, 'trade_show'], '3.5.0')); + expect((rig.engine.registry as any).getPackage(BASE)?.manifest?.version).toBe('3.5.0'); + expect((await rig.values()).registry).toEqual([...VENDOR, 'trade_show', 'trade_show__c']); + }, 60_000); +}); + +describe('[#39536] the pair\'s export carries the extension, and it re-installs', () => { + it('`GET /packages//export` carries the row as a `picklistExtensions` entry that parses', async () => { + const rig = await boot(); + await rig.saveAndPublish(PAIR, tradeShow()); + + const manifest = await rig.exportOf(PAIR); + expect(manifest.picklistExtensions, JSON.stringify(manifest)).toEqual([tradeShow()]); + const reparsed = PicklistExtensionSchema.safeParse(manifest.picklistExtensions[0]); + expect(reparsed.success, JSON.stringify(reparsed.error?.issues)).toBe(true); + }, 60_000); + + it('the base\'s export is unchanged: it carries no extension', async () => { + const rig = await boot(); + await rig.saveAndPublish(PAIR, tradeShow()); + + expect((await rig.exportOf(BASE)).picklistExtensions).toBeUndefined(); + }, 60_000); + + it('the export, saved and published into a fresh environment\'s pair, serves the same value', async () => { + const rig = await boot(); + await rig.saveAndPublish(PAIR, tradeShow()); + const [entry] = (await rig.exportOf(PAIR)).picklistExtensions; + + // The pair install writes each entry through the save door + // (`planCustomizationPairInstall`, @objectstack/cloud-connection). + const fresh = await boot(); + expect((await fresh.values()).registry).toEqual(VENDOR); + await fresh.saveAndPublish(PAIR, entry, entry.extend); + expect((await fresh.values()).registry).toEqual([...VENDOR, 'trade_show__c']); + }, 60_000); +}); + +describe('[#39536] withdrawal: deleting the row, or uninstalling the pair, removes the value from every read', () => { + it('deleting the row', async () => { + const rig = await boot(); + await rig.saveAndPublish(PAIR, tradeShow()); + + await rig.protocol.deleteMetaItem({ type: TYPE, name: LIST, packageId: PAIR }); + + expect(await rig.values()).toEqual({ registry: VENDOR, served: VENDOR }); + expect(await rig.rows()).toEqual([]); + }, 60_000); + + it('deleting one package\'s row leaves another package\'s extension of the same list', async () => { + const rig = await boot(); + await rig.saveAndPublish(PAIR, tradeShow()); + await rig.saveAndPublish(PARTNER, { extend: LIST, options: [{ label: 'Partner', value: 'partner__c' }] }); + + await rig.protocol.deleteMetaItem({ type: TYPE, name: LIST, packageId: PAIR }); + + expect((await rig.values()).registry).toEqual([...VENDOR, 'partner__c']); + }, 60_000); + + it('uninstalling the pair', async () => { + const rig = await boot(); + await rig.saveAndPublish(PAIR, tradeShow()); + + await rig.protocol.deletePackage({ packageId: PAIR }); + + expect(await rig.values()).toEqual({ registry: VENDOR, served: VENDOR }); + }, 60_000); +}); + +describe('[#39536] refused at the door, leaving no row and registering nothing', () => { + const refusals: Array<[string, string, Record, string, number, string | undefined]> = [ + ['a value without `__c` (the ruling\'s rider)', PAIR, tradeShow(['trade_show']), 'VALIDATION_ERROR', 400, 'options.0.value'], + ['an unknown list', PAIR, { extend: 'crm_nowhere', options: [{ label: 'X', value: 'x__c' }] }, 'VALIDATION_ERROR', 400, 'extend'], + ['a list outside the package\'s closure', OTHER, tradeShow(), 'VALIDATION_ERROR', 400, 'extend'], + ['a value repeated inside the item', PAIR, tradeShow(['trade_show__c', 'trade_show__c']), 'VALIDATION_ERROR', 400, 'options'], + ]; + + it.each(refusals)('%s', async (_label, packageId, body, code, status, path) => { + const rig = await boot(); + const name = typeof body.extend === 'string' ? body.extend : LIST; + const caught = await rig.refusalOf(() => rig.protocol.saveMetaItem({ type: TYPE, name, item: body, mode: 'draft', packageId })); + expect(caught, 'the save was admitted').toBeDefined(); + expect({ code: caught.code, status: caught.status }).toEqual({ code, status }); + if (path !== undefined) expect((caught.issues ?? []).map((i: any) => i.path)).toContain(path); + expect(await rig.rows()).toEqual([]); + expect((await rig.values()).registry).toEqual(VENDOR); + }, 60_000); + + it('a value another package\'s extension already carries', async () => { + const rig = await boot(); + await rig.saveAndPublish(PARTNER, tradeShow()); + const caught = await rig.refusalOf(() => rig.protocol.saveMetaItem({ type: TYPE, name: LIST, item: tradeShow(), mode: 'draft', packageId: PAIR })); + expect({ code: caught?.code, status: caught?.status }).toEqual({ code: 'VALIDATION_ERROR', status: 400 }); + expect(String(caught?.message)).toContain('trade_show__c'); + expect(await rig.rows()).toEqual([{ name: LIST, package_id: PARTNER, state: 'active' }]); + }, 60_000); + + it('a package-less write: an extension is an item of a package', async () => { + const rig = await boot(); + const caught = await rig.refusalOf(() => rig.protocol.saveMetaItem({ type: TYPE, name: LIST, item: tradeShow(), mode: 'draft' })); + expect({ code: caught?.code, status: caught?.status }).toEqual({ code: 'VALIDATION_ERROR', status: 400 }); + expect(String(caught?.message)).toContain('names none'); + expect(await rig.rows()).toEqual([]); + }, 60_000); + + it('a row filed under a name other than its target list', async () => { + const rig = await boot(); + const caught = await rig.refusalOf(() => rig.protocol.saveMetaItem({ type: TYPE, name: 'industry', item: tradeShow(), mode: 'draft', packageId: PAIR })); + expect({ code: caught?.code, status: caught?.status }).toEqual({ code: 'VALIDATION_ERROR', status: 400 }); + expect((caught?.issues ?? []).map((i: any) => i.path)).toContain('extend'); + expect(await rig.rows()).toEqual([]); + }, 60_000); + + it('a body the schema refuses (a `label` on the list): the shape gate\'s 422', async () => { + const rig = await boot(); + const caught = await rig.refusalOf(() => rig.protocol.saveMetaItem({ type: TYPE, name: LIST, item: { ...tradeShow(), label: 'Sources' }, mode: 'draft', packageId: PAIR })); + expect(caught, 'the save was admitted').toBeDefined(); + expect(caught.status).toBeGreaterThanOrEqual(400); + expect(caught.status).toBeLessThan(500); + expect(await rig.rows()).toEqual([]); + }, 60_000); + + it('a read-only package: the base itself', async () => { + const rig = await boot(); + const caught = await rig.refusalOf(() => rig.protocol.saveMetaItem({ type: TYPE, name: LIST, item: tradeShow(), mode: 'draft', packageId: BASE })); + expect(caught, 'the save was admitted').toBeDefined(); + expect(caught.status).toBeGreaterThanOrEqual(400); + expect(caught.status).toBeLessThan(500); + expect(await rig.rows()).toEqual([]); + }, 60_000); + + it('a draft whose value another package took before it was published is refused at publish', async () => { + const rig = await boot(); + await rig.protocol.saveMetaItem({ type: TYPE, name: LIST, item: tradeShow(), mode: 'draft', packageId: PAIR }); + await rig.saveAndPublish(PARTNER, tradeShow()); + const caught = await rig.refusalOf(() => rig.protocol.publishMetaItem({ type: TYPE, name: LIST, packageId: PAIR })); + expect({ code: caught?.code, status: caught?.status }).toEqual({ code: 'VALIDATION_ERROR', status: 400 }); + expect((await rig.values()).registry).toEqual([...VENDOR, 'trade_show__c']); + expect((await rig.rows()).filter((r) => r.state === 'active')).toEqual([{ name: LIST, package_id: PARTNER, state: 'active' }]); + }, 60_000); +}); From 362391662a74b196612da62c3c50d20ce5fc6420 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 08:57:00 +0000 Subject: [PATCH 03/14] fix(#39536): picklist_extension copy keeps its list name; regenerate spec artifacts; tighten item test The rename engine gave a copied picklist_extension a name key the strict PicklistExtensionSchema refuses and renamed a source-prefixed list name. Regenerated meta-url-data and the reference docs for the new type. The item test now asserts code and status on every refusal and rolls back without the package selector, as the type is not package-slotted for history. Claude-Session: https://claude.ai/code/session_01L9qibxE6RdcamcqFHHa7PC Co-authored-by: Claude --- ...pace-rename-object-extension-38709.test.ts | 31 ++++++++++++++++++- .../src/package-namespace-rename.ts | 13 ++++++-- .../meta-picklist-extension-item.test.ts | 16 +++++----- packages/spec/docs/references/api/metadata.md | 5 +-- .../docs/references/kernel/metadata-plugin.md | 6 ++-- .../meta-spelling/meta-url-data.generated.ts | 3 ++ 6 files changed, 60 insertions(+), 14 deletions(-) diff --git a/packages/metadata-protocol/src/package-namespace-rename-object-extension-38709.test.ts b/packages/metadata-protocol/src/package-namespace-rename-object-extension-38709.test.ts index f4dbd27a600..6c311d046e9 100644 --- a/packages/metadata-protocol/src/package-namespace-rename-object-extension-38709.test.ts +++ b/packages/metadata-protocol/src/package-namespace-rename-object-extension-38709.test.ts @@ -16,7 +16,7 @@ * pinned in `package-unmanaged-install.test.ts`. */ import { describe, expect, it } from 'vitest'; -import { ObjectExtensionSchema } from '@objectstack/spec/data'; +import { ObjectExtensionSchema, PicklistExtensionSchema } from '@objectstack/spec/data'; import { planNamespaceRename } from './package-namespace-rename.js'; const items = [ @@ -68,3 +68,32 @@ describe('planNamespaceRename — an `object_extension` copy carries no `name` a }); } }); + +/** + * [#39536] The twin: a `picklist_extension` row is named by the list it + * extends, always another package's (a stored package holds no `picklist`), + * so the copy keeps the row name and `extend`, even when the list's name + * carries the source's prefix, and its body gets no `name` (a refused alias of + * `extend` in the strict `PicklistExtensionSchema`). + */ +describe('planNamespaceRename — a `picklist_extension` copy carries no `name` and keeps its list (#39536)', () => { + const listItems = [ + { type: 'object', name: 'crm_lead', body: { name: 'crm_lead', fields: {} } }, + { type: 'picklist_extension', name: 'lead_source', body: { extend: 'lead_source', options: [{ label: 'Trade show', value: 'trade_show__c' }] } }, + { type: 'picklist_extension', name: 'crm_industry', body: { extend: 'crm_industry', options: [{ label: 'Retail', value: 'retail__c' }] } }, + ]; + for (const retryVerb of ['duplicate', 'install'] as const) { + it(`${retryVerb}: the row name and \`extend\` stay the list's, bare or source-prefixed, and the copy parses`, () => { + const r = planNamespaceRename({ + sourcePackageId: 'com.example.crm', sourceNamespace: 'crm', targetNamespace: 'acme', items: listItems, retryVerb, + }); + for (const { name, body } of listItems.slice(1)) { + const outcome = r.rewrite('picklist_extension', name, body); + expect(outcome).toEqual({ item: body }); + expect(r.copyName('picklist_extension', name)).toBe(name); + const parsed = PicklistExtensionSchema.safeParse((outcome as { item: unknown }).item); + expect(parsed.success, JSON.stringify(parsed.error?.issues)).toBe(true); + } + }); + } +}); diff --git a/packages/metadata-protocol/src/package-namespace-rename.ts b/packages/metadata-protocol/src/package-namespace-rename.ts index 9281b4dbf37..5008592ee48 100644 --- a/packages/metadata-protocol/src/package-namespace-rename.ts +++ b/packages/metadata-protocol/src/package-namespace-rename.ts @@ -855,8 +855,14 @@ export function planNamespaceRename(input: NamespaceRenameInput): NamespaceRenam // An `object_extension` row is named by its target (`listSlotNameOf`), so // its copy name is its target's copy name, read off the same map // `rewrite` maps `extend` through: the row and its `extend` never part. + // [#39536] A `picklist_extension` row is named by its target LIST, which is + // always another package's (a stored package holds no `picklist`: the type + // is not runtime-creatable), so the copy extends the same list under the + // same name: the row and its `extend` never part. const copyName = (type: string, name: string): string => - type === 'object' || (PLURAL_TO_SINGULAR[String(type)] ?? String(type)) === 'object_extension' + (PLURAL_TO_SINGULAR[String(type)] ?? String(type)) === 'picklist_extension' + ? name + : type === 'object' || (PLURAL_TO_SINGULAR[String(type)] ?? String(type)) === 'object_extension' ? (renameMap.get(name) ?? name) : isCapabilityType(type) ? (capabilityRenames.get(name) ?? name) @@ -944,7 +950,10 @@ export function planNamespaceRename(input: NamespaceRenameInput): NamespaceRenam // `protocol-object-extension-item.ts` reads the row's identity // off `extend`). Setting it here refused every copied // extension at the save door, for a key nobody wrote. - if (singular !== 'object_extension') rewritten.name = copyName(type, name); + // [#39536] …and so is its twin, a `picklist_extension` body + // (`PicklistExtensionSchema` is strict; `name` is a refused + // alias of `extend` there). + if (singular !== 'object_extension' && singular !== 'picklist_extension') rewritten.name = copyName(type, name); // ⭐ A COPIED EXTENSION FOLLOWS THE COPIED OBJECT. `extend` names // the object the extension merges into; when that object is one // this copy renames, the copy's extension extends the copy's diff --git a/packages/runtime/src/domains/meta-picklist-extension-item.test.ts b/packages/runtime/src/domains/meta-picklist-extension-item.test.ts index cdc68c66bf1..6e54c770d54 100644 --- a/packages/runtime/src/domains/meta-picklist-extension-item.test.ts +++ b/packages/runtime/src/domains/meta-picklist-extension-item.test.ts @@ -206,7 +206,10 @@ describe('[#39536] a writable pair saves and publishes an extension of the base\ .map((row) => Number(row.version)); expect(versions.length, 'one stored version carrying trade_show__c').toBeGreaterThanOrEqual(1); - await rig.protocol.rollbackMetaItem({ type: TYPE, name: LIST, packageId: PAIR, toVersion: Math.min(...versions) }); + // No `package` selector: like its twin `object_extension`, the type is + // not stored per (package, name) for history (`PACKAGE_SLOTTED_METADATA_TYPES`), + // so the door refuses one; the rollback restores the row the read serves. + await rig.protocol.rollbackMetaItem({ type: TYPE, name: LIST, toVersion: Math.min(...versions) }); expect((await rig.values()).registry).toEqual([...VENDOR, 'trade_show__c']); }, 60_000); @@ -339,21 +342,20 @@ describe('[#39536] refused at the door, leaving no row and registering nothing', expect(await rig.rows()).toEqual([]); }, 60_000); - it('a body the schema refuses (a `label` on the list): the shape gate\'s 422', async () => { + it('a body the schema refuses (a `label` on the list): the shape gate\'s INVALID_METADATA / 422', async () => { const rig = await boot(); const caught = await rig.refusalOf(() => rig.protocol.saveMetaItem({ type: TYPE, name: LIST, item: { ...tradeShow(), label: 'Sources' }, mode: 'draft', packageId: PAIR })); expect(caught, 'the save was admitted').toBeDefined(); - expect(caught.status).toBeGreaterThanOrEqual(400); - expect(caught.status).toBeLessThan(500); + expect({ code: caught.code, status: caught.status }).toEqual({ code: 'INVALID_METADATA', status: 422 }); + expect(String(caught.message)).toContain('`label`'); expect(await rig.rows()).toEqual([]); }, 60_000); - it('a read-only package: the base itself', async () => { + it('a read-only package: the base itself (WRITABLE_PACKAGE_REQUIRED / 422)', async () => { const rig = await boot(); const caught = await rig.refusalOf(() => rig.protocol.saveMetaItem({ type: TYPE, name: LIST, item: tradeShow(), mode: 'draft', packageId: BASE })); expect(caught, 'the save was admitted').toBeDefined(); - expect(caught.status).toBeGreaterThanOrEqual(400); - expect(caught.status).toBeLessThan(500); + expect({ code: caught.code, status: caught.status }).toEqual({ code: 'WRITABLE_PACKAGE_REQUIRED', status: 422 }); expect(await rig.rows()).toEqual([]); }, 60_000); diff --git a/packages/spec/docs/references/api/metadata.md b/packages/spec/docs/references/api/metadata.md index c6a7882054c..65f274aacee 100644 --- a/packages/spec/docs/references/api/metadata.md +++ b/packages/spec/docs/references/api/metadata.md @@ -636,7 +636,7 @@ Metadata query with filtering, sorting, and pagination | Property | Type | Required | Description | | :--- | :--- | :--- | :--- | -| **types** | `Enum<'object' \| 'object_extension' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'view' \| 'form' \| 'page' \| 'dashboard' \| 'app' \| 'action' \| 'report' \| 'dataset' \| 'flow' \| 'job' \| 'datasource' \| 'external_catalog' \| 'translation' \| 'api' \| 'email_template' \| 'doc' \| 'book' \| 'permission' \| 'position' \| 'capability' \| 'sharing_rule' \| 'queue' \| 'assignment_rule' \| 'agent' \| 'tool' \| 'skill' \| 'ai_context' \| 'knowledge_source'>[]` | optional | Filter by metadata types | +| **types** | `Enum<'object' \| 'object_extension' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'picklist_extension' \| 'view' \| 'form' \| 'page' \| 'dashboard' \| 'app' \| 'action' \| 'report' \| 'dataset' \| 'flow' \| 'job' \| 'datasource' \| 'external_catalog' \| 'translation' \| 'api' \| 'email_template' \| 'doc' \| 'book' \| 'permission' \| 'position' \| 'capability' \| 'sharing_rule' \| 'queue' \| 'assignment_rule' \| 'agent' \| 'tool' \| 'skill' \| 'ai_context' \| 'knowledge_source'>[]` | optional | Filter by metadata types | | **namespaces** | `string[]` | optional | Filter by namespaces | | **packageId** | `string` | optional | Filter by owning package | | **search** | `string` | optional | Full-text search query | @@ -703,7 +703,7 @@ Metadata query with filtering, sorting, and pagination | Property | Type | Required | Description | | :--- | :--- | :--- | :--- | -| **type** | `Enum<'object' \| 'object_extension' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'view' \| 'form' \| 'page' \| 'dashboard' \| 'app' \| 'action' \| 'report' \| … +21 more>` | ✅ | Metadata type | +| **type** | `Enum<'object' \| 'object_extension' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'picklist_extension' \| 'view' \| 'form' \| 'page' \| 'dashboard' \| 'app' \| … +23 more>` | ✅ | Metadata type | | **name** | `string` | ✅ | Item name (snake_case) | | **data** | `Record` | ✅ | Metadata payload | | **namespace** | `string` | optional | Optional namespace | @@ -717,6 +717,7 @@ Metadata query with filtering, sorting, and pagination * `seed` * `mapping` * `picklist` +* `picklist_extension` * `view` * `form` * `page` diff --git a/packages/spec/docs/references/kernel/metadata-plugin.md b/packages/spec/docs/references/kernel/metadata-plugin.md index c1dc567a086..ca1af1abd0e 100644 --- a/packages/spec/docs/references/kernel/metadata-plugin.md +++ b/packages/spec/docs/references/kernel/metadata-plugin.md @@ -173,7 +173,7 @@ const result = MetadataBulkResultSchema.parse(data); | Property | Type | Required | Description | | :--- | :--- | :--- | :--- | -| **types** | `Enum<'object' \| 'object_extension' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'view' \| 'form' \| 'page' \| 'dashboard' \| 'app' \| 'action' \| 'report' \| 'dataset' \| 'flow' \| 'job' \| 'datasource' \| 'external_catalog' \| 'translation' \| 'api' \| 'email_template' \| 'doc' \| 'book' \| 'permission' \| 'position' \| 'capability' \| 'sharing_rule' \| 'queue' \| 'assignment_rule' \| 'agent' \| 'tool' \| 'skill' \| 'ai_context' \| 'knowledge_source'>[]` | optional | Filter by metadata types | +| **types** | `Enum<'object' \| 'object_extension' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'picklist_extension' \| 'view' \| 'form' \| 'page' \| 'dashboard' \| 'app' \| 'action' \| 'report' \| 'dataset' \| 'flow' \| 'job' \| 'datasource' \| 'external_catalog' \| 'translation' \| 'api' \| 'email_template' \| 'doc' \| 'book' \| 'permission' \| 'position' \| 'capability' \| 'sharing_rule' \| 'queue' \| 'assignment_rule' \| 'agent' \| 'tool' \| 'skill' \| 'ai_context' \| 'knowledge_source'>[]` | optional | Filter by metadata types | | **namespaces** | `string[]` | optional | Filter by namespaces | | **packageId** | `string` | optional | Filter by owning package | | **search** | `string` | optional | Full-text search query | @@ -226,6 +226,7 @@ const result = MetadataBulkResultSchema.parse(data); * `seed` * `mapping` * `picklist` +* `picklist_extension` * `view` * `form` * `page` @@ -264,7 +265,7 @@ const result = MetadataBulkResultSchema.parse(data); | Property | Type | Required | Description | | :--- | :--- | :--- | :--- | -| **type** | `Enum<'object' \| 'object_extension' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'view' \| 'form' \| 'page' \| 'dashboard' \| 'app' \| 'action' \| 'report' \| … +21 more>` | ✅ | Metadata type identifier | +| **type** | `Enum<'object' \| 'object_extension' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'picklist_extension' \| 'view' \| 'form' \| 'page' \| 'dashboard' \| 'app' \| … +23 more>` | ✅ | Metadata type identifier | | **label** | `string` | ✅ | Display label for the metadata type | | **description** | `string` | optional | Description of the metadata type | | **filePatterns** | `string[]` | ✅ | Glob patterns to discover files of this type | @@ -287,6 +288,7 @@ const result = MetadataBulkResultSchema.parse(data); * `seed` * `mapping` * `picklist` +* `picklist_extension` * `view` * `form` * `page` diff --git a/packages/spec/src/meta-spelling/meta-url-data.generated.ts b/packages/spec/src/meta-spelling/meta-url-data.generated.ts index c21787bda9a..0ab0a1698da 100644 --- a/packages/spec/src/meta-spelling/meta-url-data.generated.ts +++ b/packages/spec/src/meta-spelling/meta-url-data.generated.ts @@ -54,6 +54,8 @@ export const META_URL_TO_SINGULAR: Readonly> = Object.fre "objectExtensions": "object_extension", "fields": "field", "seeds": "seed", + "picklist_extensions": "picklist_extension", + "picklistExtensions": "picklist_extension", "external_catalogs": "external_catalog", "externalCatalogs": "external_catalog", "translations": "translation", @@ -75,6 +77,7 @@ export const REGISTRY_DECLARED_META_TYPES: ReadonlyArray = Object.freeze "hook", "seed", "picklist", + "picklist_extension", "mapping", "view", "form", From 025c9558e1d0d828f3860131b7f4ca19c71f35c4 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 09:27:12 +0000 Subject: [PATCH 04/14] refactor(#39536): one SchemaRegistry door for a stored picklist_extension row The registry facade sits at its line ceiling (one line left), so the four members become one, storedPicklistExtension(request), classified write; its body lives in the picklists facet, and stored entries are marked in a facet-private WeakSet instead of a registry field. Claude-Session: https://claude.ai/code/session_01L9qibxE6RdcamcqFHHa7PC Co-authored-by: Claude --- .changeset/39536-picklist-extension-item.md | 2 +- .../src/protocol-picklist-extension-item.ts | 46 ++--- packages/objectql/src/registry-picklists.ts | 160 ++++++++++-------- packages/objectql/src/registry-revision.ts | 6 +- packages/objectql/src/registry.ts | 59 +------ .../meta-picklist-extension-item.test.ts | 2 +- 6 files changed, 128 insertions(+), 147 deletions(-) diff --git a/.changeset/39536-picklist-extension-item.md b/.changeset/39536-picklist-extension-item.md index 0909ad4f2c3..a9fcd6d91c4 100644 --- a/.changeset/39536-picklist-extension-item.md +++ b/.changeset/39536-picklist-extension-item.md @@ -18,4 +18,4 @@ Who sees it: an administrator of an installed app (for example a CRM) who needs - The doors also refuse, with `VALIDATION_ERROR` / 400: a write naming no package, a row filed under a name other than its `extend`, a list the package cannot reach (not its own and not declared by a package in its `dependencies`), and a value the list or another package's extension already carries. - A published item is served at once on every field bound to the list, re-registered at boot, replaced on re-publish (a value dropped from the item leaves the list), and withdrawn when the item is deleted or the package uninstalled. - `GET /api/v1/packages//export` carries the items as `picklistExtensions`, and `POST /api/v1/marketplace/install-local` of such a pair writes each entry back as a `picklist_extension` item (before, it refused the key). -- `SchemaRegistry` (`@objectstack/objectql`) gains `replacePicklistExtension`, `picklistExtensionReplacementRefusal`, `withdrawPicklistExtension` and `storedPicklistExtenders`. +- `SchemaRegistry` (`@objectstack/objectql`) gains `storedPicklistExtension(request)`, one door for a stored row's `replace`, `refusal`, `withdraw` and `extenders` requests of its package's contribution to a list. diff --git a/packages/metadata-protocol/src/protocol-picklist-extension-item.ts b/packages/metadata-protocol/src/protocol-picklist-extension-item.ts index 9e65a16e2cf..443d5cc6b93 100644 --- a/packages/metadata-protocol/src/protocol-picklist-extension-item.ts +++ b/packages/metadata-protocol/src/protocol-picklist-extension-item.ts @@ -30,7 +30,7 @@ * - {@link picklistExtensionItemRefusal} — the save / publish / restore gate; * - {@link registrablePicklistExtension} — the parsed body every sync * registers as the package's contribution - * (`SchemaRegistry.replacePicklistExtension`). + * (`SchemaRegistry.storedPicklistExtension`, `replace`). * * The body's SHAPE is judged by the doors' own schema gate * (`resolveOverlaySchema` → {@link PICKLIST_EXTENSION_ITEM_SCHEMA}). What the @@ -67,16 +67,23 @@ export interface PicklistExtensionOption { [key: string]: unknown; } +/** A stored row's request of the registry (`SchemaRegistry#storedPicklistExtension`, `@objectstack/objectql`). */ +export type StoredPicklistExtensionRequest = + | { op: 'replace' | 'refusal'; extension: { extend: string; options: readonly PicklistExtensionOption[] }; packageId: string } + | { op: 'withdraw'; name: string; packageId: string } + | { op: 'extenders'; name: string }; + /** The registry members the gate and the syncs read, reached through the engine. */ export interface PicklistExtensionRegistry { /** The list's resolved options from a caller package's closure; `undefined` = no list reachable. */ resolvePicklistOptions?(name: string, callerPackageId?: string | null): PicklistExtensionOption[] | undefined; - /** The refusal a {@link replacePicklistExtension} of this body would throw, without registering it. */ - picklistExtensionReplacementRefusal?(extension: { extend: string; options: readonly PicklistExtensionOption[] }, packageId: string): Error | undefined; - replacePicklistExtension?(extension: { extend: string; options: readonly PicklistExtensionOption[] }, packageId: string): void; - withdrawPicklistExtension?(name: string, packageId: string): boolean; - /** The packages whose stored (`_provenance: 'org'`) extension of `name` is registered. */ - storedPicklistExtenders?(name: string): string[]; + /** + * A stored row's four requests of its package's contribution to a list: + * `replace` it (throws the registry's refusal), the `refusal` a replace + * would throw (`undefined` = admitted), `withdraw` it (`true` when there + * was one), and the `extenders` whose contribution is a stored row. + */ + storedPicklistExtension?(request: StoredPicklistExtensionRequest): unknown; } type GateRefusal = Error & { code: 'VALIDATION_ERROR'; status: 400; issues?: MetadataIssueEntry[] }; @@ -117,7 +124,7 @@ export interface PicklistExtensionItemSubject { * reference takes), refused naming the dependency to declare. * 5. Additive only: no value repeats inside the item, and none is a value the * list or another package's extension already carries — the registry's own - * refusal (`picklistExtensionReplacementRefusal`, the sentence a sync + * refusal (`storedPicklistExtension` `refusal`, the sentence a sync * would otherwise throw at registration), asked before anything is stored. * * Whether the package is writable is the door's own refusal @@ -184,9 +191,9 @@ export function picklistExtensionItemRefusal( } // 5. - if (typeof registry.picklistExtensionReplacementRefusal === 'function') { - const registrable = { extend: target, options: options.filter(isRecord) as PicklistExtensionOption[] }; - const duplicate = registry.picklistExtensionReplacementRefusal(registrable, binding); + if (typeof registry.storedPicklistExtension === 'function') { + const extension = { extend: target, options: options.filter(isRecord) as PicklistExtensionOption[] }; + const duplicate = registry.storedPicklistExtension({ op: 'refusal', extension, packageId: binding }) as Error | undefined; if (duplicate) return refusal(duplicate.message, [{ path: 'options', message: duplicate.message }]); } return undefined; @@ -216,7 +223,7 @@ export function registrablePicklistExtension(body: unknown): { extend: string; o /** * Register a stored `picklist_extension` row as its package's contribution to * the list it names, REPLACING the package's prior one - * (`SchemaRegistry.replacePicklistExtension`): a re-publish that drops a value + * (`SchemaRegistry.storedPicklistExtension`, `replace`): a re-publish that drops a value * drops it. The one call every sync makes — the write-through, the boot * hydration and the read-side hydration (`protocol-registry-hydration.ts`). A * row bound to no package is never registered: the doors refuse to write one. @@ -232,8 +239,8 @@ export function registerStoredPicklistExtension( packageId: string | null | undefined, ): boolean { if (typeof packageId !== 'string' || packageId === '') return false; - if (typeof registry?.replacePicklistExtension !== 'function') return false; - registry.replacePicklistExtension(registrablePicklistExtension(body), packageId); + if (typeof registry?.storedPicklistExtension !== 'function') return false; + registry.storedPicklistExtension({ op: 'replace', extension: registrablePicklistExtension(body), packageId }); return true; } @@ -248,9 +255,9 @@ export interface StoredPicklistExtensionReads { /** * After a `picklist_extension` row of the list `name` is deleted: withdraw * every stored-row contribution to the list whose row is no longer stored - * (`SchemaRegistry.withdrawPicklistExtension`), and re-register the ones that + * (`SchemaRegistry.storedPicklistExtension`, `withdraw`), and re-register the ones that * are. A code package's manifest entry for the same list is never touched - * (`storedPicklistExtenders` names stored contributions only). A failed read + * (its `extenders` request names stored contributions only). A failed read * throws before anything is withdrawn: an outage is not an absence. */ export async function resyncStoredPicklistExtensions( @@ -258,15 +265,16 @@ export async function resyncStoredPicklistExtensions( name: string, reads: StoredPicklistExtensionReads, ): Promise { - if (typeof registry?.storedPicklistExtenders !== 'function' || typeof registry.withdrawPicklistExtension !== 'function') return; + const ask = registry?.storedPicklistExtension; + if (typeof ask !== 'function') return; const rows = await reads.activeRows(); const stored = new Map>(); for (const row of rows ?? []) { const pkg = typeof row.package_id === 'string' && row.package_id !== '' ? row.package_id : undefined; if (pkg) stored.set(pkg, row); } - for (const pkg of registry.storedPicklistExtenders(name)) { - if (!stored.has(pkg)) registry.withdrawPicklistExtension(name, pkg); + for (const pkg of ask.call(registry, { op: 'extenders', name }) as string[]) { + if (!stored.has(pkg)) ask.call(registry, { op: 'withdraw', name, packageId: pkg }); } for (const [pkg, row] of stored) { try { diff --git a/packages/objectql/src/registry-picklists.ts b/packages/objectql/src/registry-picklists.ts index 8ccf1c8c8be..2a1e182bac7 100644 --- a/packages/objectql/src/registry-picklists.ts +++ b/packages/objectql/src/registry-picklists.ts @@ -84,7 +84,6 @@ export interface PicklistsHost { picklistVocabularySealed: SchemaRegistry['picklistVocabularySealed']; refusePicklistArrival: SchemaRegistry['refusePicklistArrival']; refusePicklistItemArrival: SchemaRegistry['refusePicklistItemArrival']; - registerPicklistExtension: SchemaRegistry['registerPicklistExtension']; registeringPicklistArrival: SchemaRegistry['registeringPicklistArrival']; readonly residualOwnerDependencies: SchemaRegistry['residualOwnerDependencies']; residualOwnerDependenciesOf: SchemaRegistry['residualOwnerDependenciesOf']; @@ -92,6 +91,31 @@ export interface PicklistsHost { resolvePicklistOptions: SchemaRegistry['resolvePicklistOptions']; } +/** + * [#39536] A stored `picklist_extension` row's request of the registry + * (`SchemaRegistry#storedPicklistExtension`), one per question it asks. + */ +export type StoredPicklistExtensionRequest = + | { op: 'replace'; extension: { extend: string; options: readonly PicklistOptionLike[] }; packageId: string } + | { op: 'refusal'; extension: { extend: string; options: readonly PicklistOptionLike[] }; packageId: string } + | { op: 'withdraw'; name: string; packageId: string } + | { op: 'extenders'; name: string }; + +/** What `SchemaRegistry#storedPicklistExtension` answers each request. */ +export type StoredPicklistExtensionAnswer = + R extends { op: 'refusal' } ? Error | undefined + : R extends { op: 'withdraw' } ? boolean + : R extends { op: 'extenders' } ? string[] + : void; + +/** + * The contribution entries that are stored `picklist_extension` rows, not a + * manifest's `picklistExtensions` entries: the entry objects themselves, held + * weakly, so an entry leaves with its map (a withdrawal, an uninstall, a + * reset) and no registry field records the distinction. + */ +const STORED_PICKLIST_EXTENSION_ENTRIES = new WeakSet(); + /** The bodies of the "Plugins, kinds, shared picklists and reset" section of `SchemaRegistry`: a stateless facet, called by the class's stubs. */ export class PicklistsFacet { /** The body of `SchemaRegistry#getAllPlugins`; the method's docblock there is its contract. */ @@ -456,74 +480,78 @@ export class PicklistsFacet { } /** - * The body of `SchemaRegistry#picklistExtensionReplacementRefusal`; the - * method's docblock there is its contract. The additive rule of - * {@link registerPicklistExtension}, asked of a REPLACEMENT of the - * package's own contribution (its current values set aside, as - * {@link replacePicklistExtension} sets them aside), without registering - * anything. - */ - static picklistExtensionReplacementRefusal(this: Pick, extension: { extend: string; options: readonly PicklistOptionLike[] }, packageId: string): Error | undefined { - const target = extension.extend; - const candidate: PicklistContribution = { packageId, kind: 'extension', options: [...(extension.options ?? [])] }; - const others = this.picklistContributions(target).filter( - (c) => !(c.kind === 'extension' && (c.packageId ?? '') === packageId), - ); - const duplicate = findDuplicatePicklistValue([candidate]) ?? findDuplicatePicklistValue([...others, candidate]); - return duplicate ? duplicatePicklistValueError(target, duplicate) : undefined; - } - - /** - * The body of `SchemaRegistry#replacePicklistExtension`; the method's - * docblock there is its contract. The package's own contribution to the - * list is set aside, the new one registered through - * {@link registerPicklistExtension} (every judge it asks, unchanged), and - * the set-aside one put back when that throws, so a refused replacement - * leaves the list as it was. + * The body of `SchemaRegistry#storedPicklistExtension`; the method's + * docblock there is its contract. One door for the four questions a stored + * `picklist_extension` row (`@objectstack/metadata-protocol`) asks of its + * package's contribution to a list, so the registry facade grows by one + * member, classified `write` (`registry-revision.ts`): + * + * - `replace` — the publish, boot and rollback registration. A re-publish + * REPLACES the package's values ({@link registerPicklistExtension} merges + * them, for a manifest replay): the package's current contribution is set + * aside, the new one registered through that body (every judge it asks, + * unchanged), and the set-aside one put back when it throws, so a refused + * replacement leaves the list as it was. The entry is marked stored. + * - `refusal` — what `replace` would refuse for these values (a value + * repeated inside them, or one the list or another package's extension + * already carries: `INVALID_METADATA`, the additive rule's sentence), + * registering nothing; `undefined` = admitted. The doors ask it before a + * row is stored. + * - `withdraw` — the deletion of the row: drop the package's contribution; + * `true` when there was one. + * - `extenders` — the packages whose contribution to the list is a stored + * row, never a manifest's `picklistExtensions` entry. */ - static replacePicklistExtension(this: Pick, extension: { extend: string; options: readonly PicklistOptionLike[] }, packageId: string): void { - const target = extension.extend; - this.notePicklistExtension(target, packageId); - const byPackage = this.picklistExtensionContributions.get(target); - const prior = byPackage?.get(packageId); - byPackage?.delete(packageId); - try { - this.registerPicklistExtension(extension, packageId); - } catch (err) { - if (prior) { - let now = this.picklistExtensionContributions.get(target); - if (!now) this.picklistExtensionContributions.set(target, now = new Map()); - now.set(packageId, prior); - } else if (byPackage && byPackage.size === 0) { - this.picklistExtensionContributions.delete(target); + static storedPicklistExtension(this: Pick, request: StoredPicklistExtensionRequest): void | Error | undefined | boolean | string[] { + const byPackageOf = (name: string) => this.picklistExtensionContributions.get(name); + switch (request.op) { + case 'refusal': { + const { extension, packageId } = request; + const candidate: PicklistContribution = { packageId, kind: 'extension', options: [...(extension.options ?? [])] }; + const others = this.picklistContributions(extension.extend).filter( + (c) => !(c.kind === 'extension' && (c.packageId ?? '') === packageId), + ); + const duplicate = findDuplicatePicklistValue([candidate]) ?? findDuplicatePicklistValue([...others, candidate]); + return duplicate ? duplicatePicklistValueError(extension.extend, duplicate) : undefined; } - this.invalidateAll(); - throw err; + case 'replace': { + const { extension, packageId } = request; + const target = extension.extend; + const prior = byPackageOf(target)?.get(packageId); + byPackageOf(target)?.delete(packageId); + try { + PicklistsFacet.registerPicklistExtension.call(this, extension, packageId); + } catch (err) { + let now = byPackageOf(target); + if (prior) { + if (!now) this.picklistExtensionContributions.set(target, now = new Map()); + now.set(packageId, prior); + } else if (now && now.size === 0) { + this.picklistExtensionContributions.delete(target); + } + this.invalidateAll(); + throw err; + } + const entry = byPackageOf(target)?.get(packageId); + if (entry) STORED_PICKLIST_EXTENSION_ENTRIES.add(entry); + return undefined; + } + case 'withdraw': { + const { name, packageId } = request; + const byPackage = byPackageOf(name); + if (!byPackage?.has(packageId)) return false; + this.notePicklistExtension(name, packageId); + byPackage.delete(packageId); + if (byPackage.size === 0) this.picklistExtensionContributions.delete(name); + this.invalidateAll(); + this.log(`[Registry] Withdrew picklist extension: ${request.name} from ${packageId}`); + return true; + } + case 'extenders': + return [...(byPackageOf(request.name)?.values() ?? [])] + .filter((entry) => STORED_PICKLIST_EXTENSION_ENTRIES.has(entry) && typeof entry.packageId === 'string') + .map((entry) => entry.packageId as string); } - const entry = this.picklistExtensionContributions.get(target)?.get(packageId); - if (entry) entry.stored = true; - } - - /** - * The body of `SchemaRegistry#withdrawPicklistExtension`; the method's - * docblock there is its contract. - */ - static withdrawPicklistExtension(this: Pick, name: string, packageId: string): boolean { - const byPackage = this.picklistExtensionContributions.get(name); - if (!byPackage?.has(packageId)) return false; - this.notePicklistExtension(name, packageId); - byPackage.delete(packageId); - if (byPackage.size === 0) this.picklistExtensionContributions.delete(name); - this.invalidateAll(); - this.log(`[Registry] Withdrew picklist extension: ${name} from ${packageId}`); - return true; - } - - /** The body of `SchemaRegistry#storedPicklistExtenders`; the method's docblock there is its contract. */ - static storedPicklistExtenders(this: Pick, name: string): string[] { - return [...(this.picklistExtensionContributions.get(name)?.values() ?? [])] - .filter((entry) => entry.stored === true && typeof entry.packageId === 'string') - .map((entry) => entry.packageId as string); } /** Drop a package's `picklistExtensions`; `true` when it had any. */ diff --git a/packages/objectql/src/registry-revision.ts b/packages/objectql/src/registry-revision.ts index 3bbca4072b2..0c2fc561376 100644 --- a/packages/objectql/src/registry-revision.ts +++ b/packages/objectql/src/registry-revision.ts @@ -155,10 +155,8 @@ export const SCHEMA_REGISTRY_METHOD_KINDS: Readonly; stored?: boolean }>>(); + private picklistExtensionContributions = new Map }>>(); /** * Package ids that must be installed in a DISABLED state **when they have no @@ -5617,57 +5615,7 @@ export class SchemaRegistry { return PicklistsFacet.registerPicklistExtension.call(picklistsHost.of(this), extension, packageId); } - /** - * [#39536] Replace one package's contribution to a picklist with - * `extension` — the registration of a stored `picklist_extension` row - * (`@objectstack/metadata-protocol`), where a re-publish REPLACES the - * package's values instead of adding to them ({@link registerPicklistExtension} - * merges, for a manifest replay). Every judge {@link registerPicklistExtension} - * asks is asked; a refusal throws and leaves the package's prior - * contribution in place. The contribution is marked stored - * ({@link storedPicklistExtenders}). - */ - replacePicklistExtension( - extension: { extend: string; options: readonly PicklistOptionLike[] }, - packageId: string, - ): void { - return PicklistsFacet.replacePicklistExtension.call(picklistsHost.of(this), extension, packageId); - } - - /** - * [#39536] The refusal {@link replacePicklistExtension} would throw for this - * extension's values — a value repeated inside it, or one the list or - * another package's extension already carries (`INVALID_METADATA`, the - * additive rule's sentence) — without registering anything. `undefined` = - * admitted. The metadata doors ask it before a `picklist_extension` row is - * stored. - */ - picklistExtensionReplacementRefusal( - extension: { extend: string; options: readonly PicklistOptionLike[] }, - packageId: string, - ): Error | undefined { - return PicklistsFacet.picklistExtensionReplacementRefusal.call(picklistsHost.of(this), extension, packageId); - } - - /** - * [#39536] Withdraw one package's contribution to the picklist `name`: the - * deletion of a stored `picklist_extension` row. `true` when there was one. - * A package's manifest entries leave with the package - * ({@link unregisterPicklistExtensionsByPackage}). - */ - withdrawPicklistExtension(name: string, packageId: string): boolean { - return PicklistsFacet.withdrawPicklistExtension.call(picklistsHost.of(this), name, packageId); - } - - /** - * [#39536] The packages whose contribution to the picklist `name` is a - * stored `picklist_extension` row ({@link replacePicklistExtension}), never - * a manifest's `picklistExtensions` entry. - */ - storedPicklistExtenders(name: string): string[] { - return PicklistsFacet.storedPicklistExtenders.call(picklistsHost.of(this), name); - } - + /** [#39536] A stored `picklist_extension` row's `replace` / `refusal` / `withdraw` / `extenders` request of its package's contribution to a list (`PicklistsFacet.storedPicklistExtension`, whose docblock is the contract). */ storedPicklistExtension(request: R): StoredPicklistExtensionAnswer { return PicklistsFacet.storedPicklistExtension.call(picklistsHost.of(this), request) as StoredPicklistExtensionAnswer; } /** * The resolved options of a picklist — its own, then every extension's, in * registration order — or `undefined` when the name reaches no list. @@ -6361,7 +6309,6 @@ export class SchemaRegistry { set picklistVocabularySealed(v) { registry.picklistVocabularySealed = v; }, refusePicklistArrival: (...a) => registry.refusePicklistArrival(...a), refusePicklistItemArrival: (...a) => registry.refusePicklistItemArrival(...a), - registerPicklistExtension: (...a) => registry.registerPicklistExtension(...a), registeringPicklistArrival: (...a) => registry.registeringPicklistArrival(...a), get residualOwnerDependencies() { return registry.residualOwnerDependencies; }, residualOwnerDependenciesOf: (...a) => registry.residualOwnerDependenciesOf(...a), diff --git a/packages/runtime/src/domains/meta-picklist-extension-item.test.ts b/packages/runtime/src/domains/meta-picklist-extension-item.test.ts index 6e54c770d54..88bb614fc70 100644 --- a/packages/runtime/src/domains/meta-picklist-extension-item.test.ts +++ b/packages/runtime/src/domains/meta-picklist-extension-item.test.ts @@ -217,7 +217,7 @@ describe('[#39536] a writable pair saves and publishes an extension of the base\ const rig = await boot(); await rig.saveAndPublish(PAIR, tradeShow()); // The registry forgets the contribution, as a fresh process would. - (rig.engine.registry as any).withdrawPicklistExtension(LIST, PAIR); + (rig.engine.registry as any).storedPicklistExtension({ op: 'withdraw', name: LIST, packageId: PAIR }); expect((await rig.values()).registry).toEqual(VENDOR); const result = await rig.protocol.loadMetaFromDb(); From 48cdfc781f7f66bd3362fd6affa8d11e517d1a6e Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 09:37:17 +0000 Subject: [PATCH 05/14] fix(#39576): PATCH /packages/:id refuses a body key it does not read; picklist_extension reference schema and overrides remedy The package PATCH door reads the manifest wrapper and name, description, version and dependencies; any other key answered 200 and was dropped. It is now refused 400 VALIDATION_ERROR naming the unread keys, from a new sibling module. The picklist_extension type binds PicklistExtensionSchema for the reference-site derivation, and its overrides refusal names the list instead of the new-name remedy. Claude-Session: https://claude.ai/code/session_01L9qibxE6RdcamcqFHHa7PC Co-authored-by: Claude --- .../39576-patch-packages-unread-body-key.md | 13 +++++ .../src/protocol-packaged-base-refusal.ts | 8 +++ .../metadata-protocol/src/reference-sites.ts | 6 +- .../meta-picklist-extension-item.test.ts | 8 +++ .../src/domains/package-patch-body-keys.ts | 55 +++++++++++++++++++ .../packages-patch-dependencies.test.ts | 52 ++++++++++++++++++ packages/runtime/src/domains/packages.ts | 3 + 7 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 .changeset/39576-patch-packages-unread-body-key.md create mode 100644 packages/runtime/src/domains/package-patch-body-keys.ts diff --git a/.changeset/39576-patch-packages-unread-body-key.md b/.changeset/39576-patch-packages-unread-body-key.md new file mode 100644 index 00000000000..fe5db84f6af --- /dev/null +++ b/.changeset/39576-patch-packages-unread-body-key.md @@ -0,0 +1,13 @@ +--- +'@objectstack/runtime': minor +--- + +fix(runtime): `PATCH /api/v1/packages/:id` refuses a body key it does not read + +Clause-②: no (narrowing) +Metadata-protocol: narrowed + +Who sees it: an administrator or an agent who edits a package through `PATCH /api/v1/packages/` and sends a key the door does not read, such as `picklistExtensions`. Until now the door answered `200`, saved `name` / `description` / `version` / `dependencies` if present, and dropped the rest without a word, so the caller believed the extra key was stored. + +- The door reads the `manifest` wrapper and, flat or inside it, `name`, `description`, `version` and `dependencies`. Any other key is now refused with `400 VALIDATION_ERROR`, naming every unread key (`manifest.` inside the wrapper; beside an object wrapper every other top-level key is unread) and the keys the door reads, in the sentence closed query-parameter doors already answer. Nothing is written: not a valid `name` sent beside it. +- Migration: send only the four keys. A package's metadata (a picklist extension, an object extension, any item) is saved as an item through `/api/v1/meta//?package=`, never on this door. Studio's package dialog sends only the four keys and is unaffected. diff --git a/packages/metadata-protocol/src/protocol-packaged-base-refusal.ts b/packages/metadata-protocol/src/protocol-packaged-base-refusal.ts index 8939a73cc2f..320eaf8420c 100644 --- a/packages/metadata-protocol/src/protocol-packaged-base-refusal.ts +++ b/packages/metadata-protocol/src/protocol-packaged-base-refusal.ts @@ -46,6 +46,7 @@ import { } from './packaged-base-regime.js'; import { SysMetadataRepository } from './sys-metadata-repository.js'; import { OBJECT_EXTENSION_TYPE } from './protocol-object-extension-item.js'; +import { PICKLIST_EXTENSION_TYPE } from './protocol-picklist-extension-item.js'; import { customizationPairEnsureRefusal, kernelPackageScope, type PairRegistry } from './protocol-customization-package.js'; import { resolveOverlaySchema } from './protocol-meta-type-schema.js'; import { resolvePackageClosure } from '@objectstack/lint/runtime'; @@ -1232,6 +1233,13 @@ export function judgeOverrideWrite( `${item} carries \`overrides\`, but an object extension takes no override (ADR-0146 D10): it adds to the ` + `object it extends and is stored under that object's name. Remove \`overrides\` and edit the object_extension '${name}' itself.`); } + if (type === PICKLIST_EXTENSION_TYPE) { + // [#39536] Its twin: a picklist extension adds values to the list + // it names and is stored under that name, so "a new name" is no remedy. + return refuse('declared_type_not_overridable', + `${item} carries \`overrides\`, but a picklist extension takes no override (ADR-0146 D10): it adds values to ` + + `the list it extends and is stored under that list's name. Remove \`overrides\` and edit the picklist_extension '${name}' itself.`); + } if (row?.disposition !== 'overridable') { // [#30062] The citation is the type's own basis, and the remedy one that works for the type. const cite = row === undefined ? 'ADR-0146 D2' : EXCLUSION_BASIS_CITATION[row.basis]; diff --git a/packages/metadata-protocol/src/reference-sites.ts b/packages/metadata-protocol/src/reference-sites.ts index 29325584463..5ca6f86348a 100644 --- a/packages/metadata-protocol/src/reference-sites.ts +++ b/packages/metadata-protocol/src/reference-sites.ts @@ -111,7 +111,7 @@ import { z } from 'zod'; import { DEFAULT_METADATA_TYPE_REGISTRY, getMetadataTypeSchema } from '@objectstack/spec/kernel'; import { SCHEMALESS_NODE_CONFIG_SCHEMAS } from '@objectstack/spec/automation'; -import { ObjectExtensionSchema } from '@objectstack/spec/data'; +import { ObjectExtensionSchema, PicklistExtensionSchema } from '@objectstack/spec/data'; /** * One derived fact: an item of `fromType` may name a `target` item through a @@ -296,7 +296,9 @@ function nameVocabularyRejectsKey(type: DeclaredMetadataType, separator: string) * yet what an extension references is readable off its own schema. */ function declaredTypeSchema(type: string): z.ZodType | undefined { - return getMetadataTypeSchema(type) ?? (type === 'object_extension' ? ObjectExtensionSchema : undefined); + // [#39536] …and its twin `picklist_extension`, judged by `PicklistExtensionSchema`. + return getMetadataTypeSchema(type) + ?? (type === 'object_extension' ? ObjectExtensionSchema : type === 'picklist_extension' ? PicklistExtensionSchema : undefined); } /** A declared type's JSON Schema, or `undefined` when it resolves no schema or cannot be converted. */ diff --git a/packages/runtime/src/domains/meta-picklist-extension-item.test.ts b/packages/runtime/src/domains/meta-picklist-extension-item.test.ts index 88bb614fc70..16f8530c93a 100644 --- a/packages/runtime/src/domains/meta-picklist-extension-item.test.ts +++ b/packages/runtime/src/domains/meta-picklist-extension-item.test.ts @@ -351,6 +351,14 @@ describe('[#39536] refused at the door, leaving no row and registering nothing', expect(await rig.rows()).toEqual([]); }, 60_000); + it('a body carrying `overrides`: an extension takes no override, edited under the list\'s name (NOT_OVERRIDABLE / 403)', async () => { + const rig = await boot(); + const caught = await rig.refusalOf(() => rig.protocol.saveMetaItem({ type: TYPE, name: LIST, item: { ...tradeShow(), overrides: { package: BASE, basedOn: '3.4.1' } }, mode: 'draft', packageId: PAIR })); + expect({ code: caught?.code, status: caught?.status }).toEqual({ code: 'NOT_OVERRIDABLE', status: 403 }); + expect(String(caught?.message)).toContain(`edit the picklist_extension '${LIST}' itself`); + expect(await rig.rows()).toEqual([]); + }, 60_000); + it('a read-only package: the base itself (WRITABLE_PACKAGE_REQUIRED / 422)', async () => { const rig = await boot(); const caught = await rig.refusalOf(() => rig.protocol.saveMetaItem({ type: TYPE, name: LIST, item: tradeShow(), mode: 'draft', packageId: BASE })); diff --git a/packages/runtime/src/domains/package-patch-body-keys.ts b/packages/runtime/src/domains/package-patch-body-keys.ts new file mode 100644 index 00000000000..fec047151b2 --- /dev/null +++ b/packages/runtime/src/domains/package-patch-body-keys.ts @@ -0,0 +1,55 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [#39576] `PATCH /api/v1/packages/:id`'s closed body-key set, and the + * refusal of a key outside it. + * + * The door reads the `manifest` wrapper (when it is an object) and, flat or + * inside it, `name`, `description`, `version` and `dependencies` + * (`packages.ts`, the PATCH branch). Any other key was dropped without a word: + * `{ name, picklistExtensions }` answered `200` with the name saved and the + * extension gone, so an administrator or an agent believed it was stored. The + * sentence mirrors the query-parameter refusal every closed door answers + * (`unknownQueryParamRefusalMessage`, `@objectstack/rest`): the unread keys, + * sorted, then the keys this door reads. + * + * A module of its own because `packages.ts` is over a thousand lines: the + * door keeps only the call. + */ + +/** The keys the door reads, flat or under {@link PACKAGE_PATCH_WRAPPER_KEY}. */ +export const PACKAGE_PATCH_BODY_KEYS: readonly string[] = Object.freeze(['dependencies', 'description', 'name', 'version']); + +/** The wrapper the door also accepts the keys under. */ +export const PACKAGE_PATCH_WRAPPER_KEY = 'manifest'; + +const isRecord = (v: unknown): v is Record => + v !== null && typeof v === 'object' && !Array.isArray(v); + +/** + * The located sentence for a PATCH body carrying a key the door does not + * read, or `undefined` when it carries none (or is no object at all, which + * the door's own "nothing to update" answers). A key inside the wrapper is + * named `manifest.`; beside an object wrapper, every other top-level key + * is unread, the four included. + */ +export function packagePatchBodyKeyRefusal(body: unknown): string | undefined { + if (!isRecord(body)) return undefined; + const wrapper = body[PACKAGE_PATCH_WRAPPER_KEY]; + const wrapped = isRecord(wrapper); + const permitted = new Set(PACKAGE_PATCH_BODY_KEYS); + const unknown = wrapped + ? [ + ...Object.keys(body).filter((key) => key !== PACKAGE_PATCH_WRAPPER_KEY), + ...Object.keys(wrapper).filter((key) => !permitted.has(key)).map((key) => `${PACKAGE_PATCH_WRAPPER_KEY}.${key}`), + ] + : Object.keys(body).filter((key) => !permitted.has(key)); + if (unknown.length === 0) return undefined; + unknown.sort(); + const subject = unknown.length === 1 + ? `The "${unknown[0]}" body key is not read by this endpoint.` + : `The body keys ${unknown.map((key) => `"${key}"`).join(', ')} are not read by this endpoint.`; + return `${subject} This endpoint will not silently ignore a key it does not read — a dropped key answers ` + + `as if it were saved. Supported keys: ${PACKAGE_PATCH_BODY_KEYS.join(', ')}, flat or all under ` + + `\`${PACKAGE_PATCH_WRAPPER_KEY}\`; a package's metadata is saved as items through /api/v1/meta, not here.`; +} diff --git a/packages/runtime/src/domains/packages-patch-dependencies.test.ts b/packages/runtime/src/domains/packages-patch-dependencies.test.ts index a886d10a4a0..cf878457c0b 100644 --- a/packages/runtime/src/domains/packages-patch-dependencies.test.ts +++ b/packages/runtime/src/domains/packages-patch-dependencies.test.ts @@ -225,3 +225,55 @@ describe('[#24670] PATCH /packages/:id — the three existing keys behave as bef expect(updatePackage).toHaveBeenCalledWith({ packageId: ID, patch: { description: 'after', dependencies: DECLARED } }); }); }); + +/** + * [#39576] The door refuses a body key it does not read. It reads the + * `manifest` wrapper and, flat or inside it, `name`, `description`, `version` + * and `dependencies`; any other key answered `200` and was dropped, so an + * administrator or an agent sending `picklistExtensions` believed it saved. + * Now: `400 VALIDATION_ERROR` naming every unread key and the keys the door + * reads, and nothing written — not a valid `name` sent beside it, and on the + * protocol branch the protocol is never called. + */ +describe('[#39576] PATCH /packages/:id refuses a body key it does not read', () => { + for (const [form, wrap, prefix] of [ + ['flat', (patch: object) => patch, ''], + ['under the `manifest` wrapper', (patch: object) => ({ manifest: patch }), 'manifest.'], + ] as const) { + it(`${form}: \`picklistExtensions\` and an unknown key beside a valid \`name\` are refused, and nothing is written`, async () => { + const updatePackage = vi.fn(async () => ({ package: {} })); + const p = boot({ updatePackage }); + const before = p.stored(); + + const patched = await p.call('PATCH', `/${ID}`, wrap({ + name: 'Renamed', + picklistExtensions: [{ extend: 'lead_source', options: [{ label: 'Trade show', value: 'trade_show__c' }] }], + colour: 'blue', + })); + + expect({ status: patched.status, code: patched.code }, JSON.stringify(patched.body)).toEqual({ status: 400, code: 'VALIDATION_ERROR' }); + const message = String(patched.body?.error?.message); + expect(message).toContain(`"${prefix}colour"`); + expect(message).toContain(`"${prefix}picklistExtensions"`); + expect(updatePackage).not.toHaveBeenCalled(); + expect(p.stored()).toEqual(before); + }); + } + + it('a key beside the `manifest` wrapper is unread too: refused', async () => { + const p = boot(); + const patched = await p.call('PATCH', `/${ID}`, { manifest: { name: 'Renamed' }, name: 'Other' }); + expect({ status: patched.status, code: patched.code }).toEqual({ status: 400, code: 'VALIDATION_ERROR' }); + expect(String(patched.body?.error?.message)).toContain('"name"'); + expect(p.stored().name).toBe('Acme CRM'); + }); + + it('CONTROL: a body of the four keys it reads is admitted, flat and wrapped', async () => { + const p = boot(); + const flat = await p.call('PATCH', `/${ID}`, { name: 'Renamed', description: 'after', version: '1.1.0', dependencies: { ...DECLARED } }); + expect(flat.status, JSON.stringify(flat.body)).toBe(200); + const wrapped = await p.call('PATCH', `/${ID}`, { manifest: { name: 'Again' } }); + expect(wrapped.status, JSON.stringify(wrapped.body)).toBe(200); + expect(p.stored().name).toBe('Again'); + }); +}); diff --git a/packages/runtime/src/domains/packages.ts b/packages/runtime/src/domains/packages.ts index 93eacd735a6..a7c96be8617 100644 --- a/packages/runtime/src/domains/packages.ts +++ b/packages/runtime/src/domains/packages.ts @@ -54,6 +54,7 @@ import { resolveKnowledgeServiceForSave } from '../knowledge-service-lookup.js'; import { canonicalMetaUrlType } from '@objectstack/spec/shared'; import { isMissingTableError } from '@objectstack/types'; import { readEffectiveTenancyPosture } from './activation-gate.js'; +import { packagePatchBodyKeyRefusal } from './package-patch-body-keys.js'; // [#21727] ADR-0087 D1's protocol handshake and the brand predicate for its // refusal. The install branch asks the predicate ahead of its generic catch, // and its no-protocol fallback runs the same handshake. @@ -4386,6 +4387,8 @@ export async function handlePackagesRequest(deps: DomainHandlerDeps, path: strin // installed is writable by the predicate's own rule, so it still // reaches the 404 below. const readOnly = requireWritablePackage(deps, qlService, id, 'edit'); if (readOnly) return readOnly; + // [#39576] A key the door does not read is refused, never dropped. + const unreadKeys = packagePatchBodyKeyRefusal(body); if (unreadKeys) return { handled: true, response: deps.error(unreadKeys, 400, { code: 'VALIDATION_ERROR' }) }; const wrapped = Boolean(body?.manifest && typeof body.manifest === 'object'); const src = (wrapped ? body.manifest : body) ?? {}; const patch: { From 6c0e52a8f59a51de6b4532f0a44518ae82189d63 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 09:38:12 +0000 Subject: [PATCH 06/14] fix(#39576): register the PATCH /packages body-key narrowing as an ADR-0087 semantic entry Claude-Session: https://claude.ai/code/session_01L9qibxE6RdcamcqFHHa7PC Co-authored-by: Claude --- .../39576-patch-packages-unread-body-key.md | 2 ++ ...9.package-patch-unread-body-key-refused.ts | 24 +++++++++++++++++++ .../semantic-relevance-coverage-38929.test.ts | 4 ++++ 3 files changed, 30 insertions(+) create mode 100644 packages/spec/src/migrations/entries/semantic/19.package-patch-unread-body-key-refused.ts diff --git a/.changeset/39576-patch-packages-unread-body-key.md b/.changeset/39576-patch-packages-unread-body-key.md index fe5db84f6af..e5430926029 100644 --- a/.changeset/39576-patch-packages-unread-body-key.md +++ b/.changeset/39576-patch-packages-unread-body-key.md @@ -11,3 +11,5 @@ Who sees it: an administrator or an agent who edits a package through `PATCH /ap - The door reads the `manifest` wrapper and, flat or inside it, `name`, `description`, `version` and `dependencies`. Any other key is now refused with `400 VALIDATION_ERROR`, naming every unread key (`manifest.` inside the wrapper; beside an object wrapper every other top-level key is unread) and the keys the door reads, in the sentence closed query-parameter doors already answer. Nothing is written: not a valid `name` sent beside it. - Migration: send only the four keys. A package's metadata (a picklist extension, an object extension, any item) is saved as an item through `/api/v1/meta//?package=`, never on this door. Studio's package dialog sends only the four keys and is unaffected. + + diff --git a/packages/spec/src/migrations/entries/semantic/19.package-patch-unread-body-key-refused.ts b/packages/spec/src/migrations/entries/semantic/19.package-patch-unread-body-key-refused.ts new file mode 100644 index 00000000000..ad3602d0e19 --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/19.package-patch-unread-body-key-refused.ts @@ -0,0 +1,24 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// #39576 — the package edit door's closed body-key set. A REST request body, +// never stored in stack metadata: there is no source for the chain to rewrite. +export const entry: SemanticMigration = { + id: 'package-patch-unread-body-key-refused', + surface: + 'the PATCH /api/v1/packages/:id request body — any key other than name, description, version and ' + + 'dependencies (flat, or all under the `manifest` wrapper)', + replacement: + 'send only name, description, version and dependencies; a package\'s metadata (a picklist ' + + 'extension, an object extension, any item) is saved as an item through ' + + 'PUT /api/v1/meta//?package=', + reason: + 'The door read four keys and answered 200 for a body carrying any other, saving the four and ' + + 'dropping the rest without a word, so a caller that sent a key such as `picklistExtensions` ' + + 'believed it was stored. It is now refused 400 VALIDATION_ERROR naming every unread key. Nothing ' + + 'that was dropped was ever stored, so no stored row changes; what a caller owes is its request.', + acceptanceCriteria: + 'Every PATCH /api/v1/packages/:id call the deployment\'s clients and scripts make sends only the four ' + + 'keys and answers 200; none answers 400 VALIDATION_ERROR naming an unread body key.', +}; diff --git a/packages/spec/src/migrations/semantic-relevance-coverage-38929.test.ts b/packages/spec/src/migrations/semantic-relevance-coverage-38929.test.ts index db443c52729..b5e224c9008 100644 --- a/packages/spec/src/migrations/semantic-relevance-coverage-38929.test.ts +++ b/packages/spec/src/migrations/semantic-relevance-coverage-38929.test.ts @@ -162,6 +162,10 @@ const STAYS_LISTED: Readonly Date: Fri, 4 Dec 2026 09:49:57 +0000 Subject: [PATCH 07/14] test(#39536): the exact-qualifier enumerations list picklist_extension beside its twin Claude-Session: https://claude.ai/code/session_01L9qibxE6RdcamcqFHHa7PC Co-authored-by: Claude --- .../objectql/src/package-scoped-exact-qualifier.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/objectql/src/package-scoped-exact-qualifier.test.ts b/packages/objectql/src/package-scoped-exact-qualifier.test.ts index dc90122b83f..73d094296e1 100644 --- a/packages/objectql/src/package-scoped-exact-qualifier.test.ts +++ b/packages/objectql/src/package-scoped-exact-qualifier.test.ts @@ -873,7 +873,7 @@ describe('[#34040] the exact read never serves the service\'s copy of another pa expect([...COVERED].sort()).toEqual([...UNWIRED_COVERED_TYPES].sort()); expect([...OUTSIDE].sort()).toEqual( // [ADR-0150 addendum 2026-11-25] `ai_context` left this list: the registry reads it by `(package, name)`. - ['capability', 'datasource', 'doc', 'external_catalog', 'field', 'form', 'object', 'object_extension', 'position', 'seed', 'translation', 'view'], + ['capability', 'datasource', 'doc', 'external_catalog', 'field', 'form', 'object', 'object_extension', 'picklist_extension', 'position', 'seed', 'translation', 'view'], ); }); @@ -964,8 +964,8 @@ describe('[#34247] the exact read of a name the package holds no item of is refu const itemAt = async (served: ObjectStackProtocolImplementation, type: string, packageId: string) => (await served.getMetaItem({ type, name: 'shared', packageId }))?.item as { label?: string } | undefined; - it('the family: the nine types the #34040 pin fixes (`form` joins with ADR-0159) (`ai_context` is read by package since ADR-0150\'s 2026-11-25 addendum)', () => { - expect([...OUTSIDE_PINNED].sort()).toEqual(['datasource', 'doc', 'external_catalog', 'field', 'form', 'object_extension', 'seed', 'translation', 'view']); + it('the family: the types the #34040 pin fixes (`form` joins with ADR-0159, `picklist_extension` with #39536) (`ai_context` is read by package since ADR-0150\'s 2026-11-25 addendum)', () => { + expect([...OUTSIDE_PINNED].sort()).toEqual(['datasource', 'doc', 'external_catalog', 'field', 'form', 'object_extension', 'picklist_extension', 'seed', 'translation', 'view']); }); it.each(OUTSIDE_PINNED.flatMap((type) => [[type, [A, B]], [type, [B, A]]] as const))( @@ -1101,7 +1101,7 @@ describe('[#34041] the read naming no package serves the one enabled holder besi it('the enumeration: every type the registry does not read by package is pinned below, one-holder, or judged elsewhere', () => { expect([...TWO_HOLDER].sort()).toEqual( // [ADR-0150 addendum 2026-11-25] `ai_context` left this list: the registry reads it by `(package, name)`. - ['assignment_rule', 'datasource', 'doc', 'external_catalog', 'field', 'form', 'hook', 'job', 'object_extension', 'queue', 'seed', 'sharing_rule', 'translation', 'view'], + ['assignment_rule', 'datasource', 'doc', 'external_catalog', 'field', 'form', 'hook', 'job', 'object_extension', 'picklist_extension', 'queue', 'seed', 'sharing_rule', 'translation', 'view'], ); }); From 6aefd3fdfc95a175eb508f858f1e85c62475d10a Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 10:01:06 +0000 Subject: [PATCH 08/14] i18n(#39536): picklist_extension type label and description in every locale; translation pins derive instead of count The registry gained `picklist_extension`, so the metadata-forms bundles carry its display pair: regenerated and authored in all ten translated locales. The two translation ledgers pinned type and label counts that move with every new type; per AGENTS.md "Volatile counts are deleted, not synced" those pins are deleted and replaced by derived equalities (bare + panel = registry, labels = bare types, descriptions = described bare types, translated labels = carried labels). Claude-Session: https://claude.ai/code/session_01L9qibxE6RdcamcqFHHa7PC Co-authored-by: Claude --- .../ar.metadata-forms.generated.ts | 4 + .../bare-type-display-echo-decisions.test.ts | 53 ++-- .../de.metadata-forms.generated.ts | 4 + .../en.metadata-forms.generated.ts | 4 + .../es-ES.metadata-forms.generated.ts | 4 + .../fr.metadata-forms.generated.ts | 4 + .../ja-JP.metadata-forms.generated.ts | 4 + .../ko.metadata-forms.generated.ts | 4 + ...ect-lifecycle-panel-echo-decisions.test.ts | 247 +----------------- .../pt-BR.metadata-forms.generated.ts | 4 + .../ru.metadata-forms.generated.ts | 4 + .../zh-CN.metadata-forms.generated.ts | 4 + .../zh-Hant.metadata-forms.generated.ts | 4 + 13 files changed, 71 insertions(+), 273 deletions(-) diff --git a/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts index dcfe9ff902e..e95a0a9cdef 100644 --- a/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts @@ -1343,6 +1343,10 @@ export const arMetadataForms: NonNullable = { } } }, + picklist_extension: { + label: "امتداد قائمة الاختيار", + description: "قيم تضيفها حزمة إلى قائمة اختيار تملكها حزمة أخرى" + }, mapping: { label: "تعيين الاستيراد", description: "تعيين حقول قابل لإعادة الاستخدام للاستيراد/التصدير (إعادة تسمية + تحويلات)، يُشار إليه بالاسم عند الاستيراد", diff --git a/packages/platform-objects/src/apps/translations/bare-type-display-echo-decisions.test.ts b/packages/platform-objects/src/apps/translations/bare-type-display-echo-decisions.test.ts index c9e1f292ebe..71c5232f2fd 100644 --- a/packages/platform-objects/src/apps/translations/bare-type-display-echo-decisions.test.ts +++ b/packages/platform-objects/src/apps/translations/bare-type-display-echo-decisions.test.ts @@ -794,47 +794,34 @@ describe('#19403 round 7 — the provenance table agrees these leaves are now au }); describe('#19403 round 7 — the population, DERIVED from the registry and a shape', () => { - it('⭐ the registry and the catalog describe the same 35 metadata types', () => { + it('⭐ the registry and the catalog describe the same metadata types', () => { // The ratchet's anchor. The catalog is GENERATED from this registry, so a // new metadata type arrives in both at once — which is what makes the bare // class below pick up a future unauthored display pair without anybody // adding it to a list. - // 27 → 28: `picklist` joined the registry, a bare type (no form) with a description. - // 28 → 29: `sharing_rule` joined it (ADR-0131 D6), bare with a description too. - // 29 → 31: `queue` and `assignment_rule` joined it (ADR-0142 D1/D5), both bare - // with a description, and both authored in the three locales on arrival. - // 31 → 32: `object_extension` joined it (ADR-0146 D10, #28574), bare with a - // description, authored in the three locales on arrival. - // 32 → 33: `ai_context` joined it (ADR-0160 D1, #37140), bare with a label - // and no description, authored in the three locales on arrival. - // 33 → 34: `form` joined it (ADR-0159 card ②, #37086), bare with a label - // and no description (no designer until card ③), authored on arrival. - // 34 → 35: `knowledge_source` joined it (ADR-0161 K4, #37304), bare with a - // label and no description, authored in every locale on arrival. - expect(REGISTRY_TYPES.length).toBe(35); + // No count pin: a type count moves with ordinary development, so it is + // deleted rather than synced (AGENTS.md, "Volatile counts are deleted, not + // synced"). The set equality below is the anchor. + expect(REGISTRY_TYPES.length).toBeGreaterThan(0); expect([...REGISTRY_TYPES].sort()).toEqual(Object.keys(enMetadataForms as Record).sort()); }); it('the BARE predicate splits that population, and is read off the SHAPE not a name list', () => { - // Lit. - // 16 / 17 → 15 / 18: `ai_context` gained its form (ADR-0160 D1 clause 2, - // #37143), so it is a panel type now. - // 15 → 16: `form` joined bare (ADR-0159 card ②, #37086). - // 16 / 18 → 17 / 18: `knowledge_source` arrives bare (#37304). - // 17 / 18 → 16 / 19: `knowledge_source` gained its form (ADR-0161 K4 - // clause 2, #37309), so it is a panel type now. - expect(BARE_TYPES.length).toBe(16); - expect(PANEL_TYPES.length).toBe(19); + // Lit, without a count pin (AGENTS.md, "Volatile counts are deleted, not + // synced"): both halves are non-empty and they add up to the registry. + expect(BARE_TYPES.length).toBeGreaterThan(0); + expect(PANEL_TYPES.length).toBeGreaterThan(0); expect(BARE_TYPES.length + PANEL_TYPES.length).toBe(REGISTRY_TYPES.length); - for (const type of ['seed', 'mapping', 'api', 'doc', 'book', 'capability', 'picklist', 'sharing_rule', 'queue', 'assignment_rule', 'object_extension']) { + for (const type of ['seed', 'mapping', 'api', 'doc', 'book', 'capability', 'picklist', 'sharing_rule', 'queue', 'assignment_rule', 'object_extension', 'picklist_extension']) { expect(BARE_TYPES, `${type} is bare`).toContain(type); } for (const type of AUTHORED_BARE_TYPES) expect(BARE_TYPES, `${type} is bare`).toContain(type); - // 27 leaves: sixteen labels, and a description on the eleven that carry one - // (`knowledge_source`, label only, left the class with its form, #37309). - expect(BARE_LEAVES.length).toBe(27); - expect(BARE_LEAVES.filter((l) => l.prop === 'label').length).toBe(16); - expect(BARE_LEAVES.filter((l) => l.prop === 'description').length).toBe(11); + // One label per bare type, and a description on each bare type whose + // registry entry carries one — derived, not counted. + const describedBare = BARE_TYPES.filter((t) => typeof registryEntry(t)?.description === 'string'); + expect(BARE_LEAVES.filter((l) => l.prop === 'label').length).toBe(BARE_TYPES.length); + expect(BARE_LEAVES.filter((l) => l.prop === 'description').length).toBe(describedBare.length); + expect(BARE_LEAVES.length).toBe(BARE_TYPES.length + describedBare.length); expect(BARE_LEAVES.every((l) => ['label', 'description'].includes(l.prop))).toBe(true); }); @@ -853,8 +840,8 @@ describe('#19403 round 7 — the population, DERIVED from the registry and a sha expect(registryEntry('dataset')?.description, 'dataset carries a registry description like the six').toBeTruthy(); expect(isBare('dataset')).toBe(false); const described = REGISTRY_TYPES.filter((t) => typeof registryEntry(t)?.description === 'string'); - expect([...described].sort()).toEqual(['api', 'assignment_rule', 'book', 'capability', 'dataset', 'doc', 'mapping', 'object_extension', 'picklist', 'queue', 'seed', 'sharing_rule']); - expect(described.filter(isBare).sort()).toEqual(['api', 'assignment_rule', 'book', 'capability', 'doc', 'mapping', 'object_extension', 'picklist', 'queue', 'seed', 'sharing_rule']); + expect([...described].sort()).toEqual(['api', 'assignment_rule', 'book', 'capability', 'dataset', 'doc', 'mapping', 'object_extension', 'picklist', 'picklist_extension', 'queue', 'seed', 'sharing_rule']); + expect(described.filter(isBare).sort()).toEqual(['api', 'assignment_rule', 'book', 'capability', 'doc', 'mapping', 'object_extension', 'picklist', 'picklist_extension', 'queue', 'seed', 'sharing_rule']); // And no panel type's own display pair echoes — the exclusion removes only // leaves that are already decided elsewhere or already authored. const panelEchoes: string[] = []; @@ -915,13 +902,13 @@ describe('#19403 round 7 — the population, DERIVED from the registry and a sha expect(flagged.length).toBe(BARE_LEAVES.length); }); - it('⭐ this class is now DONE — zero of its 27 leaves echoes in all three locales', () => { + it('⭐ this class is now DONE — zero of its leaves echoes in all three locales', () => { const echoing = BARE_LEAVES.filter((l) => TRANSLATED_LOCALES.every(([, forms]) => forms[l.type]?.[l.prop] === l.en), ); expect(echoing.map((l) => `${l.type}.${l.prop}`)).toEqual([]); // Lit — and it really walked the class, which a zero alone would not show. - expect(BARE_LEAVES.length).toBe(27); + expect(BARE_LEAVES.length).toBeGreaterThan(0); }); }); diff --git a/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts index 682eb2bf9af..f78724f4248 100644 --- a/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts @@ -1343,6 +1343,10 @@ export const deMetadataForms: NonNullable = { } } }, + picklist_extension: { + label: "Auswahllisten-Erweiterung", + description: "Werte, die ein Paket einer Auswahlliste hinzufügt, die einem anderen Paket gehört" + }, mapping: { label: "Importzuordnung", description: "Wiederverwendbare Feldzuordnung für Import/Export (Umbenennung + Transformationen), beim Import per Name referenziert", diff --git a/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts index 00b50936924..d3a435c0c05 100644 --- a/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts @@ -1343,6 +1343,10 @@ export const enMetadataForms: NonNullable = { } } }, + picklist_extension: { + label: "Picklist Extension", + description: "Values a package adds to a picklist another package owns" + }, mapping: { label: "Import Mapping", description: "Reusable import/export field mapping (rename + transforms), referenced by name at import", diff --git a/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts index 5e12a0c3629..5479cd42dd0 100644 --- a/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts @@ -1343,6 +1343,10 @@ export const esESMetadataForms: NonNullable = } } }, + picklist_extension: { + label: "Extensión de Lista de selección", + description: "Valores que un paquete añade a una lista de selección que posee otro paquete" + }, mapping: { label: "Mapeo de importación", description: "Mapeo de campos de importación/exportación reutilizable (renombrado + transformaciones), referenciado por nombre al importar", diff --git a/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts index c0a2b184f3d..f89ea49bfd2 100644 --- a/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts @@ -1343,6 +1343,10 @@ export const frMetadataForms: NonNullable = { } } }, + picklist_extension: { + label: "Extension de liste de sélection", + description: "Valeurs qu’un package ajoute à une liste de sélection appartenant à un autre package" + }, mapping: { label: "Mappage d’import", description: "Mappage de champs d’import/export réutilisable (renommage + transformations), référencé par son nom lors de l’import", diff --git a/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts index de615a065b7..cec1d424397 100644 --- a/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts @@ -1343,6 +1343,10 @@ export const jaJPMetadataForms: NonNullable = } } }, + picklist_extension: { + label: "選択リスト拡張", + description: "パッケージが、別のパッケージの所有する選択リストに追加する値" + }, mapping: { label: "インポートマッピング", description: "再利用可能なインポート/エクスポートのフィールドマッピング(リネーム + 変換)。インポート時に名前で参照します", diff --git a/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts index 8c12cd1e3b0..bd806f8ef11 100644 --- a/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts @@ -1343,6 +1343,10 @@ export const koMetadataForms: NonNullable = { } } }, + picklist_extension: { + label: "선택 목록 확장", + description: "패키지가 다른 패키지가 소유한 선택 목록에 추가하는 값" + }, mapping: { label: "가져오기 매핑", description: "가져올 때 이름으로 참조하는 재사용 가능한 가져오기/내보내기 필드 매핑(이름 변경 + 변환)", diff --git a/packages/platform-objects/src/apps/translations/object-lifecycle-panel-echo-decisions.test.ts b/packages/platform-objects/src/apps/translations/object-lifecycle-panel-echo-decisions.test.ts index b7d17ace88e..c6d2b3087e6 100644 --- a/packages/platform-objects/src/apps/translations/object-lifecycle-panel-echo-decisions.test.ts +++ b/packages/platform-objects/src/apps/translations/object-lifecycle-panel-echo-decisions.test.ts @@ -1132,246 +1132,13 @@ describe('#19403 round 10 — the verdicts, on the live bundles', () => { // `.label` leaves, which a parser matching everything could not produce. for (const [locale, m] of catalogs) { const translated = [...en].filter(([k, v]) => k.endsWith('.label') && m.get(k) !== undefined && m.get(k) !== v); - // 583 since #19331: that card gave 45 declared-but-unoffered scalar keys a - // form row each across ten forms, and authored every one of their labels - // in all three locales rather than leaving it an extractor fill — so this - // control moves by exactly the number of rows that landed, in every - // locale, which is the reading a per-locale count is for. 584 since - // #19814: the view form's new `pagination` section, its label authored - // in all three locales. 609 since #19955: the 25 row labels of the view - // form's `columns` / `sort` / `tabs` repeaters, authored in all three - // locales. 608 since #20161: the report form's joined-block `chart` row - // left with its key (nothing ever drew a block chart), taking its label - // — authored in all three locales — out of the catalog. 614 since #20349: - // six new row labels (the object form's `highlightFields`, - // `searchableFields`, `access`, `access.default` and `requiredPermissions`, - // and the permission form's `adminScope`), authored in all three locales. - // 633 since #19332 flight G1b: nineteen new row labels — the field form's - // `accept`, `currencyConfig` (and its `currencyMode` / `defaultCurrency`), - // `dependsOn`, `lookupColumns`, `lookupFilters`, `relatedListColumns`, - // `storage` (and its `notNull`), `visibleWhen`, `readonlyWhen`, - // `requiredWhen` and `requiredPermissions`, and the action form's - // `patch`, `description`, `errorMessage`, `requiredPermissions` and - // `bodyExtra` — authored in all three locales. - // 623 since #20301: - // the list view's own `tabs` is a retired key, and its form repeater left - // `view.metadata-form.ts` with it — the repeater's own label and its nine row labels - // (`name`, `label`, `icon`, `view`, `filter`, `order`, `pinned`, - // `isDefault`, `visible`), ten leaves authored in all three locales, out of - // the catalog. - // 634 since #19332 flight G2a: eleven new row labels — the object form's - // `fieldGroups` repeater (and its `key`, `label`, `icon`, `description`, - // `collapse` and `visibleWhen` sub-rows) and its `indexes` repeater (and - // its `name`, `fields` and `unique` sub-rows) — authored in all three - // locales. - // 657 since #19332 flight G2b: twenty-three new row labels — the object - // form's `activityMilestones` repeater (and its `field`, `value`, - // `summary` and `type` sub-rows), `publicSharing` composite (and its - // `enabled`, `allowedAudiences`, `allowedPermissions`, `maxExpiryDays`, - // `redactFields` and `eligibility` sub-rows) and `userActions` composite - // (and its `create`, `import`, `edit`, `delete` and `exportCsv` - // sub-rows), and the field form's `inlineColumns` repeater (and its - // `name`, `label`, `width` and `defaultHidden` sub-rows) — authored in all - // three locales. - // 658 with the `picklist` metadata type's display pair, authored in all - // three locales. - // 659 since the field form offers `useGrouping` on `number` fields: one - // new row label, authored in all three locales. - // 660 since the agent form offers `structuredOutput`: one new row label, - // authored in all three locales. - // 659 since #21320: the agent form's `lifecycle` row left with its key - // (the conversation state machine was retired — nothing ever read it), - // taking its label — authored in all three locales — out of the catalog. - // 660 since #21765: the object form offers `imageField` beside - // `nameField` — one new row label, authored in all three locales. - // 661 since the action form offers `requiresMembershipReach` beside - // `requiresFeature` — one new row label, authored in all three locales. - // 665 since the action form offers `outcomeMessages` and the `onSuccess` - // composite (with its `navigate` and `openIn` sub-rows) beside - // `successMessage` — four new row labels, authored in all three locales. - // 667 since the field form offers the deadline pair on date and datetime - // fields, `dueLike` and `settledWhen` — two new row labels, authored in - // all three locales. - // 668 since the object form offers `enable.approvalsVisibleToReaders`, - // the per-object opt-in for the read-only record-reader approval tier — - // one new row label, authored in all three locales. - // 669 since the position form offers `permissionSets` (ADR-0131 D3/D4), - // the sets a position distributes — one new row label, authored in all - // three locales. - // 670 since the field form offers `mailAssociation` on email fields, the - // inbound-mail correspondent flag — one new row label, authored in all - // three locales. - // 668 since #22876: the email-template form's `category` select and - // `isSystem` checkbox left with their keys (both retired — nothing read - // either), taking their two labels — authored in all three locales — out - // of the catalog. - // 669 since the page form offers `interfaceConfig.emptyState`, the list - // page's own empty state, once the console list page draws it — one new - // row label, authored in all three locales. - // 672 since the field form offers the `referenceDeletedWhen` composite - // beside `referenceVia`, with its `field` and `value` sub-rows — three new - // row labels, authored in all three locales. - // 674 since #23809: the options repeaters gain `kind`, the option's - // lifecycle category — one row label on the field form, one on the - // object form, authored in all three locales. - // 673 since #23891: the permission-set form's `managedBy` select left - // with its key (retired — nothing read the authored provenance), taking - // its label — authored in all three locales — out of the catalog. - // 674 since ADR-0131 D6: `sharing_rule` joined the registry, so the catalog - // gains its type-level display pair — authored in all three locales. - // 673 since #24640: the view form's `filterableFields` input left with its - // key (retired — declared as the `userFilters.fields` shorthand, read as a - // Filter-panel whitelist), taking its label — authored in all three - // locales — out of the catalog. - // 677 since #24692: the view form's and the page form's `addRecord` - // composites spell out their two live sub-rows (`enabled`, `position`; - // `mode` / `formView` were retired), four new row labels authored in all - // three locales. - // 678 since #25330: the dataset form's dimensions repeater offers - // `nullLabel` once its liveness verdict went live — one row label, - // authored in all three locales. - // 679 since the flow form offers `requiredPermissions` (who may start the - // flow) — one row label, authored in all three locales. - // 680 since the dataset form's measures repeater offers `duration` (the - // time between two datetime fields) — one row label, authored in all - // three locales. - // 683 since #25760 (ADR-0055 §3 amendment): the object form's `sharing` - // composite — the block, its `controlledByParent` sub-block and the - // `ownerMayEdit` toggle — three row labels, authored in all three locales. - // 686 since #26548: the report form's "Period & export" section and its - // `dateRange` / `exportOptions` composites — the section label and two - // row labels, authored in all three locales. - // 688 since ADR-0142: `queue` and `assignment_rule` joined the registry, - // each with its type-level display pair, authored in all three locales. - // 689 since #26619: the action form's `disabledReason` row (why a greyed - // action is unavailable) — one row label, authored in all three locales. - // 690 since #26602: the dataset form's measures repeater offers `polarity` - // (which direction of a KPI delta is good news) — one row label, authored - // in all three locales. - // 693 since #26835: the hook form's `refusals` record and its `message` / - // `status` entry fields — three row labels, authored in all three locales. - // 695 since #27069: the object form's `relatedLists` row and the - // `fieldGroups` repeater's `relatedList` sub-row — two row labels, - // authored in all three locales. - // 694 since #26674: the field form no longer offers `externalId` (graded - // `dead`) — one row label fewer, in all three locales. - // 695 since #27184: the field form's `currencyConfig.currencyField` row - // (record currency mode) — one row label, authored in all three locales. - // 696 since #28255: the field form's `percentDisplay` row (a percent - // field's read-only face, bar or plain) — one row label, authored in all - // three locales. - // 697 since #28158: the action form's `submitText` row (the verb on the - // param dialog's submit button) — one row label, authored in all three - // locales. - // 698 since #28574 (ADR-0146 D10): `object_extension` joined the registry - // with its type-level display pair, authored in all three locales. - // 699 since #28879: the action form's `cancelText` row (the dismiss - // label of the action's confirm and param dialogs) — one row label, - // authored in all three locales. - // 700 since #29462: the field form's `referenceNameVisible` row (a lookup - // or user field shows a refused target's name as plain text) — one row - // label, authored in all three locales. - // 701 since #29442: the flow form's variables repeater offers - // `objectName` (a start input declared a record id) — one row label, - // authored in all three locales. - // 702 since #30259: the action form's params repeater offers `widget` - // (the widget that draws the param, the same key as a field's) — one - // row label, authored in all three locales. - // 732 since #30267: the view form spells out the children of its - // `selection` / `pagination` / `userFilters` (with the `fields` repeater's - // six row properties) / `appearance` / `userActions` / `navigation` / - // `sharing` composites — thirty row labels, authored in all three locales. - // 733 since #30692: the object form's `fieldGroups` repeater offers - // `requiresFeature` (the deployment feature a group needs) — one row - // label, authored in all three locales. - // 737 since the dataset form's dimensions and measures repeaters offer - // `synonyms` and `description` (ADR-0149 D1) — four row labels, authored - // in all three locales. - // 738 since the object form's `sharing.controlledByParent` sub-block - // offers `writeRequiresMasterRead` (ADR-0055 §3 as amended: read on the - // master is enough to write) — one row label, authored in all three - // locales. - // 741 since #33657: the hook form's refusal entry offers `reasons` (with - // its `message`) and `params` — three row labels, authored in all three - // locales. - // 744 since #34575: the hook form offers the `texts` record and its - // `message` / `params` entry fields — three row labels, authored in all - // three locales. - // 745 since the object form's `userActions` composite offers `transfer` - // (the Change Owner switch, ruling 7000907189 point 1) — one row label, - // authored in all three locales. - // 748 since #35096: the action form offers the `texts` record and its - // `message` / `params` entry fields — three row labels, authored in all - // three locales. - // 754 since #34823: the action form offers the `refusals` record and its - // five entry fields — six row labels, authored in all three locales. - // 755 since #35900: the object form's `fieldGroups` repeater offers - // `fields` (the group's own member list) — one row label, authored in - // all three locales. - // 756 since #35985: the object form's `basics` offers a `color` row, - // whose label zh-CN translates. - // 757 since #36290: the object form's `enable` composite offers - // `fieldHistory` — one row label, authored in all three locales. - // 759 since #36290's field off switch: the object form's `fields` - // repeater and the field form each offer a `fieldHistory` row — two - // row labels, authored in all three locales. - // 760 since #36425: the field form offers the `showOnCreate` row (ask - // for the field when a record is created) — one row label, authored in - // all three locales. - // 763 since #36366: `advanced` offers the `actionLayout` composite and - // its `list` / `record` rows — three row labels, authored in all three - // locales. - // 765 since #35315: the object form's `fields` repeater and the field - // form each offer a `transferBehavior` row — two row labels, authored in - // all three locales. - // 771 since #36447: the report form declares the `dateRange` and - // `exportOptions` children — six row labels, authored in all three - // locales. - // 823 since #36860: the Studio list column headers no form field - // labels get their own `fields..label` row (`METADATA_LIST_REGISTRY`) - // — fifty-two row labels, authored in all three locales. - // 824 since #35926: the field form offers the `inlineEdit` select (its - // boolean arm retired, a select spells 'grid' / 'form') — one row label, - // authored in all three locales. - // 825 since #37140: the `ai_context` type's own label (ADR-0160 D1), - // authored in all three locales. - // 828 since #36949: the dashboard form declares the `dateRange` - // children — three row labels, authored in all three locales. - // 837 since #37143: the `ai_context` form (ADR-0160 D1 clause 2) — two - // section labels and seven row labels, authored in all three locales. - // 839 since #36806: the field form offers the `uiReadonly` and - // `uiReadonlyWhen` rows (the hand lock), authored in every locale. - // 840 since #37141: the skill form's `context` row (ADR-0160 D8) — one - // row label, authored in all three locales. - // 841 since #37086: the `form` type's own label (ADR-0159 card ②), - // authored in all three locales. 844 since #34908: the view and - // dashboard forms offer the audience gate (`requiredPermissions`) — two - // row labels and the dashboard's `access` section label, authored in - // all three locales. - // 845 since #37304: the `knowledge_source` type's own label (ADR-0161 - // K4), authored in every locale. - // 846 since #37402: the object form's `uiReadonlyWhen` row (the - // whole-record hand lock), authored in every locale. - // 866 since #37309: the `knowledge_source` form (ADR-0161 K4 clause 2) - // — twenty of its section and row labels, authored in all three - // locales. - // 867: the `knowledge_source` form's `documentBy` row (the document - // unit) — one row label, authored in all three locales. - // 868: its `affinity` row (the order for the asker) — one row label, - // authored in all three locales. - // 869 since #37792: the object form's `pinOverview` row (the record - // page layout switch) — one row label, authored in all three locales. - // 870 since #36496: the object form's `actionLayout.selection` row - // (the multi-select bar's order), authored in all three locales. - // 872 since #38692: the `knowledge_source` form's `source.retrieval` - // group and its `mode` row (the retrieval mode) — two row labels, - // authored in every locale. - // 875 since #37802: the object form's `fieldTabs` repeater (the record - // page's field tabs) — the row and its `key` and `groups` sub-rows, - // three labels, authored in all three locales. - // 876 since ADR-0162 D1: the object form's `closedStates` row (the - // states that close a record), authored in every locale. - expect(translated.length, `${locale} positive control`).toBe(876); + // No count pin: the catalog grows with every form row that lands, so the + // count is deleted rather than synced (AGENTS.md, "Volatile counts are + // deleted, not synced"). The control is that every `.label` leaf this + // locale carries reads a translation, and that there are some. + const carried = [...en].filter(([k]) => k.endsWith('.label') && m.get(k) !== undefined); + expect(translated.length, `${locale} positive control`).toBeGreaterThan(0); + expect(translated.length, `${locale} positive control`).toBe(carried.length); } // ⭐ DARK — the blindness, executable. On a synthetic two-locale catalog the // all-three predicate returns 0 while the per-locale one returns 1, so the diff --git a/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts index d0a013f3132..5e244eafca3 100644 --- a/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts @@ -1343,6 +1343,10 @@ export const ptBRMetadataForms: NonNullable = } } }, + picklist_extension: { + label: "Extensão de lista de opções", + description: "Valores que um pacote adiciona a uma lista de opções pertencente a outro pacote" + }, mapping: { label: "Mapeamento de importação", description: "Mapeamento de campos reutilizável para importação/exportação (renomeação + transformações), referenciado pelo nome na importação", diff --git a/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts index 296a1d3725d..bbfcd565f8e 100644 --- a/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts @@ -1343,6 +1343,10 @@ export const ruMetadataForms: NonNullable = { } } }, + picklist_extension: { + label: "Расширение списка вариантов", + description: "Значения, которые пакет добавляет в список вариантов, принадлежащий другому пакету" + }, mapping: { label: "Сопоставление импорта", description: "Повторно используемое сопоставление полей для импорта/экспорта (переименование + преобразования), на которое ссылаются по имени при импорте", diff --git a/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts index 1f7cde27152..236eede4f6b 100644 --- a/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts @@ -1343,6 +1343,10 @@ export const zhCNMetadataForms: NonNullable = } } }, + picklist_extension: { + label: "共享选项集扩展", + description: "一个软件包向另一个软件包拥有的共享选项集添加的值" + }, mapping: { label: "导入映射", description: "可复用的导入/导出字段映射(重命名 + 转换),在导入时按名称引用", diff --git a/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts index 882baf4b882..f1bf495762b 100644 --- a/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts @@ -1343,6 +1343,10 @@ export const zhHantMetadataForms: NonNullable } } }, + picklist_extension: { + label: "共用選項集擴充", + description: "一個套件向另一個套件擁有的共用選項集新增的值" + }, mapping: { label: "匯入對應", description: "可複用的匯入/匯出欄位對應(重新命名 + 轉換),在匯入時依名稱參照", From f2871f70166fe19592a9b062fec2660e3f3ed183 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 11:07:41 +0000 Subject: [PATCH 09/14] fix(#39536): the __c refusal says what the ruling says; Studio menu row and pending-changes count for picklist_extension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `__c` refusal and its module docblock said the list's owner "can never ship the same value in a later version". ADR-0146 D10 as amended (PR #39636) says less: every value a picklist_extension item adds ends in `__c`, so the vendor's next version may ship `trade_show` beside the customer's `trade_show__c`; the list's own values and a code package's picklistExtensions are not judged. Text and changeset aligned. Two ui tests derive rows from the spec registry and went red on the new type: the Studio menu placement table (studioMenuPlacement.test.ts) and the pending-changes count table (DraftChangesPanel.summaryPlural-13147). The type gets a 高级 row last in 数据 Data (ADR-0084 item 6's placement for a type registered after the ruling) and a count row with keys in every ui locale (zh-Hant regenerated from zh-Hans). ADR-0084's own table row is not written here (docs/adr is out of this PR's scope). Claude-Session: https://claude.ai/code/session_01L9qibxE6RdcamcqFHHa7PC Co-authored-by: Claude --- .changeset/39536-picklist-extension-item.md | 5 ++++- .../src/protocol-picklist-extension-item.ts | 19 +++++++++++-------- .../src/preview/DraftChangesPanel.tsx | 4 ++++ .../studio-design/studioMenuPlacement.test.ts | 7 ++++--- .../studio-design/studioMenuPlacement.ts | 3 +++ ui/packages/i18n/src/locales/ar.ts | 7 +++++++ ui/packages/i18n/src/locales/de.ts | 3 +++ ui/packages/i18n/src/locales/en.ts | 3 +++ ui/packages/i18n/src/locales/es.ts | 4 ++++ ui/packages/i18n/src/locales/fr.ts | 4 ++++ ui/packages/i18n/src/locales/ja.ts | 3 +++ ui/packages/i18n/src/locales/ko.ts | 3 +++ ui/packages/i18n/src/locales/pt-BR.ts | 4 ++++ ui/packages/i18n/src/locales/ru.ts | 5 +++++ ui/packages/i18n/src/locales/zh-Hans.ts | 3 +++ ui/packages/i18n/src/locales/zh-Hant.ts | 3 +++ 16 files changed, 68 insertions(+), 12 deletions(-) diff --git a/.changeset/39536-picklist-extension-item.md b/.changeset/39536-picklist-extension-item.md index a9fcd6d91c4..d4f9d27ec05 100644 --- a/.changeset/39536-picklist-extension-item.md +++ b/.changeset/39536-picklist-extension-item.md @@ -4,6 +4,8 @@ '@objectstack/metadata-protocol': minor '@objectstack/runtime': minor '@objectstack/cloud-connection': minor +'@object-ui/app-shell': patch +'@object-ui/i18n': patch --- feat(spec, metadata-protocol, objectql, runtime, cloud-connection): a customer adds values to an installed package's picklist as a stored `picklist_extension` item of the customization pair @@ -14,8 +16,9 @@ Metadata-protocol: added Who sees it: an administrator of an installed app (for example a CRM) who needs one more value in the vendor's shared option list, such as a new lead source. Until now nothing they could reach stored it: the list belongs to the vendor's package, and the `.custom` pair had no door for `picklistExtensions`. - New metadata type `picklist_extension`, the twin of `object_extension`: values a package adds to a picklist another package owns, stored as an item of the writing package under the list's name (one item per package per list). The body is `PicklistExtensionSchema` unchanged (`extend`, `options`). It is saved as a draft, published, versioned, rolled back and deleted through `/api/v1/meta/picklist_extension/?package=` like any item, and classified `excluded` in the override table (a list is extended, never replaced). -- Every value such an item adds must end in `__c` (the suffix reserved for a customer's extension fields). A value without it is refused at the save, publish and restore doors with `VALIDATION_ERROR` / 400 located at `options..value`; the option `label` stays free text. The reason: a vendor version that later ships the same value is refused at upgrade while a customer's extension holds it, so the suffix keeps the vendor's names and the customer's apart. +- Every value such an item adds must end in `__c` (the suffix reserved for a customer's extension fields). A value without it is refused at the save, publish and restore doors with `VALIDATION_ERROR` / 400 located at `options..value`; the option `label` stays free text. The reason: a vendor version that later ships the same value is refused at upgrade while a customer's extension holds it, so with the suffix the vendor's next version may ship `trade_show` beside the customer's `trade_show__c`. The rule is asked of these items only: a list's own values and a code package's `picklistExtensions` are not judged for it. - The doors also refuse, with `VALIDATION_ERROR` / 400: a write naming no package, a row filed under a name other than its `extend`, a list the package cannot reach (not its own and not declared by a package in its `dependencies`), and a value the list or another package's extension already carries. - A published item is served at once on every field bound to the list, re-registered at boot, replaced on re-publish (a value dropped from the item leaves the list), and withdrawn when the item is deleted or the package uninstalled. - `GET /api/v1/packages//export` carries the items as `picklistExtensions`, and `POST /api/v1/marketplace/install-local` of such a pair writes each entry back as a `picklist_extension` item (before, it refused the key). - `SchemaRegistry` (`@objectstack/objectql`) gains `storedPicklistExtension(request)`, one door for a stored row's `replace`, `refusal`, `withdraw` and `extenders` requests of its package's contribution to a list. +- Studio lists the type in its left menu under 数据 Data, in the 高级 fold, last in the group, and the pending-changes summary reads a count of these items as "N picklist extensions" in every console language instead of the raw type name. No editor or 「添加选项」 control ships in this change. diff --git a/packages/metadata-protocol/src/protocol-picklist-extension-item.ts b/packages/metadata-protocol/src/protocol-picklist-extension-item.ts index 443d5cc6b93..82173b6e8f3 100644 --- a/packages/metadata-protocol/src/protocol-picklist-extension-item.ts +++ b/packages/metadata-protocol/src/protocol-picklist-extension-item.ts @@ -18,12 +18,15 @@ * * The ruling's rider: every value such an item adds ends in `__c` * (`EXTENSION_FIELD_SUFFIX`, the suffix ADR-0146 D10 reserves for a customer's - * extension fields), refused otherwise at the item's doors. The vendor's next - * version can then never ship a value the customer already holds: the registry - * refuses a list registered after an extension added one of its values - * (`assertPicklistValuesDistinct`), so without the suffix the customer's value - * would block the vendor's upgrade. The option `label` stays free text, so a - * user never sees the suffix. + * extension fields), refused otherwise at the item's doors. So a customer's + * value is `trade_show__c`, and the vendor's next version may ship `trade_show` + * beside it: the registry refuses a list registered after an extension added + * one of its values (`assertPicklistValuesDistinct`), so without the suffix the + * customer's value would block the vendor's upgrade until it was deleted. The + * rule is asked of every `picklist_extension` item and of nothing else: a + * list's own values and a code package's `picklistExtensions` never pass these + * doors, and whether either is judged for the suffix is not ruled. The option + * `label` stays free text, so a user never sees the suffix. * * This module holds what the doors ask that is particular to the type: * @@ -171,8 +174,8 @@ export function picklistExtensionItemRefusal( }); const values = unsuffixed.map(({ option }) => `'${String((option as Record).value)}'`).join(', '); return refusal( - `Picklist extension '${name}': a value a package adds to another package's list ends in ` - + `\`${EXTENSION_FIELD_SUFFIX}\`, so the list's owner can never ship the same value in a later version — ` + `Picklist extension '${name}': every value a picklist_extension item adds ends in ` + + `\`${EXTENSION_FIELD_SUFFIX}\`, so the list's next version may ship the unsuffixed value beside it — ` + `${values} ${unsuffixed.length === 1 ? 'does' : 'do'} not. Add the suffix to the value; the label stays ` + 'as users should read it.', issues, diff --git a/ui/packages/app-shell/src/preview/DraftChangesPanel.tsx b/ui/packages/app-shell/src/preview/DraftChangesPanel.tsx index c36afb14625..6ff0376b7b3 100644 --- a/ui/packages/app-shell/src/preview/DraftChangesPanel.tsx +++ b/ui/packages/app-shell/src/preview/DraftChangesPanel.tsx @@ -881,6 +881,10 @@ const TYPE_COUNT: Readonly strin // objectstack#29704 — what customizing a base package's object writes (ADR-0146 D10). object_extension: (t, count) => t('preview.changes.typeCount.object_extension', { count, defaultValue: '{{count}} object extensions' }), + // objectstack#39536 — its twin for a shared option list: the values a + // package adds to a picklist another package owns (ADR-0146 D2 / D10). + picklist_extension: (t, count) => + t('preview.changes.typeCount.picklist_extension', { count, defaultValue: '{{count}} picklist extensions' }), // A Studio-authored dataset publishes in the same batch as the report or // dashboard that reads it; without a row it read as the raw type name. dataset: (t, count) => t('preview.changes.typeCount.dataset', { count, defaultValue: '{{count}} datasets' }), diff --git a/ui/packages/app-shell/src/views/studio-design/studioMenuPlacement.test.ts b/ui/packages/app-shell/src/views/studio-design/studioMenuPlacement.test.ts index 3443876f0fe..bb5e1210c36 100644 --- a/ui/packages/app-shell/src/views/studio-design/studioMenuPlacement.test.ts +++ b/ui/packages/app-shell/src/views/studio-design/studioMenuPlacement.test.ts @@ -78,7 +78,7 @@ describe('the menu placement table holds the ruled order and tiers (objectstack# it("高级: every other type, in the proposal's order", () => { expect(STUDIO_MENU_PLACEMENT.filter((row) => row.tier === 'advanced').map((row) => row.type)).toEqual([ - 'picklist', 'hook', 'mapping', 'object_extension', 'seed', + 'picklist', 'hook', 'mapping', 'object_extension', 'seed', 'picklist_extension', 'view', 'action', 'job', 'doc', 'book', 'email_template', 'translation', 'api', 'external_catalog', @@ -205,10 +205,11 @@ describe('the groups the 2026-11-26 placements touch read as ADR-0084 lists them expect(DOMAIN_OF.get('report')).toBe('ui'); }); - it('数据 Data: object · dataset | picklist · hook · mapping · object_extension · seed', () => { + // objectstack#39536 — `picklist_extension`, registered after the ruling, last in its group (ADR-0084 item 6). + it('数据 Data: object · dataset | picklist · hook · mapping · object_extension · seed · picklist_extension', () => { expect(groupTiers('data')).toEqual({ common: ['object', 'dataset'], - advanced: ['picklist', 'hook', 'mapping', 'object_extension', 'seed'], + advanced: ['picklist', 'hook', 'mapping', 'object_extension', 'seed', 'picklist_extension'], }); }); diff --git a/ui/packages/app-shell/src/views/studio-design/studioMenuPlacement.ts b/ui/packages/app-shell/src/views/studio-design/studioMenuPlacement.ts index d0f16d3d6a7..91d1c23022c 100644 --- a/ui/packages/app-shell/src/views/studio-design/studioMenuPlacement.ts +++ b/ui/packages/app-shell/src/views/studio-design/studioMenuPlacement.ts @@ -104,6 +104,9 @@ export const STUDIO_MENU_PLACEMENT: readonly StudioMenuPlacementRow[] = Object.f { type: 'mapping', tier: 'advanced' }, { type: 'object_extension', tier: 'advanced' }, { type: 'seed', tier: 'advanced' }, + // Registered after the ruling (objectstack#39536): no ruling names it, so it + // is placed as ADR-0084 item 6 places such a type — 高级, last in its group. + { type: 'picklist_extension', tier: 'advanced' }, // 高级 — ui { type: 'view', tier: 'advanced' }, { type: 'action', tier: 'advanced' }, diff --git a/ui/packages/i18n/src/locales/ar.ts b/ui/packages/i18n/src/locales/ar.ts index 8340efe9afa..4d2c9f6a890 100644 --- a/ui/packages/i18n/src/locales/ar.ts +++ b/ui/packages/i18n/src/locales/ar.ts @@ -5864,6 +5864,13 @@ const ar = { object_extension_few: 'امتدادات كائنات {{count}}', object_extension_many: 'امتدادات كائنات {{count}}', object_extension_other: 'امتدادات كائنات {{count}}', + picklist_extension: 'امتدادات قوائم الاختيار {{count}}', + picklist_extension_zero: 'امتدادات قوائم الاختيار {{count}}', + picklist_extension_one: 'امتداد قائمة الاختيار {{count}}', + picklist_extension_two: 'امتدادات قوائم الاختيار {{count}}', + picklist_extension_few: 'امتدادات قوائم الاختيار {{count}}', + picklist_extension_many: 'امتدادات قوائم الاختيار {{count}}', + picklist_extension_other: 'امتدادات قوائم الاختيار {{count}}', dataset: 'مجموعات بيانات {{count}}', dataset_zero: 'مجموعات بيانات {{count}}', dataset_one: 'مجموعة بيانات {{count}}', diff --git a/ui/packages/i18n/src/locales/de.ts b/ui/packages/i18n/src/locales/de.ts index 94f95482acd..2eb5b503979 100644 --- a/ui/packages/i18n/src/locales/de.ts +++ b/ui/packages/i18n/src/locales/de.ts @@ -5350,6 +5350,9 @@ const de = { object_extension: '{{count}} Objekterweiterungen', object_extension_one: '{{count}} Objekterweiterung', object_extension_other: '{{count}} Objekterweiterungen', + picklist_extension: '{{count}} Auswahllisten-Erweiterungen', + picklist_extension_one: '{{count}} Auswahllisten-Erweiterung', + picklist_extension_other: '{{count}} Auswahllisten-Erweiterungen', dataset: '{{count}} Datensätze', dataset_one: '{{count}} Datensatz', dataset_other: '{{count}} Datensätze', diff --git a/ui/packages/i18n/src/locales/en.ts b/ui/packages/i18n/src/locales/en.ts index 13e09256176..4621632464d 100644 --- a/ui/packages/i18n/src/locales/en.ts +++ b/ui/packages/i18n/src/locales/en.ts @@ -4882,6 +4882,9 @@ const en = { object_extension: '{{count}} object extensions', object_extension_one: '{{count}} object extension', object_extension_other: '{{count}} object extensions', + picklist_extension: '{{count}} picklist extensions', + picklist_extension_one: '{{count}} picklist extension', + picklist_extension_other: '{{count}} picklist extensions', dataset: '{{count}} datasets', dataset_one: '{{count}} dataset', dataset_other: '{{count}} datasets', diff --git a/ui/packages/i18n/src/locales/es.ts b/ui/packages/i18n/src/locales/es.ts index 3770ec8effe..83bb0e667c7 100644 --- a/ui/packages/i18n/src/locales/es.ts +++ b/ui/packages/i18n/src/locales/es.ts @@ -5479,6 +5479,10 @@ const es = { object_extension_one: '{{count}} extensión de objeto', object_extension_many: '{{count}} de extensiones de objeto', object_extension_other: '{{count}} extensiones de objeto', + picklist_extension: '{{count}} extensiones de lista de selección', + picklist_extension_one: '{{count}} extensión de lista de selección', + picklist_extension_many: '{{count}} de extensiones de lista de selección', + picklist_extension_other: '{{count}} extensiones de lista de selección', dataset: '{{count}} conjuntos de datos', dataset_one: '{{count}} conjunto de datos', dataset_many: '{{count}} de conjuntos de datos', diff --git a/ui/packages/i18n/src/locales/fr.ts b/ui/packages/i18n/src/locales/fr.ts index 16fbd27fcf2..35262d0ca48 100644 --- a/ui/packages/i18n/src/locales/fr.ts +++ b/ui/packages/i18n/src/locales/fr.ts @@ -5475,6 +5475,10 @@ const fr = { object_extension_one: '{{count}} extension d’objet', object_extension_many: '{{count}} d’extensions d’objet', object_extension_other: '{{count}} extensions d’objet', + picklist_extension: '{{count}} extensions de liste de sélection', + picklist_extension_one: '{{count}} extension de liste de sélection', + picklist_extension_many: '{{count}} d’extensions de liste de sélection', + picklist_extension_other: '{{count}} extensions de liste de sélection', dataset: '{{count}} jeux de données', dataset_one: '{{count}} jeu de données', dataset_many: '{{count}} de jeux de données', diff --git a/ui/packages/i18n/src/locales/ja.ts b/ui/packages/i18n/src/locales/ja.ts index 82a0459cac6..a47880f7b47 100644 --- a/ui/packages/i18n/src/locales/ja.ts +++ b/ui/packages/i18n/src/locales/ja.ts @@ -5352,6 +5352,9 @@ const ja = { object_extension: 'オブジェクト拡張 {{count}}', object_extension_one: 'オブジェクト拡張 {{count}}', object_extension_other: 'オブジェクト拡張 {{count}}', + picklist_extension: '選択リスト拡張 {{count}}', + picklist_extension_one: '選択リスト拡張 {{count}}', + picklist_extension_other: '選択リスト拡張 {{count}}', dataset: 'データセット {{count}}', dataset_one: 'データセット {{count}}', dataset_other: 'データセット {{count}}', diff --git a/ui/packages/i18n/src/locales/ko.ts b/ui/packages/i18n/src/locales/ko.ts index 10ba4aa38f0..5a0a80d1464 100644 --- a/ui/packages/i18n/src/locales/ko.ts +++ b/ui/packages/i18n/src/locales/ko.ts @@ -5349,6 +5349,9 @@ const ko = { object_extension: '객체 확장 {{count}}', object_extension_one: '객체 확장 {{count}}', object_extension_other: '객체 확장 {{count}}', + picklist_extension: '선택 목록 확장 {{count}}', + picklist_extension_one: '선택 목록 확장 {{count}}', + picklist_extension_other: '선택 목록 확장 {{count}}', dataset: '데이터 세트 {{count}}', dataset_one: '데이터 세트 {{count}}', dataset_other: '데이터 세트 {{count}}', diff --git a/ui/packages/i18n/src/locales/pt-BR.ts b/ui/packages/i18n/src/locales/pt-BR.ts index 894588dc793..4bf51f1678c 100644 --- a/ui/packages/i18n/src/locales/pt-BR.ts +++ b/ui/packages/i18n/src/locales/pt-BR.ts @@ -5474,6 +5474,10 @@ const pt = { object_extension_one: '{{count}} extensão de objeto', object_extension_many: '{{count}} de extensões de objeto', object_extension_other: '{{count}} extensões de objeto', + picklist_extension: '{{count}} extensões de lista de opções', + picklist_extension_one: '{{count}} extensão de lista de opções', + picklist_extension_many: '{{count}} de extensões de lista de opções', + picklist_extension_other: '{{count}} extensões de lista de opções', dataset: '{{count}} conjuntos de dados', dataset_one: '{{count}} conjunto de dados', dataset_many: '{{count}} de conjuntos de dados', diff --git a/ui/packages/i18n/src/locales/ru.ts b/ui/packages/i18n/src/locales/ru.ts index 3c52d0d6696..86994ab88f6 100644 --- a/ui/packages/i18n/src/locales/ru.ts +++ b/ui/packages/i18n/src/locales/ru.ts @@ -5617,6 +5617,11 @@ const ru = { object_extension_few: 'Расширения объектов: {{count}}', object_extension_many: 'Расширения объектов: {{count}}', object_extension_other: 'Расширения объектов: {{count}}', + picklist_extension: 'Расширения списков вариантов: {{count}}', + picklist_extension_one: 'Расширение списка вариантов: {{count}}', + picklist_extension_few: 'Расширения списков вариантов: {{count}}', + picklist_extension_many: 'Расширения списков вариантов: {{count}}', + picklist_extension_other: 'Расширения списков вариантов: {{count}}', dataset: 'Наборы данных: {{count}}', dataset_one: 'Набор данных: {{count}}', dataset_few: 'Наборы данных: {{count}}', diff --git a/ui/packages/i18n/src/locales/zh-Hans.ts b/ui/packages/i18n/src/locales/zh-Hans.ts index 502c752c4d4..7cf194c3007 100644 --- a/ui/packages/i18n/src/locales/zh-Hans.ts +++ b/ui/packages/i18n/src/locales/zh-Hans.ts @@ -4266,6 +4266,9 @@ const zh = { object_extension: '对象扩展 {{count}}', object_extension_one: '对象扩展 {{count}}', object_extension_other: '对象扩展 {{count}}', + picklist_extension: '共享选项集扩展 {{count}}', + picklist_extension_one: '共享选项集扩展 {{count}}', + picklist_extension_other: '共享选项集扩展 {{count}}', dataset: '数据集 {{count}}', dataset_one: '数据集 {{count}}', dataset_other: '数据集 {{count}}', diff --git a/ui/packages/i18n/src/locales/zh-Hant.ts b/ui/packages/i18n/src/locales/zh-Hant.ts index e262557f2d6..ceef924de7f 100644 --- a/ui/packages/i18n/src/locales/zh-Hant.ts +++ b/ui/packages/i18n/src/locales/zh-Hant.ts @@ -4266,6 +4266,9 @@ const zhHant = { object_extension: '物件擴充 {{count}}', object_extension_one: '物件擴充 {{count}}', object_extension_other: '物件擴充 {{count}}', + picklist_extension: '共享選項集擴充 {{count}}', + picklist_extension_one: '共享選項集擴充 {{count}}', + picklist_extension_other: '共享選項集擴充 {{count}}', dataset: '資料集 {{count}}', dataset_one: '資料集 {{count}}', dataset_other: '資料集 {{count}}', From dadcac4fada873638318d5bddebb29bdce19aa11 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 11:36:43 +0000 Subject: [PATCH 10/14] fix(#39576): declare the body-key module to check:route-envelope; the PATCH test pays the metadata load at collection `package-patch-body-keys.ts` is a new file under the dispatcher's domain directory, which check:route-envelope enumerates exhaustively: declared `{ handBuilt: 0 }` (a pure function; `packages.ts` answers through `deps.error`). check:test-source-alias asks the edited PATCH test to load `@objectstack/metadata` at module top, as its precedents do. Claude-Session: https://claude.ai/code/session_01L9qibxE6RdcamcqFHHa7PC Co-authored-by: Claude --- .../runtime/src/domains/packages-patch-dependencies.test.ts | 2 ++ scripts/check-route-envelope.mjs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/packages/runtime/src/domains/packages-patch-dependencies.test.ts b/packages/runtime/src/domains/packages-patch-dependencies.test.ts index cf878457c0b..56379a7d88b 100644 --- a/packages/runtime/src/domains/packages-patch-dependencies.test.ts +++ b/packages/runtime/src/domains/packages-patch-dependencies.test.ts @@ -37,6 +37,8 @@ */ import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest'; +// Paid at collection, not inside a case's clock (check:test-source-alias). +import '@objectstack/metadata'; import { mkdtempSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; diff --git a/scripts/check-route-envelope.mjs b/scripts/check-route-envelope.mjs index d35aae7c146..cd80c08204b 100644 --- a/scripts/check-route-envelope.mjs +++ b/scripts/check-route-envelope.mjs @@ -1160,6 +1160,9 @@ const DISPATCHER_DOMAINS = { handBuilt: 1, note: 'the localized 501 (`localizedNotImplemented`, #37737), which must carry `Vary: Accept-Language` (`deps.error` takes no headers); the body is `deps.error`\'s declared envelope spread, and every door that answers a 501 in the request\'s language answers through it', }, + // [#39576] The `PATCH /packages/:id` body-key check, a pure function that + // returns the refusal sentence; `packages.ts` answers it through `deps.error`. + 'package-patch-body-keys.ts': { handBuilt: 0 }, 'packages.ts': { handBuilt: 0 }, // The `/security` domain's permission-set clone door (ADR-0126 §7.1), beside // the activation door. Every answer goes through `deps.success` / From 1448448f256a7352076d80ef616d6136ec9d5110 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 12:32:18 +0000 Subject: [PATCH 11/14] docs(adr-0084), changesets(#39536): picklist_extension's type-to-group row; both changesets declare the PR's narrowing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claim amendment 7411489087 (option B): this PR carries the one ADR-0084 row for the type ruling 7406020670 created, placed as item 6 places a type registered after the ruling (数据 Data, 8, 高级, last in its group). It turns the three ADR cases of studioMenuPlacement.test.ts green. No rule text changes. Both changesets now carry the PR-level pair the amendment sets: `Clause-②: yes (narrowing)` and `Metadata-protocol: narrowed` (several kinds ⇒ narrowed over added, AGENTS.md). Claude-Session: https://claude.ai/code/session_01L9qibxE6RdcamcqFHHa7PC Co-authored-by: Claude --- .changeset/39536-picklist-extension-item.md | 8 ++++++-- .changeset/39576-patch-packages-unread-body-key.md | 2 +- .../0084-application-builder-information-architecture.md | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.changeset/39536-picklist-extension-item.md b/.changeset/39536-picklist-extension-item.md index d4f9d27ec05..3da3f6ef7b1 100644 --- a/.changeset/39536-picklist-extension-item.md +++ b/.changeset/39536-picklist-extension-item.md @@ -10,8 +10,8 @@ feat(spec, metadata-protocol, objectql, runtime, cloud-connection): a customer adds values to an installed package's picklist as a stored `picklist_extension` item of the customization pair -Clause-②: yes -Metadata-protocol: added +Clause-②: yes (narrowing) +Metadata-protocol: narrowed Who sees it: an administrator of an installed app (for example a CRM) who needs one more value in the vendor's shared option list, such as a new lead source. Until now nothing they could reach stored it: the list belongs to the vendor's package, and the `.custom` pair had no door for `picklistExtensions`. @@ -22,3 +22,7 @@ Who sees it: an administrator of an installed app (for example a CRM) who needs - `GET /api/v1/packages//export` carries the items as `picklistExtensions`, and `POST /api/v1/marketplace/install-local` of such a pair writes each entry back as a `picklist_extension` item (before, it refused the key). - `SchemaRegistry` (`@objectstack/objectql`) gains `storedPicklistExtension(request)`, one door for a stored row's `replace`, `refusal`, `withdraw` and `extenders` requests of its package's contribution to a list. - Studio lists the type in its left menu under 数据 Data, in the 高级 fold, last in the group, and the pending-changes summary reads a count of these items as "N picklist extensions" in every console language instead of the raw type name. No editor or 「添加选项」 control ships in this change. + +Migration: none for this half. `picklist_extension` is a new type, so nothing an author already writes is refused by it; the `__c` rule applies only to items of the new type. The narrowing this pull request declares is the `PATCH /api/v1/packages/` body-key refusal, described with its migration in `.changeset/39576-patch-packages-unread-body-key.md` and registered there. + + diff --git a/.changeset/39576-patch-packages-unread-body-key.md b/.changeset/39576-patch-packages-unread-body-key.md index e5430926029..42bd1be55ef 100644 --- a/.changeset/39576-patch-packages-unread-body-key.md +++ b/.changeset/39576-patch-packages-unread-body-key.md @@ -4,7 +4,7 @@ fix(runtime): `PATCH /api/v1/packages/:id` refuses a body key it does not read -Clause-②: no (narrowing) +Clause-②: yes (narrowing) Metadata-protocol: narrowed Who sees it: an administrator or an agent who edits a package through `PATCH /api/v1/packages/` and sends a key the door does not read, such as `picklistExtensions`. Until now the door answered `200`, saved `name` / `description` / `version` / `dependencies` if present, and dropped the rest without a word, so the caller believed the extra key was stored. diff --git a/docs/adr/0084-application-builder-information-architecture.md b/docs/adr/0084-application-builder-information-architecture.md index 5dd7691a061..933b50a412e 100644 --- a/docs/adr/0084-application-builder-information-architecture.md +++ b/docs/adr/0084-application-builder-information-architecture.md @@ -179,6 +179,7 @@ Every type the spec registers, enumerated at `origin/main` `151e8123` from `pack | **数据 Data** | `data` | 5 | `mapping` 字段映射 | 高级 | | **数据 Data** | `data` | 6 | `object_extension` | 高级 | | **数据 Data** | `data` | 7 | `seed` | 高级 | +| **数据 Data** | `data` | 8 | `picklist_extension` *(registered after the ruling — [item 6](#amendment-2026-11-25-silent))* | 高级 | | **数据 Data** | `data` | — | `field` | — | | **界面 UI** | `ui` | 1 | `app` 应用 | 常用 | | **界面 UI** | `ui` | 2 | `page` 页面 | 常用 | From 41423353f12eab4187028f96ea729ccbde094754 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 12:56:51 +0000 Subject: [PATCH 12/14] test(showcase): KIND_COVERAGE accounts for picklist_extension, waived with picklist The showcase coverage ledger enumerates the registry, and the new kind reddened its test and the example-apps typecheck (Record over MetadataType). The showcase ships no picklist and depends on no package that does (`picklist` and `picklistExtensions` are waived), so an item that extends another package's list has nothing to extend: waived beside them, tracked on #39536. Claude-Session: https://claude.ai/code/session_01L9qibxE6RdcamcqFHHa7PC Co-authored-by: Claude --- examples/app-showcase/src/coverage.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/app-showcase/src/coverage.ts b/examples/app-showcase/src/coverage.ts index e2a387396b6..491fc015468 100644 --- a/examples/app-showcase/src/coverage.ts +++ b/examples/app-showcase/src/coverage.ts @@ -90,6 +90,14 @@ export const KIND_COVERAGE: Record = { 'The kind is declared ahead of its runtime reader: until the server resolves a picklist reference, a picklist-bound field is served with no options, so a demo would draw a select with nothing to choose. Demonstrate it (one list on two objects, an extension, a translated option) with the runtime layer.', issue: 'https://github.com/objectstack-ai/objectstack/issues/19519', }, + // [#39536] The stored twin of `objectExtensions` for a shared list: a + // writable package's item adding values to a picklist another package owns. + picklist_extension: { + status: 'waived', + reason: + 'An item of this kind adds values to a picklist another package owns, and the showcase ships no picklist and depends on no package that does (`picklist` and `picklistExtensions` are waived above), so there is no list to extend. Its code half is `picklistExtensions`; the item itself is written at runtime through `/api/v1/meta/picklist_extension/?package=`. Demonstrate it with the picklist kind.', + issue: 'https://github.com/objectstack-ai/objectstack/issues/39536', + }, // ── ui ── view: { status: 'demonstrated', files: ['src/ui/views/task.view.ts', 'src/ui/views/project.view.ts'] }, From e08b8901532439fbb0ae83bd0150c04831351d84 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 13:33:53 +0000 Subject: [PATCH 13/14] changeset(#39536): platform-objects ships the picklist_extension type labels The eleven `*.metadata-forms.generated.ts` bundles compile into the platform-objects dist, so the new type's translated label and description publish: `'@objectstack/platform-objects': patch`. Claude-Session: https://claude.ai/code/session_01L9qibxE6RdcamcqFHHa7PC Co-authored-by: Claude --- .changeset/39536-picklist-extension-item.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/39536-picklist-extension-item.md b/.changeset/39536-picklist-extension-item.md index 3da3f6ef7b1..871ced268e5 100644 --- a/.changeset/39536-picklist-extension-item.md +++ b/.changeset/39536-picklist-extension-item.md @@ -4,6 +4,7 @@ '@objectstack/metadata-protocol': minor '@objectstack/runtime': minor '@objectstack/cloud-connection': minor +'@objectstack/platform-objects': patch '@object-ui/app-shell': patch '@object-ui/i18n': patch --- From 0c3c0d15790be1132ae4f85e3a8350f9ed5fb1cf Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 14:05:12 +0000 Subject: [PATCH 14/14] fix(#39536): the item door asks the caller-less target judgement; a two-writer rollback is refused; L2 nits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit L2 PASS 7413270616 should-fixes, as claim amendments 7413299417 and 7413327925 rule them for this pull request: - S1: `storedPicklistExtension({ op: 'refusal' })` first asks the arrival judgement the registration asks (ADR-0150 D3): a list name two installed packages each hold is refused at the door (VALIDATION_ERROR / 400, the registry's own sentence), sealed or not, where it was stored and then refused or left unserved after a clean success. Pinned with two holders of one list name, red before and green after. - S2: the type stays unslotted; the rollback door refuses a picklist_extension name while two packages each hold an active row of it (409 RESOURCE_CONFLICT, ambiguous-in-environment), naming the holders and the remedy. Pinned with the pair and a partner both extending the list, red before and green after. object_extension is unchanged (#39698). - Both changesets carry the **BREAKING** marker; the step-2 changeset's door and rollback sentences now hold. - ADR-0084: item 6 covers picklist_extension, and a dated note recounts the table (36 rows; 数据 Data 9). - The registry row's docblock says what `**/*.picklist-extension.ts` does. - The showcase waiver tracks #39699. Claude-Session: https://claude.ai/code/session_01L9qibxE6RdcamcqFHHa7PC Co-authored-by: Claude --- .changeset/39536-picklist-extension-item.md | 6 +- .../39576-patch-packages-unread-body-key.md | 2 + ...cation-builder-information-architecture.md | 4 +- examples/app-showcase/src/coverage.ts | 2 +- .../src/protocol-package-commits.ts | 3 + .../src/protocol-picklist-extension-item.ts | 66 +++++++++++++++++-- packages/objectql/src/registry-picklists.ts | 28 ++++++-- .../meta-picklist-extension-item.test.ts | 54 +++++++++++++++ .../spec/src/kernel/metadata-plugin.zod.ts | 8 +++ 9 files changed, 158 insertions(+), 15 deletions(-) diff --git a/.changeset/39536-picklist-extension-item.md b/.changeset/39536-picklist-extension-item.md index 871ced268e5..1afa10d2eb5 100644 --- a/.changeset/39536-picklist-extension-item.md +++ b/.changeset/39536-picklist-extension-item.md @@ -16,9 +16,11 @@ Metadata-protocol: narrowed Who sees it: an administrator of an installed app (for example a CRM) who needs one more value in the vendor's shared option list, such as a new lead source. Until now nothing they could reach stored it: the list belongs to the vendor's package, and the `.custom` pair had no door for `picklistExtensions`. -- New metadata type `picklist_extension`, the twin of `object_extension`: values a package adds to a picklist another package owns, stored as an item of the writing package under the list's name (one item per package per list). The body is `PicklistExtensionSchema` unchanged (`extend`, `options`). It is saved as a draft, published, versioned, rolled back and deleted through `/api/v1/meta/picklist_extension/?package=` like any item, and classified `excluded` in the override table (a list is extended, never replaced). +**BREAKING** for the same pull request's `PATCH /api/v1/packages/` door only (see `.changeset/39576-patch-packages-unread-body-key.md`): this half adds a type and refuses nothing an author already writes. + +- New metadata type `picklist_extension`, the twin of `object_extension`: values a package adds to a picklist another package owns, stored as an item of the writing package under the list's name (one item per package per list). The body is `PicklistExtensionSchema` unchanged (`extend`, `options`). It is saved as a draft, published, versioned, rolled back and deleted through `/api/v1/meta/picklist_extension/?package=` like any item, and classified `excluded` in the override table (a list is extended, never replaced). The type takes no `package` selector on history or rollback, so while two packages each hold a row of a list's name a rollback of it is refused with `409 RESOURCE_CONFLICT`, naming both; re-publish the wanted values instead. - Every value such an item adds must end in `__c` (the suffix reserved for a customer's extension fields). A value without it is refused at the save, publish and restore doors with `VALIDATION_ERROR` / 400 located at `options..value`; the option `label` stays free text. The reason: a vendor version that later ships the same value is refused at upgrade while a customer's extension holds it, so with the suffix the vendor's next version may ship `trade_show` beside the customer's `trade_show__c`. The rule is asked of these items only: a list's own values and a code package's `picklistExtensions` are not judged for it. -- The doors also refuse, with `VALIDATION_ERROR` / 400: a write naming no package, a row filed under a name other than its `extend`, a list the package cannot reach (not its own and not declared by a package in its `dependencies`), and a value the list or another package's extension already carries. +- The doors also refuse, with `VALIDATION_ERROR` / 400: a write naming no package, a row filed under a name other than its `extend`, a list the package cannot reach (not its own and not declared by a package in its `dependencies`), a list name two installed packages each hold (the registry's own sentence: an extension's target is resolved environment-wide, so such an item could never be served), and a value the list or another package's extension already carries. - A published item is served at once on every field bound to the list, re-registered at boot, replaced on re-publish (a value dropped from the item leaves the list), and withdrawn when the item is deleted or the package uninstalled. - `GET /api/v1/packages//export` carries the items as `picklistExtensions`, and `POST /api/v1/marketplace/install-local` of such a pair writes each entry back as a `picklist_extension` item (before, it refused the key). - `SchemaRegistry` (`@objectstack/objectql`) gains `storedPicklistExtension(request)`, one door for a stored row's `replace`, `refusal`, `withdraw` and `extenders` requests of its package's contribution to a list. diff --git a/.changeset/39576-patch-packages-unread-body-key.md b/.changeset/39576-patch-packages-unread-body-key.md index 42bd1be55ef..8f6f658b11a 100644 --- a/.changeset/39576-patch-packages-unread-body-key.md +++ b/.changeset/39576-patch-packages-unread-body-key.md @@ -9,6 +9,8 @@ Metadata-protocol: narrowed Who sees it: an administrator or an agent who edits a package through `PATCH /api/v1/packages/` and sends a key the door does not read, such as `picklistExtensions`. Until now the door answered `200`, saved `name` / `description` / `version` / `dependencies` if present, and dropped the rest without a word, so the caller believed the extra key was stored. +**BREAKING** for a caller of `PATCH /api/v1/packages/` that sends a body key the door does not read: it answered 200 and saved the keys it reads; it answers 400 `VALIDATION_ERROR` and saves nothing. + - The door reads the `manifest` wrapper and, flat or inside it, `name`, `description`, `version` and `dependencies`. Any other key is now refused with `400 VALIDATION_ERROR`, naming every unread key (`manifest.` inside the wrapper; beside an object wrapper every other top-level key is unread) and the keys the door reads, in the sentence closed query-parameter doors already answer. Nothing is written: not a valid `name` sent beside it. - Migration: send only the four keys. A package's metadata (a picklist extension, an object extension, any item) is saved as an item through `/api/v1/meta//?package=`, never on this door. Studio's package dialog sends only the four keys and is unaffected. diff --git a/docs/adr/0084-application-builder-information-architecture.md b/docs/adr/0084-application-builder-information-architecture.md index 933b50a412e..3ae89ae9366 100644 --- a/docs/adr/0084-application-builder-information-architecture.md +++ b/docs/adr/0084-application-builder-information-architecture.md @@ -219,6 +219,8 @@ Every type the spec registers, enumerated at `origin/main` `151e8123` from `pack *(Rewritten 2026-11-29, card [#37087](https://github.com/objectstack-ai/objectstack/issues/37087), which carries out [Amendment (2026-11-26)](#amendment-2026-11-26-moves) for one row and decides nothing: `form`. The same change takes the type off the directory's hidden types and brings its designer, so Studio lists it and its row is written: 界面 UI, fifth, directly after `report` ([item 11](#amendment-2026-11-26-silent)), and its tier is 常用; `view` and `action`, the two types behind it, are each one place later. Read again at `origin/main` `3014176695`: the registry holds the same 35 entries, and the table now has a row for each — 35 rows, counting 数据 Data 8 · 界面 UI 7 · 自动化 Automation 2 · 平台 Platform 7 · 访问 Access 6 · AI 5. The four rows that amendment left to their changes are now each rewritten or written: `dataset`'s, `position`'s, `datasource`'s and `form`'s.)* +*(Amended 2026-12-04, pull request [#39668](https://github.com/objectstack-ai/objectstack/pull/39668), on claim amendment [7413299417](https://github.com/objectstack-ai/objectstack/issues/39536#issuecomment-7413299417), which writes one row and decides nothing: `picklist_extension`, registered `data` by ruling [7406020670](https://github.com/objectstack-ai/objectstack/issues/39536#issuecomment-7406020670), eighth in 数据 Data after `seed`, 高级, under [item 6](#amendment-2026-11-25-silent). Read again on that change: the registry holds 36 entries, and the table has a row for each — 36 rows, counting 数据 Data 9 · 界面 UI 7 · 自动化 Automation 2 · 平台 Platform 7 · 访问 Access 6 · AI 5. No type changed group.)* + *(Amended 2026-11-30, card [#38438](https://github.com/objectstack-ai/objectstack/issues/38438), from the contract review of the change that wrote the note above ([comment 7258340131](https://github.com/objectstack-ai/objectstack/pull/38619#issuecomment-7258340131), N1), which decides nothing: that note's "The same change takes the type off the directory's hidden types and brings its designer" is true of card #37087 and loose for the change. The card landed in two pull requests. The first ([#38484](https://github.com/objectstack-ai/objectstack/pull/38484)) brought the designer (`ui/packages/app-shell/src/views/studio-design/publicForm/PublicFormsDesigner.tsx`). The second ([#38619](https://github.com/objectstack-ai/objectstack/pull/38619)), the change that wrote the row, lists the type: it takes `form` off the directory's hidden types (`ui/packages/app-shell/src/views/metadata-admin/directoryScope.ts#HIDDEN_DIRECTORY_TYPES`) and gives it its place in the menu (`ui/packages/app-shell/src/views/studio-design/studioMenuPlacement.ts#STUDIO_MENU_PLACEMENT`). The row, its order and its tier stand as that note gives them, and that note is left as written.)* The rows are in the menu's order: by group, then by **Order**, which counts inside a group. **Tier** is 常用 Common or 高级 Advanced. The Chinese word beside a registered name is the one the ruling or its proposal uses for that type; a type neither names in Chinese has none. `field` carries no order and no tier because it draws no row (the second reading below). @@ -340,7 +342,7 @@ Merging accepts them; an objection names the number. 3. **Where the four entries that are not a type sit.** After the types of their group, as §3.4 leaves them. ~~The proposal's per-type table (§2) lists the organization's own flows between `flow` and `job`; this record follows §3.4, so on a package that holds a `job`, that type's entry is drawn above the organization's flows.~~ *(Amended 2026-11-29, card [#38150](https://github.com/objectstack-ai/objectstack/issues/38150), ruling record [comment 7184753035](https://github.com/objectstack-ai/objectstack/issues/37424#issuecomment-7184753035), question 3: the second sentence is struck. It placed the organization's own flows, which retired with their scope ([Organization-level content](#amendment-2026-11-26-org)). Of the four entries this item counts, a package's menu draws two since: the default sharing overview and diagnostics. The cross-package directory is the one the 2026-11-26 amendment moved to Setup ([Amendment (2026-11-26)](#amendment-2026-11-26-moves)). The first sentence stands for those two.)* 4. **The tiers' English names.** The ruling names the tiers in Chinese. This record writes Common and Advanced, after the two values of the proposal's list (§3.4). 5. **The table's shape.** One row per type, so that each type carries its own order and tier. Order counts inside a group, because the order of the groups is the six-group table's. -6. **~~A type registered after the ruling was written: `ai_context`.~~ Types registered after the ruling was written: `ai_context`, and since then `knowledge_source`.** *(Heading reworded 2026-11-27, for the second row that points here; the note that ends this item says what changed.)* The proposal and the ruling were made on a registry of 32 types. `ai_context`, the context pack of [ADR-0160](./0160-record-scoped-ai-inquiry.md) D1, was registered under `ai` the same day, after both. The maintainer's words on AI are 「AI 应该提到第一层分类,放在最下面」, and the ruling record lists the group's 常用 types as 智能体 · 工具 · 技能: three types, and not this one. Three ruled sentences place it, and they agree: its schema requires one root object, so the first test of the rule sorts it 高级; 高级 holds every type the ruling does not list as 常用; and a type with no row is drawn at the end of its group. The table writes that down as a row — last in AI, 高级 — so that the placement list has a row to mirror. If every AI type is meant to be 常用, the tier of this one row is the word to change. *(Amended 2026-11-27, card [#37740](https://github.com/objectstack-ai/objectstack/issues/37740), which decides nothing: a second type has been registered under `ai` since the ruling — `knowledge_source`, on 2026-11-27 ([ADR-0161](./0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md) K4) — and the change that registered it wrote its row under this item: fifth in AI, 高级. So `ai_context`'s row is the fourth, and no longer the last in AI. The ruling record's list of the group's 常用 types, 智能体 · 工具 · 技能, does not name this type either, and the same three sentences place it: its schema requires one object (the `object` key of its `source`, `packages/spec/src/ai/knowledge-source.zod.ts#ObjectKnowledgeSourceSchema`), so the first test of the rule sorts it 高级; 高级 holds every type the ruling does not list as 常用; and a type with no row is drawn at the end of its group. The sentence before this note holds for each of the two rows: if every AI type is meant to be 常用, the tier of that row is the word to change.)* +6. **~~A type registered after the ruling was written: `ai_context`.~~ Types registered after the ruling was written: `ai_context`, and since then `knowledge_source` and `picklist_extension`.** *(Heading reworded 2026-11-27, for the second row that points here, and again 2026-12-04, for the third; the notes that end this item say what changed.)* The proposal and the ruling were made on a registry of 32 types. `ai_context`, the context pack of [ADR-0160](./0160-record-scoped-ai-inquiry.md) D1, was registered under `ai` the same day, after both. The maintainer's words on AI are 「AI 应该提到第一层分类,放在最下面」, and the ruling record lists the group's 常用 types as 智能体 · 工具 · 技能: three types, and not this one. Three ruled sentences place it, and they agree: its schema requires one root object, so the first test of the rule sorts it 高级; 高级 holds every type the ruling does not list as 常用; and a type with no row is drawn at the end of its group. The table writes that down as a row — last in AI, 高级 — so that the placement list has a row to mirror. If every AI type is meant to be 常用, the tier of this one row is the word to change. *(Amended 2026-11-27, card [#37740](https://github.com/objectstack-ai/objectstack/issues/37740), which decides nothing: a second type has been registered under `ai` since the ruling — `knowledge_source`, on 2026-11-27 ([ADR-0161](./0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md) K4) — and the change that registered it wrote its row under this item: fifth in AI, 高级. So `ai_context`'s row is the fourth, and no longer the last in AI. The ruling record's list of the group's 常用 types, 智能体 · 工具 · 技能, does not name this type either, and the same three sentences place it: its schema requires one object (the `object` key of its `source`, `packages/spec/src/ai/knowledge-source.zod.ts#ObjectKnowledgeSourceSchema`), so the first test of the rule sorts it 高级; 高级 holds every type the ruling does not list as 常用; and a type with no row is drawn at the end of its group. The sentence before this note holds for each of the two rows: if every AI type is meant to be 常用, the tier of that row is the word to change.)* *(Amended 2026-12-04, pull request [#39668](https://github.com/objectstack-ai/objectstack/pull/39668) (card [#39536](https://github.com/objectstack-ai/objectstack/issues/39536), step 2), on claim amendment [7413299417](https://github.com/objectstack-ai/objectstack/issues/39536#issuecomment-7413299417), which decides nothing: a third type has been registered since the ruling — `picklist_extension`, registered `data` by ruling [7406020670](https://github.com/objectstack-ai/objectstack/issues/39536#issuecomment-7406020670) ([ADR-0146](./0146-studio-designs-setup-administers-one-editor-per-item-paired-customize-package.md) D2 / D10), the values a package adds to a shared option list another package owns — and the change that registered it wrote its row under this item: eighth in 数据 Data, after `seed`, 高级. No ruling names it, and the same sentences place it: its body requires one list to extend (the `extend` key of `packages/spec/src/data/picklist.zod.ts#PicklistExtensionSchema`), so it is authored from that list, which is itself 高级 by name (「选项列表 5也放到高级」); 高级 holds every type the ruling does not list as 常用; and a type with no row is drawn at the end of its group. If it is meant to sit beside `picklist` or `object_extension` instead, its Order is the word to change.)* The ruling also carries, as proposed and not restated here: the menu's visual hierarchy (§3.3), the placement list and its two pins (§3.4), how the fold is opened, remembered and searched (§3.5), and that no address changes (§3.9). Those are the work of #37200 and #37201. diff --git a/examples/app-showcase/src/coverage.ts b/examples/app-showcase/src/coverage.ts index 491fc015468..5246123337b 100644 --- a/examples/app-showcase/src/coverage.ts +++ b/examples/app-showcase/src/coverage.ts @@ -96,7 +96,7 @@ export const KIND_COVERAGE: Record = { status: 'waived', reason: 'An item of this kind adds values to a picklist another package owns, and the showcase ships no picklist and depends on no package that does (`picklist` and `picklistExtensions` are waived above), so there is no list to extend. Its code half is `picklistExtensions`; the item itself is written at runtime through `/api/v1/meta/picklist_extension/?package=`. Demonstrate it with the picklist kind.', - issue: 'https://github.com/objectstack-ai/objectstack/issues/39536', + issue: 'https://github.com/objectstack-ai/objectstack/issues/39699', }, // ── ui ── diff --git a/packages/metadata-protocol/src/protocol-package-commits.ts b/packages/metadata-protocol/src/protocol-package-commits.ts index f4db6da6260..aa37f67e72a 100644 --- a/packages/metadata-protocol/src/protocol-package-commits.ts +++ b/packages/metadata-protocol/src/protocol-package-commits.ts @@ -96,6 +96,7 @@ import { packagelessHolderRefusal } from './protocol-save.js'; import { withRefusalAudit } from './protocol-refusal-audit.js'; import type { ProtocolHost } from './protocol-host.js'; import type { ImportUnmanagedPackageAnswer, InstallPackageStoredRowHook, StoredPackageRow } from './protocol-package-install.js'; +import { refuseAmbiguousPicklistExtensionRollback } from './protocol-picklist-extension-item.js'; /** * [#30319] The grant keys of a stored permission set's `objects` map: what a @@ -2196,6 +2197,8 @@ export class ProtocolPackageCommitsFacet { // `(package, name)` only; on any other type it is refused first, // never accepted and dropped ({@link historySlotOf}). refusePackageSelectorOutsideSlottedTypes(singularType, request.packageId); + // [#39536, L2 S2] A `picklist_extension` name two packages hold. + await refuseAmbiguousPicklistExtensionRollback(host, singularType, request.name); if (!host.isOverlayAllowed(singularType) && !host.isRuntimeCreateAllowed(singularType)) { const err: any = new Error( diff --git a/packages/metadata-protocol/src/protocol-picklist-extension-item.ts b/packages/metadata-protocol/src/protocol-picklist-extension-item.ts index 82173b6e8f3..5be3555044a 100644 --- a/packages/metadata-protocol/src/protocol-picklist-extension-item.ts +++ b/packages/metadata-protocol/src/protocol-picklist-extension-item.ts @@ -33,7 +33,10 @@ * - {@link picklistExtensionItemRefusal} — the save / publish / restore gate; * - {@link registrablePicklistExtension} — the parsed body every sync * registers as the package's contribution - * (`SchemaRegistry.storedPicklistExtension`, `replace`). + * (`SchemaRegistry.storedPicklistExtension`, `replace`); + * - {@link refuseAmbiguousPicklistExtensionRollback} — the rollback door's + * refusal of a name two packages each hold a row of (the type is not + * package-slotted, so a version number does not say whose row it is). * * The body's SHAPE is judged by the doors' own schema gate * (`resolveOverlaySchema` → {@link PICKLIST_EXTENSION_ITEM_SCHEMA}). What the @@ -44,8 +47,13 @@ import { z } from 'zod'; import { PicklistExtensionSchema, EXTENSION_FIELD_SUFFIX, isExtensionFieldName } from '@objectstack/spec/data'; +import { + PackageScopedNameRefusedError, + type PackageScopedResolvableType, +} from '@objectstack/core'; import { withoutProtectionEnvelope } from './protocol-object-extension-item.js'; import type { MetadataIssueEntry } from './protocol.js'; +import type { ProtocolHost } from './protocol-host.js'; /** The metadata type of a picklist extension item. */ export const PICKLIST_EXTENSION_TYPE = 'picklist_extension' as const; @@ -125,10 +133,15 @@ export interface PicklistExtensionItemSubject { * the one holder in its declared dependency closure * (`resolvePicklistOptions` from the package, the resolver every field's * reference takes), refused naming the dependency to declare. - * 5. Additive only: no value repeats inside the item, and none is a value the - * list or another package's extension already carries — the registry's own - * refusal (`storedPicklistExtension` `refusal`, the sentence a sync - * would otherwise throw at registration), asked before anything is stored. + * 5. The registry's own refusal (`storedPicklistExtension` `refusal`, the + * sentence a sync would otherwise throw at registration), asked before + * anything is stored. First the target judged caller-less, as the + * registration judges an extension's target (ADR-0150 D3): a list name + * two installed packages each hold is refused, even when step 4 found + * one of them in the package's closure, because the registry would never + * serve the item. Then additive only: no value repeats inside the item, + * and none is a value the list or another package's extension already + * carries. * * Whether the package is writable is the door's own refusal * (`WRITABLE_PACKAGE_REQUIRED`), asked before any of this. @@ -289,3 +302,46 @@ export async function resyncStoredPicklistExtensions( } } } + +/** + * [#39536, L2 S2] The rollback door's question of this type. Its rows are + * stored one per writing package under the list's name, but the type is not + * package-slotted (`PACKAGE_SLOTTED_STORE_TYPES`), so the history and + * rollback doors take no `package` selector for it and its versions are + * numbered across every writer's row: a version number alone does not say + * whose row it may be restored into. While more than one package holds an + * active row of the name, a rollback is refused before anything is read or + * written, with the envelope the door answers for a two-holder name of a + * slotted type (`409 RESOURCE_CONFLICT`, `ambiguous-in-environment`), naming + * every holder and the remedy. One holder, or none, rolls back as before. + * + * @throws {PackageScopedNameRefusedError} for a name two or more packages hold. + */ +export async function refuseAmbiguousPicklistExtensionRollback( + host: Pick, + type: string, + name: string, +): Promise { + if (type !== PICKLIST_EXTENSION_TYPE) return; + const holders = [...new Set( + (await host.readItemActiveRows(type, name)) + .map((row) => (row as { package_id?: unknown }).package_id) + .filter((pkg): pkg is string => typeof pkg === 'string' && pkg !== ''), + )].sort(); + if (holders.length < 2) return; + const named = holders.map((pkg) => `'${pkg}'`).join(', '); + const message = `Picklist extension '${name}' cannot be rolled back: ${holders.length} packages each hold a row of it ` + + `(${named}), its versions are numbered across all of them, and this type takes no \`package\` selector on ` + + 'history or rollback, so nothing says whose row a version belongs to. Nothing was changed. To return one ' + + "package's values to an earlier version, save those values as a draft of that package's item (naming the " + + 'package) and publish it.'; + throw new PackageScopedNameRefusedError({ + status: 'refused', + reason: 'ambiguous-in-environment', + type: type as PackageScopedResolvableType, + name, + callerPackageId: null, + candidates: holders.map((packageId) => ({ kind: 'package' as const, packageId })), + message, + }); +} diff --git a/packages/objectql/src/registry-picklists.ts b/packages/objectql/src/registry-picklists.ts index 2a1e182bac7..8e8916cac92 100644 --- a/packages/objectql/src/registry-picklists.ts +++ b/packages/objectql/src/registry-picklists.ts @@ -492,21 +492,37 @@ export class PicklistsFacet { * aside, the new one registered through that body (every judge it asks, * unchanged), and the set-aside one put back when it throws, so a refused * replacement leaves the list as it was. The entry is marked stored. - * - `refusal` — what `replace` would refuse for these values (a value - * repeated inside them, or one the list or another package's extension - * already carries: `INVALID_METADATA`, the additive rule's sentence), - * registering nothing; `undefined` = admitted. The doors ask it before a - * row is stored. + * - `refusal` — what `replace` would refuse for these values, registering + * nothing; `undefined` = admitted. First the target judged caller-less, + * as the registration judges it (ADR-0150 D3): a list name two installed + * packages each hold is refused with the registry's arrival sentence, + * sealed or not, since such an item could never be served. Then the + * additive rule: a value repeated inside them, or one the list or + * another package's extension already carries (`INVALID_METADATA`, the + * additive rule's sentence). The doors ask it before a row is stored. * - `withdraw` — the deletion of the row: drop the package's contribution; * `true` when there was one. * - `extenders` — the packages whose contribution to the list is a stored * row, never a manifest's `picklistExtensions` entry. */ - static storedPicklistExtension(this: Pick, request: StoredPicklistExtensionRequest): void | Error | undefined | boolean | string[] { + static storedPicklistExtension(this: Pick, request: StoredPicklistExtensionRequest): void | Error | undefined | boolean | string[] { const byPackageOf = (name: string) => this.picklistExtensionContributions.get(name); switch (request.op) { case 'refusal': { const { extension, packageId } = request; + // [#39536, L2 S1] The question the registration asks first + // ({@link registerPicklistExtension}): the target, judged caller-less + // (ADR-0150 D3), must be one list. Asked here whether or not the + // vocabulary is sealed: unsealed, an ambiguous target would register + // and then be left out of every field's list, so the item would never + // be served. The registry's own sentence is the answer. + const ambiguous = this.picklistArrivalRefusal([{ id: packageId, picklistExtensions: [extension] }], { + replaces: false, + ownRefusals: 'ambiguous', + act: 'register', + subject: `a \`picklist_extension\` item of package '${packageId}' extending picklist '${extension.extend}'`, + }); + if (ambiguous) return ambiguous; const candidate: PicklistContribution = { packageId, kind: 'extension', options: [...(extension.options ?? [])] }; const others = this.picklistContributions(extension.extend).filter( (c) => !(c.kind === 'extension' && (c.packageId ?? '') === packageId), diff --git a/packages/runtime/src/domains/meta-picklist-extension-item.test.ts b/packages/runtime/src/domains/meta-picklist-extension-item.test.ts index 16f8530c93a..7eb3041f459 100644 --- a/packages/runtime/src/domains/meta-picklist-extension-item.test.ts +++ b/packages/runtime/src/domains/meta-picklist-extension-item.test.ts @@ -62,6 +62,8 @@ const PAIR = 'com.acme.crm.custom'; const OTHER = 'com.acme.other'; /** A writable package that depends on the base: a second writer the list is reachable from. */ const PARTNER = 'com.acme.partner'; +/** A second code package holding a list of the base's list name: two holders environment-wide. */ +const RIVAL = 'com.acme.rival'; const LIST = 'lead_source'; const TYPE = 'picklist_extension'; @@ -213,6 +215,29 @@ describe('[#39536] a writable pair saves and publishes an extension of the base\ expect((await rig.values()).registry).toEqual([...VENDOR, 'trade_show__c']); }, 60_000); + // [#39536, L2 S2] Two writers of one list: the type is not slotted, so a + // version number does not say whose row it belongs to. Refused while two + // packages hold a row, never written into either. + it('with two packages each holding a row of the list, a rollback is refused naming both, and neither row moves', async () => { + const rig = await boot(); + await rig.saveAndPublish(PAIR, tradeShow(['trade_show__c'])); + await rig.saveAndPublish(PAIR, tradeShow(['webinar__c'])); + await rig.saveAndPublish(PARTNER, { extend: LIST, options: [{ label: 'Partner', value: 'partner__c' }] }); + const before = await rig.values(); + const versions = ((await rig.engine.find('sys_metadata_history', { where: { type: TYPE, name: LIST }, context: { isSystem: true } })) as any[]) + .filter((row) => JSON.stringify(JSON.parse(String(row.metadata)).options).includes('trade_show__c')) + .map((row) => Number(row.version)); + expect(versions.length, 'one stored version carrying trade_show__c').toBeGreaterThanOrEqual(1); + + const caught = await rig.refusalOf(() => rig.protocol.rollbackMetaItem({ type: TYPE, name: LIST, toVersion: Math.min(...versions) })); + expect(caught, 'the rollback was admitted').toBeDefined(); + expect({ code: caught.code, status: caught.status }).toEqual({ code: 'RESOURCE_CONFLICT', status: 409 }); + expect(caught.message).toContain(`'${PAIR}'`); + expect(caught.message).toContain(`'${PARTNER}'`); + expect(await rig.values()).toEqual(before); + expect(before.registry).toEqual([...VENDOR, 'webinar__c', 'partner__c']); + }, 60_000); + it('a boot re-reads the stored row and registers it the same way', async () => { const rig = await boot(); await rig.saveAndPublish(PAIR, tradeShow()); @@ -367,6 +392,35 @@ describe('[#39536] refused at the door, leaving no row and registering nothing', expect(await rig.rows()).toEqual([]); }, 60_000); + // [#39536, L2 S1] Two installed packages each hold a list of the name. + // The pair reaches one of them through its closure, but the registry + // resolves an extension's target caller-less (ADR-0150 D3), where the name + // is ambiguous: the item could never be served. The door asks the + // registry's own arrival judgement before storing anything, sealed or not. + it.each([['as booted', false], ['after the vocabulary is sealed', true]] as const)( + 'a list two installed packages each hold, %s: refused with the registry\'s sentence, nothing stored or registered', + async (_label, seal) => { + const rig = await boot(); + rig.engine.registerApp({ + id: RIVAL, name: 'rival', version: '1.0.0', type: 'app', namespace: 'rival', + picklists: [{ name: LIST, label: 'Rival Source', options: [{ label: 'Fair', value: 'fair' }] }], + } as any); + if (seal) (rig.engine.registry as any).sealPicklistVocabulary(); + const caught = await rig.refusalOf(() => rig.protocol.saveMetaItem({ type: TYPE, name: LIST, item: tradeShow(), mode: 'draft', packageId: PAIR })); + expect(caught, 'the save was admitted').toBeDefined(); + expect({ code: caught.code, status: caught.status }).toEqual({ code: 'VALIDATION_ERROR', status: 400 }); + const registrySentence = (rig.engine.registry as any).picklistArrivalRefusal( + [{ id: PAIR, picklistExtensions: [tradeShow()] }], + { replaces: false, ownRefusals: 'ambiguous', act: 'register', subject: `a \`picklist_extension\` item of package '${PAIR}' extending picklist '${LIST}'` }, + )?.message; + expect(registrySentence, 'the registry itself judges the target ambiguous').toBeTruthy(); + expect(caught.message).toBe(registrySentence); + expect(await rig.rows()).toEqual([]); + expect((rig.engine.registry as any).storedPicklistExtension({ op: 'extenders', name: LIST })).toEqual([]); + }, + 60_000, + ); + it('a draft whose value another package took before it was published is refused at publish', async () => { const rig = await boot(); await rig.protocol.saveMetaItem({ type: TYPE, name: LIST, item: tradeShow(), mode: 'draft', packageId: PAIR }); diff --git a/packages/spec/src/kernel/metadata-plugin.zod.ts b/packages/spec/src/kernel/metadata-plugin.zod.ts index fe5f198e613..d51bbe7a877 100644 --- a/packages/spec/src/kernel/metadata-plugin.zod.ts +++ b/packages/spec/src/kernel/metadata-plugin.zod.ts @@ -967,6 +967,14 @@ export const DEFAULT_METADATA_TYPE_REGISTRY: MetadataTypeRegistryEntryParsed[] = // metadata-protocol doors, and every value it adds ends in `__c`. Never // overlaid: a package changes its own item. `loadOrder: 9` — after // `picklist` (8), before `object` (10), whose fields resolve the list. + // + // `filePatterns`: the `*.picklist-extension.ts` file name a code package + // may give a `PicklistExtensionSchema` body, by the twin's `*.extension.ts` + // convention. Nothing in the tree writes one yet, and a file of that name + // registers nothing: the metadata file loader globs it and skips a body + // with no `name`, as an extension body has none. A code package declares + // its extensions in `picklistExtensions`, which `registerApp` registers; + // this type's items are the stored rows the `/api/v1/meta` doors write. { type: 'picklist_extension', label: 'Picklist Extension', description: 'Values a package adds to a picklist another package owns', filePatterns: ['**/*.picklist-extension.ts'], supportsOverlay: false, allowEnvironmentOverlay: false, allowRuntimeCreate: true, supportsVersioning: true, executionPinned: false, loadOrder: 9, domain: 'data' }, { type: 'mapping', label: 'Import Mapping', description: 'Reusable import/export field mapping (rename + transforms), referenced by name at import', filePatterns: ['**/*.mapping.ts', '**/*.mapping.yml', '**/*.mapping.json'], supportsOverlay: false, allowEnvironmentOverlay: false, allowRuntimeCreate: true, supportsVersioning: true, executionPinned: false, loadOrder: 96, domain: 'data' },