diff --git a/cmd/vcom/main.go b/cmd/vcom/main.go index 297aea3..79fc307 100644 --- a/cmd/vcom/main.go +++ b/cmd/vcom/main.go @@ -38,14 +38,18 @@ func run() int { // A broken config is not fatal: defaults + a message in the status line. cfg, info, cfgErr := config.Load(*configPath) + // The theme is saved to resolvedPath: the file that was read, or — for + // an explicit -config/$VCOM_CONFIG that does not exist yet — that path, + // so the next start finds it (QA-15). "" means the default XDG file. resolvedPath := "" - if info.Found && cfgErr == nil { + explicit := *configPath != "" || os.Getenv("VCOM_CONFIG") != "" + if cfgErr == nil && (info.Found || explicit) { resolvedPath = info.Path } notice := "" switch { case cfgErr != nil: - notice = cfgErr.Error() + notice = "Config error: " + cfgErr.Error() // "error" → shown in red (QA-19) slog.Warn("config", "err", cfgErr) case len(info.Warnings) == 1: notice = "config: " + info.Warnings[0] diff --git a/internal/paths/paths.go b/internal/paths/paths.go index a849e58..0cd6db1 100644 --- a/internal/paths/paths.go +++ b/internal/paths/paths.go @@ -178,9 +178,13 @@ func ConfigFile(explicit string) (path string, found bool, err error) { return def, false, err } -// DefaultConfigFile is where a new config file is created. Under sudo it is -// the effective user's, so root does not create files in ~user. +// DefaultConfigFile is where a new config file is created: $VCOM_CONFIG if +// set (the file every start reads; QA-15), else the XDG file. Under sudo it +// is the effective user's, so root does not create files in ~user. func DefaultConfigFile() (string, error) { + if p := sys.getenv("VCOM_CONFIG"); p != "" { + return filepath.Abs(p) + } if _, sudo := SudoUser(); sudo { d, err := xdgWrite("XDG_CONFIG_HOME", ".config") if err != nil { diff --git a/internal/paths/paths_test.go b/internal/paths/paths_test.go index fbb882b..efb127e 100644 --- a/internal/paths/paths_test.go +++ b/internal/paths/paths_test.go @@ -172,3 +172,11 @@ func TestPidAlive(t *testing.T) { t.Fatal("self not alive") } } + +func TestDefaultConfigFileHonoursVCOMConfig(t *testing.T) { + home := t.TempDir() + fake(t, map[string]string{"HOME": home, "VCOM_CONFIG": filepath.Join(home, "custom", "v.toml")}, 1000, nil) + if p, _ := DefaultConfigFile(); p != filepath.Join(home, "custom", "v.toml") { + t.Fatalf("DefaultConfigFile = %s (QA-15)", p) + } +} diff --git a/internal/ui/qa_rc2_test.go b/internal/ui/qa_rc2_test.go index a7b7e98..71a9cf9 100644 --- a/internal/ui/qa_rc2_test.go +++ b/internal/ui/qa_rc2_test.go @@ -87,7 +87,6 @@ func TestQABrokenConfigNotOverwrittenByTheme(t *testing.T) { // sees it. main passes "" for a missing file and SetKey("") writes the // default ~/.config/vcom/vcom.toml instead. func TestQAThemeSavedToExplicitMissingConfig(t *testing.T) { - t.Skip("BUG QA-15 (P2): with -config/$VCOM_CONFIG pointing to a missing file, the theme is saved to ~/.config/vcom/vcom.toml (main.go:41-43 passes resolvedPath=\"\" unless the file exists; SetKey(\"\") uses the default path); the next start reads the explicit path and loses it") home := isolateEnv(t) explicit := filepath.Join(home, "custom", "vcom.toml") t.Setenv("VCOM_CONFIG", explicit)