diff --git a/internal/ui/snapshot_editor.go b/internal/ui/snapshot_editor.go index 8825246..4b66d04 100644 --- a/internal/ui/snapshot_editor.go +++ b/internal/ui/snapshot_editor.go @@ -114,14 +114,17 @@ func NewSnapshotEditor(snap *snapshot.Snapshot) SnapshotEditorModel { } tabs[3] = editorTab{name: "Taps", icon: "🔌", items: tapItems, itemType: editorItemTap} - prefItems := make([]editorItem, len(snap.MacOSPrefs)) - for i, p := range snap.MacOSPrefs { - prefItems[i] = editorItem{ + var prefItems []editorItem + for _, p := range snap.MacOSPrefs { + if p.Domain == "" || p.Key == "" { + continue + } + prefItems = append(prefItems, editorItem{ name: fmt.Sprintf("%s.%s", p.Domain, p.Key), description: fmt.Sprintf("= %s (%s)", p.Value, p.Desc), selected: true, itemType: editorItemMacOSPref, - } + }) } tabs[4] = editorTab{name: "macOS Prefs", icon: "⚙️ ", items: prefItems, itemType: editorItemMacOSPref} diff --git a/internal/ui/snapshot_editor_test.go b/internal/ui/snapshot_editor_test.go index f95d49e..b11b2b5 100644 --- a/internal/ui/snapshot_editor_test.go +++ b/internal/ui/snapshot_editor_test.go @@ -68,6 +68,25 @@ func TestNewSnapshotEditorItems(t *testing.T) { assert.Equal(t, "homebrew/core", m.tabs[3].items[0].name) } +func TestNewSnapshotEditorSkipsInvalidMacOSPrefs(t *testing.T) { + snap := makeTestSnapshot() + snap.MacOSPrefs = append(snap.MacOSPrefs, + snapshot.MacOSPref{Domain: "cirruslabs/cli", Key: ""}, // tap misclassified as pref + snapshot.MacOSPref{Domain: "", Key: "SomeKey"}, // empty domain + snapshot.MacOSPref{Domain: "com.apple.dock", Key: "tilesize", Value: "48"}, // valid + ) + m := NewSnapshotEditor(snap) + + // Only valid prefs (non-empty domain AND key) should appear in the macOS Prefs tab. + prefTab := m.tabs[4] + for _, item := range prefTab.items { + assert.NotEmpty(t, item.name, "pref item name must not be empty") + assert.Contains(t, item.name, ".", "pref item name must contain a dot separator") + } + // 2 from makeTestSnapshot + 1 valid new pref = 3 + assert.Equal(t, 3, len(prefTab.items)) +} + func TestNewSnapshotEditorAllItemsSelected(t *testing.T) { snap := makeTestSnapshot() m := NewSnapshotEditor(snap)