Repository navigation
Commit 8a33dff
fix(service-analytics)!: the dataset draft preview mints and judges an undeclared measure as the live strategies do, so a misspelled measure is refused INVALID_FIELD instead of answered as a row count (#28210)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DLMAJ9kZMBicdMLygftCdLd)_
domain:server#3 · os-elon-musk · session_016WV4cyQNVxpxREGfKkTsqs
Fixes #28172
Clause-②: no (narrowing) — a draft-preview dataset query (`queryDataset`
with `previewDrafts: true` over a pending seed draft) now refuses a
selected measure that the native and ObjectQL strategies refuse, which
it served as a row count before. No export, answer member, status or
error code is added: the refusals are the live faces' existing
`INVALID_FIELD` / 400 and `PERMISSION_DENIED` / 403.
Metadata-protocol: none
## 维护者速读
- 改了什么:数据集草稿预览遇到数据集未声明的度量,过去一律按 `count(*)` 给行数;现在按实时查询同一套铸造规则(`<字段>_sum`
等后缀、裸字段名即求和)生成度量,并在读种子行前过实时查询的同一组度量闸门。拼错的 `nope`、`ghost_avg` 现在与实时一样按
400 `INVALID_FIELD` 拒,消息逐字相同;`amount_sum`、`amount` 现在给出与实时相同的 SUM
值,不再是行数。
- 为什么改:草稿里的错别字显示一个看似合理的数,发布后才被拒;能用的推断度量在草稿里也显示错的数。
- 风险与回滚:只影响草稿预览路径上未声明的度量;已声明度量、时长度量、派生度量和 `count` 不变,实时策略不变。回滚即 revert。
- 先看:`packages/services/service-analytics/src/analytics-service.ts` 里
`answerDataset` 的 `previewService.query`(新增的铸造与闸门),同文件
`mintCallerMeasures`(从 `ensureCube` 抽出的共用循环);`preview-evaluator.ts`
的度量聚合步。
- 两分钟验证:`pnpm --filter @objectstack/service-analytics exec vitest run
src/__tests__/preview-undeclared-measure-parity.test.ts`,预期 10 passed。
- 需要你做的:无,席位落地。
## What changes
**The draft preview's measure step (`analytics-service.ts`,
`answerDataset` → `previewService.query`).** Before evaluating seed
rows, the preview now does for a measure the dataset does not declare
what the published path's `ensureCube` does:
- mints it with `mintCallerMeasures`, the loop `ensureCube` ran inline,
now extracted and shared by both: the `<cube>.` qualifier rule
(`mintableMeasureKey`, a dotted non-qualifier measure refused), then
`inferMeasure`'s suffix convention (`_sum` / `_avg` / `_min` / `_max` /
`_count_distinct`, a bare name meaning its sum, a spelling that names no
field refused). Declared measures, declared dotted keys and dataset
duration measures are never minted, as before;
- asks `assertMeasureFields` (#4437): a source field the object does not
have is refused `INVALID_FIELD` / 400 with the same message, `Valid
measures:` listing the declared ones;
- asks the measure position of the #21156 column-reference gate,
extracted from `assertCallerMembersResolvable` as
`assertCallerMeasuresResolvable` (no behaviour change on the live path):
a spelling that is not a column reference (`amount + 1`) is refused
`PERMISSION_DENIED` / 403;
- asks the #21044 aggregate × field-type door
(`assertMeasureFieldTypes`), which the live path asks in `ensureCube`:
`region_sum` over a text field is refused `INVALID_FIELD` / 400, where
the preview would otherwise sum no number and read `0`;
- hands the cube WITH the minted measures to the preview's existing
gates (stored-body, internal-field, field-level read, record-currency)
and to the evaluator, as the live gates read the cube after
`ensureCube`. So a minted measure is judged by the field it aggregates:
`secret_sum` is refused 403 when the caller may not read `secret`.
Without this, minting on the preview would sum a field the field gate
never saw (`namedQueryFields` skips a measure the cube does not carry).
**The evaluator (`preview-evaluator.ts`,
`evaluateAnalyticsQueryOverRows`).** A measure the cube it is handed
does not carry is refused `INVALID_FIELD` / 400 (`invalidMemberError`,
member and valid measures named) instead of being read as `count(*)`.
The production caller never reaches it now (it hands over the minted
cube); it stops the silent fallback from coming back.
**Answers that change value.** On the preview, an inferred measure over
a real field (`amount_sum`, `amount`, …) now answers the live value
instead of a row count. The changeset says so.
**Unchanged.** Declared, duration and derived measures, the undeclared
`count`, and both live strategies.
**Not in this PR.** An undeclared DIMENSION has the same gap on the
preview (`dimensions: ['bogus']` is refused `INVALID_FIELD` live and
served as one `null` group on the preview). Measured here, reported to
the seat and carded as #28201.
## Why
Measured on `main` `35f20551`, real SQLite engine, a dataset declaring
`total` (sum of `amount`) and `deals` (count), `dimensions: ['region']`:
| measure | native | ObjectQL | draft preview (before) | draft preview
(after) |
|:---|:---|:---|:---|:---|
| `nope` | `INVALID_FIELD` / 400 | `INVALID_FIELD` / 400 | `{amer: 2,
emea: 1}` | `INVALID_FIELD` / 400, same message |
| `ghost_avg` | `INVALID_FIELD` / 400 | `INVALID_FIELD` / 400 | `{amer:
2, emea: 1}` | `INVALID_FIELD` / 400, same message |
| `amount_sum` | `{amer: 150, emea: 30}` | `{amer: 150, emea: 30}` |
`{amer: 2, emea: 1}` | `{amer: 150, emea: 30}` |
| `amount` | `{amer: 150, emea: 30}` | `{amer: 150, emea: 30}` | `{amer:
2, emea: 1}` | `{amer: 150, emea: 30}` |
| `region_sum` (text) | `INVALID_FIELD` / 400 | `INVALID_FIELD` / 400 |
`{amer: 2, emea: 1}` | `INVALID_FIELD` / 400, same message |
| `amount + 1` | `PERMISSION_DENIED` / 403 | `PERMISSION_DENIED` / 403 |
`{amer: 2, emea: 1}` | `PERMISSION_DENIED` / 403, same message |
| `total` (declared), `count` | served | served | served, same values |
served, same values |
The live faces do not refuse every undeclared measure: they infer one
over a real field. So the triage rule ("refuses a measure the dataset
does not declare with the live faces' envelope … pin native, ObjectQL
and draft-preview parity") is implemented as parity: the preview refuses
exactly what the live faces refuse, with their envelope, and serves what
they serve. The seat confirmed this reading before the fix.
## Verification
-
`packages/services/service-analytics/src/__tests__/preview-undeclared-measure-parity.test.ts`
(new, 10, real SQLite engine through `queryDataset`, each case on all
three faces): `nope` and `ghost_avg` refused `INVALID_FIELD` / 400 with
`param`, `field`, `measure` and a message identical across native,
ObjectQL and preview; `amount_sum` and `amount` served `{amer: 150,
emea: 30}`; `region_sum` refused `INVALID_FIELD` / 400 and `amount + 1`
refused `PERMISSION_DENIED` / 403, preview message identical to native;
CONTROLS: declared `total` and undeclared `count` serve the same values
on every face; the evaluator refuses an uncarried measure (and serves a
carried one); a minted `secret_sum` is refused `PERMISSION_DENIED` / 403
naming `secret` on the preview and on a live strategy when the caller
may not read `secret`.
- Ablations (each on the source, pins rerun): both source files reset to
`main` ⇒ 8 red, the 2 CONTROLs green (one of the 8, the field-read case,
was added after this run and is covered by ablation A); A: the preview's
field-read gate given the cube without the minted measures ⇒ the
`secret_sum` case red; B: no field-type door on the preview ⇒ the
`region_sum` case red; C: no caller-measure gate on the preview ⇒ the
`amount + 1` case red; D: no `assertMeasureFields` on the preview ⇒ the
`nope` and `ghost_avg` cases red. Every added gate's pin bites on its
own.
- `pnpm --filter @objectstack/service-analytics exec vitest run` at head
(merged with `main` `1e45a4e1`): 198 files, 4788 passed, 282 skipped, 0
failed. `pnpm --filter @objectstack/service-analytics typecheck` and
eslint on the touched files clean.
- `check-issue-citations` and `check:doc-authoring` green at head. Every
`dispatch-gates --commands` family (62), `pnpm lint` and the dogfood
battery run at the final head: the readings are posted on the card with
the os-dev report.
Skills-docs: none. `git grep -n -i -E "previewDrafts|draft (data
)?preview" -- skills content/docs` (references excluded) finds
`content/docs/data-modeling/currency.mdx:146` (the currency door covers
the preview: still true) and release notes; nothing in `skills/` or
`content/docs/` describes how the preview answers an undeclared measure.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (Not touched.)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English (the 维护者速读 block is the
lane's maintainer summary).
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4cyQNVxpxREGfKkTsqs)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4cyQNVxpxREGfKkTsqs
Co-authored-by: Claude <noreply@anthropic.com>1 parent 1ea3fe9 commit 8a33dff
4 files changed
Lines changed: 382 additions & 20 deletions
File tree
- .changeset
- packages/services/service-analytics/src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
0 commit comments