refactor(remote): centralize catalog cache path and unwrap load error
Add CatalogCachePath alongside HostStorePath so run.go and its test share one canonical path instead of an inline filepath.Join literal. Also drop the redundant "malformed cache file" wrapper in Load, since normalizeCatalogCacheEntries already returns errors prefixed with "remote catalog cache: ...".
- commit
- fa63924cb6a33edca22c725375360b74956f46b5
- author
- brice · · 2026-07-31 08:31 UTC
- committer
- brice · · 2026-07-31 08:54 UTC
- parent
- f0e21e9
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
3 files · +11 -4
M internal/adapters/remote/catalog_cache.go +9 -2
| @@ -6,6 +6,7 @@ import ( | |||
| 6 | 6 | "errors" | |
| 7 | 7 | "fmt" | |
| 8 | 8 | "os" | |
| 9 | + | "path/filepath" | |
| 9 | 10 | "sort" | |
| 10 | 11 | "time" | |
| 11 | 12 | "unicode/utf8" | |
| @@ -14,7 +15,13 @@ import ( | |||
| 14 | 15 | "github.com/bnema/vev/internal/ports" | |
| 15 | 16 | ) | |
| 16 | 17 | ||
| 17 | - | const catalogCacheFileVersion = 1 | |
| 18 | + | const ( | |
| 19 | + | catalogCacheFileName = "remote-catalog-cache.json" | |
| 20 | + | catalogCacheFileVersion = 1 | |
| 21 | + | ) | |
| 22 | + | ||
| 23 | + | // CatalogCachePath returns the canonical location of the remote catalog cache in stateDir. | |
| 24 | + | func CatalogCachePath(stateDir string) string { return filepath.Join(stateDir, catalogCacheFileName) } | |
| 18 | 25 | ||
| 19 | 26 | type catalogCacheFile struct { | |
| 20 | 27 | Version *int `json:"version"` | |
| @@ -114,7 +121,7 @@ func (c *fileCatalogCache) Load() ([]ports.RemoteCatalogCacheEntry, error) { | |||
| 114 | 121 | } | |
| 115 | 122 | normalized, err := normalizeCatalogCacheEntries(entries) | |
| 116 | 123 | if err != nil { | |
| 117 | - | return nil, fmt.Errorf("remote catalog cache: malformed cache file: %w", err) | |
| 124 | + | return nil, err | |
| 118 | 125 | } | |
| 119 | 126 | return normalized, nil | |
| 120 | 127 | } | |
| @@ -6,6 +6,7 @@ import ( | |||||
| 6 | "errors" | 6 | "errors" | ||
| 7 | "fmt" | 7 | "fmt" | ||
| 8 | "os" | 8 | "os" | ||
| 9 | + | "path/filepath" | |||
| 9 | "sort" | 10 | "sort" | ||
| 10 | "time" | 11 | "time" | ||
| 11 | "unicode/utf8" | 12 | "unicode/utf8" | ||
| @@ -14,7 +15,13 @@ import ( | |||||
| 14 | "github.com/bnema/vev/internal/ports" | 15 | "github.com/bnema/vev/internal/ports" | ||
| 15 | ) | 16 | ) | ||
| 16 | 17 | ||||
| 17 | - | const catalogCacheFileVersion = 1 | 18 | + | const ( |
| 19 | + | catalogCacheFileName = "remote-catalog-cache.json" | |||
| 20 | + | catalogCacheFileVersion = 1 | |||
| 21 | + | ) | |||
| 22 | + | ||||
| 23 | + | // CatalogCachePath returns the canonical location of the remote catalog cache in stateDir. | |||
| 24 | + | func CatalogCachePath(stateDir string) string { return filepath.Join(stateDir, catalogCacheFileName) } | |||
| 18 | 25 | ||||
| 19 | type catalogCacheFile struct { | 26 | type catalogCacheFile struct { | ||
| 20 | Version *int `json:"version"` | 27 | Version *int `json:"version"` | ||
| @@ -114,7 +121,7 @@ func (c *fileCatalogCache) Load() ([]ports.RemoteCatalogCacheEntry, error) { | |||||
| 114 | } | 121 | } | ||
| 115 | normalized, err := normalizeCatalogCacheEntries(entries) | 122 | normalized, err := normalizeCatalogCacheEntries(entries) | ||
| 116 | if err != nil { | 123 | if err != nil { | ||
| 117 | - | return nil, fmt.Errorf("remote catalog cache: malformed cache file: %w", err) | 124 | + | return nil, err |
| 118 | } | 125 | } | ||
| 119 | return normalized, nil | 126 | return normalized, nil | ||
| 120 | } | 127 | } | ||
M internal/app/run.go +1 -1
| @@ -798,7 +798,7 @@ func remoteDiscoveryDaemonOption(stateDir string, observer ports.SerializedRunti | |||
| 798 | 798 | return daemon.WithRemoteDiscovery( | |
| 799 | 799 | newRemoteHostStore(remoteadapter.HostStorePath(stateDir)), | |
| 800 | 800 | newRemoteCatalogClient(), | |
| 801 | - | newRemoteCatalogCache(filepath.Join(stateDir, "remote-catalog-cache.json")), | |
| 801 | + | newRemoteCatalogCache(remoteadapter.CatalogCachePath(stateDir)), | |
| 802 | 802 | newRemoteDialerFactoryWithRuntimeObserver(observer), | |
| 803 | 803 | mode, | |
| 804 | 804 | ), nil | |
| @@ -798,7 +798,7 @@ func remoteDiscoveryDaemonOption(stateDir string, observer ports.SerializedRunti | |||||
| 798 | return daemon.WithRemoteDiscovery( | 798 | return daemon.WithRemoteDiscovery( | ||
| 799 | newRemoteHostStore(remoteadapter.HostStorePath(stateDir)), | 799 | newRemoteHostStore(remoteadapter.HostStorePath(stateDir)), | ||
| 800 | newRemoteCatalogClient(), | 800 | newRemoteCatalogClient(), | ||
| 801 | - | newRemoteCatalogCache(filepath.Join(stateDir, "remote-catalog-cache.json")), | 801 | + | newRemoteCatalogCache(remoteadapter.CatalogCachePath(stateDir)), |
| 802 | newRemoteDialerFactoryWithRuntimeObserver(observer), | 802 | newRemoteDialerFactoryWithRuntimeObserver(observer), | ||
| 803 | mode, | 803 | mode, | ||
| 804 | ), nil | 804 | ), nil | ||
M internal/app/run_test.go +1 -1
| @@ -1402,7 +1402,7 @@ func TestRemoteDiscoveryDaemonOptionWiresProductionPorts(t *testing.T) { | |||
| 1402 | 1402 | require.NoError(t, err) | |
| 1403 | 1403 | _ = daemon.New(nil, nil, slog.New(slog.NewTextHandler(io.Discard, nil)), option) | |
| 1404 | 1404 | require.Equal(t, remoteadapter.HostStorePath(stateDir), hostPath) | |
| 1405 | - | require.Equal(t, filepath.Join(stateDir, "remote-catalog-cache.json"), cachePath) | |
| 1405 | + | require.Equal(t, remoteadapter.CatalogCachePath(stateDir), cachePath) | |
| 1406 | 1406 | require.Equal(t, 1, cache.loads, "daemon startup must load the cache once") | |
| 1407 | 1407 | } | |
| 1408 | 1408 | ||
| @@ -1402,7 +1402,7 @@ func TestRemoteDiscoveryDaemonOptionWiresProductionPorts(t *testing.T) { | |||||
| 1402 | require.NoError(t, err) | 1402 | require.NoError(t, err) | ||
| 1403 | _ = daemon.New(nil, nil, slog.New(slog.NewTextHandler(io.Discard, nil)), option) | 1403 | _ = daemon.New(nil, nil, slog.New(slog.NewTextHandler(io.Discard, nil)), option) | ||
| 1404 | require.Equal(t, remoteadapter.HostStorePath(stateDir), hostPath) | 1404 | require.Equal(t, remoteadapter.HostStorePath(stateDir), hostPath) | ||
| 1405 | - | require.Equal(t, filepath.Join(stateDir, "remote-catalog-cache.json"), cachePath) | 1405 | + | require.Equal(t, remoteadapter.CatalogCachePath(stateDir), cachePath) |
| 1406 | require.Equal(t, 1, cache.loads, "daemon startup must load the cache once") | 1406 | require.Equal(t, 1, cache.loads, "daemon startup must load the cache once") | ||
| 1407 | } | 1407 | } | ||
| 1408 | 1408 | ||||