Repository navigation
Commit ba4ecf1
fix(service-analytics): refuse a derived measure currency that contradicts its operands' fixed code (#28043)
domain:server#4 · os-elon-musk · session_016WV4d1Np3hU7RQnA13YZcL
Fixes #28019
## 维护者速读
- 改了什么:数据集编译时,派生度量(derived sum / difference)若自行声明的 `currency`
与其操作数统一解析出的 `fixed` 币种不同,直接拒绝(`DATASET_INVALID` / 400),报错写明改法;重述同一币种仍合法。
- 为什么改:守卫 1 原先跳过派生度量,两个 EUR 固定币种的度量求和后声明 `currency: 'USD'`
能编译通过,结果列把欧元金额标成美元,没有任何提示(#28019)。
- 风险与回滚:收窄,`Clause-②: yes (narrowing)`、`Metadata-protocol:
narrowed`、`minor`;此前能编译的这类数据集现在被拒,仓内没有数据集用到该形态,已部署租户若有,报错会点名要删的
`currency`。回滚即还原本 PR。
-
先看:`packages/services/service-analytics/src/measure-currency-coherence.ts`
守卫 1 末尾新增的 fixed 判断,`src/__tests__/record-currency-analytics.test.ts`
新增的固定测试。
- 两分钟验证:`pnpm --filter @objectstack/service-analytics exec vitest run
src/__tests__/record-currency-analytics.test.ts`,49 例全绿;修复前其中 5 例红。
- 需要你做的:无(契约复审由席位在本 head 上做,席位按本任落地授权落地)。
Clause-②: yes (narrowing) — a dataset that declared a derived measure's
`currency` against its operands' single `fixed` code compiled before and
is refused now
Metadata-protocol: narrowed
## What changes
- `measure-currency-coherence.ts`, Guard 1: a derived measure that
declares a `currency` is now also compared with its resolved currency
(`resolvedOf`). When every monetary operand resolves to one `fixed` code
and the declared code differs, compile refuses with `DATASET_INVALID` /
400. The sentence follows the existing fixed-field refusal: it names the
dataset, the derived measure, its operands, the operands' code, and the
fix (delete the measure's `currency`; the column takes the operands'
code). Operands reached through a fixed-code derived sum are covered
too.
- Unchanged: a derived measure that restates its operands' `fixed` code;
a derived measure whose operands resolve to no one `fixed` code (a
`fixed` amount with a tenant-currency one, a `ratio` / `product`); the
record-mode refusal on derived measures; Guard 2.
- The module header and Guard 1's comment describe the derived arm.
- One `minor` changeset for `@objectstack/service-analytics` (a dataset
value is refused, so `Metadata-protocol: narrowed`, as in #27579's
changeset for the sibling refusals), with the BREAKING note and the
ADR-0087 `not-required (no-migration-prescription)` disposition.
## Why
`{ derived: { op: 'sum', of: ['eur_a', 'eur_b'] }, currency: 'USD' }`
over two EUR-fixed measures compiled, and `enrichResultColumns` let the
declared `USD` label a column of euros. Guard 1 skipped derived measures
for the fixed comparison (`const field = m.derived ? undefined :
fieldOf(m)`), although `resolvedOf` already knew the operands' common
`fixed` code. Triage (6518908209) ruled that Guard 1 judges derived
measures too and that restating the same code stays legal.
## Verification
- Red first: on the unfixed tree `record-currency-analytics.test.ts`
gives 5 failed / 44 passed. The 5 are the derived sum and difference
pins, the fixed-code derived sum pin, and the `queryDataset` and
draft-preview door pins; the controls (restated code, no one fixed code)
stay green.
- Ablation: with the new condition replaced by `false`, the same 5 go
red; restored, the blob equals HEAD's and `git diff HEAD` is empty.
- `pnpm --filter @objectstack/service-analytics test`: 196 files, 4759
passed / 282 skipped. `typecheck` exits 0. eslint on both changed files
exits 0.
- `dispatch-gates --commands`: 59 derived, 58 run green, 1 not measured
locally (`check:dual-build-cjs-loads` needs a whole-tree build), 0
unrun. Dogfood battery: 357 files / 2875 tests passed, 0 failures.
- The declaration lines were moved from the claim's first `no
(narrowing)` / `none` / `patch` to `yes (narrowing)` / `narrowed` /
`minor` before the push (claim amended); the gates above ran on the same
code.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4d1Np3hU7RQnA13YZcL
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 5f31470 commit ba4ecf1
3 files changed
Lines changed: 79 additions & 3 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
370 | 371 | | |
371 | 372 | | |
372 | 373 | | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
373 | 416 | | |
374 | 417 | | |
375 | 418 | | |
| |||
400 | 443 | | |
401 | 444 | | |
402 | 445 | | |
| 446 | + | |
403 | 447 | | |
404 | 448 | | |
405 | 449 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
| |||
147 | 150 | | |
148 | 151 | | |
149 | 152 | | |
150 | | - | |
| 153 | + | |
| 154 | + | |
151 | 155 | | |
152 | 156 | | |
153 | 157 | | |
| |||
176 | 180 | | |
177 | 181 | | |
178 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
179 | 192 | | |
180 | 193 | | |
181 | 194 | | |
| |||
0 commit comments