Skip to content

Commit d9fabb2

Browse files
fix(metadata-protocol): the publish probes skip a missing widget dataset, not check the read's envelope (#34669)
Fixes #34560 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:发布后的运行时探针在读取仪表盘组件引用的数据集时,若数据集不存在,现在按「图问题」跳过,不再把读取结果的外层信封当成数据集去检查。 - 为什么改:按名称读取元数据时,条目不存在会返回一个 item 为空的外层信封,而不是空值;读取函数把信封本身当成了数据集,导致该组件被计入「已检查」,还会报出一条假的「组件查询失败」(已实测复现)。 - 风险与回滚:极低。只改一行读取逻辑:信封里没有 item 就返回空;存在的数据集读取方式不变。回滚即还原该行。 - 先看:`packages/metadata-protocol/src/build-probes.ts`(`publishedItemReader` 的返回行);`packages/metadata-protocol/src/build-probes-dataset-holders.test.ts`(新增的 `[#34560]` 用例组)。 - 两分钟验证:`pnpm --filter @objectstack/metadata-protocol exec vitest run src/build-probes-dataset-holders.test.ts`,预期 13 个用例全部通过。 - 需要你做的:无,席位落地。 ## What changes `publishedItemReader` (the item read the ADR-0038 L3 publish probes use, over the protocol facade at `protocol-history-and-publish.ts`) returned `wrapper?.item ?? wrapper`. The real by-name read `getMetaItem` answers an item nothing holds with its envelope (`{ type, name, item: undefined, lock, editable, … }`), never a throw and never `undefined`, so the reader handed the envelope to the widget plane as the dataset body. A widget naming a missing dataset was then counted in `checked.widgets`, and its query ran over the envelope, which reports a false `widget_query_failed`. The reader now returns the envelope's `item` alone (`envelope?.item`). A dataset that exists is read exactly as before; a missing one reads as no body, so the widget takes the dangling-dataset path again (an L1 graph finding, not probed, not counted). Why the fallback existed: it was born with the probes (`106ce3d1dc`, ADR-0038 L3) as a defensive spread for a protocol that might answer a bare body. No producer ever did: `getMetaItem` answered an envelope then and answers one now. Every double that feeds `publishedItemReader` was checked, and none returns a bare body: - `build-probes-dataset-holders.test.ts` (the `#31700` protocol double): answers `{ item }`, `undefined`, or throws `PackageScopedNameRefusedError`; - `packages/rest/src/analytics-routes.test.ts` and `packages/runtime/src/domains/meta-qualified-item-read.test.ts`: drive the real `ObjectStackProtocolImplementation`, on datasets that exist or that are refused. `packages/metadata-protocol/src/build-probes-dataset-holders.test.ts` gains a top-level `[#34560]` describe that drives `ObjectStackProtocolImplementation` itself (its real `getMetaItem` and `resolveCallerPackageAddress`) over a registry double that reads `dataset` by package, as `SchemaRegistry` does. So the envelope under test is the one the read builds, not a hand-copied one. It covers both reader arms, from the publishing package (the publish path) and by name: - the real read answers `missing_ds` with an envelope whose `item` is undefined, and the reader returns `undefined` for it; - the widget plane: `checked.widgets` is 1 (only the existing dataset), no issue codes, and only `own_ds` is queried; - CONTROL: an existing dataset is handed over as its body (no `item` key). `scripts/engine-double-contract.pinned.json` gains one row: the new engine double's `findOne` is pinned through `assertEngineFindOnePredicate`, and `check:engine-double-contract` asks the ledger to record it (`--write`: 1 row added, 0 lost). ## Tests Premise, measured on the unmodified `build-probes.ts` (`origin/main` `082f9c2945`) with the new pin: 4 of the new cases fail, with the real envelope and the false finding in the output. <details><summary>Premise reading on origin/main source</summary> ```text × read from package com.qa.app: the real read answers a missing dataset with its envelope, and the reader hands the probes no body × read from package com.qa.app: the widget takes the L1 skip path: not counted, not queried, no widget_query_failed × read by name: the real read answers a missing dataset with its envelope, and the reader hands the probes no body × read by name: the widget takes the L1 skip path: not counted, not queried, no widget_query_failed AssertionError: expected { type: 'dataset', …(7) } to be undefined + Received: { "deletable": true, "editable": true, "item": undefined, "lock": "none", "name": "missing_ds", "resettable": false, "type": "dataset", "version": null } AssertionError: expected { checked: 2, …(2) } to deeply equal { checked: 1, codes: [], …(1) } - "checked": 1, - "codes": [], + "checked": 2, + "codes": [ "widget_query_failed" ], "queried": [ + "missing_ds", "own_ds", Tests 4 failed | 9 passed (13) ``` </details> <details><summary>After the fix</summary> ```text src/build-probes-dataset-holders.test.ts Tests 13 passed (13) pnpm --filter @objectstack/metadata-protocol exec vitest run --maxWorkers=2 Test Files 348 passed | 9 skipped (357) Tests 23052 passed | 45 skipped (23097) os-verify-lock: VERDICT command-exit 0 pnpm --filter @objectstack/metadata-protocol typecheck (tsc --noEmit; --listFiles includes the test file) os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Ablation: restore the fallback, the pin goes red; restore, the blob equals HEAD</summary> `node scripts/ablation-replace.mjs` on `build-probes.ts`, anchor `return envelope?.item;` replaced with `return envelope?.item ?? envelope ?? undefined;` (the pre-fix fallback). The test imports `./build-probes.js` by relative specifier, so it reads `src/`, not `dist/`. ```text ablation-replace: anchor x1 -> x0 ablation-replace: replace " return envelope?.item ?? envelope ?? undefined;" x0 -> x1 ablation-replace: ok mutation landed: anchor 1 -> 0, blob feb1269 -> de11d1693def Tests 4 failed | 9 passed (13) (the same four cases as the premise reading) ablation-replace: ok restored: blob == HEAD (feb1269) and `git diff HEAD` is empty ``` </details> ## Acceptance notes - The analytics double in the pin refuses a body that binds no object. That is how the false `widget_query_failed` shows up in the test. Whatever the real analytics service does with an envelope, the reader fix keeps the envelope from reaching it. - The registry double declares `dataset` read by package (`readsByPackage`), as `SchemaRegistry` does. With `NO_PACKAGE_SCOPED_READS` alone, the real read refuses the bare `dataset` read as unjudgeable (ADR-0150 D2/D3) before it reaches the envelope. ## Verification Every reading below was taken at head `aaafe49eff` (the branch with `origin/main` merged in; `main` had moved `meta-compile-cache.ts` / `meta-overlay-cache.ts` in this package, which `getMetaItem` reads through, so the package suite was run again after the merge). - `pnpm --filter @objectstack/metadata-protocol exec vitest run --maxWorkers=2` then `pnpm --filter @objectstack/metadata-protocol typecheck`: Test Files 348 passed | 9 skipped (357), Tests 23056 passed | 45 skipped (23101); `VERDICT command-exit 0`. - Derived gate families (`node scripts/pm/dispatch-gates.mjs --commands`, derived at `aaafe49eff`): 73 run, each exit code captured before any pipe; `--ran` reconciliation: `Run reconciliation — 73 derived, 73 run, 0 NOT-MEASURED, 0 UNRUN.` The dist-reading families (`check:dual-build-cjs-loads`, `check:lean-entry-closure`, `check:dts-closure`, `check:published-files`) ran after a full `turbo run build --filter=!@objectstack/docs` (`VERDICT command-exit 0`) and a rebuild of this package after the merge. - Not run locally, declared to CI: `test:repo`, and the importers' suites in `@objectstack/rest` and `@objectstack/runtime` (the reader's exported type is unchanged; its answer changes only for an item nothing holds, which neither suite reads). Dogfood: n/a (no `!` in the title, `Clause-②: no`). <details><summary>Gate record (command :: exit code)</summary> ```text node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-adoption.mjs :: exit 0 node scripts/check-comment-mask-adoption.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-dts-emitted.mjs --self-test :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 node scripts/check-issue-citations.mjs :: exit 0 node scripts/check-plugin-teardown-shape.mjs :: exit 0 node scripts/check-plugin-teardown-shape.mjs --self-test :: exit 0 node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0 node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0 node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0 node scripts/ci/snapshot-next.mjs --self-test :: exit 0 node scripts/docs-audit/check-affected-docs.mjs :: exit 0 node scripts/docs-audit/check-drift-comment.mjs :: exit 0 node scripts/pm/check-governed-queue-guard.mjs --self-test :: exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0 node scripts/release-pending-publish.mjs --self-test :: exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0 pnpm --filter @objectstack/spec run check:error-code-provenance :: exit 0 pnpm check:adr-anchors :: exit 0 pnpm check:agent-test-spelling :: exit 0 pnpm check:bash32-floor :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 pnpm check:ci-filter-parity :: exit 0 pnpm check:cli-command-ids :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:dispatcher-error-vocabulary :: exit 0 pnpm check:doc-authoring :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:dts-closure :: exit 0 pnpm check:dual-build-cjs-loads :: exit 0 pnpm check:durability-log-level :: exit 0 pnpm check:engine-double-contract :: exit 0 pnpm check:entry-guard :: exit 0 pnpm check:error-code-casing :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:issue-citations :: exit 0 pnpm check:keyed-text-bounds :: exit 0 pnpm check:lean-entry-closure :: exit 0 pnpm check:logger-receiver-detach :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:object-def-param-keys :: exit 0 pnpm check:objectql-double-limit :: exit 0 pnpm check:org-identifier :: exit 0 pnpm check:page-declaration-shape :: exit 0 pnpm check:parse-guard :: exit 0 pnpm check:platform-object-tenancy-census :: exit 0 pnpm check:pnpm-filter-targets :: exit 0 pnpm check:pnpm-flag-spellings :: exit 0 pnpm check:published-files :: exit 0 pnpm check:query-options-erasure :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:registry-log-declared :: exit 0 pnpm check:rest-log-spy-declared :: exit 0 pnpm check:scripts-symbol-anchors :: exit 0 pnpm check:slot-lookup :: exit 0 pnpm check:sourcemap-no-sources-content :: exit 0 pnpm check:system-context-census :: exit 0 pnpm check:test-source-alias :: exit 0 pnpm check:tier-file-adoption :: exit 0 pnpm check:type-check-coverage :: exit 0 pnpm check:type-check-debt :: exit 0 pnpm check:undeclared-dep-imports :: exit 0 pnpm check:vouch-for-reference-callers :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm check:where-matcher :: exit 0 ``` </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmPJxG4vBVaLCBWLcWJ)_ <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmPJxG4vBVaLCBWLcWJ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0004e8d commit d9fabb2

