attachment_route_identity_test.go RawHistoryFolder

1package daemon
2
3import (
4	"errors"
5	"testing"
6
7	"github.com/bnema/vev/internal/domain"
8	"github.com/bnema/vev/internal/protocol"
9	"github.com/bnema/vev/internal/protocol/wire"
10	"github.com/stretchr/testify/require"
11)
12
13type committedIdentityErrorTransport struct {
14	closeTrackingTransport
15}
16
17func (t *committedIdentityErrorTransport) Send(frame wire.Envelope) error {
18	if envelopeMessageName(nil, frame.Payload) == "CommittedRouteIdentity" {
19		return errors.New("committed identity send failed")
20	}
21	return t.closeTrackingTransport.Send(frame)
22}
23
24func TestAttachmentTransitionPublishesCommittedRouteIdentity(t *testing.T) {
25	d, source, ac, _ := newManualSessionWithPTYs(t, nil)
26	transport := &closeTrackingTransport{}
27	ac.replaceTransport(transport)
28	rc := d.attachCoordinator(source, nil, ac, true)
29	token := source.captureAttachmentCapability(ac, transport)
30	token.lease = rc.attachmentLease(ac)
31	ac.installTestAttachmentCapability(token)
32	ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1})
33
34	target := &session{
35		sessionCore: sessionCore{
36			id:          "target",
37			name:        "target",
38			incarnation: domain.IncarnationID{2},
39		},
40		ctx:    source.ctx,
41		cancel: func() {},
42		tabs:   []*tab{newTab(nil, domain.Size{Cols: 80, Rows: 23})},
43	}
44	d.mu.Lock()
45	d.sessions[target.id] = target
46	d.mu.Unlock()
47
48	transition, err := d.transitionAttachment(attachmentTransitionRequest{
49		source:            source,
50		target:            target,
51		next:              ac,
52		expectedTransport: transportSnapshot{transport: transport, incarnation: ac.transportSnapshot().incarnation},
53		ready:             true,
54	})
55	require.NoError(t, err)
56	d.deferAttachmentTransitionCleanups(transition)
57
58	var identity protocol.CommittedRouteIdentity
59	found := false
60	for _, frame := range transport.Sends() {
61		decoded, ok := decodeServerMessage(t, frame).(protocol.CommittedRouteIdentity)
62		if !ok {
63			continue
64		}
65		identity, found = decoded, true
66	}
67	require.True(t, found, "attachment transitions must publish their committed route identity")
68	require.Equal(t, "target", identity.Target.SessionName)
69	require.Equal(t, domain.IncarnationID{2}, identity.Target.LifecycleID)
70}
71
72func TestAttachmentTransitionTearsDownAfterCommittedIdentitySendFailure(t *testing.T) {
73	d, source, ac, _ := newManualSessionWithPTYs(t, nil)
74	transport := &committedIdentityErrorTransport{}
75	ac.replaceTransport(transport)
76	rc := d.attachCoordinator(source, nil, ac, true)
77	token := source.captureAttachmentCapability(ac, transport)
78	token.lease = rc.attachmentLease(ac)
79	ac.installTestAttachmentCapability(token)
80	ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1})
81
82	target := &session{
83		sessionCore: sessionCore{
84			id:          "target",
85			name:        "target",
86			incarnation: domain.IncarnationID{2},
87		},
88		ctx:    source.ctx,
89		cancel: func() {},
90		tabs:   []*tab{newTab(nil, domain.Size{Cols: 80, Rows: 23})},
91	}
92	d.mu.Lock()
93	d.sessions[target.id] = target
94	d.mu.Unlock()
95
96	_, err := d.transitionAttachment(attachmentTransitionRequest{
97		source:            source,
98		target:            target,
99		next:              ac,
100		expectedTransport: transportSnapshot{transport: transport, incarnation: ac.transportSnapshot().incarnation},
101		ready:             true,
102	})
103	require.ErrorContains(t, err, "committed identity send failed")
104	require.Empty(t, target.snapshotAttachments())
105	require.Empty(t, source.snapshotAttachments())
106	require.True(t, transport.Closed())
107}

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