From dc452153487e5b082589f435cb6f5bbacf8446c0 Mon Sep 17 00:00:00 2001 From: "Theodor S. Midtlien" Date: Tue, 22 Sep 2026 17:32:05 +0200 Subject: [PATCH] Add config name to ConfigInput --- client/internal/profilemanager/config.go | 14 +++++++++++--- client/internal/profilemanager/service.go | 3 +-- client/internal/profilemanager/service_test.go | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/client/internal/profilemanager/config.go b/client/internal/profilemanager/config.go index f14b955f9..c5323f894 100644 --- a/client/internal/profilemanager/config.go +++ b/client/internal/profilemanager/config.go @@ -104,7 +104,11 @@ type ConfigInput struct { LocalMetricsEnabled *bool LocalMetricsAddress *string - Owner *ipcauth.Identity + + // Name is the profile's display name, independent of the on-disk + // filename. Empty leaves the stored name unchanged. + Name string + Owner *ipcauth.Identity } // Config Configuration type @@ -323,8 +327,12 @@ func createNewConfig(input ConfigInput) (*Config, error) { } func (config *Config) apply(input ConfigInput) (updated bool, err error) { - if config.Name != "" { - sanitized, err := sanitizeDisplayName(config.Name) + name := config.Name + if input.Name != "" { + name = input.Name + } + if name != "" { + sanitized, err := sanitizeDisplayName(name) if err != nil { return false, fmt.Errorf("invalid profile name: %w", err) } diff --git a/client/internal/profilemanager/service.go b/client/internal/profilemanager/service.go index f39bb2e3d..3d48d75e9 100644 --- a/client/internal/profilemanager/service.go +++ b/client/internal/profilemanager/service.go @@ -413,11 +413,10 @@ func (s *ServiceManager) AddProfile(displayName string, callerId *ipcauth.Identi } profPath := filepath.Join(configDir, id.String()+".json") - cfg, err := createNewConfig(ConfigInput{ConfigPath: profPath, Owner: callerId}) + cfg, err := createNewConfig(ConfigInput{ConfigPath: profPath, Owner: callerId, Name: displayName}) if err != nil { return nil, fmt.Errorf("failed to create new config: %w", err) } - cfg.Name = displayName if err := util.WriteJsonWithRestrictedPermission(context.Background(), profPath, cfg); err != nil { return nil, fmt.Errorf("failed to write profile config: %w", err) diff --git a/client/internal/profilemanager/service_test.go b/client/internal/profilemanager/service_test.go index b61110b98..fb0bf3356 100644 --- a/client/internal/profilemanager/service_test.go +++ b/client/internal/profilemanager/service_test.go @@ -191,6 +191,21 @@ func TestAddProfile_AllowsDuplicateWithFlag(t *testing.T) { }) } +func TestAddProfile_PersistsName(t *testing.T) { + // The returned Profile carries the name regardless, so this reads the + // file back: the name has to reach the config apply pass, which is what + // the owner log line and every later reader see. + withTestSM(t, func(sm *ServiceManager, userID ipcauth.Identity) { + prof, err := sm.AddProfile("My Work Account", &userID) + require.NoError(t, err) + + cfg, err := ReadConfig(prof.Path) + require.NoError(t, err) + assert.Equal(t, "My Work Account", cfg.Name, "stored config should carry the display name") + require.Len(t, cfg.Owners, 1, "profile should record its creator as owner") + }) +} + func TestAddProfile_RejectsInvalidNames(t *testing.T) { withTestSM(t, func(sm *ServiceManager, userID ipcauth.Identity) { cases := []string{