Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/38623-translation-target-door.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@objectstack/lint': patch
---

feat(lint): the metadata save door advises on a translation key nothing declares

Clause-②: no
Metadata-protocol: none

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.

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`.

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.
6 changes: 3 additions & 3 deletions content/docs/deployment/validating-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ orthogonal to both, and no cell here can carry it; it is written out in
| Ordering comparands naming a date-range preset — `last_30_days` in a `>=` position (#8793) | ✓ | ✓ | ✓ | ✓ᵈᵛᵒᵖᶠʳ |
| Empty filter combinators — `$and: []`, `$or: []`, `$not: {}` (#5330) | ✓ | ✓ | ✓ | ✓ᶠʳ |
| 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) | ✓ | ✓ | ✓ | ✓ᶠᵈᵗᵃᶜ |
| 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) | ✓ | ✓ | ✓ | ✓ᶠᵛᵒᵈᵗʳᵖᵃᶜ |
| 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) | ✓ | ✓ | ✓ | ✓ᶠᵛᵒᵈᵗʳᵖᵃᶜᵗ |
| 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) | ✓ | ✓ | ✓ | ✓ᶠᵛᵒᵖ |
| Page-component field bindings (#3583) | ✓ | ✓ | ✓ | ✓ᶠ |
| React page block field bindings — §10 (#4340) | ✓ | ✓ | ✓ | ✓ᶠ |
Expand Down Expand Up @@ -566,12 +566,12 @@ orthogonal to both, and no cell here can carry it; it is written out in
writes that rule inspects: `✓ᶠ` `flow`, `✓ᵛ` `view`, `✓ᵈ` `dashboard`, `✓ᵒ`
`object`, `✓ᵖ` `page`, `✓ˢ` `seed`, `✓ᵇ` `book`, `✓ᵖᵉ` `permission`,
`✓ᵖᵒ` `position`, `✓ᵃ` `app`, `✓ᵉ` `email_template`, `✓ᵈᵗ` `dataset`, `✓ʳ` `report`,
`✓ᵃᶜ` `action`, `✓ʰ` `hook`, `✓ᵐ` `mapping`, `✓ᵈˢ` `datasource`, `✓ᶜ` `connector`, `✓ᵒˣ` `object_extension`** — the two
`✓ᵃᶜ` `action`, `✓ʰ` `hook`, `✓ᵐ` `mapping`, `✓ᵈˢ` `datasource`, `✓ᶜ` `connector`, `✓ᵒˣ` `object_extension`, `✓ᵗ` `translation`** — the two
`ᵖ`-initial pairs carry a second letter because `page` already holds `ᵖ` on its
own, `dataset` and `datasource` carry `ᵈᵗ` and `ᵈˢ` because `dashboard` holds `ᵈ`,
`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`
followed by `object`, `ᵖᵉ` is `permission`, never `page` followed by
`email_template`, `ᵈᵗ` is `dataset`, `ᵈˢ` is `datasource`, `ᵃᶜ` is `action` and `ᵒˣ` is `object_extension`.
`email_template`, `ᵈᵗ` is `dataset`, `ᵈˢ` is `datasource`, `ᵃᶜ` is `action`, `ᵒˣ` is `object_extension`, and a bare `ᵗ` is `translation` — `ᵈᵗ` is still `dataset`, never `dashboard` followed by `translation`.
A row whose rules are members of the reference-integrity suite reads the
members' own `runtimeTypes` in `packages/lint/src/reference-integrity-suite.ts`,
and a member that declares none runs on `flow` writes only (the suite's frozen
Expand Down
3 changes: 2 additions & 1 deletion packages/lint/src/authoring-rule-wiring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ describe('authoring-rule registry wiring (#4409)', () => {
expect(runtimeAuthoringRulesFor('flow').map((r) => r.name)).toContain('validateApprovalApprovers');
expect(runtimeAuthoringRulesFor('flow').map((r) => r.name)).toContain('validateStackExpressions');
// A type nobody gated returns nothing rather than everything.
expect(runtimeAuthoringRulesFor('translation')).toEqual([]);
// (`doc`: `translation` held this place until #38623 crossed it.)
expect(runtimeAuthoringRulesFor('doc')).toEqual([]);
});

// ── #7220: a rule FAMILY crosses this wall together, or not at all ──
Expand Down
13 changes: 12 additions & 1 deletion packages/lint/src/authoring-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1445,8 +1445,19 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
// (`sortable: false`, a `formula`, and since #30093 a field the object
// does not have, as `page-field-unknown`) is refused at publish rather
// than at its first fetch. Every other member keeps its declaration.
// [#38623] `translation` joins, NARROW by the same mechanism and ADVISORY
// by the member's own save-door reading: a translation write reaches
// exactly `validateTranslationReferences`, which at this door judges only
// the families the snapshot carries (objects, their fields, validation
// rules and milestones, permission sets) and reports at `warning`, so an
// orphan key is an advisory on the save answer and never a 422 — a
// published item naming a key an upgrade removed still loads and saves.
// This is the `translation` reading the ADR-0049 group B line deferred the
// wiring to (measured: 85 phantom orphans on the showcase bundle with the
// rule unrestricted, 0 of 287 keys restricted). Apps and their navigation
// stay unjudged at this door: the snapshot carries no apps.
surfaces: CLI_AND_RUNTIME,
runtimeTypes: ['flow', 'view', 'object', 'dataset', 'report', 'page', 'action'],
runtimeTypes: ['flow', 'view', 'object', 'dataset', 'report', 'page', 'action', 'translation'],
run: (stack, ctx) => validateReferenceIntegrity(stack, ctx),
},
// ADR-0078 / #5068 — the SDUI component-props gate. `PageComponent.properties`
Expand Down
18 changes: 17 additions & 1 deletion packages/lint/src/reference-integrity-suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,23 @@ export const REFERENCE_INTEGRITY_RULES: readonly ReferenceIntegrityRule[] = [
// maintainer ruling of 2026-08-12 makes THIS the mandatory companion, so the
// prune is never silent to the author who wrote the row.
{ name: 'validateNavObjectServability', run: validateNavObjectServability },
{ name: 'validateTranslationReferences', run: validateTranslationReferences },
// [#38623] `runtimeTypes` gains `translation`: a translation item saved over
// the metadata API (Studio, REST `/meta`, an MCP/AI author) was published
// `valid` while `os validate` refused the same orphan key. At that door the
// rule takes its save-door reading off `ctx.runtimeWriteType`, the signal
// the members above read for `wholeCollection`: it
// judges only the families the per-write snapshot carries — `objects.<name>`
// (not under a package closure), its `fields` (with inline `options`),
// `_validations`, `_milestones`, and `permissions.<name>` — and reports at
// `warning`, so the finding is an advisory on the save answer and never a
// 422. Every other family (apps and their navigation among them) resolves
// into a collection no snapshot carries and is not judged at the door.
// MEASURED before crossing on `examples/app-showcase`'s bundle at the door's
// own snapshot: the unrestricted rule reports 85 orphans the whole stack does
// not; the judged families report 0 of 287 keys, as on the whole stack.
// The member hands its run context straight through: the rule reads
// `runtimeWriteType` and `packageScope` off it (`TranslationReferenceOptions`).
{ name: 'validateTranslationReferences', runtimeTypes: ['flow', 'translation'], run: validateTranslationReferences },
// The same family from the other end (#5417). Its sibling above asks "does
// this bundle key resolve?"; this one asks "is there a key at all?" — a form
// section authored with a `label` and no `name` renders a heading that
Expand Down
11 changes: 6 additions & 5 deletions packages/lint/src/runtime-gate.datasource-writes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,12 @@ describe('#19568 — DARK: what this crossing did NOT widen', () => {
});

it('the types still awaiting their own readings are untouched', () => {
// The standing ungated controls: group B reads `translation` / `tool`
// first, group D retires `doc` / `external_catalog`, and `skill` stays
// outside the door by design (ruling `5791822697` on #19527), for the
// reason this file tested itself against.
expect(runtimeAuthoringRulesFor('translation')).toEqual([]);
// The standing ungated controls: group B reads `tool` first (`translation`
// crossed on its own reading, #38623, and `capability`, a runtime-creatable
// type no rule gates, holds its place here), group D retires `doc` /
// `external_catalog`, and `skill` stays outside the door by design (ruling
// `5791822697` on #19527), for the reason this file tested itself against.
expect(runtimeAuthoringRulesFor('capability')).toEqual([]);
expect(runtimeAuthoringRulesFor('tool')).toEqual([]);
expect(runtimeAuthoringRulesFor('doc')).toEqual([]);
expect(runtimeAuthoringRulesFor('external_catalog')).toEqual([]);
Expand Down
7 changes: 4 additions & 3 deletions packages/lint/src/runtime-gate.inert-type-writes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1035,9 +1035,10 @@ describe('#19542 — DARK: what the five crossings did NOT widen', () => {
});

it('crossing these five widened no OTHER type s roster', () => {
// The card is six metadata types, five of them wired. `translation` is the standing
// ungated control — its own ruling group (B) reads first.
expect(runtimeAuthoringRulesFor('translation')).toEqual([]);
// The card is six metadata types, five of them wired. `translation` stood here as
// the standing ungated control until its own group B reading crossed it (#38623);
// the control is now `capability`, a runtime-creatable type no rule gates.
expect(runtimeAuthoringRulesFor('capability')).toEqual([]);
expect(runtimeAuthoringRulesFor('doc')).toEqual([]);
expect(runtimeAuthoringRulesFor('external_catalog')).toEqual([]);
expect(runtimeAuthoringRulesFor('tool')).toEqual([]);
Expand Down
6 changes: 4 additions & 2 deletions packages/lint/src/runtime-gate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ describe('runtime publish gate (#4463)', () => {
// ── Dispatch ─────────────────────────────────────────────────────────

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

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

Expand Down
144 changes: 144 additions & 0 deletions packages/lint/src/runtime-gate.translation-writes-38623.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* #38623 — a `translation` write at the runtime publish gate.
*
* A translation item saved over the metadata API naming a key nothing declares
* was published `valid`, because no rule ran on a `translation` write, while
* `os validate` refused the same key (`translation-target-unknown`). The gate
* now dispatches `validateTranslationReferences` on that write, in its
* save-door reading: only the families the per-write snapshot carries are
* judged, and every finding is a `warning`, so it rides `advisories` and never
* `errors` (a published item naming a key an upgrade removed must still load
* and save).
*
* These pins go through the gate's own entry (`runRuntimeAuthoringRules`), the
* function the metadata door calls, never a mirror of its snapshot.
*/
import { describe, expect, it } from 'vitest';

import {
runRuntimeAuthoringRules,
runtimeAuthoringRulesFor,
stackKeyForType,
} from './runtime-gate.js';
import { REFERENCE_INTEGRITY_RULES } from './reference-integrity-suite.js';
import { validateTranslationReferences, TRANSLATION_TARGET_UNKNOWN } from './validate-translation-references.js';

const OBJECTS = [
{
name: 'crm_lead',
fields: {
name: { type: 'text' },
stage: { type: 'select', options: [{ value: 'new', label: 'New' }, { value: 'won', label: 'Won' }] },
region: { type: 'select', picklist: 'regions' },
},
validations: [{ name: 'name_required', type: 'script', condition: 'true', message: 'Name is required' }],
},
];
const PERMISSIONS = [{ name: 'sales_rep', label: 'Sales Rep' }];
const CONTEXT = { objects: OBJECTS, permissions: PERMISSIONS, books: [], datasets: [] };

const item = (over: Record<string, unknown>) => ({ name: 'zh_cn', locale: 'zh-CN', ...over });

const publish = (body: unknown, extra: Record<string, unknown> = {}) =>
runRuntimeAuthoringRules({ type: 'translation', item: body, context: CONTEXT, ...extra });

const rulesOf = (fs: Array<{ rule: string }>) => fs.map((f) => f.rule);

describe('a translation write reaches the translation rule at the door (#38623)', () => {
it('the write type dispatches the suite, and the suite dispatches exactly the translation member', () => {
expect(stackKeyForType('translation')).toBe('translations');
expect(runtimeAuthoringRulesFor('translation').map((r) => r.name)).toEqual(['validateReferenceIntegrity']);
const members = REFERENCE_INTEGRITY_RULES
.filter((m) => (m.runtimeTypes ?? ['flow']).includes('translation'))
.map((m) => m.name);
expect(members).toEqual(['validateTranslationReferences']);
});

it('⭐ LIT — a removed field key answers with the advisory, never an error', () => {
const result = publish(item({ objects: { crm_lead: { fields: { zzz_removed: { label: '旧字段' } } } } }));
expect(result.errors).toEqual([]);
expect(rulesOf(result.advisories)).toEqual([TRANSLATION_TARGET_UNKNOWN]);
expect(result.advisories[0]!.severity).toBe('warning');
expect(result.advisories[0]!.path).toBe('translations[0].objects.crm_lead.fields.zzz_removed');
expect(result.rulesRun).toEqual(['validateReferenceIntegrity']);
});

it('⭐ LIT — an object, a validation rule and a milestone nothing declares are advised too', () => {
const result = publish(item({
objects: {
crm_gone: { label: '旧对象' },
crm_lead: { _validations: { zzz_rule: { message: 'x' } }, _milestones: { stage: { won: 'x' } } },
},
}));
expect(result.errors).toEqual([]);
expect(result.advisories.map((f) => f.path).sort()).toEqual([
'translations[0].objects.crm_gone',
'translations[0].objects.crm_lead._milestones.stage.won',
'translations[0].objects.crm_lead._validations.zzz_rule',
]);
});

it('⭐ LIT — a permission-set orphan answers with the advisory', () => {
const result = publish(item({ permissions: { zzz_gone_set: { label: '旧权限集' } } }));
expect(result.errors).toEqual([]);
expect(result.advisories.map((f) => [f.rule, f.path])).toEqual([
[TRANSLATION_TARGET_UNKNOWN, 'translations[0].permissions.zzz_gone_set'],
]);
});

it('DARK — live keys answer with none', () => {
const result = publish(item({
objects: {
crm_lead: {
label: '线索',
fields: { name: { label: '名称' }, stage: { label: '阶段', options: { new: '新建', won: '赢单' } } },
_validations: { name_required: { message: '名称必填' } },
},
},
permissions: { sales_rep: { label: '销售' } },
}));
expect(result.errors).toEqual([]);
expect(result.advisories).toEqual([]);
});

it('DARK — families the snapshot does not carry are not judged at the door', () => {
// Apps and their navigation, views, sections, global actions, positions:
// each resolves into a collection no per-write snapshot carries, so a key
// there is never guessed unknown here (`os validate` still judges it).
const result = publish(item({
apps: { studio: { navigation: { nav_zzz_gone: { label: 'x' } } } },
globalActions: { zzz_action: { label: 'x' } },
positions: { zzz_position: { label: 'x' } },
objects: { crm_lead: { _views: { zzz_view: { label: 'x' } }, _sections: { zzz_section: { label: 'x' } } } },
}));
expect(result.errors).toEqual([]);
expect(result.advisories).toEqual([]);
});

it('DARK — a picklist-bound field\'s option keys are not judged (its served options are not in the snapshot)', () => {
const result = publish(item({ objects: { crm_lead: { fields: { region: { options: { emea: '欧洲' } } } } } }));
expect(result.advisories).toEqual([]);
});

it('DARK — under a package closure an object the snapshot lacks is not judged; its fields still are', () => {
const scope = { packageId: 'com.acme.crm', dependencies: [] };
const result = publish(
item({ objects: { crm_other_pkg: { label: 'x' }, crm_lead: { fields: { zzz_removed: { label: 'x' } } } } }),
{ packageScope: scope, context: { ...CONTEXT, objects: OBJECTS.map((o) => ({ ...o, _packageId: 'com.acme.crm' })) } },
);
expect(result.errors).toEqual([]);
expect(result.advisories.map((f) => f.path)).toEqual(['translations[0].objects.crm_lead.fields.zzz_removed']);
});

it('the CLI reading of the same key is unchanged: a bundle, at error', () => {
const findings = validateTranslationReferences({
objects: OBJECTS,
translations: [{ 'zh-CN': { objects: { crm_lead: { fields: { zzz_removed: { label: 'x' } } } } } }],
});
expect(findings.map((f) => [f.severity, f.path])).toEqual([
['error', 'translations[0]["zh-CN"].objects.crm_lead.fields.zzz_removed'],
]);
});
});
Loading
Loading