@@ -175,6 +175,77 @@ function copyDiagnostics(verdict: MetadataDiagnostics): MetadataDiagnostics {
175175 return copy ;
176176}
177177
178+ // ---------------------------------------------------------------------------
179+ // [#26886] Options the runtime resolved from a shared picklist
180+ // ---------------------------------------------------------------------------
181+ //
182+ // A field authors `picklist: '<name>'` and no `options`; every object read
183+ // serves it with the list's options written beside `picklist` (the registry's
184+ // picklist resolution, `PicklistServedFieldSchema`). Diagnostics judge what the
185+ // author wrote, so the field schema's rule that refuses `picklist` and
186+ // `options` together must not read the copy the runtime wrote: it flagged
187+ // every picklist-bound field of every app.
188+ //
189+ // The resolution therefore MARKS the options array it derived
190+ // ({@link markResolvedPicklistOptions}), and only a marked array is left out
191+ // here. A field that authored its own `options` beside `picklist` arrives
192+ // unmarked and is still flagged, with the same message and severity. The mark
193+ // is a non-enumerable property, so no response, stored row or memo key ever
194+ // carries it, and it is keyed with `Symbol.for` so every loaded copy of this
195+ // package reads the one mark. A copy of the array (`.map`, a JSON round trip)
196+ // drops it, and the field is then judged with its `options`: the failure
197+ // direction is the old false error, never a missed one.
198+
199+ const RESOLVED_PICKLIST_OPTIONS = Symbol . for ( '@objectstack/metadata-protocol:resolved-picklist-options' ) ;
200+
201+ /**
202+ * Mark an `options` array as resolved from a shared picklist rather than
203+ * authored on the field. Returns the same array.
204+ */
205+ export function markResolvedPicklistOptions < T extends object > ( options : T ) : T {
206+ if ( ! Object . prototype . hasOwnProperty . call ( options , RESOLVED_PICKLIST_OPTIONS ) ) {
207+ Object . defineProperty ( options , RESOLVED_PICKLIST_OPTIONS , { value : true } ) ;
208+ }
209+ return options ;
210+ }
211+
212+ /** `true` when `options` is an array {@link markResolvedPicklistOptions} marked. */
213+ export function isResolvedPicklistOptions ( options : unknown ) : boolean {
214+ return Array . isArray ( options )
215+ && ( options as unknown as Record < symbol , unknown > ) [ RESOLVED_PICKLIST_OPTIONS ] === true ;
216+ }
217+
218+ function withoutResolvedOptions ( field : unknown ) : unknown {
219+ if ( ! field || typeof field !== 'object' ) return field ;
220+ const { picklist, options } = field as { picklist ?: unknown ; options ?: unknown } ;
221+ if ( typeof picklist !== 'string' || ! isResolvedPicklistOptions ( options ) ) return field ;
222+ const { options : _resolved , ...authored } = field as Record < string , unknown > ;
223+ return authored ;
224+ }
225+
226+ /**
227+ * A document with the resolved `options` left out of every picklist-bound
228+ * field, in both field spellings a served body carries (a name-keyed record,
229+ * an array). By reference when no field carries resolved options.
230+ */
231+ function withoutResolvedPicklistOptions ( document : unknown ) : unknown {
232+ if ( ! document || typeof document !== 'object' ) return document ;
233+ const fields = ( document as { fields ?: unknown } ) . fields ;
234+ if ( ! fields || typeof fields !== 'object' ) return document ;
235+ if ( Array . isArray ( fields ) ) {
236+ const next = fields . map ( withoutResolvedOptions ) ;
237+ return next . some ( ( f , i ) => f !== fields [ i ] ) ? { ...( document as object ) , fields : next } : document ;
238+ }
239+ let next : Record < string , unknown > | undefined ;
240+ for ( const [ name , field ] of Object . entries ( fields as Record < string , unknown > ) ) {
241+ const judged = withoutResolvedOptions ( field ) ;
242+ if ( judged === field ) continue ;
243+ next ??= { ...( fields as Record < string , unknown > ) } ;
244+ next [ name ] = judged ;
245+ }
246+ return next ? { ...( document as object ) , fields : next } : document ;
247+ }
248+
178249/**
179250 * Compute spec diagnostics for a single metadata document.
180251 *
@@ -224,7 +295,10 @@ export function computeMetadataDiagnostics(
224295 // says. Same class as #6810 (`indexed`), different remedy — that key did
225296 // not belong on the served body at all and left at its injection site,
226297 // whereas this one is read by the UI and belongs on the response.
227- const candidate = stripReadDecorations ( item ) ;
298+ // [#26886] …and judge each picklist-bound field as its author wrote it:
299+ // the `options` the runtime resolved onto it are not part of that shape
300+ // ({@link withoutResolvedPicklistOptions}).
301+ const candidate = withoutResolvedPicklistOptions ( stripReadDecorations ( item ) ) ;
228302
229303 // [#25783] A document parsed before against this same schema is answered
230304 // from the memo — see "The verdict memo" above.
0 commit comments