detached 388d3be

repos_mutate_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package kvstore_test
4
5import (
6	"errors"
7	"testing"
8	"time"
9
10	"github.com/stretchr/testify/require"
11
12	"bnema.dev/ermite/internal/domain"
13)
14
15func TestRepoMutateInterleavedWrites(t *testing.T) {
16	ctx := t.Context()
17	s := openStore(t, t.TempDir())
18	n := name(t, "proj")
19	original := domain.Repo{Name: n, Visibility: domain.VisibilityPublic, CreatedAt: created}
20	require.NoError(t, s.Create(ctx, original))
21	later := created.Add(2 * time.Hour)
22	calls := 0
23	got, err := s.Mutate(ctx, n, func(r *domain.Repo) (bool, error) {
24		calls++
25		// Test-only interleaving: inject a committed write after the outer read.
26		if calls == 1 {
27			_, err := s.Mutate(ctx, n, func(current *domain.Repo) (bool, error) {
28				current.Visibility = domain.VisibilityPrivate
29				current.ActiveAt = later
30				current.PushedAt = later
31				return true, nil
32			})
33			require.NoError(t, err)
34		}
35		r.Description = "updated"
36		at := created.Add(time.Hour)
37		if at.After(r.ActiveAt) {
38			r.ActiveAt = at
39		}
40		if at.After(r.PushedAt) {
41			r.PushedAt = at
42		}
43		return true, nil
44	})
45	require.NoError(t, err)
46	require.Equal(t, 2, calls)
47	require.Equal(t, domain.VisibilityPrivate, got.Visibility)
48	require.Equal(t, "updated", got.Description)
49	require.Equal(t, later, got.ActiveAt)
50	require.Equal(t, later, got.PushedAt)
51	stored, err := s.Get(ctx, n)
52	require.NoError(t, err)
53	require.Equal(t, got, stored)
54}
55
56func TestRepoMutateContracts(t *testing.T) {
57	ctx := t.Context()
58	s := openStore(t, t.TempDir())
59	n := name(t, "proj")
60	require.NoError(t, s.Create(ctx, domain.Repo{Name: n, Visibility: domain.VisibilityPublic, CreatedAt: created}))
61	original, err := s.Get(ctx, n)
62	require.NoError(t, err)
63	boom := errors.New("callback failed")
64	_, err = s.Mutate(ctx, n, func(r *domain.Repo) (bool, error) { r.Description = "discard"; return true, boom })
65	require.ErrorIs(t, err, boom)
66	got, err := s.Mutate(ctx, n, func(r *domain.Repo) (bool, error) { r.Description = "discard"; return false, nil })
67	require.NoError(t, err)
68	require.Equal(t, original, got)
69	for _, changed := range []bool{false, true} {
70		_, err = s.Mutate(ctx, n, func(r *domain.Repo) (bool, error) { r.Name = name(t, "other"); return changed, nil })
71		require.ErrorIs(t, err, domain.ErrInvalidName)
72	}
73	got, err = s.Get(ctx, n)
74	require.NoError(t, err)
75	require.Equal(t, original, got)
76	calls := 0
77	_, err = s.Mutate(ctx, n, func(r *domain.Repo) (bool, error) {
78		calls++
79		_, err := s.Mutate(ctx, n, func(current *domain.Repo) (bool, error) { current.Description = "concurrent"; return true, nil })
80		require.NoError(t, err)
81		return true, nil
82	})
83	require.ErrorIs(t, err, domain.ErrConflict)
84	require.Equal(t, 8, calls)
85	_, err = s.Mutate(ctx, n, func(r *domain.Repo) (bool, error) { require.NoError(t, s.Delete(ctx, n)); return true, nil })
86	require.ErrorIs(t, err, domain.ErrNotFound)
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 4

Tags 45

↑↓ moveenter openesc close