fix(palette): retain distinct local routes remotely
- commit
- f519cfa514351350c151db564e451e543671159a
- author
- brice · · 2026-08-11 09:46 UTC
- committer
- brice · · 2026-08-11 09:47 UTC
- parent
- 5ed306e
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +17 -5
M internal/usecase/daemon/palette.go +10 -3
| @@ -107,11 +107,18 @@ func (d *Daemon) paletteResults(current *session, commands []command.Command, ro | |||
| 107 | 107 | continue | |
| 108 | 108 | } | |
| 109 | 109 | if _, represented := localNames[entry.Name]; represented { | |
| 110 | - | localRoute := entry.Kind == ports.RouteKindLocal | |
| 111 | - | currentRemoteRoute := entry.Kind == ports.RouteKindRemote && currentRemoteOrigin != "" && entry.HostLabel == currentRemoteOrigin | |
| 112 | - | if localRoute || currentRemoteRoute { | |
| 110 | + | sameOrigin := (entry.Kind == ports.RouteKindLocal && currentRemoteOrigin == "") || | |
| 111 | + | (entry.Kind == ports.RouteKindRemote && currentRemoteOrigin != "" && entry.HostLabel == currentRemoteOrigin) | |
| 112 | + | if sameOrigin { | |
| 113 | 113 | continue | |
| 114 | 114 | } | |
| 115 | + | if entry.Kind == ports.RouteKindLocal && currentRemoteOrigin != "" { | |
| 116 | + | label = formatRecentRouteName(recentRoutePresentation{ | |
| 117 | + | name: entry.Name, | |
| 118 | + | kind: recentRouteLocal, | |
| 119 | + | ephemeral: entry.Ephemeral, | |
| 120 | + | }, true) | |
| 121 | + | } | |
| 115 | 122 | } | |
| 116 | 123 | results = append(results, palette.NewRecentRouteResult(label, ports.RouteNavigationAction{ | |
| 117 | 124 | SnapshotGeneration: routeSnapshot.Generation, | |
| @@ -107,11 +107,18 @@ func (d *Daemon) paletteResults(current *session, commands []command.Command, ro | |||||
| 107 | continue | 107 | continue | ||
| 108 | } | 108 | } | ||
| 109 | if _, represented := localNames[entry.Name]; represented { | 109 | if _, represented := localNames[entry.Name]; represented { | ||
| 110 | - | localRoute := entry.Kind == ports.RouteKindLocal | 110 | + | sameOrigin := (entry.Kind == ports.RouteKindLocal && currentRemoteOrigin == "") || |
| 111 | - | currentRemoteRoute := entry.Kind == ports.RouteKindRemote && currentRemoteOrigin != "" && entry.HostLabel == currentRemoteOrigin | 111 | + | (entry.Kind == ports.RouteKindRemote && currentRemoteOrigin != "" && entry.HostLabel == currentRemoteOrigin) |
| 112 | - | if localRoute || currentRemoteRoute { | 112 | + | if sameOrigin { |
| 113 | continue | 113 | continue | ||
| 114 | } | 114 | } | ||
| 115 | + | if entry.Kind == ports.RouteKindLocal && currentRemoteOrigin != "" { | |||
| 116 | + | label = formatRecentRouteName(recentRoutePresentation{ | |||
| 117 | + | name: entry.Name, | |||
| 118 | + | kind: recentRouteLocal, | |||
| 119 | + | ephemeral: entry.Ephemeral, | |||
| 120 | + | }, true) | |||
| 121 | + | } | |||
| 115 | } | 122 | } | ||
| 116 | results = append(results, palette.NewRecentRouteResult(label, ports.RouteNavigationAction{ | 123 | results = append(results, palette.NewRecentRouteResult(label, ports.RouteNavigationAction{ | ||
| 117 | SnapshotGeneration: routeSnapshot.Generation, | 124 | SnapshotGeneration: routeSnapshot.Generation, | ||
M internal/usecase/daemon/palette_test.go +7 -2
| @@ -438,13 +438,18 @@ func TestPaletteResultsDeduplicateRoutesLocalToCurrentRemoteDaemon(t *testing.T) | |||
| 438 | 438 | want []string | |
| 439 | 439 | }{ | |
| 440 | 440 | {name: "remote daemon", currentOrigin: "remote", want: []string{"Switch to session remote-manual"}}, | |
| 441 | + | {name: "remote daemon keeps distinct local route", currentOrigin: "remote", want: []string{"Switch to session remote-manual", "Switch to session remote-manual@local"}}, | |
| 441 | 442 | {name: "home daemon keeps distinct remote", want: []string{"Switch to session remote-manual", "Switch to session remote-manual@remote"}}, | |
| 442 | 443 | } { | |
| 443 | 444 | t.Run(test.name, func(t *testing.T) { | |
| 444 | - | results := d.paletteResults(current, nil, snapshot, test.currentOrigin) | |
| 445 | + | testSnapshot := snapshot | |
| 446 | + | if test.name == "remote daemon keeps distinct local route" { | |
| 447 | + | testSnapshot.Entries = append(testSnapshot.Entries, ports.RecentRouteEntry{Key: 3, Generation: 1, Name: "remote-manual", Kind: ports.RouteKindLocal}) | |
| 448 | + | } | |
| 449 | + | results := d.paletteResults(current, nil, testSnapshot, test.currentOrigin) | |
| 445 | 450 | var matching []string | |
| 446 | 451 | for _, result := range results { | |
| 447 | - | if result.DisplayText() == "Switch to session remote-manual" || result.DisplayText() == "Switch to session remote-manual@remote" { | |
| 452 | + | if result.DisplayText() == "Switch to session remote-manual" || result.DisplayText() == "Switch to session remote-manual@local" || result.DisplayText() == "Switch to session remote-manual@remote" { | |
| 448 | 453 | matching = append(matching, result.DisplayText()) | |
| 449 | 454 | } | |
| 450 | 455 | } | |
| @@ -438,13 +438,18 @@ func TestPaletteResultsDeduplicateRoutesLocalToCurrentRemoteDaemon(t *testing.T) | |||||
| 438 | want []string | 438 | want []string | ||
| 439 | }{ | 439 | }{ | ||
| 440 | {name: "remote daemon", currentOrigin: "remote", want: []string{"Switch to session remote-manual"}}, | 440 | {name: "remote daemon", currentOrigin: "remote", want: []string{"Switch to session remote-manual"}}, | ||
| 441 | + | {name: "remote daemon keeps distinct local route", currentOrigin: "remote", want: []string{"Switch to session remote-manual", "Switch to session remote-manual@local"}}, | |||
| 441 | {name: "home daemon keeps distinct remote", want: []string{"Switch to session remote-manual", "Switch to session remote-manual@remote"}}, | 442 | {name: "home daemon keeps distinct remote", want: []string{"Switch to session remote-manual", "Switch to session remote-manual@remote"}}, | ||
| 442 | } { | 443 | } { | ||
| 443 | t.Run(test.name, func(t *testing.T) { | 444 | t.Run(test.name, func(t *testing.T) { | ||
| 444 | - | results := d.paletteResults(current, nil, snapshot, test.currentOrigin) | 445 | + | testSnapshot := snapshot |
| 446 | + | if test.name == "remote daemon keeps distinct local route" { | |||
| 447 | + | testSnapshot.Entries = append(testSnapshot.Entries, ports.RecentRouteEntry{Key: 3, Generation: 1, Name: "remote-manual", Kind: ports.RouteKindLocal}) | |||
| 448 | + | } | |||
| 449 | + | results := d.paletteResults(current, nil, testSnapshot, test.currentOrigin) | |||
| 445 | var matching []string | 450 | var matching []string | ||
| 446 | for _, result := range results { | 451 | for _, result := range results { | ||
| 447 | - | if result.DisplayText() == "Switch to session remote-manual" || result.DisplayText() == "Switch to session remote-manual@remote" { | 452 | + | if result.DisplayText() == "Switch to session remote-manual" || result.DisplayText() == "Switch to session remote-manual@local" || result.DisplayText() == "Switch to session remote-manual@remote" { |
| 448 | matching = append(matching, result.DisplayText()) | 453 | matching = append(matching, result.DisplayText()) | ||
| 449 | } | 454 | } | ||
| 450 | } | 455 | } | ||