Skip to content

Commit 5466366

Browse files
committed
fix(lint): judge an inline action's description as the template slot it is
The action-copy pass judged an inline `properties.action` on `confirmText`, `successMessage` and `params[].helpText` only, because `InlineActionSchema` did not pick `description`. Now that it does, an inline sentence with a `${…}` token, a hole over an unbound root or a blank text would publish from a page while the same text on a registered action is refused at `objectstack validate`, `compile` and the publish gate. INLINE_KEYS gains `description`; the inline pass already takes the locale map. Claude-Session: https://claude.ai/code/session_01ADHkmT9dnPvF2SeYafuvmH Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6307efe commit 5466366

2 files changed

Lines changed: 53 additions & 6 deletions

File tree

‎packages/lint/src/validate-action-copy-templates.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,47 @@ describe('validateStackExpressions — description, params[].helpText and outcom
317317
expect(onObjectWrite.map((i) => i.where)).toEqual(["object 'crm_account' · action 'invite' description"]);
318318
});
319319

320+
// cloud#3281 (ruling A): `InlineActionSchema` picks `description`, so an
321+
// inline sentence is judged by the same slot rules as a registered one —
322+
// otherwise a text the registered door refuses would publish from a page.
323+
it('judges an inline `properties.action` description like a registered one, locale map included', () => {
324+
const button = (description: unknown) => ({
325+
type: 'element:button',
326+
properties: { label: 'Invite', action: { type: 'api', target: '/api/v1/invite', description } },
327+
});
328+
const page = pageWith([
329+
button('Invite ${record.name}?'),
330+
button({ en: 'Invite {{ record.name }}?', 'zh-CN': '邀请 ${record.name}?' }),
331+
button(' '),
332+
button('Sent to {{ result.email }}'),
333+
button('Invite {{ record.name }} to this account.'),
334+
button({ en: 'Sends an invitation e-mail.', 'zh-CN': '发送邀请邮件。' }),
335+
]);
336+
const issues = runStackExpressionPasses({ objects, pages: [page] }, { runtimeWriteType: 'page' })
337+
.filter((i) => /description/.test(i.where));
338+
expect(issues.map((i) => [i.where, i.severity])).toEqual([
339+
["page 'account_home'.regions[0].components[0] (element:button) · action description", 'error'],
340+
["page 'account_home'.regions[0].components[1] (element:button) · action description.zh-CN", 'error'],
341+
["page 'account_home'.regions[0].components[2] (element:button) · action description", 'error'],
342+
["page 'account_home'.regions[0].components[3] (element:button) · action description", 'error'],
343+
]);
344+
expect(issues[0]!.message).toContain("An action's `description`");
345+
expect(issues[0]!.message).toContain('as `Invite {{ record.name }}?`');
346+
expect(issues[2]!.message).toMatch(/^An action's `description` is blank/);
347+
});
348+
349+
it('the publish gate answers an inline `${…}` description on a page write with one error and no advisory', () => {
350+
const page = pageWith([{
351+
type: 'element:button',
352+
properties: { label: 'Invite', action: { type: 'api', target: '/api/v1/invite', description: 'Invite ${record.name}?' } },
353+
}]);
354+
const { errors, advisories } = runRuntimeAuthoringRules({ type: 'page', item: page, context: { objects } });
355+
const copy = (f: { where: string }) => /description/.test(f.where);
356+
expect(errors.filter(copy)).toHaveLength(1);
357+
expect(errors.filter(copy)[0]!.where).toContain('(element:button) · action description');
358+
expect(advisories.filter(copy)).toEqual([]);
359+
});
360+
320361
it('the publish gate answers each `${…}` with one error and no advisory', () => {
321362
const gate = (item: unknown) => {
322363
const { errors, advisories } = runRuntimeAuthoringRules({ type: 'action', item, context: { objects } });

‎packages/lint/src/validate-action-copy-templates.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
* all three keys;
1818
* - a page component's inline `properties.action` (`InlineActionSchema`, the
1919
* pick of `ActionSchema` an `element:button` carries): `confirmText`,
20-
* `successMessage` and each `params[].helpText`.
20+
* `successMessage`, `description` (each with the locale map) and each
21+
* `params[].helpText`.
2122
*
2223
* The same two steps the bulk `confirmText` pass takes, through the same
2324
* judge: `closedScopeTemplateRefusal` names a `${…}` or single-brace token
@@ -60,16 +61,21 @@ type CopyKey = 'confirmText' | 'successMessage' | 'errorMessage' | 'description'
6061
const ACTION_KEYS: readonly CopyKey[] = ['confirmText', 'successMessage'];
6162

6263
/**
63-
* [#27948] The keys only a REGISTERED action carries as `template` slots, past
64+
* [#27948] The keys a REGISTERED action carries as `template` slots past
6465
* {@link ACTION_KEYS}: the param dialog's `description`, each
6566
* `outcomeMessages` entry, each `params[].helpText`. An inline action's pick
66-
* has `params` but neither of the other two, so it is judged on `helpText`
67-
* alone ({@link INLINE_KEYS}).
67+
* has `params` and `description` but not `outcomeMessages`, so it is judged on
68+
* `description` and `helpText` ({@link INLINE_KEYS}).
6869
*/
6970
const REGISTERED_KEYS: readonly CopyKey[] = [...ACTION_KEYS, 'description', 'outcomeMessages', 'helpText'];
7071

71-
/** The keys an inline `properties.action` carries as `template` slots. */
72-
const INLINE_KEYS: readonly CopyKey[] = [...ACTION_KEYS, 'helpText'];
72+
/**
73+
* The keys an inline `properties.action` carries as `template` slots.
74+
* `description` joined when `InlineActionSchema` picked it (cloud#3281, ruling
75+
* A): the same slot, so the same judge, or an inline sentence the registered
76+
* door refuses would publish.
77+
*/
78+
const INLINE_KEYS: readonly CopyKey[] = [...ACTION_KEYS, 'description', 'helpText'];
7379

7480
/** The keys a page action row carries as `template` slots. */
7581
const ROW_KEYS: readonly CopyKey[] = ['confirmText', 'successMessage', 'errorMessage'];

0 commit comments

Comments
 (0)