Skip to content

Commit 785fc10

Browse files
committed
test(lint,metadata-protocol): pin the key path on a flow node config-value finding (WIP)
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibxhpYpVUxgK5jbQMXT
1 parent 9f13ee8 commit 785fc10

4 files changed

Lines changed: 180 additions & 2 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/lint': patch
3+
---
4+
5+
fix(lint): a flow node config-value finding carries the slot's key path, so Studio's Problems row selects the node
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`validateStackExpressions` located a finding on a flow node's config value (an `expression-invalid` on an Update Records `fields` value, a node `condition`, a text slot, an undeclared config key, a `script` node with no `function`) by its `where` prose alone. The runtime authoring gate then used that prose as the finding's `path`, so a draft's `_diagnostics` entry for it could not be resolved to a node: Studio's Problems list showed the refusal but could not select or badge the node.
11+
12+
Each such finding now also carries the slot's key path, in the spelling a flow edge's `condition` finding uses: `flows[0].nodes[1].config.fields.status` (a draft's `_diagnostics` reads `nodes.1.config.fields.status`). A `connector_action` input value is located in its own block (`flows[0].nodes[2].connectorConfig.input.customerId`). The `where` prose and the message are unchanged. As for edges, a node inside a nested region (a `loop` body) and a map-form `flows` collection have no index to spell, so their findings keep `where` alone. The CLI's `rule: … at …` line prints the key path for these findings, as it does for an edge's.

‎packages/lint/src/validate-expressions.edge-condition-path.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('expression-invalid on a flow edge condition carries a key path (#26858
7575
for (const i of onEdge) expect(i.path).toBeUndefined();
7676
});
7777

