Skip to content

Commit 3ce6b65

Browse files
fix(service-automation): name the braces rule in the invalid-expression header only over a brace refusal (#35627)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuRTHmmdYhGsPrpf8EzYYxUk)_ Fixes #35369 Clause-②: no Metadata-protocol: none ## 维护者速读 - 流程作者发布或启动流程被拒时,若被拒的表达式与花括号无关(例如对日期字段写了时间戳转换),提示首句不再讲花括号规则,改为中性的计数说明;含花括号错误时提示与之前一字不差。 - 属于流程注册把关的报错质量改进,替被误导的流程作者解决"先被告知一个自己没犯的错"的问题。 - 出错只会让提示首句措辞不准,哪些流程被拒、每条拒绝原因都不变;可直接撤回。 - 无 ## What changes The "invalid expression" refusal `registerFlow` throws (and the stored pass previews) opened with one fixed header for every failure kind: the ADR-0032 §1a braces sentence ("Predicates ... must not wrap references in `{…}` template braces ..."). Over a date-text verdict, an unknown function or a `{{ }}` hole over an unbound `$` name, that told the author about a mistake they did not make. Per the card's fix direction, verbatim: "Name the braces rule only when a listed refusal is a brace refusal (`cel-template-brace` / `template-single-brace` / dialect mismatch); otherwise a neutral count header." - **Brace class** (header unchanged, byte for byte, citation kept): an expression-judge refusal whose `code` is `cel-template-brace`, `template-single-brace`, `cel-dialect-mismatch` or `template-dialect-mismatch`; every retired `{…}` token in a value-slot literal (`flowNodeValueTemplateRefusals`); a text-slot refusal whose single-brace half leads with the spec's published `TEXT_SLOT_TEMPLATE_REFUSAL`; a value envelope naming a dialect other than `cel` (its shape refusal carries no code). - **Everything else** (date-text family, unknown function, malformed shapes, blank sources, unbound `$` holes) is listed under the neutral header: `Flow 'X' has N invalid expression(s); each is refused for the reason given with it, and the flow does not register until every one is fixed:`. A mixed list keeps the braces header. - The kind is decided where each refusal is pushed (a `braces` argument on `refuse`), never read back out of the sentence. To carry it for value envelopes, the internal `valueEnvelopeRefusals` (dag-traversal) now passes through the judge's `code` beside `message`/`source`; that is two small edits outside the claim's file surface (`dag-traversal.ts`, `engine.ts` private signature), recorded as a deviation. - No verdict change: which flows are refused and every listed refusal line are unchanged (pinned: the mixed list's body contains each solo body byte for byte). Files to read first, by risk: 1. `packages/services/service-automation/src/flow-registration-checks.ts`: the value-envelope hunk (`refusal.code` vs `envelopeNamesNonCelDialect`) and the header hunk. 2. `packages/services/service-automation/src/dag-traversal.ts`: `ValueEnvelopeRefusal` plus the `code` pass-through. 3. `packages/services/service-automation/src/flow-registration-checks.test.ts`: the new top-level describe. ## Tests New top-level describe in `flow-registration-checks.test.ts` (9 cases): date-text alone, unknown function alone and unbound `$` hole alone give the neutral header with no braces sentence; braced predicate, retired `{…}` value literal, template-dialect value envelope, braced CEL value envelope and flow-text single-brace token give the braces header; the mix gives the braces header over both lines, each byte-identical to its solo listing. `registerFlow` throws a plain `Error` (no HTTP door is reached), so no `code`/`status` envelope exists to assert there. No existing pin had to change: a repo-wide grep of the header's literal text found only the source and a comment in `packages/spec/src/automation/flow.test.ts` that quotes the braces header over a brace failure (still true). Every `/template braces/` pin in the package sits on a brace failure. <details><summary>Package suite and typecheck</summary> `pnpm --filter @objectstack/service-automation typecheck && pnpm --filter @objectstack/service-automation test` under the verify lock at 18e9316 (the final head): `VERDICT command-exit 0`, Test Files 289 passed (289), Tests 4195 passed (4195). </details> <details><summary>Ablations (each committed first, landed through ablation-replace, restored to the HEAD blob)</summary> - header forced to the braces form (`braceRuleRefused` to `true`): 3 failed, the three neutral cases. - value-envelope kind forced to non-brace: 1 failed, the template-dialect envelope case. - the code arm of the envelope kind forced to non-brace: 1 failed, the braced CEL envelope case. Each restore: `blob == HEAD (204687c)`, `git diff HEAD` empty. </details> ## Acceptance notes - The brace class follows the card's list plus the two retired-token judges whose refusals are by construction `{…}` tokens; a `{{ }}` hole over an unbound `$` name is deliberately NOT brace class (its braces are the legal hole syntax). - The neutral header carries no ADR citation: ADR-0032 §1a is the build-time parse rule, and a date-text verdict is not a parse error. ## Verification <details><summary>Derived gate families (dispatch-gates --commands at 18e9316, 72 families)</summary> 71 exit 0 · 1 NOT MEASURED: `node scripts/check-plugin-teardown-shape.mjs --self-test` exit 3 (shallow checkout cannot reach its pinned positive control; CI runs it). `pnpm check:dual-build-cjs-loads` first exited 3 (no dist), re-run after the closure build: exit 0. `dispatch-gates --ran`: 72 derived, 71 run, 1 NOT-MEASURED, 0 UNRUN. </details> Two-minute check: `pnpm --filter @objectstack/service-automation exec vitest run src/flow-registration-checks.test.ts` and expect 32 passed, among them the describe "the invalid-expression header names the braces rule only over a brace refusal". --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgUZrkMKgGrXXe8zPGq)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgUZrkMKgGrXXe8zPGq <!-- signed: repo:objectstack#1 · os-sales · session_01L6bhgUZrkMKgGrXXe8zPGq --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f6b095a commit 3ce6b65

5 files changed

Lines changed: 214 additions & 20 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/service-automation': patch
3+
---
4+
5+
fix(service-automation): the "invalid expression" registration refusal names the template-braces rule only when a refusal it lists is a brace refusal
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Registering a flow whose only refused expression is not about braces — the date-text verdict on `timestamp(record.borrow_date)` over a date field, an unknown function, a `{{ }}` hole over a `$` name the engine does not bind — used to open with the ADR-0032 §1a braces sentence ("Predicates … must not wrap references in `{…}` template braces …"), telling the author about a mistake they did not make. That refusal now opens with a neutral count, `Flow 'X' has N invalid expression(s); each is refused for the reason given with it, and the flow does not register until every one is fixed:`. The braces sentence, unchanged, still heads any list that holds a brace refusal: a `{…}` brace in a CEL slot, a single-brace token in a text slot, a retired `{…}` token in a value slot, or an envelope naming the wrong dialect for its slot.
11+
12+
Which flows are refused, and every refusal line listed under the header, are unchanged.

‎packages/services/service-automation/src/dag-traversal.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import { FlowValueSlotSchema, VALUE_ENVELOPE_REFUSAL } from '@objectstack/spec/a
6363
// `previous.*`, `budget > 100000`, …) skipped its flow. A static import binds the
6464
// engine at module load in both ESM and CJS builds.
6565
import { ExpressionEngine, validateExpression } from '@objectstack/formula';
66+
import type { ExprValidationCode } from '@objectstack/formula';
6667
import { readPartialSteps } from './partial-steps.js';
6768
import { isRegionSuspensionRefusal, refuseRegionSuspension } from './region-suspension-refusal.js';
6869
import { stampFlowRunSlot } from './flow-slots.js';
@@ -1065,11 +1066,25 @@ export function celScope(
10651066
return { extra: { ...vars, vars, current_user: runUserOf(context) } };
10661067
}
10671068

1069+
/**
1070+
* One refusal {@link valueEnvelopeRefusals} returns. `code` is the
1071+
* expression judge's own refusal code (`@objectstack/formula`), present
1072+
* exactly when the refusal came from `validateExpression`; a refusal of the
1073+
* envelope's SHAPE (no envelope, no or blank `source`, a dialect other than
1074+
* `cel`) carries none. `registerFlow` reads it to say which rule its header
1075+
* names; the message is unchanged by it.
1076+
*/
1077+
export interface ValueEnvelopeRefusal {
1078+
readonly message: string;
1079+
readonly source: string;
1080+
readonly code?: ExprValidationCode;
1081+
}
1082+
10681083
/** The body of {@link AutomationEngine.valueEnvelopeRefusals}; that method's docblock is its contract. */
10691084
export function valueEnvelopeRefusals(
10701085
value: unknown,
10711086
fieldTypes?: Readonly<Record<string, string>>,
1072-
): { message: string; source: string }[] {
1087+
): ValueEnvelopeRefusal[] {
10731088
// [#16439] Presence, asked before either primitive, because neither can
10741089
// answer it (see rule 0 above). It is stated HERE and not as a guard in
10751090
// {@link evaluateValueEnvelope} deliberately: a reject reason living
@@ -1122,6 +1137,7 @@ export function valueEnvelopeRefusals(
11221137
return parsed.errors.map((e) => ({
11231138
message: `${VALUE_ENVELOPE_REFUSAL} ${e.message}`,
11241139
source: e.source,
1140+
code: e.code,
11251141
}));
11261142
}
11271143

‎packages/services/service-automation/src/engine.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ import {
129129
startConditionHolds,
130130
executeWithoutRetry,
131131
type runUserOf,
132+
type ValueEnvelopeRefusal,
132133
} from './dag-traversal.js';
133134
import { activeDryRunExecuteNode, dryRun as dryRunBody, type DryRunHost } from './dry-run.js';
134135
// [#25222] The run history's bodies: recording a run's log entry, finishing a
@@ -11669,7 +11670,7 @@ export class AutomationEngine implements IAutomationService {
1166911670
private valueEnvelopeRefusals(
1167011671
value: unknown,
1167111672
fieldTypes?: Readonly<Record<string, string>>,
11672-
): { message: string; source: string }[] {
11673+
): ValueEnvelopeRefusal[] {
1167311674
// The body lives in ./dag-traversal.ts (#25222).
1167411675
return valueEnvelopeRefusals(value, fieldTypes);
1167511676
}

‎packages/services/service-automation/src/flow-registration-checks.test.ts‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,106 @@ describe('registration: an inline outbound call retried in an after-save flow is
258258
expect(await registers(flowOf(undefined, guarded(http())))).toBe(true);
259259
});
260260
});
261+
262+
/**
263+
* The "invalid expression" refusal names the braces rule (ADR-0032 §1a) only
264+
* when a refusal it lists is one that rule speaks to — a `{…}` brace in a CEL
265+
* slot, a single-brace token in a text slot, a retired `{…}` token in a value
266+
* slot, an envelope naming the wrong dialect. Over any other list (a date-text
267+
* verdict, an unknown function) the header is a neutral count, so the author
268+
* is not first told about a mistake they did not make. The refused flows and
269+
* every listed line are unchanged; only the header above the list moves.
270+
*/
271+
describe('registration: the invalid-expression header names the braces rule only over a brace refusal', () => {
272+
const BRACES_HEADER = (count: number) =>
273+
`Flow 'loan_due' has ${count} invalid expression${count > 1 ? 's' : ''} (ADR-0032 §1a). ` +
274+
"Predicates — conditions and declared bare-CEL slots such as a screen field's `visibleWhen` — " +
275+
'must not wrap references in `{…}` template braces, and neither may a value slot (a computed ' +
276+
'value is a CEL envelope, the list a `loop` or `map` iterates included):';
277+
const NEUTRAL_HEADER = (count: number) =>
278+
`Flow 'loan_due' has ${count} invalid expression${count > 1 ? 's' : ''}; each is refused for the ` +
279+
'reason given with it, and the flow does not register until every one is fixed:';
280+
const LOAN_SCHEMA = { fields: ['borrow_date', 'title'], fieldTypes: { borrow_date: 'date', title: 'text' } };
281+
282+
/** A record-triggered flow on `library_loan`: an optional decision, then an assignment, then an end. */
283+
const loanFlow = (opts: { assign?: unknown; condition?: string; successMessage?: string }) => {
284+
const nodes: unknown[] = [
285+
{ id: 'start', type: 'start', label: 'Start', config: { objectName: 'library_loan', triggerType: 'record-after-update' } },
286+
];
287+
const edges: unknown[] = [];
288+
let prev = 'start';
289+
if (opts.condition !== undefined) {
290+
nodes.push({ id: 'gate', type: 'decision', label: 'Gate', config: { condition: opts.condition } });
291+
edges.push({ id: `e_${prev}`, source: prev, target: 'gate' });
292+
prev = 'gate';
293+
}
294+
if (opts.assign !== undefined) {
295+
nodes.push({ id: 'set', type: 'assignment', label: 'Set', config: { assignments: { due: opts.assign } } });
296+
edges.push({ id: `e_${prev}`, source: prev, target: 'set' });
297+
prev = 'set';
298+
}
299+
nodes.push({ id: 'end', type: 'end', label: 'End' });
300+
edges.push({ id: `e_${prev}`, source: prev, target: 'end' });
301+
return {
302+
name: 'loan_due', label: 'Loan due', type: 'record_change', nodes, edges,
303+
...(opts.successMessage === undefined ? {} : { successMessage: opts.successMessage }),
304+
};
305+
};
306+
const refusalOf = (flow: unknown): Error => {
307+
const engine = new AutomationEngine(loggerCapturing([]));
308+
engine.setObjectSchemaResolver((name) => (name === 'library_loan' ? LOAN_SCHEMA : undefined));
309+
try {
310+
engine.registerFlow('loan_due', flow as never);
311+
} catch (e) {
312+
return e as Error;
313+
}
314+
throw new Error('control: registerFlow was expected to refuse this flow');
315+
};
316+
const header = (e: Error) => e.message.split('\n')[0];
317+
const body = (e: Error) => e.message.split('\n').slice(1).join('\n');
318+
319+
const DATE_TEXT = { dialect: 'cel', source: 'timestamp(record.borrow_date)' };
320+
const BRACED_CONDITION = '{record.title} == "x"';
321+
322+
it('a date-text verdict alone: the neutral count header, no braces sentence, the verdict listed', () => {
323+
const e = refusalOf(loanFlow({ assign: DATE_TEXT }));
324+
expect(header(e)).toBe(NEUTRAL_HEADER(1));
325+
expect(e.message).not.toContain('template braces');
326+
expect(e.message).not.toContain('ADR-0032 §1a');
327+
expect(body(e)).toContain("node 'set' (assignment)");
328+
expect(body(e)).toContain('`isoDate(addDays(record.borrow_date, N))`');
329+
});
330+
331+
it('an unknown function in a predicate alone: the neutral count header', () => {
332+
const e = refusalOf(loanFlow({ condition: 'noSuchFn(record.title)' }));
333+
expect(header(e)).toBe(NEUTRAL_HEADER(1));
334+
expect(e.message).not.toContain('template braces');
335+
});
336+
337+
it('a `{{ }}` hole over an unbound `$` name in a text slot alone: the neutral count header', () => {
338+
const e = refusalOf(loanFlow({ successMessage: 'Done {{ $Nope }}' }));
339+
expect(header(e)).toBe(NEUTRAL_HEADER(1));
340+
expect(e.message).not.toContain('template braces');
341+
});
342+
343+
it('a braced predicate alone: the braces header, as before', () => {
344+
const e = refusalOf(loanFlow({ condition: BRACED_CONDITION }));
345+
expect(header(e)).toBe(BRACES_HEADER(1));
346+
});
347+
348+
it.each([
349+
['a retired `{…}` token in a value slot literal', { assign: 'Due {record.title}' }],
350+
['a value envelope naming the template dialect', { assign: { dialect: 'template', source: 'Due' } }],
351+
['a CEL value envelope wrapping a reference in braces', { assign: { dialect: 'cel', source: '{record.title}' } }],
352+
['a single-brace token in the flow\'s text slot', { successMessage: 'Done {record.title}' }],
353+
])('%s alone: the braces header', (_label, opts) => {
354+
expect(header(refusalOf(loanFlow(opts)))).toBe(BRACES_HEADER(1));
355+
});
356+
357+
it('a mix: the braces header over both lines, each line byte-identical to its solo listing', () => {
358+
const mixed = refusalOf(loanFlow({ condition: BRACED_CONDITION, assign: DATE_TEXT }));
359+
expect(header(mixed)).toBe(BRACES_HEADER(2));
360+
expect(body(mixed)).toContain(body(refusalOf(loanFlow({ condition: BRACED_CONDITION }))));
361+
expect(body(mixed)).toContain(body(refusalOf(loanFlow({ assign: DATE_TEXT }))));
362+
});
363+
});

0 commit comments

Comments
 (0)