Skip to content

Commit a708eff

Browse files
committed
test(lint): pin every flow-condition type-mismatch site and the MCP gate parity
Formula pins for type-mismatch-run-may-fail and the record-root pass, lint pins for record.x / decision on record-triggered and other flows, MCP validate_expression parity against the gate for each severity and trigger kind, publish-door cases, the ADR-0087 semantic entry and the changeset. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzf4UmgvS2cusNbWnvy
1 parent 1200680 commit a708eff

9 files changed

Lines changed: 399 additions & 11 deletions
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
'@objectstack/formula': minor
3+
'@objectstack/lint': minor
4+
'@objectstack/mcp': minor
5+
'@objectstack/spec': minor
6+
---
7+
8+
fix(lint)!: every flow condition's text-vs-number comparison gets a verdict that says what the run does — a record-triggered flow's `record.<field>` read and `decision` branch are refused like its bare name, and any other flow's warning says the run fails instead of "evaluates to null" (#29959)
9+
10+
Clause-②: yes (narrowing) — the author-time gate (`os build`, `os validate`, the package publish and the flow publish door) refuses, on a record-triggered flow, a `type-mismatch` in a `decision` branch and in a `record.<field>` / `previous.<field>` read of a start or edge condition, which it passed with no verdict before; and a flow condition's `type-mismatch` warning is served under its own code `type-mismatch-run-may-fail` instead of `type-mismatch`. Added beside them (the widening half): the optional `severity` and `triggerKind` inputs of the `validate_expression` MCP tool, and the code `type-mismatch-run-may-fail` in `@objectstack/formula`'s `ExpressionRefusalCode`.
11+
Metadata-protocol: narrowed
12+
Skills-docs: updated here — `content/docs/data-modeling/formulas.mdx` (the type-soundness row names the decision branch, the `record.<field>` read and the warning on other flows) and the MCP skill text in `packages/mcp/src/skill-md.ts` (the two new `validate_expression` inputs); `skills/**` teaches no text-vs-number comparison in a flow condition (grep for `type mismatch`, `evaluates to null`, `validate_expression` and the decision examples), so no skill or eval moves.
13+
14+
<!-- adr-0087: registered flow-record-read-and-decision-type-mismatch-refused -->
15+
16+
**BREAKING** accept-set narrowing at the author-time expression gate, served by `os build`, `os validate` and `POST /api/v1/packages/:id/publish-drafts`.
17+
18+
- **Record-triggered flows — before.** The start and edge conditions refused `name > 5` on a text field (`type-mismatch-run-fails`), but `record.name > 5` in the same slot, and `name > 5` in a `decision` node's `config.conditions[].expression`, published with no verdict at all. Both fail the run the same way: the engine's `evaluateCondition` throws on the fault, the run binds the trigger record both as `record` and flattened to bare names, and a decision branch is evaluated over the same variables as an edge.
19+
- **Now.** Both are refused as `expression-invalid` at `severity: error`, code `type-mismatch-run-fails`, with the message the bare name already gets: the run fails at the condition and the triggering write still lands. `previous.<field>` is judged the same way. The date verdicts stay on the bare name only, as before.
20+
- **Any other flow** (no `triggerType`, a `schedule` or time-relative flow, an `api` flow) and an inert node `condition` keep a warning. Its text said the expression "silently evaluates to null", which is false on every flow: a condition that faults fails the run. It is now `type-mismatch-run-may-fail`, worded for the failed run, and a warning because such a flow is handed whatever its entrance carries (an API request body, an action's partial record, a parent flow's record, or nothing), so the field's type is not proven to be what the name holds. A `record.<field>` read and a `decision` branch there get the same warning. The flow registration log line reads the same text.
21+
- **`validate_expression` (MCP).** Two optional inputs, so the tool answers what the gate will: `severity` (`error` | `warning` | `info`, site `validation`; default `error`) gives an advisory rule the gate's `type-mismatch-fail-open` instead of the fail-closed verdict, and `triggerKind` (`record_change` | `time_relative` | `schedule` | `api` | `none`, site `flow_condition`; default `record_change`) gives a flow that is not record-triggered the gate's warning instead of the run-fails error. Either input on a site it does not describe is refused as a tool error. A call that passes neither answers as before.
22+
- **`@objectstack/spec`.** Upgrade guide entry `flow-record-read-and-decision-type-mismatch-refused` (semantic: no mechanical rewrite).
23+
24+
**FROM → TO.** In a record-triggered flow: `record.name > 5` (or a decision branch `name > 5`) on a text field → `size(record.name) > 5` for its length, `record.score > 5` on a number field for a value, or `double(record.name) > 5` only when every value is numeric text. A boolean: `record.active > 0` → `record.active == true`. A consumer keyed to the code of a flow condition's warning: `type-mismatch` → `type-mismatch-run-may-fail` (`@objectstack/formula@18.3.0` and `@objectstack/mcp@18.3.0` serve `type-mismatch` there; the record-scoped `type-mismatch`, on a formula field or a display predicate, is unchanged).