4 files changed

Lines changed: 137 additions & 2 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol): the publish probes skip a widget whose dataset does not exist instead of checking the read's envelope
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The by-name read `getMetaItem` answers an item that does not exist with its envelope, `item` empty, not with `undefined`. The publish probes' reader (`publishedItemReader`) fell back to that envelope when it carried no `item`, so a dashboard widget naming a dataset nothing holds was handed the envelope as its dataset. The widget was counted in `checked.widgets`, and its query ran over a body that binds no object, which could report a false `widget_query_failed` on the publish receipt and in `verify_build`. The reader now answers no body when the envelope carries no `item`, so such a widget takes the dangling-dataset path again: an L1 graph finding, not probed and not counted. A dataset that exists is read exactly as before.

‎packages/metadata-protocol/src/build-probes-dataset-holders.test.ts‎

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import { describe, expect, it } from 'vitest';
2121
// clocked window (`pnpm check:test-source-alias`).
2222
import '@objectstack/lint';
2323
import { PackageScopedNameRefusedError, type PackageScopedRefusal } from '@objectstack/core';
24+
import { assertEngineFindOnePredicate } from '@objectstack/metadata-core';
2425
import { publishedItemReader, runBuildProbes, type ProbeEngine, type ProbeItemProtocol } from './build-probes.js';
26+
import { ObjectStackProtocolImplementation } from './protocol.js';
27+
import { NO_PACKAGE_SCOPED_READS } from './no-package-scoped-reads.testkit.js';
2528

