You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c94191d
Browse filesBrowse the repository at this point in the historyBrowse files
fix(service-print, spec): the print door's 5xx sentences follow the request's language (#37272)
Fixes#37260
repo:objectstack#4 · os-justin · session_01QSeKYnagJvGbCtNg2PhvgW
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:在中文(以及日文、西班牙文)界面里点击打印,若服务器上的打印引擎未就绪、打印超时或服务器出错,提示条现在用界面语言显示;英文界面与以前一字不差。
- 为什么做:报价单打印失败时中文界面弹出整句英文,看起来像坏了,业务用户也看不懂;这是该缺陷卡(打印失败提示不跟随界面语言)本身。
- 出错会怎样:最坏情况是某种语言的提示措辞不够好,状态码与错误码都不变,不影响打印本身;可直接撤回本改动。
- 要你做什么:无。
## What changes
- `packages/spec/src/system/operation-message.ts`: four keys in the
platform's operation-message catalog (`BUILTIN_OPERATION_MESSAGES`), in
all four locales it carries (`en`, `zh-CN`, `ja-JP`, `es-ES`):
`print_engine_unavailable` (503), `print_timed_out` (504),
`print_failed` (the 5xx fallback) and `print_caller_unresolved` (the
door's caller-resolution 500). English is byte-identical to the fixed
text the door answered before. No placeholder; the header documents them
beside the other keys.
- `packages/services/service-print/src/print-routes.ts`:
`serverAnswerFor(status, locale)` maps the status to its catalog key and
renders it through `operationUserMessage` (`@objectstack/core`), the
shared helper the platform's other localized refusals use;
`relayPrintFailure` and the caller-resolution fault pass the request's
top `Accept-Language` tag (`preferredLocaleFromHeader`). The door reads
no query parameter, so `?locale` is not a source. Code, status, the
fault log and the 4xx relay are unchanged.
- `packages/services/service-print/vitest.config.ts`: aliases
`@objectstack/spec/system` to source like the other spec subpaths, so
the new import is judged against this checkout, never a stale `dist/`.
The mechanism reused, not a new one: the operation-message catalog plus
`operationUserMessage` is the platform's one seat for localized
user-facing server sentences (its header: "a second mechanism for the
second producer is exactly what this module exists to prevent"). The
door's `message` itself is localized, because `sendServerFault`'s
`message` is already the route's generic user-facing text (the thrown
detail goes only to the fault log) and `sendServerFault` declares no
`userMessage` channel; widening it would change an `@objectstack/types`
export outside this card's file surface.
The action path from the repro (`POST
/api/v1/actions/crm_quote/print_quote`) produces no sentence of its own
for these failures: the `/actions` door forwards a same-origin `type:
'api'` action in-process with `accept-language` on its header allowlist
(`API_FORWARD_HEADER_ALLOWLIST`,
`packages/runtime/src/action-execution.ts`) and relays the target's
refusal envelope with its `message` as written (`restAnswerOf`,
`forward-refused`, `packages/runtime/src/action-dispatch.ts`). So fixing
the door fixes the action toast; nothing changed in `packages/runtime`.
Bounded in-place fix, declared: the caller-resolution 500 (`The caller
of this print could not be resolved.`) is the same door's own 5xx
sentence, the same defect class, the same file in the claim's surface,
the same gate family; it is localized the same way and pinned below.
### Read first
1. `packages/services/service-print/src/print-routes.ts` (the
`requestLocaleOf` / `serverAnswerKeyFor` / `serverAnswerFor` hunk) — the
only behaviour change.
2. `packages/spec/src/system/operation-message.ts` — the 16 new catalog
strings; the zh-CN, ja-JP and es-ES wording is the review risk.
3. `packages/services/service-print/src/print-routes.test.ts` — the new
top-level `describe`.
### Two-minute verification
`pnpm --filter @objectstack/service-print exec vitest run --maxWorkers=2
src/print-routes.test.ts` — expect 36 passed, including ten under "its
own 5xx sentences, in the request's language".
## Tests
All at head `3dfbfdb5a`.
- `pnpm --filter @objectstack/service-print test` — Test Files 9 passed
(9), Tests 145 passed (145).
- `pnpm --filter @objectstack/spec test` — Test Files 891 passed (891),
Tests 28371 passed, 1 todo.
- `pnpm --filter @objectstack/service-print typecheck` exit 0; `pnpm
--filter @objectstack/spec typecheck` exit 0 (tsc, scripts and test
typecheck).
- New pins (door, `print-routes.test.ts`): 503, 504 and 500 under
`accept-language: zh-CN,zh;q=0.9,en;q=0.8` answer the zh-CN catalog
sentence and not the English one; the control: `en-US` and an absent
header answer the English sentence, for each of the three; the English
sentences equal the pre-change text; `ja` reaches ja-JP and `de-DE`
falls back to English; the caller-resolution 500 in zh-CN and absent; a
4xx keeps its producer's text under zh-CN.
- New pins (catalog, `operation-message.test.ts`): all four keys in
every locale, placeholder-free, naming no wire code or host vocabulary,
distinct from every other key, rendering zh-CN / es / en fallback.
<details><summary>Ablation: hard-coded English restored, zh pins turn
red</summary>
`node scripts/ablation-replace.mjs` on `print-routes.ts`, anchor `return
operationUserMessage(serverAnswerKeyFor(status), { locale });` replaced
with the three original hard-coded English returns. The test imports the
subject by relative path and aliases core/spec to source, so no build
stands between the mutation and the run.
```
ablation-replace: anchor x1 -> x0
ablation-replace: blob 44b2c38 -> 97403a9b77a977dc80088aafb8a207052ec53393
ablation-replace: ok mutation landed: anchor 1 -> 0, blob 44b2c38 -> 97403a9b77a9
× no print engine ready: SERVICE_UNAVAILABLE / 503 under accept-language zh-CN answers the zh-CN sentence
× the render ran past its time: TIMEOUT / 504 under accept-language zh-CN answers the zh-CN sentence
× an undeclared fault: INTERNAL_ERROR / 500 under accept-language zh-CN answers the zh-CN sentence
× a base language reaches its regional catalog (ja → ja-JP); a language the catalog lacks answers English
Tests 4 failed | 32 passed (36)
ablation-replace: ok restored: blob == HEAD (44b2c38) and `git diff HEAD` is empty
```
The three English controls stayed green under the mutation, as they
should.
</details>
<details><summary>Gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands` derived 91 families for
this diff; all 91 were run at `3dfbfdb5a`, each exit captured before any
pipe. Reconciliation (`--ran` with exit codes): `✓ 91 derived famil(ies)
accounted for — 88 run, 3 NOT-MEASURED (3 DERIVED from a recorded exit
3)`.
- 88 exit 0.
- NOT MEASURED: `node scripts/check-plugin-teardown-shape.mjs
--self-test`, reason: shallow clone cannot reach its pinned
positive-control commit.
- NOT MEASURED: `pnpm check:dual-build-cjs-loads`, reason: reads every
package's built output; only the service-print closure was built here.
- NOT MEASURED: `pnpm check:type-check-debt`, reason: its re-measure
queued on the shared verify lock behind a long dogfood run (exit 99
twice).
All three run in CI on this PR. `test:repo` was not run locally (no diff
in that project); declared to CI's `Test Core`.
</details>
## Acceptance notes
- The language source is the request's `Accept-Language` only. The
door's execution context carries no locale and no workspace default
(`requestLocale: undefined`, `localization: undefined`), so
`operationUserMessage`'s second rung (the workspace default) has nothing
to read here; the console sends its UI language on every call, which is
the issue's case.
- No deployment `errors.print_*` translation override is consulted:
`operationUserMessage` is the helper for producers that hold no i18n
service, and the door holds none.
- The door's own 4xx refusals (the impersonation refusal, the
request-shape refusals) stay English developer text; they are outside
this card, which names the 5xx sentences.
- Observation only, not filed: the `/actions` door's own
forward-unavailable sentence (`apiActionForwardUnavailableError`, 503)
and the print bridge's `501` are English too; neither is on this card's
path when the door is mounted, and neither was reproduced here.
- Clause-② measured: no new export, no type change, no new envelope
field, no new input read as a contract (any header was already
accepted); the catalog gains entries in an existing exported `Record`
value, and the wire `message` changes language only for a non-English
request.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QSeKYnagJvGbCtNg2PhvgW)_
Co-authored-by: Claude <noreply@anthropic.com>
The print door (`POST /api/v1/print/records`) now answers its own 5xx sentences in the request's language. A print that fails on the server because the print engine is not ready (`503`), ran past its time (`504`), failed for any other reason (`500`), or could not resolve its caller (`500`) used to answer a fixed English `error.message` whatever the request's `Accept-Language`, so a Chinese console showed the toast in English. The sentences are now four keys of the platform's operation-message catalog (`print_engine_unavailable`, `print_timed_out`, `print_failed`, `print_caller_unresolved` in `BUILTIN_OPERATION_MESSAGES`, `@objectstack/spec/system`) in `en`, `zh-CN`, `ja-JP` and `es-ES`, written through `operationUserMessage` (`@objectstack/core`) in the request's top `Accept-Language` tag. A print clicked as a `type: 'api'` action answers the same way: the `/actions` door forwards the caller's `Accept-Language` and relays the door's `message` as written.
10
+
11
+
Code, status and the English text do not change: a request in English, with no `Accept-Language`, or in a language the catalog carries no text for, reads the same sentence as before. What the engine or the host said is still withheld from the wire and kept in the server fault log.
0 commit comments