From 8204782c3a3f9cb49344d7be982b904457216951 Mon Sep 17 00:00:00 2001 From: Victor Gutierrez Calderon Date: Fri, 23 Jan 2026 14:20:35 +1100 Subject: [PATCH] status displays only the applied settings --- cmd/entire/cli/setup.go | 48 ++++++++++++------------------------ cmd/entire/cli/setup_test.go | 11 +++++---- 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/cmd/entire/cli/setup.go b/cmd/entire/cli/setup.go index 42f18c26d..cad6c87ac 100644 --- a/cmd/entire/cli/setup.go +++ b/cmd/entire/cli/setup.go @@ -1,7 +1,6 @@ package cli import ( - "encoding/json" "errors" "fmt" "io" @@ -457,7 +456,7 @@ func runStatus(w io.Writer) error { localSettingsPath = EntireSettingsLocalFile } - // Check if either settings file exists + // Check which settings files exist (for source label) _, projectErr := os.Stat(settingsPath) if projectErr != nil && !errors.Is(projectErr, fs.ErrNotExist) { return fmt.Errorf("cannot access project settings file: %w", projectErr) @@ -474,40 +473,25 @@ func runStatus(w io.Writer) error { return nil } - // Load and display project settings (if exists) - if projectExists { - data, readErr := os.ReadFile(settingsPath) //nolint:gosec // path is from AbsPath or constant - if readErr != nil { - return fmt.Errorf("failed to read project settings: %w", readErr) - } - projectSettings := &EntireSettings{ - Strategy: strategy.DefaultStrategyName, - Enabled: true, - } - if unmarshalErr := json.Unmarshal(data, projectSettings); unmarshalErr != nil { - return fmt.Errorf("failed to parse project settings: %w", unmarshalErr) - } - projectSettings.Strategy = strategy.NormalizeStrategyName(projectSettings.Strategy) - fmt.Fprintln(w, formatSettingsStatus("Project", projectSettings)) + // Load merged settings + settings, err := LoadEntireSettings() + if err != nil { + return fmt.Errorf("failed to load settings: %w", err) } + settings.Strategy = strategy.NormalizeStrategyName(settings.Strategy) - // Load and display local settings (if exists) - if localExists { - data, readErr := os.ReadFile(localSettingsPath) //nolint:gosec // path is from AbsPath or constant - if readErr != nil { - return fmt.Errorf("failed to read local settings: %w", readErr) - } - localSettings := &EntireSettings{ - Strategy: strategy.DefaultStrategyName, - Enabled: true, - } - if unmarshalErr := json.Unmarshal(data, localSettings); unmarshalErr != nil { - return fmt.Errorf("failed to parse local settings: %w", unmarshalErr) - } - localSettings.Strategy = strategy.NormalizeStrategyName(localSettings.Strategy) - fmt.Fprintln(w, formatSettingsStatus("Local", localSettings)) + // Determine source label + var sourceLabel string + switch { + case projectExists && localExists: + sourceLabel = "Project + Local" + case localExists: + sourceLabel = "Local" + default: + sourceLabel = "Project" } + fmt.Fprintln(w, formatSettingsStatus(sourceLabel, settings)) return nil } diff --git a/cmd/entire/cli/setup_test.go b/cmd/entire/cli/setup_test.go index 8f5f1b4dc..6de5e7e4d 100644 --- a/cmd/entire/cli/setup_test.go +++ b/cmd/entire/cli/setup_test.go @@ -518,6 +518,9 @@ func TestRunStatus_LocalSettingsOnly(t *testing.T) { func TestRunStatus_BothProjectAndLocal(t *testing.T) { setupTestRepo(t) + // Project: enabled=true, strategy=manual-commit + // Local: enabled=false, strategy=auto-commit + // Merged: enabled=false (local overrides), strategy=auto-commit (local overrides) writeSettings(t, `{"strategy": "manual-commit", "enabled": true}`) writeLocalSettings(t, `{"strategy": "auto-commit", "enabled": false}`) @@ -527,11 +530,9 @@ func TestRunStatus_BothProjectAndLocal(t *testing.T) { } output := stdout.String() - if !strings.Contains(output, "Project, enabled (manual-commit)") { - t.Errorf("Expected output to show 'Project, enabled (manual-commit)', got: %s", output) - } - if !strings.Contains(output, "Local, disabled (auto-commit)") { - t.Errorf("Expected output to show 'Local, disabled (auto-commit)', got: %s", output) + // Should show merged settings with "Project + Local" source label + if !strings.Contains(output, "Project + Local, disabled (auto-commit)") { + t.Errorf("Expected output to show 'Project + Local, disabled (auto-commit)', got: %s", output) } }