Skip to content

Commit d042837

Browse files
fix(lint)!: refuse a list view grouped by a field the engine does not group by (#38651)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9JeHmqv6CKCkW8ewrPBLekk)_ Refs #38433 (item 3) Clause-②: no (narrowing) Metadata-protocol: narrowed Skills-docs: follow-up #38655 ## 维护者速读 - 作者在命令行校验或在设计器保存表格列表视图时,若按多值字段、JSON 字段或公式字段分组,会被直接拒绝并给出改法;看板、日历等其它视图不受影响,运行中的用户无感。 - 属于「发布时拦下保存成功却用不了的元数据」这一组检查,补上看板分组提示修复之后剩下的一项,替作者在发布前发现一打开就报错的列表。 - 碰到的是已经这样分组的表格视图作者,下次保存会被拒(这样的视图本来一打开就报错,平台自带的视图无一受影响);撤回本合并即可恢复原状。 - 无 ## What changes Item 3 of the card. Items 1, 2 and 4 landed in PR #38635. - New lint finding `list-view-group-field-ungroupable` (`error`) in `validateListViewFieldRefs`. It fires when a grid list view's `grouping.fields[].field` (a view whose `type` is `grid`, or absent, since the schema defaults it to `grid`) names a multi-valued field (`multiselect`, `checkboxes`, `tags`, or a `multiple` select or reference), a structured-JSON field (`json`, `address`, `composite`, …) or a `formula` field. The grouping compiles to the group header query (`compileListViewGroupQuery`), and `engine.aggregate` refuses a `groupBy` over each of these with `400 INVALID_FIELD`. Until now such a view saved and published, then opened on that error. - Other list-view kinds are not judged: `kanban`, `gallery`, `calendar`, `timeline`, `gantt`, `map`, `chart`, `tree`, `timesheet`. The list view asks the group header query only when it renders as a grid. Kanban was measured: it reads `grouping.fields[0].field` as its swimlane fallback, asks that read only when the board is windowed, and on a refusal drops the lanes and keeps drawing its cards. It does not break, so it stays quiet here. - The finding runs wherever this rule function already runs: `os validate` / `lint` / `compile` / `build`, and the runtime save door on `view` and `object` writes. `runtimeTypes` is unchanged. - The refused set comes from one helper, `groupByRefusedClass`. It asks the spec predicates the engine's two doors ask: - `STRUCTURED_JSON_TYPES` and `isMultiValueField`, asked by `assertGroupByNamesNoJsonStoredField` (`packages/objectql/src/group-by-structured-json-door.ts:130-132`, called at `engine-delete-and-aggregate.ts:1086`); - `isVirtualSearchField`, asked by `assertGroupByTargetsAreStored` (`aggregate-query-shape-door.ts:249`, called at `:1120`). - The kanban hint from PR #38635 now calls the same helper, so there is no second type list. - The hint prescribes a fix the engine accepts: show the field as a grid column, or group by a stored single-valued field. - The rule refuses exactly the three storage classes the engine refuses. Not judged by this finding: an unknown name (`list-view-field-unknown`) and a dotted name. The engine refuses a dotted name on another ground (`aggregate-query-shape-door.ts:231`), which this verdict does not report (#38654). - Also in this PR: - an `os explain` entry, with its barrel export `LIST_VIEW_GROUP_FIELD_UNGROUPABLE`; - the `validating-metadata.mdx` row; - the ADR-0087 semantic entry `publish-refuses-list-view-grouping-the-engine-does-not-group-by` (`@objectstack/spec` patch); - a minor changeset for `@objectstack/lint` with a BREAKING banner and FROM → TO. First-party impact, measured: 7 first-party list views declare a grouping, in `packages/platform-objects` and `plugin-approvals`. Every one groups by a stored single-valued text, select or lookup field, and running the new rule over them gives 0 findings. `examples/**` and `packages/apps/**` declare no grouping. Contract face: the lint rule's accept set narrows. This PR stays draft for the CONTRACT_REVIEW_TIER review the seat routes. ## Read first 1. `packages/lint/src/validate-list-view-field-refs.ts`: `groupByRefusedClass` and `checkGroupField`. `groupByRefusedClass` is the refusal set (the engine's three storage classes); `groupingReachesAggregate` is the kind gate (grid or absent `type`). 2. `packages/spec/src/migrations/entries/semantic/19.publish-refuses-list-view-grouping-the-engine-does-not-group-by.ts`: the upgrade-guide text. 3. `.changeset/38433-list-view-group-field-ungroupable.md`: the BREAKING banner and FROM → TO. ## Two-minute check `pnpm --filter @objectstack/lint exec vitest run src/validate-list-view-field-refs.group-field-38433.test.ts`: 21 passed. ## Tests New file `packages/lint/src/validate-list-view-field-refs.group-field-38433.test.ts`, 21 cases: - one refused case per engine-refused class: `multiselect`, a `multiple` lookup, `json` and `formula`. Each asserts the rule id, `severity: error`, `where` and `path`, and first checks the engine predicate for that declaration; - controls that stay quiet: a single-valued select, a text field and a single-valued lookup; - a dotted case (`account.tags`, `account.name`) that stays quiet; - an unknown name and a multi-level grouping; - `validate` and `build` fail; - a runtime `view` save-door case through `runRuntimeAuthoringRules`: refused on `json`, admitted on `status`; - the `os explain` entry; - an untyped list view: `ListViewSchema` parses an absent `type` to `grid`, and the rule judges it; - quiet controls for `kanban`, `gallery`, `calendar`, `timeline`, `gantt` and `map` list views grouped by every refused class. <details><summary>Readings</summary> - Head 63018a1 (origin/main f5da514 is its merge base). - New file plus the sibling suites `validate-list-view-field-refs.test.ts`, `validate-list-view-kanban-lanes.test.ts` and `rule-explanations.test.ts`: Test Files 4 passed (4), Tests 274 passed (274). - `packages/spec/src/migrations`: Test Files 5 passed, Tests 209 passed. - `pnpm --filter @objectstack/lint typecheck`: `VERDICT command-exit 0`. - Whole `@objectstack/lint` suite, at 410314f, before the merge and before the kind gate: Test Files 247 passed (247), Tests 9977 passed, 5 skipped. Not re-run at this head. - Ablation 1, `scripts/ablation-replace.mjs --delete` of the kind gate (`if (!groupingReachesAggregate(listView)) return;`): anchor 1 to 0, blob ece52e6 to c7376add4dc5. 6 failed: the six kind controls. 15 passed. After the restore the blob equals HEAD and `git diff HEAD` is empty. - Ablation 2, `--delete` of the `checkGroupField` call: anchor 1 to 0, blob ece52e6 to 12f0dde9d8bf. 9 failed: the four refused classes, the untyped view, multi-level, validate, build and the save door. 12 passed. Restored the same way; the tree is clean. </details> ## Verification <details><summary>Gates on 63018a1</summary> - `node scripts/check-changeset-no-major.mjs --base origin/main --event EVENT` (EVENT built from a live read of this PR): exit 0. - `node scripts/check-adr-0087-registration.mjs --base origin/main`, same event: exit 0. `registered publish-refuses-list-view-grouping-the-engine-does-not-group-by`, `1 migration entry added, each at or above PROTOCOL_MAJOR 19`. - After a spec build under the lock: `check:spec-changes` exit 0 (`aggregate 118 converted / 691 migrated`), `check:upgrade-guide` exit 0, `check:docs` exit 0. - `check:doc-authoring`, `check:issue-citations`, `check:nul-bytes`: exit 0. - `node scripts/pm/overlap-check.mjs --branch=HEAD`: `VERDICT clean exit 0`; the push was gated on it. - The rest of the derived family set is left to CI. At db3d5ec, before the merge, 64 of 70 derived families exited 0 locally; the other 6 were NOT MEASURED (a prerequisite not met, or my per-gate timeout). - Full dogfood battery: run at b7e76b2 (Test Files 495 passed, 3 skipped; Tests 4187 passed, 68 skipped). NOT MEASURED at 63018a1, reason: not re-run for this round. </details> ## Acceptance notes - A dotted grouping field (`account.name`, `account.tags`) still passes `os validate`. `grouping.fields` has no dotted-axis row in this rule, while `engine.aggregate` refuses every undeclared dotted `groupBy` name with `400 INVALID_FIELD`. It is filed as #38654 and is not widened here. - The Grouping section of `skills/objectstack-ui/rules/list-views.md` should name this refusal. That is follow-up #38655. - AGENTS.md puts a new pin for a component with a shared harness file into that file (ruling record 6583487846). The dispatch ordered a new file named for the card, which this PR follows. The conflict is flagged here. --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B)_ <!-- signed: repo:objectstack#3 · os-steve · session_01ADHkmSwS4mQyXWrddL4r6B --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4d5cfa9 commit d042837

7 files changed

Lines changed: 351 additions & 7 deletions
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
'@objectstack/lint': minor
3+
'@objectstack/spec': patch
4+
---
5+
6+
fix(lint)!: refuse a list view grouped by a field the engine does not group by
7+
8+
Clause-②: no (narrowing)
9+
Metadata-protocol: narrowed
10+
Skills-docs: follow-up #38655
11+
12+
<!-- adr-0087: registered publish-refuses-list-view-grouping-the-engine-does-not-group-by -->
13+
14+
**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`.
15+
16+
- `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`).
17+
18+
## FROM → TO
19+
20+
- 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`.
21+
- 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']`).
22+
23+
`@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`.

‎content/docs/deployment/validating-metadata.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ orthogonal to both, and no cell here can carry it; it is written out in
508508
| Empty filter combinators — `$and: []`, `$or: []`, `$not: {}` (#5330) | ✓ | ✓ | ✓ | ✓ᶠʳ |
509509
| 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) | ✓ | ✓ | ✓ | ✓ᶠᵈᵗᵃᶜ |
510510
| 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) | ✓ | ✓ | ✓ | ✓ᶠᵛᵒᵈᵗʳᵖᵃᶜᵗ |
511-
| 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) | ✓ | ✓ | ✓ | ✓ᶠᵛᵒᵖ |
511+
| 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) | ✓ | ✓ | ✓ | ✓ᶠᵛᵒᵖ |
512512
| Page-component field bindings (#3583) | ✓ | ✓ | ✓ | ✓ᶠ |
513513
| React page block field bindings — §10 (#4340) | ✓ | ✓ | ✓ | ✓ᶠ |
514514
| Chart bindings outside dashboards (#3583) | ✓ | ✓ | ✓ | ✓ᶠʳᵛᵒ |

‎packages/lint/src/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ export {
719719
LIST_VIEW_FIELD_UNKNOWN,
720720
LIST_VIEW_FIELD_DOTTED,
721721
LIST_VIEW_GROUP_ORDER_UNORDERABLE,
722+
// [#38433] A grouping level over a field the engine does not group by.
723+
LIST_VIEW_GROUP_FIELD_UNGROUPABLE,
722724
LIST_VIEW_SUMMARY_FIELD_TYPE_REFUSED,
723725
LIST_VIEW_CHART_DATASET_FOREIGN_OBJECT,
724726
LIST_VIEW_KANBAN_LANE_UNKNOWN,

‎packages/lint/src/rule-explanations.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4497,6 +4497,28 @@ const LIST_VIEW_GROUP_ORDER_UNORDERABLE_EXPLANATION: RuleExplanation = {
44974497
],
44984498
};
44994499

4500+
const LIST_VIEW_GROUP_FIELD_UNGROUPABLE_EXPLANATION: RuleExplanation = {
4501+
rule: 'list-view-group-field-ungroupable',
4502+
covers: 'which fields a grid list view can be grouped by',
4503+
paragraphs: [
4504+
'A grid list view sends its grouping to the engine as one aggregate: each grouping level\'s `field` is one ' +
4505+
'`groupBy` column of the group header query. The engine refuses to group by three kinds of field ' +
4506+
'(`400 INVALID_FIELD`), before any database is asked: a multi-valued field (`multiselect`, `checkboxes`, ' +
4507+
'`tags`, or a `multiple` select or reference), a JSON-stored field (`json`, `address`, `composite` and the ' +
4508+
'like), and a `formula` field, which is computed on read and stores no column. A grid grouped by one saves ' +
4509+
'and publishes, then opens on that error and renders no group.',
4510+
'An error, so the publish is refused and `os validate` and `os build` fail. The verdict asks the same spec ' +
4511+
'predicates the engine asks, so it refuses exactly the three storage classes the engine refuses. A dotted ' +
4512+
'name is refused by the engine on another ground, which this verdict does not report. Judged on a list view ' +
4513+
'whose `type` is `grid` or absent (the default is `grid`); any other kind is not judged, because none was ' +
4514+
'measured to send its grouping to the engine: a gallery groups the cards it fetched, and a kanban board ' +
4515+
'keeps drawing its cards when its grouped count read is refused. Not judged either: a name that resolves ' +
4516+
'to nothing (`list-view-field-unknown`) and a field whose type is not readable.',
4517+
'To fix it, show the field as a grid column, or group by a stored single-valued field: a single-valued ' +
4518+
'`select`, a boolean, a single-valued lookup, or a text, number or date field.',
4519+
],
4520+
};
4521+
45004522
const LIST_VIEW_SUMMARY_FIELD_TYPE_REFUSED_EXPLANATION: RuleExplanation = {
45014523
rule: 'list-view-summary-field-type-refused',
45024524
covers: 'which functions a column summary can apply to its field',
@@ -7442,6 +7464,7 @@ export const RULE_EXPLANATIONS: Readonly<Record<string, RuleExplanation>> = Obje
74427464
[LIST_VIEW_FIELD_UNKNOWN_EXPLANATION.rule]: LIST_VIEW_FIELD_UNKNOWN_EXPLANATION,
74437465
[LIST_VIEW_FIELD_DOTTED_EXPLANATION.rule]: LIST_VIEW_FIELD_DOTTED_EXPLANATION,
74447466
[LIST_VIEW_GROUP_ORDER_UNORDERABLE_EXPLANATION.rule]: LIST_VIEW_GROUP_ORDER_UNORDERABLE_EXPLANATION,
7467+
[LIST_VIEW_GROUP_FIELD_UNGROUPABLE_EXPLANATION.rule]: LIST_VIEW_GROUP_FIELD_UNGROUPABLE_EXPLANATION,
74457468
[LIST_VIEW_SUMMARY_FIELD_TYPE_REFUSED_EXPLANATION.rule]: LIST_VIEW_SUMMARY_FIELD_TYPE_REFUSED_EXPLANATION,
74467469
[LIST_VIEW_CHART_DATASET_FOREIGN_OBJECT_EXPLANATION.rule]: LIST_VIEW_CHART_DATASET_FOREIGN_OBJECT_EXPLANATION,
74477470
[LIST_VIEW_KANBAN_LANE_UNKNOWN_EXPLANATION.rule]: LIST_VIEW_KANBAN_LANE_UNKNOWN_EXPLANATION,
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
// [#38433] A list view `grouping.fields[].field` naming a field the engine
4+
// does not group by. The grouping compiles to the group header query
5+
// (`compileListViewGroupQuery`), whose `groupBy` `engine.aggregate` refuses
6+
// with `400 INVALID_FIELD` over a multi-value or structured-JSON field
7+
// (`assertGroupByNamesNoJsonStoredField`) and over a `formula` field
8+
// (`assertGroupByTargetsAreStored`). The rule asks the same spec predicates,
9+
// so each class is pinned here from the predicate the engine door reads.
10+
11+
import { describe, expect, it } from 'vitest';
12+
13+
import { STRUCTURED_JSON_TYPES, isMultiValueField, isVirtualSearchField } from '@objectstack/spec/data';
14+
import { ListViewSchema } from '@objectstack/spec/ui';
15+
16+
import { runAuthoringRules, splitBySeverity } from './authoring-rules.js';
17+
import { explainRule } from './rule-explanations.js';
18+
import { runRuntimeAuthoringRules } from './runtime-gate.js';
19+
import {
20+
LIST_VIEW_GROUP_FIELD_UNGROUPABLE,
21+
validateListViewFieldRefs,
22+
} from './validate-list-view-field-refs.js';
23+
24+
type AnyRec = Record<string, unknown>;
25+
26+
const OBJECTS = [
27+
{
28+
name: 'grp_task',
29+
label: 'Task',
30+
fields: [
31+
{ name: 'title', type: 'text', label: 'Title' },
32+
{ name: 'status', type: 'select', label: 'Status', options: [{ value: 'open', label: 'Open' }] },
33+
{ name: 'labels', type: 'multiselect', label: 'Labels', options: [{ value: 'a', label: 'A' }] },
34+
{ name: 'owners', type: 'lookup', reference: 'grp_account', multiple: true, label: 'Owners' },
35+
{ name: 'account', type: 'lookup', reference: 'grp_account', label: 'Account' },
36+
{ name: 'meta', type: 'json', label: 'Meta' },
37+
{ name: 'score', type: 'formula', label: 'Score' },
38+
],
39+
},
40+
{
41+
name: 'grp_account',
42+
label: 'Account',
43+
fields: [
44+
{ name: 'name', type: 'text', label: 'Name' },
45+
{ name: 'tags', type: 'tags', label: 'Tags' },
46+
],
47+
},
48+
];
49+
50+
const groupedBy = (field: string): AnyRec => ({
51+
name: 'all',
52+
type: 'grid',
53+
data: { provider: 'object', object: 'grp_task' },
54+
columns: ['title'],
55+
grouping: { fields: [{ field }] },
56+
});
57+
58+
const stackWith = (listView: AnyRec): AnyRec => ({
59+
name: 'probe',
60+
objects: OBJECTS,
61+
views: [{ name: 'grp_task', object: 'grp_task', list: listView }],
62+
});
63+
64+
const ungroupable = (field: string) =>
65+
validateListViewFieldRefs(stackWith(groupedBy(field))).filter((f) => f.rule === LIST_VIEW_GROUP_FIELD_UNGROUPABLE);
66+
67+
const declared = (name: string) =>
68+
OBJECTS.flatMap((o) => o.fields as AnyRec[]).find((f) => f.name === name) as { type: string; multiple?: boolean };
69+
70+
describe('[#38433] a list view grouped by a field the engine does not group by', () => {
71+
it.each([
72+
['a multi-value field', 'labels', () => isMultiValueField(declared('labels') as never)],
73+
['a multi-value reference (`multiple: true` lookup)', 'owners', () => isMultiValueField(declared('owners') as never)],
74+
['a structured-JSON field', 'meta', () => STRUCTURED_JSON_TYPES.has(declared('meta').type)],
75+
['a formula field', 'score', () => isVirtualSearchField(declared('score') as never)],
76+
])('refuses %s, as the engine door\'s own predicate does', (_label, field, enginePredicate) => {
77+
expect(enginePredicate(), 'the engine door refuses this declaration').toBe(true);
78+
const findings = ungroupable(field);
79+
expect(findings.map((f) => [f.rule, f.severity, f.where, f.path])).toEqual([
80+
[LIST_VIEW_GROUP_FIELD_UNGROUPABLE, 'error', 'view "grp_task" › list › grouping', 'views[0].list.grouping.fields[0].field'],
81+
]);
82+
expect(findings[0].message).toContain('400 INVALID_FIELD');
83+
// The fix holds: a grid column, or a grouping the engine accepts — never a
84+
// grid grouping on this field.
85+
expect(findings[0].hint).toContain(`Show "${field}" as a grid column`);
86+
expect(findings[0].hint).not.toContain('grid grouping');
87+
for (const line of [findings[0].message, findings[0].hint]) {
88+
expect(line).not.toContain('\n');
89+
expect(line.length, line).toBeLessThanOrEqual(200);
90+
}
91+
});
92+
93+
it.each([
94+
['a single-valued select', 'status'],
95+
['a text field', 'title'],
96+
['a single-valued lookup', 'account'],
97+
])('CONTROL — %s, stored and single-valued, is quiet', (_label, field) => {
98+
expect(ungroupable(field)).toEqual([]);
99+
expect(validateListViewFieldRefs(stackWith(groupedBy(field)))).toEqual([]);
100+
});
101+
102+
it('a dotted name is not this verdict: the engine refuses every dotted groupBy name on its own ground, multi-valued leaf or not', () => {
103+
// `account.tags` ends on a `tags` field, `account.name` on a text one; the
104+
// engine's dotted-name branch refuses both alike, so the storage class of
105+
// the leaf is not what the engine judges there.
106+
expect(ungroupable('account.tags')).toEqual([]);
107+
expect(ungroupable('account.name')).toEqual([]);
108+
});
109+
110+
// [M1 of the contract review] Only a grid sends its grouping to
111+
// `engine.aggregate` (objectui's `ListView.tsx` asks the group header query
112+
// under `currentView === 'grid'` alone). A gallery groups the cards it
113+
// fetched; a kanban board keeps drawing its cards when its swimlane count
114+
// read is refused; calendar, timeline, gantt and map do not read grouping.
115+
it('an absent `type` is a grid, the schema\'s default, and is judged', () => {
116+
const parsed = ListViewSchema.safeParse({ columns: ['title'] });
117+
expect(parsed.success && (parsed.data as { type?: unknown }).type).toBe('grid');
118+
const { type: _type, ...untyped } = groupedBy('labels');
119+
const findings = validateListViewFieldRefs(stackWith(untyped)).filter((f) => f.rule === LIST_VIEW_GROUP_FIELD_UNGROUPABLE);
120+
expect(findings.map((f) => [f.severity, f.path])).toEqual([['error', 'views[0].list.grouping.fields[0].field']]);
121+
});
122+
123+
it.each(['kanban', 'gallery', 'calendar', 'timeline', 'gantt', 'map'])(
124+
'CONTROL — a `%s` list view is not judged: its grouping does not reach the engine',
125+
(type) => {
126+
for (const field of ['labels', 'owners', 'meta', 'score']) {
127+
const findings = validateListViewFieldRefs(stackWith({ ...groupedBy(field), type }))
128+
.filter((f) => f.rule === LIST_VIEW_GROUP_FIELD_UNGROUPABLE);
129+
expect(findings, `${type} grouped by ${field}`).toEqual([]);
130+
}
131+
},
132+
);
133+
134+
it('a name that resolves to nothing stays `list-view-field-unknown`', () => {
135+
expect(ungroupable('nope')).toEqual([]);
136+
});
137+
138+
it('judges every level of a multi-level grouping', () => {
139+
const listView = { ...groupedBy('status'), grouping: { fields: [{ field: 'status' }, { field: 'score' }] } };
140+
const findings = validateListViewFieldRefs(stackWith(listView)).filter((f) => f.rule === LIST_VIEW_GROUP_FIELD_UNGROUPABLE);
141+
expect(findings.map((f) => f.path)).toEqual(['views[0].list.grouping.fields[1].field']);
142+
});
143+
144+
for (const command of ['validate', 'build'] as const) {
145+
it(`fails \`${command}\``, () => {
146+
const { errors } = splitBySeverity(runAuthoringRules(command, { normalized: stackWith(groupedBy('labels')) }));
147+
expect(errors.map((f) => f.rule)).toContain(LIST_VIEW_GROUP_FIELD_UNGROUPABLE);
148+
});
149+
}
150+
151+
it('is refused at the runtime `view` save door, and admitted once the grouping names a stored single-valued field', () => {
152+
const item = (field: string) => ({ name: 'grp_task', object: 'grp_task', list: groupedBy(field) });
153+
const refused = runRuntimeAuthoringRules({ type: 'view', item: item('meta'), context: { objects: OBJECTS } });
154+
expect(refused.errors.map((f) => [f.rule, f.severity])).toEqual([[LIST_VIEW_GROUP_FIELD_UNGROUPABLE, 'error']]);
155+
expect(refused.errors[0].path).toMatch(/grouping\.fields\[0\]\.field$/);
156+
const clean = runRuntimeAuthoringRules({ type: 'view', item: item('status'), context: { objects: OBJECTS } });
157+
expect(clean.errors).toEqual([]);
158+
});
159+
160+
it('`os explain` carries the reasoning and the fix', () => {
161+
const text = explainRule(LIST_VIEW_GROUP_FIELD_UNGROUPABLE)!.paragraphs.join('\n');
162+
for (const fact of ['400 INVALID_FIELD', 'grid column', 'stored single-valued field', '`list-view-field-unknown`']) {
163+
expect(text, fact).toContain(fact);
164+
}
165+
});
166+
});

0 commit comments

Comments
 (0)