Repository navigation
Commit f5da514
feat(lint): the metadata save door advises on a translation key nothing declares (#38648)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9JeHmqv6CKCkW8ewrPBLekk)_
Fixes #38623
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 在 Studio、元数据接口或 AI
助手里保存或发布一条翻译时,如果它指向一个已经不存在的对象、字段、校验规则、里程碑或权限集,保存结果里会多出一条提示;以前保存显示一切正常,什么都不说。
- 属于“错误的元数据要被明确指出”这项构建能力:本地校验早就会报这类问题,线上保存却静默通过,这次替在 Studio 和 AI
助手里写翻译的作者补上这个缺口。
-
出错的最坏情况是对一条其实有效的翻译多报一条提示,保存本身照常成功、不会被拒;应用的导航菜单和应用名这类翻译这次仍不检查,可以直接撤回这次改动。
- 无。
## What changes
A `translation` item saved (active) or published over the metadata API
now runs `validateTranslationReferences` at the runtime publish gate. An
orphan key comes back as a `translation-target-unknown` **advisory** on
the save and publish answer (`advisories`, severity `warning`). Before
this, no rule ran on a `translation` write
(`runtimeAuthoringRulesFor('translation')` was `[]`): the item was
accepted as valid while `os validate` refused the same key.
**Never a refusal.** Every finding on a translation write is a
`warning`, so it lands in `advisories` and never in the 422 `errors`. A
published item that names a key an upgrade removed still loads and
saves. `os validate` keeps reporting the same key at `error`.
**Families the door judges** (the ones the per-write snapshot carries,
`RuntimeStackContext`: objects, permissions, books, datasets):
- `objects.NAME`, only when the gate did not narrow `objects` to the
write's package closure. The i18n layer is process-wide, so a
translation may legitimately name an object outside its package's
closure.
- `objects.NAME.fields.FIELD`, and the field's `options` keys, only for
a field that declares options inline. A picklist-bound field's served
options are not in the snapshot.
- `objects.NAME._validations.RULE`
- `objects.NAME._milestones.FIELD.VALUE`
- `permissions.NAME`
**Not judged at the door:** apps and their navigation
(platform-contributed nav items included), `_views`, `_sections`,
`_tabs`, `_relatedLists`, `_actions`, `globalActions`, `dashboards`,
`forms`, `pages`, `picklists`, `positions`, `reports`, `mappings`,
`books` (the implicit per-package book is named by a package id the
snapshot never sees), `flows`, `hooks`. Each resolves into a collection
no per-write snapshot carries, so the door never guesses a key there
unknown; `os validate` still judges all of them. Judging apps and
navigation at the door would mean carrying served apps in the snapshot.
That is a separate decision and not this card.
The changes:
- `authoring-rules.ts`: the `validateReferenceIntegrity` entry's
`runtimeTypes` gains `translation`, so a translation write dispatches
the suite.
- `reference-integrity-suite.ts`: the `validateTranslationReferences`
member gains `runtimeTypes: ['flow', 'translation']` and still hands its
run context straight through.
- `validate-translation-references.ts`: the rule reads `runtimeWriteType
=== 'translation'` off that context as its save-door reading. That is
the signal the suite's other members already read for `wholeCollection`.
In that reading the rule treats the entry as one item (keyed by its own
`locale`), reduces the item to the judged families, and maps every
finding to `warning`.
- `runtime-gate.ts`: `TYPE_TO_STACK_KEY` gains `translation:
'translations'`. No context row is added, and no metadata-protocol
source changes.
- `scripts/engine-double-contract.pinned.json`: the three engine doubles
the new protocol pin uses (`delete`, `findOne`, `update`) are recorded,
written by `check-engine-double-contract --write`.
- `content/docs/deployment/validating-metadata.mdx`: the "Reference
integrity" row's runtime-publish cell gains `translation`
(`✓ᶠᵛᵒᵈᵗʳᵖᵃᶜᵗ`), and its text says what a translation write runs. The
superscript legend gains `✓ᵗ` `translation`, and the longest-first note
now covers it. Nothing else on the page changes.
The CLI reading is byte-identical: without `runtimeWriteType` the rule
takes its old path, the whole rule at its own severities.
**Control pins moved** (each held `translation` as the ungated control;
it now crosses, so the control moves to a type that stays ungated;
`tool`'s own control is untouched):
- `packages/lint/src/authoring-rule-wiring.test.ts` ("a type nobody
gated returns nothing"): `translation` → `doc`
- `packages/lint/src/runtime-gate.test.ts` ("runs nothing for a metadata
type no rule gates"): `translation` → `doc`
- `packages/lint/src/runtime-gate.test.ts` ("returns null for an
unmapped type"): `translation` → `doc`
- `packages/lint/src/runtime-gate.inert-type-writes.test.ts` ("crossing
these five widened no OTHER type s roster"): `translation` →
`capability`
- `packages/lint/src/runtime-gate.datasource-writes.test.ts` ("the types
still awaiting their own readings are untouched"): `translation` →
`capability`, and the comment says `translation` crossed on its own
reading
The seat's reading (7260663888 on #38623) takes this card as the
`translation` reading that the ADR-0049 group B line defers the wiring
to.
**Read these first** (ranked by risk):
1. `packages/lint/src/validate-translation-references.ts`:
`doorJudgedSubset` and the `localeEntries` / `atSaveDoor` lines in
`validateTranslationReferences`. This hunk decides what the door may
judge; a family added here without its collection in the snapshot is a
false advisory on every save.
2. `packages/lint/src/reference-integrity-suite.ts`: the member's
`runtimeTypes`.
3. `packages/lint/src/authoring-rules.ts`: the entry's `runtimeTypes`.
**Two-minute verification:** `pnpm --filter @objectstack/lint exec
vitest run --maxWorkers=2
src/runtime-gate.translation-writes-38623.test.ts` shows 9 passing. The
removed field key, the orphan object, rule and milestone, and the orphan
permission set come back in `advisories` with `errors` empty. Live keys
and the unjudged families come back with neither.
## Tests
New files, named for this card:
- `packages/lint/src/runtime-gate.translation-writes-38623.test.ts`,
through the gate's own entry (`runRuntimeAuthoringRules`):
- the dispatch: suite on `translation`, exactly the translation member
- a removed field → advisory, `errors` `[]`
- an orphan object, validation rule and milestone → advisories
- an orphan permission set → advisory
- live keys → none
- apps, navigation, global actions, positions, views and sections → not
judged
- a picklist-bound field's option keys → not judged
- under a package closure, an object outside it is not judged while its
sibling's removed field still is
- the CLI reading is unchanged (a bundle, at `error`)
-
`packages/metadata-protocol/src/protocol.translation-target-door-38623.test.ts`,
through the real `saveMetaItem` / `publishMetaItem` write path over a
stub engine:
- an active save naming a removed field → `success`, the advisory, and
the row landed
- a draft save says nothing (D1), and its publish answers with the
advisory
- a permission-set orphan → advisory
- live keys → none
- an already-published orphan neither blocks nor rides on an unrelated
translation write
<details><summary>Test runs: the new files at 8775b06; the
whole-package readings at 66c22be (before the main merge, which
brought no lint or metadata-protocol file)</summary>
- At head 8775b06, under the verify lock, after a fresh build of the
`@objectstack/metadata-protocol...` closure:
`protocol.translation-target-door-38623.test.ts` Tests 5 passed (5),
`runtime-gate.translation-writes-38623.test.ts` Tests 9 passed (9),
`VERDICT command-exit 0`. The later docs commit changes no code.
- `pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2`
(whole package): Test Files 247 passed (247), Tests 9977 passed (9977)
- `pnpm --filter @objectstack/lint typecheck`: exit 0 (`tsc --noEmit`
and `check:test-typecheck` OK)
- `pnpm --filter @objectstack/metadata-protocol typecheck`: exit 0
- `pnpm --filter @objectstack/metadata-protocol exec vitest run
--maxWorkers=2 src/protocol.translation-target-door-38623.test.ts`:
Tests 5 passed (5)
- The 29 metadata-protocol test files that mention `translation`: Test
Files 29 passed (29), Tests 862 passed (862)
</details>
<details><summary>Ablation: the entry widening reverted</summary>
`'translation'` removed from the entry's `runtimeTypes` through
`scripts/ablation-replace.mjs`:
- The anchor hit once and the mutation landed (blob 663f139 →
3068dd8e9df2).
- lint was rebuilt, and `ablation-dist-preflight.mjs @objectstack/lint
'"page", "action", "translation"]' --absent` confirmed the marker absent
from all 20 built files. It had been present in the pristine
`dist/runtime.js` and `dist/index.js`.
Results on the mutant:
- lint file: 5 failed / 4 passed. The dispatch case, the removed field,
the orphan object, rule and milestone, the permission set and the
closure case went quiet. Live keys stayed clean, and so did the
unjudged-families, picklist and CLI cases.
- protocol file: 4 failed / 1 passed. The active save, the draft publish
and the permission set went quiet. The live-key save stayed clean. The
already-published-orphan case also fails, because its first save asserts
the advisory as a precondition.
Restored: blob == HEAD (663f139) and `git diff HEAD` empty. lint
was rebuilt, and the protocol file then read 5 passed (5).
</details>
## Acceptance notes
- **False positives, measured on `examples/app-showcase`'s real
`ShowcaseTranslationBundle`** (en + zh-CN; context = the showcase's
objects, permissions, books and datasets):
- whole-stack `validateTranslationReferences`: 0 findings
- the rule unrestricted on the door's snapshot: 85 phantom
`translation-target-unknown`. By family: `_views` 28, `_sections` 19,
positions 10, flows 10, dashboards 6, `_tabs` 4, reports 4,
`globalActions` 2, apps 1, mappings 1. That is why the door judges only
the families listed above.
- this PR, through `runRuntimeAuthoringRules({ type: 'translation' })`
per locale: errors 0, advisories 0
- the lit control on the same context (a removed `showcase_project`
field) comes back as one `warning` advisory
- A draft save is still never gated (#4463 D1). The advisory appears on
an active save and on publishing a draft, not on the draft save itself.
- Found while measuring, not changed here: `os validate` refuses a
bundle key under the platform `studio` app at the app level, whatever
the navigation id (`translations[0]["zh-CN"].apps.studio`, "which this
stack neither defines nor contributes into"), even for a live id such as
`nav_api_console`. The lint's apps rung has no platform-app ladder; the
objects rung has `isPlatformProvidedObjectName`. Reported to the seat
with the CLI reproduction.
## Verification
<details><summary>Local gates, derived with dispatch-gates
--commands</summary>
At head 9b075e6. Gates were derived with `node
scripts/pm/dispatch-gates.mjs --commands` (105 families) and each exit
code was captured before any pipe. The `--ran` reconciliation reads: 105
derived, 103 run, 2 NOT MEASURED (derived from a recorded exit 3), 0
unrun.
- 68 code families were read at the code head: 266bea7, then
8775b06 for the ledger. The docs commit 9b075e6 changes only the
page.
- 37 families the docs path adds, all at 9b075e6: exit 0. They
include `check-adr-links` with its self-test (the local half of Check
Documentation Links; lychee runs only in CI, and the edit adds no link),
`check:doc-anchors`, `check:doc-frontmatter`, `check:docs-redirects`,
`check:docs-single-h1`, `check:docs-spec-enumerations`,
`check:docs-audit-scope` and `@objectstack/spec` `check:docs`.
- `@objectstack/spec` `check:skill-examples` first exited 3
(PREREQUISITE NOT MET: client SDK not built). After building
`@objectstack/client-react...` and `@objectstack/client...` under the
lock, it exits 0: "352 prose examples type-check across 3 surface(s)".
- `pnpm check:engine-double-contract`: exit 1 before the ledger commit,
exit 0 after it at 8775b06.
- `pnpm check:objectql-double-limit`: exit 0 ("none new").
- `node scripts/check-nul-bytes.mjs`: exit 0.
- `node scripts/pm/overlap-check.mjs --branch=HEAD` at 9b075e6:
`VERDICT clean exit 0`. The branch merges cleanly with origin/main and
with #38643, #38642, #38594, #38550 and #38497.
- NOT MEASURED:
- `node scripts/check-plugin-teardown-shape.mjs --self-test`: exit 3
(shallow checkout).
- `pnpm check:dual-build-cjs-loads`: exit 3 (needs a full `pnpm build`).
- `pnpm check:dts-closure`: exit 1. The self-test passed. The scan's red
came from a local build that skipped declaration output in an earlier
worktree. `@objectstack/lint` and `@objectstack/metadata-protocol` were
not among the packages it named. CI's fresh build gives the real
reading.
The families CI runs (the repo-wide lint, `test:repo`, Check
Documentation Links' lychee step, the artifact roster) are read from
this PR's check-runs. They were not re-run here.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B
<!-- signed: repo:objectstack#3 · os-steve ·
session_01ADHkmSwS4mQyXWrddL4r6B -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 0ba5e06 commit f5da514
13 files changed
Lines changed: 565 additions & 19 deletions
File tree
- .changeset
- content/docs/deployment
- packages
- lint/src
- metadata-protocol/src
- scripts
| 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 | |
|---|---|---|---|
| |||
507 | 507 | | |
508 | 508 | | |
509 | 509 | | |
510 | | - | |
| 510 | + | |
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
| |||
566 | 566 | | |
567 | 567 | | |
568 | 568 | | |
569 | | - | |
| 569 | + | |
570 | 570 | | |
571 | 571 | | |
572 | 572 | | |
573 | 573 | | |
574 | | - | |
| 574 | + | |
575 | 575 | | |
576 | 576 | | |
577 | 577 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
456 | 456 | | |
457 | 457 | | |
458 | 458 | | |
459 | | - | |
| 459 | + | |
| 460 | + | |
460 | 461 | | |
461 | 462 | | |
462 | 463 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1445 | 1445 | | |
1446 | 1446 | | |
1447 | 1447 | | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
1448 | 1459 | | |
1449 | | - | |
| 1460 | + | |
1450 | 1461 | | |
1451 | 1462 | | |
1452 | 1463 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
707 | 707 | | |
708 | 708 | | |
709 | 709 | | |
710 | | - | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
711 | 727 | | |
712 | 728 | | |
713 | 729 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
366 | 367 | | |
367 | 368 | | |
368 | 369 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1035 | 1035 | | |
1036 | 1036 | | |
1037 | 1037 | | |
1038 | | - | |
1039 | | - | |
1040 | | - | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
1041 | 1042 | | |
1042 | 1043 | | |
1043 | 1044 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
| 185 | + | |
| 186 | + | |
186 | 187 | | |
187 | 188 | | |
188 | 189 | | |
| |||
224 | 225 | | |
225 | 226 | | |
226 | 227 | | |
227 | | - | |
| 228 | + | |
| 229 | + | |
228 | 230 | | |
229 | 231 | | |
230 | 232 | | |
| |||
| 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 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 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 | + | |
0 commit comments