Skip to content
Merged
23 changes: 23 additions & 0 deletions .changeset/38433-list-view-group-field-ungroupable.md
Original file line number Diff line number Diff line change
@@ -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

<!-- adr-0087: registered publish-refuses-list-view-grouping-the-engine-does-not-group-by -->

**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`.
2 changes: 1 addition & 1 deletion content/docs/deployment/validating-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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) | ✓ | ✓ | ✓ | ✓ᶠʳᵛᵒ |
Expand Down
2 changes: 2 additions & 0 deletions packages/lint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions packages/lint/src/rule-explanations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -7438,6 +7460,7 @@ export const RULE_EXPLANATIONS: Readonly<Record<string, RuleExplanation>> = 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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string, unknown>;

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);
}
});
});
Loading
Loading