Fix: agent code exec test run does not work (#20705)

This commit is contained in:
Wang Qi
2026-10-10 13:09:16 +08:00
committed by GitHub
parent 9e658aef4a
commit e8a80ed045
2 changed files with 25 additions and 4 deletions
@@ -647,6 +647,17 @@ func TestCodeExec_LegacyDSLWrapperBridgesParamsAndOutputs(t *testing.T) {
if got := out["_ERROR"]; got != "" {
t.Errorf("CodeExec _ERROR = %v, want empty string", got)
}
out, err = c.Invoke(t.Context(), nil, map[string]any{"x": 7})
if err != nil {
t.Fatalf("CodeExec.Invoke with named argument: %v", err)
}
if got := recorder.req.Arguments["x"]; got != float64(7) {
t.Errorf("sandbox arguments[x] = %v, want 7 from named argument", got)
}
if got := out["result"]; got != float64(14) {
t.Errorf("CodeExec result = %v, want numeric 14", got)
}
}
func TestCodeExec_LegacyDSLWrapperResolvesArgumentRefsFromState(t *testing.T) {
@@ -531,8 +531,9 @@ func (c *codeExecComponent) Inputs() map[string]string {
}
func (c *codeExecComponent) GetInputForm() map[string]any {
res := make(map[string]any, len(c.params))
for k := range c.params {
arguments := asAnyMap(c.params["arguments"])
res := make(map[string]any, len(arguments))
for k := range arguments {
res[k] = map[string]any{
"type": "line",
"name": k,
@@ -558,12 +559,21 @@ func (c *codeExecComponent) Invoke(ctx context.Context, db *gorm.DB, inputs map[
for k, v := range c.params {
merged[k] = v
}
arguments := asAnyMap(c.params["arguments"])
for k, v := range inputs {
merged[k] = v
if _, ok := arguments[k]; !ok {
merged[k] = v
}
}
if rawArgs, ok := merged["arguments"].(map[string]any); ok {
state, _ := runtime.GetStateFromContext(ctx)
merged["arguments"] = resolveCodeExecArguments(rawArgs, merged, state)
resolvedArgs := resolveCodeExecArguments(rawArgs, merged, state)
for k := range rawArgs {
if v, ok := inputs[k]; ok {
resolvedArgs[k] = v
}
}
merged["arguments"] = resolvedArgs
}
common.Debug("CodeExec wrapper invoke",
zap.Int("params_keys", len(c.params)),