From e623746e60b9f8ff3cb6f21af21ab0fcecdb0972 Mon Sep 17 00:00:00 2001 From: Graeme Foster <80714+GraemeF@users.noreply.github.com> Date: Sat, 3 Jan 2026 19:51:01 +0000 Subject: [PATCH] fix(config): normalize keys in GetYamlConfig to match SetYamlConfig (#874) GetYamlConfig was not normalizing key aliases (e.g., sync.branch -> sync-branch), causing 'bd config get sync.branch' to return 'not set' even when the value was correctly stored. SetYamlConfig already normalized keys, but GetYamlConfig did not, leading to a confusing mismatch where set appeared to work but get could not find the value. Added TestGetYamlConfig_KeyNormalization to verify the fix. Fixes #873 --- internal/config/yaml_config.go | 4 ++- internal/config/yaml_config_test.go | 47 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/internal/config/yaml_config.go b/internal/config/yaml_config.go index 6bdc31f5..a5c3108e 100644 --- a/internal/config/yaml_config.go +++ b/internal/config/yaml_config.go @@ -130,11 +130,13 @@ func SetYamlConfig(key, value string) error { // GetYamlConfig gets a configuration value from config.yaml. // Returns empty string if key is not found or is commented out. +// Keys are normalized to their canonical yaml format (e.g., sync.branch -> sync-branch). func GetYamlConfig(key string) string { if v == nil { return "" } - return v.GetString(key) + normalizedKey := normalizeYamlKey(key) + return v.GetString(normalizedKey) } // findProjectConfigYaml finds the project's .beads/config.yaml file. diff --git a/internal/config/yaml_config_test.go b/internal/config/yaml_config_test.go index 9f09b6aa..de8e7ded 100644 --- a/internal/config/yaml_config_test.go +++ b/internal/config/yaml_config_test.go @@ -224,6 +224,53 @@ sync-branch: old-value } } +func TestGetYamlConfig_KeyNormalization(t *testing.T) { + // Create a temp directory with .beads/config.yaml + tmpDir, err := os.MkdirTemp("", "beads-yaml-get-key-norm-*") + if err != nil { + t.Fatalf("Failed to create temp dir: %v", err) + } + defer os.RemoveAll(tmpDir) + + beadsDir := filepath.Join(tmpDir, ".beads") + if err := os.MkdirAll(beadsDir, 0755); err != nil { + t.Fatalf("Failed to create .beads dir: %v", err) + } + + // Write config with canonical key name (sync-branch, not sync.branch) + configPath := filepath.Join(beadsDir, "config.yaml") + initialConfig := `# Beads Config +sync-branch: test-value +` + if err := os.WriteFile(configPath, []byte(initialConfig), 0644); err != nil { + t.Fatalf("Failed to write config.yaml: %v", err) + } + + // Change to temp directory for the test + oldWd, _ := os.Getwd() + if err := os.Chdir(tmpDir); err != nil { + t.Fatalf("Failed to chdir: %v", err) + } + defer os.Chdir(oldWd) + + // Initialize viper to read the config + if err := Initialize(); err != nil { + t.Fatalf("Initialize() error = %v", err) + } + + // Test GetYamlConfig with aliased key (sync.branch should find sync-branch value) + got := GetYamlConfig("sync.branch") + if got != "test-value" { + t.Errorf("GetYamlConfig(\"sync.branch\") = %q, want %q", got, "test-value") + } + + // Also verify canonical key works + got = GetYamlConfig("sync-branch") + if got != "test-value" { + t.Errorf("GetYamlConfig(\"sync-branch\") = %q, want %q", got, "test-value") + } +} + func TestSetYamlConfig(t *testing.T) { // Create a temp directory with .beads/config.yaml tmpDir, err := os.MkdirTemp("", "beads-yaml-test-*")