‎packages/formula/src/expression-refusal-codes.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,35 @@ const PINS: { readonly [C in ExpressionRefusalCode]: readonly [Pin<C>, ...Pin<C>
427427
'length, `double(record.name)` for its value (which itself faults on text that is not a number).',
428428
},
429429
],
430+
// [#29959] A flow condition the caller declared no outcome for: still a
431+
// warning, worded for the failed run a fault is there (never a null). The
432+
// second case is the `record.<field>` read, judged as its bare name is.
433+
'type-mismatch-run-may-fail': [
434+
{
435+
produce: () => onlyWarning('predicate', 'name > 5', { scope: 'flattened', fields: ['name'], fieldTypes: { name: 'text' } }),
436+
params: { operands: 'string > int', operator: '>', held: 'text', reference: 'name' },
437+
message:
438+
'type mismatch `string > int` — `name` holds text but is used with `>` against a number. CEL has no such operation, so ' +
439+
'wherever the value is not numeric text (an empty value included) the expression faults, and a flow condition that ' +
440+
'faults when it is evaluated fails the run: the flow stops at this condition and the work it exists to do is not done ' +
441+
'(it does not read null). Whether `name` holds text there depends on what the run binds — on a flow that is not ' +
442+
'record-triggered, whatever started it — so this is a warning, not a refusal. ' +
443+
'Compare like with like: use a number field, compare text with text, or convert explicitly — `size(name)` for its ' +
444+
'length, `double(name)` for its value (which itself faults on text that is not a number).',
445+
},
446+
{
447+
produce: () =>
448+
onlyWarning('predicate', 'record.active > 0', { scope: 'flattened', fields: ['active'], fieldTypes: { active: 'boolean' } }),
449+
params: { operands: 'bool > int', operator: '>', held: 'boolean', reference: 'record.active' },
450+
message:
451+
'type mismatch `bool > int` — `record.active` holds a boolean but is used with `>` against a number. CEL has no such ' +
452+
'operation, so wherever the value is not numeric text (an empty value included) the expression faults, and a flow ' +
453+
'condition that faults when it is evaluated fails the run: the flow stops at this condition and the work it exists ' +
454+
'to do is not done (it does not read null). Whether `record.active` holds a boolean there depends on what the run ' +
455+
'binds — on a flow that is not record-triggered, whatever started it — so this is a warning, not a refusal. ' +
456+
'Compare a boolean with `true` / `false`, or use a number field.',
457+
},
458+
],
430459
'field-near-miss': [
431460
{
432461
produce: () => onlyWarning('predicate', "stauts == 'x'", { fields: ['status'], objectName: 'deal' }),
@@ -611,6 +640,9 @@ const SWEEP_SCHEMAS: readonly (ExprSchemaHint | undefined)[] = [
611640
fieldTypes: { name: 'text', active: 'boolean' },
612641
faultOutcome,
613642
})),
643+
// [#29959] A flattened (flow) condition with no declared outcome reaches
644+
// `type-mismatch-run-may-fail`, bare and through `record.`.
645+
{ scope: 'flattened', objectName: 'deal', fields: ['amount', 'name', 'active'], fieldTypes: { name: 'text', active: 'boolean' } },
614646
{ fields: ['status'] },
615647
{ fieldTypes: { account: 'lookup' }, traversalHydration: true },
616648
];

