diff --git a/.changeset/38433-list-view-group-field-ungroupable.md b/.changeset/38433-list-view-group-field-ungroupable.md new file mode 100644 index 00000000000..35b5fcfcc71 --- /dev/null +++ b/.changeset/38433-list-view-group-field-ungroupable.md @@ -0,0 +1,23 @@ +--- +'@objectstack/lint': minor +'@objectstack/spec': patch +--- + +fix(lint)!: refuse a list view grouped by a field the engine does not group by + +Clause-②: no (narrowing) +Metadata-protocol: narrowed +Skills-docs: follow-up #38655 + + + +**BREAKING** for a `grid` list view (or one with no `type`, which defaults to `grid`) whose `grouping.fields[].field` names a multi-valued, JSON-stored or `formula` field: it was accepted before and is refused now, with the fix named in the finding. The schema is unchanged and stored metadata is not rewritten or refused at boot; the refusal comes at the next publish of the view (a `view` write, or an `object` write through the object's own `listViews`), and from `os validate` / `lint` / `compile` / `build`. + +- `list-view-group-field-ungroupable` (error): a grid list view's grouping level over a multi-valued field (`multiselect`, `checkboxes`, `tags`, or a `multiple` select or reference), a JSON-stored field (`json`, `address`, `composite` and the like) or a field computed on read (`formula`). A grid sends its grouping as the group header query, and the engine refuses a `groupBy` over each of these (`400 INVALID_FIELD`), so the view saved, then opened on that error and rendered no group. The verdict asks the same spec predicates the engine's two doors ask, so it refuses exactly the three storage classes the engine refuses. A dotted name is refused by the engine on another ground, which this verdict does not report (#38654). Not judged: any other list-view kind (`kanban`, `gallery`, `calendar`, `timeline`, `gantt`, `map`, `chart`, `tree`, `timesheet`), whose grouping was not measured to reach the engine, and an unknown name (`list-view-field-unknown`). + +## FROM → TO + +- FROM: a `grid` list view with `grouping: { fields: [{ field: 'labels' }] }` where `labels` is a `multiselect`, a JSON-stored or a `formula` field — saved, then the grid opened on `400 INVALID_FIELD`. +- TO: group by a stored single-valued field (`grouping: { fields: [{ field: 'status' }] }`, a single-valued `select`, a boolean, a single-valued lookup, or a text, number or date field), or drop the grouping and show the field as a grid column (`columns: [..., 'labels']`). + +`@objectstack/lint` exports the rule id constant `LIST_VIEW_GROUP_FIELD_UNGROUPABLE`, so `os explain list-view-group-field-ungroupable` carries an entry. `@objectstack/spec` adds only the upgrade-guide entry `publish-refuses-list-view-grouping-the-engine-does-not-group-by`. diff --git a/content/docs/deployment/validating-metadata.mdx b/content/docs/deployment/validating-metadata.mdx index a2e3963bbab..6ee86a4932d 100644 --- a/content/docs/deployment/validating-metadata.mdx +++ b/content/docs/deployment/validating-metadata.mdx @@ -508,7 +508,7 @@ orthogonal to both, and no cell here can carry it; it is written out in | Empty filter combinators — `$and: []`, `$or: []`, `$not: {}` (#5330) | ✓ | ✓ | ✓ | ✓ᶠʳ | | Object & action name references (#3583) — and the object a seed dataset, a flow `get_record` / `create_record` / `update_record` / `delete_record` / object-form `screen` node or a standalone action is bound to (`object-reference-unknown`, #35143); a flow node's miss is a warning on the CLI, where a declared dependency may define the object, and an error at the publish door; at the publish door a seed over an unknown object is the save door's own refusal (#34864) | ✓ | ✓ | ✓ | ✓ᶠᵈᵗᵃᶜ | | Reference integrity — flow node writes, template paths, read-only writes (#3583); at the publish door each write type runs only the members that declare it, and the flow members run on `flow` alone (#9313); a `translation` write runs only the translation-key member, advisory only and never a 422, on the families the per-write snapshot carries (objects, their fields and inline options, validation rules, milestones, permission sets; apps and navigation are not judged) (#38623) | ✓ | ✓ | ✓ | ✓ᶠᵛᵒᵈᵗʳᵖᵃᶜᵗ | -| List-view field members — a list view's `sort` (a `sortable: false` field, a `formula`, an unknown name: `sort-field-unsortable`), its `searchableFields` (`searchable-field-unknown`) and its field references, columns, filter keys, grouping and the board bindings (`list-view-field-unknown`); a filter key on a `formula` field, which the engine refuses to filter by (`list-view-filter-field-virtual`, #35143), and, advisory, a board grouped by a field with no fixed set of lanes (`list-view-kanban-group-field-uncategorical`, #35143); the row merges three members, so its codes follow no one rule's order, and the `page` door runs the sort member only (#9313, #15495, #30095) | ✓ | ✓ | ✓ | ✓ᶠᵛᵒᵖ | +| List-view field members — a list view's `sort` (a `sortable: false` field, a `formula`, an unknown name: `sort-field-unsortable`), its `searchableFields` (`searchable-field-unknown`) and its field references, columns, filter keys, grouping and the board bindings (`list-view-field-unknown`); a filter key on a `formula` field, which the engine refuses to filter by (`list-view-filter-field-virtual`, #35143), a grid list view's grouping level over a multi-valued, JSON-stored or `formula` field, which the engine refuses to group by (`list-view-group-field-ungroupable`, #38433), and, advisory, a board grouped by a field with no fixed set of lanes (`list-view-kanban-group-field-uncategorical`, #35143); the row merges three members, so its codes follow no one rule's order, and the `page` door runs the sort member only (#9313, #15495, #30095) | ✓ | ✓ | ✓ | ✓ᶠᵛᵒᵖ | | Page-component field bindings (#3583) | ✓ | ✓ | ✓ | ✓ᶠ | | React page block field bindings — §10 (#4340) | ✓ | ✓ | ✓ | ✓ᶠ | | Chart bindings outside dashboards (#3583) | ✓ | ✓ | ✓ | ✓ᶠʳᵛᵒ | diff --git a/packages/lint/src/index.ts b/packages/lint/src/index.ts index 57f1d56abef..d94da62aad8 100644 --- a/packages/lint/src/index.ts +++ b/packages/lint/src/index.ts @@ -718,6 +718,8 @@ export { LIST_VIEW_FIELD_UNKNOWN, LIST_VIEW_FIELD_DOTTED, LIST_VIEW_GROUP_ORDER_UNORDERABLE, + // [#38433] A grouping level over a field the engine does not group by. + LIST_VIEW_GROUP_FIELD_UNGROUPABLE, LIST_VIEW_SUMMARY_FIELD_TYPE_REFUSED, LIST_VIEW_CHART_DATASET_FOREIGN_OBJECT, LIST_VIEW_KANBAN_LANE_UNKNOWN, diff --git a/packages/lint/src/rule-explanations.ts b/packages/lint/src/rule-explanations.ts index 689b821ee6e..58456906080 100644 --- a/packages/lint/src/rule-explanations.ts +++ b/packages/lint/src/rule-explanations.ts @@ -4497,6 +4497,28 @@ const LIST_VIEW_GROUP_ORDER_UNORDERABLE_EXPLANATION: RuleExplanation = { ], }; +const LIST_VIEW_GROUP_FIELD_UNGROUPABLE_EXPLANATION: RuleExplanation = { + rule: 'list-view-group-field-ungroupable', + covers: 'which fields a grid list view can be grouped by', + paragraphs: [ + 'A grid list view sends its grouping to the engine as one aggregate: each grouping level\'s `field` is one ' + + '`groupBy` column of the group header query. The engine refuses to group by three kinds of field ' + + '(`400 INVALID_FIELD`), before any database is asked: a multi-valued field (`multiselect`, `checkboxes`, ' + + '`tags`, or a `multiple` select or reference), a JSON-stored field (`json`, `address`, `composite` and the ' + + 'like), and a `formula` field, which is computed on read and stores no column. A grid grouped by one saves ' + + 'and publishes, then opens on that error and renders no group.', + 'An error, so the publish is refused and `os validate` and `os build` fail. The verdict asks the same spec ' + + 'predicates the engine asks, so it refuses exactly the three storage classes the engine refuses. A dotted ' + + 'name is refused by the engine on another ground, which this verdict does not report. Judged on a list view ' + + 'whose `type` is `grid` or absent (the default is `grid`); any other kind is not judged, because none was ' + + 'measured to send its grouping to the engine: a gallery groups the cards it fetched, and a kanban board ' + + 'keeps drawing its cards when its grouped count read is refused. Not judged either: a name that resolves ' + + 'to nothing (`list-view-field-unknown`) and a field whose type is not readable.', + 'To fix it, show the field as a grid column, or group by a stored single-valued field: a single-valued ' + + '`select`, a boolean, a single-valued lookup, or a text, number or date field.', + ], +}; + const LIST_VIEW_SUMMARY_FIELD_TYPE_REFUSED_EXPLANATION: RuleExplanation = { rule: 'list-view-summary-field-type-refused', covers: 'which functions a column summary can apply to its field', @@ -7438,6 +7460,7 @@ export const RULE_EXPLANATIONS: Readonly> = Obje [LIST_VIEW_FIELD_UNKNOWN_EXPLANATION.rule]: LIST_VIEW_FIELD_UNKNOWN_EXPLANATION, [LIST_VIEW_FIELD_DOTTED_EXPLANATION.rule]: LIST_VIEW_FIELD_DOTTED_EXPLANATION, [LIST_VIEW_GROUP_ORDER_UNORDERABLE_EXPLANATION.rule]: LIST_VIEW_GROUP_ORDER_UNORDERABLE_EXPLANATION, + [LIST_VIEW_GROUP_FIELD_UNGROUPABLE_EXPLANATION.rule]: LIST_VIEW_GROUP_FIELD_UNGROUPABLE_EXPLANATION, [LIST_VIEW_SUMMARY_FIELD_TYPE_REFUSED_EXPLANATION.rule]: LIST_VIEW_SUMMARY_FIELD_TYPE_REFUSED_EXPLANATION, [LIST_VIEW_CHART_DATASET_FOREIGN_OBJECT_EXPLANATION.rule]: LIST_VIEW_CHART_DATASET_FOREIGN_OBJECT_EXPLANATION, [LIST_VIEW_KANBAN_LANE_UNKNOWN_EXPLANATION.rule]: LIST_VIEW_KANBAN_LANE_UNKNOWN_EXPLANATION, diff --git a/packages/lint/src/validate-list-view-field-refs.group-field-38433.test.ts b/packages/lint/src/validate-list-view-field-refs.group-field-38433.test.ts new file mode 100644 index 00000000000..9acdee9c9f0 --- /dev/null +++ b/packages/lint/src/validate-list-view-field-refs.group-field-38433.test.ts @@ -0,0 +1,166 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +// [#38433] A list view `grouping.fields[].field` naming a field the engine +// does not group by. The grouping compiles to the group header query +// (`compileListViewGroupQuery`), whose `groupBy` `engine.aggregate` refuses +// with `400 INVALID_FIELD` over a multi-value or structured-JSON field +// (`assertGroupByNamesNoJsonStoredField`) and over a `formula` field +// (`assertGroupByTargetsAreStored`). The rule asks the same spec predicates, +// so each class is pinned here from the predicate the engine door reads. + +import { describe, expect, it } from 'vitest'; + +import { STRUCTURED_JSON_TYPES, isMultiValueField, isVirtualSearchField } from '@objectstack/spec/data'; +import { ListViewSchema } from '@objectstack/spec/ui'; + +import { runAuthoringRules, splitBySeverity } from './authoring-rules.js'; +import { explainRule } from './rule-explanations.js'; +import { runRuntimeAuthoringRules } from './runtime-gate.js'; +import { + LIST_VIEW_GROUP_FIELD_UNGROUPABLE, + validateListViewFieldRefs, +} from './validate-list-view-field-refs.js'; + +type AnyRec = Record; + +const OBJECTS = [ + { + name: 'grp_task', + label: 'Task', + fields: [ + { name: 'title', type: 'text', label: 'Title' }, + { name: 'status', type: 'select', label: 'Status', options: [{ value: 'open', label: 'Open' }] }, + { name: 'labels', type: 'multiselect', label: 'Labels', options: [{ value: 'a', label: 'A' }] }, + { name: 'owners', type: 'lookup', reference: 'grp_account', multiple: true, label: 'Owners' }, + { name: 'account', type: 'lookup', reference: 'grp_account', label: 'Account' }, + { name: 'meta', type: 'json', label: 'Meta' }, + { name: 'score', type: 'formula', label: 'Score' }, + ], + }, + { + name: 'grp_account', + label: 'Account', + fields: [ + { name: 'name', type: 'text', label: 'Name' }, + { name: 'tags', type: 'tags', label: 'Tags' }, + ], + }, +]; + +const groupedBy = (field: string): AnyRec => ({ + name: 'all', + type: 'grid', + data: { provider: 'object', object: 'grp_task' }, + columns: ['title'], + grouping: { fields: [{ field }] }, +}); + +const stackWith = (listView: AnyRec): AnyRec => ({ + name: 'probe', + objects: OBJECTS, + views: [{ name: 'grp_task', object: 'grp_task', list: listView }], +}); + +const ungroupable = (field: string) => + validateListViewFieldRefs(stackWith(groupedBy(field))).filter((f) => f.rule === LIST_VIEW_GROUP_FIELD_UNGROUPABLE); + +const declared = (name: string) => + OBJECTS.flatMap((o) => o.fields as AnyRec[]).find((f) => f.name === name) as { type: string; multiple?: boolean }; + +describe('[#38433] a list view grouped by a field the engine does not group by', () => { + it.each([ + ['a multi-value field', 'labels', () => isMultiValueField(declared('labels') as never)], + ['a multi-value reference (`multiple: true` lookup)', 'owners', () => isMultiValueField(declared('owners') as never)], + ['a structured-JSON field', 'meta', () => STRUCTURED_JSON_TYPES.has(declared('meta').type)], + ['a formula field', 'score', () => isVirtualSearchField(declared('score') as never)], + ])('refuses %s, as the engine door\'s own predicate does', (_label, field, enginePredicate) => { + expect(enginePredicate(), 'the engine door refuses this declaration').toBe(true); + const findings = ungroupable(field); + expect(findings.map((f) => [f.rule, f.severity, f.where, f.path])).toEqual([ + [LIST_VIEW_GROUP_FIELD_UNGROUPABLE, 'error', 'view "grp_task" › list › grouping', 'views[0].list.grouping.fields[0].field'], + ]); + expect(findings[0].message).toContain('400 INVALID_FIELD'); + // The fix holds: a grid column, or a grouping the engine accepts — never a + // grid grouping on this field. + expect(findings[0].hint).toContain(`Show "${field}" as a grid column`); + expect(findings[0].hint).not.toContain('grid grouping'); + for (const line of [findings[0].message, findings[0].hint]) { + expect(line).not.toContain('\n'); + expect(line.length, line).toBeLessThanOrEqual(200); + } + }); + + it.each([ + ['a single-valued select', 'status'], + ['a text field', 'title'], + ['a single-valued lookup', 'account'], + ])('CONTROL — %s, stored and single-valued, is quiet', (_label, field) => { + expect(ungroupable(field)).toEqual([]); + expect(validateListViewFieldRefs(stackWith(groupedBy(field)))).toEqual([]); + }); + + it('a dotted name is not this verdict: the engine refuses every dotted groupBy name on its own ground, multi-valued leaf or not', () => { + // `account.tags` ends on a `tags` field, `account.name` on a text one; the + // engine's dotted-name branch refuses both alike, so the storage class of + // the leaf is not what the engine judges there. + expect(ungroupable('account.tags')).toEqual([]); + expect(ungroupable('account.name')).toEqual([]); + }); + + // [M1 of the contract review] Only a grid sends its grouping to + // `engine.aggregate` (objectui's `ListView.tsx` asks the group header query + // under `currentView === 'grid'` alone). A gallery groups the cards it + // fetched; a kanban board keeps drawing its cards when its swimlane count + // read is refused; calendar, timeline, gantt and map do not read grouping. + it('an absent `type` is a grid, the schema\'s default, and is judged', () => { + const parsed = ListViewSchema.safeParse({ columns: ['title'] }); + expect(parsed.success && (parsed.data as { type?: unknown }).type).toBe('grid'); + const { type: _type, ...untyped } = groupedBy('labels'); + const findings = validateListViewFieldRefs(stackWith(untyped)).filter((f) => f.rule === LIST_VIEW_GROUP_FIELD_UNGROUPABLE); + expect(findings.map((f) => [f.severity, f.path])).toEqual([['error', 'views[0].list.grouping.fields[0].field']]); + }); + + it.each(['kanban', 'gallery', 'calendar', 'timeline', 'gantt', 'map'])( + 'CONTROL — a `%s` list view is not judged: its grouping does not reach the engine', + (type) => { + for (const field of ['labels', 'owners', 'meta', 'score']) { + const findings = validateListViewFieldRefs(stackWith({ ...groupedBy(field), type })) + .filter((f) => f.rule === LIST_VIEW_GROUP_FIELD_UNGROUPABLE); + expect(findings, `${type} grouped by ${field}`).toEqual([]); + } + }, + ); + + it('a name that resolves to nothing stays `list-view-field-unknown`', () => { + expect(ungroupable('nope')).toEqual([]); + }); + + it('judges every level of a multi-level grouping', () => { + const listView = { ...groupedBy('status'), grouping: { fields: [{ field: 'status' }, { field: 'score' }] } }; + const findings = validateListViewFieldRefs(stackWith(listView)).filter((f) => f.rule === LIST_VIEW_GROUP_FIELD_UNGROUPABLE); + expect(findings.map((f) => f.path)).toEqual(['views[0].list.grouping.fields[1].field']); + }); + + for (const command of ['validate', 'build'] as const) { + it(`fails \`${command}\``, () => { + const { errors } = splitBySeverity(runAuthoringRules(command, { normalized: stackWith(groupedBy('labels')) })); + expect(errors.map((f) => f.rule)).toContain(LIST_VIEW_GROUP_FIELD_UNGROUPABLE); + }); + } + + it('is refused at the runtime `view` save door, and admitted once the grouping names a stored single-valued field', () => { + const item = (field: string) => ({ name: 'grp_task', object: 'grp_task', list: groupedBy(field) }); + const refused = runRuntimeAuthoringRules({ type: 'view', item: item('meta'), context: { objects: OBJECTS } }); + expect(refused.errors.map((f) => [f.rule, f.severity])).toEqual([[LIST_VIEW_GROUP_FIELD_UNGROUPABLE, 'error']]); + expect(refused.errors[0].path).toMatch(/grouping\.fields\[0\]\.field$/); + const clean = runRuntimeAuthoringRules({ type: 'view', item: item('status'), context: { objects: OBJECTS } }); + expect(clean.errors).toEqual([]); + }); + + it('`os explain` carries the reasoning and the fix', () => { + const text = explainRule(LIST_VIEW_GROUP_FIELD_UNGROUPABLE)!.paragraphs.join('\n'); + for (const fact of ['400 INVALID_FIELD', 'grid column', 'stored single-valued field', '`list-view-field-unknown`']) { + expect(text, fact).toContain(fact); + } + }); +}); diff --git a/packages/lint/src/validate-list-view-field-refs.ts b/packages/lint/src/validate-list-view-field-refs.ts index 2cfed8e597e..ece52e66551 100644 --- a/packages/lint/src/validate-list-view-field-refs.ts +++ b/packages/lint/src/validate-list-view-field-refs.ts @@ -332,6 +332,36 @@ * nothing is judged at `orderBy` there: the `field` position already judges * the name. * + * ## [#38433] `grouping.fields[].field` — a field the engine does not group by + * + * {@link LIST_VIEW_GROUP_FIELD_UNGROUPABLE}, `error`. The grouping field is + * one `groupBy` column of the same group header query, and `engine.aggregate` + * refuses a `groupBy` over three classes of declared field, `400 + * INVALID_FIELD`, before any driver is asked: + * + * - a multi-value field (`multiselect`, `checkboxes`, `tags`, a `multiple` + * select or reference) and a structured-JSON field (`json`, `composite`, + * `address`, …): `assertGroupByNamesNoJsonStoredField`, which asks the + * spec's `STRUCTURED_JSON_TYPES` and `isMultiValueField`; + * - a field computed on read (`formula`): `assertGroupByTargetsAreStored`, + * which asks the spec's `isVirtualSearchField`. + * + * So a grid list view grouped by one saves and publishes, then opens on that + * error and renders no group. Judged on a `grid` and on a list view with no + * `type` (the schema's default is `grid`) only, the kinds whose grouping is + * sent as that query ({@link groupingReachesAggregate}); every other kind + * (`kanban`, `gallery`, `calendar`, `timeline`, `gantt`, `map`, `chart`, + * `tree`, `timesheet`) is not judged. The verdict asks + * those same three predicates + * ({@link groupByRefusedClass}, which the kanban hint above reads too), ⛔ + * never a type list of its own, so the linter refuses exactly the set the + * engine refuses. Judged at an undotted name whose declaration resolves with + * a readable type. Not judged here: an unknown name + * ({@link LIST_VIEW_FIELD_UNKNOWN}), and a dotted name — the engine refuses + * every dotted `groupBy` name on its own ground (a path, whatever the head + * or the leaf), not by the storage class of the field it ends on, so this + * verdict does not speak for it. + * * ## [#32449] `columns[].summary` — a function the aggregate door refuses * * A column summary is not a renderer binding either: it reaches @@ -575,6 +605,49 @@ export const LIST_VIEW_FIELD_DOTTED = 'list-view-field-dotted'; */ export const LIST_VIEW_GROUP_ORDER_UNORDERABLE = 'list-view-group-order-unorderable'; +/** + * [#38433] A grouping level of a `grid` list view whose `field` names a field + * `engine.aggregate` does not group by — a multi-value, a structured-JSON or a + * `formula` field — so the grid's group header query answers `400 + * INVALID_FIELD` and no group renders. See the section of that name on this + * module. + */ +export const LIST_VIEW_GROUP_FIELD_UNGROUPABLE = 'list-view-group-field-ungroupable'; + +/** + * [#38433] Does this list view's `grouping` reach `engine.aggregate`? Only a + * `grid` sends it as the group header query (objectui's `ListView.tsx` asks + * the header query only under `currentView === 'grid'`), and an absent `type` + * is a grid: `ListViewSchema`'s `type` defaults to `'grid'`. Every other kind + * reads `grouping` in the browser or not at all: a gallery buckets the cards + * it fetched, a kanban board takes `grouping.fields[0]` as its swimlane + * fallback and, when its one grouped count read is refused, keeps drawing its + * cards with page counts, and calendar, timeline, gantt and map do not read + * it. No other kind was measured to send it. So the grouping verdict is + * judged on a grid alone. + */ +function groupingReachesAggregate(listView: AnyRec): boolean { + return listView.type === undefined || listView.type === 'grid'; +} + +/** + * [#38433] Why `engine.aggregate` refuses a `groupBy` over a field with this + * declaration, in an author's words, or `null` where it groups by it. The + * engine's two doors' own spec predicates — `STRUCTURED_JSON_TYPES` and + * `isMultiValueField` (`assertGroupByNamesNoJsonStoredField`), then + * `isVirtualSearchField` (`assertGroupByTargetsAreStored`) — ⛔ never a type + * list of this file's. Read by the grouping verdict and by the kanban hint, + * which offers a grid grouping only where this answers `null`. + */ +function groupByRefusedClass(meta: { type?: string; multiple?: boolean } | undefined): string | null { + const type = meta?.type; + if (typeof type !== 'string') return null; + if (STRUCTURED_JSON_TYPES.has(type)) return 'a JSON-stored field'; + if (isMultiValueField({ type, multiple: meta?.multiple === true } as never)) return 'a multi-valued field'; + if (isVirtualSearchField({ type } as never)) return 'a field computed on read'; + return null; +} + /** * [#32449] A column summary whose function the engine's aggregate door * refuses over the aggregated field's declaration — `sum` / `avg` over a @@ -1477,12 +1550,9 @@ export function validateListViewFieldRefs( // which refuses a `groupBy` over a multi-value or structured-JSON field // (`assertGroupByNamesNoJsonStoredField`) and over a virtual `formula` // field (`assertGroupByTargetsAreStored`), `400 INVALID_FIELD`. Those three - // classes, read from the same spec predicates, get a grid column instead. - const ungroupable = multi - ? 'a multi-valued field' - : STRUCTURED_JSON_TYPES.has(type) - ? 'a JSON-stored field' - : isVirtualSearchField({ type } as never) ? 'a field computed on read' : null; + // classes, read from the same spec predicates, get a grid column instead + // (the verdict `list-view-group-field-ungroupable` gives such a grouping). + const ungroupable = groupByRefusedClass(verdict.meta); const gridRemedy = ungroupable === null ? `show "${groupBy}" as a grid grouping` : `show "${groupBy}" as a grid column (a list cannot be grouped by ${ungroupable})`; @@ -1616,6 +1686,37 @@ export function validateListViewFieldRefs( }); }; + /** + * [#38433] One `grouping.fields[]` entry's `field` — see the section of that + * name on this module: a declared field `engine.aggregate` does not group by. + */ + const checkGroupField = ( + listView: AnyRec, + entry: AnyRec, + object: string, + where: string, + path: string, + subject: string, + ): void => { + if (!groupingReachesAggregate(listView)) return; + const written = strName(entry.field); + if (!written || written.includes('.')) return; + const verdict = resolveFieldPath(graph, object, written); + if (!verdict || verdict.kind !== 'ok') return; + const refused = groupByRefusedClass(verdict.meta); + if (refused === null) return; + findings.push({ + severity: 'error', + rule: LIST_VIEW_GROUP_FIELD_UNGROUPABLE, + where, + path, + message: + `${subject} "${written}" is ${refused} (\`${verdict.meta?.type}\`), which the engine does not group by: ` + + "the grid's group header query answers 400 INVALID_FIELD and no group renders", + hint: `Show "${written}" as a grid column, or group by a stored single-valued field of "${object}"`, + }); + }; + /** * [#32449] One `columns[]` entry's `summary` — see the section of that name * on this module: the member's function over the aggregated field's @@ -1722,6 +1823,7 @@ export function validateListViewFieldRefs( check(entry.field, bound, severity, hostWhere, `${entryPath}.field`, `${key}[${i}].field`, axis); // [#25786] The keys a `grouping.fields[]` entry carries beside `field`. if (block === 'grouping' && key === 'fields') { + checkGroupField(listView, entry, bound, hostWhere, `${entryPath}.field`, `${key}[${i}].field`); for (const nested of GROUPING_ENTRY_POSITIONS) { checkGroupOrder(entry, nested, bound, hostWhere, `${entryPath}.${nested.key}`, `${key}[${i}].${nested.key}`); } diff --git a/packages/spec/src/migrations/entries/semantic/19.publish-refuses-list-view-grouping-the-engine-does-not-group-by.ts b/packages/spec/src/migrations/entries/semantic/19.publish-refuses-list-view-grouping-the-engine-does-not-group-by.ts new file mode 100644 index 00000000000..b694399da45 --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/19.publish-refuses-list-view-grouping-the-engine-does-not-group-by.ts @@ -0,0 +1,28 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// The upgrade-guide entry of the list-view grouping refusal (#38433): a grid +// list view's `grouping.fields[].field` the schema still accepts but the engine +// refuses to group by, refused at publish and in `os validate` / `build`. Notice only: no +// key is removed and no D2 conversion exists, because the fix is a choice only +// the author can make (which stored field to group by, or a column instead). +export const entry: SemanticMigration = { + id: 'publish-refuses-list-view-grouping-the-engine-does-not-group-by', + surface: + 'One author-time error, run by `os validate` / `lint` / `compile` / `build`: a `grid` list view (or one with no ' + + '`type`, which defaults to `grid`) whose `grouping.fields[].field` names a multi-valued field (`multiselect`, ' + + '`checkboxes`, `tags`, or a `multiple` select or reference), a JSON-stored field (`json`, `address`, ' + + '`composite` and the like) or a `formula` field (`list-view-group-field-ungroupable`, also refused by the ' + + 'runtime publish gate on a `view` or `object` write). Other list-view kinds are not judged', + replacement: + 'Group by a stored single-valued field (a single-valued `select`, a boolean, a single-valued lookup, or a text, ' + + 'number or date field), or show the field as a grid column instead', + reason: + 'The grouping parses and publishes, then shows nothing: a grid sends its grouping as the group header query, ' + + 'which the engine refuses for such a field (400 INVALID_FIELD), so the grid opens on that error and renders no ' + + 'group. Stored metadata is not rewritten or refused at boot. The next publish of a view or object carrying such ' + + 'a grid grouping is refused with the fix named.', + acceptanceCriteria: + 'os validate reports no list-view-group-field-ungroupable error; a publish of every view and object the package carries succeeds.', +};