fix(plugins): preserve trusted legacy selector

This commit is contained in:
ayattara
2026-09-08 09:29:14 +00:00
parent b08e1d99d9
commit 5f76822f38
2 changed files with 43 additions and 6 deletions
@@ -179,6 +179,42 @@ func TestPreserveLegacyUtilityAgentConfigRequiresUpgradeMarker(t *testing.T) {
}
}
func TestPreserveLegacyUtilityAgentConfigKeepsOnlyPreTransitionSelector(t *testing.T) {
schema := map[string]any{"properties": map[string]any{
agentProfileConfigKey: map[string]any{"type": "string", "format": "agent-profile"},
}}
tests := []struct {
name string
existing map[string]any
config map[string]any
want string
present bool
}{
{
name: "replaces submitted selector with pre-transition selector",
existing: map[string]any{utilityAgentConfigKey: "utility-agent-before-upgrade"},
config: map[string]any{utilityAgentConfigKey: "utility-agent-injected"},
want: "utility-agent-before-upgrade",
present: true,
},
{
name: "drops newly submitted selector without pre-transition selector",
existing: map[string]any{},
config: map[string]any{utilityAgentConfigKey: "utility-agent-injected"},
present: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := preserveLegacyUtilityAgentConfig(tt.config, tt.existing, schema, true)
selector, present := got[utilityAgentConfigKey]
if present != tt.present || (present && selector != tt.want) {
t.Fatalf("legacy selector = (%v, present=%t), want (%q, present=%t)", selector, present, tt.want, tt.present)
}
})
}
}
func TestValidateConfigSchema(t *testing.T) {
schema := testConfigSchema()
cases := []struct {
@@ -37,9 +37,9 @@ func (s *Service) UpdateConfig(ctx context.Context, id string, config map[string
}
merged := mergeMaskedSecrets(config, existing, rec.ConfigSchema)
// A direct-profile plugin upgraded from the legacy utility-agent selector
// carries a persisted provenance marker. Keep that selector across the
// full-replacement settings write when the new form does not submit it, so
// host-side compatibility remains durable after the operator saves.
// carries a persisted provenance marker. Keep only the selector that
// existed before the manifest transition: the replacement schema no longer
// declares this key, so a later payload must not introduce or replace it.
merged = preserveLegacyUtilityAgentConfig(merged, existing, rec.ConfigSchema, rec.LegacyUtilityAgentFallback)
if err := validateConfigSchema(rec.ID, merged, rec.ConfigSchema); err != nil {
return err
@@ -73,9 +73,10 @@ func preserveLegacyUtilityAgentConfig(config, existing, schema map[string]any, a
if !allowLegacyFallback || !hasAgentProfileConfig(schema) {
return config
}
if _, submitted := config[utilityAgentConfigKey]; submitted {
return config
}
// The legacy field is intentionally absent from the replacement schema.
// Ignore any submitted value and restore only the value retained from the
// pre-transition configuration.
delete(config, utilityAgentConfigKey)
if agentID, ok := existing[utilityAgentConfigKey].(string); ok && agentID != "" {
config[utilityAgentConfigKey] = agentID
}