Skip to content

Commit a3e2481

Browse files
committed
wip: registration rejection tests for connectorConfig.input
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibzGExkj8nxREmV7FjX
1 parent 489409a commit a3e2481

1 file changed

Lines changed: 137 additions & 0 deletions

File tree

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* **A `connector_action` node's `connectorConfig.input` is judged at
5+
* registration** (#27968) — the registration half of #27327.
6+
*
7+
* #27327 made the executor evaluate the map through the one per-key value-slot
8+
* resolver (`connector-input-value-slot.test.ts`). Registration judges value
9+
* slots only through the spec's expression ledger, whose paths were rooted in
10+
* `node.config`, so it could not name a slot in the `connectorConfig` sibling
11+
* block: a malformed CEL envelope, a template-dialect envelope and a `{…}`
12+
* token string all REGISTERED there, while the same three under a `subflow`'s
13+
* `config.input` were refused. One slot, two reject sets. The ledger now roots
14+
* the slot in the block, and `registerFlow` judges it like every other value
15+
* slot, located at `connectorConfig.input.<key>`:
16+
*
17+
* 1. the three shapes are refused, each at its key, each with the value
18+
* slot's own refusal — and side by side with the `subflow` control, which
19+
* answers the same sentence;
20+
* 2. a valid envelope and literals still register and run.
21+
*/
22+
23+
import { describe, expect, it } from 'vitest';
24+
import { VALUE_ENVELOPE_REFUSAL, VALUE_SLOT_TEMPLATE_REFUSAL } from '@objectstack/spec/automation';
25+
import type { Connector } from '@objectstack/spec/integration';
26+
import { AutomationEngine } from '../engine.js';
27+
import { installBuiltinNodes } from './index.js';
28+
29+
function silentLogger(): any {
30+
return { info() {}, warn() {}, error() {}, debug() {}, child() { return silentLogger(); } };
31+
}
32+
function ctx(): any {
33+
return { logger: silentLogger(), getService() { return undefined; } };
34+
}
35+
36+
const CONNECTOR = {
37+
name: 'vendor',
38+
label: 'Vendor',
39+
type: 'api',
40+
authentication: { type: 'none' },
41+
actions: [{ key: 'lookup', label: 'Lookup' }],
42+
} as Connector;
43+
44+
function makeEngine(): { engine: AutomationEngine; received: Record<string, unknown>[] } {
45+
const engine = new AutomationEngine(silentLogger());
46+
installBuiltinNodes(engine, ctx());
47+
const received: Record<string, unknown>[] = [];
48+
engine.registerConnector(CONNECTOR, {
49+
async lookup(input) {
50+
received.push(input);
51+
return { ok: true };
52+
},
53+
});
54+
return { engine, received };
55+
}
56+
57+
/** start → `node` → end, the record an input variable. */
58+
function flowWith(name: string, node: Record<string, unknown>): any {
59+
return {
60+
name, label: name, type: 'autolaunched',
61+
variables: [{ name: 'rec', type: 'object', isInput: true }],
62+
nodes: [
63+
{ id: 'start', type: 'start', label: 'Start' },
64+
{ id: 'call', label: 'Call', ...node },
65+
{ id: 'end', type: 'end', label: 'End' },
66+
],
67+
edges: [{ id: 'e1', source: 'start', target: 'call' }, { id: 'e2', source: 'call', target: 'end' }],
68+
};
69+
}
70+
71+
const connectorNode = (input: Record<string, unknown>) => ({
72+
type: 'connector_action',
73+
connectorConfig: { connectorId: 'vendor', actionId: 'lookup', input },
74+
});
75+
const subflowNode = (input: Record<string, unknown>) => ({
76+
type: 'subflow',
77+
config: { flowName: 'child', input },
78+
});
79+
80+
/** The message `registerFlow` throws for `node`, or `''` when it registers. */
81+
function registrationError(node: Record<string, unknown>): string {
82+
const { engine } = makeEngine();
83+
try {
84+
engine.registerFlow('judged', flowWith('judged', node));
85+
} catch (e) {
86+
return (e as Error).message;
87+
}
88+
return '';
89+
}
90+
91+
/** The three shapes the #27327 thread measured registering under `connectorConfig.input`. */
92+
const SHAPES = [
93+
['a malformed CEL envelope', { dialect: 'cel', source: 'rec.' }, ''],
94+
['a template-dialect envelope', { dialect: 'template', source: '{rec.id}' }, VALUE_ENVELOPE_REFUSAL],
95+
['a bare `{…}` token string', '{rec.id}', VALUE_SLOT_TEMPLATE_REFUSAL],
96+
] as const;
97+
98+
describe('1. registerFlow refuses the three shapes at `connectorConfig.input.<key>`', () => {
99+
it.each(SHAPES)('%s', (_shape, value, lead) => {
100+
const message = registrationError(connectorNode({ customerId: value, region: 'eu' }));
101+
expect(message).toContain(`node 'call' (connector_action) connector_action input value at connectorConfig.input.customerId: ${lead}`);
102+
// Only the key that holds the shape is named; the literal beside it is not.
103+
expect(message).not.toContain('connectorConfig.input.region');
104+
// The same shape under a `subflow`'s input map draws the same refusal —
105+
// one slot rule, two positions, one reject set.
106+
const control = registrationError(subflowNode({ customerId: value }));
107+
expect(control).toContain(`node 'call' (subflow) subflow input value at config.input.customerId: ${lead}`);
108+
const detail = (m: string) => m.slice(m.indexOf('input.customerId: ') + 'input.customerId: '.length).split('\n')[0];
109+
expect(detail(message)).toBe(detail(control));
110+
});
111+
112+
it('a refused flow is not registered: it cannot be run', async () => {
113+
const { engine, received } = makeEngine();
114+
expect(() => engine.registerFlow('refused', flowWith('refused', connectorNode({ customerId: '{rec.id}' })))).toThrow();
115+
const run = await engine.execute('refused', { params: { rec: { id: 'cus_42' } } } as any).catch((e: Error) => ({ success: false, error: e.message }));
116+
expect(run.success).toBe(false);
117+
expect(received).toEqual([]);
118+
});
119+
});
120+
121+
describe('2. a valid envelope and literals still register, and the run evaluates the envelope', () => {
122+
it('registers, and the action receives the computed value beside the literal', async () => {
123+
const { engine, received } = makeEngine();
124+
engine.registerFlow('valid', flowWith('valid', connectorNode({
125+
customerId: { dialect: 'cel', source: 'rec.id' },
126+
region: 'eu',
127+
body: { filter: { dialect: 'cel', source: 'rec.id' } },
128+
})));
129+
const run = await engine.execute('valid', { params: { rec: { id: 'cus_42' } } } as any);
130+
expect(run.success, run.error).toBe(true);
131+
expect(received).toEqual([{ customerId: 'cus_42', region: 'eu', body: { filter: { dialect: 'cel', source: 'rec.id' } } }]);
132+
});
133+
134+
it('a node with no `input` registers, as before', () => {
135+
expect(registrationError({ type: 'connector_action', connectorConfig: { connectorId: 'vendor', actionId: 'lookup' } })).toBe('');
136+
});
137+
});

0 commit comments

Comments
 (0)