|
28 | 28 | */ |
29 | 29 | import { describe, expect, it } from 'vitest'; |
30 | 30 | import { |
| 31 | + datasetBoundObjectNames, |
31 | 32 | narrowObjectsToPackageClosure, |
32 | 33 | runRuntimeAuthoringRules, |
33 | 34 | type RuntimePackageScope, |
@@ -643,3 +644,134 @@ describe('the dataset door under a package closure, and the shared prescription |
643 | 644 | expect(dataset.hint).toBe(`${clause}point it at an object inside that closure`); |
644 | 645 | }); |
645 | 646 | }); |
| 647 | + |
| 648 | +// ───────────────────────────────────────────────────────────────────────────── |
| 649 | +// #30005 — a dashboard or report on ANOTHER package's dataset, under a closure. |
| 650 | +// ───────────────────────────────────────────────────────────────────────────── |
| 651 | + |
| 652 | +describe('a dataset outside the closure: its filter keys are judged against its object (#30005)', () => { |
| 653 | + /** |
| 654 | + * The filer's shape: a runtime package (`OWN`, which declares no dependency |
| 655 | + * on the showcase) builds on `showcase_task_metrics`, a dataset the showcase |
| 656 | + * package ships over its own `showcase_task`. `datasets` is never narrowed, |
| 657 | + * so the binding resolves; before this card the object fell out of the |
| 658 | + * closure and both filter-key rules took their "object absent" skip. |
| 659 | + */ |
| 660 | + const SHOWCASE = 'com.example.showcase'; |
| 661 | + const objects = [ |
| 662 | + ...packagedTenant(2), |
| 663 | + obj('showcase_task', SHOWCASE, { |
| 664 | + fields: { |
| 665 | + name: { type: 'text', label: 'Name' }, |
| 666 | + status: { type: 'select', label: 'Status', options: [{ label: 'Done', value: 'done' }] }, |
| 667 | + estimate_hours: { type: 'number', label: 'Estimate' }, |
| 668 | + }, |
| 669 | + }), |
| 670 | + ]; |
| 671 | + const datasets = [ |
| 672 | + { |
| 673 | + name: 'showcase_task_metrics', |
| 674 | + label: 'Task Metrics', |
| 675 | + object: 'showcase_task', |
| 676 | + _packageId: SHOWCASE, |
| 677 | + dimensions: [{ name: 'status', label: 'Status', field: 'status', type: 'string' }], |
| 678 | + measures: [ |
| 679 | + { name: 'task_count', label: 'Tasks', aggregate: 'count' }, |
| 680 | + { name: 'est_hours', label: 'Estimated Hours', aggregate: 'sum', field: 'estimate_hours' }, |
| 681 | + ], |
| 682 | + }, |
| 683 | + ]; |
| 684 | + const context = { objects, datasets }; |
| 685 | + const board = (filter: AnyRec): AnyRec => ({ |
| 686 | + name: 'runtime_ops_board', |
| 687 | + label: 'Runtime Ops', |
| 688 | + widgets: [ |
| 689 | + { id: 'tasks', type: 'metric', title: 'Tasks', dataset: 'showcase_task_metrics', values: ['task_count'], filter }, |
| 690 | + ], |
| 691 | + }); |
| 692 | + const report = (runtimeFilter: AnyRec): AnyRec => ({ |
| 693 | + name: 'runtime_task_report', |
| 694 | + label: 'Runtime Tasks', |
| 695 | + type: 'summary', |
| 696 | + dataset: 'showcase_task_metrics', |
| 697 | + rows: ['status'], |
| 698 | + values: ['est_hours'], |
| 699 | + runtimeFilter, |
| 700 | + }); |
| 701 | + const gate = (type: string, item: AnyRec, scope: RuntimePackageScope | undefined = SCOPE) => |
| 702 | + runRuntimeAuthoringRules({ type, item, context, ...(scope ? { packageScope: scope } : {}) }); |
| 703 | + const at = (fs: AnyRec[]) => fs.map((f) => [f.rule, f.path]); |
| 704 | + |
| 705 | + it('⭐ LIT — the filer\'s repro: a widget key the dataset\'s object lacks is REFUSED at the widget path', () => { |
| 706 | + const result = gate('dashboard', board({ no_such_field: 'x' })); |
| 707 | + expect(at(result.errors)).toEqual([ |
| 708 | + ['widget-filter-field-unknown', 'dashboards[0].widgets[0].filter.no_such_field'], |
| 709 | + ]); |
| 710 | + expect(result.errors[0]!.severity).toBe('error'); |
| 711 | + }); |
| 712 | + |
| 713 | + it('⭐ LIT — the same key on a report `runtimeFilter` is REFUSED at its path', () => { |
| 714 | + const result = gate('report', report({ no_such_field: 'x' })); |
| 715 | + expect(at(result.errors)).toEqual([ |
| 716 | + ['report-filter-field-unknown', 'reports[0].runtimeFilter.no_such_field'], |
| 717 | + ]); |
| 718 | + }); |
| 719 | + |
| 720 | + it('⭐ LIT — a joined block on that dataset: the block key and the container key are both judged', () => { |
| 721 | + const joined = { |
| 722 | + name: 'runtime_joined', |
| 723 | + label: 'Joined', |
| 724 | + type: 'joined', |
| 725 | + runtimeFilter: { nope: 1 }, |
| 726 | + blocks: [ |
| 727 | + { name: 'b1', type: 'summary', dataset: 'showcase_task_metrics', rows: ['status'], values: ['est_hours'], runtimeFilter: { also_nope: 1 } }, |
| 728 | + ], |
| 729 | + }; |
| 730 | + expect(at(gate('report', joined).errors)).toEqual([ |
| 731 | + ['report-filter-field-unknown', 'reports[0].runtimeFilter.nope'], |
| 732 | + ['report-filter-field-unknown', 'reports[0].blocks[0].runtimeFilter.also_nope'], |
| 733 | + ]); |
| 734 | + }); |
| 735 | + |
| 736 | + it('⭐ CONTROL — a key the dataset door binds still publishes, on the widget and on the report', () => { |
| 737 | + for (const filter of [{ status: 'done' }, { estimate_hours: { $gte: 1 } }, { created_at: { $gte: '{today}' } }]) { |
| 738 | + expect(gate('dashboard', board(filter)).errors, JSON.stringify(filter)).toEqual([]); |
| 739 | + expect(gate('report', report(filter)).errors, JSON.stringify(filter)).toEqual([]); |
| 740 | + } |
| 741 | + }); |
| 742 | + |
| 743 | + it('the scoped verdict is now the whole-collection one — the closure no longer hides the finding', () => { |
| 744 | + for (const [type, item] of [['dashboard', board({ no_such_field: 'x' })], ['report', report({ no_such_field: 'x' })]] as const) { |
| 745 | + expect(verdict(gate(type, item))).toEqual(verdict(gate(type, item, undefined))); |
| 746 | + expect(verdict(gate(type, item))).toHaveLength(1); |
| 747 | + } |
| 748 | + }); |
| 749 | + |
| 750 | + it('a dataset that resolves to nothing re-admits nothing — `widget-dataset-unknown` keeps the typo', () => { |
| 751 | + const dangling = { ...board({ no_such_field: 'x' }) }; |
| 752 | + dangling.widgets = [{ ...dangling.widgets[0], dataset: 'no_such_dataset' }]; |
| 753 | + expect(gate('dashboard', dangling).errors.map((f) => f.rule)).toEqual(['widget-dataset-unknown']); |
| 754 | + }); |
| 755 | + |
| 756 | + it('DARK — only a dashboard or report re-admits: a flow or a list view outside the closure is still refused', () => { |
| 757 | + // Limb 5 is keyed on the written TYPE. A flow trigger and a list view name |
| 758 | + // their object directly, and the closure's verdict on them is the ruling's. |
| 759 | + const flow = gate('flow', flowOn('on_task', 'showcase_task')); |
| 760 | + expect(flow.errors.map((f) => f.rule)).toContain('flow-trigger-unknown-object'); |
| 761 | + const view = listViewOn('showcase_task', ['name']); |
| 762 | + view.chart = { chartType: 'bar', dataset: 'showcase_task_metrics', dimensions: ['status'], values: ['task_count'] }; |
| 763 | + expect(gate('view', view).errors.map((f) => f.rule)).toContain('list-view-object-outside-closure'); |
| 764 | + }); |
| 765 | + |
| 766 | + it('the public `narrowObjectsToPackageClosure` stays the four-limb closure — limb 5 is the write\'s', () => { |
| 767 | + const names = (narrowObjectsToPackageClosure(objects, SCOPE) as AnyRec[]).map((o) => o.name); |
| 768 | + expect(names).not.toContain('showcase_task'); |
| 769 | + }); |
| 770 | + |
| 771 | + it('datasetBoundObjectNames reads the two bound positions and nothing else', () => { |
| 772 | + expect([...datasetBoundObjectNames('dashboard', board({}), datasets)]).toEqual(['showcase_task']); |
| 773 | + expect([...datasetBoundObjectNames('report', report({}), datasets)]).toEqual(['showcase_task']); |
| 774 | + expect(datasetBoundObjectNames('view', { chart: { dataset: 'showcase_task_metrics' } }, datasets).size).toBe(0); |
| 775 | + expect(datasetBoundObjectNames('dashboard', board({}), undefined).size).toBe(0); |
| 776 | + }); |
| 777 | +}); |
0 commit comments