Skip to content

Commit 3e83c8d

Browse files
committed
test: pin the picklist diagnostics on the item, list and sweep doors; changeset
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5nFWpcGdLrSDAf6vS9
1 parent 6d64e11 commit 3e83c8d

4 files changed

Lines changed: 160 additions & 7 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
'@objectstack/objectql': patch
4+
---
5+
6+
fix(metadata-protocol): load-time diagnostics no longer report "`picklist` and `options` cannot both be declared" on a field that declares only `picklist`
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
A select field that names a shared list (`picklist: 'industry'`) is served with the list's options written beside `picklist`, and the diagnostics judged that served copy, so every shared-picklist field of every app was reported as declaring both keys: in an item's `_diagnostics`, in the list read's, and in `GET /meta/diagnostics` (Setup › All Metadata Types). They now judge the field as its author wrote it.
12+
13+
- **The rule stands.** A field that authors both `picklist` and `options` is still reported, with the same message and severity, at `fields.NAME.options`.
14+
- **What `/meta` serves is unchanged.** A picklist-bound field is still served with `picklist` and the resolved `options`.
15+
- **How the two are told apart.** The picklist resolution marks the options array it derives; `@objectstack/metadata-protocol` exports `markResolvedPicklistOptions` and `isResolvedPicklistOptions`, and the diagnostics leave a marked array out of the judgement. The mark is not part of any response or stored row.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #26886 — load-time diagnostics judge a picklist-bound field as its author
5+
* wrote it, never with the `options` the runtime resolved onto it.
6+
*
7+
* Every object read serves a field that authors `picklist: '<name>'` with the
8+
* list's options written beside it, and the field schema refuses `picklist`
9+
* and `options` together. Judging the served copy flagged every shared-picklist
10+
* field of every app. The resolution marks the array it derived
11+
* (`markResolvedPicklistOptions`), and only a marked array is left out of the
12+
* judgement:
13+
*
14+
* - a field naming only a picklist, served with resolved options: clean;
15+
* - a field that AUTHORS both keys (an unmarked array): still flagged, with
16+
* the rule's own message, at `fields.NAME.options`;
17+
* - a field with inline `options` only: clean, before and after.
18+
*
19+
* The mark never reaches a response or a memo key: a marked document and an
20+
* unmarked one with the same JSON are two verdicts.
21+
*/
22+
import { describe, expect, it } from 'vitest';
23+
import {
24+
computeMetadataDiagnostics,
25+
decorateMetadataItem,
26+
isResolvedPicklistOptions,
27+
markResolvedPicklistOptions,
28+
} from './metadata-diagnostics.js';
29+
30+
const BOTH_KEYS = '`picklist` and `options` cannot both be declared';
31+
32+
const resolved = () => markResolvedPicklistOptions([{ label: 'Tech', value: 'tech' }]);
33+
const authored = () => [{ label: 'Tech', value: 'tech' }];
34+
35+
function objectWith(fields: Record<string, unknown>) {
36+
return { name: 'pk_probe', label: 'Probe', fields: { name: { name: 'name', type: 'text', label: 'Name' }, ...fields } };
37+
}
38+
39+
const industry = (options: unknown[]) =>
40+
({ name: 'industry', type: 'select', label: 'Industry', picklist: 'industry', options });
41+
42+
function bothKeysPaths(diagnostics: ReturnType<typeof computeMetadataDiagnostics>): string[] {
43+
return (diagnostics?.errors ?? []).filter((e) => e.message.startsWith(BOTH_KEYS)).map((e) => e.path);
44+
}
45+
46+
describe('diagnostics — options resolved from a shared picklist', () => {
47+
it('a field naming only a picklist, served with its resolved options, is clean', () => {
48+
expect(computeMetadataDiagnostics('object', objectWith({ industry: industry(resolved()) }))).toEqual({ valid: true });
49+
});
50+
51+
it('a field that authors `options` beside `picklist` is still flagged, at its options path', () => {
52+
const diagnostics = computeMetadataDiagnostics('object', objectWith({ industry: industry(authored()) }));
53+
expect(diagnostics?.valid).toBe(false);
54+
expect(bothKeysPaths(diagnostics)).toEqual(['fields.industry.options']);
55+
});
56+
57+
it('a field with inline `options` only is clean', () => {
58+
const inline = { name: 'stage', type: 'select', label: 'Stage', options: [{ label: 'Open', value: 'open' }] };
59+
expect(computeMetadataDiagnostics('object', objectWith({ stage: inline }))).toEqual({ valid: true });
60+
});
61+
62+
it('a marked array on a field with no `picklist` is judged as written', () => {
63+
// A one-character option value is refused; left out, nothing would be.
64+
const stray = { name: 'stage', type: 'select', label: 'Stage', options: markResolvedPicklistOptions([{ label: 'X', value: 'x' }]) };
65+
const diagnostics = computeMetadataDiagnostics('object', objectWith({ stage: stray }));
66+
expect(diagnostics?.errors?.map((e) => e.path)).toEqual(['fields.stage.options.0.value']);
67+
});
68+
69+
it('a marked and an unmarked document with the same JSON are two verdicts, in either order', () => {
70+
const marked = objectWith({ industry: industry(resolved()) });
71+
const unmarked = objectWith({ industry: industry(authored()) });
72+
expect(JSON.stringify(marked)).toBe(JSON.stringify(unmarked));
73+
expect(bothKeysPaths(computeMetadataDiagnostics('object', unmarked))).toEqual(['fields.industry.options']);
74+
expect(computeMetadataDiagnostics('object', marked)).toEqual({ valid: true });
75+
expect(bothKeysPaths(computeMetadataDiagnostics('object', unmarked))).toEqual(['fields.industry.options']);
76+
});
77+
78+
it('the served item keeps both keys and carries no trace of the mark', () => {
79+
const served = decorateMetadataItem('object', objectWith({ industry: industry(resolved()) })) as any;
80+
expect(served._diagnostics).toEqual({ valid: true });
81+
expect(served.fields.industry).toMatchObject({ picklist: 'industry', options: [{ label: 'Tech', value: 'tech' }] });
82+
expect(JSON.parse(JSON.stringify(served.fields.industry))).toEqual(industry(authored()));
83+
expect(Object.keys(served.fields.industry.options)).toEqual(['0']);
84+
});
85+
86+
it('a copy of a marked array is unmarked: the failure direction is the old error, never a missed one', () => {
87+
const options = resolved();
88+
expect(isResolvedPicklistOptions(options)).toBe(true);
89+
expect(isResolvedPicklistOptions(options.map((o) => ({ ...o })))).toBe(false);
90+
expect(isResolvedPicklistOptions(JSON.parse(JSON.stringify(options)))).toBe(false);
91+
expect(isResolvedPicklistOptions([...options])).toBe(false);
92+
});
93+
});

