Skip to content

Commit 85a8fa0

Browse files
fix(lint)!: under a package closure, judge a dashboard or report filter key on another package's dataset against that dataset's object (#30005) (#30231)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgExW7pTnaDz9uWuFj6oaHvG)_ Fixes #30005 Clause-②: no (narrowing) Metadata-protocol: narrowed Skills-docs: updated here — content/docs/deployment/validating-metadata.mdx (the fourth-door paragraph) now names the fifth closure limb for dashboard and report writes; skills/** teaches neither the rules nor the closure. ## 维护者速读 - **改了什么:** 发布门按软件包闭包收窄 `objects` 时,dashboard 与 report 的写入额外保留「它所绑定的 dataset 的基础对象」(第五肢)。于是运行时包的看板用别的包的 dataset(如 `showcase_task_metrics`)时,`filter: {no_such_field: 'x'}` 在 widget 路径被 422 拒收;report 的 `runtimeFilter` 同理;正确的键照常发布。 - **为什么改:** 以前 `datasets` 不收窄、`objects` 收窄,dataset 找得到而它的对象被筛掉,两条筛选键规则走「对象不在快照里」的跳过分支,拼错的键发布 200,读者只看到空图块或报错面板。 - **风险与回滚:** 只多拒收闭包外 dataset 上「对象确实没有的字段」;第五肢只对 dashboard/report 生效,flow、列表视图、dataset 写入的闭包判定不变(有 pin)。公开函数 `narrowObjectsToPackageClosure` 签名与结果不变。回滚即撤 PR。 - **先看:** `packages/lint/src/runtime-gate.ts` 的 `datasetBoundObjectNames` 与 `narrowObjectsToWriteClosure` 的 Limb 5 一行;`buildRuntimeWriteSnapshotSet` 里调用处;测试文件末尾 `#30005` 一节。 - **两分钟验证:** `pnpm --filter @objectstack/lint exec vitest run src/runtime-gate.package-closure.test.ts`,预期 48 条全过(其中 #30005 一节 9 条)。 - **需要你做的:** 无,席位落地。 ## What changes **The gap.** `buildRuntimeWriteSnapshotSet` narrows `objects` to the written package's closure (ruling #9612) and carries `datasets` whole. A runtime package's dashboard bound to `showcase_task_metrics`, which the showcase package ships over `showcase_task`, therefore resolved its dataset but not the dataset's object, and `judgeDatasetFilterKeys` took skip 1 ("object this stack does not define") for every key. Both `widget-filter-field-unknown` and `report-filter-field-unknown` were silent, so `filter: { no_such_field: 'x' }` published. **The fix: route 1 of the card, bring the referenced dataset's object into the snapshot.** The closure gains a fifth limb, stated by the snapshot builder: an object survives narrowing when it is the base object of a dataset the written item binds. `datasetBoundObjectNames(type, item, datasets)` reads the bound names at the positions the two rules read (a dashboard's `widgets[].dataset`; a report's `dataset` and each joined block's `dataset`) and resolves them against the carried `datasets`. It answers the empty set for every other write type. The limb applies to the baseline, candidate and stored passes alike, as the existing four do. **Why route 1 and not route 2 (narrow `datasets` and give a cross-closure reference its own verdict).** - The card requires that a good key on the cross-package dataset still publishes. Under route 2, the cross-closure reference needs a verdict of its own; refusing it would break that requirement, and a non-refusing verdict still leaves the filter keys unjudged unless the object is brought in anyway. - The dataset door binds a cross-package dataset at run time against the dataset's own object, with no closure. Route 1 hands the rules exactly that universe, so the publish verdict matches what the door does. With no closure in force the same key was already refused; route 1 makes the scoped verdict equal the whole-collection one (pinned). - Route 1 changes no rule. Both rules keep their skips, so a key the dataset door binds (a field, a registry-injected column, a dotted path, a `$` operator) is not refused. **Why only dashboard and report writes.** Limb 5 re-admits an object the package did not declare. A write that names an object directly is judged against the closure on purpose: a flow trigger outside it is refused (`flow-trigger-unknown-object`), a list view bound outside it is refused (`list-view-object-outside-closure`), a dataset's base object outside it gets the closure fix line on `object-reference-unknown`. A list view's `chart.dataset` re-admitting the object the view lists would wave that verdict through. A dashboard or report reaches an object only through a dataset, so the type gate is the boundary. Pinned in both directions. **Public surface.** `narrowObjectsToPackageClosure` keeps its signature and its four-limb answer: the implementation moved to an internal `narrowObjectsToWriteClosure`, and the public function states an empty limb 5 (pinned). `datasetBoundObjectNames` is exported from the module for the test only, and is not on any package entry. That is why the declaration is `Clause-②: no (narrowing)`: nothing is widened. ## Tests New top-level `describe` in `packages/lint/src/runtime-gate.package-closure.test.ts` (the closure's existing harness), 9 cases: - LIT: the filer's repro, a runtime-package dashboard on `showcase_task_metrics` with `filter: { no_such_field: 'x' }`, refused with exactly `widget-filter-field-unknown` at `dashboards[0].widgets[0].filter.no_such_field`, severity `error`. - LIT: the same key on a report `runtimeFilter`, refused with `report-filter-field-unknown` at `reports[0].runtimeFilter.no_such_field`. - LIT: a joined report whose block binds that dataset: the container key and the block key are both refused. - CONTROL: `{ status: 'done' }`, `{ estimate_hours: { $gte: 1 } }` and the injected `created_at` publish clean on the widget and on the report. - The scoped verdict equals the whole-collection verdict for both repros (one finding each). - A widget on a dataset that resolves to nothing re-admits nothing: only `widget-dataset-unknown`. - DARK: a flow triggering on `showcase_task` and a list view of `showcase_task` with a `chart.dataset` on `showcase_task_metrics`, both under the same closure and context, are still refused. - The public `narrowObjectsToPackageClosure` still drops `showcase_task`. - `datasetBoundObjectNames` reads the two bound positions and answers empty for a view or with no datasets. <details><summary>Ablation (once, through `scripts/ablation-replace.mjs`)</summary> Mutation: limb 5 disabled, `datasetBoundObjects.has(name)) return true;` → `datasetBoundObjects.has(name) && !'ABLATED_30005') return true;`. The test imports `./runtime-gate.js` from source, so no build sits between the mutation and the run. ``` HEAD b37c73d ablation-replace: ok mutation landed: anchor 1 -> 0, blob c6fdac3 -> efeee56d4cce × ⭐ LIT — the filer's repro: a widget key the dataset's object lacks is REFUSED at the widget path × ⭐ LIT — the same key on a report `runtimeFilter` is REFUSED at its path × ⭐ LIT — a joined block on that dataset: the block key and the container key are both judged × the scoped verdict is now the whole-collection one — the closure no longer hides the finding Tests 4 failed | 5 passed | 39 skipped (48) ablation-replace: ok restored: blob == HEAD (c6fdac3) and `git diff HEAD` is empty ``` The five that stay green under the mutation are the controls, the dangling-dataset case, the DARK case and the two unit pins: they assert what the fix must not change. </details> <details><summary>Gates, local subset, on head `b37c73da8`</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 57 families; each exit code was recorded to a file before any pipe, then reconciled with `--ran`: ``` Run reconciliation — 57 derived, 56 run, 1 NOT-MEASURED, 0 UNRUN. NOT-MEASURED · DERIVED (1) — pnpm check:dual-build-cjs-loads [recorded exit 3 — PREREQUISITE NOT MET] ✓ dispatch-gates --ran: 57 derived famil(ies) accounted for — 56 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3). ``` - `pnpm check:dual-build-cjs-loads`: exit 3, it needs the whole workspace built. NOT MEASURED, left to CI. - `check-plugin-teardown-shape.mjs --self-test` and `pnpm check:lean-entry-closure` first exited 3 (shallow clone; `objectql` not built). After fetching the control commit and building the dogfood closure, both exited 0; those are the codes recorded. - Beyond the derivation: `pnpm --filter @objectstack/lint test` exit 0 (Test Files 193 passed, Tests 8003 passed), `pnpm --filter @objectstack/lint typecheck` exit 0, `pnpm lint` exit 0. </details> <details><summary>Dogfood battery, once, on head `b37c73da8` (the title carries `!` and the declaration a narrowing arm)</summary> Closure built with `turbo run build --filter='@objectstack/dogfood^...'`, then `pnpm --filter @objectstack/dogfood test` under `os-verify-lock.sh`: ``` Test Files 1 failed | 418 passed | 3 skipped (422) Tests 1 failed | 3487 passed | 36 skipped (3524) os-verify-lock: VERDICT command-exit 1 · held the lock 1363s (22m43s) ``` The one failure is not this change's: `test/update-by-id-refusal-order.dogfood.test.ts` › "control: an organization administrator, who reads the platform grant object, keeps the administration gate's sentence for a row and for no row" expects `403 PERMISSION_DENIED` for an update of a missing `sys_user_permission_set` id and receives `404 RECORD_NOT_FOUND`. It fails the same way alone (1 failed | 18 passed), and fails the same way with `packages/lint/src/runtime-gate.ts` restored to `origin/main` and `@objectstack/lint` rebuilt (the built `dist` carries 0 occurrences of `datasetBoundObjectNames`). The diff touches nothing on the data update path. Reported to the seat. </details> ## Acceptance notes - **#30006 meets a wider population.** The widget rule still refuses a bare dimension or measure name that is not a field of the object (#30006, serial behind this card, not touched here). Before this PR a cross-closure dataset was not judged at all, so that defect now also reaches dashboards on another package's dataset. The report rule already accepts a dimension name. - **Dotted keys.** Only the base object is re-admitted. A dotted key whose hop lands on an object outside the closure stays the rules' "unknowable" skip, never a refusal. - **The HTTP status.** The door maps a gate `error` to `422 INVALID_METADATA`; the cross-closure case is pinned in `packages/metadata-protocol/src/protocol.dashboard-dataset-publish-gate.test.ts` (the `#30005` block: a wrong key is refused 422 `INVALID_METADATA` at `dashboards[0].widgets[0].filter.no_such_field` with no active row; the `status` key saves). ## Verification ``` pnpm --filter @objectstack/lint exec vitest run src/runtime-gate.package-closure.test.ts ``` Expect 48 passed; the `#30005` block is the last `describe` in the file. <!-- signed: domain:server#3 · os-bill · session_01Utp6CbPxYq1wQmUNWvMZkC --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c045c34 commit 85a8fa0

5 files changed

Lines changed: 359 additions & 1 deletion

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@objectstack/lint': minor
3+
---
4+
5+
fix(lint)!: under a package closure, a dashboard widget `filter` or report `runtimeFilter` on another package's dataset is judged against that dataset's object, so a key the object lacks is refused at publish (#30005)
6+
7+
Clause-②: no (narrowing) — the runtime publish door, for a write that names its package, refuses a dashboard widget `filter` key or a report `runtimeFilter` key on a dataset outside the package's closure when the dataset's object has no such field, a body it accepted before. Nothing is widened: `narrowObjectsToPackageClosure` keeps its signature and its four-limb answer, and no export is added to any package entry.
8+
Metadata-protocol: narrowed
9+
Skills-docs: updated here — `content/docs/deployment/validating-metadata.mdx` (the fourth-door paragraph) now names the fifth closure limb for dashboard and report writes; `skills/**` teaches neither the rules nor the closure.
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed or renamed: DashboardWidgetSchema.filter and ReportSchema.runtimeFilter keep their shape and meaning, and a dataset outside the closure now gets the verdict a dataset inside it already got. A refused key never served the board or the report (every reader saw an empty tile or a Dataset query failed panel), so there is no rewrite that keeps what the author meant; the author names a real field, and the refusal says which. -->
12+
13+
**BREAKING** accept-set narrowing at the runtime publish door for `dashboard` and `report` writes (the per-item publish and the package draft publish; Studio, REST and MCP authors), for a write whose package is known. `os validate`, `os build` and `os lint` are unchanged: they never narrow to a closure.
14+
15+
- **Before.** The publish gate narrows the live `objects` to the written package's closure (the package, its declared dependencies, platform objects, rows with no package) but carries every dataset. A runtime package's dashboard on `showcase_task_metrics`, a dataset the showcase package ships over `showcase_task`, therefore found the dataset but not its object, and `widget-filter-field-unknown` and `report-filter-field-unknown` skipped the filter as "object not in this snapshot". `filter: { no_such_field: 'x' }` published `200`, and every reader saw an empty tile or an error panel.
16+
- **Now.** A dashboard or report write also carries the base object of each dataset it binds (`widgets[].dataset`; a report's `dataset` and each joined block's `dataset`), which is the object the dataset query resolves the filter against at run time. The same key is refused `422 INVALID_METADATA` at `dashboards[0].widgets[0].filter.no_such_field` (or `reports[0].runtimeFilter.no_such_field`), the verdict the same key already got on a dataset inside the closure or with no closure in force.
17+
- **Which rules now judge such a dataset.** Every rule that resolves a dashboard's or report's filter against the dataset's object, all six already judging datasets inside the closure: `widget-filter-field-unknown`, `widget-filter-field-not-included`, `dashboard-filter-field-unknown`, `dashboard-filter-field-not-included`, `dashboard-filter-field-unprovisioned` and `report-filter-field-unknown`.
18+
- **A dimension name as a widget filter key.** On a dataset outside the closure, a widget `filter` key that names a dimension of the dataset but no field of its object is now refused with `widget-filter-field-unknown`, as it already was on a dataset inside the closure. The dataset query binds such a key; the correction of that verdict, for both cases, is tracked in #30006.
19+
- **Accepted, as before.** Every key the object has, a registry-injected system column, a dotted relationship path, every `$` operator. A dotted key whose hop lands on an object the snapshot still does not carry is not judged.
20+
- **Not changed.** Only dashboard and report writes carry the extra objects. A flow trigger, a list view or a dataset base object outside the closure is still refused as before (`flow-trigger-unknown-object`, `list-view-object-outside-closure`, `object-reference-unknown`), and a list view's `chart.dataset` brings no object in.
21+
22+
**What an author does.** Nothing for a board or report whose filter keys name real fields. A refused key never filtered anything, so there is no rewrite that keeps what the author meant: name a field of the dataset's object. The refusal names the key and the nearest field.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,12 @@ findings the item **added** (#4463). Its package dimension narrows that context
745745
the written item's **package closure** — the written package, its declared
746746
dependencies, and unconditionally both platform/system objects and rows carrying
747747
no package provenance (#9612); a provenance it cannot read narrows nothing at all.
748+
A dashboard or report write also keeps the base object of each dataset it binds
749+
(a widget's `dataset`; a report's `dataset` and each joined block's), because the
750+
datasets are never narrowed and the dataset query resolves a filter against that
751+
object whichever package ships it: a filter key the object lacks is refused there
752+
just as it is on a dataset inside the closure (#30005). No other write type keeps
753+
it, so a flow or a list view never reaches an outside object through a dataset.
748754
That changes what a rule can **resolve**, never which rules run, and nothing at
749755
this door walks `packages[]`. Two rules are told the closure is in force. A flow
750756
whose trigger object is outside it is refused with `flow-trigger-unknown-object`

‎packages/lint/src/runtime-gate.package-closure.test.ts‎

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929
import { describe, expect, it } from 'vitest';
3030
import {
31+
datasetBoundObjectNames,
3132
narrowObjectsToPackageClosure,
3233
runRuntimeAuthoringRules,
3334
type RuntimePackageScope,
@@ -643,3 +644,134 @@ describe('the dataset door under a package closure, and the shared prescription
643644
expect(dataset.hint).toBe(`${clause}point it at an object inside that closure`);
644645
});
645646
});
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+
});

‎packages/lint/src/runtime-gate.ts‎

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ export interface RuntimePackageScope {
400400
dependencies: readonly string[];
401401
}
402402

403+
/** The empty limb-5 set: no object is reached through a dataset (#30005). */
404+
const NO_NAMES: ReadonlySet<string> = new Set<string>();
405+
403406
/**
404407
* `objects` reduced to the written item's package closure (#9612).
405408
*
@@ -418,12 +421,39 @@ export interface RuntimePackageScope {
418421
* 3. it belongs to the **written package** itself;
419422
* 4. it belongs to one of that package's **declared dependencies**.
420423
*
424+
* [#30005] A fifth limb, stated by the caller and empty unless it says so:
425+
*
426+
* 5. it is the **base object of a dataset the written item binds**
427+
* ({@link datasetBoundObjectNames}, for a dashboard or report write; the
428+
* snapshot builder states it, this public spelling never does).
429+
* `datasets` is never narrowed — a dashboard may bind another package's
430+
* dataset, and the dataset door binds it at run time against the
431+
* dataset's own object, closure or no closure — so a filter key on that
432+
* binding is judged against that object. Without
433+
* this limb the object fell out of the snapshot while its dataset stayed,
434+
* and `widget-filter-field-unknown` / `report-filter-field-unknown` took
435+
* their "object absent" skip: a misspelled key published and every reader
436+
* got an empty tile or an error panel.
437+
*
421438
* Pure, allocation-light, and total: a non-object member is kept rather than
422439
* inspected, because deciding it is not this function's job.
423440
*/
424441
export function narrowObjectsToPackageClosure(
425442
objects: readonly unknown[],
426443
scope: RuntimePackageScope | undefined,
444+
): readonly unknown[] {
445+
return narrowObjectsToWriteClosure(objects, scope, NO_NAMES);
446+
}
447+
448+
/**
449+
* {@link narrowObjectsToPackageClosure} with limb 5 stated — the one
450+
* implementation of both; the public spelling states an empty limb 5, so its
451+
* signature and answer are the four-limb ones they always were (#30005).
452+
*/
453+
function narrowObjectsToWriteClosure(
454+
objects: readonly unknown[],
455+
scope: RuntimePackageScope | undefined,
456+
datasetBoundObjects: ReadonlySet<string>,
427457
): readonly unknown[] {
428458
if (!packageScopeInForce(scope)) return objects;
429459
const reachable = new Set<string>([scope.packageId, ...scope.dependencies]);
@@ -436,12 +466,77 @@ export function narrowObjectsToPackageClosure(
436466
if (typeof owner !== 'string' || owner === '' || owner === OVERLAY_PROVENANCE_SENTINEL) return true;
437467
// Limbs 3 and 4.
438468
if (reachable.has(owner)) return true;
469+
// Limb 5 — reached through a dataset the written item binds (#30005).
470+
const name = (entry as AnyRec).name;
471+
if (typeof name === 'string' && datasetBoundObjects.has(name)) return true;
439472
// Limb 1 — checked last only because it is the rarest, never because it is
440473
// the weakest: it is the one limb with no escape.
441474
return isSystemObject(entry as AnyRec);
442475
});
443476
}
444477

