v0.7.0 4c16dd8

session_test.go RawHistoryFolder

1package protocol
2
3import (
4	"errors"
5	"testing"
6
7	renderer "github.com/bnema/vev-vt"
8	"github.com/bnema/vev/internal/domain"
9	"github.com/stretchr/testify/require"
10)
11
12func TestVersionRemainsWireCompatible(t *testing.T) {
13	require.Equal(t, uint16(65), Version)
14	require.Equal(t, (16<<20)-407, MaxOutputDataLen)
15}
16
17func TestHelloSemanticValidation(t *testing.T) {
18	base := Hello{Version: Version, Intent: IntentAttach, Name: "work", Size: domain.Size{Cols: 80, Rows: 24}}
19	tests := []struct {
20		name   string
21		mutate func(*Hello)
22		want   error
23	}{
24		{name: "valid", mutate: func(*Hello) {}},
25		{name: "unknown intent", mutate: func(h *Hello) { h.Intent = 99 }, want: ErrInvalidHello},
26		{name: "invalid geometry", mutate: func(h *Hello) { h.Size.Rows = 0 }, want: ErrInvalidHello},
27		{name: "local client pid", mutate: func(h *Hello) { h.ClientPID = 4242 }},
28		{name: "remote client pid", mutate: func(h *Hello) { h.Remote, h.ClientPID = true, 4242 }, want: ErrInvalidHello},
29		{name: "unsafe navigation", mutate: func(h *Hello) { h.NavigationCapabilities = 8 }, want: ErrInvalidHello},
30		{name: "exact target name mismatch", mutate: func(h *Hello) {
31			h.ExactTarget = &ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{1}, SessionName: "other"}
32		}, want: ErrInvalidHello},
33	}
34	for _, tt := range tests {
35		t.Run(tt.name, func(t *testing.T) {
36			hello := base
37			tt.mutate(&hello)
38			err := ValidateHello(hello)
39			if tt.want == nil {
40				require.NoError(t, err)
41				return
42			}
43			require.ErrorIs(t, err, tt.want)
44		})
45	}
46}
47
48func TestSessionAttachTargetOrdinalValidationIsStrict(t *testing.T) {
49	valid := SessionAttachTarget{LifecycleID: domain.SessionLifecycleID{1}, SessionName: "work", TabIndex: 0, TabRawName: "first", TabExpectedCount: 1, Stopped: true}
50	require.NoError(t, valid.Validate())
51
52	tests := []struct {
53		name   string
54		mutate func(*SessionAttachTarget)
55	}{
56		{name: "expected count required", mutate: func(target *SessionAttachTarget) { target.TabExpectedCount = 0 }},
57		{name: "index bounded by expected count", mutate: func(target *SessionAttachTarget) { target.TabIndex = 1 }},
58		{name: "raw name too long", mutate: func(target *SessionAttachTarget) { target.TabRawName = string(make([]byte, 257)) }},
59		{name: "raw name control", mutate: func(target *SessionAttachTarget) { target.TabRawName = "bad\nname" }},
60	}
61	for _, test := range tests {
62		t.Run(test.name, func(t *testing.T) {
63			target := valid
64			test.mutate(&target)
65			require.Error(t, target.Validate())
66		})
67	}
68
69	index, ok := valid.ResolveTab([]domain.TabSelectorTab{{Name: "first"}})
70	require.True(t, ok)
71	require.Zero(t, index)
72	_, ok = valid.ResolveTab([]domain.TabSelectorTab{{Name: "replaced"}})
73	require.False(t, ok)
74	_, ok = valid.ResolveTab([]domain.TabSelectorTab{{Name: "first"}, {Name: "second"}})
75	require.False(t, ok)
76
77	empty := SessionAttachTarget{LifecycleID: domain.SessionLifecycleID{1}, SessionName: "work", TabIndex: NoTabIndex, Stopped: true}
78	require.NoError(t, empty.Validate())
79	_, ok = empty.ResolveTab([]domain.TabSelectorTab{{Name: "first"}, {Name: "second"}})
80	require.False(t, ok)
81}
82
83func TestOutputSemanticValidation(t *testing.T) {
84	context := ViewContext{
85		Publication: 1,
86		Route:       CommittedRouteIdentity{Target: ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{1}, SessionName: "work"}},
87		TabID:       "tab-1", FocusedPaneID: "pane-1",
88	}
89	valid := Output{Epoch: 1, New: 1, Full: true, Size: domain.Size{Cols: 80, Rows: 24}, Context: &context}
90	require.NoError(t, ValidateOutput(valid))
91
92	invalid := valid
93	invalid.Epoch = 0
94	require.ErrorIs(t, ValidateOutput(invalid), ErrInvalidOutput)
95
96	invalid = valid
97	invalid.Data = make([]byte, MaxOutputDataLen+1)
98	require.ErrorIs(t, ValidateOutput(invalid), ErrInvalidOutput)
99}
100
101func TestRouteAndPreviewSemanticValidation(t *testing.T) {
102	require.Error(t, ValidateRouteLabel("\x1b[31m", false))
103	require.NoError(t, RouteRef{}.Validate())
104	require.Error(t, (RouteRef{Key: 1}).Validate())
105
106	target := domain.RemoteSessionTarget{
107		Endpoint: "remote", DisplayOrigin: "remote", LifecycleID: domain.SessionLifecycleID{1},
108		SessionName: "work", LiveTabID: "tab-1",
109	}
110	request := RemotePreviewRequest{Version: RemotePreviewSchemaVersion, Target: target, Width: 1, Height: 1}
111	require.NoError(t, ValidateRemotePreviewRequest(request))
112	preview := RemotePreview{
113		Version: RemotePreviewSchemaVersion, Status: RemotePreviewOK,
114		LifecycleID: target.LifecycleID, TabID: target.LiveTabID, Revision: 1,
115		Width: 1, Height: 1, Cells: []renderer.Cell{{Rune: 'x'}},
116	}
117	require.NoError(t, ValidateRemotePreview(preview))
118	preview.Cells[0].Rune = '\n'
119	require.ErrorIs(t, ValidateRemotePreview(preview), ErrInvalidRemotePreview)
120}
121
122func TestSemanticErrorsPreserveClassification(t *testing.T) {
123	require.True(t, errors.Is(ValidateAck(Ack{}), ErrInvalidAck))
124	require.True(t, errors.Is(ValidateAttachTarget(AttachTarget{}), ErrInvalidAttachTarget))
125}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 12

Tags 11

↑↓ moveenter openesc close