High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: check config FILE not directory for legacy path (issue #224)
dddabtcf8ae9e8971f9
diff --git a/internal/config/config_utils.go b/internal/config/config_utils.goindex e20c8c31..fc38c5d3 100644--- a/internal/config/config_utils.go+++ b/internal/config/config_utils.go@@ -30,16 +30,29 @@ func userConfigDir() string {newPath := filepath.Join(configDir, "pinchtab")- legacyExists := dirExists(legacyPath)- newExists := dirExists(newPath)+ // Priority 1: Check for config FILE (handles case where both dirs exist+ // but only legacy has config.json — the issue #224 scenario)+ legacyConfig := filepath.Join(legacyPath, "config.json")+ newConfig := filepath.Join(newPath, "config.json")- if legacyExists && !newExists {+ if fileExists(legacyConfig) && !fileExists(newConfig) {+ return legacyPath+ }++ // Priority 2: Check for DIRECTORY (handles init scenario where+ // legacy dir exists from npm install but no config yet)+ if dirExists(legacyPath) && !dirExists(newPath) {return legacyPath}return newPath}+func fileExists(path string) bool {+ info, err := os.Stat(path)+ return err == nil && !info.IsDir()+}+// DefaultConfigPath returns the default config file location used when// PINCHTAB_CONFIG is not explicitly set.func DefaultConfigPath() string {diff --git a/internal/config/config_utils_test.go b/internal/config/config_utils_test.goindex e352f302..4eba4727 100644--- a/internal/config/config_utils_test.go+++ b/internal/config/config_utils_test.go@@ -1,6 +1,11 @@package config-import "testing"+import (+ "os"+ "path/filepath"+ "runtime"+ "testing"+)func TestCompareVersions(t *testing.T) {tests := []struct {@@ -54,3 +59,78 @@ func TestIsFirstRun(t *testing.T) {t.Error("expected not IsFirstRun for versioned config")}}++// TestUserConfigDirLegacyConfigFilePriority tests that when legacy config FILE exists+// but the XDG config directory already exists (without config.json), the legacy path+// is still used. This exercises the full userConfigDir path resolution for issue #224.+func TestUserConfigDirLegacyConfigFilePriority(t *testing.T) {+ if runtime.GOOS != "linux" {+ t.Skip("Linux-specific XDG path test")+ }++ tmpHome, err := os.MkdirTemp("", "pinchtab-home-*")+ if err != nil {+ t.Fatalf("Failed to create temp home: %v", err)+ }+ defer func() { _ = os.RemoveAll(tmpHome) }()++ t.Setenv("HOME", tmpHome)+ t.Setenv("XDG_CONFIG_HOME", filepath.Join(tmpHome, ".config"))++ legacyDir := filepath.Join(tmpHome, ".pinchtab")+ newDir := filepath.Join(tmpHome, ".config", "pinchtab")+ if err := os.MkdirAll(legacyDir, 0755); err != nil {+ t.Fatalf("Failed to create legacy dir: %v", err)+ }+ if err := os.MkdirAll(newDir, 0755); err != nil {+ t.Fatalf("Failed to create new dir: %v", err)+ }++ legacyConfig := filepath.Join(legacyDir, "config.json")+ if err := os.WriteFile(legacyConfig, []byte(`{"server":{"port":"9876"}}`), 0644); err != nil {+ t.Fatalf("Failed to create legacy config: %v", err)+ }++ got := userConfigDir()+ if got != legacyDir {+ t.Fatalf("userConfigDir() = %q, want legacy path %q", got, legacyDir)+ }+}++func TestUserConfigDirPrefersNewConfigFileWhenPresent(t *testing.T) {+ if runtime.GOOS != "linux" {+ t.Skip("Linux-specific XDG path test")+ }++ tmpHome, err := os.MkdirTemp("", "pinchtab-home-*")+ if err != nil {+ t.Fatalf("Failed to create temp home: %v", err)+ }+ defer func() { _ = os.RemoveAll(tmpHome) }()++ t.Setenv("HOME", tmpHome)+ t.Setenv("XDG_CONFIG_HOME", filepath.Join(tmpHome, ".config"))++ legacyDir := filepath.Join(tmpHome, ".pinchtab")+ newDir := filepath.Join(tmpHome, ".config", "pinchtab")+ if err := os.MkdirAll(legacyDir, 0755); err != nil {+ t.Fatalf("Failed to create legacy dir: %v", err)+ }+ if err := os.MkdirAll(newDir, 0755); err != nil {+ t.Fatalf("Failed to create new dir: %v", err)+ }++ for _, path := range []string{+ filepath.Join(legacyDir, "config.json"),+ filepath.Join(newDir, "config.json"),+ } {+ if err := os.WriteFile(path, []byte(`{"server":{"port":"9876"}}`), 0644); err != nil {+ t.Fatalf("Failed to create config %s: %v", path, err)+ }+ }++ got := userConfigDir()+ if got != newDir {+ t.Fatalf("userConfigDir() = %q, want new XDG path %q", got, newDir)+ }+}