Skip to content
Open
Changes from 1 commit
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
31 changes: 16 additions & 15 deletions gateway/gateway-controller/pkg/utils/llm_transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,10 @@ func (t *LLMProviderTransformer) transformProxy(proxy *api.LLMProxyConfiguration
operationRegistry[targetKey] = targetOp
}

templateParams, err := buildTemplateParams(tmpl, targetPath)
if err != nil {
return nil, fmt.Errorf("failed to build template params: %w", err)
}
pol := api.Policy{
Name: llmPol.Name,
Version: llmPol.Version,
Params: mergeParams(pathEntry.Params, templateParams),
Params: copyParams(pathEntry.Params),
}
Comment thread
Sithumli marked this conversation as resolved.
appendOperationPolicy(targetOp, pol)
attachedPolicyPaths[targetPath] = true
Expand Down Expand Up @@ -510,14 +506,10 @@ func (t *LLMProviderTransformer) transformProvider(provider *api.LLMProviderConf
continue
}

templateParams, err := buildTemplateParams(tmpl, targetPath)
if err != nil {
return nil, fmt.Errorf("failed to build template params: %w", err)
}
pol := api.Policy{
Name: llmPol.Name,
Version: llmPol.Version,
Params: mergeParams(pathEntry.Params, templateParams),
Params: copyParams(pathEntry.Params),
}
appendOperationPolicy(targetOp, pol)
attachedPolicyPaths[targetPath] = true
Expand Down Expand Up @@ -615,14 +607,10 @@ func (t *LLMProviderTransformer) transformProvider(provider *api.LLMProviderConf
operationRegistry[targetKey] = targetOp
}

templateParams, err := buildTemplateParams(tmpl, targetPath)
if err != nil {
return nil, fmt.Errorf("failed to build template params: %w", err)
}
pol := api.Policy{
Name: llmPol.Name,
Version: llmPol.Version,
Params: mergeParams(pathEntry.Params, templateParams),
Params: copyParams(pathEntry.Params),
}
appendOperationPolicy(targetOp, pol)
attachedPolicyPaths[targetPath] = true
Expand Down Expand Up @@ -793,6 +781,19 @@ func mergeParams(base map[string]interface{}, extra map[string]interface{}) *map
return &merged
}

// copyParams creates a shallow copy of the parameters map and returns a pointer to it.
// Returns nil if the input map is nil or empty.
func copyParams(params map[string]interface{}) *map[string]interface{} {
if len(params) == 0 {
return nil
}
copied := make(map[string]interface{}, len(params))
for k, v := range params {
copied[k] = v
}
return &copied
}
Comment on lines +784 to +795
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New helper copyParams and the behavioral change (policies should no longer receive template extraction keys like requestModel/promptTokens/etc.) aren’t covered by unit tests. Since this package already has tests for related helpers (buildTemplateParams/mergeParams), add tests for copyParams and a transformer-level test asserting that attached policies only include user-provided params (and not template extraction fields).

Copilot uses AI. Check for mistakes.

func appendOperationPolicy(op *api.Operation, pol api.Policy) {
if op.Policies == nil {
op.Policies = &[]api.Policy{pol}
Expand Down
Loading