Skip to content

Commit 45ada0d

Browse files
committed
test(lint,rest): pin chart list-view refusals at the view and object doors
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufziFPBpGc76tAFHbB8v
1 parent 21e8217 commit 45ada0d

3 files changed

Lines changed: 233 additions & 5 deletions

File tree

‎packages/lint/src/reference-integrity-suite.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,10 @@ export const REFERENCE_INTEGRITY_RULES: readonly ReferenceIntegrityRule[] = [
447447
// published with a dangling chart binding is now refused (422) rather than
448448
// stored silently. Each was MEASURED over the shipped corpus at the door's
449449
// own snapshot shape before crossing — `report`: 9 reports (showcase 4,
450-
// todo 5), 0 findings; `view` / `object`: MEASURED_VIEW_CORPUS — with a lit
451-
// synthetic probe refused at each door.
450+
// todo 5), 0 findings; `view` / `object`: every view and every object with
451+
// `listViews` in the four example apps and platform-objects, of which two
452+
// list views chart (showcase `task` and `project`), 0 findings. A lit
453+
// synthetic probe is refused at each door.
452454
{ name: 'validateChartBindings', runtimeTypes: ['flow', 'report', 'view', 'object'], run: validateChartBindings },
453455
// [#26548] The same report, one key on: `dateRange.dimension` resolved
454456
// against the bound dataset's `type: 'date'` dimensions (named, or the ONE

‎packages/lint/src/validate-chart-bindings.test.ts‎

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
CHART_AXIS_NOT_SELECTED,
1010
} from './validate-chart-bindings.js';
1111
import { explainRule } from './rule-explanations.js';
12+
import { runRuntimeAuthoringRules } from './runtime-gate.js';
13+
import { REFERENCE_INTEGRITY_RULES } from './reference-integrity-suite.js';
1214

1315
// [#22161] Each finding of the two converted ids is one verdict sentence; the
1416
// reasoning it used to carry is the id's `os explain` entry. Every call below
@@ -851,6 +853,150 @@ describe('validateChartBindings — list-view charts', () => {
851853
});
852854
});
853855

