Skip to content

Commit f5da514

Browse files
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
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/lint': patch
3+
---
4+
5+
feat(lint): the metadata save door advises on a translation key nothing declares
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A `translation` item saved or published over the metadata API (Studio, REST `/meta`, an MCP or AI author) that names a key nothing declares now gets a `translation-target-unknown` advisory on the save and publish answer (`advisories`, severity `warning`). Before this, no rule ran on a `translation` write: the item was accepted as valid while `os validate` refused the same key.
11+
12+
The door never refuses such a write. A published item that names a key an upgrade removed still loads and saves, and `os validate` keeps reporting it at `error`.
13+
14+
The door judges only the families its per-write snapshot carries: `objects.NAME` (not when the write's package closure narrowed the objects), `objects.NAME.fields.FIELD` and the field's inline `options`, `objects.NAME._validations.RULE`, `objects.NAME._milestones.FIELD.VALUE`, and `permissions.NAME`. Every other family is not judged at the door, because the snapshot carries no collection to resolve it against. That covers apps and their navigation (platform-contributed items included), views, sections, tabs, related lists, actions, dashboards, forms, pages, picklists, positions, reports, mappings, books, flows and hooks. `os validate` still judges all of them.

‎content/docs/deployment/validating-metadata.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ orthogonal to both, and no cell here can carry it; it is written out in
507507
| Ordering comparands naming a date-range preset — `last_30_days` in a `>=` position (#8793) | ✓ | ✓ | ✓ | ✓ᵈᵛᵒᵖᶠʳ |
508508
| Empty filter combinators — `$and: []`, `$or: []`, `$not: {}` (#5330) | ✓ | ✓ | ✓ | ✓ᶠʳ |
509509
| Object & action name references (#3583) — and the object a seed dataset, a flow `get_record` / `create_record` / `update_record` / `delete_record` / object-form `screen` node or a standalone action is bound to (`object-reference-unknown`, #35143); a flow node's miss is a warning on the CLI, where a declared dependency may define the object, and an error at the publish door; at the publish door a seed over an unknown object is the save door's own refusal (#34864) | ✓ | ✓ | ✓ | ✓ᶠᵈᵗᵃᶜ |
510-
| Reference integrity — flow node writes, template paths, read-only writes (#3583); at the publish door each write type runs only the members that declare it, and the flow members run on `flow` alone (#9313) | ✓ | ✓ | ✓ | ✓ᶠᵛᵒᵈᵗʳᵖᵃᶜ |
510+
| Reference integrity — flow node writes, template paths, read-only writes (#3583); at the publish door each write type runs only the members that declare it, and the flow members run on `flow` alone (#9313); a `translation` write runs only the translation-key member, advisory only and never a 422, on the families the per-write snapshot carries (objects, their fields and inline options, validation rules, milestones, permission sets; apps and navigation are not judged) (#38623) | ✓ | ✓ | ✓ | ✓ᶠᵛᵒᵈᵗʳᵖᵃᶜᵗ |
511511
| List-view field members — a list view's `sort` (a `sortable: false` field, a `formula`, an unknown name: `sort-field-unsortable`), its `searchableFields` (`searchable-field-unknown`) and its field references, columns, filter keys, grouping and the board bindings (`list-view-field-unknown`); a filter key on a `formula` field, which the engine refuses to filter by (`list-view-filter-field-virtual`, #35143), and, advisory, a board grouped by a field with no fixed set of lanes (`list-view-kanban-group-field-uncategorical`, #35143); the row merges three members, so its codes follow no one rule's order, and the `page` door runs the sort member only (#9313, #15495, #30095) | ✓ | ✓ | ✓ | ✓ᶠᵛᵒᵖ |
512512
| Page-component field bindings (#3583) | ✓ | ✓ | ✓ | ✓ᶠ |
513513
| React page block field bindings — §10 (#4340) | ✓ | ✓ | ✓ | ✓ᶠ |
@@ -566,12 +566,12 @@ orthogonal to both, and no cell here can carry it; it is written out in
566566
writes that rule inspects: `✓ᶠ` `flow`, `✓ᵛ` `view`, `✓ᵈ` `dashboard`, `✓ᵒ`
567567
`object`, `✓ᵖ` `page`, `✓ˢ` `seed`, `✓ᵇ` `book`, `✓ᵖᵉ` `permission`,
568568
`✓ᵖᵒ` `position`, `✓ᵃ` `app`, `✓ᵉ` `email_template`, `✓ᵈᵗ` `dataset`, `✓ʳ` `report`,
569-
`✓ᵃᶜ` `action`, `✓ʰ` `hook`, `✓ᵐ` `mapping`, `✓ᵈˢ` `datasource`, `✓ᶜ` `connector`, `✓ᵒˣ` `object_extension`** — the two
569+
`✓ᵃᶜ` `action`, `✓ʰ` `hook`, `✓ᵐ` `mapping`, `✓ᵈˢ` `datasource`, `✓ᶜ` `connector`, `✓ᵒˣ` `object_extension`, `✓ᵗ` `translation`** — the two
570570
`ᵖ`-initial pairs carry a second letter because `page` already holds `ᵖ` on its
571571
own, `dataset` and `datasource` carry `ᵈᵗ` and `ᵈˢ` because `dashboard` holds `ᵈ`,
572572
`action` carries `ᵃᶜ` because `app` holds `ᵃ`, and `object_extension` carries `ᵒˣ` because `object` holds `ᵒ`, while `connector` takes the bare `ᶜ`. Read the codes **longest-first**: `ᵖᵒ` is `position`, never `page`
573573
followed by `object`, `ᵖᵉ` is `permission`, never `page` followed by
574-
`email_template`, `ᵈᵗ` is `dataset`, `ᵈˢ` is `datasource`, `ᵃᶜ` is `action` and `ᵒˣ` is `object_extension`.
574+
`email_template`, `ᵈᵗ` is `dataset`, `ᵈˢ` is `datasource`, `ᵃᶜ` is `action`, `ᵒˣ` is `object_extension`, and a bare `ᵗ` is `translation` — `ᵈᵗ` is still `dataset`, never `dashboard` followed by `translation`.
575575
A row whose rules are members of the reference-integrity suite reads the
576576
members' own `runtimeTypes` in `packages/lint/src/reference-integrity-suite.ts`,
577577
and a member that declares none runs on `flow` writes only (the suite's frozen

‎packages/lint/src/authoring-rule-wiring.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,8 @@ describe('authoring-rule registry wiring (#4409)', () => {
456456
expect(runtimeAuthoringRulesFor('flow').map((r) => r.name)).toContain('validateApprovalApprovers');
457457
expect(runtimeAuthoringRulesFor('flow').map((r) => r.name)).toContain('validateStackExpressions');
458458
// A type nobody gated returns nothing rather than everything.
459-
expect(runtimeAuthoringRulesFor('translation')).toEqual([]);
459+
// (`doc`: `translation` held this place until #38623 crossed it.)
460+
expect(runtimeAuthoringRulesFor('doc')).toEqual([]);
460461
});
461462

462463
// ── #7220: a rule FAMILY crosses this wall together, or not at all ──

‎packages/lint/src/authoring-rules.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,8 +1445,19 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
14451445
// (`sortable: false`, a `formula`, and since #30093 a field the object
14461446
// does not have, as `page-field-unknown`) is refused at publish rather
14471447
// than at its first fetch. Every other member keeps its declaration.
1448+
// [#38623] `translation` joins, NARROW by the same mechanism and ADVISORY
1449+
// by the member's own save-door reading: a translation write reaches
1450+
// exactly `validateTranslationReferences`, which at this door judges only
1451+
// the families the snapshot carries (objects, their fields, validation
1452+
// rules and milestones, permission sets) and reports at `warning`, so an
1453+
// orphan key is an advisory on the save answer and never a 422 — a
1454+
// published item naming a key an upgrade removed still loads and saves.
1455+
// This is the `translation` reading the ADR-0049 group B line deferred the
1456+
// wiring to (measured: 85 phantom orphans on the showcase bundle with the
1457+
// rule unrestricted, 0 of 287 keys restricted). Apps and their navigation
1458+
// stay unjudged at this door: the snapshot carries no apps.
14481459
surfaces: CLI_AND_RUNTIME,
1449-
runtimeTypes: ['flow', 'view', 'object', 'dataset', 'report', 'page', 'action'],
1460+
runtimeTypes: ['flow', 'view', 'object', 'dataset', 'report', 'page', 'action', 'translation'],
14501461
run: (stack, ctx) => validateReferenceIntegrity(stack, ctx),
14511462
},
14521463
// ADR-0078 / #5068 — the SDUI component-props gate. `PageComponent.properties`

‎packages/lint/src/reference-integrity-suite.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,23 @@ export const REFERENCE_INTEGRITY_RULES: readonly ReferenceIntegrityRule[] = [
707707
// maintainer ruling of 2026-08-12 makes THIS the mandatory companion, so the
708708
// prune is never silent to the author who wrote the row.
709709
{ name: 'validateNavObjectServability', run: validateNavObjectServability },
710-
{ name: 'validateTranslationReferences', run: validateTranslationReferences },
710+
// [#38623] `runtimeTypes` gains `translation`: a translation item saved over
711+
// the metadata API (Studio, REST `/meta`, an MCP/AI author) was published
712+
// `valid` while `os validate` refused the same orphan key. At that door the
713+
// rule takes its save-door reading off `ctx.runtimeWriteType`, the signal
714+
// the members above read for `wholeCollection`: it
715+
// judges only the families the per-write snapshot carries — `objects.<name>`
716+
// (not under a package closure), its `fields` (with inline `options`),
717+
// `_validations`, `_milestones`, and `permissions.<name>` — and reports at
718+
// `warning`, so the finding is an advisory on the save answer and never a
719+
// 422. Every other family (apps and their navigation among them) resolves
720+
// into a collection no snapshot carries and is not judged at the door.
721+
// MEASURED before crossing on `examples/app-showcase`'s bundle at the door's
722+
// own snapshot: the unrestricted rule reports 85 orphans the whole stack does
723+
// not; the judged families report 0 of 287 keys, as on the whole stack.
724+
// The member hands its run context straight through: the rule reads
725+
// `runtimeWriteType` and `packageScope` off it (`TranslationReferenceOptions`).
726+
{ name: 'validateTranslationReferences', runtimeTypes: ['flow', 'translation'], run: validateTranslationReferences },
711727
// The same family from the other end (#5417). Its sibling above asks "does
712728
// this bundle key resolve?"; this one asks "is there a key at all?" — a form
713729
// section authored with a `label` and no `name` renders a heading that

‎packages/lint/src/runtime-gate.datasource-writes.test.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,12 @@ describe('#19568 — DARK: what this crossing did NOT widen', () => {
358358
});
359359

360360
it('the types still awaiting their own readings are untouched', () => {
361-
// The standing ungated controls: group B reads `translation` / `tool`
362-
// first, group D retires `doc` / `external_catalog`, and `skill` stays
363-
// outside the door by design (ruling `5791822697` on #19527), for the
364-
// reason this file tested itself against.
365-
expect(runtimeAuthoringRulesFor('translation')).toEqual([]);
361+
// The standing ungated controls: group B reads `tool` first (`translation`
362+
// crossed on its own reading, #38623, and `capability`, a runtime-creatable
363+
// type no rule gates, holds its place here), group D retires `doc` /
364+
// `external_catalog`, and `skill` stays outside the door by design (ruling
365+
// `5791822697` on #19527), for the reason this file tested itself against.
366+
expect(runtimeAuthoringRulesFor('capability')).toEqual([]);
366367
expect(runtimeAuthoringRulesFor('tool')).toEqual([]);
367368
expect(runtimeAuthoringRulesFor('doc')).toEqual([]);
368369
expect(runtimeAuthoringRulesFor('external_catalog')).toEqual([]);

‎packages/lint/src/runtime-gate.inert-type-writes.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,9 +1035,10 @@ describe('#19542 — DARK: what the five crossings did NOT widen', () => {
10351035
});
10361036

10371037
it('crossing these five widened no OTHER type s roster', () => {
1038-
// The card is six metadata types, five of them wired. `translation` is the standing
1039-
// ungated control — its own ruling group (B) reads first.
1040-
expect(runtimeAuthoringRulesFor('translation')).toEqual([]);
1038+
// The card is six metadata types, five of them wired. `translation` stood here as
1039+
// the standing ungated control until its own group B reading crossed it (#38623);
1040+
// the control is now `capability`, a runtime-creatable type no rule gates.
1041+
expect(runtimeAuthoringRulesFor('capability')).toEqual([]);
10411042
expect(runtimeAuthoringRulesFor('doc')).toEqual([]);
10421043
expect(runtimeAuthoringRulesFor('external_catalog')).toEqual([]);
10431044
expect(runtimeAuthoringRulesFor('tool')).toEqual([]);

‎packages/lint/src/runtime-gate.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ describe('runtime publish gate (#4463)', () => {
182182
// ── Dispatch ─────────────────────────────────────────────────────────
183183

184184
it('runs nothing for a metadata type no rule gates', () => {
185-
const result = runRuntimeAuthoringRules({ type: 'translation', item: { name: 'x' } });
185+
// `doc`: `translation` held this place until #38623 crossed it.
186+
const result = runRuntimeAuthoringRules({ type: 'doc', item: { name: 'x' } });
186187
expect(result.rulesRun).toEqual([]);
187188
expect(result.errors).toEqual([]);
188189
});
@@ -224,7 +225,8 @@ describe('runtime publish gate (#4463)', () => {
224225
};
225226

226227
it('returns null for an unmapped type or a non-object body', () => {
227-
expect(buildRuntimeWriteSnapshots({ type: 'translation', item: { name: 'x' }, context })).toBeNull();
228+
// `doc` is unmapped; `translation` held this place until #38623 mapped it.
229+
expect(buildRuntimeWriteSnapshots({ type: 'doc', item: { name: 'x' }, context })).toBeNull();
228230
expect(buildRuntimeWriteSnapshots({ type: 'flow', item: 'not-an-object', context })).toBeNull();
229231
});
230232

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #38623 — a `translation` write at the runtime publish gate.
5+
*
6+
* A translation item saved over the metadata API naming a key nothing declares
7+
* was published `valid`, because no rule ran on a `translation` write, while
8+
* `os validate` refused the same key (`translation-target-unknown`). The gate
9+
* now dispatches `validateTranslationReferences` on that write, in its
10+
* save-door reading: only the families the per-write snapshot carries are
11+
* judged, and every finding is a `warning`, so it rides `advisories` and never
12+
* `errors` (a published item naming a key an upgrade removed must still load
13+
* and save).
14+
*
15+
* These pins go through the gate's own entry (`runRuntimeAuthoringRules`), the
16+
* function the metadata door calls, never a mirror of its snapshot.
17+
*/
18+
import { describe, expect, it } from 'vitest';
19+
20+
import {
21+
runRuntimeAuthoringRules,
22+
runtimeAuthoringRulesFor,
23+
stackKeyForType,
24+
} from './runtime-gate.js';
25+
import { REFERENCE_INTEGRITY_RULES } from './reference-integrity-suite.js';
26+
import { validateTranslationReferences, TRANSLATION_TARGET_UNKNOWN } from './validate-translation-references.js';
27+
28+
const OBJECTS = [
29+
{
30+
name: 'crm_lead',
31+
fields: {
32+
name: { type: 'text' },
33+
stage: { type: 'select', options: [{ value: 'new', label: 'New' }, { value: 'won', label: 'Won' }] },
34+
region: { type: 'select', picklist: 'regions' },
35+
},
36+
validations: [{ name: 'name_required', type: 'script', condition: 'true', message: 'Name is required' }],
37+
},
38+
];
39+
const PERMISSIONS = [{ name: 'sales_rep', label: 'Sales Rep' }];
40+
const CONTEXT = { objects: OBJECTS, permissions: PERMISSIONS, books: [], datasets: [] };
41+
42+
const item = (over: Record<string, unknown>) => ({ name: 'zh_cn', locale: 'zh-CN', ...over });
43+
44+
const publish = (body: unknown, extra: Record<string, unknown> = {}) =>
45+
runRuntimeAuthoringRules({ type: 'translation', item: body, context: CONTEXT, ...extra });
46+
47+
const rulesOf = (fs: Array<{ rule: string }>) => fs.map((f) => f.rule);
48+
49+
describe('a translation write reaches the translation rule at the door (#38623)', () => {
50+
it('the write type dispatches the suite, and the suite dispatches exactly the translation member', () => {
51+
expect(stackKeyForType('translation')).toBe('translations');
52+
expect(runtimeAuthoringRulesFor('translation').map((r) => r.name)).toEqual(['validateReferenceIntegrity']);
53+
const members = REFERENCE_INTEGRITY_RULES
54+
.filter((m) => (m.runtimeTypes ?? ['flow']).includes('translation'))
55+
.map((m) => m.name);
56+
expect(members).toEqual(['validateTranslationReferences']);
57+
});
58+
59+
it('⭐ LIT — a removed field key answers with the advisory, never an error', () => {
60+
const result = publish(item({ objects: { crm_lead: { fields: { zzz_removed: { label: '旧字段' } } } } }));
61+
expect(result.errors).toEqual([]);
62+
expect(rulesOf(result.advisories)).toEqual([TRANSLATION_TARGET_UNKNOWN]);
63+
expect(result.advisories[0]!.severity).toBe('warning');
64+
expect(result.advisories[0]!.path).toBe('translations[0].objects.crm_lead.fields.zzz_removed');
65+
expect(result.rulesRun).toEqual(['validateReferenceIntegrity']);
66+
});
67+
68+
it('⭐ LIT — an object, a validation rule and a milestone nothing declares are advised too', () => {
69+
const result = publish(item({
70+
objects: {
71+
crm_gone: { label: '旧对象' },
72+
crm_lead: { _validations: { zzz_rule: { message: 'x' } }, _milestones: { stage: { won: 'x' } } },
73+
},
74+
}));
75+
expect(result.errors).toEqual([]);
76+
expect(result.advisories.map((f) => f.path).sort()).toEqual([
77+
'translations[0].objects.crm_gone',
78+
'translations[0].objects.crm_lead._milestones.stage.won',
79+
'translations[0].objects.crm_lead._validations.zzz_rule',
80+
]);
81+
});
82+
83+
it('⭐ LIT — a permission-set orphan answers with the advisory', () => {
84+
const result = publish(item({ permissions: { zzz_gone_set: { label: '旧权限集' } } }));
85+
expect(result.errors).toEqual([]);
86+
expect(result.advisories.map((f) => [f.rule, f.path])).toEqual([
87+
[TRANSLATION_TARGET_UNKNOWN, 'translations[0].permissions.zzz_gone_set'],
88+
]);
89+
});
90+
91+
it('DARK — live keys answer with none', () => {
92+
const result = publish(item({
93+
objects: {
94+
crm_lead: {
95+
label: '线索',
96+
fields: { name: { label: '名称' }, stage: { label: '阶段', options: { new: '新建', won: '赢单' } } },
97+
_validations: { name_required: { message: '名称必填' } },
98+
},
99+
},
100+
permissions: { sales_rep: { label: '销售' } },
101+
}));
102+
expect(result.errors).toEqual([]);
103+
expect(result.advisories).toEqual([]);
104+
});
105+
106+
it('DARK — families the snapshot does not carry are not judged at the door', () => {
107+
// Apps and their navigation, views, sections, global actions, positions:
108+
// each resolves into a collection no per-write snapshot carries, so a key
109+
// there is never guessed unknown here (`os validate` still judges it).
110+
const result = publish(item({
111+
apps: { studio: { navigation: { nav_zzz_gone: { label: 'x' } } } },
112+
globalActions: { zzz_action: { label: 'x' } },
113+
positions: { zzz_position: { label: 'x' } },
114+
objects: { crm_lead: { _views: { zzz_view: { label: 'x' } }, _sections: { zzz_section: { label: 'x' } } } },
115+
}));
116+
expect(result.errors).toEqual([]);
117+
expect(result.advisories).toEqual([]);
118+
});
119+
120+
it('DARK — a picklist-bound field\'s option keys are not judged (its served options are not in the snapshot)', () => {
121+
const result = publish(item({ objects: { crm_lead: { fields: { region: { options: { emea: '欧洲' } } } } } }));
122+
expect(result.advisories).toEqual([]);
123+
});
124+
125+
it('DARK — under a package closure an object the snapshot lacks is not judged; its fields still are', () => {
126+
const scope = { packageId: 'com.acme.crm', dependencies: [] };
127+
const result = publish(
128+
item({ objects: { crm_other_pkg: { label: 'x' }, crm_lead: { fields: { zzz_removed: { label: 'x' } } } } }),
129+
{ packageScope: scope, context: { ...CONTEXT, objects: OBJECTS.map((o) => ({ ...o, _packageId: 'com.acme.crm' })) } },
130+
);
131+
expect(result.errors).toEqual([]);
132+
expect(result.advisories.map((f) => f.path)).toEqual(['translations[0].objects.crm_lead.fields.zzz_removed']);
133+
});
134+
135+
it('the CLI reading of the same key is unchanged: a bundle, at error', () => {
136+
const findings = validateTranslationReferences({
137+
objects: OBJECTS,
138+
translations: [{ 'zh-CN': { objects: { crm_lead: { fields: { zzz_removed: { label: 'x' } } } } } }],
139+
});
140+
expect(findings.map((f) => [f.severity, f.path])).toEqual([
141+
['error', 'translations[0]["zh-CN"].objects.crm_lead.fields.zzz_removed'],
142+
]);
143+
});
144+
});

0 commit comments

Comments
 (0)