diff --git a/.changeset/19856-joined-report-container-selection-refused.md b/.changeset/19856-joined-report-container-selection-refused.md new file mode 100644 index 00000000000..605578d346d --- /dev/null +++ b/.changeset/19856-joined-report-container-selection-refused.md @@ -0,0 +1,46 @@ +--- +'@objectstack/spec': minor +--- + +fix(spec): a `joined` report refuses a top-level `dataset` / `rows` / `columns` / `values`, pointing each onto `blocks[]` (#19856) + +Clause-②: no (narrowing) + +**BREAKING** — shipped as `minor` under the launch-window convention +(`check-changeset-no-major` refuses `major` until GA; breaking-ness is carried by +this banner, the `(narrowing)` arm above and the ADR-0087 disposition below, +never by the level). + +A `joined` report selects nothing itself: each block binds its own `dataset` and +selects its own `rows` / `columns` / `values`, and the renderer's joined branch +reads `blocks` and returns before it reads any top-level selection key. +`ReportSchema` already refused a container-level `order` for exactly that +reason, but the four selection keys beside it parsed green and were then dropped +without a word. Each is now refused at its own path: + +``` +FROM ReportSchema.safeParse({ name: 'overview', label: 'Overview', type: 'joined', + blocks: [/* … */], dataset: 'tasks', values: ['task_count'] }) + -> { success: true } // both keys silently ignored at render + +TO -> { success: false, issues: [ + { code: 'custom', path: ['dataset'], + message: 'a `joined` report selects per block — move `dataset` onto `blocks[]`, or delete it; on the container it selects nothing.' }, + { code: 'custom', path: ['values'], + message: 'a `joined` report selects per block — move `values` onto `blocks[]`, or delete it; on the container it selects nothing.' } ] } +``` + +**Fix.** Move the key onto the `blocks[]` entries that need it, or delete it. +Either way the report renders exactly as before, because the container value was +never read. + +**What does not change.** A present `dataset` and a NON-EMPTY list are refused; +an empty `rows` / `columns` / `values` list selects nothing and still parses (the +same threshold as the container `order` refusal, whose message is unchanged). A +joined report's container `runtimeFilter` and `drilldown` — the two container keys +the joined branch does read — parse as before, and every non-joined report is +untouched. An aliased spelling (`measures` → `values`, `dataSet` → `dataset`, …) +is still renamed first, and the renamed key on a joined container then meets this +refusal. + + diff --git a/packages/spec/src/migrations/entries/semantic/18.ui-report-joined-container-selection-refused.ts b/packages/spec/src/migrations/entries/semantic/18.ui-report-joined-container-selection-refused.ts new file mode 100644 index 00000000000..87ccb64bff2 --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.ui-report-joined-container-selection-refused.ts @@ -0,0 +1,52 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +export const entry: SemanticMigration = { + id: 'ui-report-joined-container-selection-refused', + surface: 'report selection keys on a `joined` container — a top-level `dataset`, or a ' + + 'NON-EMPTY top-level `rows` / `columns` / `values` list, on a report whose `type` is ' + + '`joined` (`ReportSchema`\'s refinement)', + replacement: 'the same key on the `blocks[]` entries that need it — each block binds its own ' + + '`dataset` and selects its own `rows` / `columns` / `values` — or DELETE it. Deleting ' + + 'changes nothing that renders: the container value was never read. The refusal lands at ' + + 'the key\'s own path and says both, the way the container `order` refusal beside it ' + + 'always has, and that `order` refusal is unchanged.', + reason: + 'ADR-0049 enforce-or-remove, the enforce arm: the four keys stay declared (they are the ' + + 'selection of every non-joined report), and the one report type that never reads them ' + + 'now refuses them. A `joined` report selects nothing itself, and the refinement already ' + + 'said so for `order` alone — it refused a container `order` with a pointer onto ' + + '`blocks[]` while the four selection keys beside it parsed green. Measured at this ' + + 'repo\'s `.objectui-sha` pin `f8a9d0fb0596f4521076628e2bbfe27e6ce67d52`: ' + + '`DatasetReportRenderer`\'s joined branch (`DatasetReportRenderer.tsx:1462`) reads ' + + '`blocks`, plus the container `runtimeFilter` and `drilldown` resolved above it, and ' + + 'returns before the top-level reads of `columns` / `dataset` / `rows` / `values` begin ' + + '(line 1529 onward) — so each was accepted by the metadata layer and dropped by the ' + + 'renderer without a word. The alias tables made it reachable: `fields` / `measures` / ' + + '`metrics` route to `values`, `groupings` / `groupBy` / `dimensions` to `rows`, and ' + + '`objectName` / `object` / `dataSet` / `source` to `dataset`, on a joined report as on ' + + 'any other. Studio\'s report inspector hides the top-level binding for a joined report ' + + '(`ReportDefaultInspector.tsx:328`) but its type picker patches only `type`, so a ' + + 'report bound first and switched to `joined` second carries the keys invisibly. An ' + + 'empty list is NOT refused: it selects nothing, which is what a joined container ' + + 'selects — the container `order` refusal\'s own threshold. Ships at once, no ' + + 'deprecation window: there is no window in which a key the renderer never reads does ' + + 'anything.', + acceptanceCriteria: + 'WHICH DOOR: this is the spec schema\'s refusal, so it lands wherever a report is parsed ' + + 'through `@objectstack/spec` — `defineReport`, `os validate` / `os build`, and the ' + + 'metadata save door (the `report` entry of the metadata type registry) — as one ' + + '`custom` issue per key at `dataset` / `rows` / `columns` / `values`. A stored ' + + '`sys_metadata` report row is not rewritten: it carries the same issue in its read-side ' + + '`_diagnostics` and is refused on its next save. Fix each by moving the key onto the ' + + 'blocks that need it or deleting it, then check the rendered report: it renders exactly ' + + 'as before, because the container value was never read. A joined report that carries ' + + 'only `blocks`, `runtimeFilter`, `drilldown` and the identity / protection keys parses ' + + 'byte-identically to before, and every non-joined report is untouched. Census at the ' + + 'time of the change: zero joined reports carry any of the four at the container — in ' + + 'this repo one example-app report, one docs example and five test fixtures across ' + + '`packages/lint` and `packages/platform-objects`; in objectui every joined-report ' + + 'fixture and docs example at the pin above (13 occurrences); in the cloud repo none ' + + 'exist.', +}; diff --git a/packages/spec/src/migrations/registry.ts b/packages/spec/src/migrations/registry.ts index c92e1d2c3ba..efdd597234b 100644 --- a/packages/spec/src/migrations/registry.ts +++ b/packages/spec/src/migrations/registry.ts @@ -13876,6 +13876,54 @@ const step18: MigrationStep = { + 'reports no `component-props-unknown-key` / `component-props-invalid` finding for the ' + 'rail.', }, + { + id: 'ui-report-joined-container-selection-refused', + surface: 'report selection keys on a `joined` container — a top-level `dataset`, or a ' + + 'NON-EMPTY top-level `rows` / `columns` / `values` list, on a report whose `type` is ' + + '`joined` (`ReportSchema`\'s refinement)', + replacement: 'the same key on the `blocks[]` entries that need it — each block binds its own ' + + '`dataset` and selects its own `rows` / `columns` / `values` — or DELETE it. Deleting ' + + 'changes nothing that renders: the container value was never read. The refusal lands at ' + + 'the key\'s own path and says both, the way the container `order` refusal beside it ' + + 'always has, and that `order` refusal is unchanged.', + reason: + 'ADR-0049 enforce-or-remove, the enforce arm: the four keys stay declared (they are the ' + + 'selection of every non-joined report), and the one report type that never reads them ' + + 'now refuses them. A `joined` report selects nothing itself, and the refinement already ' + + 'said so for `order` alone — it refused a container `order` with a pointer onto ' + + '`blocks[]` while the four selection keys beside it parsed green. Measured at this ' + + 'repo\'s `.objectui-sha` pin `f8a9d0fb0596f4521076628e2bbfe27e6ce67d52`: ' + + '`DatasetReportRenderer`\'s joined branch (`DatasetReportRenderer.tsx:1462`) reads ' + + '`blocks`, plus the container `runtimeFilter` and `drilldown` resolved above it, and ' + + 'returns before the top-level reads of `columns` / `dataset` / `rows` / `values` begin ' + + '(line 1529 onward) — so each was accepted by the metadata layer and dropped by the ' + + 'renderer without a word. The alias tables made it reachable: `fields` / `measures` / ' + + '`metrics` route to `values`, `groupings` / `groupBy` / `dimensions` to `rows`, and ' + + '`objectName` / `object` / `dataSet` / `source` to `dataset`, on a joined report as on ' + + 'any other. Studio\'s report inspector hides the top-level binding for a joined report ' + + '(`ReportDefaultInspector.tsx:328`) but its type picker patches only `type`, so a ' + + 'report bound first and switched to `joined` second carries the keys invisibly. An ' + + 'empty list is NOT refused: it selects nothing, which is what a joined container ' + + 'selects — the container `order` refusal\'s own threshold. Ships at once, no ' + + 'deprecation window: there is no window in which a key the renderer never reads does ' + + 'anything.', + acceptanceCriteria: + 'WHICH DOOR: this is the spec schema\'s refusal, so it lands wherever a report is parsed ' + + 'through `@objectstack/spec` — `defineReport`, `os validate` / `os build`, and the ' + + 'metadata save door (the `report` entry of the metadata type registry) — as one ' + + '`custom` issue per key at `dataset` / `rows` / `columns` / `values`. A stored ' + + '`sys_metadata` report row is not rewritten: it carries the same issue in its read-side ' + + '`_diagnostics` and is refused on its next save. Fix each by moving the key onto the ' + + 'blocks that need it or deleting it, then check the rendered report: it renders exactly ' + + 'as before, because the container value was never read. A joined report that carries ' + + 'only `blocks`, `runtimeFilter`, `drilldown` and the identity / protection keys parses ' + + 'byte-identically to before, and every non-joined report is untouched. Census at the ' + + 'time of the change: zero joined reports carry any of the four at the container — in ' + + 'this repo one example-app report, one docs example and five test fixtures across ' + + '`packages/lint` and `packages/platform-objects`; in objectui every joined-report ' + + 'fixture and docs example at the pin above (13 occurrences); in the cloud repo none ' + + 'exist.', + }, // The absent-value half of the coupling #6227 declared, recorded beside its // array half (`view-filter-rule-scalar-operator-array-refused`) rather than // amended onto it: that entry's own replacement prose told an upgrading author diff --git a/packages/spec/src/ui/report.test.ts b/packages/spec/src/ui/report.test.ts index ce7cb693555..ef403e4b8f6 100644 --- a/packages/spec/src/ui/report.test.ts +++ b/packages/spec/src/ui/report.test.ts @@ -9,8 +9,10 @@ import { Report, JoinedReportBlockSchema, reportSelectionOrder, + defineReport, } from './report.zod'; import { strictObjectDeclarations } from '../shared/strict-object'; +import { getMetadataTypeSchema } from '../kernel/metadata-type-schemas'; /** * ADR-0021 single-form: a report binds a `dataset` and selects `rows` @@ -99,6 +101,124 @@ describe('Joined reports', () => { }); }); +/** + * A `joined` container selects nothing itself: each block binds its own + * dataset and picks its own dimensions and measures, and the renderer's joined + * branch returns before it reads any top-level selection key. Until this + * refinement, a container `dataset` / `rows` / `columns` / `values` parsed + * green and was then dropped without a word — while `order`, one key over, was + * already refused for exactly that reason. + * + * Every refusal below asserts the envelope a schema door owes: the issue + * `code`, its `path`, and the prescription (the key moves onto `blocks[]`). + */ +describe('Joined reports refuse top-level selection keys', () => { + const BLOCK = { name: 'open_block', type: 'summary', dataset: 'tasks', rows: ['status'], values: ['task_count'] } as const; + const JOINED = { name: 'overview', label: 'Overview', type: 'joined', blocks: [BLOCK] } as const; + const PRESCRIPTION = (key: string) => + `a \`joined\` report selects per block — move \`${key}\` onto \`blocks[]\`, or delete it; on the container it selects nothing.`; + const ORDER_MESSAGE = 'a `joined` report orders per block — move `order` onto `blocks[]`.'; + + /** A NON-EMPTY value the key accepts on a plain report, so only the joined arm can refuse it. */ + const SELECTION: ReadonlyArray = [ + ['dataset', 'tasks'], + ['rows', ['status']], + ['columns', ['priority']], + ['values', ['task_count']], + ]; + + it.each(SELECTION)('`%s` on a joined container is refused at its own path, pointing at `blocks[]`', (key, value) => { + const r = ReportSchema.safeParse({ ...JOINED, [key]: value }); + expect(r.success, `a joined report carrying \`${key}\` parsed green — the key would be silently dropped`).toBe(false); + expect(r.error!.issues.map((i) => ({ code: i.code, path: i.path, message: i.message }))).toEqual([ + { code: 'custom', path: [key], message: PRESCRIPTION(key) }, + ]); + }); + + it('refuses all four at once, one issue per key — and the `order` refusal beside them is unchanged', () => { + const r = ReportSchema.safeParse({ + ...JOINED, + dataset: 'tasks', rows: ['status'], columns: ['priority'], values: ['task_count'], + order: [{ by: 'task_count' }], + }); + expect(r.success).toBe(false); + expect(r.error!.issues.map((i) => ({ code: i.code, path: i.path, message: i.message }))).toEqual([ + ...SELECTION.map(([key]) => ({ code: 'custom', path: [key], message: PRESCRIPTION(key) })), + { code: 'custom', path: ['order'], message: ORDER_MESSAGE }, + ]); + }); + + it('the authoring factory refuses it too — `defineReport` throws the same prescription', () => { + expect(() => defineReport({ ...JOINED, values: ['task_count'] } as never)).toThrow(PRESCRIPTION('values')); + }); + + it('the metadata save door refuses it — the registry\'s `report` schema is the same schema', () => { + const saveDoor = getMetadataTypeSchema('report'); + expect(saveDoor, 'the `report` metadata type must resolve a schema').toBeDefined(); + const r = saveDoor!.safeParse({ ...JOINED, dataset: 'tasks' }); + expect(r.success).toBe(false); + expect(r.error!.issues.map((i) => ({ code: i.code, path: i.path, message: i.message }))).toEqual([ + { code: 'custom', path: ['dataset'], message: PRESCRIPTION('dataset') }, + ]); + }); + + it('taking the advice parses — each key is accepted on a block', () => { + const r = ReportSchema.safeParse({ + ...JOINED, + blocks: [{ ...BLOCK, type: 'matrix', dataset: 'tasks', rows: ['status'], columns: ['priority'], values: ['task_count'] }], + }); + expect(r.success, JSON.stringify(r.error?.issues ?? [])).toBe(true); + expect(r.data!.blocks![0]).toMatchObject({ dataset: 'tasks', rows: ['status'], columns: ['priority'], values: ['task_count'] }); + }); + + it('an EMPTY list selects nothing, so it is not refused — the same threshold as `order`', () => { + const r = ReportSchema.safeParse({ ...JOINED, rows: [], columns: [], values: [], order: [] }); + expect(r.success, JSON.stringify(r.error?.issues ?? [])).toBe(true); + }); + + it('the container keys a joined report DOES read still parse — `runtimeFilter` and `drilldown`', () => { + const r = ReportSchema.safeParse({ ...JOINED, runtimeFilter: { done: false }, drilldown: false }); + expect(r.success, JSON.stringify(r.error?.issues ?? [])).toBe(true); + expect(r.data!.runtimeFilter).toEqual({ done: false }); + expect(r.data!.drilldown).toBe(false); + }); + + it('a non-joined report is untouched — the same four keys are its selection', () => { + const r = ReportSchema.safeParse({ + name: 'hours_matrix', label: 'Hours', type: 'matrix', + dataset: 'tasks', rows: ['status'], columns: ['priority'], values: ['task_count'], + }); + expect(r.success, JSON.stringify(r.error?.issues ?? [])).toBe(true); + }); + + /** + * The alias tables route an author ONTO these keys (`measures` → `values`, + * `dataSet` → `dataset`). On a joined report the prescribed key is itself + * refused, with the pointer onto `blocks[]` — the same two-step answer an + * author already gets for `sort` → `order`. The refusal must still be reached + * after the rename; this pins it end to end, both spellings. + */ + it.each([ + ['measures', 'values', ['task_count']], + ['dataSet', 'dataset', 'tasks'], + ] as const)('the alias `%s` → `%s` still ends at the joined refusal, and then at `blocks[]`', (alias, target, value) => { + const aliased = ReportSchema.safeParse({ ...JOINED, [alias]: value }); + expect(aliased.success).toBe(false); + const unknown = aliased.error!.issues.find((i) => i.code === 'unrecognized_keys'); + expect(unknown, `\`${alias}\` must be refused as an unknown key`).toBeDefined(); + expect(unknown!.message).toContain(`Did you mean \`${alias}\` → \`${target}\`?`); + + const renamed = ReportSchema.safeParse({ ...JOINED, [target]: value }); + expect(renamed.success, `taking the rename put \`${target}\` on a joined container and it parsed green`).toBe(false); + expect(renamed.error!.issues.map((i) => ({ code: i.code, path: i.path, message: i.message }))).toEqual([ + { code: 'custom', path: [target], message: PRESCRIPTION(target) }, + ]); + + const moved = ReportSchema.safeParse({ ...JOINED, blocks: [{ ...BLOCK, [target]: value }] }); + expect(moved.success, JSON.stringify(moved.error?.issues ?? [])).toBe(true); + }); +}); + /** * #3916 — reports can declare an ordering. Before this the report schema had no * sort field at all: `DatasetSelection.order` existed but was unreachable for diff --git a/packages/spec/src/ui/report.zod.ts b/packages/spec/src/ui/report.zod.ts index 452f138f054..f13efbaf468 100644 --- a/packages/spec/src/ui/report.zod.ts +++ b/packages/spec/src/ui/report.zod.ts @@ -241,6 +241,16 @@ export const JoinedReportBlockSchema: z.ZodTypeAny = lazySchema(() => strictObje order: z.array(ReportSortSchema).optional().describe('Result ordering, most significant key first').meta({ title: 'Order' }), }).superRefine(checkReportOrder)); +/** + * The top-level keys a `type: 'joined'` report refuses, each with a pointer + * onto `blocks[]`: every one of them SELECTS data, and a joined container + * selects nothing itself — each block binds its own `dataset` and picks its own + * `rows` / `columns` / `values`. `order` is refused beside them, by its own + * message, for the same reason. Not exported: the refinement below is the only + * reader, and `report.test.ts` pins the list by parse. + */ +const JOINED_CONTAINER_SELECTION_KEYS = ['dataset', 'rows', 'columns', 'values'] as const; + /** * Report Schema * Deep data analysis definition. @@ -331,17 +341,26 @@ export const ReportSchema = lazySchema(() => strictObject({ * dimensions — numbers stay consistent with every other surface using the * same dataset. This is the single author-facing analytics shape (the legacy * inline `objectName` + `columns` + `groupings` query was removed in the - * single-form cutover). For a `joined` report, the data lives on `blocks`. + * single-form cutover). For a `joined` report, the data lives on `blocks`: + * a top-level `dataset` on one is refused — each block binds its own. */ dataset: SnakeCaseIdentifierSchema.optional().describe('Dataset name to bind (ADR-0021)'), - /** Dimension names (from the dataset) to group rows by (down axis). */ + /** + * Dimension names (from the dataset) to group rows by (down axis). A + * non-empty list on a `joined` report is refused — see `blocks[].rows`. + */ rows: z.array(z.string()).optional().describe('Dimension names down'), /** * Dimension names across (ADR-0021 D2) — a `matrix` report pivots - * `rows` × `columns` with `values` in the cells. Ignored for other types. + * `rows` × `columns` with `values` in the cells. Ignored for the other + * non-joined types; a non-empty list on a `joined` report is refused — see + * `blocks[].columns`. */ columns: z.array(z.string()).optional().describe('Dimension names across (matrix)'), - /** Measure names (from the dataset) to display. */ + /** + * Measure names (from the dataset) to display. A non-empty list on a + * `joined` report is refused — see `blocks[].values`. + */ values: z.array(z.string()).optional().describe('Measure names to show'), /** Render-time scope filter, ANDed at query time. */ runtimeFilter: FilterConditionSchema.optional().describe('Render-time scope filter'), @@ -421,8 +440,24 @@ export const ReportSchema = lazySchema(() => strictObject({ path: ['dataset'], }); } - // A `joined` report selects nothing itself — its ordering lives per block. + // A `joined` report selects nothing itself — its selection and its ordering + // live per block. The renderer's joined branch reads `blocks` (plus the + // container's `runtimeFilter` and `drilldown`) and returns before it reads + // any top-level selection key, so a container `dataset` / `rows` / `columns` + // / `values` was accepted here and then dropped without a word — the exact + // experience the `order` refusal below already existed to prevent, one key + // over. The threshold is `order`'s: a present `dataset`, a NON-EMPTY list. + // An empty list selects nothing, which is what a joined container selects. if (r.type === 'joined') { + for (const key of JOINED_CONTAINER_SELECTION_KEYS) { + const value = r[key]; + if (value === undefined || (Array.isArray(value) && value.length === 0)) continue; + ctx.addIssue({ + code: 'custom', + message: `a \`joined\` report selects per block — move \`${key}\` onto \`blocks[]\`, or delete it; on the container it selects nothing.`, + path: [key], + }); + } if (r.order?.length) { ctx.addIssue({ code: 'custom',