478+
/**
479+
* The base objects of the datasets a written dashboard or report binds (#30005)
480+
* — limb 5 of {@link narrowObjectsToPackageClosure}.
481+
*
482+
* Read off the item at the positions the two dataset filter-key rules read:
483+
* a dashboard's `widgets[].dataset` (`validateWidgetBindings`, whose
484+
* dashboard-level filters resolve through the same widget datasets), a
485+
* report's `dataset` and each joined block's `dataset`
486+
* (`validateReportRuntimeFilters`). Each name is resolved against the carried
487+
* `datasets` collection, which is never narrowed; a name that resolves to
488+
* nothing contributes nothing (`widget-dataset-unknown` /
489+
* `chart-dataset-unknown` own that typo).
490+
*
491+
* ⛔ Every other write type answers the empty set, and that is the point, not
492+
* an omission. Limb 5 re-admits an object the package did not declare, and a
493+
* write that names an OBJECT directly is judged against the closure on
494+
* purpose: a flow trigger, a list view or a dataset's base object outside it
495+
* is refused (`flow-trigger-unknown-object` at `error` under a closure,
496+
* `list-view-object-outside-closure`, the closure fix line on
497+
* `object-reference-unknown`). A list view's `chart.dataset` re-admitting the
498+
* object the view lists would wave that verdict through. A dashboard or report
499+
* reaches an object only THROUGH a dataset, and the dataset door is what binds
500+
* it, so the re-admitted object is exactly the universe the door resolves the
501+
* filter in.
502+
*
503+
* Only the base object: a dotted key whose hop lands on an object the snapshot
504+
* still does not carry stays the rules' "unknowable" skip — never a refusal.
505+
*/
506+
export function datasetBoundObjectNames(
507+
type: string,
508+
item: unknown,
509+
datasets: readonly unknown[] | undefined,
510+
): ReadonlySet<string> {
511+
if (type !== 'dashboard' && type !== 'report') return NO_NAMES;
512+
if (!item || typeof item !== 'object' || !Array.isArray(datasets) || datasets.length === 0) return NO_NAMES;
513+
const body = item as AnyRec;
514+
const bound = new Set<string>();
515+
const note = (v: unknown): void => {
516+
if (typeof v === 'string' && v !== '') bound.add(v);
517+
};
518+
if (type === 'dashboard') {
519+
for (const w of Array.isArray(body.widgets) ? body.widgets : []) {
520+
if (w && typeof w === 'object') note((w as AnyRec).dataset);
521+
}
522+
} else {
523+
note(body.dataset);
524+
for (const b of Array.isArray(body.blocks) ? body.blocks : []) {
525+
if (b && typeof b === 'object') note((b as AnyRec).dataset);
526+
}
527+
}
528+
if (bound.size === 0) return NO_NAMES;
529+
const objects = new Set<string>();
530+
for (const ds of datasets) {
531+
if (!ds || typeof ds !== 'object') continue;
532+
const { name, object } = ds as AnyRec;
533+
if (typeof name === 'string' && bound.has(name) && typeof object === 'string' && object !== '') {
534+
objects.add(object);
535+
}
536+
}
537+
return objects;
538+
}
539+
445540
/**
446541
* Whether `scope` narrows anything (#9612): a stated, non-empty package id.
447542
*
@@ -769,9 +864,17 @@ export function buildRuntimeWriteSnapshotSet(
769864
// ⛔ Applied to BOTH passes, necessarily. The gate's verdict is
770865
// candidate MINUS baseline, so narrowing one side and not the other would
771866
// not be a smaller input — it would be a different question.
867+
//
868+
// [#30005] `datasets` stays whole, so the objects a written dashboard or
869+
// report binds THROUGH a dataset are kept beside the closure (limb 5,
870+
// {@link datasetBoundObjectNames}) — in both passes, by the same rule.
772871
const raw = (args.context?.[key] ?? []) as readonly AnyRec[];
773872
const collection = key === 'objects'
774-
? (narrowObjectsToPackageClosure(raw, args.packageScope) as readonly AnyRec[])
873+
? (narrowObjectsToWriteClosure(
874+
raw,
875+
args.packageScope,
876+
datasetBoundObjectNames(args.type, item, args.context?.datasets),
877+
) as readonly AnyRec[])
775878
: raw;
776879
if (key === stackKey) {
777880
baseline[key] = collection.filter((o) => !itemName || o?.name !== itemName);

0 commit comments

Comments
 (0)