MCPcopy Create free account
hub / github.com/ForestHubAI/edge-agents / TestFunctionCall_Execute

Function TestFunctionCall_Execute

go/engine/node/functioncall_test.go:126–261  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

124}
125
126func TestFunctionCall_Execute(t *testing.T) {
127 t.Run("evaluates input bindings, runs fn, applies output bindings", func(t *testing.T) {
128 s, err := engine.NewMainScope([]workflowapi.Variable{
129 {Uid: "x", DataType: workflowapi.Int, InitialValue: float64(11)},
130 {Uid: "y", DataType: workflowapi.Int}, // assign target
131 })
132 require.NoError(t, err)
133
134 fn := passthroughFn()
135 fc, err := NewFunctionCall("fc", fn,
136 map[string]workflowapi.Expression{
137 "a": {
138 Expression: "${}",
139 DataType: workflowapi.Int,
140 References: []workflowapi.Reference{{SrcId: engine.SrcDeclared, VarId: "x"}},
141 },
142 },
143 map[string]workflowapi.OutputBinding{
144 "ret": {
145 Active: true,
146 Mode: workflowapi.OutputBindingModeAssign,
147 Target: &workflowapi.Reference{SrcId: engine.SrcDeclared, VarId: "y"},
148 },
149 },
150 "",
151 )
152 require.NoError(t, err)
153
154 next, err := fc.Execute(context.Background(), s)
155 require.NoError(t, err)
156 assert.Equal(t, engine.StateIdle, next)
157
158 v, err := s.Resolve(workflowapi.Reference{SrcId: engine.SrcDeclared, VarId: "y"})
159 require.NoError(t, err)
160 assert.Equal(t, expr.IntVal(11), v)
161 })
162
163 t.Run("input expression error is wrapped with node and arg name", func(t *testing.T) {
164 s, err := engine.NewMainScope(nil)
165 require.NoError(t, err)
166
167 fn := passthroughFn()
168 fc, err := NewFunctionCall("fc-bad", fn,
169 map[string]workflowapi.Expression{
170 "a": {
171 Expression: "${}",
172 DataType: workflowapi.Int,
173 References: []workflowapi.Reference{{SrcId: "missing", VarId: "x"}},
174 },
175 },
176 map[string]workflowapi.OutputBinding{
177 "ret": {Active: true, Mode: workflowapi.OutputBindingModeEmit},
178 },
179 "",
180 )
181 require.NoError(t, err)
182
183 _, err = fc.Execute(context.Background(), s)

Callers

nothing calls this directly

Calls 7

ExecuteMethod · 0.95
passthroughFnFunction · 0.85
NewFunctionCallFunction · 0.85
ResolveMethod · 0.65
AddTransitionMethod · 0.65
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected