fix: preserve legacy plugin agent config on settings save

This commit is contained in:
ayattara
2026-08-30 11:34:31 +00:00
parent b96dbf92b8
commit 604354bf59
2 changed files with 42 additions and 0 deletions
@@ -143,6 +143,30 @@ func TestMergeMaskedSecretsDropsMaskWithNoStoredValue(t *testing.T) {
}
}
func TestUpdateConfigPreservesLegacyUtilityAgentForDirectProfileSchema(t *testing.T) {
schema := map[string]any{
"properties": map[string]any{
agentProfileConfigKey: map[string]any{"type": "string", "format": "agent-profile"},
},
}
merged := mergeMaskedSecrets(map[string]any{agentProfileConfigKey: "profile-1"}, map[string]any{
utilityAgentConfigKey: "utility-agent-1",
}, schema)
if _, submitted := merged[utilityAgentConfigKey]; submitted {
t.Fatal("precondition: legacy selector should be absent from the replacement payload")
}
if agentID, ok := merged[utilityAgentConfigKey].(string); ok && agentID != "" {
t.Fatalf("legacy selector unexpectedly present before preservation: %q", agentID)
}
merged = preserveLegacyUtilityAgentConfig(merged, map[string]any{
utilityAgentConfigKey: "utility-agent-1",
}, schema)
if merged[utilityAgentConfigKey] != "utility-agent-1" {
t.Fatalf("legacy selector = %v, want utility-agent-1", merged[utilityAgentConfigKey])
}
}
func TestValidateConfigSchema(t *testing.T) {
schema := testConfigSchema()
cases := []struct {
@@ -36,6 +36,11 @@ func (s *Service) UpdateConfig(ctx context.Context, id string, config map[string
return err
}
merged := mergeMaskedSecrets(config, existing, rec.ConfigSchema)
// Direct-profile plugins can be upgraded from the legacy utility-agent
// selector. 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 the new settings.
merged = preserveLegacyUtilityAgentConfig(merged, existing, rec.ConfigSchema)
if err := validateConfigSchema(rec.ID, merged, rec.ConfigSchema); err != nil {
return err
}
@@ -64,6 +69,19 @@ func (s *Service) UpdateConfig(ctx context.Context, id string, config map[string
return s.restartForConfigChange(rec)
}
func preserveLegacyUtilityAgentConfig(config, existing, schema map[string]any) map[string]any {
if !hasAgentProfileConfig(schema) {
return config
}
if _, submitted := config[utilityAgentConfigKey]; submitted {
return config
}
if agentID, ok := existing[utilityAgentConfigKey].(string); ok && agentID != "" {
config[utilityAgentConfigKey] = agentID
}
return config
}
// errSecretVaultRequired is returned by storeConfigSecrets when a plugin
// declares secret config fields but no vault is wired. It fails closed
// rather than silently persisting the secret in cleartext — production