Skip to content

Commit 2bb3512

Browse files
committed
feat(spec): list a stored dashboard that repeats a global filter key in the v18 stored listing
The duplicate globalFilters key refusal had no RefusedStoredShape, so `os migrate meta --stored` named no stored dashboard the parse refuses. The detector calls duplicateGlobalFilterNames, the refinement's own predicate, and reports at the site the parse locates. Claude-Session: https://claude.ai/code/session_01ADHkmQfSq34mnnkWb6STfV Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5a2bdf9 commit 2bb3512

2 files changed

Lines changed: 92 additions & 1 deletion

File tree

‎packages/spec/src/conversions/refused-shapes.test.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { flowNodeValueTemplateRefusals } from '../automation/flow-value-slot-tem
77
import { ObjectSchema } from '../data/object.zod.js';
88
import { MIGRATIONS_BY_MAJOR } from '../migrations/registry.js';
99
import { ComponentPropsMap } from '../ui/component.zod.js';
10+
import { DashboardSchema } from '../ui/dashboard.zod.js';
1011
import { PageSchema } from '../ui/page.zod.js';
1112
import { ViewDataSchema } from '../ui/view.zod.js';
1213
import { applyConversions, applyConversionsToFlow } from './apply.js';
@@ -71,6 +72,7 @@ describe('the refused-shape list — registered against the migration chain', ()
7172
'object-external-binding-managed-datasource-refused',
7273
'visibility-predicate-has-argument-refused',
7374
'object-duplicate-action-name-refused',
75+
'ui-dashboard-global-filter-duplicate-name-refused',
7476
]);
7577
});
7678