78-
it('a finding off the edge condition gains no path', () => {
78+
it('a finding off the edge condition gains no edge path (#27828: a node condition carries its node\'s)', () => {
7979
const issues = validateStackExpressions({
8080
flows: [
8181
flow([{ id: 'e1', source: 'start', target: 'end' }], {
@@ -87,7 +87,7 @@ describe('expression-invalid on a flow edge condition carries a key path (#26858
8787
],
8888
});
8989
expect(issues.length).toBeGreaterThan(0);
90-
for (const i of issues) expect(i.path).toBeUndefined();
90+
for (const i of issues) expect(i.path).toBe('flows[0].nodes[0].config.condition');
9191
});
9292

9393
it('reaches the publish gate: the refusal is located at the edge condition, message unchanged', () => {
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #27828 — a flow node's config-value finding carries the slot's key path.
5+
*
6+
* `expression-invalid` is what publish refuses a node's config value with
7+
* (measured on a blank expression in an Update Records value), and its finding
8+
* was located by its `where` prose alone (`flow 'f' · node 'set' (update_record)
9+
* update_record field value at config.fields.status`). A draft's
10+
* `_diagnostics` path was therefore that prose, so Studio's Problems row listed
11+
* the refusal but could not select the node. The finding now carries the key
12+
* path in the spelling the edge findings use since #26858
13+
* (`flows[0].nodes[1].config.fields.status`) beside the unchanged `where` and
14+
* message.
15+
*/
16+
17+
import { describe, expect, it } from 'vitest';
18+
19+
import { runRuntimeAuthoringRules } from './runtime-gate.js';
20+
import { validateStackExpressions } from './validate-expressions.js';
21+
import type { ExprIssue } from './validate-expressions.js';
22+
23+
type AnyRec = Record<string, unknown>;
24+
25+
const BLANK = { dialect: 'cel', source: ' ' };
26+
27+
const START = { id: 'start', type: 'start', label: 'Start' };
28+
const END = { id: 'end', type: 'end', label: 'End' };
29+
30+
/** An Update Records node whose `status` value is a blank CEL envelope. */
31+
const SET = {
32+
id: 'set',
33+
type: 'update_record',
34+
label: 'Set',
35+
config: { objectName: 'task', filter: { id: 'x' }, fields: { title: 'kept', status: BLANK } },
36+
};
37+
38+
function flow(nodes: unknown[], extra: AnyRec = {}): AnyRec {
39+
return {
40+
name: 'node_cfg',
41+
label: 'Node config',
42+
type: 'autolaunched',
43+
nodes,
44+
edges: [
45+
{ id: 'e1', source: 'start', target: 'set' },
46+
{ id: 'e2', source: 'set', target: 'end' },
47+
],
48+
...extra,
49+
};
50+
}
51+
52+
const onNode = (issues: ExprIssue[], id: string) => issues.filter((i) => i.where.includes(`node '${id}'`));
53+
54+
describe('a flow node config-value finding carries a key path (#27828)', () => {
55+
it('names the node by its index in the authored list, where and message unchanged', () => {
56+
const issues = onNode(validateStackExpressions({ flows: [flow([START, SET, END])] }), 'set');
57+
expect(issues.length).toBeGreaterThan(0);
58+
for (const i of issues) {
59+
expect(i.path).toBe('flows[0].nodes[1].config.fields.status');
60+
expect(i.where).toBe("flow 'node_cfg' · node 'set' (update_record) update_record field value at config.fields.status");
61+
}
62+
});
63+
64+
it('indexes the raw list: a null member before the node does not renumber it', () => {
65+
const issues = onNode(validateStackExpressions({ flows: [flow([START, null, SET, END])] }), 'set');
66+
expect(issues.length).toBeGreaterThan(0);
67+
for (const i of issues) expect(i.path).toBe('flows[0].nodes[2].config.fields.status');
68+
});
69+
70+
it('indexes the flow in the stack', () => {
71+
const clean = { ...flow([START, END]), name: 'clean', edges: [{ id: 'e1', source: 'start', target: 'end' }] };
72+
const issues = onNode(validateStackExpressions({ flows: [clean, flow([START, SET, END])] }), 'set');
73+
expect(issues.length).toBeGreaterThan(0);
74+
for (const i of issues) expect(i.path).toBe('flows[1].nodes[1].config.fields.status');
75+
});
76+
77+
it('every node-config arm locates its finding at the slot it judged', () => {
78+
const nodes = [
79+
{ ...START, config: { condition: 'record.name ==' } },
80+
// A value slot's retired single-brace token (the template-refusal arm).
81+
{ id: 'tok', type: 'update_record', label: 'Tok', config: { objectName: 'task', filter: { id: 'x' }, fields: { title: '{record.name}' } } },
82+
// A text slot's single-brace token (the text-slot arm).
83+
{ id: 'say', type: 'notify', label: 'Say', config: { channel: 'email', recipients: ['a@b.c'], title: 'Hi {record.name}', message: 'ok' } },
84+
// A key the node's contract does not declare (the config-refusal arm).
85+
{ id: 'odd', type: 'end', label: 'Odd', config: { bogusKey: 1 } },
86+
// A script with no callable (the script arm).
87+
{ id: 'run', type: 'script', label: 'Run', config: {} },
88+
];
89+
const issues = validateStackExpressions({ flows: [flow(nodes, { edges: [] })] });
90+
const pathsOf = (id: string) => [...new Set(onNode(issues, id).map((i) => i.path))];
91+
expect(pathsOf('start')).toEqual(['flows[0].nodes[0].config.condition']);
92+
expect(pathsOf('tok')).toEqual(['flows[0].nodes[1].config.fields.title']);
93+
expect(pathsOf('say')).toEqual(['flows[0].nodes[2].config.title']);
94+
expect(pathsOf('odd')).toEqual(['flows[0].nodes[3].config.bogusKey']);
95+
expect(pathsOf('run')).toEqual(['flows[0].nodes[4].config.function']);
96+
});
97+
98+
it('a map-form flows collection has no index to spell, so the finding keeps where alone', () => {
99+
const { name: _name, ...body } = flow([START, SET, END]);
100+
const issues = onNode(validateStackExpressions({ flows: { node_cfg: body } }), 'set');
101+
expect(issues.length).toBeGreaterThan(0);
102+
for (const i of issues) expect(i.path).toBeUndefined();
103+
});
104+
105+
it('a node inside a nested region keeps where alone, as a nested edge does', () => {
106+
const loop = {
107+
id: 'each',
108+
type: 'loop',
109+
label: 'Each',
110+
config: {
111+
collection: { dialect: 'cel', source: '[1, 2]' },
112+
itemVariable: 'item',
113+
body: { nodes: [{ ...SET, id: 'inner' }], edges: [] },
114+
},
115+
};
116+
const issues = onNode(
117+
validateStackExpressions({ flows: [flow([START, loop, END], { edges: [{ id: 'e1', source: 'start', target: 'each' }, { id: 'e2', source: 'each', target: 'end' }] })] }),
118+
'inner',
119+
);
120+
expect(issues.length).toBeGreaterThan(0);
121+
for (const i of issues) expect(i.path).toBeUndefined();
122+
});
123+
124+
it('reaches the publish gate: the refusal is located at the node config value, message unchanged', () => {
125+
const result = runRuntimeAuthoringRules({ type: 'flow', item: flow([START, SET, END]) });
126+
const refusals = result.errors.filter((f) => f.rule === 'expression-invalid');
127+
expect(refusals.length).toBeGreaterThan(0);
128+
for (const f of refusals) {
129+
expect(f.path).toMatch(/^flows(\[0\]|\.node_cfg)\.nodes\[1\]\.config\.fields\.status$/);
130+
expect(f.where).toBe("flow 'node_cfg' · node 'set' (update_record) update_record field value at config.fields.status");
131+
}
132+
});
133+
});

‎packages/metadata-protocol/src/protocol.draft-publish-verdict.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,39 @@ describe('a draft reads the verdict its publish gives (#26707)', () => {
462462
expect.objectContaining({ path: 'nodes.0.config.secret', code: 'flow-api-trigger-secret-missing' }),
463463
);
464464
});
465+
466+
it('[#27828] a node config value refused by expression-invalid is located at the node, not in where prose', async () => {
467+
const { engine } = makeStubEngine();
468+
const protocol = new ObjectStackProtocolImplementation(engine);
469+
// Studio's Update Records value with its expression left blank.
470+
const flow = {
471+
name: 'blank_value',
472+
label: 'Blank Value',
473+
type: 'autolaunched',
474+
nodes: [
475+
{ id: 'start', type: 'start', label: 'Start' },
476+
{
477+
id: 'set',
478+
type: 'update_record',
479+
label: 'Set',
480+
config: { objectName: 'deal', filter: { id: 'x' }, fields: { name: { dialect: 'cel', source: ' ' } } },
481+
},
482+
{ id: 'end', type: 'end', label: 'End' },
483+
],
484+
edges: [
485+
{ id: 'e1', source: 'start', target: 'set' },
486+
{ id: 'e2', source: 'set', target: 'end' },
487+
],
488+
};
489+
await stageDraft(protocol, 'flow', flow);
490+
491+
const diagnostics = await draftDiagnostics(protocol, 'flow', flow.name);
492+
const refused = (diagnostics.errors ?? []).filter((e) => e.code === 'expression-invalid');
493+
expect(diagnostics.valid).toBe(false);
494+
expect(refused.length).toBeGreaterThan(0);
495+
// `nodes.<index>.…` is the spelling Studio's Problems list maps onto a node.
496+
for (const e of refused) expect(e.path).toBe('nodes.1.config.fields.name');
497+
});
465498
});
466499

467500
describe('[#27444] an object draft without its package namespace prefix', () => {

0 commit comments

Comments
 (0)