From e11c35fbdacd3fbb3ac8486f05650a9d70802d58 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 13:46:58 +0000 Subject: [PATCH 1/7] wip(spec,plugin-audit,lint): translatable activity-milestone summaries Claude-Session: https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj Co-authored-by: Claude --- .../src/system/translations/index.ts | 7 ++ packages/lint/src/i18n-walk.ts | 30 +++++++ .../src/activity-summary-message.ts | 83 ++++++++++++++++++- .../plugins/plugin-audit/src/audit-writers.ts | 39 +++++++-- packages/spec/src/system/i18n-resolver.ts | 33 ++++++++ packages/spec/src/system/translation.zod.ts | 23 +++++ 6 files changed, 205 insertions(+), 10 deletions(-) diff --git a/examples/app-showcase/src/system/translations/index.ts b/examples/app-showcase/src/system/translations/index.ts index a5f7d4b905e..a8f8c2f7ea9 100644 --- a/examples/app-showcase/src/system/translations/index.ts +++ b/examples/app-showcase/src/system/translations/index.ts @@ -501,6 +501,13 @@ export const ShowcaseTranslationBundle = { _validations: { task_status_flow: { message: '任务状态流转无效。' }, }, + // The object's one activity milestone (`status` → `done`), keyed by + // the pair that fires it; `{title}` is the authored template's token. + // A zh-CN reader's timeline row reads this; the stored row keeps the + // authored English sentence for every other reader. + _milestones: { + status: { done: { summary: '✅ 任务已完成:{title}' } }, + }, _views: { // The default list — keyed `default`, see showcase_project above. default: { label: '全部任务' }, diff --git a/packages/lint/src/i18n-walk.ts b/packages/lint/src/i18n-walk.ts index 839003b0f47..4d7316ee956 100644 --- a/packages/lint/src/i18n-walk.ts +++ b/packages/lint/src/i18n-walk.ts @@ -85,6 +85,8 @@ * ^ a bulk param spells its hint `help`; an ACTION param spells the same * idea `helpText` (`ui/bulk-action.zod.ts`'s known divergence) * objects.._validations..message + * objects.._milestones...summary (an `activityMilestones` + * entry's summary template) * objects.._relatedLists..label (an object-form `relatedLists` * entry that authors a `label`) * objects.._actions..label @@ -1002,6 +1004,28 @@ function pushValidationMessages( } } +/** + * Emit `objects.._milestones...summary` for each + * `activityMilestones` entry (ADR-0052 §5b.2), seeded with its authored + * template, `{field}` tokens and all. Only the first entry of a `field` + + * `value` pair is emitted: the writer fires the first match, so a later + * entry's template is never rendered. + */ +function pushMilestoneSummaries(out: ExpectedEntry[], objectName: string, milestones: unknown): void { + if (!Array.isArray(milestones)) return; + const seen = new Set(); + for (const m of milestones) { + if (!m || typeof m !== 'object') continue; + const field = (m as any).field; + const value = (m as any).value; + if (typeof field !== 'string' || field.length === 0 || typeof value !== 'string' || value.length === 0) continue; + const pair = `${field}\u0000${value}`; + if (seen.has(pair)) continue; + seen.add(pair); + pushEntry(out, ['objects', objectName, '_milestones', field, value, 'summary'], (m as any).summary, 'object', { objectName }); + } +} + /** * Emit `objects.._relatedLists..label` for every object-form * `relatedLists` entry of an object that authors a `label` (the record page's @@ -1653,6 +1677,12 @@ export function collectExpectedEntries( // Custom validation-rule rejection messages (`_validations..message`). pushValidationMessages(out, objectName, obj.validations, 0); + // Activity-milestone summary templates (`_milestones...summary`, + // #37524): keyed by the watched field and the value the milestone fires on, + // the address `resolveObjectMilestoneSummary` reads. The first milestone + // declared for a pair is the one that fires, so a later duplicate gets no key. + pushMilestoneSummaries(out, objectName, obj.activityMilestones); + // Record-page related-list titles (`_relatedLists..label`): the // `label` an object-form `relatedLists` entry authors on this parent, // keyed by the entry's literal `list` (`object.field` is one key). diff --git a/packages/plugins/plugin-audit/src/activity-summary-message.ts b/packages/plugins/plugin-audit/src/activity-summary-message.ts index d6a6785ba67..79235c49e89 100644 --- a/packages/plugins/plugin-audit/src/activity-summary-message.ts +++ b/packages/plugins/plugin-audit/src/activity-summary-message.ts @@ -65,12 +65,23 @@ * service is registered, when the reader's locale has no template for the code, * or when composing throws — the stored sentence stands. A row written before * this change carries no code and is served as written (no migration, no - * backfill). A fired milestone's summary carries no code either: its template - * is the author's sentence and is never translated (#7290). + * backfill). + * + * [#37524] A fired milestone's row carries a code too (`activityMilestone`): + * the milestone's `field` + `value`, the address of its translated template + * (`objects.._milestones...summary`, + * `resolveObjectMilestoneSummary`), and each interpolated token's value. A + * reader whose language translates the milestone reads the translated template + * interpolated with those values, a select value named by its option label in + * the reader's language; a reader whose language has no entry reads the + * authored sentence as stored. A tenant that reworded a packaged milestone's + * `summary` keeps its words (ADR-0029 D9.2a), as a reworded validation message + * does. */ import { resolveBundleLocale, + resolveObjectMilestoneSummary, translateObject, type ResolveOptions, type TranslationBundle, @@ -120,7 +131,16 @@ export interface ActivitySummaryFieldChange { export type ActivitySummaryMessage = | { key: 'activityCreated' | 'activityDeleted' | 'activityUpdated'; object: string; label: string } | { key: 'activityUpdatedFields'; object: string; label: string; fields: string[]; more: number } - | { key: 'fieldChanges'; object: string; changes: ActivitySummaryFieldChange[] }; + | { key: 'fieldChanges'; object: string; changes: ActivitySummaryFieldChange[] } + | { + key: 'activityMilestone'; + object: string; + /** The watched field and the value the milestone fired on — its translation address. */ + field: string; + value: string; + /** Each `{token}` the authored template interpolated, by token name. */ + tokens: Record; + }; /** One language a summary is composed in. */ export interface ActivitySummaryLocale { @@ -134,6 +154,13 @@ export interface ActivitySummaryLocale { * `translateObject` put in the reader's language. */ getObjectDef(objectName: string): any; + /** + * [#37524] The translated summary template of the milestone `field` + + * `value` declares on `objectName`, in this locale; `undefined` when the + * locale has none, or the milestone's served `summary` is a tenant's + * rewording of the packaged one. Absent on the writer's locale. + */ + milestoneSummary?(objectName: string, field: string, value: string): string | undefined; } /** Interpolate one `{{param}}` template, the shared convention (`createMemoryI18n`, FileI18nAdapter). */ @@ -263,6 +290,19 @@ export function composeActivitySummary( ) .join('; '); } + case 'activityMilestone': { + const template = locale.milestoneSummary?.(message.object, message.field, message.value); + if (template === undefined) return undefined; + const fields = locale.getObjectDef(message.object)?.fields; + // The authored template's tokens are the ones with a stored value; a + // token the translation adds, or one whose value was empty, renders + // empty, as an empty value does in the authored sentence. + return template.replace(/\{(\w+)\}/g, (_match: string, token: string) => { + const value = Object.prototype.hasOwnProperty.call(message.tokens, token) ? message.tokens[token] : undefined; + if (!value) return ''; + return value.option !== undefined ? (optionLabelOn(fields?.[token], value.option) ?? value.text) : value.text; + }); + } } } @@ -290,6 +330,15 @@ export function readActivitySummaryMessage(value: unknown): ActivitySummaryMessa ? (value as ActivitySummaryMessage) : null; } + if (value.key === 'activityMilestone') { + const tokens = value.tokens; + return typeof value.field === 'string' && + typeof value.value === 'string' && + isRecord(tokens) && + Object.values(tokens).every(isValue) + ? (value as ActivitySummaryMessage) + : null; + } if (value.key === 'fieldChanges') { const changes = value.changes; return Array.isArray(changes) && @@ -434,9 +483,37 @@ export function readerSummaryLocale( }, locale, getObjectDef: translatedObjectDef, + milestoneSummary: (objectName, field, value) => { + try { + translation ??= { value: labelTranslationOf(service, locale) }; + if (!translation.value) return undefined; + // ADR-0029 D9.2a: a tenant's rewording of a packaged milestone is + // authored data and keeps its words, judged as a validation message + // is — the served milestone against the packaged one of the same pair. + const served = milestoneOn(getObjectDef(objectName), field, value); + const packaged = milestoneOn(getPackagedObjectBase?.(objectName), field, value); + if (served && packaged && typeof served.summary === 'string' && served.summary !== packaged.summary) { + return undefined; + } + return resolveObjectMilestoneSummary(translation.value.bundle, objectName, field, value, translation.value.options); + } catch { + // A misbehaving i18n service must not fail the read: the stored text stands. + return undefined; + } + }, }; } +/** [#37524] The first milestone `def` declares for `field` + `value` — the one that fires, as the writer matches. */ +function milestoneOn(def: unknown, field: string, value: string): Record | undefined { + const milestones = isRecord(def) ? def.activityMilestones : undefined; + if (!Array.isArray(milestones)) return undefined; + for (const m of milestones) { + if (isRecord(m) && m.field === field && String(m.value) === value) return m; + } + return undefined; +} + /** Parse a stored `metadata` value: a JSON object, or `null` for anything else. */ function parseMetadata(raw: unknown): Record | null { if (isRecord(raw)) return raw; diff --git a/packages/plugins/plugin-audit/src/audit-writers.ts b/packages/plugins/plugin-audit/src/audit-writers.ts index 82a65c69d15..7e5d7187021 100644 --- a/packages/plugins/plugin-audit/src/audit-writers.ts +++ b/packages/plugins/plugin-audit/src/audit-writers.ts @@ -1283,7 +1283,7 @@ function matchMilestone( objectDef: any, before: Record | null, after: Record | null, -): { template: string; type?: string; watched: string[] } | null { +): { template: string; field: string; value: string; type?: string; watched: string[] } | null { const milestones = objectDef && Array.isArray(objectDef.activityMilestones) ? objectDef.activityMilestones : null; if (!milestones || !after || !before) return null; @@ -1293,6 +1293,10 @@ function matchMilestone( if (after[m.field] === m.value && before[m.field] !== m.value) { return { template: m.summary, + // [#37524] The pair the milestone is addressed by in the translation + // bundle (`objects.._milestones...summary`). + field: m.field, + value: String(m.value), type: typeof m.type === 'string' ? m.type : undefined, // [ADR-0139 E6] The same list the read rule keys the CURRENT // declaration by, from the same function. @@ -1398,19 +1402,29 @@ function renderMilestoneSummary( fields: Record | undefined | null, after: Record | null, lookupTitles?: Map>, -): { text: string; fields: string[] } { +): { text: string; fields: string[]; tokens: Record } { const interpolated = new Set(); + // [#37524] Each interpolated token's value, as a field change stores one: + // the text rendered here and the option it matched, so a reader's + // composition names the option in the reader's language. + const tokens: Record = {}; const text = template.replace(milestoneTokenRe(), (_match: string, key: string) => { const v = after ? after[key] : undefined; if (v === null || v === undefined || v === '') return ''; interpolated.add(key); const field = fields ? fields[key] : undefined; - if (!field) return String(v); + if (!field) { + tokens[key] = { text: String(v) }; + return String(v); + } const reference = referenceTargetForSummary(field); const titlesFor = reference ? lookupTitles?.get(reference) : undefined; - return displayFieldValue(field, v, titlesFor); + const shown = displayFieldValue(field, v, titlesFor); + const value = summaryValueOf(field, v, titlesFor); + tokens[key] = value.option !== undefined ? { text: shown, option: value.option } : { text: shown }; + return shown; }); - return { text, fields: [...interpolated] }; + return { text, fields: [...interpolated], tokens }; } /** @@ -2632,8 +2646,9 @@ export function installAuditWriters( // and the read side composes it in the READER's language // (`activity-summary-message.ts`). The stored `summary` is the English // sentence, the fallback text for every reader that composition does not - // reach, so no write asks for a locale. A fired milestone's author-written - // template has no code and stays as written. + // reach, so no write asks for a locale. A fired milestone's stored text is + // its author-written template rendered as written; [#37524] its code names + // the milestone, so a reader's language may translate the template. const writeLocale = storedSummaryLocale; let summary: string; let summaryMessage: ActivitySummaryMessage | undefined; @@ -2680,6 +2695,16 @@ export function installAuditWriters( const rendered = renderMilestoneSummary(milestone.template, summaryFields, afterView, lookupTitles); summary = rendered.text; summarySources = rendered.fields; + // [#37524] The row's code: which milestone fired and its token values. + // The stored `summary` stays the authored sentence; a reader whose + // language translates this milestone reads it composed in that language. + summaryMessage = { + key: 'activityMilestone', + object: ctx.object, + field: milestone.field, + value: milestone.value, + tokens: rendered.tokens, + }; if (milestone.type) activityType = milestone.type; // [#22771] `type` stays what the declaration names; the row says it is // a milestone in `metadata.kind`, so a "Case resolved" milestone of diff --git a/packages/spec/src/system/i18n-resolver.ts b/packages/spec/src/system/i18n-resolver.ts index 1d2f0c95845..411cae0ff25 100644 --- a/packages/spec/src/system/i18n-resolver.ts +++ b/packages/spec/src/system/i18n-resolver.ts @@ -4589,6 +4589,39 @@ export function objectValidationMessageKey(objectName: string, ruleName: string) return `objects.${objectName}._validations.${ruleName}.message`; } +/** + * The translated summary TEMPLATE of an object's activity milestone (ADR-0052 + * §5b.2) — `objects.._milestones...summary` — along the + * locale chain, or `undefined` when no locale of the chain carries a non-empty + * entry. + * + * A milestone declares no name: the watched `field` and the `value` it fires + * on are what fire it, so the pair is its address. `field` and `value` are each + * ONE key (a value is never split on a dot). The answer is a template with the + * authored `{field}` tokens; the caller interpolates it. + * + * Deliberately not overlaid by {@link translateObject}: a served object that + * carried the translated template would round-trip it into the authored + * declaration on the next Studio save. The one reader is the activity timeline, + * which composes a fired milestone's row in its reader's language. + */ +export function resolveObjectMilestoneSummary( + bundle: TranslationBundle | undefined, + objectName: string, + field: string, + value: string, + opts?: ResolveOptions, +): string | undefined { + if (!bundle) return undefined; + for (const code of localeChain(opts)) { + const objects = asRecord(asRecord(pickData(bundle, code))?.objects); + const milestones = asRecord(asRecord(objects?.[objectName])?._milestones); + const candidate = asRecord(asRecord(milestones?.[field])?.[value])?.summary; + if (typeof candidate === 'string' && candidate.length > 0) return candidate; + } + return undefined; +} + /** * Dot-notation i18n key for a refused `end` node's message — * `flows..refusals..message` (#22450). diff --git a/packages/spec/src/system/translation.zod.ts b/packages/spec/src/system/translation.zod.ts index 033cc6ecb9d..84355d08247 100644 --- a/packages/spec/src/system/translation.zod.ts +++ b/packages/spec/src/system/translation.zod.ts @@ -562,6 +562,7 @@ export const ObjectTranslationDataSchema = lazySchema(() => strictObject({ // and the un-prefixed spelling is the one an author reaches for first. views: '_views', actions: '_actions', sections: '_sections', validations: '_validations', validationRules: '_validations', rules: '_validations', relatedLists: '_relatedLists', + milestones: '_milestones', activityMilestones: '_milestones', plural: 'pluralLabel', labelPlural: 'pluralLabel', name: 'label', title: 'label', columns: 'fields', properties: 'fields', attributes: 'fields', }, @@ -965,6 +966,28 @@ export const ObjectTranslationDataSchema = lazySchema(() => strictObject({ message: z.string().optional() .describe("Translated rejection message — overlays the rule's authored `message` on every rejected write"), })).optional().describe('Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`)'), + + /** + * Activity-milestone summaries (ADR-0052 §5b.2), keyed by the milestone's + * watched `field`, then by the `value` it fires on: + * + * objects.._milestones...summary + * + * A milestone declares no name, and `field` + `value` is what fires it (the + * first declared milestone for the pair wins), so the pair is its address. + * The translated template carries the same `{field}` tokens as the authored + * `summary`; the record timeline composes it in the reader's language, and a + * token naming a select value is rendered with that option's label in the + * same language. A milestone with no entry keeps its authored `summary`. + */ + _milestones: z.record(z.string(), z.record(z.string(), strictObject({ + surface: 'this activity milestone translation', + history: TRANSLATION_HISTORY, + aliases: { message: 'summary', template: 'summary', text: 'summary', title: 'summary' }, + }, { + summary: z.string().optional() + .describe("Translated milestone summary template — the same `{field}` tokens as the milestone's authored `summary`"), + }))).optional().describe('Activity-milestone summary translations keyed by the watched field, then by the value the milestone fires on'), }).describe('Translation data for a single object')); export type ObjectTranslationData = z.input; From 42f2a830e0f62dda005034e8437f284f998825fa Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 13:50:17 +0000 Subject: [PATCH 2/7] wip: milestone locale integration pins, translation-reference orphan check Claude-Session: https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj Co-authored-by: Claude --- .../src/validate-translation-references.ts | 41 +++++ ...lestone-summary-locale.integration.test.ts | 170 ++++++++++++++++++ packages/spec/authorable-surface/system.json | 1 + 3 files changed, 212 insertions(+) create mode 100644 packages/plugins/plugin-audit/src/activity-milestone-summary-locale.integration.test.ts diff --git a/packages/lint/src/validate-translation-references.ts b/packages/lint/src/validate-translation-references.ts index fb0fb0c3d6a..dc8f6189973 100644 --- a/packages/lint/src/validate-translation-references.ts +++ b/packages/lint/src/validate-translation-references.ts @@ -477,6 +477,12 @@ interface ObjectFacts { * locale inside an otherwise translated refusal. */ validations: Set; + /** + * `_milestones` addresses — per watched `field`, the `value`s an + * `activityMilestones` entry of this object fires on (#37524). + * `objects.._milestones...summary` is keyed by that pair. + */ + milestones: Map>; /** * `_tabs` names — the filter-preset tabs declared for this object, from * `page.interfaceConfig.userFilters.tabs[].name`. See {@link collectPageTabs} @@ -667,6 +673,7 @@ function emptyFacts(): ObjectFacts { sections: new Set(), sectionEntries: new Map(), validations: new Set(), + milestones: new Map(), tabs: new Set(), relatedListLabels: new Set(), relatedListNames: new Set(), @@ -1338,6 +1345,15 @@ function buildUniverse(stack: AnyRec): Universe { for (const rule of recordsOf(obj.validations)) { collectValidationRuleNames(rule, facts.validations); } + // #37524: `_milestones..` is keyed by the pair a milestone fires on. + for (const milestone of recordsOf(obj.activityMilestones)) { + const field = strName(milestone.field); + const value = typeof milestone.value === 'string' && milestone.value.length > 0 ? milestone.value : undefined; + if (!field || !value) continue; + let values = facts.milestones.get(field); + if (!values) facts.milestones.set(field, (values = new Set())); + values.add(value); + } // `_relatedLists.` is keyed by an object-form `relatedLists` entry's // literal `list` (`object.field` is one key), and resolves only over an // entry that authors a `label`: `translateObject` overlays that label and @@ -2201,6 +2217,31 @@ export function validateTranslationReferences(stack: AnyRec): TranslationRefFind ); } + // _milestones.. + // + // A milestone's summary template, keyed by the pair that fires it. A + // key over a pair no milestone declares is never read: the row keeps + // its authored sentence. + for (const [field, rawValues] of Object.entries(asRecord(rawNode._milestones))) { + for (const value of Object.keys(asRecord(rawValues))) { + if (facts.milestones.get(field)?.has(value)) continue; + const declared = facts.milestones.get(field); + orphan( + `${inLocale} · object "${objectName}" · milestone "${field}" → "${value}"`, + `${objPath}._milestones${memberPath(field)}${memberPath(value)}`, + declared + ? `Translations are keyed to a milestone of field "${field}" firing on "${value}", ` + + `which object "${objectName}" does not declare, so no timeline row reads this key.` + + suggest(value, declared) + : `Translations are keyed to a milestone watching field "${field}", which no ` + + `\`activityMilestones\` entry of object "${objectName}" watches, so no timeline row ` + + `reads this key.`, + `Match the key to the milestone's \`field\` and \`value\`, or drop it if the milestone ` + + `was changed or removed.`, + ); + } + } + // _actions.[.params.[.options.] | .outcomeMessages. // | .resultDialog.(title|description|acknowledge) // | .resultDialog.fields. diff --git a/packages/plugins/plugin-audit/src/activity-milestone-summary-locale.integration.test.ts b/packages/plugins/plugin-audit/src/activity-milestone-summary-locale.integration.test.ts new file mode 100644 index 00000000000..afc5896b450 --- /dev/null +++ b/packages/plugins/plugin-audit/src/activity-milestone-summary-locale.integration.test.ts @@ -0,0 +1,170 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [#37524] A fired activity milestone's timeline row reads in the READER's + * language, through `objects.._milestones...summary`. + * + * The rows are written by the real audit writer, stored by a real SQLite + * driver and read back through the real engine middleware chain, under a caller + * context whose `locale` is what the REST door resolves from `Accept-Language` + * (the harness of `activity-summary-reader-locale.integration.test.ts`). + */ + +import { describe, it, expect, beforeAll, afterAll } from 'vitest'; +import { ObjectKernel } from '@objectstack/core'; +import type { II18nService } from '@objectstack/spec/contracts'; +import { ObjectQL, ObjectQLPlugin } from '@objectstack/objectql'; +import { SqliteWasmDriver } from '@objectstack/driver-sqlite-wasm'; + +import { AuditPlugin } from './audit-plugin.js'; +import { singlePostureTenancy } from './__tests__/single-posture-tenancy.js'; +import { installDefaultOrganization } from './default-organization.testkit.js'; + +const HARNESS_PACKAGE = 'com.objectstack.audit.test.milestone-summary-locale'; +const DEAL = 'biz_deal'; + +const deal = { + name: DEAL, + label: 'Deal', + fields: { + name: { name: 'name', label: 'Name', type: 'text' as const }, + stage: { + name: 'stage', + label: 'Stage', + type: 'select' as const, + options: [ + { value: 'open', label: 'Open' }, + { value: 'won', label: 'Won' }, + { value: 'lost', label: 'Lost' }, + ], + }, + note: { name: 'note', label: 'Note', type: 'text' as const }, + }, + activityMilestones: [ + { field: 'stage', value: 'won', summary: 'Deal won: {name} ({stage})' }, + { field: 'stage', value: 'lost', summary: 'Deal lost: {name}, {note}' }, + ], +}; + +const SYS = { context: { isSystem: true } }; +const READER = { userId: 'u_reader', tenantId: 'org_1', positions: ['org_member'] }; +/** A reader the security service does not serve the deal's `note` field. */ +const NOTE_HIDDEN = { userId: 'u_note_hidden', tenantId: 'org_1', positions: ['org_member'] }; +const reader = (locale?: string, who: Record = READER) => ({ + context: { ...who, ...(locale ? { locale } : {}) }, +}); + +type Row = Record; + +describe('activity milestone summary — rendered in the reader\'s language (#37524)', () => { + let kernel: ObjectKernel; + let engine: ObjectQL; + const ids: Record<'won' | 'lost', { record: string; row: string }> = {} as never; + + async function rowOf(which: 'won' | 'lost', opts: Record): Promise { + const rows = (await engine.find('sys_activity', { + where: { object_name: DEAL, record_id: ids[which].record }, + ...opts, + })) as Row[]; + return rows.find((r) => r.id === ids[which].row); + } + + const security = { + async getReadableFields(object: string, context?: any): Promise { + const all = Object.keys(((engine as any).getSchema(object)?.fields ?? {}) as Record); + return context?.userId === NOTE_HIDDEN.userId && object === DEAL ? all.filter((f) => f !== 'note') : all; + }, + async getQueryableFields(object: string, context?: any): Promise { + return security.getReadableFields(object, context); + }, + }; + + beforeAll(async () => { + kernel = new ObjectKernel({ logger: { level: 'silent' } } as any); + await kernel.use(new ObjectQLPlugin()); + await kernel.use({ + name: 'test.security-double', + version: '0.0.0', + init: async (ctx: any) => ctx.registerService('security', security), + start: async () => {}, + } as any); + await kernel.use(singlePostureTenancy()); + await kernel.use(new AuditPlugin()); + await kernel.bootstrap(); + + engine = kernel.getService('objectql'); + const driver = new SqliteWasmDriver({ filename: ':memory:' }); + await driver.connect(); + engine.registerDriver(driver, true); + engine.registry.registerObject(deal as any, HARNESS_PACKAGE); + await engine.syncSchemas(); + await installDefaultOrganization(engine); + + // The app's zh-CN pack: the milestones' templates, keyed by the pair that + // fires each, and the option labels a `{stage}` token is named by. + kernel.getService('i18n').loadTranslations('zh-CN', { + objects: { + [DEAL]: { + label: '商机', + fields: { + stage: { label: '阶段', options: { open: '进行中', won: '赢单', lost: '输单' } }, + }, + _milestones: { + stage: { + won: { summary: '商机赢单:{name}({stage})' }, + lost: { summary: '商机输单:{name},{note}' }, + }, + }, + }, + }, + }); + + for (const [which, to] of [['won', 'won'], ['lost', 'lost']] as const) { + const created = (await engine.insert(DEAL, { name: 'Acme', stage: 'open', note: 'budget cut' }, SYS)) as Row; + const record = String(created.id); + await engine.update(DEAL, { stage: to }, { where: { id: record }, ...SYS }); + const rows = (await engine.find('sys_activity', { where: { object_name: DEAL, record_id: record }, ...SYS })) as Row[]; + const fired = rows.find((r) => r.type !== 'created'); + expect(fired, `the ${which} milestone row`).toBeDefined(); + ids[which] = { record, row: String(fired!.id) }; + } + }, 120_000); + + afterAll(async () => { + if (kernel) { + await Promise.race([kernel.shutdown(), new Promise((resolve) => setTimeout(resolve, 10_000))]); + } + }, 30_000); + + it('red first: a zh-CN reader reads the translated template, a select token by its zh-CN option label', async () => { + expect((await rowOf('won', reader('zh-CN')))?.summary).toBe('商机赢单:Acme(赢单)'); + }); + + it('stores the authored sentence, and serves it to an en reader, a read with no locale, and a locale with no entry', async () => { + const authored = 'Deal won: Acme (Won)'; + expect((await rowOf('won', SYS))?.summary).toBe(authored); + expect((await rowOf('won', reader('en-US')))?.summary).toBe(authored); + expect((await rowOf('won', reader()))?.summary).toBe(authored); + expect((await rowOf('won', reader('ja-JP')))?.summary).toBe(authored); + }); + + it('stores the milestone code for the system, and serves it to no other caller', async () => { + const atRest = await rowOf('won', SYS); + expect(JSON.parse(atRest!.metadata).summary_message).toEqual({ + key: 'activityMilestone', + object: DEAL, + field: 'stage', + value: 'won', + tokens: { name: { text: 'Acme' }, stage: { text: 'Won', option: 'won' } }, + }); + const served = await rowOf('won', reader('zh-CN')); + expect(JSON.parse(served!.metadata)).not.toHaveProperty('summary_message'); + }); + + it('the field redaction still judges the text: a reader not served a token\'s field gets no summary in any language', async () => { + expect((await rowOf('lost', reader('zh-CN')))?.summary).toBe('商机输单:Acme,budget cut'); + const hidden = await rowOf('lost', reader('zh-CN', NOTE_HIDDEN)); + expect(hidden).toBeDefined(); + expect(hidden).not.toHaveProperty('summary'); + }); +}); diff --git a/packages/spec/authorable-surface/system.json b/packages/spec/authorable-surface/system.json index a674725026c..8ca7143bf68 100644 --- a/packages/spec/authorable-surface/system.json +++ b/packages/spec/authorable-surface/system.json @@ -858,6 +858,7 @@ "system/ObjectStorageConfig:quota", "system/ObjectStorageConfig:scope", "system/ObjectTranslationData:_actions", + "system/ObjectTranslationData:_milestones", "system/ObjectTranslationData:_relatedLists", "system/ObjectTranslationData:_sections", "system/ObjectTranslationData:_tabs", From fe9e56228fe88136f327940bb77e20613e40eaa3 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 13:52:15 +0000 Subject: [PATCH 3/7] wip: unit pins, docs, changeset Claude-Session: https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj Co-authored-by: Claude --- .../37524-milestone-summary-translations.md | 15 ++++ .../docs/protocol/kernel/i18n-standard.mdx | 1 + content/docs/ui/translations.mdx | 1 + .../lint/src/i18n-milestones-37524.test.ts | 68 +++++++++++++++++++ .../src/activity-summary-message.test.ts | 50 ++++++++++++++ .../spec/src/system/i18n-resolver.test.ts | 39 +++++++++++ 6 files changed, 174 insertions(+) create mode 100644 .changeset/37524-milestone-summary-translations.md create mode 100644 packages/lint/src/i18n-milestones-37524.test.ts diff --git a/.changeset/37524-milestone-summary-translations.md b/.changeset/37524-milestone-summary-translations.md new file mode 100644 index 00000000000..3abed7efe20 --- /dev/null +++ b/.changeset/37524-milestone-summary-translations.md @@ -0,0 +1,15 @@ +--- +'@objectstack/spec': minor +'@objectstack/plugin-audit': patch +'@objectstack/lint': patch +--- + +feat(spec,plugin-audit): an activity milestone's timeline row reads in the reader's language — `objects.._milestones...summary` + +Clause-②: yes (widening) +Metadata-protocol: added + +- **Translation slot.** An object translation accepts `_milestones`, keyed by an `activityMilestones` entry's watched `field` and then the `value` it fires on, each carrying `summary`: the milestone's template in that language, with the same `{field}` tokens. `milestones` and `activityMilestones` are accepted as aliases of the group. `resolveObjectMilestoneSummary` (`@objectstack/spec/system`) reads it along the locale chain. +- **Timeline rows.** A fired milestone's `sys_activity` row now stores a summary code (`metadata.summary_message`, `key: 'activityMilestone'`): the pair, and each interpolated token's value with the select option it matched. On a read whose caller has a locale, a language that translates the milestone serves the row's `summary` composed from its template, a select token named by the option label in that language. The stored `summary` is unchanged — the authored sentence — and a language with no entry, a read with no locale, and every row written before this change read it as stored. A tenant that reworded a packaged milestone's `summary` keeps its words. The field redaction still judges the composed text by the fields the row was composed from. +- **Extraction and references.** `os i18n extract` scaffolds the key for each milestone pair (the first entry of a repeated pair, the one that fires), and the translation-reference rule flags a `_milestones` key over a pair no milestone of the object declares. +- **Docs.** `content/docs/ui/translations.mdx` and the i18n standard's reference table name the key. diff --git a/content/docs/protocol/kernel/i18n-standard.mdx b/content/docs/protocol/kernel/i18n-standard.mdx index ba8b38db68f..11c82f3d30e 100644 --- a/content/docs/protocol/kernel/i18n-standard.mdx +++ b/content/docs/protocol/kernel/i18n-standard.mdx @@ -1176,6 +1176,7 @@ beneath an action entry are judged the same way under either. | `objects.{object}._tabs.{tab}` | a filter-preset tab's `name` in `interfaceConfig.userFilters.tabs` on a page over that object (`interfaceConfig.source`, else the page's `object`) — a list view's own `tabs` has no renderer and is not resolvable | | `objects.{object}._relatedLists.{list}` | the `list` of an object-form `relatedLists` entry on that object that authors a `label` — a dotted `object.field` is one key; a key over an entry with no `label`, a bare-string entry or a built-in tab is an orphan, because that tab's title is the child lookup field's `relatedListTitle`, translated on the child | | `objects.{object}._validations.{rule}` | a validation rule's `name` in that object's `validations[]` or in an `objectExtensions[]` entry aimed at it — a `conditional` rule's `then` / `otherwise` branch included | +| `objects.{object}._milestones.{field}.{value}` | an `activityMilestones[]` entry of that object watching `field` and firing on `value` | | `objects.{object}._actions.{action}` | an action bound to that object: one in its `actions`, or a stack-level action whose `objectName` is that object | | `globalActions.{action}` | an action with **no** `objectName` — a key naming a bound action is an error whose message names the `objects.{owner}._actions.{action}` key to write instead, `{owner}` being the action's own `objectName` | | `{action}.params.{param}` | a param's `name` on that action | diff --git a/content/docs/ui/translations.mdx b/content/docs/ui/translations.mdx index 8303aaf32cc..0b0ea81ad5a 100644 --- a/content/docs/ui/translations.mdx +++ b/content/docs/ui/translations.mdx @@ -79,6 +79,7 @@ export default defineStack({ | Column headers of a table in an action's result dialog or preflight panel | `objects.._actions..resultDialog.columns..` / `.preflight.columns..` — a sibling of `fields`, both paths written literally, dots included | | Form sections | `objects.._sections.
` | | Custom validation-rule messages | `objects.._validations..message` | +| Activity-milestone timeline rows | `objects.._milestones...summary` — keyed by the milestone's watched `field` and the `value` it fires on; the template keeps the authored `{field}` tokens, and a reader in that language reads the row composed from it, a select token named by its translated option label. A language with no entry reads the authored `summary` | | App navigation | `apps..navigation..label` | | Dashboard label / description | `dashboards..label` / `description` | | Dashboard widget title / description (the card-header subtitle) | `dashboards..widgets..title` / `description` | diff --git a/packages/lint/src/i18n-milestones-37524.test.ts b/packages/lint/src/i18n-milestones-37524.test.ts new file mode 100644 index 00000000000..98370021e80 --- /dev/null +++ b/packages/lint/src/i18n-milestones-37524.test.ts @@ -0,0 +1,68 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// `objects.._milestones...summary` on the two lint +// readers every object translation group has: the extractor walk that +// scaffolds and gates the key, and the orphan rule that refuses a key nothing +// reads. Both key on the pair an `activityMilestones` entry fires on. + +import { describe, it, expect } from 'vitest'; +import { collectExpectedEntries } from './i18n-walk.js'; +import { validateTranslationReferences, TRANSLATION_TARGET_UNKNOWN } from './validate-translation-references.js'; + +const CASE = { + name: 'crm_case', + label: 'Case', + fields: { + subject: { name: 'subject', type: 'text', label: 'Subject' }, + status: { name: 'status', type: 'select', label: 'Status', options: [{ value: 'open', label: 'Open' }, { value: 'closed', label: 'Closed' }] }, + }, + activityMilestones: [ + { field: 'status', value: 'closed', summary: 'Case closed — {subject}' }, + // The same pair again: the writer fires the first, so this one is never rendered. + { field: 'status', value: 'closed', summary: 'Never shown' }, + { field: 'status', value: 'open', summary: 'Case reopened — {subject}' }, + ], +}; + +describe('collectExpectedEntries — an activity milestone\'s summary (#37524)', () => { + const entries = collectExpectedEntries({ objects: [CASE] }, { warnedGroups: new Set() }); + const milestoneEntries = entries.filter((e) => e.path[2] === '_milestones'); + + it('emits one key per fired pair, seeded with the authored template, tokens and all', () => { + expect(milestoneEntries.map((e) => [e.path, e.sourceValue])).toEqual([ + [['objects', 'crm_case', '_milestones', 'status', 'closed', 'summary'], 'Case closed — {subject}'], + [['objects', 'crm_case', '_milestones', 'status', 'open', 'summary'], 'Case reopened — {subject}'], + ]); + expect(milestoneEntries.every((e) => e.source === 'object' && e.objectName === 'crm_case')).toBe(true); + }); +}); + +describe('validateTranslationReferences — _milestones (#37524)', () => { + const stackWith = (milestones: Record) => ({ + objects: [CASE], + translations: [{ 'zh-CN': { objects: { crm_case: { _milestones: milestones } } } }], + }); + + it('resolves a key over each declared pair', () => { + expect(validateTranslationReferences(stackWith({ + status: { closed: { summary: '工单已关闭 — {subject}' }, open: { summary: '工单已重开 — {subject}' } }, + }))).toEqual([]); + }); + + it('flags a value no milestone of the field fires on, and a field no milestone watches', () => { + const findings = validateTranslationReferences(stackWith({ + status: { close: { summary: '已关闭' } }, + priority: { high: { summary: '高' } }, + })); + expect(findings.map((f) => [f.rule, f.severity, f.path])).toEqual([ + [TRANSLATION_TARGET_UNKNOWN, 'error', 'translations[0]["zh-CN"].objects.crm_case._milestones.status.close'], + [TRANSLATION_TARGET_UNKNOWN, 'error', 'translations[0]["zh-CN"].objects.crm_case._milestones.priority.high'], + ]); + // A misspelt value is pointed at the declared one it nearly names. + expect(findings[0].message).toContain('"closed"'); + for (const f of findings) { + expect(f.message.length, f.message).toBeLessThanOrEqual(200); + expect(f.hint.length, f.hint).toBeLessThanOrEqual(200); + } + }); +}); diff --git a/packages/plugins/plugin-audit/src/activity-summary-message.test.ts b/packages/plugins/plugin-audit/src/activity-summary-message.test.ts index 28bc6ebfdbe..d72b3d2659a 100644 --- a/packages/plugins/plugin-audit/src/activity-summary-message.test.ts +++ b/packages/plugins/plugin-audit/src/activity-summary-message.test.ts @@ -375,3 +375,53 @@ describe('[#35384] a renamed packaged object is named by its rename, as /meta na expect(ctx.result[0].summary).toBe('创建了 商机 "Acme"'); }); }); + +describe('composeActivitySummary — a fired milestone (#37524)', () => { + const MILESTONE_DEFS: Record = { + biz_deal: { + ...DEFS.biz_deal, + activityMilestones: [{ field: 'stage', value: 'won', summary: 'Deal won: {name} ({stage})' }], + }, + }; + const WON: ActivitySummaryMessage = { + key: 'activityMilestone', + object: 'biz_deal', + field: 'stage', + value: 'won', + tokens: { name: { text: 'Acme' }, stage: { text: 'Won', option: 'won' } }, + }; + function milestoneI18n() { + const i18n = makeI18n(); + i18n.loadTranslations('zh-CN', { + objects: { biz_deal: { _milestones: { stage: { won: { summary: '赢单:{name}({stage}){extra}' } } } } }, + }); + return i18n; + } + + it('composes the translated template, a select token by the reader\'s option label, an unstored token empty', () => { + const locale = readerSummaryLocale(milestoneI18n(), 'zh-CN', (n) => MILESTONE_DEFS[n] ?? null)!; + expect(composeActivitySummary(WON, locale)).toBe('赢单:Acme(赢单)'); + }); + + it('composes nothing — the stored sentence stands — for a locale with no entry, and on the writer\'s locale', () => { + const ja = readerSummaryLocale(milestoneI18n(), 'ja-JP', (n) => MILESTONE_DEFS[n] ?? null)!; + expect(composeActivitySummary(WON, ja)).toBeUndefined(); + const { milestoneSummary: _none, ...writer } = ja; + expect(composeActivitySummary(WON, writer)).toBeUndefined(); + }); + + it('keeps a tenant\'s rewording of a packaged milestone (ADR-0029 D9.2a)', () => { + const reworded = { biz_deal: { ...MILESTONE_DEFS.biz_deal, activityMilestones: [{ field: 'stage', value: 'won', summary: 'Closed! {name}' }] } }; + const packaged = (n: string) => MILESTONE_DEFS[n]; + const tenant = readerSummaryLocale(milestoneI18n(), 'zh-CN', (n) => (reworded as any)[n] ?? null, packaged)!; + expect(composeActivitySummary(WON, tenant)).toBeUndefined(); + const untouched = readerSummaryLocale(milestoneI18n(), 'zh-CN', (n) => MILESTONE_DEFS[n] ?? null, packaged)!; + expect(composeActivitySummary(WON, untouched)).toBe('赢单:Acme(赢单)'); + }); + + it('reads the stored code back, and refuses a malformed one', () => { + expect(readActivitySummaryMessage(WON)).toEqual(WON); + expect(readActivitySummaryMessage({ ...WON, tokens: { name: 'Acme' } })).toBeNull(); + expect(readActivitySummaryMessage({ ...WON, value: 1 })).toBeNull(); + }); +}); diff --git a/packages/spec/src/system/i18n-resolver.test.ts b/packages/spec/src/system/i18n-resolver.test.ts index 36d3fc33119..714d2409b64 100644 --- a/packages/spec/src/system/i18n-resolver.test.ts +++ b/packages/spec/src/system/i18n-resolver.test.ts @@ -6908,3 +6908,42 @@ describe('resolveFlowApprovalStepLabel — an approval step label from the `flow .toBeUndefined(); }); }); + +import { resolveObjectMilestoneSummary, translateObject as translateObjectForMilestones } from './i18n-resolver'; + +describe('resolveObjectMilestoneSummary — objects.._milestones...summary (#37524)', () => { + const bundle: TranslationBundle = { + 'zh-CN': { + objects: { + crm_case: { _milestones: { status: { closed: { summary: '工单已关闭:{subject}' }, 'v1.0': { summary: '版本 {subject}' } } } }, + }, + }, + en: { objects: { crm_case: { _milestones: { status: { escalated: { summary: 'Escalated: {subject}' } } } } } }, + }; + + it('reads the template keyed by the watched field and the value, tokens untouched', () => { + expect(resolveObjectMilestoneSummary(bundle, 'crm_case', 'status', 'closed', { locale: 'zh-CN' })).toBe('工单已关闭:{subject}'); + }); + + it('indexes a dotted value as one key, never splitting it', () => { + expect(resolveObjectMilestoneSummary(bundle, 'crm_case', 'status', 'v1.0', { locale: 'zh-CN' })).toBe('版本 {subject}'); + }); + + it('walks the declared fallback chain, and answers undefined on a miss', () => { + expect(resolveObjectMilestoneSummary(bundle, 'crm_case', 'status', 'escalated', { locale: 'zh-CN', fallbackChain: ['en'] })).toBe('Escalated: {subject}'); + expect(resolveObjectMilestoneSummary(bundle, 'crm_case', 'status', 'reopened', { locale: 'zh-CN' })).toBeUndefined(); + expect(resolveObjectMilestoneSummary(bundle, 'crm_case', 'priority', 'closed', { locale: 'zh-CN' })).toBeUndefined(); + expect(resolveObjectMilestoneSummary(undefined, 'crm_case', 'status', 'closed', { locale: 'zh-CN' })).toBeUndefined(); + }); + + it('the object translation schema accepts the group, and translateObject leaves the authored summary on the served object', () => { + expect(ObjectTranslationDataSchema.safeParse({ _milestones: { status: { closed: { summary: '已关闭' } } } }).success).toBe(true); + expect(ObjectTranslationDataSchema.safeParse({ _milestones: { status: { closed: { label: '已关闭' } } } }).success).toBe(false); + const served = translateObjectForMilestones( + { name: 'crm_case', activityMilestones: [{ field: 'status', value: 'closed', summary: 'Case closed: {subject}' }] } as any, + bundle, + { locale: 'zh-CN' }, + ) as any; + expect(served.activityMilestones[0].summary).toBe('Case closed: {subject}'); + }); +}); From caca7485dce2ea82cb63dbf75bdb9308e093d6ca Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 13:58:22 +0000 Subject: [PATCH 4/7] chore(spec): regenerate api-surface, export-origins, strictness ledger, reference docs Claude-Session: https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj Co-authored-by: Claude --- content/docs/references/system/translation.mdx | 11 +++++++++++ .../system.md | 2 +- packages/spec/api-surface/system.json | 1 + packages/spec/export-origins/system.json | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/content/docs/references/system/translation.mdx b/content/docs/references/system/translation.mdx index f432f6a5987..c1b06ac5b20 100644 --- a/content/docs/references/system/translation.mdx +++ b/content/docs/references/system/translation.mdx @@ -100,6 +100,7 @@ Translation data for a single object | **_tabs** | `Record` | optional | Filter-preset tab translations keyed by tab name | | **_relatedLists** | `Record` | optional | Record-page related list titles keyed by the relatedLists entry list name | | **_validations** | `Record` | optional | Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`) | +| **_milestones** | `Record>` | optional | Activity-milestone summary translations keyed by the watched field, then by the value the milestone fires on | ### Nested Shape: `ObjectTranslationData.fields[string]` @@ -169,6 +170,12 @@ Translation data for a single field | :--- | :--- | :--- | :--- | | **message** | `string` | optional | Translated rejection message — overlays the rule's authored `message` on every rejected write | +### Nested Shape: `ObjectTranslationData._milestones[string][string]` + +| Property | Type | Required | Description | +| :--- | :--- | :--- | :--- | +| **summary** | `string` | optional | Translated milestone summary template — the same `{field}` tokens as the milestone's authored `summary` | + --- @@ -224,6 +231,7 @@ Translation data for a single object | **_tabs** | `Record` | optional | Filter-preset tab translations keyed by tab name | | **_relatedLists** | `Record` | optional | Record-page related list titles keyed by the relatedLists entry list name | | **_validations** | `Record` | optional | Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`) | +| **_milestones** | `Record>` | optional | Activity-milestone summary translations keyed by the watched field, then by the value the milestone fires on | ### Nested Shape: `PlatformTranslationData.picklists[string]` @@ -415,6 +423,7 @@ Translation data for a single object | **_tabs** | `Record` | optional | Filter-preset tab translations keyed by tab name | | **_relatedLists** | `Record` | optional | Record-page related list titles keyed by the relatedLists entry list name | | **_validations** | `Record` | optional | Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`) | +| **_milestones** | `Record>` | optional | Activity-milestone summary translations keyed by the watched field, then by the value the milestone fires on | ### Nested Shape: `ServedTranslationData.picklists[string]` @@ -669,6 +678,7 @@ Translation data for a single object | **_tabs** | `Record` | optional | Filter-preset tab translations keyed by tab name | | **_relatedLists** | `Record` | optional | Record-page related list titles keyed by the relatedLists entry list name | | **_validations** | `Record` | optional | Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`) | +| **_milestones** | `Record>` | optional | Activity-milestone summary translations keyed by the watched field, then by the value the milestone fires on | ### Nested Shape: `TranslationData.picklists[string]` @@ -892,6 +902,7 @@ Translation data for a single object | **_tabs** | `Record` | optional | Filter-preset tab translations keyed by tab name | | **_relatedLists** | `Record` | optional | Record-page related list titles keyed by the relatedLists entry list name | | **_validations** | `Record` | optional | Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`) | +| **_milestones** | `Record>` | optional | Activity-milestone summary translations keyed by the watched field, then by the value the milestone fires on | ### Nested Shape: `TranslationItem.picklists[string]` diff --git a/docs/audits/2026-07-unknown-key-strictness-ledger.counts/system.md b/docs/audits/2026-07-unknown-key-strictness-ledger.counts/system.md index e35ee35f184..22a10369642 100644 --- a/docs/audits/2026-07-unknown-key-strictness-ledger.counts/system.md +++ b/docs/audits/2026-07-unknown-key-strictness-ledger.counts/system.md @@ -19,4 +19,4 @@ hand-patch a number here** — fix the code or the verdict and regenerate. | Dir | Sites | |---|---| -| `system/` | 409 | +| `system/` | 410 | diff --git a/packages/spec/api-surface/system.json b/packages/spec/api-surface/system.json index 16e1d3e81f4..91228fd7486 100644 --- a/packages/spec/api-surface/system.json +++ b/packages/spec/api-surface/system.json @@ -923,6 +923,7 @@ "resolveMetadataTypeDescription (function)", "resolveMetadataTypeLabel (function)", "resolveObjectFieldLabels (function)", + "resolveObjectMilestoneSummary (function)", "resolveSettingsActionConfirm (function)", "resolveSettingsActionLabel (function)", "resolveSettingsActionSuccess (function)", diff --git a/packages/spec/export-origins/system.json b/packages/spec/export-origins/system.json index e638da027a2..bbf89649372 100644 --- a/packages/spec/export-origins/system.json +++ b/packages/spec/export-origins/system.json @@ -883,6 +883,7 @@ "resolveMetadataTypeDescription": "src/system/i18n-resolver.ts#resolveMetadataTypeDescription (function)", "resolveMetadataTypeLabel": "src/system/i18n-resolver.ts#resolveMetadataTypeLabel (function)", "resolveObjectFieldLabels": "src/system/i18n-resolver.ts#resolveObjectFieldLabels (function)", + "resolveObjectMilestoneSummary": "src/system/i18n-resolver.ts#resolveObjectMilestoneSummary (function)", "resolveSettingsActionConfirm": "src/system/i18n-resolver.ts#resolveSettingsActionConfirm (function)", "resolveSettingsActionLabel": "src/system/i18n-resolver.ts#resolveSettingsActionLabel (function)", "resolveSettingsActionSuccess": "src/system/i18n-resolver.ts#resolveSettingsActionSuccess (function)", From 92e8e1bcf10bc620ac40a123ba1c6ab4a7acb7d5 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 14:04:13 +0000 Subject: [PATCH 5/7] test: classify _milestones in the lint coverage pin; move the resolver pins to their own file Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj --- .../validate-translation-references.test.ts | 7 +++ .../src/system/i18n-milestone-summary.test.ts | 45 +++++++++++++++++++ .../spec/src/system/i18n-resolver.test.ts | 39 ---------------- 3 files changed, 52 insertions(+), 39 deletions(-) create mode 100644 packages/spec/src/system/i18n-milestone-summary.test.ts diff --git a/packages/lint/src/validate-translation-references.test.ts b/packages/lint/src/validate-translation-references.test.ts index 627fce2fcbe..9da08dcc79c 100644 --- a/packages/lint/src/validate-translation-references.test.ts +++ b/packages/lint/src/validate-translation-references.test.ts @@ -3855,6 +3855,7 @@ describe('validateTranslationReferences — object-branch coverage vs the schema fieldGroups: [{ key: 'basics', label: 'Basics' }], actions: [{ name: 'convert_lead', label: 'Convert' }], validations: [{ name: 'lead_needs_name', type: 'script', message: 'Name is required' }], + activityMilestones: [{ field: 'name', value: 'won', summary: 'Lead won: {name}' }], }, ], views: [{ name: 'open_leads', objectName: 'crm_lead', label: 'Open Leads' }], @@ -3920,6 +3921,11 @@ describe('validateTranslationReferences — object-branch coverage vs the schema ghost: { _validations: { ghost_rule: { message: 'Ghost' } } }, path: 'translations[0].en.objects.crm_lead._validations.ghost_rule', }, + _milestones: { + kind: 'reference-checked', + ghost: { _milestones: { name: { ghost_value: { summary: 'Ghost' } } } }, + path: 'translations[0].en.objects.crm_lead._milestones.name.ghost_value', + }, }; it('classifies every key `ObjectTranslationDataSchema` declares, and no key it does not', () => { @@ -3955,6 +3961,7 @@ describe('validateTranslationReferences — object-branch coverage vs the schema _actions: { convert_lead: { label: 'Convert' } }, _tabs: { urgent: { label: 'Urgent' } }, _validations: { lead_needs_name: { message: 'A name is required' } }, + _milestones: { name: { won: { summary: 'Lead won: {name}' } } }, }), ); expect(findings).toEqual([]); diff --git a/packages/spec/src/system/i18n-milestone-summary.test.ts b/packages/spec/src/system/i18n-milestone-summary.test.ts new file mode 100644 index 00000000000..2a2c1b1cd28 --- /dev/null +++ b/packages/spec/src/system/i18n-milestone-summary.test.ts @@ -0,0 +1,45 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// `objects.._milestones...summary`: the template an +// activity milestone's timeline row is composed from in the reader's language. + +import { describe, it, expect } from 'vitest'; +import { ObjectTranslationDataSchema, type TranslationBundle } from './translation.zod'; +import { resolveObjectMilestoneSummary, translateObject } from './i18n-resolver'; + +describe('resolveObjectMilestoneSummary — objects.._milestones...summary (#37524)', () => { + const bundle: TranslationBundle = { + 'zh-CN': { + objects: { + crm_case: { _milestones: { status: { closed: { summary: '工单已关闭:{subject}' }, 'v1.0': { summary: '版本 {subject}' } } } }, + }, + }, + en: { objects: { crm_case: { _milestones: { status: { escalated: { summary: 'Escalated: {subject}' } } } } } }, + }; + + it('reads the template keyed by the watched field and the value, tokens untouched', () => { + expect(resolveObjectMilestoneSummary(bundle, 'crm_case', 'status', 'closed', { locale: 'zh-CN' })).toBe('工单已关闭:{subject}'); + }); + + it('indexes a dotted value as one key, never splitting it', () => { + expect(resolveObjectMilestoneSummary(bundle, 'crm_case', 'status', 'v1.0', { locale: 'zh-CN' })).toBe('版本 {subject}'); + }); + + it('walks the declared fallback chain, and answers undefined on a miss', () => { + expect(resolveObjectMilestoneSummary(bundle, 'crm_case', 'status', 'escalated', { locale: 'zh-CN', fallbackChain: ['en'] })).toBe('Escalated: {subject}'); + expect(resolveObjectMilestoneSummary(bundle, 'crm_case', 'status', 'reopened', { locale: 'zh-CN' })).toBeUndefined(); + expect(resolveObjectMilestoneSummary(bundle, 'crm_case', 'priority', 'closed', { locale: 'zh-CN' })).toBeUndefined(); + expect(resolveObjectMilestoneSummary(undefined, 'crm_case', 'status', 'closed', { locale: 'zh-CN' })).toBeUndefined(); + }); + + it('the object translation schema accepts the group, and translateObject leaves the authored summary on the served object', () => { + expect(ObjectTranslationDataSchema.safeParse({ _milestones: { status: { closed: { summary: '已关闭' } } } }).success).toBe(true); + expect(ObjectTranslationDataSchema.safeParse({ _milestones: { status: { closed: { label: '已关闭' } } } }).success).toBe(false); + const served = translateObject( + { name: 'crm_case', activityMilestones: [{ field: 'status', value: 'closed', summary: 'Case closed: {subject}' }] } as any, + bundle, + { locale: 'zh-CN' }, + ) as any; + expect(served.activityMilestones[0].summary).toBe('Case closed: {subject}'); + }); +}); diff --git a/packages/spec/src/system/i18n-resolver.test.ts b/packages/spec/src/system/i18n-resolver.test.ts index 714d2409b64..36d3fc33119 100644 --- a/packages/spec/src/system/i18n-resolver.test.ts +++ b/packages/spec/src/system/i18n-resolver.test.ts @@ -6908,42 +6908,3 @@ describe('resolveFlowApprovalStepLabel — an approval step label from the `flow .toBeUndefined(); }); }); - -import { resolveObjectMilestoneSummary, translateObject as translateObjectForMilestones } from './i18n-resolver'; - -describe('resolveObjectMilestoneSummary — objects.._milestones...summary (#37524)', () => { - const bundle: TranslationBundle = { - 'zh-CN': { - objects: { - crm_case: { _milestones: { status: { closed: { summary: '工单已关闭:{subject}' }, 'v1.0': { summary: '版本 {subject}' } } } }, - }, - }, - en: { objects: { crm_case: { _milestones: { status: { escalated: { summary: 'Escalated: {subject}' } } } } } }, - }; - - it('reads the template keyed by the watched field and the value, tokens untouched', () => { - expect(resolveObjectMilestoneSummary(bundle, 'crm_case', 'status', 'closed', { locale: 'zh-CN' })).toBe('工单已关闭:{subject}'); - }); - - it('indexes a dotted value as one key, never splitting it', () => { - expect(resolveObjectMilestoneSummary(bundle, 'crm_case', 'status', 'v1.0', { locale: 'zh-CN' })).toBe('版本 {subject}'); - }); - - it('walks the declared fallback chain, and answers undefined on a miss', () => { - expect(resolveObjectMilestoneSummary(bundle, 'crm_case', 'status', 'escalated', { locale: 'zh-CN', fallbackChain: ['en'] })).toBe('Escalated: {subject}'); - expect(resolveObjectMilestoneSummary(bundle, 'crm_case', 'status', 'reopened', { locale: 'zh-CN' })).toBeUndefined(); - expect(resolveObjectMilestoneSummary(bundle, 'crm_case', 'priority', 'closed', { locale: 'zh-CN' })).toBeUndefined(); - expect(resolveObjectMilestoneSummary(undefined, 'crm_case', 'status', 'closed', { locale: 'zh-CN' })).toBeUndefined(); - }); - - it('the object translation schema accepts the group, and translateObject leaves the authored summary on the served object', () => { - expect(ObjectTranslationDataSchema.safeParse({ _milestones: { status: { closed: { summary: '已关闭' } } } }).success).toBe(true); - expect(ObjectTranslationDataSchema.safeParse({ _milestones: { status: { closed: { label: '已关闭' } } } }).success).toBe(false); - const served = translateObjectForMilestones( - { name: 'crm_case', activityMilestones: [{ field: 'status', value: 'closed', summary: 'Case closed: {subject}' }] } as any, - bundle, - { locale: 'zh-CN' }, - ) as any; - expect(served.activityMilestones[0].summary).toBe('Case closed: {subject}'); - }); -}); From 578a08d188abbe34f068395203243db11371a8a5 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 14:14:22 +0000 Subject: [PATCH 6/7] chore(changeset): name the skills-docs follow-up Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj --- .changeset/37524-milestone-summary-translations.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/37524-milestone-summary-translations.md b/.changeset/37524-milestone-summary-translations.md index 3abed7efe20..c0dbf2efb50 100644 --- a/.changeset/37524-milestone-summary-translations.md +++ b/.changeset/37524-milestone-summary-translations.md @@ -8,6 +8,7 @@ feat(spec,plugin-audit): an activity milestone's timeline row reads in the reade Clause-②: yes (widening) Metadata-protocol: added +Skills-docs: follow-up #37585 - **Translation slot.** An object translation accepts `_milestones`, keyed by an `activityMilestones` entry's watched `field` and then the `value` it fires on, each carrying `summary`: the milestone's template in that language, with the same `{field}` tokens. `milestones` and `activityMilestones` are accepted as aliases of the group. `resolveObjectMilestoneSummary` (`@objectstack/spec/system`) reads it along the locale chain. - **Timeline rows.** A fired milestone's `sys_activity` row now stores a summary code (`metadata.summary_message`, `key: 'activityMilestone'`): the pair, and each interpolated token's value with the select option it matched. On a read whose caller has a locale, a language that translates the milestone serves the row's `summary` composed from its template, a select token named by the option label in that language. The stored `summary` is unchanged — the authored sentence — and a language with no entry, a read with no locale, and every row written before this change read it as stored. A tenant that reworded a packaged milestone's `summary` keeps its words. The field redaction still judges the composed text by the fields the row was composed from. From 4a22422916b2b8cd04b935863d6a8f683a928e85 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 15:39:03 +0000 Subject: [PATCH 7/7] fix(plugin-audit): judge a milestone rewording through the resolver's one predicate The feed's milestone translator carried its own copy of the ADR-0029 D9.2a "tenant reworded the packaged value" comparison, which disagreed with the shared predicate on an empty served summary. scalarOverridesPackagedBase now takes 'summary', and the feed asks it with the packaged milestone as base. Also corrects the changeset's alias sentence (the aliases are refused, naming _milestones) and two audit-writers comments that predate the translation key. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj --- .../37524-milestone-summary-translations.md | 2 +- .../src/activity-summary-message.test.ts | 5 +++++ .../plugin-audit/src/activity-summary-message.ts | 8 ++++---- .../plugins/plugin-audit/src/audit-writers.ts | 15 ++++++++------- packages/spec/src/system/i18n-resolver.ts | 9 ++++++++- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/.changeset/37524-milestone-summary-translations.md b/.changeset/37524-milestone-summary-translations.md index c0dbf2efb50..9c45810c1dc 100644 --- a/.changeset/37524-milestone-summary-translations.md +++ b/.changeset/37524-milestone-summary-translations.md @@ -10,7 +10,7 @@ Clause-②: yes (widening) Metadata-protocol: added Skills-docs: follow-up #37585 -- **Translation slot.** An object translation accepts `_milestones`, keyed by an `activityMilestones` entry's watched `field` and then the `value` it fires on, each carrying `summary`: the milestone's template in that language, with the same `{field}` tokens. `milestones` and `activityMilestones` are accepted as aliases of the group. `resolveObjectMilestoneSummary` (`@objectstack/spec/system`) reads it along the locale chain. +- **Translation slot.** An object translation accepts `_milestones`, keyed by an `activityMilestones` entry's watched `field` and then the `value` it fires on, each carrying `summary`: the milestone's template in that language, with the same `{field}` tokens. `milestones` and `activityMilestones` are refused, and the refusal names `_milestones` as the key to write. `resolveObjectMilestoneSummary` (`@objectstack/spec/system`) reads it along the locale chain. - **Timeline rows.** A fired milestone's `sys_activity` row now stores a summary code (`metadata.summary_message`, `key: 'activityMilestone'`): the pair, and each interpolated token's value with the select option it matched. On a read whose caller has a locale, a language that translates the milestone serves the row's `summary` composed from its template, a select token named by the option label in that language. The stored `summary` is unchanged — the authored sentence — and a language with no entry, a read with no locale, and every row written before this change read it as stored. A tenant that reworded a packaged milestone's `summary` keeps its words. The field redaction still judges the composed text by the fields the row was composed from. - **Extraction and references.** `os i18n extract` scaffolds the key for each milestone pair (the first entry of a repeated pair, the one that fires), and the translation-reference rule flags a `_milestones` key over a pair no milestone of the object declares. - **Docs.** `content/docs/ui/translations.mdx` and the i18n standard's reference table name the key. diff --git a/packages/plugins/plugin-audit/src/activity-summary-message.test.ts b/packages/plugins/plugin-audit/src/activity-summary-message.test.ts index d72b3d2659a..bd310d2e095 100644 --- a/packages/plugins/plugin-audit/src/activity-summary-message.test.ts +++ b/packages/plugins/plugin-audit/src/activity-summary-message.test.ts @@ -417,6 +417,11 @@ describe('composeActivitySummary — a fired milestone (#37524)', () => { expect(composeActivitySummary(WON, tenant)).toBeUndefined(); const untouched = readerSummaryLocale(milestoneI18n(), 'zh-CN', (n) => MILESTONE_DEFS[n] ?? null, packaged)!; expect(composeActivitySummary(WON, untouched)).toBe('赢单:Acme(赢单)'); + // An empty served summary is no rewording: the resolver's one predicate + // reads it as nothing to protect, so the catalog still applies. + const blank = { biz_deal: { ...MILESTONE_DEFS.biz_deal, activityMilestones: [{ field: 'stage', value: 'won', summary: '' }] } }; + const emptied = readerSummaryLocale(milestoneI18n(), 'zh-CN', (n) => (blank as any)[n] ?? null, packaged)!; + expect(composeActivitySummary(WON, emptied)).toBe('赢单:Acme(赢单)'); }); it('reads the stored code back, and refuses a malformed one', () => { diff --git a/packages/plugins/plugin-audit/src/activity-summary-message.ts b/packages/plugins/plugin-audit/src/activity-summary-message.ts index 79235c49e89..3f889aad30e 100644 --- a/packages/plugins/plugin-audit/src/activity-summary-message.ts +++ b/packages/plugins/plugin-audit/src/activity-summary-message.ts @@ -82,6 +82,7 @@ import { resolveBundleLocale, resolveObjectMilestoneSummary, + scalarOverridesPackagedBase, translateObject, type ResolveOptions, type TranslationBundle, @@ -489,12 +490,11 @@ export function readerSummaryLocale( if (!translation.value) return undefined; // ADR-0029 D9.2a: a tenant's rewording of a packaged milestone is // authored data and keeps its words, judged as a validation message - // is — the served milestone against the packaged one of the same pair. + // is — the served milestone against the packaged one of the same pair, + // through the resolver's one predicate (never a copy of it). const served = milestoneOn(getObjectDef(objectName), field, value); const packaged = milestoneOn(getPackagedObjectBase?.(objectName), field, value); - if (served && packaged && typeof served.summary === 'string' && served.summary !== packaged.summary) { - return undefined; - } + if (scalarOverridesPackagedBase(packaged, 'summary', served?.summary)) return undefined; return resolveObjectMilestoneSummary(translation.value.bundle, objectName, field, value, translation.value.options); } catch { // A misbehaving i18n service must not fail the read: the stored text stands. diff --git a/packages/plugins/plugin-audit/src/audit-writers.ts b/packages/plugins/plugin-audit/src/audit-writers.ts index 7e5d7187021..ee4d7151cff 100644 --- a/packages/plugins/plugin-audit/src/audit-writers.ts +++ b/packages/plugins/plugin-audit/src/audit-writers.ts @@ -929,10 +929,11 @@ function displayFieldValue( optionLabelFor?: (optionValue: string) => string | undefined, ): string { const shown = summaryValueOf(field, value, titlesFor); - // A milestone's sentence is the author's, in the author's language, and is - // never re-composed per reader (#7290): an English yes/no word interpolated - // into it would be the very mixed-language sentence the field-change wording - // removes, so a boolean token keeps rendering its stored value here. + // A milestone's sentence is composed in the author's language at write time; + // a reader's translation, when its locale carries one, is re-rendered from the + // `_milestones` key on the feed (`activity-summary-message.ts`). An English + // yes/no word interpolated here would be the very mixed-language sentence the + // field-change wording removes, so a boolean token keeps its stored value. if (shown.boolean !== undefined) return String(value); return shown.option !== undefined ? (optionLabelFor?.(shown.option) ?? shown.text) : shown.text; } @@ -1378,9 +1379,9 @@ function planMilestoneTokenReads( * is locale-INDEPENDENT: `usr_1` → `张伟` is the record's own datum, the same * string in every locale, so it could be added to an untranslated sentence * without giving that sentence a locale. An option label is locale-DEPENDENT - * rendering, and a milestone template is an author-written sentence with NO - * bundle key of its own — #7290 ruled translating templates a contract decision - * and left it. So the author's own option label is the only rendering + * rendering, and the stored row is the author's template in the author's + * language (a reader's translation, when one exists, is rendered on the feed from + * `_milestones`, not here). So the author's own option label is the only rendering * guaranteed to agree with the sentence around it: template and option label are * both authored metadata, in one language, by one author. Reading the bundle * here would GUARANTEE a split sentence (`Deal moved to 已赢单`) in exactly the diff --git a/packages/spec/src/system/i18n-resolver.ts b/packages/spec/src/system/i18n-resolver.ts index 411cae0ff25..fd7fc702d2c 100644 --- a/packages/spec/src/system/i18n-resolver.ts +++ b/packages/spec/src/system/i18n-resolver.ts @@ -4984,10 +4984,17 @@ function builtinSystemFieldLabel( * rewrite is judged by one comparison on both readers and the two keep * answering one sentence. The key is the only thing it adds: the three edges * above hold for it unchanged. + * + * ## `summary` — an activity milestone's, judged on the feed reader + * + * The audit plugin's feed translates a packaged milestone's `summary` only + * while the served milestone's still equals the packaged one of the same + * `field` + `value` pair (ADR-0029 D9.2a), asking through this export with the + * packaged MILESTONE as `base`, as the evaluator asks with the packaged rule. */ export function scalarOverridesPackagedBase( base: unknown, - key: 'label' | 'pluralLabel' | 'description' | 'message', + key: 'label' | 'pluralLabel' | 'description' | 'message' | 'summary', value: unknown, ): boolean { return valueOverridesPackagedBase(base, key, value);