Skip to content

Commit 489409a

Browse files
committed
wip: consumers hand the node; ratchet reads the sibling-block channel
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibzGExkj8nxREmV7FjX
1 parent 7abeaf4 commit 489409a

4 files changed

Lines changed: 199 additions & 10 deletions

File tree

‎packages/services/service-automation/src/builtin/config-expression-ledger.test.ts‎

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import { describe, it, expect } from 'vitest';
2929
import {
3030
FLOW_NODE_EXPRESSION_PATHS,
31+
FLOW_NODE_SIBLING_EXPRESSION_BLOCKS,
3132
flowNodeConfigRefusals,
33+
getFlowNodeSiblingBlockJsonSchemas,
3234
getSchemalessNodeConfigJsonSchemas,
3335
resolveFlowNodeExpressions,
3436
type FlowNodeExpressionRole,
@@ -126,7 +128,7 @@ function collectExpressionProps(
126128
const engine = new AutomationEngine(silentLogger());
127129
installBuiltinNodes(engine, ctx());
128130

129-
type DeclaredSlot = { nodeType: string; path: string; role: FlowNodeExpressionRole; required: boolean };
131+
type DeclaredSlot = { nodeType: string; block?: string; path: string; role: FlowNodeExpressionRole; required: boolean };
130132

131133
/** Resolve an `xExpression` marker to its ledger role, failing loudly on an unknown one. */
132134
function roleOf(nodeType: string, path: string, marker: string): FlowNodeExpressionRole {
@@ -177,12 +179,39 @@ function declaredFromSchemalessConfigs(): DeclaredSlot[] {
177179
return found;
178180
}
179181

180-
/** Every declared expression slot, from BOTH declaration channels. */
182+
/**
183+
* [#27968] Declared expression slots in a node's SIBLING blocks — the blocks
184+
* of `FlowNodeSchema` beside `config` (`connectorConfig`, `waitEventConfig`,
185+
* …), whose own Zod carries the marker. The ledger roots such a slot in its
186+
* block (`block`), and the block names its node type through
187+
* `FLOW_NODE_SIBLING_EXPRESSION_BLOCKS`. Every block is walked, so a marker on
188+
* one the table does not name fails here: a slot no consumer can reach.
189+
*/
190+
function declaredFromSiblingBlocks(): DeclaredSlot[] {
191+
const found: DeclaredSlot[] = [];
192+
const nodeTypeOf: Readonly<Record<string, string>> = FLOW_NODE_SIBLING_EXPRESSION_BLOCKS;
193+
for (const [block, json] of Object.entries(getFlowNodeSiblingBlockJsonSchemas())) {
194+
for (const { path, marker, required } of collectExpressionProps(json as SchemaNode)) {
195+
const nodeType = nodeTypeOf[block];
196+
expect(
197+
nodeType,
198+
`FlowNodeSchema.${block}.${path} declares an xExpression marker on a block the ledger cannot root a path in — `
199+
+ 'name the block and its node type in FLOW_NODE_SIBLING_EXPRESSION_BLOCKS',
200+
).toBeDefined();
201+
found.push({ nodeType: nodeType!, block, path, role: roleOf(nodeType!, `${block}.${path}`, marker), required });
202+
}
203+
}
204+
return found;
205+
}
206+
207+
/** Every declared expression slot, from ALL THREE declaration channels. */
181208
function declaredEverywhere(): DeclaredSlot[] {
182-
return [...declaredFromDescriptors(), ...declaredFromSchemalessConfigs()];
209+
return [...declaredFromDescriptors(), ...declaredFromSchemalessConfigs(), ...declaredFromSiblingBlocks()];
183210
}
184211

185-
const key = (e: { nodeType: string; path: string; role: string }) => `${e.nodeType}.${e.path} (${e.role})`;
212+
/** `nodeType.path (role)`, the path prefixed with its block when it is not `config` (#27968). */
213+
const key = (e: { nodeType: string; block?: string; path: string; role: string }) =>
214+
`${e.nodeType}.${e.block === undefined ? '' : `${e.block}.`}${e.path} (${e.role})`;
186215

187216
describe('configSchema ↔ expression-ledger reconciliation (#4027)', () => {
188217
it('every xExpression property a builtin declares is in the ledger', () => {
@@ -206,6 +235,7 @@ describe('configSchema ↔ expression-ledger reconciliation (#4027)', () => {
206235
it.each([
207236
['descriptor configSchema', declaredFromDescriptors],
208237
['schemaless-node-config.zod.ts', declaredFromSchemalessConfigs],
238+
['FlowNodeSchema sibling-block', declaredFromSiblingBlocks],
209239
] as const)('derives at least one slot from the %s channel', (_channel, derive) => {
210240
expect(derive().length).toBeGreaterThan(0);
211241
});
@@ -274,6 +304,28 @@ describe('configSchema ↔ expression-ledger reconciliation (#4027)', () => {
274304
}
275305
});
276306

307+
/**
308+
* [#27968] A `connector_action` node's `connectorConfig.input` is a `value`
309+
* slot rooted in the node's sibling block, declared on that block's own Zod
310+
* (`FlowNodeSchema.connectorConfig`'s `input` map value) and on no `config`
311+
* channel — the node publishes no `configSchema` and has no `config`
312+
* contract. Before #27968 the ledger could address `config` only, so the
313+
* slot the executor evaluates was judged by neither door.
314+
*/
315+
it('connector_action connectorConfig.input.* is covered — the #27968 sibling-block value slot', () => {
316+
const slot = FLOW_NODE_EXPRESSION_PATHS.find(
317+
(e) => e.nodeType === 'connector_action' && e.block === 'connectorConfig' && e.path === 'input.*',
318+
);
319+
expect(slot, 'the slot the connector_action executor evaluates through resolveValueSlotMap').toBeDefined();
320+
expect(slot!.role).toBe('value');
321+
expect(declaredFromSiblingBlocks().map(key)).toEqual(['connector_action.connectorConfig.input.* (value)']);
322+
expect(declaredFromDescriptors().filter((d) => d.nodeType === 'connector_action')).toEqual([]);
323+
expect(declaredFromSchemalessConfigs().filter((d) => d.nodeType === 'connector_action')).toEqual([]);
324+
// The table names exactly the blocks a slot is declared in — no block an
325+
// entry could be rooted in with nothing declaring it.
326+
expect(Object.keys(FLOW_NODE_SIBLING_EXPRESSION_BLOCKS)).toEqual(['connectorConfig']);
327+
});
328+
277329
it('decision.conditions[].expression is covered — the #4439 hole', () => {
278330
const decision = FLOW_NODE_EXPRESSION_PATHS.find(
279331
(e) => e.nodeType === 'decision' && e.path === 'conditions[].expression',
@@ -423,6 +475,7 @@ describe('configSchema ↔ expression-ledger reconciliation (#4027)', () => {
423475
const markers = [
424476
...engine.getActionDescriptors().flatMap((d) => collectExpressionProps(d.configSchema as SchemaNode)),
425477
...Object.values(getSchemalessNodeConfigJsonSchemas()).flatMap((json) => collectExpressionProps(json as SchemaNode)),
478+
...Object.values(getFlowNodeSiblingBlockJsonSchemas()).flatMap((json) => collectExpressionProps(json as SchemaNode)),
426479
].map((p) => p.marker);
427480
expect(markers.length).toBeGreaterThan(0);
428481
expect(markers).not.toContain('template');

‎packages/spec/src/automation/flow-node-expression-paths.test.ts‎

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import { describe, expect, it } from 'vitest';
1818

1919
import {
2020
FLOW_NODE_EXPRESSION_PATHS,
21+
FLOW_NODE_SIBLING_EXPRESSION_BLOCKS,
2122
flowFilterOperands,
23+
flowNodeExpressionBlock,
2224
isExpressionEnvelopeShaped,
2325
resolveFlowNodeExpressions,
2426
resolveFlowNodeValueSlots,
@@ -550,7 +552,8 @@ describe('isExpressionEnvelopeShaped — the recognizer a value slot discriminat
550552
});
551553

552554
describe('every entry older than the value role resolves byte-identically (the ratchet\'s fixtures, restated)', () => {
553-
const byKey = (e: FlowNodeExpressionPath) => `${e.nodeType}.${e.path} (${e.role})`;
555+
const byKey = (e: FlowNodeExpressionPath) =>
556+
`${e.nodeType}.${e.block === undefined ? '' : `${e.block}.`}${e.path} (${e.role})`;
554557

555558
it('the entries that existed before are still declared exactly as they were — each value-slot widening only appended rows', () => {
556559
// The census: five rows before #19938, seven after, ten after #19939's
@@ -563,7 +566,9 @@ describe('every entry older than the value role resolves byte-identically (the r
563566
// `flow-template` role to `value` IN PLACE (`screen.fields[].visibleWhen`
564567
// keeps its `predicate` row beside the screen's value rows). Stage S4
565568
// appended the three `notify` value rows, stage S5 the `http` body's, and
566-
// stage S6 the three CRUD `filter` operand rows.
569+
// stage S6 the three CRUD `filter` operand rows. #27968 appended the first
570+
// row rooted in a sibling block rather than `config`: a `connector_action`
571+
// node's `connectorConfig.input` map.
567572
expect(FLOW_NODE_EXPRESSION_PATHS.map(byKey)).toEqual([
568573
'screen.fields[].visibleWhen (predicate)',
569574
'decision.conditions[].expression (predicate)',
@@ -585,6 +590,7 @@ describe('every entry older than the value role resolves byte-identically (the r
585590
'get_record.filter (value)',
586591
'update_record.filter (value)',
587592
'delete_record.filter (value)',
593+
'connector_action.connectorConfig.input.* (value)',
588594
]);
589595
});
590596

@@ -878,3 +884,61 @@ describe('every entry older than the value role resolves byte-identically (the r
878884
});
879885
});
880886
});
887+
888+
/**
889+
* [#27968] A ledger path rooted in a node's SIBLING block — a
890+
* `connector_action` node's `connectorConfig.input`, the map its executor
891+
* evaluates through the per-key value-slot resolver. The resolvers read the
892+
* block off the node they are handed, name the block in each result, and
893+
* answer a caller that hands only `config` for `config` alone.
894+
*/
895+
describe('a path rooted in a sibling block (#27968)', () => {
896+
const ENVELOPE = { dialect: 'cel', source: 'record.id' };
897+
const connectorNode = (input: Record<string, unknown>) => ({
898+
type: 'connector_action',
899+
connectorConfig: { connectorId: 'helpdesk', actionId: 'open_ticket', input },
900+
});
901+
902+
it('declares connector_action input.* in the connectorConfig block, as a value slot', () => {
903+
const entry = FLOW_NODE_EXPRESSION_PATHS.find((e) => e.nodeType === 'connector_action');
904+
expect(entry).toMatchObject({ block: 'connectorConfig', path: 'input.*', role: 'value' });
905+
expect(FLOW_NODE_SIBLING_EXPRESSION_BLOCKS).toEqual({ connectorConfig: 'connector_action' });
906+
expect(flowNodeExpressionBlock(entry!)).toBe('connectorConfig');
907+
// Every other entry is rooted in `config`.
908+
expect(FLOW_NODE_EXPRESSION_PATHS.filter((e) => e.block !== undefined)).toEqual([entry]);
909+
});
910+
911+
it('resolves the envelope in the block, located in it — the node handed, no config', () => {
912+
const node = connectorNode({ ticket: ENVELOPE, queue: 'support' });
913+
expect(resolveFlowNodeExpressions('connector_action', undefined, node)).toEqual([
914+
{ entry: expect.objectContaining({ block: 'connectorConfig' }), block: 'connectorConfig', path: 'input.ticket', value: ENVELOPE },
915+
]);
916+
// The value walk hands the literal over too, for the template judge.
917+
expect(resolveFlowNodeValueSlots('connector_action', undefined, node).map((f) => [f.block, f.path, f.value])).toEqual([
918+
['connectorConfig', 'input.ticket', ENVELOPE],
919+
['connectorConfig', 'input.queue', 'support'],
920+
]);
921+
});
922+
923+
it('answers a caller that hands only config for config alone', () => {
924+
const node = connectorNode({ ticket: ENVELOPE });
925+
expect(resolveFlowNodeExpressions('connector_action', undefined)).toEqual([]);
926+
expect(resolveFlowNodeValueSlots('connector_action', {})).toEqual([]);
927+
// A loose `config.input` (refused by the flow parse) is no position the
928+
// entry names: the block, never `config`, is read.
929+
expect(resolveFlowNodeExpressions('connector_action', { input: { ticket: ENVELOPE } }, { connectorConfig: {} })).toEqual([]);
930+
expect(resolveFlowNodeExpressions('connector_action', undefined, node)).toHaveLength(1);
931+
});
932+
933+
it('names `config` as the block of every config-rooted result', () => {
934+
const found = resolveFlowNodeExpressions('assignment', TWO_VARIABLE_ASSIGNMENT, connectorNode({ ticket: ENVELOPE }));
935+
expect(found.map((f) => [f.block, f.path])).toEqual([['config', 'assignments.digest']]);
936+
});
937+
938+
it('skips a block that is absent, null or not an object', () => {
939+
for (const connectorConfig of [undefined, null, 'x', 42]) {
940+
expect(resolveFlowNodeValueSlots('connector_action', undefined, { connectorConfig })).toEqual([]);
941+
}
942+
expect(resolveFlowNodeValueSlots('connector_action', undefined, { connectorConfig: { connectorId: 'a', actionId: 'b' } })).toEqual([]);
943+
});
944+
});

‎packages/spec/src/automation/flow-value-slot-template.test.ts‎

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ import {
5252
celExpression,
5353
celPath,
5454
} from './flow-template-token';
55-
import { FLOW_NODE_EXPRESSION_PATHS } from './flow-node-expression-paths';
55+
import { FLOW_NODE_EXPRESSION_PATHS, type FlowNodeExpressionPath } from './flow-node-expression-paths';
5656
import {
5757
VALUE_SLOT_TEMPLATE_REFUSAL,
5858
classifyFlowFilterOperandString,
5959
flowNodeValueTemplateRefusals,
6060
valueSlotTemplateRefusals,
61+
type FlowNodeValueTemplateRefusal,
6162
} from './flow-value-slot-template';
6263

6364
/**
@@ -87,6 +88,18 @@ function configForEntry(
8788
return entry.onlyWithKey === undefined ? config : { ...config, [entry.onlyWithKey]: { nodes: [], edges: [] } };
8889
}
8990

91+
/**
92+
* [#27968] The template refusals of a node carrying `value` at `entry`'s
93+
* position — in `config`, or in the sibling block the entry is rooted in,
94+
* handed over as the node's sibling blocks.
95+
*/
96+
function refusalsForEntry(entry: FlowNodeExpressionPath, value: unknown): FlowNodeValueTemplateRefusal[] {
97+
const at = configForEntry(entry, value);
98+
return entry.block === undefined
99+
? flowNodeValueTemplateRefusals(entry.nodeType, at)
100+
: flowNodeValueTemplateRefusals(entry.nodeType, undefined, { [entry.block]: at });
101+
}
102+
90103
/** The one refusal a string draws, or a failure naming what came back. */
91104
function refusalOf(value: unknown): string {
92105
const refusals = valueSlotTemplateRefusals(value);
@@ -588,6 +601,31 @@ describe('`flowNodeValueTemplateRefusals` — every value position of a node, lo
588601
const [refusal] = flowNodeValueTemplateRefusals('subflow', { flowName: 'child', input: { list: '{rows}' } });
589602
expect(refusal!.message).toContain("{ dialect: 'cel', source: 'rows' }");
590603
});
604+
605+
// [#27968] The one value slot rooted outside `config`: reached through the
606+
// node's sibling blocks, located in `connectorConfig`, with the generic
607+
// remedy — the action was handed the token's text, not nothing.
608+
it('a connector_action node\'s `connectorConfig.input` — the node handed for its sibling block', () => {
609+
const node = {
610+
type: 'connector_action',
611+
connectorConfig: {
612+
connectorId: 'helpdesk',
613+
actionId: 'open_ticket',
614+
input: { recordId: '{rec.id}', queue: 'support', tags: ['{rec.tag}'] },
615+
},
616+
};
617+
const refusals = flowNodeValueTemplateRefusals('connector_action', undefined, node);
618+
expect(refusals.map((r) => [r.block, r.path, r.label, r.source])).toEqual([
619+
['connectorConfig', 'input.recordId', 'connector_action input value', '{rec.id}'],
620+
['connectorConfig', 'input.tags[0]', 'connector_action input value', '{rec.tag}'],
621+
]);
622+
expect(refusals[0]!.message.startsWith(VALUE_SLOT_TEMPLATE_REFUSAL)).toBe(true);
623+
expect(refusals[0]!.message).toContain("{ dialect: 'cel', source: 'rec.id' }");
624+
expect(refusals[0]!.message).not.toMatch(/child flow|the function/);
625+
// Handed only `config`, the block is not read; every config refusal names `config`.
626+
expect(flowNodeValueTemplateRefusals('connector_action', undefined)).toEqual([]);
627+
expect(flowNodeValueTemplateRefusals('assignment', { assignments: { t: '{a}' } }, node).map((r) => r.block)).toEqual(['config']);
628+
});
591629
});
592630

593631
/**
@@ -731,7 +769,7 @@ describe('a callee\'s input map: the refusal says what the guarded form hands th
731769
const valueEntries = FLOW_NODE_EXPRESSION_PATHS.filter((e) => e.role === 'value');
732770
expect(valueEntries.filter((e) => CALLEE.has(`${e.nodeType} ${e.path}`))).toHaveLength(3);
733771
for (const entry of valueEntries) {
734-
const refusals = flowNodeValueTemplateRefusals(entry.nodeType, configForEntry(entry, '{x}'));
772+
const refusals = refusalsForEntry(entry, '{x}');
735773
expect(refusals, `${entry.nodeType} ${entry.path}`).toHaveLength(1);
736774
const carries = /is (the child flow|each item's child flow|the function)'s/.test(refusals[0]!.message);
737775
expect(carries, `${entry.nodeType} ${entry.path}`).toBe(CALLEE.has(`${entry.nodeType} ${entry.path}`));
@@ -836,7 +874,7 @@ describe('a screen\'s value slots: the refusal says what the client is served in
836874
const valueEntries = FLOW_NODE_EXPRESSION_PATHS.filter((e) => e.role === 'value');
837875
expect(valueEntries.filter((e) => SCREEN.has(`${e.nodeType} ${e.path}`))).toHaveLength(3);
838876
for (const entry of valueEntries) {
839-
const [refusal] = flowNodeValueTemplateRefusals(entry.nodeType, configForEntry(entry, '{x}'));
877+
const [refusal] = refusalsForEntry(entry, '{x}');
840878
const carries = /prefills (the object form|this screen field)|names the record an `edit` form opens/.test(refusal!.message);
841879
expect(carries, `${entry.nodeType} ${entry.path}`).toBe(SCREEN.has(`${entry.nodeType} ${entry.path}`));
842880
}
@@ -891,7 +929,7 @@ describe('a notify node\'s value slots: located per position, a recipient\'s ref
891929
it('only `recipients` carries it — one list: the ledger', () => {
892930
const valueEntries = FLOW_NODE_EXPRESSION_PATHS.filter((e) => e.role === 'value');
893931
for (const entry of valueEntries) {
894-
const [refusal] = flowNodeValueTemplateRefusals(entry.nodeType, configForEntry(entry, '{x}'));
932+
const [refusal] = refusalsForEntry(entry, '{x}');
895933
const carries = /names who the notification goes to/.test(refusal!.message);
896934
expect(carries, `${entry.nodeType} ${entry.path}`).toBe(`${entry.nodeType} ${entry.path}` === 'notify recipients');
897935
}

‎packages/spec/src/automation/flow.zod.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,40 @@ function flowNodeObject() { return strictObject(
861861
}).optional().describe("Configuration for boundary events attached to host nodes. REQUIRED on a `type: 'boundary_event'` node — without it the node names neither the activity it watches nor what fires it.").meta({ title: 'Boundary Event' }),
862862
}); }
863863

864+
/**
865+
* [#27968] Every property of a flow node OTHER than `config` — the sibling
866+
* blocks `connectorConfig`, `waitEventConfig`, `boundaryConfig` and the rest —
867+
* as JSON Schema, keyed by the property name, memoized.
868+
*
869+
* The third channel the expression ledger's reconciliation ratchet reads
870+
* (`config-expression-ledger.test.ts` in `service-automation`), beside a
871+
* descriptor's `configSchema` and `getSchemalessNodeConfigJsonSchemas()`: a
872+
* `.meta({ xExpression })` marker inside a block declares a slot the ledger
873+
* roots in that block (`FlowNodeExpressionPath.block`), and the ratchet maps
874+
* the block to its node type through `FLOW_NODE_SIBLING_EXPRESSION_BLOCKS` —
875+
* every block is handed over, not only the listed ones, so a marker on a block
876+
* the ledger cannot address fails it instead of going unseen.
877+
*
878+
* Derived in `input` mode, like the schemaless channel, which is what carries
879+
* the markers through verbatim.
880+
*/
881+
let cachedFlowNodeSiblingBlockJsonSchemas: Readonly<Record<string, unknown>> | undefined;
882+
export function getFlowNodeSiblingBlockJsonSchemas(): Readonly<Record<string, unknown>> {
883+
if (cachedFlowNodeSiblingBlockJsonSchemas === undefined) {
884+
const json = z.toJSONSchema(flowNodeObject(), {
885+
target: 'draft-2020-12',
886+
io: 'input',
887+
unrepresentable: 'any',
888+
}) as { properties?: Record<string, unknown> };
889+
const out: Record<string, unknown> = {};
890+
for (const [key, schema] of Object.entries(json.properties ?? {})) {
891+
if (key !== 'config') out[key] = schema;
892+
}
893+
cachedFlowNodeSiblingBlockJsonSchemas = out;
894+
}
895+
return cachedFlowNodeSiblingBlockJsonSchemas;
896+
}
897+
864898
/**
865899
* Flow Edge Schema
866900
* Connections between nodes.

0 commit comments

Comments
 (0)