Skip to content

Commit 04dd99c

Browse files
committed
feat(lint,platform-objects,plugin-approvals): judge action copy as template slots; convert the platform's ${result.*} sentences
Claude-Session: https://claude.ai/code/session_01DcqhBfbrsH8ACDsMQ62Hzq Co-authored-by: Claude <noreply@anthropic.com>
1 parent a23c4b9 commit 04dd99c

10 files changed

Lines changed: 244 additions & 39 deletions

‎packages/lint/src/runtime-gate.page-visibility-predicate-writes.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ const dump = (r: unknown) => JSON.stringify(r, null, 2);
127127
describe('#24491 — the page door gives the build\'s visibility-predicate verdict', () => {
128128
it('dispatches `page` writes to both family rules, after the component rules', () => {
129129
expect(runtimeAuthoringRulesFor('page').map((r) => r.name)).toEqual([
130+
// #24814 — the expression rule's one page pass, the action copy template
131+
// slots (warnings only); first because it is the registry's first rule.
132+
'validateStackExpressions',
130133
'validatePresetComparands',
131134
'validateComponentProps',
132135
'validateComponentTypes',
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// #24814 (ruling A) — an action's person-facing copy is an ADR-0032 `template`
4+
// slot over the closed scope the console's runner binds: `confirmText` over
5+
// `record` (and `params` beside static values), `successMessage` over `result`
6+
// and `record`, `errorMessage` over nothing. `validateStackExpressions` — the
7+
// rule `objectstack validate`, `objectstack compile` and the runtime publish
8+
// gate all run — judges every sentence through the template judge's
9+
// closed-scope entry, then compiles it as a template. Every finding is a
10+
// WARNING: each of these texts parsed while the keys were plain strings, and
11+
// refusing them is its own card. So a pin here asserts `severity: 'warning'`
12+
// and, at the publish gate, an advisory with no error.
13+
//
14+
// The gate half drives the REAL dispatch (`runRuntimeAuthoringRules`) with a
15+
// page write and an action write, because a `runtimeTypes` widening whose
16+
// walk reads nothing is a no-op that reads as coverage.
17+
18+
import { describe, expect, it } from 'vitest';
19+
20+
import { runStackExpressionPasses, validateStackExpressions } from './validate-expressions.js';
21+
import { runRuntimeAuthoringRules } from './runtime-gate.js';
22+
23+
const objects = [{ name: 'crm_account', label: 'Account', fields: { name: { type: 'text', label: 'Name' } } }];
24+
25+
const invite = (patch: Record<string, unknown>) => ({
26+
name: 'invite',
27+
label: 'Invite',
28+
type: 'api',
29+
target: '/api/v1/invite',
30+
objectName: 'crm_account',
31+
...patch,
32+
});
33+
34+
const copyIssues = (stack: Record<string, unknown>) =>
35+
validateStackExpressions(stack).filter((i) => /confirmText|successMessage|errorMessage/.test(i.where));
36+
37+
const pageWith = (components: unknown[]) => ({
38+
name: 'account_home',
39+
type: 'record',
40+
object: 'crm_account',
41+
regions: [{ name: 'main', components }],
42+
});
43+
44+
describe('validateStackExpressions — a registered action\'s copy is judged as the template slot it is (#24814)', () => {
45+
it('passes plain text and holes over bound roots — bare, as the envelope, or in a locale map', () => {
46+
for (const patch of [
47+
{ confirmText: 'Invite {{ record.name }}?' },
48+
{ successMessage: 'Invitation sent to {{ result.email }}' },
49+
{ successMessage: 'Sent to {{ result.email }} for {{ record.name | upper }}' },
50+
{ successMessage: { dialect: 'template', source: 'Sent to {{ result.email }}' } },
51+
{ successMessage: { en: 'Sent to {{ result.email }}', 'zh-CN': '已发送至 {{ result.email }}' } },
52+
{ confirmText: 'Invite this contact?', successMessage: 'Invitation sent' },
53+
]) {
54+
expect(copyIssues({ objects, actions: [invite(patch)] }), JSON.stringify(patch)).toEqual([]);
55+
}
56+
});
57+
58+
it('names a `${…}` token with a WARNING prescribing its `{{ }}` hole, never `${{ … }}`', () => {
59+
const [issue, ...rest] = copyIssues({ objects, actions: [invite({ successMessage: 'Invitation sent to ${result.email}' })] });
60+
expect(rest).toEqual([]);
61+
expect(issue!.severity).toBe('warning');
62+
expect(issue!.where).toBe("stack · action 'invite' successMessage");
63+
expect(issue!.message).toContain('Write `Invitation sent to ${result.email}` as `Invitation sent to {{ result.email }}`.');
64+
expect(issue!.message).not.toContain('${{');
65+
expect(issue!.message).toMatch(/A warning, not a refusal/);
66+
});
67+
68+
it('names a hole over a root the runner does not bind — `result` in a confirmText', () => {
69+
const [issue] = copyIssues({ objects, actions: [invite({ confirmText: 'Send to {{ result.email }}?' })] });
70+
expect(issue!.severity).toBe('warning');
71+
expect(issue!.message).toContain("An action's `confirmText` binds only `record`");
72+
expect(issue!.message).toContain('`{{ result.email }}`');
73+
});
74+
75+
it('judges each value of a locale map at its own location', () => {
76+
const issues = copyIssues({ objects, actions: [invite({ successMessage: { en: 'Sent', 'zh-CN': '已发送 {result.email}' } })] });
77+
expect(issues.map((i) => i.where)).toEqual(["stack · action 'invite' successMessage.zh-CN"]);
78+
});
79+
80+
it('names logic in a hole, an unknown formatter and a blank sentence — all warnings', () => {
81+
for (const successMessage of ['{{ result.count * 2 }} sent', '{{ result.email | shout }}', ' ']) {
82+
const issues = copyIssues({ objects, actions: [invite({ successMessage })] });
83+
expect(issues.length, successMessage).toBeGreaterThan(0);
84+
expect(issues.every((i) => i.severity === 'warning'), successMessage).toBe(true);
85+
}
86+
});
87+
88+
it('judges an object\'s own actions on an object write, once when also declared top-level', () => {
89+
const action = invite({ confirmText: 'Invite ${record.name}?' });
90+
const stack = { objects: [{ ...objects[0], actions: [action] }], actions: [action] };
91+
expect(copyIssues(stack)).toHaveLength(1);
92+
const onObjectWrite = runStackExpressionPasses({ objects: stack.objects }, { runtimeWriteType: 'object' })
93+
.filter((i) => i.where.includes('confirmText'));
94+
expect(onObjectWrite.map((i) => i.where)).toEqual(["object 'crm_account' · action 'invite' confirmText"]);
95+
});
96+
97+
it('control: ActionSchema\'s errorMessage is not in the family — a `${…}` there draws nothing', () => {
98+
expect(copyIssues({ objects, actions: [invite({ errorMessage: 'Failed for ${record.name}' })] })).toEqual([]);
99+
});
100+
});
101+
102+
describe('validateStackExpressions — a page action row\'s copy (#24814)', () => {
103+
it('judges an action:button\'s three keys, binding `params` only beside static values', () => {
104+
const button = (properties: Record<string, unknown>) => ({ type: 'action:button', properties: { label: 'Run', actionType: 'script', target: 'run', ...properties } });
105+
const issues = copyIssues({
106+
objects,
107+
pages: [pageWith([
108+
button({ confirmText: 'Run for {{ params.tier }}?', params: { tier: 'gold' } }),
109+
button({ confirmText: 'Run for {{ params.tier }}?', params: [{ name: 'tier', type: 'text' }] }),
110+
button({ errorMessage: 'Failed for {{ record.name }}' }),
111+
button({ successMessage: 'Done', errorMessage: 'Could not run' }),
112+
])],
113+
});
114+
expect(issues.map((i) => i.where)).toEqual([
115+
"page 'account_home'.regions[0].components[1] (action:button) · confirmText",
116+
"page 'account_home'.regions[0].components[2] (action:button) · errorMessage",
117+
]);
118+
expect(issues[0]!.message).toContain("binds only `record`, so a hole over any other root");
119+
expect(issues[1]!.message).toContain('binds no root, so it fills no hole');
120+
expect(issues.every((i) => i.severity === 'warning')).toBe(true);
121+
});
122+
123+
it('judges each action:group / action:menu member, an action:icon, and an inline `properties.action`', () => {
124+
const issues = copyIssues({
125+
objects,
126+
pages: [pageWith([
127+
{ type: 'action:group', properties: { actions: [{ name: 'a', type: 'script', target: 'a', confirmText: 'Run ${record.name}?' }] } },
128+
{ type: 'action:menu', properties: { actions: [{ name: 'b', type: 'script', target: 'b', successMessage: '{count} done' }] } },
129+
{ type: 'action:icon', properties: { label: 'X', actionType: 'script', target: 'x', confirmText: '' } },
130+
{ type: 'element:button', properties: { label: 'Go', action: { type: 'script', target: 'go', successMessage: 'Went to ${result.url}' } } },
131+
])],
132+
});
133+
expect(issues.map((i) => i.where)).toEqual([
134+
"page 'account_home'.regions[0].components[0] (action:group) · actions[0] confirmText",
135+
"page 'account_home'.regions[0].components[1] (action:menu) · actions[0] successMessage",
136+
"page 'account_home'.regions[0].components[2] (action:icon) · confirmText",
137+
"page 'account_home'.regions[0].components[3] (element:button) · action successMessage",
138+
]);
139+
expect(issues[0]!.message).toContain('as `Run {{ record.name }}?`');
140+
expect(issues[2]!.message).toMatch(/^An action's `confirmText` is blank/);
141+
});
142+
143+
it('on a page write runs that pass alone', () => {
144+
const stack = {
145+
objects,
146+
pages: [pageWith([{ type: 'action:button', properties: { label: 'Run', actionType: 'script', target: 'run', confirmText: '{{ x }}' } }])],
147+
flows: [{ name: 'f', nodes: [{ id: 'n', type: 'notify', config: { title: '{bad}' } }] }],
148+
};
149+
const issues = runStackExpressionPasses(stack, { runtimeWriteType: 'page' });
150+
expect(issues).toHaveLength(1);
151+
expect(issues[0]!.where).toContain('confirmText');
152+
});
153+
});
154+
155+
describe('the runtime publish gate — an advisory, never a refusal (#24814)', () => {
156+
const findings = (type: string, item: unknown) => {
157+
const { errors, advisories } = runRuntimeAuthoringRules({ type, item, context: { objects } });
158+
const copy = (f: { where: string }) => /confirmText|successMessage|errorMessage/.test(f.where);
159+
return { errors: errors.filter(copy), advisories: advisories.filter(copy) };
160+
};
161+
162+
it('a page write carrying a `${…}` confirmText answers one advisory and no error', () => {
163+
const page = pageWith([{ type: 'action:button', properties: { label: 'Run', actionType: 'script', target: 'run', confirmText: 'Delete ${record.name}?' } }]);
164+
const { errors, advisories } = findings('page', page);
165+
expect(errors).toEqual([]);
166+
expect(advisories).toHaveLength(1);
167+
expect(advisories[0]!.message).toContain('as `Delete {{ record.name }}?`');
168+
});
169+
170+
it('an action write carrying a `${result.*}` successMessage answers one advisory and no error', () => {
171+
const { errors, advisories } = findings('action', invite({ successMessage: 'Invitation sent to ${result.email}' }));
172+
expect(errors).toEqual([]);
173+
expect(advisories).toHaveLength(1);
174+
});
175+
176+
it('control: the converted platform sentence draws nothing', () => {
177+
expect(findings('action', invite({ successMessage: 'Invitation sent to {{ result.email }}' }))).toEqual({ errors: [], advisories: [] });
178+
});
179+
});

‎packages/lint/src/validate-expressions.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3533,6 +3533,11 @@ describe('validateStackExpressions — reads only keys the spec declares (meta-t
35333533
// this file is a local named `scope`; `graph.scope` is a KEY read off the
35343534
// tabled `graph` receiver, so the metadata guard loses no coverage here.
35353535
'scope',
3536+
// [#24814] NOT a receiver either — the tail of the
3537+
// `'./validate-action-copy-templates.js'` import specifier, the same
3538+
// artefact as `scope` above. The action copy pass reads its metadata in
3539+
// that module, not here.
3540+
'templates',
35363541
// [#19939] The spec's value-slot template judge, one refusal at a time.
35373542
// Its keys are that helper's own `{ path, label, message, source }` —
35383543
// never metadata keys — and it is named to stay clear of the `message` /

‎packages/platform-objects/src/apps/translations/en.objects.generated.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export const enObjects: NonNullable<TranslationData['objects']> = {
139139
invite_user: {
140140
label: "Invite User",
141141
description: "Invite someone by email address. They join this organization with the chosen role when they accept the invitation.",
142-
successMessage: "Invitation sent to ${result.email}",
142+
successMessage: "Invitation sent to {{ result.email }}",
143143
params: {
144144
role: {
145145
options: {
@@ -576,7 +576,7 @@ export const enObjects: NonNullable<TranslationData['objects']> = {
576576
invite_user: {
577577
label: "Invite User",
578578
description: "Invite someone by email address. They join this organization with the chosen role when they accept the invitation.",
579-
successMessage: "Invitation sent to ${result.email}",
579+
successMessage: "Invitation sent to {{ result.email }}",
580580
params: {
581581
role: {
582582
options: {
@@ -663,7 +663,7 @@ export const enObjects: NonNullable<TranslationData['objects']> = {
663663
invite_user: {
664664
label: "Invite User",
665665
description: "Invite someone by email address. They join this organization with the chosen role when they accept the invitation.",
666-
successMessage: "Invitation sent to ${result.email}",
666+
successMessage: "Invitation sent to {{ result.email }}",
667667
params: {
668668
role: {
669669
options: {
@@ -793,7 +793,7 @@ export const enObjects: NonNullable<TranslationData['objects']> = {
793793
invite_user: {
794794
label: "Invite User",
795795
description: "Invite someone by email address. They join this organization with the chosen role when they accept the invitation.",
796-
successMessage: "Invitation sent to ${result.email}",
796+
successMessage: "Invitation sent to {{ result.email }}",
797797
params: {
798798
role: {
799799
options: {

‎packages/platform-objects/src/identity/invite-user-action-copy.test.ts‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
// - `description` is the parameter dialog's subtitle. With none declared the
1010
// dialog falls back to a generic "Please provide the required information
1111
// to continue.", which says nothing about what Confirm will do.
12-
// - `successMessage` is the toast after Confirm. On a `type: 'api'` action the
13-
// runner fills `${result.*}` from the answer (ActionSchema.successMessage).
14-
// `/api/v1/auth/organization/invite-member` answers the bare invitation row,
15-
// whose top-level `email` is the invitee's address, so `${result.email}`
16-
// names the person invited. A copy without the token names nobody.
12+
// - `successMessage` is the toast after Confirm, a `template` slot (#24814):
13+
// the runner fills its `{{ result.* }}` holes from the answer
14+
// (ActionSchema.successMessage). `/api/v1/auth/organization/invite-member`
15+
// answers the bare invitation row, whose top-level `email` is the invitee's
16+
// address, so `{{ result.email }}` names the person invited. A copy without
17+
// the hole names nobody.
1718
//
1819
// The translated bundles are pinned as well, because the extractor cannot keep
1920
// them honest by itself: `--fill=default` seeds a NEW key (the description)
@@ -22,6 +23,7 @@
2223
// the old, invitee-less sentence. Both states are "in sync" to `check:i18n`.
2324
import { describe, expect, it } from 'vitest';
2425
import { translateMetadataDocument } from '@objectstack/spec/system';
26+
import { templateSlotSource } from '@objectstack/spec/automation';
2527
import { SetupAppTranslations } from '../apps/translations/setup.translation.js';
2628
import { enObjects } from '../apps/translations/en.objects.generated.js';
2729
import { zhCNObjects } from '../apps/translations/zh-CN.objects.generated.js';
@@ -38,8 +40,8 @@ interface CopyAction {
3840
successMessage?: unknown;
3941
}
4042

41-
/** The token the console runner fills from the invite-member answer. */
42-
const INVITEE = '${result.email}';
43+
/** The hole the console runner fills from the invite-member answer. */
44+
const INVITEE = '{{ result.email }}';
4345

4446
const MIRRORS: Array<[string, unknown]> = [
4547
['sys_user', SysUser],
@@ -54,12 +56,15 @@ const TRANSLATED = [
5456
['es-ES', esESObjects],
5557
] as const;
5658

59+
// [#24814] `successMessage` is a `template` slot: the parsed
60+
// object carries the `{ dialect: 'template', source }` envelope, so the copy is
61+
// read through the template judge's one reader, `templateSlotSource`.
5762
function invite(object: unknown): CopyAction {
5863
const found = ((object as { actions?: CopyAction[] }).actions ?? []).find(
5964
(a) => a.name === 'invite_user',
6065
);
6166
expect(found, 'invite_user is declared').toBeDefined();
62-
return found as CopyAction;
67+
return { ...found, successMessage: templateSlotSource(found?.successMessage) } as CopyAction;
6368
}
6469

6570
const bundleNode = (bundle: unknown, object: string): CopyAction | undefined =>

‎packages/platform-objects/src/identity/transfer-ownership-action-copy.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// translated value, so a revised English source leaves the old promise served
1717
// in zh-CN / ja-JP / es-ES while `check:i18n` reads "in sync".
1818
import { describe, expect, it } from 'vitest';
19+
import { templateSlotSource } from '@objectstack/spec/automation';
1920
import { enObjects } from '../apps/translations/en.objects.generated.js';
2021
import { zhCNObjects } from '../apps/translations/zh-CN.objects.generated.js';
2122
import { jaJPObjects } from '../apps/translations/ja-JP.objects.generated.js';
@@ -34,10 +35,17 @@ interface CopyAction {
3435
visible?: unknown;
3536
}
3637

38+
// [#24814] `confirmText` / `successMessage` are `template` slots: the parsed
39+
// object carries the `{ dialect: 'template', source }` envelope, so the copy is
40+
// read through the template judge's one reader, `templateSlotSource`.
3741
function declared(name: string): CopyAction {
3842
const found = ((SysMember as { actions?: CopyAction[] }).actions ?? []).find((a) => a.name === name);
3943
expect(found, `${name} is declared`).toBeDefined();
40-
return found as CopyAction;
44+
return {
45+
...found,
46+
confirmText: templateSlotSource(found?.confirmText),
47+
successMessage: templateSlotSource(found?.successMessage),
48+
} as CopyAction;
4149
}
4250

4351
const bundled = (bundle: unknown, name: string): CopyAction | undefined =>

0 commit comments

Comments
 (0)