2629
const ALPHA = 'com.qa.alpha';
2730
const BETA = 'com.qa.beta';
@@ -186,3 +189,116 @@ describe('[#31700] the probes read a widget\'s dataset from the publishing packa
186189
expect(issue!.fix).toContain('would be a cycle, so move the dashboard into that package');
187190
});
188191
});
192+
193+
/**
194+
* [#34560] A widget whose dataset does not exist, read through the REAL
195+
* by-name read: `getMetaItem` answers a missing item with its envelope
196+
* (`{ type, name, item: undefined, lock, editable, … }`), never a throw and
197+
* never `undefined`. The reader the publish uses (`publishedItemReader`, over
198+
* the protocol facade) must hand the probes no body for it, so the widget
199+
* takes the dangling-dataset path (an L1 graph finding, skipped here): it is
200+
* not counted in `checked.widgets`, no dataset query runs, and no
201+
* `widget_query_failed` is reported. The doubles above answer `undefined` for
202+
* a missing item, which is why none of them reached this.
203+
*
204+
* The protocol here is `ObjectStackProtocolImplementation` itself over a
205+
* registry double (the shape `protocol.item-execution-read.test.ts` drives),
206+
* so the envelope is the one the read builds, not a hand-copied one.
207+
*/
208+
describe('[#34560] a missing widget dataset under the real getMetaItem envelope is skipped, not checked', () => {
209+
const APP = 'com.qa.app';
210+
const REGISTRY_ITEMS: Record<string, unknown> = {
211+
'dashboard board': {
212+
name: 'board',
213+
widgets: [
214+
{ id: 'w_missing', dataset: 'missing_ds', values: ['total'] },
215+
{ id: 'w_own', dataset: 'own_ds', values: ['total'] },
216+
],
217+
},
218+
'dataset own_ds': { name: 'own_ds', object: 'task_item', measures: [{ name: 'total', aggregate: 'count' }] },
219+
};
220+
const held = (type: string, name: string): unknown => {
221+
const item = REGISTRY_ITEMS[`${type} ${name}`];
222+
return item === undefined ? undefined : structuredClone(item);
223+
};
224+
225+
function realProtocol() {
226+
const engine: Record<string, unknown> = {
227+
registry: {
228+
...NO_PACKAGE_SCOPED_READS,
229+
// `dataset` is read by package (ADR-0150 D3), as
230+
// `SchemaRegistry` reads it: `own_ds` is held by package APP,
231+
// and `missing_ds` by no one, so its read answers no item.
232+
readsByPackage: (type: string): boolean => type === 'dataset' || NO_PACKAGE_SCOPED_READS.readsByPackage(type),
233+
packageScopedHoldersOf: (type: string, name: string): string[] =>
234+
type === 'dataset' && held(type, name) !== undefined ? [APP] : [],
235+
getPackageScopedItem: (type: string, name: string, packageId: string): unknown =>
236+
packageId === APP ? held(type, name) : undefined,
237+
getItem: (type: string, name: string) => held(type, name),
238+
getObject: () => undefined,
239+
listItems: () => [],
240+
getPackage: () => undefined,
241+
getArtifactItem: () => undefined,
242+
isPackageDisabled: () => false,
243+
isObjectPackageDisabled: () => false,
244+
registerItem: () => undefined,
245+
registerObject: () => undefined,
246+
applyNavContributions: (app: unknown) => app,
247+
},
248+
writeEpoch: { current: 0, bump: () => 1, subscribe: () => () => {} },
249+
registerMiddleware: () => undefined,
250+
find: async () => [],
251+
findOne: async (table: string, q: Record<string, unknown> = {}) => {
252+
assertEngineFindOnePredicate(table, q as never);
253+
return null;
254+
},
255+
};
256+
const services = new Map<string, unknown>();
257+
return new ObjectStackProtocolImplementation(engine as never, () => services as Map<string, never>) as unknown as ProbeItemProtocol;
258+
}
259+
260+
// The publish reads FROM the publishing package (`request.packageId`);
261+
// with no package the dataset is read by name. Both arms of the reader.
262+
for (const publisher of [APP, undefined]) {
263+
const arm = publisher === undefined ? 'read by name' : `read from package ${publisher}`;
264+
265+
it(`${arm}: the real read answers a missing dataset with its envelope, and the reader hands the probes no body`, async () => {
266+
const protocol = realProtocol();
267+
const envelope = (await protocol.getMetaItem({
268+
type: 'dataset', name: 'missing_ds', ...(publisher !== undefined ? { packageId: publisher } : {}),
269+
})) as Record<string, unknown>;
270+
expect(envelope, 'the by-name read answers an envelope, not undefined').toBeTypeOf('object');
271+
expect(envelope).toMatchObject({ type: 'dataset', name: 'missing_ds' });
272+
expect(Object.prototype.hasOwnProperty.call(envelope, 'item')).toBe(true);
273+
expect(envelope.item).toBeUndefined();
274+
expect(await publishedItemReader(protocol, publisher)('dataset', 'missing_ds')).toBeUndefined();
275+
});
276+
277+
it(`${arm}: the widget takes the L1 skip path: not counted, not queried, no widget_query_failed`, async () => {
278+
const queried: unknown[] = [];
279+
const report = await runBuildProbes({
280+
engine,
281+
getItem: publishedItemReader(realProtocol(), publisher),
282+
analytics: {
283+
// Refuses a body that binds no object, as a dataset query
284+
// over nothing can only fail: the shape of the false
285+
// `widget_query_failed` the envelope used to produce.
286+
queryDataset: async (dataset: any) => {
287+
queried.push(dataset?.name);
288+
if (typeof dataset?.object !== 'string') throw new Error('dataset binds no object');
289+
return { rows: [{ total: 1 }] };
290+
},
291+
},
292+
published: [{ type: 'dashboard', name: 'board' }],
293+
});
294+
expect({ checked: report.checked.widgets, codes: report.issues.map((i) => i.code), queried })
295+
.toEqual({ checked: 1, codes: [], queried: ['own_ds'] });
296+
});
297+
298+
it(`${arm}: CONTROL — a dataset the real read finds is handed over as its body`, async () => {
299+
const body = await publishedItemReader(realProtocol(), publisher)('dataset', 'own_ds');
300+
expect(body).toMatchObject({ name: 'own_ds', object: 'task_item' });
301+
expect(body).not.toHaveProperty('item');
302+
});
303+
}
304+
});