‎packages/metadata-protocol/src/metadata-diagnostics.ts‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,13 @@ function withoutResolvedOptions(field: unknown): unknown {
225225

226226
/**
227227
* 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.
228+
* field of its name-keyed `fields` (the only spelling the object schema
229+
* accepts). By reference when no field carries resolved options.
230230
*/
231231
function withoutResolvedPicklistOptions(document: unknown): unknown {
232232
if (!document || typeof document !== 'object') return document;
233233
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-
}
234+
if (!fields || typeof fields !== 'object' || Array.isArray(fields)) return document;
239235
let next: Record<string, unknown> | undefined;
240236
for (const [name, field] of Object.entries(fields as Record<string, unknown>)) {
241237
const judged = withoutResolvedOptions(field);

‎packages/objectql/src/protocol-picklist-served-roundtrip.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,52 @@ describe('picklist — the protocol object read and the authoring door', () => {
184184
expect(err.message).toContain('`picklist` and `options` cannot both be declared');
185185
});
186186
});
187+
188+
// [#26886] Every door that shows a load-time diagnostic judges a
189+
// picklist-bound field as its author wrote it: the item's `_diagnostics`, the
190+
// list's, and `GET /meta/diagnostics`. The read itself keeps serving both keys.
191+
describe('picklist — the load-time diagnostics judge the authored field, not the served copy', () => {
192+
const BOTH_KEYS = '`picklist` and `options` cannot both be declared';
193+
let protocol: ObjectStackProtocolImplementation;
194+
195+
beforeEach(async () => {
196+
const engine = new ObjectQL();
197+
engine.registerDriver(makeStubDriver().driver, true);
198+
await engine.init();
199+
engine.registry.registerObject(sysMetadataObject);
200+
for (const o of [SysMetadataHistoryObject, SysMetadataAuditObject, SysMetadataCommitObject]) engine.registry.registerObject(o as any);
201+
engine.registerApp({
202+
id: 'com.test.lists', name: 'lists',
203+
picklists: [{ name: 'industry', label: 'Industry', options: [{ label: 'Tech', value: 'tech' }] }],
204+
objects: [{
205+
name: 'pd_obj', label: 'Probe', sharingModel: 'public_read_write',
206+
fields: {
207+
name: { name: 'name', type: 'text', label: 'Name' },
208+
industry: { name: 'industry', type: 'select', label: 'Industry', picklist: 'industry' },
209+
stage: { name: 'stage', type: 'select', label: 'Stage', options: [{ label: 'Open', value: 'open' }] },
210+
both: { name: 'both', type: 'select', label: 'Both', picklist: 'industry', options: [{ label: 'Own', value: 'own' }] },
211+
},
212+
}],
213+
} as any);
214+
protocol = new ObjectStackProtocolImplementation(engine);
215+
});
216+
217+
const bothKeysPaths = (diagnostics: any): string[] =>
218+
(diagnostics?.errors ?? []).filter((e: any) => String(e.message).startsWith(BOTH_KEYS)).map((e: any) => e.path);
219+
220+
it('the item read: only the field that authored both keys is flagged, and both keys are still served', async () => {
221+
const served: any = await protocol.getMetaItem({ type: 'object', name: 'pd_obj' } as any);
222+
expect(served.item.fields.industry).toMatchObject({ picklist: 'industry', options: [{ label: 'Tech', value: 'tech' }] });
223+
expect(bothKeysPaths(served.item._diagnostics)).toEqual(['fields.both.options']);
224+
expect(served.item._diagnostics.errors.map((e: any) => e.path)).toEqual(['fields.both.options']);
225+
});
226+
227+
it('the list read and `GET /meta/diagnostics` agree with the item read', async () => {
228+
const listed: any = await protocol.getMetaItems({ type: 'object' } as any);
229+
const item = (listed.items ?? listed).find((i: any) => i.name === 'pd_obj');
230+
expect(bothKeysPaths(item._diagnostics)).toEqual(['fields.both.options']);
231+
const sweep: any = await (protocol as any).getMetaDiagnostics({ type: 'object' });
232+
const entry = sweep.entries.find((e: any) => e.name === 'pd_obj');
233+
expect(entry.diagnostics.errors.map((e: any) => e.path)).toEqual(['fields.both.options']);
234+
});
235+
});

0 commit comments

Comments
 (0)