@@ -792,3 +794,62 @@ describe('#26725 — a stored object that declares one action name twice is list
792794
expect(dupActionIssue(row)).toBeUndefined();
793795
});
794796
});
797+
798+
// ── #29212 (the #29023 refusal) ───────────────────────────────────────────
799+
800+
const dupBoard = (globalFilters: unknown[]) => ({ name: 'crm_kpi', label: 'KPI', widgets: [], globalFilters });
801+
/** The dashboard parse's duplicate-key issue, or undefined. */
802+
const dupFilterIssue = (row: unknown) => {
803+
const parsed = DashboardSchema.safeParse(row);
804+
return parsed.success
805+
? undefined
806+
: parsed.error.issues.find((i) => i.path[0] === 'globalFilters' && /declares the global filter/.test(i.message));
807+
};
808+
809+
describe('#29212 — a stored dashboard that declares one global filter key twice is listed by dashboard', () => {
810+
it('one TODO at the second declaration\'s name, naming the key and both indexes; the row is not rewritten', () => {
811+
const row = dupBoard([
812+
{ name: 'r', field: 'region', type: 'text' },
813+
{ name: 'r', field: 'status', type: 'text' },
814+
]);
815+
const { item, todos } = storedTodos('dashboard', row);
816+
expect(item).toEqual(row);
817+
expect(todos).toHaveLength(1);
818+
const todo = todos[0]!;
819+
expect(todo.conversionId).toBe('ui-dashboard-global-filter-duplicate-name-refused');
820+
expect(todo.path).toBe('dashboards[0].globalFilters[1].name');
821+
expect(todo.reason).toMatch(/^No lossless rewrite: which definition keeps the key/);
822+
expect(todo.reason).toContain(
823+
"This dashboard declares the global filter 'r' twice in globalFilters: globalFilters[0] and globalFilters[1].",
824+
);
825+
expect(todo.reason).not.toMatch(/#\d{3,}/);
826+
expect(JSON.parse(todo.from)).toEqual({ name: 'r', indexes: [0, 1] });
827+
// The listing and the parse refuse ONE set: the stored row still fails the parse, at the same site.
828+
expect(dupFilterIssue(item)?.path).toEqual(['globalFilters', 1, 'name']);
829+
});
830+
831+
it('a key that falls back to `field` is listed at that field, as the parse locates it', () => {
832+
const row = dupBoard([
833+
{ field: 'region', type: 'text' },
834+
{ field: 'region', type: 'select', options: [{ value: 'north', label: 'North' }] },
835+
{ name: 'region', field: 'sales_region', type: 'text' },
836+
]);
837+
const { todos } = storedTodos('dashboard', row);
838+
expect(todos).toHaveLength(1);
839+
expect(todos[0]!.path).toBe('dashboards[0].globalFilters[1].field');
840+
expect(JSON.parse(todos[0]!.from)).toEqual({ name: 'region', indexes: [0, 1, 2] });
841+
expect(todos[0]!.reason).toContain("the global filter 'region' 3 times");
842+
expect(dupFilterIssue(row)?.path).toEqual(['globalFilters', 1, 'field']);
843+
});
844+
845+
it('distinct keys, and distinct names over one field, are not listed — and the parse accepts them', () => {
846+
for (const filters of [
847+
[{ name: 'r', field: 'region', type: 'text' }, { name: 's', field: 'status', type: 'text' }],
848+
[{ name: 'region_a', field: 'region', type: 'text' }, { name: 'region_b', field: 'region', type: 'text' }],
849+
]) {
850+
const row = dupBoard(filters);
851+
expect(storedTodos('dashboard', row).todos).toEqual([]);
852+
expect(DashboardSchema.safeParse(row).success).toBe(true);
853+
}
854+
});
855+
});

‎packages/spec/src/conversions/refused-shapes.ts‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
* `external` binding judge
4444
* the object refinement and `defineStack` share
4545
* ({@link externalBindingDatasourceRefusal}), and the one-name-per-action
46-
* judge of the object refinement ({@link duplicateActionNames}). A site is listed here exactly
46+
* judge of the object refinement ({@link duplicateActionNames}), and the
47+
* one-key-per-global-filter judge of the dashboard refinement
48+
* ({@link duplicateGlobalFilterNames}). A site is listed here exactly
4749
* when that door refuses it. One door lives outside this package: the
4850
* page/view `visibleWhen` rule in `@objectstack/lint` judges a `has()`
4951
* argument on the engine's AST, which this package cannot parse, so its
@@ -68,6 +70,7 @@ import {
6870
import { duplicateActionNames } from '../data/duplicate-action-names.js';
6971
import { externalBindingDatasourceRefusal } from '../data/external-binding-datasource.js';
7072
import { ComponentPropsMap } from '../ui/component.zod.js';
73+
import { duplicateGlobalFilterNames } from '../ui/duplicate-global-filter-names.js';
7174
import { ViewDataSchema } from '../ui/view.zod.js';
7275
import { refusedHasArguments } from './cel-has-argument.js';
7376
import type { ConversionTodoDetail } from './types.js';
@@ -555,6 +558,32 @@ const objectDuplicateActionName: RefusedStoredShape = {
555558
},
556559
};
557560

561+
// ── #29212: a dashboard that declares one global filter key twice (the #29023 refusal) ──
562+
563+
const dashboardDuplicateGlobalFilterName: RefusedStoredShape = {
564+
id: 'ui-dashboard-global-filter-duplicate-name-refused',
565+
toMajor: 18,
566+
surface: 'dashboard.globalFilters — two or more entries of one dashboard under the same filter key '
567+
+ '(the entry\'s `name`, or its `field` when it has no `name`)',
568+
detect(stack, report) {
569+
mapCollection(stack, 'dashboards', (dashboard, path) => {
570+
for (const duplicate of duplicateGlobalFilterNames(dashboard.globalFilters)) {
571+
report({
572+
// The site the dashboard parse refuses: the second declaration's `name`, or its `field`.
573+
path: `${path}.globalFilters[${duplicate.indexes[1]}].${duplicate.secondKey}`,
574+
from: JSON.stringify({ name: duplicate.name, indexes: duplicate.indexes }),
575+
reason: 'No lossless rewrite: which definition keeps the key, and what the others are renamed to '
576+
+ '(with every widget `filterBindings` key that means a renamed one), only the author knows. Left as '
577+
+ 'stored, the dashboard still loads with `_diagnostics` reading `valid: false`, and its next save, '
578+
+ 'draft or publish, is refused with 422 INVALID_METADATA. '
579+
+ duplicate.message,
580+
});
581+
}
582+
return dashboard;
583+
});
584+
},
585+
};
586+
558587
/**
559588
* Every refused stored shape, in report order. A new entry is a reviewed edit:
560589
* `refused-shapes.test.ts` pins each one.
@@ -567,6 +596,7 @@ export const REFUSED_STORED_SHAPES: readonly RefusedStoredShape[] = [
567596
externalBindingOnManagedDatasource,
568597
visibilityHasArgument,
569598
objectDuplicateActionName,
599+
dashboardDuplicateGlobalFilterName,
570600
];
571601

572602
/**

0 commit comments

Comments
 (0)