‎packages/metadata-protocol/src/build-probes.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,14 @@ export function publishedItemReader(
274274
const address = protocol.resolveCallerPackageAddress({ type, name, callerPackageId: publishingPackageId });
275275
if (address.kind === 'package') packageId = address.packageId;
276276
}
277-
const wrapper = (await protocol.getMetaItem({ type, name, ...(packageId !== undefined ? { packageId } : {}) })) as
277+
const envelope = (await protocol.getMetaItem({ type, name, ...(packageId !== undefined ? { packageId } : {}) })) as
278278
| { item?: unknown }
279279
| undefined;
280-
return wrapper?.item ?? wrapper ?? undefined;
280+
// [#34560] The by-name read answers a missing item with its envelope,
281+
// `item` empty, never `undefined`: the body is the envelope's `item`
282+
// alone, so a dataset nothing holds reads as no body (the widget
283+
// plane's dangling-dataset skip), never as the envelope itself.
284+
return envelope?.item;
281285
};
282286
}
283287

‎scripts/engine-double-contract.pinned.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@
256256
"verb": "update",
257257
"pinned": 1
258258
},
259+
{
260+
"file": "packages/metadata-protocol/src/build-probes-dataset-holders.test.ts",
261+
"verb": "findOne",
262+
"pinned": 1
263+
},
259264
{
260265
"file": "packages/metadata-protocol/src/meta-compile-cache.test.ts",
261266
"verb": "findOne",

0 commit comments

Comments
 (0)