feat(status): show only this client's visited sessions in the recent history
- commit
- 4eaa45ddbe63e65974bbee95fbc4d2535016454a
- author
- brice · · 2026-09-23 19:46 UTC
- parent
- 80cdd12
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
17 files · +95 -18
M internal/adapters/sessionwire/proto_convert_navigation.go +2 -0
| @@ -72,6 +72,7 @@ func recentRouteEntryToWire(entry protocol.RecentRouteEntry) (*wire.RecentRouteE | |||
| 72 | 72 | Attention: entry.Attention, | |
| 73 | 73 | Reachability: uint32(entry.Reachability), | |
| 74 | 74 | AttentionSeq: entry.AttentionSeq, | |
| 75 | + | Visited: entry.Visited, | |
| 75 | 76 | }, nil | |
| 76 | 77 | } | |
| 77 | 78 | ||
| @@ -115,6 +116,7 @@ func recentRouteEntryFromWire(message *wire.RecentRouteEntry) (protocol.RecentRo | |||
| 115 | 116 | return protocol.RecentRouteEntry{}, err | |
| 116 | 117 | } | |
| 117 | 118 | entry.AttentionSeq = message.GetAttentionSeq() | |
| 119 | + | entry.Visited = message.GetVisited() | |
| 118 | 120 | return entry, nil | |
| 119 | 121 | } | |
| 120 | 122 | ||
| @@ -72,6 +72,7 @@ func recentRouteEntryToWire(entry protocol.RecentRouteEntry) (*wire.RecentRouteE | |||||
| 72 | Attention: entry.Attention, | 72 | Attention: entry.Attention, | ||
| 73 | Reachability: uint32(entry.Reachability), | 73 | Reachability: uint32(entry.Reachability), | ||
| 74 | AttentionSeq: entry.AttentionSeq, | 74 | AttentionSeq: entry.AttentionSeq, | ||
| 75 | + | Visited: entry.Visited, | |||
| 75 | }, nil | 76 | }, nil | ||
| 76 | } | 77 | } | ||
| 77 | 78 | ||||
| @@ -115,6 +116,7 @@ func recentRouteEntryFromWire(message *wire.RecentRouteEntry) (protocol.RecentRo | |||||
| 115 | return protocol.RecentRouteEntry{}, err | 116 | return protocol.RecentRouteEntry{}, err | ||
| 116 | } | 117 | } | ||
| 117 | entry.AttentionSeq = message.GetAttentionSeq() | 118 | entry.AttentionSeq = message.GetAttentionSeq() | ||
| 119 | + | entry.Visited = message.GetVisited() | |||
| 118 | return entry, nil | 120 | return entry, nil | ||
| 119 | } | 121 | } | ||
| 120 | 122 | ||||
M internal/ports/broker_acquisition_test.go +1 -1
| @@ -9,7 +9,7 @@ import ( | |||
| 9 | 9 | ) | |
| 10 | 10 | ||
| 11 | 11 | func acquisitionTestPolicy() BrokerPolicy { | |
| 12 | - | return BrokerPolicy{ProtocolVersion: 58, CatalogSchemaVersion: 3, EnvironmentPolicy: protocol.EnvironmentPolicyDaemonOwned, Transport: "quic", Trust: "openssh", Launch: "explicit", Isolation: "user"} | |
| 12 | + | return BrokerPolicy{ProtocolVersion: 59, CatalogSchemaVersion: 3, EnvironmentPolicy: protocol.EnvironmentPolicyDaemonOwned, Transport: "quic", Trust: "openssh", Launch: "explicit", Isolation: "user"} | |
| 13 | 13 | } | |
| 14 | 14 | ||
| 15 | 15 | func TestBrokerDialTargetFirstContactAndBoundValidation(t *testing.T) { | |
| @@ -9,7 +9,7 @@ import ( | |||||
| 9 | ) | 9 | ) | ||
| 10 | 10 | ||||
| 11 | func acquisitionTestPolicy() BrokerPolicy { | 11 | func acquisitionTestPolicy() BrokerPolicy { | ||
| 12 | - | return BrokerPolicy{ProtocolVersion: 58, CatalogSchemaVersion: 3, EnvironmentPolicy: protocol.EnvironmentPolicyDaemonOwned, Transport: "quic", Trust: "openssh", Launch: "explicit", Isolation: "user"} | 12 | + | return BrokerPolicy{ProtocolVersion: 59, CatalogSchemaVersion: 3, EnvironmentPolicy: protocol.EnvironmentPolicyDaemonOwned, Transport: "quic", Trust: "openssh", Launch: "explicit", Isolation: "user"} |
| 13 | } | 13 | } | ||
| 14 | 14 | ||||
| 15 | func TestBrokerDialTargetFirstContactAndBoundValidation(t *testing.T) { | 15 | func TestBrokerDialTargetFirstContactAndBoundValidation(t *testing.T) { | ||
M internal/protocol/routes.go +3 -0
| @@ -318,6 +318,9 @@ type RecentRouteEntry struct { | |||
| 318 | 318 | // AttentionSeq orders attention onsets across every daemon the client | |
| 319 | 319 | // observes: a smaller value is older. It is zero without attention. | |
| 320 | 320 | AttentionSeq uint64 | |
| 321 | + | // Visited reports that this client attached to the route. The status-bar | |
| 322 | + | // history and jump-recent ranks show only visited routes. | |
| 323 | + | Visited bool | |
| 321 | 324 | } | |
| 322 | 325 | ||
| 323 | 326 | // RouteHost is one daemon the client can create a session on, other than | |
| @@ -318,6 +318,9 @@ type RecentRouteEntry struct { | |||||
| 318 | // AttentionSeq orders attention onsets across every daemon the client | 318 | // AttentionSeq orders attention onsets across every daemon the client | ||
| 319 | // observes: a smaller value is older. It is zero without attention. | 319 | // observes: a smaller value is older. It is zero without attention. | ||
| 320 | AttentionSeq uint64 | 320 | AttentionSeq uint64 | ||
| 321 | + | // Visited reports that this client attached to the route. The status-bar | |||
| 322 | + | // history and jump-recent ranks show only visited routes. | |||
| 323 | + | Visited bool | |||
| 321 | } | 324 | } | ||
| 322 | 325 | ||||
| 323 | // RouteHost is one daemon the client can create a session on, other than | 326 | // RouteHost is one daemon the client can create a session on, other than | ||
M internal/protocol/session.go +1 -1
| @@ -16,7 +16,7 @@ import ( | |||
| 16 | 16 | // daemonmux physical preamble conversation (multiplex.proto), whose | |
| 17 | 17 | // negotiated ceilings and accepted daemon binding ride the same wire | |
| 18 | 18 | // version as the session and broker conversations. | |
| 19 | - | const Version uint16 = 58 | |
| 19 | + | const Version uint16 = 59 | |
| 20 | 20 | ||
| 21 | 21 | // HandshakeTimeout bounds every transport handshake from connect through the | |
| 22 | 22 | // first committed publication. It excludes the preceding client-local | |
| @@ -16,7 +16,7 @@ import ( | |||||
| 16 | // daemonmux physical preamble conversation (multiplex.proto), whose | 16 | // daemonmux physical preamble conversation (multiplex.proto), whose | ||
| 17 | // negotiated ceilings and accepted daemon binding ride the same wire | 17 | // negotiated ceilings and accepted daemon binding ride the same wire | ||
| 18 | // version as the session and broker conversations. | 18 | // version as the session and broker conversations. | ||
| 19 | - | const Version uint16 = 58 | 19 | + | const Version uint16 = 59 |
| 20 | 20 | ||||
| 21 | // HandshakeTimeout bounds every transport handshake from connect through the | 21 | // HandshakeTimeout bounds every transport handshake from connect through the | ||
| 22 | // first committed publication. It excludes the preceding client-local | 22 | // first committed publication. It excludes the preceding client-local | ||
M internal/protocol/session_test.go +1 -1
| @@ -10,7 +10,7 @@ import ( | |||
| 10 | 10 | ) | |
| 11 | 11 | ||
| 12 | 12 | func TestVersionRemainsWireCompatible(t *testing.T) { | |
| 13 | - | require.Equal(t, uint16(58), Version) | |
| 13 | + | require.Equal(t, uint16(59), Version) | |
| 14 | 14 | require.Equal(t, (16<<20)-407, MaxOutputDataLen) | |
| 15 | 15 | } | |
| 16 | 16 | ||
| @@ -10,7 +10,7 @@ import ( | |||||
| 10 | ) | 10 | ) | ||
| 11 | 11 | ||||
| 12 | func TestVersionRemainsWireCompatible(t *testing.T) { | 12 | func TestVersionRemainsWireCompatible(t *testing.T) { | ||
| 13 | - | require.Equal(t, uint16(58), Version) | 13 | + | require.Equal(t, uint16(59), Version) |
| 14 | require.Equal(t, (16<<20)-407, MaxOutputDataLen) | 14 | require.Equal(t, (16<<20)-407, MaxOutputDataLen) | ||
| 15 | } | 15 | } | ||
| 16 | 16 | ||||
M internal/protocol/wire/envelope_inventory_test.go +2 -2
| @@ -15,8 +15,8 @@ import ( | |||
| 15 | 15 | // shares a payload type except route navigation failure, and the preamble | |
| 16 | 16 | // constants agree with the schema authority. | |
| 17 | 17 | func TestEnvelopeInventoryProvesDirectionAndSemanticPath(t *testing.T) { | |
| 18 | - | if protocol.Version != 58 { | |
| 19 | - | t.Fatalf("protocol.Version = %d, want 58", protocol.Version) | |
| 18 | + | if protocol.Version != 59 { | |
| 19 | + | t.Fatalf("protocol.Version = %d, want 59", protocol.Version) | |
| 20 | 20 | } | |
| 21 | 21 | if ProtocolEpoch != 1 { | |
| 22 | 22 | t.Fatalf("ProtocolEpoch = %d, want 1", ProtocolEpoch) | |
| @@ -15,8 +15,8 @@ import ( | |||||
| 15 | // shares a payload type except route navigation failure, and the preamble | 15 | // shares a payload type except route navigation failure, and the preamble | ||
| 16 | // constants agree with the schema authority. | 16 | // constants agree with the schema authority. | ||
| 17 | func TestEnvelopeInventoryProvesDirectionAndSemanticPath(t *testing.T) { | 17 | func TestEnvelopeInventoryProvesDirectionAndSemanticPath(t *testing.T) { | ||
| 18 | - | if protocol.Version != 58 { | 18 | + | if protocol.Version != 59 { |
| 19 | - | t.Fatalf("protocol.Version = %d, want 58", protocol.Version) | 19 | + | t.Fatalf("protocol.Version = %d, want 59", protocol.Version) |
| 20 | } | 20 | } | ||
| 21 | if ProtocolEpoch != 1 { | 21 | if ProtocolEpoch != 1 { | ||
| 22 | t.Fatalf("ProtocolEpoch = %d, want 1", ProtocolEpoch) | 22 | t.Fatalf("ProtocolEpoch = %d, want 1", ProtocolEpoch) | ||
M internal/protocol/wire/schema/session.proto +3 -0
| @@ -162,6 +162,9 @@ message RecentRouteEntry { | |||
| 162 | 162 | uint32 reachability = 9; | |
| 163 | 163 | // Client-assigned attention onset order; zero without attention. | |
| 164 | 164 | uint64 attention_seq = 10; | |
| 165 | + | // True once this client attached to the route; the status-bar history | |
| 166 | + | // shows only visited routes. | |
| 167 | + | bool visited = 11; | |
| 165 | 168 | } | |
| 166 | 169 | ||
| 167 | 170 | // RouteHost is one creation destination other than the serving daemon. | |
| @@ -162,6 +162,9 @@ message RecentRouteEntry { | |||||
| 162 | uint32 reachability = 9; | 162 | uint32 reachability = 9; | ||
| 163 | // Client-assigned attention onset order; zero without attention. | 163 | // Client-assigned attention onset order; zero without attention. | ||
| 164 | uint64 attention_seq = 10; | 164 | uint64 attention_seq = 10; | ||
| 165 | + | // True once this client attached to the route; the status-bar history | |||
| 166 | + | // shows only visited routes. | |||
| 167 | + | bool visited = 11; | |||
| 165 | } | 168 | } | ||
| 166 | 169 | ||||
| 167 | // RouteHost is one creation destination other than the serving daemon. | 170 | // RouteHost is one creation destination other than the serving daemon. | ||
M internal/protocol/wire/session.pb.go +14 -3 generated file: collapsed
M internal/usecase/client/route_ledger.go +2 -0
| @@ -201,6 +201,7 @@ func (l *routeLedger) build(snapshot ports.BrokerSnapshot, active routeActive) ( | |||
| 201 | 201 | entry := routeActiveEntry(candidates, activeID, active, activeObservation) | |
| 202 | 202 | entry.Key, entry.Generation = l.keyFor(activeID), 1 | |
| 203 | 203 | entry.AttentionSeq = l.attention[activeID] | |
| 204 | + | entry.Visited = true | |
| 204 | 205 | if validateRouteEntryShape(entry) == nil { | |
| 205 | 206 | next.ActiveEntry = entry | |
| 206 | 207 | next.Active = protocol.RouteRef{Key: entry.Key, Generation: entry.Generation} | |
| @@ -220,6 +221,7 @@ func (l *routeLedger) build(snapshot ports.BrokerSnapshot, active routeActive) ( | |||
| 220 | 221 | entry := candidate.entry | |
| 221 | 222 | entry.Key, entry.Generation = l.keyFor(candidate.id), 1 | |
| 222 | 223 | entry.AttentionSeq = l.attention[candidate.id] | |
| 224 | + | entry.Visited = l.attached[candidate.id] != 0 | |
| 223 | 225 | ref := protocol.RouteRef{Key: entry.Key, Generation: entry.Generation} | |
| 224 | 226 | if next.Previous.IsZero() && l.attached[candidate.id] != 0 { | |
| 225 | 227 | next.Previous = ref | |
| @@ -201,6 +201,7 @@ func (l *routeLedger) build(snapshot ports.BrokerSnapshot, active routeActive) ( | |||||
| 201 | entry := routeActiveEntry(candidates, activeID, active, activeObservation) | 201 | entry := routeActiveEntry(candidates, activeID, active, activeObservation) | ||
| 202 | entry.Key, entry.Generation = l.keyFor(activeID), 1 | 202 | entry.Key, entry.Generation = l.keyFor(activeID), 1 | ||
| 203 | entry.AttentionSeq = l.attention[activeID] | 203 | entry.AttentionSeq = l.attention[activeID] | ||
| 204 | + | entry.Visited = true | |||
| 204 | if validateRouteEntryShape(entry) == nil { | 205 | if validateRouteEntryShape(entry) == nil { | ||
| 205 | next.ActiveEntry = entry | 206 | next.ActiveEntry = entry | ||
| 206 | next.Active = protocol.RouteRef{Key: entry.Key, Generation: entry.Generation} | 207 | next.Active = protocol.RouteRef{Key: entry.Key, Generation: entry.Generation} | ||
| @@ -220,6 +221,7 @@ func (l *routeLedger) build(snapshot ports.BrokerSnapshot, active routeActive) ( | |||||
| 220 | entry := candidate.entry | 221 | entry := candidate.entry | ||
| 221 | entry.Key, entry.Generation = l.keyFor(candidate.id), 1 | 222 | entry.Key, entry.Generation = l.keyFor(candidate.id), 1 | ||
| 222 | entry.AttentionSeq = l.attention[candidate.id] | 223 | entry.AttentionSeq = l.attention[candidate.id] | ||
| 224 | + | entry.Visited = l.attached[candidate.id] != 0 | |||
| 223 | ref := protocol.RouteRef{Key: entry.Key, Generation: entry.Generation} | 225 | ref := protocol.RouteRef{Key: entry.Key, Generation: entry.Generation} | ||
| 224 | if next.Previous.IsZero() && l.attached[candidate.id] != 0 { | 226 | if next.Previous.IsZero() && l.attached[candidate.id] != 0 { | ||
| 225 | next.Previous = ref | 227 | next.Previous = ref | ||
M internal/usecase/client/route_ledger_test.go +8 -0
| @@ -147,6 +147,14 @@ func TestRouteLedgerActivePreviousAndHome(t *testing.T) { | |||
| 147 | 147 | previous, ok := ledger.resolve(snapshot.Previous) | |
| 148 | 148 | require.True(t, ok) | |
| 149 | 149 | require.Equal(t, tt.wantPrevious, previous.target.SessionName) | |
| 150 | + | require.True(t, snapshot.ActiveEntry.Visited) | |
| 151 | + | var visited []string | |
| 152 | + | for _, entry := range snapshot.Entries { | |
| 153 | + | if entry.Visited { | |
| 154 | + | visited = append(visited, entry.Name) | |
| 155 | + | } | |
| 156 | + | } | |
| 157 | + | require.Equal(t, []string{tt.wantPrevious}, visited, "only attached routes are visited") | |
| 150 | 158 | kinds := make([]protocol.RouteKind, 0, len(snapshot.Hosts)) | |
| 151 | 159 | for _, host := range snapshot.Hosts { | |
| 152 | 160 | kinds = append(kinds, host.Kind) | |
| @@ -147,6 +147,14 @@ func TestRouteLedgerActivePreviousAndHome(t *testing.T) { | |||||
| 147 | previous, ok := ledger.resolve(snapshot.Previous) | 147 | previous, ok := ledger.resolve(snapshot.Previous) | ||
| 148 | require.True(t, ok) | 148 | require.True(t, ok) | ||
| 149 | require.Equal(t, tt.wantPrevious, previous.target.SessionName) | 149 | require.Equal(t, tt.wantPrevious, previous.target.SessionName) | ||
| 150 | + | require.True(t, snapshot.ActiveEntry.Visited) | |||
| 151 | + | var visited []string | |||
| 152 | + | for _, entry := range snapshot.Entries { | |||
| 153 | + | if entry.Visited { | |||
| 154 | + | visited = append(visited, entry.Name) | |||
| 155 | + | } | |||
| 156 | + | } | |||
| 157 | + | require.Equal(t, []string{tt.wantPrevious}, visited, "only attached routes are visited") | |||
| 150 | kinds := make([]protocol.RouteKind, 0, len(snapshot.Hosts)) | 158 | kinds := make([]protocol.RouteKind, 0, len(snapshot.Hosts)) | ||
| 151 | for _, host := range snapshot.Hosts { | 159 | for _, host := range snapshot.Hosts { | ||
| 152 | kinds = append(kinds, host.Kind) | 160 | kinds = append(kinds, host.Kind) | ||
M internal/usecase/daemon/palette.go +4 -2
| @@ -282,6 +282,7 @@ func (d *Daemon) refreshPalette(ac *attachedClient) { | |||
| 282 | 282 | } | |
| 283 | 283 | ||
| 284 | 284 | func recentRouteHints(snapshot protocol.RecentRouteSnapshot, args []string) palette.ContextualHints { | |
| 285 | + | snapshot = visitedRouteSnapshot(snapshot) | |
| 285 | 286 | formatted := formatRecentRouteSnapshot(snapshot) | |
| 286 | 287 | names := make([]string, len(formatted)) | |
| 287 | 288 | for i, entry := range formatted { | |
| @@ -1123,10 +1124,11 @@ func (e paletteExec) YankLastNotification() error { | |||
| 1123 | 1124 | } | |
| 1124 | 1125 | ||
| 1125 | 1126 | func (e paletteExec) JumpRecentSession(rank int) error { | |
| 1126 | - | if e.routeSnapshot.Generation == 0 || rank < 1 || rank > len(e.routeSnapshot.Entries) { | |
| 1127 | + | visited := visitedRouteSnapshot(e.routeSnapshot) | |
| 1128 | + | if visited.Generation == 0 || rank < 1 || rank > len(visited.Entries) { | |
| 1127 | 1129 | return command.ErrInvalidArguments | |
| 1128 | 1130 | } | |
| 1129 | - | entry := e.routeSnapshot.Entries[rank-1] | |
| 1131 | + | entry := visited.Entries[rank-1] | |
| 1130 | 1132 | return e.NavigateRecentRoute(protocol.RouteNavigationAction{ | |
| 1131 | 1133 | SnapshotGeneration: e.routeSnapshot.Generation, | |
| 1132 | 1134 | Key: entry.Key, | |
| @@ -282,6 +282,7 @@ func (d *Daemon) refreshPalette(ac *attachedClient) { | |||||
| 282 | } | 282 | } | ||
| 283 | 283 | ||||
| 284 | func recentRouteHints(snapshot protocol.RecentRouteSnapshot, args []string) palette.ContextualHints { | 284 | func recentRouteHints(snapshot protocol.RecentRouteSnapshot, args []string) palette.ContextualHints { | ||
| 285 | + | snapshot = visitedRouteSnapshot(snapshot) | |||
| 285 | formatted := formatRecentRouteSnapshot(snapshot) | 286 | formatted := formatRecentRouteSnapshot(snapshot) | ||
| 286 | names := make([]string, len(formatted)) | 287 | names := make([]string, len(formatted)) | ||
| 287 | for i, entry := range formatted { | 288 | for i, entry := range formatted { | ||
| @@ -1123,10 +1124,11 @@ func (e paletteExec) YankLastNotification() error { | |||||
| 1123 | } | 1124 | } | ||
| 1124 | 1125 | ||||
| 1125 | func (e paletteExec) JumpRecentSession(rank int) error { | 1126 | func (e paletteExec) JumpRecentSession(rank int) error { | ||
| 1126 | - | if e.routeSnapshot.Generation == 0 || rank < 1 || rank > len(e.routeSnapshot.Entries) { | 1127 | + | visited := visitedRouteSnapshot(e.routeSnapshot) |
| 1128 | + | if visited.Generation == 0 || rank < 1 || rank > len(visited.Entries) { | |||
| 1127 | return command.ErrInvalidArguments | 1129 | return command.ErrInvalidArguments | ||
| 1128 | } | 1130 | } | ||
| 1129 | - | entry := e.routeSnapshot.Entries[rank-1] | 1131 | + | entry := visited.Entries[rank-1] |
| 1130 | return e.NavigateRecentRoute(protocol.RouteNavigationAction{ | 1132 | return e.NavigateRecentRoute(protocol.RouteNavigationAction{ | ||
| 1131 | SnapshotGeneration: e.routeSnapshot.Generation, | 1133 | SnapshotGeneration: e.routeSnapshot.Generation, | ||
| 1132 | Key: entry.Key, | 1134 | Key: entry.Key, | ||
M internal/usecase/daemon/recent_route_presentation_test.go +1 -1
| @@ -90,7 +90,7 @@ func TestRecentSessionHintsAndRankedRenderingShareCanonicalLabels(t *testing.T) | |||
| 90 | 90 | snapshot := protocol.RecentRouteSnapshot{ | |
| 91 | 91 | Generation: 1, | |
| 92 | 92 | Entries: []protocol.RecentRouteEntry{ | |
| 93 | - | {Key: 1, Generation: 1, Target: testRouteTarget("logs", 1), Name: "logs", Kind: protocol.RouteKindLocal, Attention: true}, | |
| 93 | + | {Key: 1, Generation: 1, Target: testRouteTarget("logs", 1), Name: "logs", Kind: protocol.RouteKindLocal, Attention: true, Visited: true}, | |
| 94 | 94 | testRouteEntry(2, 1, "logs", 2, protocol.RouteKindLocal), | |
| 95 | 95 | }, | |
| 96 | 96 | } | |
| @@ -90,7 +90,7 @@ func TestRecentSessionHintsAndRankedRenderingShareCanonicalLabels(t *testing.T) | |||||
| 90 | snapshot := protocol.RecentRouteSnapshot{ | 90 | snapshot := protocol.RecentRouteSnapshot{ | ||
| 91 | Generation: 1, | 91 | Generation: 1, | ||
| 92 | Entries: []protocol.RecentRouteEntry{ | 92 | Entries: []protocol.RecentRouteEntry{ | ||
| 93 | - | {Key: 1, Generation: 1, Target: testRouteTarget("logs", 1), Name: "logs", Kind: protocol.RouteKindLocal, Attention: true}, | 93 | + | {Key: 1, Generation: 1, Target: testRouteTarget("logs", 1), Name: "logs", Kind: protocol.RouteKindLocal, Attention: true, Visited: true}, |
| 94 | testRouteEntry(2, 1, "logs", 2, protocol.RouteKindLocal), | 94 | testRouteEntry(2, 1, "logs", 2, protocol.RouteKindLocal), | ||
| 95 | }, | 95 | }, | ||
| 96 | } | 96 | } | ||
M internal/usecase/daemon/recent_route_snapshot.go +18 -0
| @@ -35,6 +35,24 @@ func recentRoutePresentationsFromSnapshot(snapshot protocol.RecentRouteSnapshot) | |||
| 35 | 35 | return out | |
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | + | // visitedRouteSnapshot keeps only the routes this client attached to. The | |
| 39 | + | // status-bar history and jump-recent ranks start from the current session and | |
| 40 | + | // grow as the client visits others; the palette and attention keep the full | |
| 41 | + | // snapshot. | |
| 42 | + | func visitedRouteSnapshot(snapshot protocol.RecentRouteSnapshot) protocol.RecentRouteSnapshot { | |
| 43 | + | if snapshot.Entries == nil { | |
| 44 | + | return snapshot | |
| 45 | + | } | |
| 46 | + | visited := make([]protocol.RecentRouteEntry, 0, len(snapshot.Entries)) | |
| 47 | + | for _, entry := range snapshot.Entries { | |
| 48 | + | if entry.Visited { | |
| 49 | + | visited = append(visited, entry) | |
| 50 | + | } | |
| 51 | + | } | |
| 52 | + | snapshot.Entries = visited | |
| 53 | + | return snapshot | |
| 54 | + | } | |
| 55 | + | ||
| 38 | 56 | func formatRecentRouteSnapshot(snapshot protocol.RecentRouteSnapshot) []recentRouteDisplay { | |
| 39 | 57 | return formatRecentRoutePresentations(recentRoutePresentationsFromSnapshot(snapshot)) | |
| 40 | 58 | } | |
| @@ -35,6 +35,24 @@ func recentRoutePresentationsFromSnapshot(snapshot protocol.RecentRouteSnapshot) | |||||
| 35 | return out | 35 | return out | ||
| 36 | } | 36 | } | ||
| 37 | 37 | ||||
| 38 | + | // visitedRouteSnapshot keeps only the routes this client attached to. The | |||
| 39 | + | // status-bar history and jump-recent ranks start from the current session and | |||
| 40 | + | // grow as the client visits others; the palette and attention keep the full | |||
| 41 | + | // snapshot. | |||
| 42 | + | func visitedRouteSnapshot(snapshot protocol.RecentRouteSnapshot) protocol.RecentRouteSnapshot { | |||
| 43 | + | if snapshot.Entries == nil { | |||
| 44 | + | return snapshot | |||
| 45 | + | } | |||
| 46 | + | visited := make([]protocol.RecentRouteEntry, 0, len(snapshot.Entries)) | |||
| 47 | + | for _, entry := range snapshot.Entries { | |||
| 48 | + | if entry.Visited { | |||
| 49 | + | visited = append(visited, entry) | |||
| 50 | + | } | |||
| 51 | + | } | |||
| 52 | + | snapshot.Entries = visited | |||
| 53 | + | return snapshot | |||
| 54 | + | } | |||
| 55 | + | ||||
| 38 | func formatRecentRouteSnapshot(snapshot protocol.RecentRouteSnapshot) []recentRouteDisplay { | 56 | func formatRecentRouteSnapshot(snapshot protocol.RecentRouteSnapshot) []recentRouteDisplay { | ||
| 39 | return formatRecentRoutePresentations(recentRoutePresentationsFromSnapshot(snapshot)) | 57 | return formatRecentRoutePresentations(recentRoutePresentationsFromSnapshot(snapshot)) | ||
| 40 | } | 58 | } | ||
M internal/usecase/daemon/recent_route_snapshot_test.go +31 -3
| @@ -13,7 +13,7 @@ func TestAttachmentStatusUsesClientRouteSnapshot(t *testing.T) { | |||
| 13 | 13 | Generation: 2, | |
| 14 | 14 | Active: protocol.RouteRef{Key: 3, Generation: 2}, | |
| 15 | 15 | Entries: []protocol.RecentRouteEntry{ | |
| 16 | - | {Key: 2, Generation: 1, Target: testRouteTarget("logs", 2), Name: "logs", HostLabel: "user@edge", Kind: protocol.RouteKindRemote}, | |
| 16 | + | {Key: 2, Generation: 1, Target: testRouteTarget("logs", 2), Name: "logs", HostLabel: "user@edge", Kind: protocol.RouteKindRemote, Visited: true}, | |
| 17 | 17 | testRouteEntry(1, 1, "work", 1, protocol.RouteKindLocal), | |
| 18 | 18 | }, | |
| 19 | 19 | }) | |
| @@ -30,7 +30,7 @@ func TestAttachmentStatusUsesClientPublishedAttention(t *testing.T) { | |||
| 30 | 30 | Generation: 2, | |
| 31 | 31 | Active: protocol.RouteRef{Key: 3, Generation: 2}, | |
| 32 | 32 | Entries: []protocol.RecentRouteEntry{{ | |
| 33 | - | Key: 2, Generation: 1, Target: testRouteTarget("local", 9), Name: "local", Kind: protocol.RouteKindLocal, Attention: true, | |
| 33 | + | Key: 2, Generation: 1, Target: testRouteTarget("local", 9), Name: "local", Kind: protocol.RouteKindLocal, Attention: true, Visited: true, | |
| 34 | 34 | }}, | |
| 35 | 35 | }) | |
| 36 | 36 | ||
| @@ -104,7 +104,7 @@ func TestRecentRouteHintsRetainSnapshotSelectionIdentity(t *testing.T) { | |||
| 104 | 104 | snapshot := protocol.RecentRouteSnapshot{ | |
| 105 | 105 | Generation: 8, | |
| 106 | 106 | Entries: []protocol.RecentRouteEntry{{ | |
| 107 | - | Key: 11, Generation: 7, Target: testRouteTarget("logs", 11), Name: "logs", HostLabel: "edge", Kind: protocol.RouteKindRemote, | |
| 107 | + | Key: 11, Generation: 7, Target: testRouteTarget("logs", 11), Name: "logs", HostLabel: "edge", Kind: protocol.RouteKindRemote, Visited: true, | |
| 108 | 108 | }}, | |
| 109 | 109 | } | |
| 110 | 110 | ||
| @@ -116,3 +116,31 @@ func TestRecentRouteHintsRetainSnapshotSelectionIdentity(t *testing.T) { | |||
| 116 | 116 | require.Equal(t, uint64(11), hints.Recent[0].Key) | |
| 117 | 117 | require.Equal(t, uint64(7), hints.Recent[0].Generation) | |
| 118 | 118 | } | |
| 119 | + | ||
| 120 | + | func TestStatusHistoryShowsOnlyVisitedRoutes(t *testing.T) { | |
| 121 | + | unvisited := testRouteEntry(4, 1, "other", 4, protocol.RouteKindLocal) | |
| 122 | + | unvisited.Visited = false | |
| 123 | + | tests := []struct { | |
| 124 | + | name string | |
| 125 | + | entries []protocol.RecentRouteEntry | |
| 126 | + | want []string | |
| 127 | + | }{ | |
| 128 | + | {name: "fresh client shows no history", entries: []protocol.RecentRouteEntry{unvisited}, want: nil}, | |
| 129 | + | {name: "visited routes keep their order", entries: []protocol.RecentRouteEntry{testRouteEntry(2, 1, "work", 2, protocol.RouteKindLocal), unvisited, testRouteEntry(3, 1, "logs", 3, protocol.RouteKindLocal)}, want: []string{"work", "logs"}}, | |
| 130 | + | } | |
| 131 | + | for _, tt := range tests { | |
| 132 | + | t.Run(tt.name, func(t *testing.T) { | |
| 133 | + | d, sess, ac, _ := newManualSessionWithPTYs(t, nil) | |
| 134 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 2, Entries: tt.entries}) | |
| 135 | + | ||
| 136 | + | state := d.barStateForAttachmentPaletteHintsFor(sess, ac, "", nil, protocol.RecentRouteSnapshot{}) | |
| 137 | + | ||
| 138 | + | var names []string | |
| 139 | + | for _, entry := range state.mru { | |
| 140 | + | names = append(names, entry.name) | |
| 141 | + | } | |
| 142 | + | require.Equal(t, tt.want, names) | |
| 143 | + | require.Equal(t, len(tt.want), len(recentRouteHints(ac.routeSnapshotCopy(), nil).Recent)) | |
| 144 | + | }) | |
| 145 | + | } | |
| 146 | + | } | |
| @@ -13,7 +13,7 @@ func TestAttachmentStatusUsesClientRouteSnapshot(t *testing.T) { | |||||
| 13 | Generation: 2, | 13 | Generation: 2, | ||
| 14 | Active: protocol.RouteRef{Key: 3, Generation: 2}, | 14 | Active: protocol.RouteRef{Key: 3, Generation: 2}, | ||
| 15 | Entries: []protocol.RecentRouteEntry{ | 15 | Entries: []protocol.RecentRouteEntry{ | ||
| 16 | - | {Key: 2, Generation: 1, Target: testRouteTarget("logs", 2), Name: "logs", HostLabel: "user@edge", Kind: protocol.RouteKindRemote}, | 16 | + | {Key: 2, Generation: 1, Target: testRouteTarget("logs", 2), Name: "logs", HostLabel: "user@edge", Kind: protocol.RouteKindRemote, Visited: true}, |
| 17 | testRouteEntry(1, 1, "work", 1, protocol.RouteKindLocal), | 17 | testRouteEntry(1, 1, "work", 1, protocol.RouteKindLocal), | ||
| 18 | }, | 18 | }, | ||
| 19 | }) | 19 | }) | ||
| @@ -30,7 +30,7 @@ func TestAttachmentStatusUsesClientPublishedAttention(t *testing.T) { | |||||
| 30 | Generation: 2, | 30 | Generation: 2, | ||
| 31 | Active: protocol.RouteRef{Key: 3, Generation: 2}, | 31 | Active: protocol.RouteRef{Key: 3, Generation: 2}, | ||
| 32 | Entries: []protocol.RecentRouteEntry{{ | 32 | Entries: []protocol.RecentRouteEntry{{ | ||
| 33 | - | Key: 2, Generation: 1, Target: testRouteTarget("local", 9), Name: "local", Kind: protocol.RouteKindLocal, Attention: true, | 33 | + | Key: 2, Generation: 1, Target: testRouteTarget("local", 9), Name: "local", Kind: protocol.RouteKindLocal, Attention: true, Visited: true, |
| 34 | }}, | 34 | }}, | ||
| 35 | }) | 35 | }) | ||
| 36 | 36 | ||||
| @@ -104,7 +104,7 @@ func TestRecentRouteHintsRetainSnapshotSelectionIdentity(t *testing.T) { | |||||
| 104 | snapshot := protocol.RecentRouteSnapshot{ | 104 | snapshot := protocol.RecentRouteSnapshot{ | ||
| 105 | Generation: 8, | 105 | Generation: 8, | ||
| 106 | Entries: []protocol.RecentRouteEntry{{ | 106 | Entries: []protocol.RecentRouteEntry{{ | ||
| 107 | - | Key: 11, Generation: 7, Target: testRouteTarget("logs", 11), Name: "logs", HostLabel: "edge", Kind: protocol.RouteKindRemote, | 107 | + | Key: 11, Generation: 7, Target: testRouteTarget("logs", 11), Name: "logs", HostLabel: "edge", Kind: protocol.RouteKindRemote, Visited: true, |
| 108 | }}, | 108 | }}, | ||
| 109 | } | 109 | } | ||
| 110 | 110 | ||||
| @@ -116,3 +116,31 @@ func TestRecentRouteHintsRetainSnapshotSelectionIdentity(t *testing.T) { | |||||
| 116 | require.Equal(t, uint64(11), hints.Recent[0].Key) | 116 | require.Equal(t, uint64(11), hints.Recent[0].Key) | ||
| 117 | require.Equal(t, uint64(7), hints.Recent[0].Generation) | 117 | require.Equal(t, uint64(7), hints.Recent[0].Generation) | ||
| 118 | } | 118 | } | ||
| 119 | + | ||||
| 120 | + | func TestStatusHistoryShowsOnlyVisitedRoutes(t *testing.T) { | |||
| 121 | + | unvisited := testRouteEntry(4, 1, "other", 4, protocol.RouteKindLocal) | |||
| 122 | + | unvisited.Visited = false | |||
| 123 | + | tests := []struct { | |||
| 124 | + | name string | |||
| 125 | + | entries []protocol.RecentRouteEntry | |||
| 126 | + | want []string | |||
| 127 | + | }{ | |||
| 128 | + | {name: "fresh client shows no history", entries: []protocol.RecentRouteEntry{unvisited}, want: nil}, | |||
| 129 | + | {name: "visited routes keep their order", entries: []protocol.RecentRouteEntry{testRouteEntry(2, 1, "work", 2, protocol.RouteKindLocal), unvisited, testRouteEntry(3, 1, "logs", 3, protocol.RouteKindLocal)}, want: []string{"work", "logs"}}, | |||
| 130 | + | } | |||
| 131 | + | for _, tt := range tests { | |||
| 132 | + | t.Run(tt.name, func(t *testing.T) { | |||
| 133 | + | d, sess, ac, _ := newManualSessionWithPTYs(t, nil) | |||
| 134 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 2, Entries: tt.entries}) | |||
| 135 | + | ||||
| 136 | + | state := d.barStateForAttachmentPaletteHintsFor(sess, ac, "", nil, protocol.RecentRouteSnapshot{}) | |||
| 137 | + | ||||
| 138 | + | var names []string | |||
| 139 | + | for _, entry := range state.mru { | |||
| 140 | + | names = append(names, entry.name) | |||
| 141 | + | } | |||
| 142 | + | require.Equal(t, tt.want, names) | |||
| 143 | + | require.Equal(t, len(tt.want), len(recentRouteHints(ac.routeSnapshotCopy(), nil).Recent)) | |||
| 144 | + | }) | |||
| 145 | + | } | |||
| 146 | + | } | |||
M internal/usecase/daemon/route_identity_test_helpers_test.go +1 -1
| @@ -12,6 +12,6 @@ func testRouteTarget(name string, marker byte) protocol.ExactSessionTarget { | |||
| 12 | 12 | func testRouteEntry(key, generation uint64, name string, marker byte, kind protocol.RouteKind) protocol.RecentRouteEntry { | |
| 13 | 13 | return protocol.RecentRouteEntry{ | |
| 14 | 14 | Key: key, Generation: generation, Target: testRouteTarget(name, marker), | |
| 15 | - | Name: name, Kind: kind, | |
| 15 | + | Name: name, Kind: kind, Visited: true, | |
| 16 | 16 | } | |
| 17 | 17 | } | |
| @@ -12,6 +12,6 @@ func testRouteTarget(name string, marker byte) protocol.ExactSessionTarget { | |||||
| 12 | func testRouteEntry(key, generation uint64, name string, marker byte, kind protocol.RouteKind) protocol.RecentRouteEntry { | 12 | func testRouteEntry(key, generation uint64, name string, marker byte, kind protocol.RouteKind) protocol.RecentRouteEntry { | ||
| 13 | return protocol.RecentRouteEntry{ | 13 | return protocol.RecentRouteEntry{ | ||
| 14 | Key: key, Generation: generation, Target: testRouteTarget(name, marker), | 14 | Key: key, Generation: generation, Target: testRouteTarget(name, marker), | ||
| 15 | - | Name: name, Kind: kind, | 15 | + | Name: name, Kind: kind, Visited: true, |
| 16 | } | 16 | } | ||
| 17 | } | 17 | } | ||
M internal/usecase/daemon/status.go +2 -2
| @@ -237,7 +237,7 @@ func rankedRecentForHintsWithSnapshot(hints *palette.ContextualHints, snapshot p | |||
| 237 | 237 | } | |
| 238 | 238 | var formatted []recentRouteDisplay | |
| 239 | 239 | if snapshot.Generation != 0 { | |
| 240 | - | formatted = formatRecentRouteSnapshot(snapshot) | |
| 240 | + | formatted = formatRecentRouteSnapshot(visitedRouteSnapshot(snapshot)) | |
| 241 | 241 | } | |
| 242 | 242 | entries := make([]rankedRecent, 0, len(hints.Recent)) | |
| 243 | 243 | for i, hint := range hints.Recent { | |
| @@ -296,7 +296,7 @@ func (d *Daemon) barStateForAttachmentPaletteHintsFor(cur *session, ac *attached | |||
| 296 | 296 | if ranked != nil { | |
| 297 | 297 | state.rankedRecent = ranked | |
| 298 | 298 | } else if routeSnapshot.Generation != 0 { | |
| 299 | - | state.mru = formatRecentRouteSnapshot(routeSnapshot) | |
| 299 | + | state.mru = formatRecentRouteSnapshot(visitedRouteSnapshot(routeSnapshot)) | |
| 300 | 300 | } | |
| 301 | 301 | return state | |
| 302 | 302 | } | |
| @@ -237,7 +237,7 @@ func rankedRecentForHintsWithSnapshot(hints *palette.ContextualHints, snapshot p | |||||
| 237 | } | 237 | } | ||
| 238 | var formatted []recentRouteDisplay | 238 | var formatted []recentRouteDisplay | ||
| 239 | if snapshot.Generation != 0 { | 239 | if snapshot.Generation != 0 { | ||
| 240 | - | formatted = formatRecentRouteSnapshot(snapshot) | 240 | + | formatted = formatRecentRouteSnapshot(visitedRouteSnapshot(snapshot)) |
| 241 | } | 241 | } | ||
| 242 | entries := make([]rankedRecent, 0, len(hints.Recent)) | 242 | entries := make([]rankedRecent, 0, len(hints.Recent)) | ||
| 243 | for i, hint := range hints.Recent { | 243 | for i, hint := range hints.Recent { | ||
| @@ -296,7 +296,7 @@ func (d *Daemon) barStateForAttachmentPaletteHintsFor(cur *session, ac *attached | |||||
| 296 | if ranked != nil { | 296 | if ranked != nil { | ||
| 297 | state.rankedRecent = ranked | 297 | state.rankedRecent = ranked | ||
| 298 | } else if routeSnapshot.Generation != 0 { | 298 | } else if routeSnapshot.Generation != 0 { | ||
| 299 | - | state.mru = formatRecentRouteSnapshot(routeSnapshot) | 299 | + | state.mru = formatRecentRouteSnapshot(visitedRouteSnapshot(routeSnapshot)) |
| 300 | } | 300 | } | ||
| 301 | return state | 301 | return state | ||
| 302 | } | 302 | } | ||
M internal/usecase/daemon/status_test.go +1 -1
| @@ -990,7 +990,7 @@ func TestBarStateForContextualRecentUsesClientSnapshot(t *testing.T) { | |||
| 990 | 990 | ||
| 991 | 991 | snapshot := protocol.RecentRouteSnapshot{ | |
| 992 | 992 | Generation: 1, | |
| 993 | - | Entries: []protocol.RecentRouteEntry{{Key: 2, Generation: 1, Target: testRouteTarget("captured", 2), Name: "captured", Kind: protocol.RouteKindLocal, Attention: true}}, | |
| 993 | + | Entries: []protocol.RecentRouteEntry{{Key: 2, Generation: 1, Target: testRouteTarget("captured", 2), Name: "captured", Kind: protocol.RouteKindLocal, Attention: true, Visited: true}}, | |
| 994 | 994 | } | |
| 995 | 995 | hints := palette.ContextualHints{ | |
| 996 | 996 | Kind: command.ContextHintRecentSessions, | |
| @@ -990,7 +990,7 @@ func TestBarStateForContextualRecentUsesClientSnapshot(t *testing.T) { | |||||
| 990 | 990 | ||||
| 991 | snapshot := protocol.RecentRouteSnapshot{ | 991 | snapshot := protocol.RecentRouteSnapshot{ | ||
| 992 | Generation: 1, | 992 | Generation: 1, | ||
| 993 | - | Entries: []protocol.RecentRouteEntry{{Key: 2, Generation: 1, Target: testRouteTarget("captured", 2), Name: "captured", Kind: protocol.RouteKindLocal, Attention: true}}, | 993 | + | Entries: []protocol.RecentRouteEntry{{Key: 2, Generation: 1, Target: testRouteTarget("captured", 2), Name: "captured", Kind: protocol.RouteKindLocal, Attention: true, Visited: true}}, |
| 994 | } | 994 | } | ||
| 995 | hints := palette.ContextualHints{ | 995 | hints := palette.ContextualHints{ | ||
| 996 | Kind: command.ContextHintRecentSessions, | 996 | Kind: command.ContextHintRecentSessions, | ||