|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * **`objectstack validate` judges a `connector_action` node's |
| 5 | + * `connectorConfig.input`** (#27968) — the build door's half of the slot |
| 6 | + * `registerFlow` now judges too. |
| 7 | + * |
| 8 | + * The expression pass reads value slots only through the spec's expression |
| 9 | + * ledger, whose paths were rooted in `node.config`; `connectorConfig` is a |
| 10 | + * sibling block, so a malformed CEL envelope, a template-dialect envelope and a |
| 11 | + * `{…}` token string there passed `validateStackExpressions` clean while the |
| 12 | + * same three under a `subflow`'s `config.input` were refused. The ledger now |
| 13 | + * roots the slot in the block, and this pass judges it like every other value |
| 14 | + * slot, located at `connectorConfig.input.<key>`, at `error`. The runtime |
| 15 | + * authoring gate runs the same pass, so a flow write is refused there as well. |
| 16 | + */ |
| 17 | + |
| 18 | +import { describe, expect, it } from 'vitest'; |
| 19 | +import { VALUE_ENVELOPE_REFUSAL, VALUE_SLOT_TEMPLATE_REFUSAL } from '@objectstack/spec/automation'; |
| 20 | + |
| 21 | +import { runRuntimeAuthoringRules } from './runtime-gate.js'; |
| 22 | +import { validateStackExpressions, type ExprIssue } from './validate-expressions.js'; |
| 23 | + |
| 24 | +type AnyRec = Record<string, unknown>; |
| 25 | + |
| 26 | +/** start → `node` → end, the record an input variable. */ |
| 27 | +function flowWith(node: AnyRec): AnyRec { |
| 28 | + return { |
| 29 | + name: 'f', |
| 30 | + label: 'F', |
| 31 | + type: 'autolaunched', |
| 32 | + variables: [{ name: 'rec', type: 'object', isInput: true }], |
| 33 | + nodes: [ |
| 34 | + { id: 'start', type: 'start', config: {} }, |
| 35 | + { id: 'call', label: 'Call', ...node }, |
| 36 | + { id: 'done', type: 'end', config: {} }, |
| 37 | + ], |
| 38 | + edges: [{ id: 'e1', source: 'start', target: 'call' }, { id: 'e2', source: 'call', target: 'done' }], |
| 39 | + }; |
| 40 | +} |
| 41 | + |
| 42 | +const connectorNode = (input: AnyRec): AnyRec => ({ |
| 43 | + type: 'connector_action', |
| 44 | + connectorConfig: { connectorId: 'vendor', actionId: 'lookup', input }, |
| 45 | +}); |
| 46 | +const subflowNode = (input: AnyRec): AnyRec => ({ type: 'subflow', config: { flowName: 'child', input } }); |
| 47 | + |
| 48 | +const errorsOf = (flow: AnyRec): ExprIssue[] => |
| 49 | + validateStackExpressions({ flows: [flow] }).filter((i) => (i.severity ?? 'error') === 'error'); |
| 50 | + |
| 51 | +/** The three shapes the #27327 thread measured passing the build door under `connectorConfig.input`. */ |
| 52 | +const SHAPES = [ |
| 53 | + ['a malformed CEL envelope', { dialect: 'cel', source: 'rec.' }, VALUE_ENVELOPE_REFUSAL], |
| 54 | + ['a template-dialect envelope', { dialect: 'template', source: '{rec.id}' }, VALUE_ENVELOPE_REFUSAL], |
| 55 | + ['a bare `{…}` token string', '{rec.id}', VALUE_SLOT_TEMPLATE_REFUSAL], |
| 56 | +] as const; |
| 57 | + |
| 58 | +describe('objectstack validate refuses the three shapes at `connectorConfig.input.<key>`', () => { |
| 59 | + it.each(SHAPES)('%s', (_shape, value, lead) => { |
| 60 | + const found = errorsOf(flowWith(connectorNode({ customerId: value, region: 'eu' }))); |
| 61 | + expect(found.map((i) => i.where)).toEqual([ |
| 62 | + "flow 'f' · node 'call' (connector_action) connector_action input value at connectorConfig.input.customerId", |
| 63 | + ]); |
| 64 | + expect(found[0]!.message.startsWith(lead)).toBe(true); |
| 65 | + // The same shape under a `subflow`'s input map: the same refusal, at its own position. |
| 66 | + const control = errorsOf(flowWith(subflowNode({ customerId: value }))); |
| 67 | + expect(control.map((i) => i.where)).toEqual([ |
| 68 | + "flow 'f' · node 'call' (subflow) subflow input value at config.input.customerId", |
| 69 | + ]); |
| 70 | + // The connector's refusal is the subflow's, minus the callee sentence a |
| 71 | + // child flow's input value adds: the action was handed the text, not nothing. |
| 72 | + expect(control[0]!.message.startsWith(found[0]!.message)).toBe(true); |
| 73 | + }); |
| 74 | + |
| 75 | + it('a valid envelope and literals pass', () => { |
| 76 | + expect(errorsOf(flowWith(connectorNode({ |
| 77 | + customerId: { dialect: 'cel', source: 'rec.id' }, |
| 78 | + region: 'eu', |
| 79 | + body: { filter: { dialect: 'cel', source: 'rec.id' } }, |
| 80 | + })))).toEqual([]); |
| 81 | + expect(errorsOf(flowWith({ type: 'connector_action', connectorConfig: { connectorId: 'vendor', actionId: 'lookup' } }))).toEqual([]); |
| 82 | + }); |
| 83 | + |
| 84 | + it('the runtime authoring gate refuses a flow write carrying one, through the same pass', () => { |
| 85 | + const result = runRuntimeAuthoringRules({ type: 'flow', item: flowWith(connectorNode({ customerId: '{rec.id}' })) }); |
| 86 | + const refused = result.errors.filter((f) => f.where.includes('connectorConfig.input.customerId')); |
| 87 | + expect(refused.map((f) => f.rule)).toEqual(['expression-invalid']); |
| 88 | + expect(refused[0]!.message.startsWith(VALUE_SLOT_TEMPLATE_REFUSAL)).toBe(true); |
| 89 | + }); |
| 90 | +}); |
0 commit comments