|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * #26858 — a flow edge's `condition` finding carries the slot's key path. |
| 5 | + * |
| 6 | + * `expression-invalid` is what publish refuses a flow edge's CEL with, and its |
| 7 | + * finding was located by its `where` prose alone (`flow 'f' · edge 'e2' |
| 8 | + * (decide→end) condition`). A draft's `_diagnostics` is item-relative and |
| 9 | + * dotted (`edges.1.condition`), so Studio's edge condition field could not ask |
| 10 | + * whether the refusal was its own. The finding now carries the key path in the |
| 11 | + * spelling the other rules use (`flows[0].edges[1].condition`) beside the |
| 12 | + * unchanged `where` and message. |
| 13 | + */ |
| 14 | + |
| 15 | +import { describe, expect, it } from 'vitest'; |
| 16 | + |
| 17 | +import { runRuntimeAuthoringRules } from './runtime-gate.js'; |
| 18 | +import { validateStackExpressions } from './validate-expressions.js'; |
| 19 | + |
| 20 | +type AnyRec = Record<string, unknown>; |
| 21 | + |
| 22 | +const BROKEN = 'record.name =='; |
| 23 | + |
| 24 | +function flow(edges: unknown[], extra: AnyRec = {}): AnyRec { |
| 25 | + return { |
| 26 | + name: 'edge_cel', |
| 27 | + label: 'Edge CEL', |
| 28 | + type: 'autolaunched', |
| 29 | + nodes: [ |
| 30 | + { id: 'start', type: 'start', label: 'Start' }, |
| 31 | + { id: 'decide', type: 'decision', label: 'Decide' }, |
| 32 | + { id: 'end', type: 'end', label: 'End' }, |
| 33 | + ], |
| 34 | + edges, |
| 35 | + ...extra, |
| 36 | + }; |
| 37 | +} |
| 38 | + |
| 39 | +const EDGES = [ |
| 40 | + { id: 'e1', source: 'start', target: 'decide' }, |
| 41 | + { id: 'e2', source: 'decide', target: 'end', type: 'conditional', condition: BROKEN }, |
| 42 | +]; |
| 43 | + |
| 44 | +describe('expression-invalid on a flow edge condition carries a key path (#26858)', () => { |
| 45 | + it('names the edge by its index in the authored list, where and message unchanged', () => { |
| 46 | + const issues = validateStackExpressions({ flows: [flow(EDGES)] }); |
| 47 | + const onEdge = issues.filter((i) => i.where.includes("edge 'e2'")); |
| 48 | + expect(onEdge.length).toBeGreaterThan(0); |
| 49 | + for (const i of onEdge) { |
| 50 | + expect(i.path).toBe('flows[0].edges[1].condition'); |
| 51 | + expect(i.where).toBe("flow 'edge_cel' · edge 'e2' (decide→end) condition"); |
| 52 | + } |
| 53 | + }); |
| 54 | + |
| 55 | + it('indexes the raw list: a null member before the edge does not renumber it', () => { |
| 56 | + const issues = validateStackExpressions({ flows: [flow([null, ...EDGES])] }); |
| 57 | + const onEdge = issues.filter((i) => i.where.includes("edge 'e2'")); |
| 58 | + expect(onEdge.length).toBeGreaterThan(0); |
| 59 | + for (const i of onEdge) expect(i.path).toBe('flows[0].edges[2].condition'); |
| 60 | + }); |
| 61 | + |
| 62 | + it('indexes the flow in the stack', () => { |
| 63 | + const other = { ...flow([{ id: 'x1', source: 'start', target: 'end' }]), name: 'clean' }; |
| 64 | + const issues = validateStackExpressions({ flows: [other, flow(EDGES)] }); |
| 65 | + const onEdge = issues.filter((i) => i.where.includes("edge 'e2'")); |
| 66 | + expect(onEdge.length).toBeGreaterThan(0); |
| 67 | + for (const i of onEdge) expect(i.path).toBe('flows[1].edges[1].condition'); |
| 68 | + }); |
| 69 | + |
| 70 | + it('a map-form flows collection has no index to spell, so the finding keeps where alone', () => { |
| 71 | + const { name: _name, ...body } = flow(EDGES); |
| 72 | + const issues = validateStackExpressions({ flows: { edge_cel: body } }); |
| 73 | + const onEdge = issues.filter((i) => i.where.includes("edge 'e2'")); |
| 74 | + expect(onEdge.length).toBeGreaterThan(0); |
| 75 | + for (const i of onEdge) expect(i.path).toBeUndefined(); |
| 76 | + }); |
| 77 | + |
| 78 | + it('a finding off the edge condition gains no path', () => { |
| 79 | + const issues = validateStackExpressions({ |
| 80 | + flows: [ |
| 81 | + flow([{ id: 'e1', source: 'start', target: 'end' }], { |
| 82 | + nodes: [ |
| 83 | + { id: 'start', type: 'start', label: 'Start', config: { condition: BROKEN } }, |
| 84 | + { id: 'end', type: 'end', label: 'End' }, |
| 85 | + ], |
| 86 | + }), |
| 87 | + ], |
| 88 | + }); |
| 89 | + expect(issues.length).toBeGreaterThan(0); |
| 90 | + for (const i of issues) expect(i.path).toBeUndefined(); |
| 91 | + }); |
| 92 | + |
| 93 | + it('reaches the publish gate: the refusal is located at the edge condition, message unchanged', () => { |
| 94 | + const result = runRuntimeAuthoringRules({ type: 'flow', item: flow(EDGES) }); |
| 95 | + const refusals = result.errors.filter((f) => f.rule === 'expression-invalid'); |
| 96 | + expect(refusals.length).toBeGreaterThan(0); |
| 97 | + for (const f of refusals) { |
| 98 | + expect(f.path).toMatch(/^flows(\[0\]|\.edge_cel)\.edges\[1\]\.condition$/); |
| 99 | + expect(f.where).toBe("flow 'edge_cel' · edge 'e2' (decide→end) condition"); |
| 100 | + } |
| 101 | + }); |
| 102 | +}); |
0 commit comments