fix(cef): use XDG config dir for user data
- commit
- dfa0012d18960c4dc46531ecbb2fd03850863739
- author
- brice · · 2026-04-09 04:26 UTC
- parent
- 3b3765d
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +34 -2
M internal/infrastructure/cef/engine_init.go +7 -1
| @@ -94,7 +94,13 @@ func prepareCEFSettings(cfg config.CEFEngineConfig, logger *zerolog.Logger) pure | |||
| 94 | 94 | } | |
| 95 | 95 | ||
| 96 | 96 | func defaultCEFUserDataDir() string { | |
| 97 | - | return filepath.Clean(filepath.Join(os.Getenv("HOME"), ".config", "cef_user_data")) | |
| 97 | + | // Use Dumber's XDG helpers to get the config directory | |
| 98 | + | dirs, err := config.GetXDGDirs() | |
| 99 | + | if err != nil { | |
| 100 | + | // Fallback to HOME-based path if XDG resolution fails | |
| 101 | + | return filepath.Clean(filepath.Join(os.Getenv("HOME"), ".config", "cef_user_data")) | |
| 102 | + | } | |
| 103 | + | return filepath.Join(dirs.ConfigHome, "cef_user_data") | |
| 98 | 104 | } | |
| 99 | 105 | ||
| 100 | 106 | // initializeCEF calls cef_initialize with the App to register custom schemes | |
| @@ -94,7 +94,13 @@ func prepareCEFSettings(cfg config.CEFEngineConfig, logger *zerolog.Logger) pure | |||||
| 94 | } | 94 | } | ||
| 95 | 95 | ||||
| 96 | func defaultCEFUserDataDir() string { | 96 | func defaultCEFUserDataDir() string { | ||
| 97 | - | return filepath.Clean(filepath.Join(os.Getenv("HOME"), ".config", "cef_user_data")) | 97 | + | // Use Dumber's XDG helpers to get the config directory |
| 98 | + | dirs, err := config.GetXDGDirs() | |||
| 99 | + | if err != nil { | |||
| 100 | + | // Fallback to HOME-based path if XDG resolution fails | |||
| 101 | + | return filepath.Clean(filepath.Join(os.Getenv("HOME"), ".config", "cef_user_data")) | |||
| 102 | + | } | |||
| 103 | + | return filepath.Join(dirs.ConfigHome, "cef_user_data") | |||
| 98 | } | 104 | } | ||
| 99 | 105 | ||||
| 100 | // initializeCEF calls cef_initialize with the App to register custom schemes | 106 | // initializeCEF calls cef_initialize with the App to register custom schemes | ||
M internal/infrastructure/cef/engine_init_test.go +27 -1
| @@ -1,6 +1,7 @@ | |||
| 1 | 1 | package cef | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | + | "os" | |
| 4 | 5 | "path/filepath" | |
| 5 | 6 | "testing" | |
| 6 | 7 | ||
| @@ -30,11 +31,36 @@ func TestPrepareCEFInitTraceFile_EnabledViaEnv(t *testing.T) { | |||
| 30 | 31 | } | |
| 31 | 32 | ||
| 32 | 33 | func TestPrepareCEFSettings_SetsRootCachePath(t *testing.T) { | |
| 34 | + | // Test production mode: should use XDG config home | |
| 33 | 35 | homeDir := filepath.Join(t.TempDir(), "home") | |
| 34 | 36 | t.Setenv("HOME", homeDir) | |
| 37 | + | t.Setenv("ENV", "") | |
| 35 | 38 | ||
| 36 | 39 | logger := zerolog.Nop() | |
| 37 | 40 | settings := prepareCEFSettings(config.CEFEngineConfig{}, &logger) | |
| 38 | 41 | ||
| 39 | - | require.Equal(t, filepath.Join(homeDir, ".config", "cef_user_data"), settings.RootCachePath) | |
| 42 | + | // Should use XDG config home (~/.config/dumber/cef_user_data in prod) | |
| 43 | + | require.Equal(t, filepath.Join(homeDir, ".config", "dumber", "cef_user_data"), settings.RootCachePath) | |
| 44 | + | } | |
| 45 | + | ||
| 46 | + | func TestPrepareCEFSettings_RootCachePath_DevMode(t *testing.T) { | |
| 47 | + | // Create a temp directory and change into it for the test | |
| 48 | + | tempDir := t.TempDir() | |
| 49 | + | originalDir, err := os.Getwd() | |
| 50 | + | require.NoError(t, err) | |
| 51 | + | defer func() { | |
| 52 | + | _ = os.Chdir(originalDir) | |
| 53 | + | }() | |
| 54 | + | ||
| 55 | + | err = os.Chdir(tempDir) | |
| 56 | + | require.NoError(t, err) | |
| 57 | + | ||
| 58 | + | // Set ENV=dev to trigger dev mode | |
| 59 | + | t.Setenv("ENV", "dev") | |
| 60 | + | ||
| 61 | + | logger := zerolog.Nop() | |
| 62 | + | settings := prepareCEFSettings(config.CEFEngineConfig{}, &logger) | |
| 63 | + | ||
| 64 | + | // In dev mode, should resolve under .dev/dumber/cef_user_data | |
| 65 | + | require.Equal(t, filepath.Join(tempDir, ".dev", "dumber", "cef_user_data"), settings.RootCachePath) | |
| 40 | 66 | } | |
| @@ -1,6 +1,7 @@ | |||||
| 1 | package cef | 1 | package cef | ||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | + | "os" | |||
| 4 | "path/filepath" | 5 | "path/filepath" | ||
| 5 | "testing" | 6 | "testing" | ||
| 6 | 7 | ||||
| @@ -30,11 +31,36 @@ func TestPrepareCEFInitTraceFile_EnabledViaEnv(t *testing.T) { | |||||
| 30 | } | 31 | } | ||
| 31 | 32 | ||||
| 32 | func TestPrepareCEFSettings_SetsRootCachePath(t *testing.T) { | 33 | func TestPrepareCEFSettings_SetsRootCachePath(t *testing.T) { | ||
| 34 | + | // Test production mode: should use XDG config home | |||
| 33 | homeDir := filepath.Join(t.TempDir(), "home") | 35 | homeDir := filepath.Join(t.TempDir(), "home") | ||
| 34 | t.Setenv("HOME", homeDir) | 36 | t.Setenv("HOME", homeDir) | ||
| 37 | + | t.Setenv("ENV", "") | |||
| 35 | 38 | ||||
| 36 | logger := zerolog.Nop() | 39 | logger := zerolog.Nop() | ||
| 37 | settings := prepareCEFSettings(config.CEFEngineConfig{}, &logger) | 40 | settings := prepareCEFSettings(config.CEFEngineConfig{}, &logger) | ||
| 38 | 41 | ||||
| 39 | - | require.Equal(t, filepath.Join(homeDir, ".config", "cef_user_data"), settings.RootCachePath) | 42 | + | // Should use XDG config home (~/.config/dumber/cef_user_data in prod) |
| 43 | + | require.Equal(t, filepath.Join(homeDir, ".config", "dumber", "cef_user_data"), settings.RootCachePath) | |||
| 44 | + | } | |||
| 45 | + | ||||
| 46 | + | func TestPrepareCEFSettings_RootCachePath_DevMode(t *testing.T) { | |||
| 47 | + | // Create a temp directory and change into it for the test | |||
| 48 | + | tempDir := t.TempDir() | |||
| 49 | + | originalDir, err := os.Getwd() | |||
| 50 | + | require.NoError(t, err) | |||
| 51 | + | defer func() { | |||
| 52 | + | _ = os.Chdir(originalDir) | |||
| 53 | + | }() | |||
| 54 | + | ||||
| 55 | + | err = os.Chdir(tempDir) | |||
| 56 | + | require.NoError(t, err) | |||
| 57 | + | ||||
| 58 | + | // Set ENV=dev to trigger dev mode | |||
| 59 | + | t.Setenv("ENV", "dev") | |||
| 60 | + | ||||
| 61 | + | logger := zerolog.Nop() | |||
| 62 | + | settings := prepareCEFSettings(config.CEFEngineConfig{}, &logger) | |||
| 63 | + | ||||
| 64 | + | // In dev mode, should resolve under .dev/dumber/cef_user_data | |||
| 65 | + | require.Equal(t, filepath.Join(tempDir, ".dev", "dumber", "cef_user_data"), settings.RootCachePath) | |||
| 40 | } | 66 | } | ||