Repository navigation
Commit d4e4dfb
fix(formula): label() over a multi-select reads each selected option's label, joined (#34443)
Fixes #34339
Clause-②: no
Metadata-protocol: semantic
Skills-docs: follow-up #34444 (`skills/objectstack-formula/SKILL.md`,
the `label(record.f)` row; the multi-select join is taught in
content/docs/data-modeling/formulas.mdx in this PR)
## 维护者速读
- **改了什么**:公式 `label(record.X)` 作用在多选字段(`multiple: true` 的
select)上,不再出错读成 null,而是按读者语言输出每个已选项的标签,按记录里存储的顺序,用 `, ` 连接;空选择仍读
`''`,单选不变。
- **为什么改**:下游 CRM 报价行用多选字段 + `label()` 拼一句「无法估算毛利的原因」,在 18.5.0 上每条记录都读成
null,而 `os validate` / `os lint --strict` 都放行。
- **风险与回滚**:风险低。只有原先读成 null 的公式变成有文字;单选、空值、未知值的读法不变。和邮件模板 `option`
占位符走同一个拼接函数,两边不会再分叉。回滚即撤销本 PR。
- **先看**:`packages/formula/src/stdlib.ts` 的 `labelEachOption` 与
`optionLabelOf` /
`oneOptionLabel`;`packages/formula/src/template-engine.ts` 的 `option`
格式化器那一行;`packages/objectql/src/engine-formula-option-label.test.ts`
末尾新增的 describe。
- **两分钟验证**:`pnpm --filter @objectstack/formula exec vitest run
src/option-label.test.ts`,预期 18 个用例全绿(在 main 上其中 7 个红)。
- **需要你做的**:无,席位落地。
## What changes
`label(record.FIELD)` over a `multiple: true` select used to throw
(`renders ONE option value, and FIELD holds a list of values`), so the
formula field read null on every non-empty selection. It now reads:
| Value | Reads |
|---|---|
| `['no_sales_price', 'no_customer']` | `无销售价, 无客户` (zh-CN) / `No sales
price, No customer` (en-US) |
| `['no_freight_region']` | that one label |
| `[]`, `null` | `''` (unchanged; measured below) |
| a listed value no option declares | as stored, as the single-value
path reads an unknown value |
| a list holding an object | runtime fault, as an object value faults
today |
- **One rule, one helper.** `labelEachOption`
(`packages/formula/src/stdlib.ts`, package-internal) maps each listed
value through the caller's single-value lookup and joins with `, `. The
mail template's `option` hole (`template-engine.ts`,
`OPTION_ARGUMENT_RULE`) now calls the same helper instead of its own
`map(...).join(', ')`, so the two cannot drift. A unit test asserts
`label()` and `formatValue('option', …)` print the same string for the
same list.
- **Order: stored order.** Measured: `['no_freight_region',
'no_sales_price']` reads `No freight region, No sales price`, although
the options declare `no_sales_price` first. That is the order the
template engine already used. This is the claim's choice (claim
6923097287, Shape: "by the same rule the mail-template option hole
already uses"), and it differs from the card's words: ask 1 says "joined
with `, ` in option order" while naming the mail-template `option` hole
(`OPTION_ARGUMENT_RULE`) as precedent, and that hole measures STORED
order. So a reader of the downstream CRM quote line gets the labels in
the order the values were stored, not the order the options are
declared.
- **No `labels()` sibling, and no author-time refusal** (the card's ask
2): the card asks for it only "Until (1) ships", and ask 1 ships here;
claim 6923097287 (Shape) records that choice. Ruling 6919059607 is the
claim permission (batch 1), not a ruling on order or on ask 2.
- **The objectql seam needed no change.** `formula-option-labels.ts`
builds the label map from every served field that declares `options`,
whatever `multiple` says, with the translation bundle laid over it. The
real-engine pin below reads translated multi-select labels through it
unchanged.
- **Docs:** `content/docs/data-modeling/formulas.mdx` said "A
multi-value select is refused." It now teaches the join, the order and
the empty reading.
## Tests
- `packages/formula/src/option-label.test.ts`: a new describe for the
multi-select (zh-CN and en-US join, one element, stored order, empty
list and null, unknown value, composition, a field without options, an
object inside the list, and agreement with the mail `option` hole). The
old "refuses a list value" assertion is removed. An object value is
still refused, in its own case.
- `packages/objectql/src/engine-formula-option-label.test.ts`: a new
top-level describe on the real `ObjectQL` engine (stub driver, i18n
service with a zh-CN bundle) reads `label(record.gaps)` over a
multi-select in zh-CN and en-US, beside a single-select CONTROL on the
same record, plus the one-element and empty cases.
-
`packages/qa/dogfood/test/formula-option-label-locale.dogfood.test.ts`:
the fixture gains a multi-select and its formula. One new case reads it
through REST (`POST` / `GET /data/:object/:id` with `Accept-Language`)
in zh-CN and en-US, with the existing single-select name as the CONTROL,
plus the one-element, empty-list and unset cases.
## Acceptance notes
- `main` is red on `check:platform-checklist`
(`approvals.approver-resolution-matrix` VARIANTS STALE). That red is
main's, not this diff's; the seat has a stopgap PR. `Lint & Repo Gates`
will show it on this PR.
- A CEL read of a key the record does not carry (`record.gaps` on `{}`)
faults with `No such key` before `label()` runs. This is the same for a
single select and is not changed here. The engine hands formulas every
declared field, so a stored record does not hit it.
## Verification
All readings below come from runs under `scripts/pm/os-verify-lock.sh`,
on a shared box.
- Final head `4a1ed6a82f`: the dogfood file alone, after `turbo run
build --filter='@objectstack/dogfood^...'` (70 tasks, exit 0): `pnpm
--filter @objectstack/dogfood exec vitest run --maxWorkers=1
test/formula-option-label-locale.dogfood.test.ts` gives `Test Files 1
passed (1)`, `Tests 6 passed (6)` (5 existing + the new multi-select
case). Lock VERDICT `command-exit 0`. Its red on main was not run; the
objectql pin carries the red-on-main reading.
<details><summary>Red on main (tests at c0547aa, formula source at
the merge base)</summary>
- `pnpm --filter @objectstack/formula exec vitest run --maxWorkers=2
src/option-label.test.ts`: `Tests 7 failed | 11 passed (18)`. Each of
the seven multi-select cases answered `{ ok: false, … }`.
- `pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2
src/engine-formula-option-label.test.ts`: `Tests 2 failed | 10 passed
(12)`, `AssertionError: expected null to be '无销售价, 无客户'`. The engine
logged the card's own line: `formula field 'gaps_note' on
'ol_quote_line' could not be evaluated, so it reads null …
label(record.gaps) renders ONE option value, and gaps holds a list of
values on this record.`
- The empty-selection case was already green on main at the engine
level: the engine reads `''` for `[]` and for `null` there, and still
does.
</details>
<details><summary>Green, and the ablation (one locked run at 6fa079a;
formula src unchanged since)</summary>
- `pnpm --filter @objectstack/formula build`: exit 0. `node
scripts/ablation-dist-preflight.mjs @objectstack/formula
'oneOptionLabel(field, item, options, true)'`: marker present in
`dist/index.js` and `dist/index.mjs`.
- objectql file: `Tests 12 passed (12)`.
- `pnpm --filter @objectstack/formula typecheck`: exit 0.
- Ablation: `node scripts/ablation-replace.mjs --file
packages/formula/src/stdlib.ts --anchor ' if (Array.isArray(value))
return labelEachOption(…);' --delete -- …`. Anchor count went from 1 to
0, blob `af2083df5155` to `a999c7ce79c1`. Formula rebuilt, `--absent`
preflight: marker absent from all 6 built files. Then objectql file
`Tests 2 failed | 10 passed (12)` and formula file `Tests 7 failed | 11
passed (18)`. Restore: `blob == HEAD (af2083d) and git diff HEAD is
empty`. Rebuilt, marker present again, objectql file `Tests 12 passed
(12)`.
- At the final head 4a1ed6a, which only drops one assertion from
`option-label.test.ts`: `pnpm --filter @objectstack/formula test` gives
`Test Files 67 passed (67)`, `Tests 1770 passed (1770)`.
</details>
<details><summary>Derived gates</summary>
At the final head `4a1ed6a82f`: `node scripts/pm/dispatch-gates.mjs
--commands` derived 94 commands, and all 94 were run locally, each exit
code captured before any pipe: 94 exit 0. `node
scripts/pm/dispatch-gates.mjs --ran` gives: `94 derived famil(ies)
accounted for — 94 run, 0 NOT-MEASURED (a DERIVED zero — all 94 recorded
an exit code and none of them is 3)`. CI's `Lint & Repo Gates` runs the
full farm.
</details>
- Dogfood battery: not owed (no `!` in the title, no `(narrowing)` arm).
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5kgF3mo9f7LXuv5hac)_
<!-- signed: repo:objectstack#1 · os-project-manager ·
session_01FEkQ5kgF3mo9f7LXuv5hac -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 6aeb665 commit d4e4dfb
7 files changed
Lines changed: 261 additions & 17 deletions
File tree
- .changeset
- content/docs/data-modeling
- packages
- formula/src
- objectql/src
- qa/dogfood/test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
308 | 313 | | |
309 | 314 | | |
310 | 315 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | | - | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| |||
100 | 101 | | |
101 | 102 | | |
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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
490 | 490 | | |
491 | 491 | | |
492 | 492 | | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
493 | 509 | | |
494 | 510 | | |
495 | 511 | | |
496 | 512 | | |
497 | 513 | | |
498 | | - | |
499 | | - | |
500 | | - | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
501 | 519 | | |
502 | 520 | | |
503 | 521 | | |
| |||
513 | 531 | | |
514 | 532 | | |
515 | 533 | | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
516 | 545 | | |
517 | 546 | | |
518 | 547 | | |
519 | | - | |
520 | | - | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
521 | 551 | | |
522 | 552 | | |
523 | 553 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
| 168 | + | |
| 169 | + | |
169 | 170 | | |
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
173 | 174 | | |
174 | | - | |
| 175 | + | |
175 | 176 | | |
176 | 177 | | |
177 | 178 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
215 | 215 | | |
216 | 216 | | |
217 | 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 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
53 | 69 | | |
54 | 70 | | |
55 | 71 | | |
56 | 72 | | |
57 | 73 | | |
58 | 74 | | |
59 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
60 | 83 | | |
61 | 84 | | |
62 | 85 | | |
| |||
142 | 165 | | |
143 | 166 | | |
144 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
145 | 187 | | |
0 commit comments