Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion handlers/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,35 @@ func ensureConnectorConnected(ctx context.Context, connector module.IntegrationC
}

// resolveParamValue resolves a single input value, substituting step result references where applicable.
// References use the ${varName} syntax. If the variable is not found, the original value is returned.
// References use the ${varName} syntax. Dot-notation is supported: ${step1.value} looks up results["step1"]
// and then retrieves the "value" key from the resulting map. If the variable is not found, the original value is returned.
func resolveParamValue(v any, results map[string]any) any {
strVal, ok := v.(string)
if !ok || len(strVal) <= 3 || strVal[0:2] != "${" || strVal[len(strVal)-1] != '}' {
return v
}
// Extract the variable name, e.g., ${step1.value} -> step1.value
varName := strVal[2 : len(strVal)-1]
// Fast path: exact match in results
if result, found := results[varName]; found {
return result
}
// Dot-notation path: split on "." and traverse nested maps
parts := strings.SplitN(varName, ".", 2)
if len(parts) != 2 {
return v
}
stepResult, found := results[parts[0]]
if !found {
return v
}
nested, ok := stepResult.(map[string]any)
if !ok {
return v
}
if val, found := nested[parts[1]]; found {
return val
}
return v
}

Expand Down
60 changes: 60 additions & 0 deletions handlers/integration_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,63 @@ func TestExecuteStepWithRetry_ExhaustedRetries(t *testing.T) {
t.Fatal("expected error after exhausted retries")
}
}

func TestResolveParamValue_PlainValue(t *testing.T) {
results := map[string]any{"step1": map[string]any{"value": "hello"}}
got := resolveParamValue(42, results)
if got != 42 {
t.Errorf("expected 42, got %v", got)
}
}

func TestResolveParamValue_ExactMatch(t *testing.T) {
results := map[string]any{"step1": "direct"}
got := resolveParamValue("${step1}", results)
if got != "direct" {
t.Errorf("expected 'direct', got %v", got)
}
}

func TestResolveParamValue_DotNotation(t *testing.T) {
results := map[string]any{
"step1": map[string]any{"value": "resolved"},
}
got := resolveParamValue("${step1.value}", results)
if got != "resolved" {
t.Errorf("expected 'resolved', got %v", got)
}
}

func TestResolveParamValue_DotNotation_MissingKey(t *testing.T) {
results := map[string]any{
"step1": map[string]any{"other": "x"},
}
got := resolveParamValue("${step1.value}", results)
if got != "${step1.value}" {
t.Errorf("expected original string, got %v", got)
}
}

func TestResolveParamValue_DotNotation_NonMapResult(t *testing.T) {
results := map[string]any{"step1": "not-a-map"}
got := resolveParamValue("${step1.value}", results)
if got != "${step1.value}" {
t.Errorf("expected original string when step result is not a map, got %v", got)
}
}

func TestResolveParamValue_DotNotation_MissingStep(t *testing.T) {
results := map[string]any{}
got := resolveParamValue("${step1.value}", results)
if got != "${step1.value}" {
t.Errorf("expected original string when step not found, got %v", got)
}
}

func TestResolveParamValue_NotAReference(t *testing.T) {
results := map[string]any{"foo": "bar"}
got := resolveParamValue("just-a-string", results)
if got != "just-a-string" {
t.Errorf("expected 'just-a-string', got %v", got)
}
}