fix: save the theme to an explicit config that does not exist yet (QA-15)
With -config or $VCOM_CONFIG naming a missing file, main now passes that path to the UI and paths.DefaultConfigFile returns $VCOM_CONFIG, so SetKey creates the file every later start reads instead of writing ~/.config/vcom/vcom.toml. A broken-config notice now starts with "Config error:" so the status line shows it as an error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
98aaa09a2b
commit
ec3eeef436
4 changed files with 20 additions and 5 deletions
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue