Skip to content

Commit 4a22422

Browse files
committed
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj
1 parent 578a08d commit 4a22422

5 files changed

Lines changed: 26 additions & 13 deletions

File tree

‎.changeset/37524-milestone-summary-translations.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Clause-②: yes (widening)
1010
Metadata-protocol: added
1111
Skills-docs: follow-up #37585
1212

13-
- **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.
13+
- **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.
1414
- **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.
1515
- **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.
1616
- **Docs.** `content/docs/ui/translations.mdx` and the i18n standard's reference table name the key.

‎packages/plugins/plugin-audit/src/activity-summary-message.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,11 @@ describe('composeActivitySummary — a fired milestone (#37524)', () => {
417417
expect(composeActivitySummary(WON, tenant)).toBeUndefined();
418418
const untouched = readerSummaryLocale(milestoneI18n(), 'zh-CN', (n) => MILESTONE_DEFS[n] ?? null, packaged)!;
419419
expect(composeActivitySummary(WON, untouched)).toBe('赢单:Acme(赢单)');
420+
// An empty served summary is no rewording: the resolver's one predicate
421+
// reads it as nothing to protect, so the catalog still applies.
422+
const blank = { biz_deal: { ...MILESTONE_DEFS.biz_deal, activityMilestones: [{ field: 'stage', value: 'won', summary: '' }] } };
423+
const emptied = readerSummaryLocale(milestoneI18n(), 'zh-CN', (n) => (blank as any)[n] ?? null, packaged)!;
424+
expect(composeActivitySummary(WON, emptied)).toBe('赢单:Acme(赢单)');
420425
});
421426

422427
it('reads the stored code back, and refuses a malformed one', () => {

‎packages/plugins/plugin-audit/src/activity-summary-message.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import {
8383
resolveBundleLocale,
8484
resolveObjectMilestoneSummary,
85+
scalarOverridesPackagedBase,
8586
translateObject,
8687
type ResolveOptions,
8788
type TranslationBundle,
@@ -489,12 +490,11 @@ export function readerSummaryLocale(
489490
if (!translation.value) return undefined;
490491
// ADR-0029 D9.2a: a tenant's rewording of a packaged milestone is
491492
// authored data and keeps its words, judged as a validation message
492-
// is — the served milestone against the packaged one of the same pair.
493+
// is — the served milestone against the packaged one of the same pair,
494+
// through the resolver's one predicate (never a copy of it).
493495
const served = milestoneOn(getObjectDef(objectName), field, value);
494496
const packaged = milestoneOn(getPackagedObjectBase?.(objectName), field, value);
495-
if (served && packaged && typeof served.summary === 'string' && served.summary !== packaged.summary) {
496-
return undefined;
497-
}
497+
if (scalarOverridesPackagedBase(packaged, 'summary', served?.summary)) return undefined;
498498
return resolveObjectMilestoneSummary(translation.value.bundle, objectName, field, value, translation.value.options);
499499
} catch {
500500
// A misbehaving i18n service must not fail the read: the stored text stands.

‎packages/plugins/plugin-audit/src/audit-writers.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -929,10 +929,11 @@ function displayFieldValue(
929929
optionLabelFor?: (optionValue: string) => string | undefined,
930930
): string {
931931
const shown = summaryValueOf(field, value, titlesFor);
932-
// A milestone's sentence is the author's, in the author's language, and is
933-
// never re-composed per reader (#7290): an English yes/no word interpolated
934-
// into it would be the very mixed-language sentence the field-change wording
935-
// removes, so a boolean token keeps rendering its stored value here.
932+
// A milestone's sentence is composed in the author's language at write time;
933+
// a reader's translation, when its locale carries one, is re-rendered from the
934+
// `_milestones` key on the feed (`activity-summary-message.ts`). An English
935+
// yes/no word interpolated here would be the very mixed-language sentence the
936+
// field-change wording removes, so a boolean token keeps its stored value.
936937
if (shown.boolean !== undefined) return String(value);
937938
return shown.option !== undefined ? (optionLabelFor?.(shown.option) ?? shown.text) : shown.text;
938939
}
@@ -1378,9 +1379,9 @@ function planMilestoneTokenReads(
13781379
* is locale-INDEPENDENT: `usr_1` → `张伟` is the record's own datum, the same
13791380
* string in every locale, so it could be added to an untranslated sentence
13801381
* without giving that sentence a locale. An option label is locale-DEPENDENT
1381-
* rendering, and a milestone template is an author-written sentence with NO
1382-
* bundle key of its own — #7290 ruled translating templates a contract decision
1383-
* and left it. So the author's own option label is the only rendering
1382+
* rendering, and the stored row is the author's template in the author's
1383+
* language (a reader's translation, when one exists, is rendered on the feed from
1384+
* `_milestones`, not here). So the author's own option label is the only rendering
13841385
* guaranteed to agree with the sentence around it: template and option label are
13851386
* both authored metadata, in one language, by one author. Reading the bundle
13861387
* here would GUARANTEE a split sentence (`Deal moved to 已赢单`) in exactly the

‎packages/spec/src/system/i18n-resolver.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4984,10 +4984,17 @@ function builtinSystemFieldLabel(
49844984
* rewrite is judged by one comparison on both readers and the two keep
49854985
* answering one sentence. The key is the only thing it adds: the three edges
49864986
* above hold for it unchanged.
4987+
*
4988+
* ## `summary` — an activity milestone's, judged on the feed reader
4989+
*
4990+
* The audit plugin's feed translates a packaged milestone's `summary` only
4991+
* while the served milestone's still equals the packaged one of the same
4992+
* `field` + `value` pair (ADR-0029 D9.2a), asking through this export with the
4993+
* packaged MILESTONE as `base`, as the evaluator asks with the packaged rule.
49874994
*/
49884995
export function scalarOverridesPackagedBase(
49894996
base: unknown,
4990-
key: 'label' | 'pluralLabel' | 'description' | 'message',
4997+
key: 'label' | 'pluralLabel' | 'description' | 'message' | 'summary',
49914998
value: unknown,
49924999
): boolean {
49935000
return valueOverridesPackagedBase(base, key, value);

0 commit comments

Comments
 (0)