Repository navigation
Commit 6296909
fix(spec): a deployment's validation override prints a written value as written (#35325)
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgRuogP8Tp8XyFXLc92Bxvo6)_
repo:objectstack#5 · os-bill · session_01Utp6CZiaBg6rk7dpy1s9Me
Fixes #34509
Clause-②: no
Metadata-protocol: none
## 维护者速读
- **改了什么:** `renderValidationMessage` 向部署方的 `validation.field.*`
覆盖文案只要模板(不再把参数交给 i18n 服务),由渲染器自己填一次占位符;两个 `translate` 选项的注释写明这一点。
- **为什么改:** i18n 服务拿到参数会自己填一遍,渲染器再填一遍。用户写入的值里如果带 `{{label}}`
之类,第二遍会把它换成字段名,报错句子就引错了用户写的内容。
- **风险与回滚:** 只改展示文字,错误码、状态码、返回的 `value` 字段都不变;只用 `{{name}}`
占位符的覆盖文案读出来与以前一样。函数签名不变。回滚即 revert 本 PR。
- **先看:** `packages/spec/src/system/validation-message.ts` 中
`opts.translate(key, locale)` 那一行(原来带
`params`);`packages/spec/src/system/validation-message.override-once.test.ts`。
- **两分钟验证:** `pnpm --filter @objectstack/spec exec vitest run
--maxWorkers=2 src/system/validation-message.override-once.test.ts`,预期 2
个用例通过。
- **需要你做的:** 无,席位落地(合入前由区线程安排 L2 契约复核)。
## What changes
- `renderValidationMessage` (`@objectstack/spec/system`) asks the
deployment override as `opts.translate(key, locale)`, with no params,
and interpolates the answer once. Before, it passed `params` to the
translator (which, like `FileI18nAdapter.t`, fills `{{name}}` itself)
and interpolated the answer again, so a written value containing a
placeholder was expanded on the second pass. This is the shape
`renderOperationMessage` already has.
- Fold-in (accepted nit N2 of contract record 6932332429): the
`translate` option docblocks on `RenderValidationMessageOptions` and
`RenderOperationMessageOptions` say the lookup is asked for the template
with no params. The type `ValidationMessageTranslator` and both option
signatures are unchanged (`check:api-surface`: unchanged).
- Changeset: `@objectstack/spec` patch.
## Tests
New file
`packages/spec/src/system/validation-message.override-once.test.ts`: an
interpolating translator (fills `{{name}}` from params, as
`FileI18nAdapter.t` does) overrides `invalid_option_value`, which echoes
`{{value}}`; the written value is `{{label}} plan`. The override path
must print it as written. CONTROL leg: the built-in path (no override),
which was already single-pass.
<details><summary>Red leg (test committed before the fix,
128113d)</summary>
```
× prints a written value containing a placeholder as written on the override path
Expected: "套餐的取值「{{label}} plan」无效,请从 basic, pro 中选择"
Received: "套餐的取值「套餐 plan」无效,请从 basic, pro 中选择"
Tests 1 failed | 1 passed (2)
os-verify-lock: VERDICT command-exit 1
```
</details>
<details><summary>Green leg (c0ed09b)</summary>
```
validation-message.override-once.test.ts + validation-message.test.ts + operation-message.test.ts
Test Files 3 passed (3)
Tests 99 passed (99)
os-verify-lock: VERDICT command-exit 0
```
</details>
## Acceptance notes
- A1 (callers that pass a `translate`): only `objectql`
`record-validator` (through `engine-validation-messages.ts`) and `core`
`import-coerce` (through `import-runner`) hand `renderValidationMessage`
a translator; `rest` `form-routes`, `service-settings` and
`service-messaging` `actor-reference` pass none. Every translator found
is a wrapper over `II18nService.t` (`FileI18nAdapter.t`, the core memory
fallback), which looks up by key and locale and uses params only to
interpolate. None needs params at lookup time.
- A2: the published `.d.ts` of
`RenderValidationMessageOptions.translate` is still `translate?:
ValidationMessageTranslator`; only its docblock changed. Clause-② no.
- The test is a new file, as the claim's file surface names. The twin
pin for `renderOperationMessage` sits in `operation-message.test.ts`; a
reviewer who prefers the pin as a top-level `describe` in
`validation-message.test.ts` can ask for the move.
- The `RenderOperationMessageOptions` docblock is in
`operation-message.ts`, not `validation-message.ts` as the claim's file
surface reads; the claim names that docblock, so the one comment edit
there is in scope.
## Verification
All readings are at head `c0ed09b721`.
- `pnpm --filter @objectstack/spec build`: `VERDICT command-exit 0`. The
dependency closure of `@objectstack/spec` is empty.
- `pnpm --filter @objectstack/spec test`: Test Files 856 passed (856),
Tests 27366 passed, 1 todo; `VERDICT command-exit 0`.
- `pnpm --filter @objectstack/spec typecheck`: `VERDICT command-exit 0`.
- Gate families derived by `node scripts/pm/dispatch-gates.mjs
--commands` (83): 80 exit 0, 3 exit 3 (PREREQUISITE NOT MET, they read
workspace `dist/` not built here): `check:doc-formula-expressions`
(`@objectstack/formula`), `check:dual-build-cjs-loads`,
`check:lean-entry-closure` (`@objectstack/objectql`). NOT MEASURED
locally; CI's `Lint & Repo Gates` runs them. `--ran` reconciliation: 83
derived, 80 run, 3 NOT-MEASURED, 0 UNRUN.
- `check:api-surface`: public API surface and factory signatures
unchanged. `check:docs`: 249 generated files in sync. `check:nul-bytes`:
OK.
- `pnpm check:dev-prereqs` (local only): exit 1, "The workspace is not
built" (35 of 108 packages, all outside this diff). This is a reading of
this machine, not of the diff.
- `node scripts/pm/overlap-check.mjs
--branch=claude/issue-34509-validation-override-once`: `VERDICT clean
exit 0`.
- `test:repo` and the full dogfood battery are not run locally: the
title carries no `!` and no `(narrowing)` arm; CI's `Test Core` runs
`test:repo`. Consumer packages' tests (`objectql`, `core`) are left to
CI: the public surface is byte-unchanged in signature.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent e4bfa33 commit 6296909
4 files changed
Lines changed: 82 additions & 5 deletions
File tree
- .changeset
- packages/spec/src/system
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
541 | | - | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
542 | 546 | | |
543 | 547 | | |
544 | 548 | | |
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
352 | | - | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
353 | 357 | | |
354 | 358 | | |
355 | 359 | | |
| |||
383 | 387 | | |
384 | 388 | | |
385 | 389 | | |
386 | | - | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
387 | 397 | | |
388 | 398 | | |
389 | 399 | | |
390 | 400 | | |
391 | 401 | | |
392 | | - | |
393 | | - | |
| 402 | + | |
394 | 403 | | |
395 | 404 | | |
396 | 405 | | |
| |||
0 commit comments