main ab6686c

snapshot_test.go RawHistoryFolder

1package vt
2
3import (
4	"testing"
5
6	renderer "github.com/bnema/vev-vt/core"
7	"github.com/stretchr/testify/require"
8)
9
10func TestHistorySnapshotViewDoesNotSealTailAndCopiesIt(t *testing.T) {
11	history := NewHistory(HistoryConfig{MaxRows: 8, ChunkRows: 2})
12	requireHistoryAppend(t, history, historyRow("AAAA"))
13	requireHistoryAppend(t, history, historyRow("BBBB"))
14	requireHistoryAppend(t, history, historyRow("CCCC"))
15	sealed := history.View().Chunk(0)
16
17	view := history.SnapshotView()
18	if got, want := view.ChunkCount(), 1; got != want {
19		t.Fatalf("sealed chunks = %d, want %d", got, want)
20	}
21	if view.Chunk(0) != sealed {
22		t.Fatal("snapshot copied an immutable sealed chunk")
23	}
24	if got, want := len(history.tail), 1; got != want {
25		t.Fatalf("live tail rows = %d, want %d; snapshot sealed it", got, want)
26	}
27	history.tail[0][0].Rune = 'X'
28	if got, want := rowText(view.Tail().Row(0)), "CCCC"; got != want {
29		t.Fatalf("snapshot tail = %q, want %q", got, want)
30	}
31	if got, want := view.Len(), 3; got != want {
32		t.Fatalf("snapshot rows = %d, want %d", got, want)
33	}
34	if got, want := view.Cells(), 12; got != want {
35		t.Fatalf("snapshot cells = %d, want %d", got, want)
36	}
37	wantID := view.Tail().RowID(0)
38	history.tailIDs[0] = 99
39	if got := view.Tail().RowID(0); got != wantID {
40		t.Fatalf("snapshot tail ID = %d after live mutation, want %d", got, wantID)
41	}
42
43	tail, err := MarshalHistoryTail(view)
44	require.NoError(t, err)
45	decoded, err := UnmarshalHistory(tail)
46	require.NoError(t, err)
47	require.Equal(t, []string{"CCCC"}, historyViewTexts(decoded))
48}
49
50func TestHistoryFromBlobsNormalizesFullTailBeforeAppend(t *testing.T) {
51	fullTail, err := MarshalHistory(HistoryView{
52		chunks:    []*HistoryChunk{testHistoryChunk([][]renderer.Cell{historyRow("AAAA"), historyRow("BBBB")}, nil, []RowID{1, 2})},
53		rows:      2,
54		nextRowID: 3,
55	})
56	require.NoError(t, err)
57
58	restored, err := HistoryFromBlobs(HistoryConfig{MaxRows: 4, ChunkRows: 2}, nil, fullTail)
59	require.NoError(t, err)
60	requireHistoryAppend(t, restored, historyRow("CCCC"))
61
62	require.Equal(t, []string{"AAAA", "BBBB", "CCCC"}, historyViewTexts(restored.View()))
63	require.Len(t, restored.chunks, 1, "a full restored tail must become sealed")
64	require.Len(t, restored.tail, 1, "the appended row must be the mutable tail")
65}
66
67func TestHistoryFromBlobsRestoresAccountingAndEvictsToBothBudgets(t *testing.T) {
68	history := NewHistory(HistoryConfig{MaxRows: 4, MaxBytes: 1 << 20, ChunkRows: 2})
69	for _, text := range []string{"a", "b", "cc"} {
70		requireHistoryAppend(t, history, historyRow(text))
71	}
72	view := history.SnapshotView()
73	sealed := make([][]byte, view.ChunkCount())
74	for i := range sealed {
75		var err error
76		sealed[i], err = MarshalHistoryChunk(view.Chunk(i))
77		require.NoError(t, err)
78	}
79	tail, err := MarshalHistoryTail(view)
80	require.NoError(t, err)
81
82	const budget = 2*renderer.StoredCellLogicalBytes + renderer.RowDescriptorLogicalBytes + renderer.StyleRecordLogicalBytes
83	restored, err := HistoryFromBlobs(HistoryConfig{MaxRows: 4, MaxBytes: budget, ChunkRows: 2}, sealed, tail)
84	require.NoError(t, err)
85	require.Equal(t, []string{"cc"}, historyViewTexts(restored.View()))
86	require.Equal(t, 2, restored.Cells())
87}

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 2

Tags 13

↑↓ moveenter openesc close