refactor(domain,persist): delete dead registration dedup and read-only catalogue load
UniqueRemoteRegistrations has no caller. LoadReadOnly/LoadCatalogueReadOnly backed the old offline read-only CLI path the broker cutover replaced; its three dedicated tests are rewritten against Open/openCurrentCatalogue (the real production path already covered elsewhere in this file) or dropped where they proved a mapping (bare-catalogue-is-empty) production no longer performs.
- commit
- 3e67bb0b2dab79c98a61ab47c38a9487c39f2148
- author
- brice · · 2026-09-23 01:54 UTC
- parent
- 05bb4e9
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
3 files · +7 -51
M internal/domain/remote_host.go +0 -15
| @@ -44,18 +44,3 @@ func UniqueRemoteHostTargets(values []string) []string { | |||
| 44 | 44 | } | |
| 45 | 45 | return out | |
| 46 | 46 | } | |
| 47 | - | ||
| 48 | - | // UniqueRemoteRegistrations returns a de-duplicated copy preserving first | |
| 49 | - | // occurrence order by endpoint. | |
| 50 | - | func UniqueRemoteRegistrations(values []RemoteRegistration) []RemoteRegistration { | |
| 51 | - | seen := make(map[string]struct{}, len(values)) | |
| 52 | - | out := make([]RemoteRegistration, 0, len(values)) | |
| 53 | - | for _, value := range values { | |
| 54 | - | if _, ok := seen[value.Endpoint]; ok { | |
| 55 | - | continue | |
| 56 | - | } | |
| 57 | - | seen[value.Endpoint] = struct{}{} | |
| 58 | - | out = append(out, value) | |
| 59 | - | } | |
| 60 | - | return out | |
| 61 | - | } | |
| @@ -44,18 +44,3 @@ func UniqueRemoteHostTargets(values []string) []string { | |||||
| 44 | } | 44 | } | ||
| 45 | return out | 45 | return out | ||
| 46 | } | 46 | } | ||
| 47 | - | ||||
| 48 | - | // UniqueRemoteRegistrations returns a de-duplicated copy preserving first | |||
| 49 | - | // occurrence order by endpoint. | |||
| 50 | - | func UniqueRemoteRegistrations(values []RemoteRegistration) []RemoteRegistration { | |||
| 51 | - | seen := make(map[string]struct{}, len(values)) | |||
| 52 | - | out := make([]RemoteRegistration, 0, len(values)) | |||
| 53 | - | for _, value := range values { | |||
| 54 | - | if _, ok := seen[value.Endpoint]; ok { | |||
| 55 | - | continue | |||
| 56 | - | } | |||
| 57 | - | seen[value.Endpoint] = struct{}{} | |||
| 58 | - | out = append(out, value) | |||
| 59 | - | } | |||
| 60 | - | return out | |||
| 61 | - | } | |||
M internal/persist/catalogue_test.go +7 -17
| @@ -21,9 +21,8 @@ func TestCatalogue(t *testing.T) { | |||
| 21 | 21 | t.Run("apply-rename-replace", testCatalogueApplyRenameReplace) | |
| 22 | 22 | t.Run("metadata-update-preserves-authority", testCatalogueMetadataUpdatePreservesAuthority) | |
| 23 | 23 | t.Run("metadata-update-is-deferred", testCatalogueMetadataUpdateIsDeferred) | |
| 24 | - | t.Run("read-only-malformed", testCatalogueLoadReadOnlyRejectsMalformedValue) | |
| 25 | - | t.Run("read-only-fresh-install", testCatalogueLoadReadOnlyFreshInstallHasNoSessions) | |
| 26 | - | t.Run("read-only-ignores-stray-tmp", testCatalogueLoadReadOnlyIgnoresStrayTmp) | |
| 24 | + | t.Run("open-rejects-malformed", testCatalogueOpenRejectsMalformedValue) | |
| 25 | + | t.Run("open-ignores-stray-tmp", testCatalogueOpenIgnoresStrayTmp) | |
| 27 | 26 | } | |
| 28 | 27 | ||
| 29 | 28 | func testCatalogueRecordRoundTrip(t *testing.T) { | |
| @@ -263,27 +262,17 @@ func testCatalogueMetadataUpdateIsDeferred(t *testing.T) { | |||
| 263 | 262 | require.NotEqual(t, afterSync, afterIdentity, "identity writes must sync before returning") | |
| 264 | 263 | } | |
| 265 | 264 | ||
| 266 | - | func testCatalogueLoadReadOnlyRejectsMalformedValue(t *testing.T) { | |
| 265 | + | func testCatalogueOpenRejectsMalformedValue(t *testing.T) { | |
| 267 | 266 | dir := privateDir(t) | |
| 268 | 267 | store, err := kv.Open(filepath.Join(dir, filename)) | |
| 269 | 268 | require.NoError(t, err) | |
| 270 | 269 | require.NoError(t, store.Set([]byte("work"), []byte("malformed"))) | |
| 271 | 270 | require.NoError(t, store.Close()) | |
| 272 | - | _, err = LoadCatalogueReadOnly(dir) | |
| 271 | + | _, err = Open(dir) | |
| 273 | 272 | require.Error(t, err) | |
| 274 | 273 | } | |
| 275 | 274 | ||
| 276 | - | // testCatalogueLoadReadOnlyFreshInstallHasNoSessions covers `vev ls` on a | |
| 277 | - | // machine with no daemon and no catalogue. This must yield an empty catalogue, | |
| 278 | - | // not an error. | |
| 279 | - | func testCatalogueLoadReadOnlyFreshInstallHasNoSessions(t *testing.T) { | |
| 280 | - | dir := privateDir(t) | |
| 281 | - | records, err := LoadCatalogueReadOnly(dir) | |
| 282 | - | require.NoError(t, err) | |
| 283 | - | require.Empty(t, records) | |
| 284 | - | } | |
| 285 | - | ||
| 286 | - | func testCatalogueLoadReadOnlyIgnoresStrayTmp(t *testing.T) { | |
| 275 | + | func testCatalogueOpenIgnoresStrayTmp(t *testing.T) { | |
| 287 | 276 | dir := privateDir(t) | |
| 288 | 277 | p, _, err := openCurrentCatalogue(dir, true) | |
| 289 | 278 | require.NoError(t, err) | |
| @@ -292,8 +281,9 @@ func testCatalogueLoadReadOnlyIgnoresStrayTmp(t *testing.T) { | |||
| 292 | 281 | require.NoError(t, p.Close()) | |
| 293 | 282 | require.NoError(t, os.WriteFile(StorePath(dir)+".tmp", []byte("partial rewrite"), 0o600)) | |
| 294 | 283 | ||
| 295 | - | records, err := LoadCatalogueReadOnly(dir) | |
| 284 | + | reopened, records, err := openCurrentCatalogue(dir, false) | |
| 296 | 285 | require.NoError(t, err) | |
| 286 | + | require.NoError(t, reopened.Close()) | |
| 297 | 287 | require.Equal(t, []domain.CatalogueRecord{want}, records) | |
| 298 | 288 | tmp, err := os.ReadFile(StorePath(dir) + ".tmp") | |
| 299 | 289 | require.NoError(t, err) | |
| @@ -21,9 +21,8 @@ func TestCatalogue(t *testing.T) { | |||||
| 21 | t.Run("apply-rename-replace", testCatalogueApplyRenameReplace) | 21 | t.Run("apply-rename-replace", testCatalogueApplyRenameReplace) | ||
| 22 | t.Run("metadata-update-preserves-authority", testCatalogueMetadataUpdatePreservesAuthority) | 22 | t.Run("metadata-update-preserves-authority", testCatalogueMetadataUpdatePreservesAuthority) | ||
| 23 | t.Run("metadata-update-is-deferred", testCatalogueMetadataUpdateIsDeferred) | 23 | t.Run("metadata-update-is-deferred", testCatalogueMetadataUpdateIsDeferred) | ||
| 24 | - | t.Run("read-only-malformed", testCatalogueLoadReadOnlyRejectsMalformedValue) | 24 | + | t.Run("open-rejects-malformed", testCatalogueOpenRejectsMalformedValue) |
| 25 | - | t.Run("read-only-fresh-install", testCatalogueLoadReadOnlyFreshInstallHasNoSessions) | 25 | + | t.Run("open-ignores-stray-tmp", testCatalogueOpenIgnoresStrayTmp) |
| 26 | - | t.Run("read-only-ignores-stray-tmp", testCatalogueLoadReadOnlyIgnoresStrayTmp) | |||
| 27 | } | 26 | } | ||
| 28 | 27 | ||||
| 29 | func testCatalogueRecordRoundTrip(t *testing.T) { | 28 | func testCatalogueRecordRoundTrip(t *testing.T) { | ||
| @@ -263,27 +262,17 @@ func testCatalogueMetadataUpdateIsDeferred(t *testing.T) { | |||||
| 263 | require.NotEqual(t, afterSync, afterIdentity, "identity writes must sync before returning") | 262 | require.NotEqual(t, afterSync, afterIdentity, "identity writes must sync before returning") | ||
| 264 | } | 263 | } | ||
| 265 | 264 | ||||
| 266 | - | func testCatalogueLoadReadOnlyRejectsMalformedValue(t *testing.T) { | 265 | + | func testCatalogueOpenRejectsMalformedValue(t *testing.T) { |
| 267 | dir := privateDir(t) | 266 | dir := privateDir(t) | ||
| 268 | store, err := kv.Open(filepath.Join(dir, filename)) | 267 | store, err := kv.Open(filepath.Join(dir, filename)) | ||
| 269 | require.NoError(t, err) | 268 | require.NoError(t, err) | ||
| 270 | require.NoError(t, store.Set([]byte("work"), []byte("malformed"))) | 269 | require.NoError(t, store.Set([]byte("work"), []byte("malformed"))) | ||
| 271 | require.NoError(t, store.Close()) | 270 | require.NoError(t, store.Close()) | ||
| 272 | - | _, err = LoadCatalogueReadOnly(dir) | 271 | + | _, err = Open(dir) |
| 273 | require.Error(t, err) | 272 | require.Error(t, err) | ||
| 274 | } | 273 | } | ||
| 275 | 274 | ||||
| 276 | - | // testCatalogueLoadReadOnlyFreshInstallHasNoSessions covers `vev ls` on a | 275 | + | func testCatalogueOpenIgnoresStrayTmp(t *testing.T) { |
| 277 | - | // machine with no daemon and no catalogue. This must yield an empty catalogue, | |||
| 278 | - | // not an error. | |||
| 279 | - | func testCatalogueLoadReadOnlyFreshInstallHasNoSessions(t *testing.T) { | |||
| 280 | - | dir := privateDir(t) | |||
| 281 | - | records, err := LoadCatalogueReadOnly(dir) | |||
| 282 | - | require.NoError(t, err) | |||
| 283 | - | require.Empty(t, records) | |||
| 284 | - | } | |||
| 285 | - | ||||
| 286 | - | func testCatalogueLoadReadOnlyIgnoresStrayTmp(t *testing.T) { | |||
| 287 | dir := privateDir(t) | 276 | dir := privateDir(t) | ||
| 288 | p, _, err := openCurrentCatalogue(dir, true) | 277 | p, _, err := openCurrentCatalogue(dir, true) | ||
| 289 | require.NoError(t, err) | 278 | require.NoError(t, err) | ||
| @@ -292,8 +281,9 @@ func testCatalogueLoadReadOnlyIgnoresStrayTmp(t *testing.T) { | |||||
| 292 | require.NoError(t, p.Close()) | 281 | require.NoError(t, p.Close()) | ||
| 293 | require.NoError(t, os.WriteFile(StorePath(dir)+".tmp", []byte("partial rewrite"), 0o600)) | 282 | require.NoError(t, os.WriteFile(StorePath(dir)+".tmp", []byte("partial rewrite"), 0o600)) | ||
| 294 | 283 | ||||
| 295 | - | records, err := LoadCatalogueReadOnly(dir) | 284 | + | reopened, records, err := openCurrentCatalogue(dir, false) |
| 296 | require.NoError(t, err) | 285 | require.NoError(t, err) | ||
| 286 | + | require.NoError(t, reopened.Close()) | |||
| 297 | require.Equal(t, []domain.CatalogueRecord{want}, records) | 287 | require.Equal(t, []domain.CatalogueRecord{want}, records) | ||
| 298 | tmp, err := os.ReadFile(StorePath(dir) + ".tmp") | 288 | tmp, err := os.ReadFile(StorePath(dir) + ".tmp") | ||
| 299 | require.NoError(t, err) | 289 | require.NoError(t, err) | ||
M internal/persist/persist.go +0 -19
| @@ -127,25 +127,6 @@ func openCurrentCatalogue(dir string, createProvenEmpty bool) (*Persister, []dom | |||
| 127 | 127 | return p, records, nil | |
| 128 | 128 | } | |
| 129 | 129 | ||
| 130 | - | func LoadReadOnly(dir string) ([]domain.CatalogueRecord, error) { return LoadCatalogueReadOnly(dir) } | |
| 131 | - | ||
| 132 | - | // LoadCatalogueReadOnly loads the catalogue without retaining a store handle. | |
| 133 | - | // A fresh install with no main catalogue is not an error. Stray temporary | |
| 134 | - | // files are ignored, while malformed main files fail closed. | |
| 135 | - | func LoadCatalogueReadOnly(dir string) ([]domain.CatalogueRecord, error) { | |
| 136 | - | p, records, err := openCurrentCatalogue(dir, false) | |
| 137 | - | if err != nil { | |
| 138 | - | if errors.Is(err, errPersistenceUnavailable) { | |
| 139 | - | return []domain.CatalogueRecord{}, nil | |
| 140 | - | } | |
| 141 | - | return nil, fmt.Errorf("%w: %s: %w", ErrCatalogueUnreadable, StorePath(dir), err) | |
| 142 | - | } | |
| 143 | - | if err := p.Close(); err != nil { | |
| 144 | - | return nil, err | |
| 145 | - | } | |
| 146 | - | return records, nil | |
| 147 | - | } | |
| 148 | - | ||
| 149 | 130 | func (p *Persister) Save(record domain.CatalogueRecord) error { return p.Replace(record.Name, record) } | |
| 150 | 131 | func (p *Persister) Create(record domain.CatalogueRecord) error { | |
| 151 | 132 | if p == nil { | |
| @@ -127,25 +127,6 @@ func openCurrentCatalogue(dir string, createProvenEmpty bool) (*Persister, []dom | |||||
| 127 | return p, records, nil | 127 | return p, records, nil | ||
| 128 | } | 128 | } | ||
| 129 | 129 | ||||
| 130 | - | func LoadReadOnly(dir string) ([]domain.CatalogueRecord, error) { return LoadCatalogueReadOnly(dir) } | |||
| 131 | - | ||||
| 132 | - | // LoadCatalogueReadOnly loads the catalogue without retaining a store handle. | |||
| 133 | - | // A fresh install with no main catalogue is not an error. Stray temporary | |||
| 134 | - | // files are ignored, while malformed main files fail closed. | |||
| 135 | - | func LoadCatalogueReadOnly(dir string) ([]domain.CatalogueRecord, error) { | |||
| 136 | - | p, records, err := openCurrentCatalogue(dir, false) | |||
| 137 | - | if err != nil { | |||
| 138 | - | if errors.Is(err, errPersistenceUnavailable) { | |||
| 139 | - | return []domain.CatalogueRecord{}, nil | |||
| 140 | - | } | |||
| 141 | - | return nil, fmt.Errorf("%w: %s: %w", ErrCatalogueUnreadable, StorePath(dir), err) | |||
| 142 | - | } | |||
| 143 | - | if err := p.Close(); err != nil { | |||
| 144 | - | return nil, err | |||
| 145 | - | } | |||
| 146 | - | return records, nil | |||
| 147 | - | } | |||
| 148 | - | ||||
| 149 | func (p *Persister) Save(record domain.CatalogueRecord) error { return p.Replace(record.Name, record) } | 130 | func (p *Persister) Save(record domain.CatalogueRecord) error { return p.Replace(record.Name, record) } | ||
| 150 | func (p *Persister) Create(record domain.CatalogueRecord) error { | 131 | func (p *Persister) Create(record domain.CatalogueRecord) error { | ||
| 151 | if p == nil { | 132 | if p == nil { | ||