856+
// [#26847] The two standalone `views[]` shapes `PUT /api/v1/meta/view` carries,
857+
// and the publish door itself. Measured on main before the change: a chart list
858+
// view naming no declared dataset, or a measure its dataset lacks, published
859+
// 200 through that door as a ViewItem record, a flattened overlay and a
860+
// container `listViews` member alike, while `os validate` refused the file.
861+
describe('[#26847] list-view charts at the view and object publish doors', () => {
862+
const chart = (over: Record<string, unknown> = {}) => ({
863+
chartType: 'bar',
864+
dataset: 'task_metrics',
865+
dimensions: ['status'],
866+
values: ['est_hours'],
867+
...over,
868+
});
869+
const listView = (over: Record<string, unknown> = {}) => ({
870+
type: 'chart',
871+
label: 'Hours by status',
872+
data: { provider: 'object', object: 'showcase_task' },
873+
columns: ['status'],
874+
chart: chart(over),
875+
});
876+
const SHAPES: Array<[string, (over?: Record<string, unknown>) => Record<string, unknown>, string]> = [
877+
[
878+
'a ViewItem record',
879+
(over) => ({ name: 'showcase_task.hours', object: 'showcase_task', viewKind: 'list', label: 'Hours', config: listView(over) }),
880+
'views[0].config.chart',
881+
],
882+
[
883+
'a flattened list overlay',
884+
(over) => ({ name: 'showcase_task.hours', object: 'showcase_task', viewKind: 'list', ...listView(over) }),
885+
'views[0].chart',
886+
],
887+
[
888+
'a container listViews member',
889+
(over) => ({ name: 'showcase_task', object: 'showcase_task', listViews: { hours: listView(over) } }),
890+
'views[0].listViews.hours.chart',
891+
],
892+
];
893+
894+
describe.each(SHAPES)('the rule walks %s', (_label, view, at) => {
895+
it('chart-dataset-unknown at `chart.dataset`', () => {
896+
const findings = validateChartBindings({ ...baseStack(), views: [view({ dataset: 'no_such_dataset' })] });
897+
expect(findings.map((f) => [f.rule, f.severity, f.path])).toEqual([[CHART_DATASET_UNKNOWN, 'error', `${at}.dataset`]]);
898+
});
899+
900+
it('chart-measure-unknown at `chart.values[i]`', () => {
901+
const findings = validateChartBindings({ ...baseStack(), views: [view({ values: ['est_hours', 'ghost_measure'] })] });
902+
expect(findings.map((f) => [f.rule, f.severity, f.path])).toEqual([[CHART_MEASURE_UNKNOWN, 'error', `${at}.values[1]`]]);
903+
});
904+
905+
it('CONTROL — a fully resolved chart reports nothing', () => {
906+
expect(validateChartBindings({ ...baseStack(), views: [view()] })).toEqual([]);
907+
});
908+
});
909+
910+
it('a ViewItem record is judged at `config` only — its envelope carries no chart to walk twice', () => {
911+
const item = { ...SHAPES[0][1]({ dataset: 'no_such_dataset' }), chart: chart({ dataset: 'no_such_dataset' }) };
912+
expect(validateChartBindings({ ...baseStack(), views: [item] }).map((f) => f.path)).toEqual([
913+
'views[0].config.chart.dataset',
914+
]);
915+
});
916+
917+
it('an object list view names a dataset in a stack that declares none: refused, not skipped', () => {
918+
const findings = validateChartBindings({
919+
objects: [{ name: 'showcase_task', fields: {}, listViews: { hours: listView() } }],
920+
});
921+
expect(findings.map((f) => [f.rule, f.path])).toEqual([
922+
[CHART_DATASET_UNKNOWN, 'objects[0].listViews.hours.chart.dataset'],
923+
]);
924+
});
925+
926+
describe('at the runtime publish door', () => {
927+
const { datasets } = baseStack();
928+
const objects = [
929+
{
930+
name: 'showcase_task',
931+
label: 'Task',
932+
sharingModel: 'private',
933+
fields: {
934+
status: { type: 'text', label: 'Status' },
935+
estimate_hours: { type: 'number', label: 'Estimate' },
936+
},
937+
},
938+
];
939+
const chartRules = (fs: Array<{ rule: string; path: string }>) =>
940+
fs.filter((f) => f.rule.startsWith('chart-')).map((f) => [f.rule, f.path]);
941+
942+
it('`validateChartBindings` reaches `view` and `object` writes', () => {
943+
for (const type of ['view', 'object']) {
944+
expect(
945+
REFERENCE_INTEGRITY_RULES.find((r) => r.name === 'validateChartBindings')?.runtimeTypes,
946+
type,
947+
).toContain(type);
948+
}
949+
});
950+
951+
describe.each(SHAPES)('a view written as %s', (_label, view, at) => {
952+
const write = (over?: Record<string, unknown>) =>
953+
runRuntimeAuthoringRules({ type: 'view', item: view(over), context: { objects, datasets } });
954+
955+
it('⭐ LIT — a chart naming no declared dataset is REFUSED at `chart.dataset`', () => {
956+
const result = write({ dataset: 'no_such_dataset' });
957+
expect(chartRules(result.errors)).toEqual([[CHART_DATASET_UNKNOWN, `${at}.dataset`]]);
958+
});
959+
960+
it('⭐ LIT — a chart whose `values` names no measure of its dataset is REFUSED at `chart.values[i]`', () => {
961+
const result = write({ values: ['ghost_measure'] });
962+
expect(chartRules(result.errors)).toEqual([[CHART_MEASURE_UNKNOWN, `${at}.values[0]`]]);
963+
});
964+
965+
it('⭐ CONTROL — the same view bound to a declared dataset and measure publishes clean', () => {
966+
const result = write();
967+
expect(result.rulesRun).toContain('validateReferenceIntegrity');
968+
expect(result.errors).toEqual([]);
969+
});
970+
});
971+
972+
describe('an object write carrying a built-in chart list view', () => {
973+
const write = (over?: Record<string, unknown>) =>
974+
runRuntimeAuthoringRules({
975+
type: 'object',
976+
item: { ...objects[0], listViews: { hours: { ...listView(over), data: undefined } } },
977+
context: { objects, datasets },
978+
});
979+
980+
it('⭐ LIT — an unknown dataset is REFUSED', () => {
981+
// The door names an object entry by name rather than position.
982+
expect(chartRules(write({ dataset: 'no_such_dataset' }).errors)).toEqual([
983+
[CHART_DATASET_UNKNOWN, 'objects.showcase_task.listViews.hours.chart.dataset'],
984+
]);
985+
});
986+
987+
it('⭐ LIT — an unknown measure is REFUSED', () => {
988+
expect(chartRules(write({ values: ['ghost_measure'] }).errors)).toEqual([
989+
[CHART_MEASURE_UNKNOWN, 'objects.showcase_task.listViews.hours.chart.values[0]'],
990+
]);
991+
});
992+
993+
it('⭐ CONTROL — a resolved chart publishes clean', () => {
994+
expect(write().errors).toEqual([]);
995+
});
996+
});
997+
});
998+
});
999+
8541000
describe('validateChartBindings — dataset-bound page chart components', () => {
8551001
it('checks dimensions/values and a ChartConfig-style yAxis', () => {
8561002
const findings = validateChartBindings({

‎packages/rest/src/meta-view-chart-binding.test.ts‎

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
* list overlay member accepted `type: 'chart'` with no `chart` block, and an
1212
* `options.chart` bag holding only `chartType`.
1313
*
14+
* #26847 extends the file one binding deeper: a chart whose `dataset` names no
15+
* declared dataset, or whose `values` names no measure of it, is refused too.
16+
*
1417
* Refusal cases assert the ADR-0112 envelope — `code` AND `status` — and that
1518
* no row reached `sys_metadata`. The last case measures the READ side of the
1619
* narrowing on a row stored before it: served as stored, flagged in its
@@ -97,15 +100,27 @@ async function boot() {
97100
if (!route) throw new Error(`${method} ${META_ITEM} is not registered`);
98101
return route;
99102
};
100-
const call = async (method: string, name: string, body?: unknown) => {
103+
const call = async (method: string, name: string, body?: unknown, type = 'view') => {
101104
const res = makeRes();
102-
await routeFor(method).handler({ params: { type: 'view', name }, query: {}, headers: {}, body } as any, res);
105+
await routeFor(method).handler({ params: { type, name }, query: {}, headers: {}, body } as any, res);
103106
return res;
104107
};
108+
// [#26847] The dataset the fixture views bind, published through its own
109+
// door: the view door resolves a chart's `dataset` and `values` against the
110+
// live datasets, so a binding nobody declares is refused.
111+
const published = await call('PUT', DATASET.name, DATASET, 'dataset');
112+
if (published._status !== 200) throw new Error(`dataset fixture refused: ${JSON.stringify(published._json)}`);
105113
const storedRows = async (name: string) => engine.find('sys_metadata', { where: { type: 'view', name } });
106114
return { engine, put: (name: string, body: unknown) => call('PUT', name, body), get: (name: string) => call('GET', name), storedRows };
107115
}
108116

117+
const DATASET = {
118+
name: 'lead_metrics',
119+
label: 'Lead metrics',
120+
object: 'crm_lead',
121+
dimensions: [{ name: 'stage', field: 'stage', type: 'string' }],
122+
measures: [{ name: 'amount_sum', aggregate: 'sum', field: 'amount' }],
123+
};
109124
const BINDING = { chartType: 'bar', dataset: 'lead_metrics', dimensions: ['stage'], values: ['amount_sum'] };
110125
const chartView = (name: string, extra: Record<string, unknown>) => ({
111126
name,
@@ -117,7 +132,7 @@ const chartView = (name: string, extra: Record<string, unknown>) => ({
117132
...extra,
118133
});
119134

120-
type Issue = { path?: string; code?: string; message?: string };
135+
type Issue = { path?: string; code?: string; message?: string; rule?: string };
121136
const issuesOf = (res: any): Issue[] => (res._json?.issues ?? []) as Issue[];
122137

123138
const NO_BLOCK_VERDICT =
@@ -194,3 +209,68 @@ describe("#22491 PUT /api/v1/meta/view refuses a `type: 'chart'` list view that
194209
expect(issuesOf(again).some((i) => i.path === 'chart')).toBe(true);
195210
});
196211
});
212+
213+
// [#26847] The same door, one binding deeper: a chart that DOES name a dataset,
214+
// but one nobody declares, or a measure its dataset lacks. Measured on main
215+
// `20457f6f` before the change: all six refusals below answered 200 and were
216+
// stored, while `os validate` refused the same file.
217+
describe('#26847 PUT /api/v1/meta/view refuses a chart list view whose dataset or measure does not resolve', () => {
218+
const chartConfig = (chart: Record<string, unknown>) => ({
219+
type: 'chart',
220+
label: 'Pipeline by stage',
221+
columns: ['stage', 'amount'],
222+
chart: { ...BINDING, ...chart },
223+
});
224+
const SHAPES: Array<[string, string, (chart: Record<string, unknown>) => Record<string, unknown>, string]> = [
225+
[
226+
'a view item (`config`)',
227+
'crm_lead.pipeline_item',
228+
(chart) => ({ name: 'crm_lead.pipeline_item', object: 'crm_lead', viewKind: 'list', label: 'Pipeline', config: chartConfig(chart) }),
229+
'views[0].config.chart',
230+
],
231+
[
232+
'a flattened list overlay',
233+
'crm_lead.pipeline_flat',
234+
(chart) => ({ name: 'crm_lead.pipeline_flat', object: 'crm_lead', viewKind: 'list', ...chartConfig(chart) }),
235+
'views[0].chart',
236+
],
237+
[
238+
'a container `listViews` member',
239+
'crm_lead',
240+
(chart) => ({ name: 'crm_lead', object: 'crm_lead', list: { type: 'grid', columns: ['stage'] }, listViews: { pipeline: chartConfig(chart) } }),
241+
'views[0].listViews.pipeline.chart',
242+
],
243+
];
244+
245+
describe.each(SHAPES)('%s', (_label, name, body, at) => {
246+
it('`chart.dataset` naming no declared dataset: 422 INVALID_METADATA, chart-dataset-unknown at `chart.dataset`, nothing stored', async () => {
247+
const { put, storedRows } = await boot();
248+
const res = await put(name, body({ dataset: 'no_such_dataset' }));
249+
250+
expect(res._status, JSON.stringify(res._json)).toBe(422);
251+
expect(res._json?.code).toBe('INVALID_METADATA');
252+
expect(await storedRows(name)).toEqual([]);
253+
const hit = issuesOf(res).find((i) => i.rule === 'chart-dataset-unknown');
254+
expect(hit?.path, JSON.stringify(res._json)).toBe(`${at}.dataset`);
255+
});
256+
257+
it('`chart.values` naming no measure of its dataset: 422 INVALID_METADATA, chart-measure-unknown at `chart.values[0]`, nothing stored', async () => {
258+
const { put, storedRows } = await boot();
259+
const res = await put(name, body({ values: ['ghost_measure'] }));
260+
261+
expect(res._status, JSON.stringify(res._json)).toBe(422);
262+
expect(res._json?.code).toBe('INVALID_METADATA');
263+
expect(await storedRows(name)).toEqual([]);
264+
const hit = issuesOf(res).find((i) => i.rule === 'chart-measure-unknown');
265+
expect(hit?.path, JSON.stringify(res._json)).toBe(`${at}.values[0]`);
266+
});
267+
268+
it('the control: the same view bound to the declared dataset and measure answers 200 and is stored', async () => {
269+
const { put, storedRows } = await boot();
270+
const res = await put(name, body({}));
271+
272+
expect(res._status, JSON.stringify(res._json)).toBe(200);
273+
expect(await storedRows(name)).toHaveLength(1);
274+
});
275+
});
276+
});

0 commit comments

Comments
 (0)