‎packages/formula/src/validate.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,45 @@ describe('validateExpression (ADR-0032)', () => {
806806
}
807807
});
808808

809+
// [#29959] A flow condition reads the field bare AND as `record.<field>`
810+
// (`seedRunVariables` binds both to the trigger record), so the record
811+
// read gets the bare name's verdict: here the run-fails error.
812+
it('judges a flattened condition\'s record.<field> and previous.<field> reads as its bare name (#29959)', () => {
813+
const flat = { ...schema, scope: 'flattened' as const, faultOutcome: 'run-fails' as const };
814+
for (const [source, reference] of [
815+
['record.name > 5', 'record.name'],
816+
['previous.name * 2 > 1', 'previous.name'],
817+
['record.is_active > 0', 'record.is_active'],
818+
] as const) {
819+
const r = validateExpression('predicate', source, flat);
820+
expect(r.warnings, source).toHaveLength(0);
821+
expect(r.errors.map((e) => [e.code, e.params.reference]), source).toEqual([['type-mismatch-run-fails', reference]]);
822+
expect(r.errors[0].message, source).toContain(`\`${reference}\``);
823+
}
824+
// Controls: a well-typed record read, a number field, and the
825+
// conversions the message names stay clean.
826+
for (const fixed of ['size(record.name) > 5', 'double(record.name) > 5', 'record.amount > 5', "record.name == 'x'", 'record.is_active == true']) {
827+
const ok = validateExpression('predicate', fixed, flat);
828+
expect([ok.errors, ok.warnings], fixed).toEqual([[], []]);
829+
}
830+
});
831+
832+
// [#29959] With no declared outcome a flattened condition is a flow's
833+
// that is not proven to bind the field: a warning, but one saying the run
834+
// fails on the fault, since a flow condition never reads null.
835+
it('warns with the run-may-fail wording on a flattened condition with no declared outcome (#29959)', () => {
836+
const flat = { ...schema, scope: 'flattened' as const };
837+
for (const source of ['name > 5', 'record.name > 5']) {
838+
const r = validateExpression('predicate', source, flat);
839+
expect(r.errors, source).toHaveLength(0);
840+
expect(r.warnings.map((w) => w.code), source).toEqual(['type-mismatch-run-may-fail']);
841+
expect(r.warnings[0].message, source).toContain('fails the run');
842+
expect(r.warnings[0].message, source).not.toMatch(/evaluates to null|still lands|is refused/);
843+
}
844+
// The record scope's warning keeps its own code and its true text there.
845+
expect(validateExpression('predicate', 'record.name > 5', schema).warnings.map((w) => w.code)).toEqual(['type-mismatch']);
846+
});
847+
809848
it('errors with the skipped-advisory wording where the caller declares fail-open (#29926)', () => {
810849
const r = validateExpression('predicate', 'record.name > 5', { ...schema, faultOutcome: 'fail-open' });
811850
expect(r.warnings).toHaveLength(0);

‎packages/formula/src/validate.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ function typeSoundnessIssue(
425425
),
426426
};
427427
}
428-
const heldKind = mismatch.celType === 'bool' ? 'boolean' : 'text';
428+
const heldKind: 'boolean' | 'text' = mismatch.celType === 'bool' ? 'boolean' : 'text';
429429
const held = heldKind === 'boolean' ? 'a boolean' : 'text';
430430
const subject = ref ? `${ref} holds ${held}` : `${held === 'a boolean' ? 'a boolean' : 'a text'} field`;
431431
const params = {

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

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,33 +1004,103 @@ describe('validateStackExpressions (ADR-0032 build-time)', () => {
10041004
expect(found[0].message).toMatch(/`size\(title\)`/);
10051005
});
10061006

1007-
it('keeps the warning on a flow that is not record-triggered: start and edge conditions (#29926)', () => {
1008-
// No `triggerType` (the shape the pre-existing flattened-flow pin uses)
1009-
// and a `schedule` start: neither is `record_change`, so the ledger
1010-
// declares no outcome there and the verdict stays the warning.
1011-
for (const [name, startConfig] of [
1012-
['plain_flow', {}],
1013-
['sched_flow', { schedule: '0 * * * *' }],
1007+
it('keeps the warning on a flow that is not record-triggered, worded for the run it fails (#29926, #29959)', () => {
1008+
// No `triggerType` (the shape the pre-existing flattened-flow pin uses),
1009+
// a `schedule` start and an `api` flow: none is `record_change`, so the
1010+
// ledger declares no outcome there and the verdict stays the warning.
1011+
// [#29959] Its text is the run's: `evaluateCondition` throws on a fault
1012+
// on every flow, so "silently evaluates to null" was false here too. The
1013+
// `record.<field>` read and the `decision` branch get the same verdict.
1014+
for (const [name, startConfig, flowType] of [
1015+
['plain_flow', {}, 'autolaunched'],
1016+
['sched_flow', { schedule: '0 * * * *' }, 'autolaunched'],
1017+
['api_flow', {}, 'api'],
10141018
] as const) {
10151019
const issues = validateStackExpressions({
10161020
objects: [{ name: 'crm_opportunity', fields: { title: { type: 'text', required: true } } }],
10171021
flows: [{
10181022
name,
1023+
type: flowType,
10191024
nodes: [
10201025
{ id: 'start', type: 'start', config: { objectName: 'crm_opportunity', condition: 'title * 2 > 10', ...startConfig } },
1026+
{ id: 'route', type: 'decision', config: { conditions: [{ label: 'Long', expression: 'title > 5' }] } },
10211027
{ id: 'end', type: 'end' },
10221028
],
1023-
edges: [{ id: 'e1', source: 'start', target: 'end', condition: 'title > 5' }],
1029+
edges: [
1030+
{ id: 'e1', source: 'start', target: 'route', condition: 'record.title > 5' },
1031+
{ id: 'e2', source: 'route', target: 'end', label: 'Long' },
1032+
],
10241033
}],
10251034
});
10261035
const found = typeMismatches(issues);
10271036
expect(found.map(i => [i.where, i.severity]), name).toEqual([
10281037
[`flow '${name}' · node 'start' (start) condition`, 'warning'],
1029-
[`flow '${name}' · edge 'e1' (start→end) condition`, 'warning'],
1038+
[`flow '${name}' · node 'route' (decision) decision branch expression at config.conditions[0].expression`, 'warning'],
1039+
[`flow '${name}' · edge 'e1' (start→route) condition`, 'warning'],
10301040
]);
1041+
for (const i of found) {
1042+
expect(i.message, `${name} ${i.where}`).toContain('a flow condition that faults when it is evaluated fails the run');
1043+
expect(i.message, `${name} ${i.where}`).not.toMatch(/evaluates to null|still lands/);
1044+
}
1045+
expect(found[2]!.message).toContain('`record.title` holds text');
10311046
}
10321047
});
10331048

1049+
// [#29959] The two sites #29926 left without the run-fails verdict on a
1050+
// record-triggered flow: a `record.<field>` read (the same trigger record
1051+
// as the bare name) and a `decision` branch (evaluated like an edge).
1052+
it('refuses a type mismatch in a record.x read and a decision branch of a record-triggered flow (#29959)', () => {
1053+
const issues = validateStackExpressions({
1054+
objects: [{ name: 'crm_opportunity', fields: { title: { type: 'text', required: true }, won: { type: 'boolean' } } }],
1055+
flows: [{
1056+
name: 'rt_flow',
1057+
nodes: [
1058+
{ id: 'start', type: 'start', config: { objectName: 'crm_opportunity', triggerType: 'record-after-update', condition: 'record.title > 5' } },
1059+
{ id: 'route', type: 'decision', config: { conditions: [{ label: 'Long', expression: 'title * 2 > 10' }, { label: 'Won', expression: 'record.won > 0' }] } },
1060+
{ id: 'end', type: 'end' },
1061+
],
1062+
edges: [
1063+
{ id: 'e1', source: 'start', target: 'route', condition: 'previous.title > 5' },
1064+
{ id: 'e2', source: 'route', target: 'end', label: 'Long' },
1065+
{ id: 'e3', source: 'route', target: 'end', label: 'Won' },
1066+
],
1067+
}],
1068+
});
1069+
const found = typeMismatches(issues);
1070+
expect(found.map(i => [i.where, i.severity, i.path])).toEqual([
1071+
["flow 'rt_flow' · node 'start' (start) condition", 'error', 'flows[0].nodes[0].config.condition'],
1072+
["flow 'rt_flow' · node 'route' (decision) decision branch expression at config.conditions[0].expression", 'error', 'flows[0].nodes[1].config.conditions[0].expression'],
1073+
["flow 'rt_flow' · node 'route' (decision) decision branch expression at config.conditions[1].expression", 'error', 'flows[0].nodes[1].config.conditions[1].expression'],
1074+
["flow 'rt_flow' · edge 'e1' (start→route) condition", 'error', 'flows[0].edges[0].condition'],
1075+
]);
1076+
for (const i of found) {
1077+
expect(i.message, i.where).toContain('fails the run: the flow stops at this condition, the write that fired it still lands');
1078+
expect(i.message, i.where).not.toMatch(/evaluates to null|is refused/);
1079+
}
1080+
expect(found.map(i => /`([\w.]+)` holds/.exec(i.message)?.[1])).toEqual(['record.title', 'title', 'record.won', 'previous.title']);
1081+
});
1082+
1083+
it('leaves a well-typed record.x read and decision branch of a record-triggered flow clean (#29959)', () => {
1084+
const issues = validateStackExpressions({
1085+
objects: [{ name: 'crm_opportunity', fields: { title: { type: 'text', required: true }, amount: { type: 'number', required: true }, won: { type: 'boolean' } } }],
1086+
flows: [{
1087+
name: 'rt_flow',
1088+
nodes: [
1089+
{ id: 'start', type: 'start', config: { objectName: 'crm_opportunity', triggerType: 'record-after-update', condition: 'size(record.title) > 5' } },
1090+
{ id: 'route', type: 'decision', config: { conditions: [{ label: 'Big', expression: 'record.amount > 10' }, { label: 'Won', expression: 'won == true' }] } },
1091+
{ id: 'end', type: 'end' },
1092+
],
1093+
edges: [
1094+
{ id: 'e1', source: 'start', target: 'route', condition: "record.title != 'x'" },
1095+
{ id: 'e2', source: 'route', target: 'end', label: 'Big' },
1096+
{ id: 'e3', source: 'route', target: 'end', label: 'Won' },
1097+
],
1098+
}],
1099+
});
1100+
expect(typeMismatches(issues)).toEqual([]);
1101+
expect(issues.filter(i => i.severity === 'error')).toEqual([]);
1102+
});
1103+
10341104
it('keeps the warning on an inert node condition of a record-triggered flow (#29926)', () => {
10351105
const issues = validateStackExpressions({
10361106
objects: [{ name: 'crm_opportunity', fields: { title: { type: 'text', required: true } } }],
@@ -3962,6 +4032,10 @@ describe('validateStackExpressions — reads only keys the spec declares (meta-t
39624032
// `severity`, `recordTriggered`), built at each call site from the
39634033
// tabled receivers (`rule.severity`) — never read off metadata itself.
39644034
'site',
4035+
// [#29959] A `decision` branch's flow-condition hint (`objectName`,
4036+
// `faultOutcome`), built at the call site from the walk's own
4037+
// `objectName` and the ledger's answer — never read off metadata itself.
4038+
'flowCondition',
39654039
]);
39664040
expect(receivers.filter((r) => !tabled.has(r) && !PLUMBING.has(r))).toEqual([]);
39674041
});

‎packages/mcp/src/mcp-http-tools.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ const VALIDATION_SEVERITIES = ['error', 'warning', 'info'] as const satisfies re
681681
* autolaunched flow started by hand, an action or a parent flow).
682682
*/
683683
type FlowTriggerOrNone = FlowTriggerKind | 'none';
684-
const FLOW_TRIGGER_INPUTS = [...FLOW_TRIGGER_KINDS, 'none'] as [FlowTriggerOrNone, ...FlowTriggerOrNone[]];
684+
const FLOW_TRIGGER_INPUTS: [FlowTriggerOrNone, ...FlowTriggerOrNone[]] = ['none', ...FLOW_TRIGGER_KINDS];
685685

686686
// ── Tool arguments: an undeclared key is REFUSED, not stripped (#16913) ──────
687687

0 commit comments

Comments
 (0)