supervisor_presentation_test.go RawHistoryFolder

1package client
2
3import (
4	"context"
5	"testing"
6	"time"
7
8	"github.com/bnema/vev/internal/ports"
9	"github.com/stretchr/testify/require"
10)
11
12// TestSupervisorPublishesConnectingBeforeGrantAndPickerAfterDrain pins the
13// supervisor's publication ownership: it publishes Connecting before the
14// attachment foreground is granted (so a capture during the attempt sees
15// Connecting, never a stale attachment context), and Picker only after the
16// attachment run drained, revoked, and closed its stream. Attached is never
17// published by the supervisor: it belongs to the admitted foreground.
18func TestSupervisorPublishesConnectingBeforeGrantAndPickerAfterDrain(t *testing.T) {
19	picker := newAttachTestPicker()
20	var ui *UI
21	harness := startAttachHarnessConfig(t, picker, func(cfg *SupervisorConfig) {
22		ui = NewUI(cfg.Terminal.(ports.UIState), cfg.Clock)
23		cfg.UI = ui
24	})
25	stream := newSessionTestStream()
26	harness.service.setOpenStream(func(context.Context, ports.BrokerOpenStreamRequest) (ports.BrokerLogicalConnection, error) {
27		return stream, nil
28	})
29
30	picker.commit(sessionTestRequest(true))
31	awaitHello(t, stream)
32
33	// The Connecting presentation is published by the supervisor before the
34	// foreground commits any frame, so the composition's recorded publication
35	// order starts with an unattached Connecting context.
36	terminal := harness.terminal
37	require.Eventually(t, func() bool {
38		for _, publication := range terminal.publicationList() {
39			if publication.Status == ports.UIStatusConnecting {
40				return true
41			}
42		}
43		return false
44	}, 5*time.Second, time.Millisecond, "the supervisor must publish Connecting before the grant writes")
45	publications := terminal.publicationList()
46	require.Zero(t, publications[0].Generation, "Connecting never carries an actionable generation")
47	require.Equal(t, ui.Handle(), publications[0].AttachmentHandle)
48	require.Zero(t, publications[0].OutputState, "Connecting never carries a committed output boundary")
49
50	deliverReadyStream(t, stream)
51	awaitAttachedState(t, harness.sup)
52	attached := terminal.publicationList()
53	last := attached[len(attached)-1]
54	require.Equal(t, ports.UIStatusAttached, last.Status)
55	require.NotZero(t, last.Generation, "the committed attachment publishes its real action generation")
56	require.Equal(t, uint64(1), last.OutputState, "the attached publication carries the committed frame boundary")
57
58	// A broker loss settles the attachment; the supervisor returns to Picker
59	// only after the run drained and revoked.
60	harness.service.lose(errTestPresentationLoss)
61	awaitPickerState(t, harness.sup)
62	require.Eventually(t, func() bool {
63		list := terminal.publicationList()
64		return list[len(list)-1].Status == ports.UIStatusPicker
65	}, 5*time.Second, time.Millisecond, "the supervisor publishes Picker after the drain")
66	returned := terminal.publicationList()
67	last = returned[len(returned)-1]
68	require.Equal(t, ports.UIStatusPicker, last.Status)
69	require.Zero(t, last.Generation, "the returned Picker presentation carries no actionable generation")
70	require.Zero(t, last.OutputState, "the returned Picker presentation carries no session metadata")
71	ui.mu.Lock()
72	require.Nil(t, ui.input, "the UI binding is revoked before Picker is presented")
73	require.Nil(t, ui.foreground, "the UI foreground is retired before Picker is presented")
74	ui.mu.Unlock()
75}
76
77var errTestPresentationLoss = errPresentationLossForTest()
78
79func errPresentationLossForTest() error {
80	return &ports.BrokerError{Code: ports.BrokerErrorUnavailable, Text: "attachment lost"}
81}

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