Repository navigation
Commit 6bc775f
fix(rest): /meta negotiates the request locale against the held locales before it picks a pack (#36561)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi92ncfFpPUpTD8314otX5oaG)_
Fixes #36466
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:应用以英文编写、默认面向中文用户、并持有英文语言包时,浏览器语言为美式英语等地区写法的用户,在对象元数据接口里看到的对象名称由中文变为英文原文,和同一请求下保存报错里的名称一致;没有对应语言包的语言仍按默认语言显示。
- 为什么做:多语言标签统一的后续:让元数据接口和服务端各处读者用同一种方式把地区语言写法对到已有语言包。
- 出错会怎样:最坏情况是某个地区语言写法的用户看到的对象名称语言不对,不影响数据和权限,合并后可直接回退。
- 要你做什么:无
## What changes
The card's ruling, quoted: "Make the `/meta` read
(`packages/rest/src/meta-item-read-gate.ts`) negotiate the request tag
the way the other readers do before it picks a pack. No spec change."
- `metaTranslateOptions` (the `ResolveOptions` every metadata-document
translation builds) now carries `locale` as the request tag negotiated
against the locales the i18n service reports: `resolveBundleLocale`
(`@objectstack/spec/system`, the platform's one locale ladder) over
`getLocales()`. That is the question objectql's
`negotiatedMessageLocale` and plugin-approvals' `negotiatedReaderLocale`
already ask, over the same set. Neither of those is importable from
`@objectstack/rest` without a new export (objectql does not export it;
plugin-approvals is downstream), so a private helper beside it
(`negotiatedTranslationLocale`) repeats only the offered-set plumbing
and calls the shared rule. It adds no second rule and no new export.
- The tag passes through untouched when there is nothing to negotiate
against: no service, no `getLocales`, a throwing, empty or non-array
answer, or no match. So a locale the deployment holds no pack for still
walks the declared chain to the default locale.
- Reach: `metaTranslateOptions` is the one builder, so the item read and
the list read on both transports (`RestServer` and the runtime
dispatcher, which share `translateMetaDocument` / `translateMetaList`),
the view container, the stale-plural rule, the `GET /meta` types listing
and the public form's object labels (`translateOptionsFor` delegates
here) all read the negotiated tag. The doc locale collapse
(`resolveDocLocale`) and `extractLocale`'s other callers (export, import
template) are untouched.
- No `packages/spec` change.
## Tests
New top-level describe `#36466 §7` in
`packages/rest/src/meta-i18n-declared-fallback-chain.test.ts`, the
shared harness of the `/meta` i18n pins (§6 is this deployment's
`sourceLocale` case). The fixture is `sourceLocale: 'en'`,
`defaultLocale: 'zh-CN'`, the chain collapsed to `zh-CN`, a `zh-CN`
pack, and an `en` pack that holds no `account` rows.
- Card pin 1: an `en-US` request with only an `en` pack reads `Account`
from `/meta` (item read, list read, and bare `en` agree).
- Card pin 2: a request for a locale with no pack at all (`fr-FR`), and
a header-less request, still read the default locale (`客户`).
- Control: with no `en` locale held, `en-US` has nothing to negotiate to
and walks to `客户`; `zh` still reads the `zh-CN` pack.
- Acceptance parity: for `en-US` and `fr-FR`, `/meta`'s label and the
label objectql's `DELETE_RESTRICTED` (code and status asserted) names on
the same i18n service are the same (`Account` and `客户`), and the other
one is absent.
- Cached arm (`getMetaItemCached`, the default door): `en-US` is served
`Account` and `en` the same body; the `en-US` validator revalidates its
own request (`304`); sent with `zh-CN` or `fr-FR` it answers `200` with
`客户`, never a `304` for the English body.
## Acceptance notes
- **Cache key (measured, unchanged here).** The cached arm's validator
is the protocol's hash of the untranslated document folded with the tag
the request SENT (`extractLocale`, `meta-item-read-routes.ts`, #1319).
Translation runs after it with the negotiated tag. So within a running
server each sent tag maps to one body: `en-US` and `en` get separate
validators over identical bodies (fewer shared `304`s, never a wrong
one), and a validator never crosses languages (pinned above). Keying the
validator on the negotiated tag would need `meta-item-read-routes.ts`,
outside this card's file surface, so it is raised as a question in the
report. Not pinned, because it is already true of any pack edit: the
validator hashes no translation input, so a client that cached an
`en-US` body before this deploy can be answered `304` on the old `客户`
body until the document changes.
- **plugin-security does not negotiate (measured; the card's premise
holds for objectql and the #36464 readers only).** Reading taken with a
scratch copy of `controlled-by-parent-master-edit-user-message.test.ts`
(deleted, not committed) on an i18n service with `sourceLocale: 'en'`,
`defaultLocale`/fallback `zh-CN` and an `en` pack: the master-detail
refusal's `userMessage` names the master `Contract` for `en`, `合同` for
`en-US`, and `Contract` for `fr-FR`. `denialLocaleOf` returns the raw
request tag and `denialLabels` hands it to `translateObject` as written.
So after this PR, `/meta` (`Contract`) and plugin-security (`合同`) still
disagree for `en-US`, and for `fr-FR` (`/meta` serves `合同`,
plugin-security falls back to an `en` sentence naming `Contract`). This
is reported for the seat to file, not fixed here.
- The public form and the `GET /meta` types listing negotiate too,
because they read the same builder. That is the same defect class on the
same function; no pin was added for them.
## Verification
Two-minute check: `pnpm --filter @objectstack/rest exec vitest run
--maxWorkers=2 src/meta-i18n-declared-fallback-chain.test.ts`. Expect 30
passed, including `#36466 §7 … an en-US request with only an en pack
reads Account`.
Read first:
1. `packages/rest/src/meta-item-read-gate.ts`, the
`metaTranslateOptions` hunk (`locale:
negotiatedTranslationLocale(service, locale)`) and the new helper below
it.
2. `packages/rest/src/meta-i18n-declared-fallback-chain.test.ts`, the
`#36466 §7` describe (the parity and cached-arm cases).
<details><summary>Test readings (head 5555e3e)</summary>
- `pnpm --filter @objectstack/rest test && pnpm --filter
@objectstack/rest typecheck` under the verify lock: Test Files 427
passed (427), Tests 8788 passed, 351 skipped (9139); `tsc --noEmit` and
`check:test-typecheck` OK (0 files in debt). Lock VERDICT command-exit
0.
- New describe alone: Test Files 1 passed (1), Tests 30 passed (30).
Lock VERDICT command-exit 0.
- Dependency closure built first: `pnpm --workspace-concurrency=2
--filter '@objectstack/rest^...' build`, lock VERDICT command-exit 0.
The parity case reads `@objectstack/objectql` from that build.
</details>
<details><summary>Ablation (fix committed first)</summary>
`node scripts/ablation-replace.mjs --file
packages/rest/src/meta-item-read-gate.ts --anchor 'locale:
negotiatedTranslationLocale(service, locale),' --replacement 'locale, /*
ABLATION-36466 */' -- …vitest run …
meta-i18n-declared-fallback-chain.test.ts`: anchor 1 to 0, marker 0 to
1, blob 3b1e091 to e2c5192f903c. The test imports
`./rest-server.js` from source, so no dist step is involved. Result: 3
failed, 27 passed. Red: `an en-US request with only an en pack reads
Account`, `for the same request, /meta and objectql name the object with
the same label`, and the cached-arm case. The no-pack, no-en and `zh`
controls stayed green. Restore: blob equals HEAD (3b1e091), and
`git diff HEAD` is empty.
</details>
<details><summary>Gates</summary>
Derived with `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` at 5555e3e: 69 commands (3 changed
paths). Each was run with stdin closed and its exit captured before any
pipe.
- 69 of 69 exit 0. Two needed a second pass. `check:type-check-debt` hit
the per-command 420 s cap (exit 124) on the first pass; re-run alone, it
reported `OK — 0 ledger entr(ies) re-measured … 0 raw tsc error(s)`,
exit 0. `check:dual-build-cjs-loads` exited 3 (PREREQUISITE NOT MET, no
full build); after `pnpm turbo run build --concurrency=2
--filter='!@objectstack/docs'` (lock VERDICT command-exit 0, 120/120
tasks) it reported `124 published require entry point(s) across 72
package(s) load`, exit 0.
- `--ran` reconciliation: `69 derived famil(ies) accounted for — 69 run,
0 NOT-MEASURED`.
- `node scripts/pm/overlap-check.mjs --branch=HEAD`: `VERDICT clean exit
0` (merges cleanly with origin/main d463c46; no open PR head shares a
file).
- CI at 5555e3e: all 53 check-runs completed, each success or
skipped. Among them: Lint & Repo Gates, TypeScript Type Check, Test Core
(10/10), Build Core, Governed Surface Queue Guard, Live E2E UI, Test UI,
Dogfood Regression Gate, Check Changeset.
</details>
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmRB34k9WUWeGpRnVNm
<!-- signed: repo:objectstack#2 · os-steve ·
session_01ADHkmRB34k9WUWeGpRnVNm -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent b572420 commit 6bc775f
3 files changed
Lines changed: 249 additions & 2 deletions
File tree
- .changeset
- packages/rest/src
| 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 | |
|---|---|---|---|
| |||
438 | 438 | | |
439 | 439 | | |
440 | 440 | | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
3306 | 3306 | | |
3307 | 3307 | | |
3308 | 3308 | | |
| 3309 | + | |
| 3310 | + | |
| 3311 | + | |
| 3312 | + | |
| 3313 | + | |
| 3314 | + | |
| 3315 | + | |
| 3316 | + | |
3309 | 3317 | | |
3310 | 3318 | | |
3311 | 3319 | | |
| |||
3317 | 3325 | | |
3318 | 3326 | | |
3319 | 3327 | | |
3320 | | - | |
| 3328 | + | |
| 3329 | + | |
| 3330 | + | |
3321 | 3331 | | |
3322 | 3332 | | |
3323 | 3333 | | |
3324 | 3334 | | |
3325 | 3335 | | |
| 3336 | + | |
| 3337 | + | |
| 3338 | + | |
| 3339 | + | |
| 3340 | + | |
| 3341 | + | |
| 3342 | + | |
| 3343 | + | |
| 3344 | + | |
| 3345 | + | |
| 3346 | + | |
| 3347 | + | |
| 3348 | + | |
| 3349 | + | |
| 3350 | + | |
| 3351 | + | |
| 3352 | + | |
| 3353 | + | |
| 3354 | + | |
| 3355 | + | |
| 3356 | + | |
| 3357 | + | |
| 3358 | + | |
| 3359 | + | |
| 3360 | + | |
| 3361 | + | |
| 3362 | + | |
| 3363 | + | |
| 3364 | + | |
| 3365 | + | |
| 3366 | + | |
3326 | 3367 | | |
3327 | 3368 | | |
3328 | 3369 | | |
| |||
0 commit comments