1package daemon
2
3import (
4 "testing"
5
6 "github.com/stretchr/testify/require"
7
8 "github.com/bnema/vev/internal/domain"
9)
10
11func TestRemoteStoppedSelectorsResolveOnlyAgainstExactTabMetadata(t *testing.T) {
12 lifecycle := remoteLifecycleForTest()
13 stopped := stoppedSession{
14 name: "work", incarnation: lifecycle,
15 tabNames: []string{"alpha", "beta"},
16 tabRecords: []domain.CatalogueTabRecord{
17 {StableID: "tab-a", Name: "alpha"},
18 {StableID: "tab-b", Name: "beta"},
19 },
20 }
21
22 stable := domain.RemoteSessionTarget{
23 Endpoint: "arch", DisplayOrigin: "arch", LifecycleID: lifecycle,
24 SessionName: "work", Stopped: true,
25 StoppedTab: domain.NewStableTabSelector("tab-b"),
26 }
27 index, ok := remoteTargetTabIndexStopped(stopped, stable)
28 require.True(t, ok)
29 require.Equal(t, 1, index)
30
31 ordinal := stable
32 ordinal.StoppedTab = domain.NewOrdinalTabSelector(1, "beta", 2)
33 index, ok = remoteTargetTabIndexStopped(stopped, ordinal)
34 require.True(t, ok)
35 require.Equal(t, 1, index)
36
37 for _, invalid := range []domain.RemoteSessionTarget{
38 func() domain.RemoteSessionTarget {
39 candidate := stable
40 candidate.StoppedTab = domain.NewStableTabSelector("missing")
41 return candidate
42 }(),
43 func() domain.RemoteSessionTarget {
44 candidate := ordinal
45 candidate.StoppedTab = domain.NewOrdinalTabSelector(1, "replaced", 2)
46 return candidate
47 }(),
48 func() domain.RemoteSessionTarget {
49 candidate := ordinal
50 candidate.StoppedTab = domain.NewOrdinalTabSelector(1, "beta", 3)
51 return candidate
52 }(),
53 } {
54 _, ok := remoteTargetTabIndexStopped(stopped, invalid)
55 require.False(t, ok)
56 }
57
58 reordered := stopped
59 reordered.tabRecords = []domain.CatalogueTabRecord{
60 {StableID: "tab-b", Name: "beta"},
61 {StableID: "tab-a", Name: "alpha"},
62 }
63 index, ok = remoteTargetTabIndexStopped(reordered, stable)
64 require.True(t, ok)
65 require.Equal(t, 0, index, "stable selectors follow identity, not the old ordinal")
66}