detached ef93e42

test(snapshot): cover content addressed publication

commit
ef93e42a5aa725cca841f8f7664611f3f4618a2f
author
brice · · 2026-07-21 19:52 UTC
committer
brice · · 2026-07-21 19:53 UTC
parent
e144d99
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +71 -0
A internal/adapters/snapshot/repository_test.go +71 -0
@@ -0,0 +1,71 @@
1+package snapshot
2+
3+import (
4+ "context"
5+ "testing"
6+
7+ "github.com/bnema/vev/internal/ports"
8+ codec "github.com/bnema/vev/internal/usecase/snapshot"
9+)
10+
11+func TestRepositoryPublishesAndLoadsCompleteGeneration(t *testing.T) {
12+ t.Parallel()
13+ dir := privateDir(t)
14+ repo := NewRepository(dir)
15+ pub := repositoryPublication(t, "named", 1, []byte("state"))
16+ if err := repo.Publish(context.Background(), pub); err != nil {
17+ t.Fatalf("Publish: %v", err)
18+ }
19+ got, err := repo.Load(context.Background(), "named")
20+ if err != nil {
21+ t.Fatalf("Load: %v", err)
22+ }
23+ if got.Name != "named" || got.Generation != 1 || len(got.Objects) != 2 {
24+ t.Fatalf("Load = %#v", got)
25+ }
26+}
27+
28+func TestRepositoryDoesNotRewriteVerifiedImmutableBlob(t *testing.T) {
29+ t.Parallel()
30+ dir := privateDir(t)
31+ repo := NewRepository(dir)
32+ pub := repositoryPublication(t, "named", 1, []byte("state"))
33+ if err := repo.Publish(context.Background(), pub); err != nil {
34+ t.Fatal(err)
35+ }
36+ writes := 0
37+ repo.hooks.beforeBlobWrite = func(string) error { writes++; return nil }
38+ pub.Generation = 2
39+ manifest, err := codec.UnmarshalManifest(pub.Manifest)
40+ if err != nil {
41+ t.Fatal(err)
42+ }
43+ manifest.Generation = 2
44+ pub.Manifest, err = codec.MarshalManifest(manifest)
45+ if err != nil {
46+ t.Fatal(err)
47+ }
48+ if err := repo.Publish(context.Background(), pub); err != nil {
49+ t.Fatal(err)
50+ }
51+ if writes != 0 {
52+ t.Fatalf("blob writes = %d, want 0", writes)
53+ }
54+}
55+
56+func repositoryPublication(t *testing.T, name string, generation uint64, payload []byte) ports.SnapshotPublication {
57+ t.Helper()
58+ tail, err := codec.MarshalObject(codec.HistoryTail, payload)
59+ if err != nil {
60+ t.Fatal(err)
61+ }
62+ visible, err := codec.MarshalObject(codec.Visible, []byte("visible"))
63+ if err != nil {
64+ t.Fatal(err)
65+ }
66+ manifest, err := codec.MarshalManifest(codec.Manifest{Generation: generation, Name: name, Tabs: []codec.ManifestTab{{Cols: 1, Rows: 1, Panes: []codec.ManifestPane{{ID: "p", Tail: codec.ObjectRef{Kind: codec.HistoryTail, Digest: tail.Digest, Size: uint32(len(tail.Data))}, Visible: codec.ObjectRef{Kind: codec.Visible, Digest: visible.Digest, Size: uint32(len(visible.Data))}}}}}})
67+ if err != nil {
68+ t.Fatal(err)
69+ }
70+ return ports.SnapshotPublication{Name: name, Generation: generation, Manifest: manifest, Objects: []ports.SnapshotObject{tail, visible}}
71+}
@@ -0,0 +1,71 @@
1+package snapshot
2+
3+import (
4+ "context"
5+ "testing"
6+
7+ "github.com/bnema/vev/internal/ports"
8+ codec "github.com/bnema/vev/internal/usecase/snapshot"
9+)
10+
11+func TestRepositoryPublishesAndLoadsCompleteGeneration(t *testing.T) {
12+ t.Parallel()
13+ dir := privateDir(t)
14+ repo := NewRepository(dir)
15+ pub := repositoryPublication(t, "named", 1, []byte("state"))
16+ if err := repo.Publish(context.Background(), pub); err != nil {
17+ t.Fatalf("Publish: %v", err)
18+ }
19+ got, err := repo.Load(context.Background(), "named")
20+ if err != nil {
21+ t.Fatalf("Load: %v", err)
22+ }
23+ if got.Name != "named" || got.Generation != 1 || len(got.Objects) != 2 {
24+ t.Fatalf("Load = %#v", got)
25+ }
26+}
27+
28+func TestRepositoryDoesNotRewriteVerifiedImmutableBlob(t *testing.T) {
29+ t.Parallel()
30+ dir := privateDir(t)
31+ repo := NewRepository(dir)
32+ pub := repositoryPublication(t, "named", 1, []byte("state"))
33+ if err := repo.Publish(context.Background(), pub); err != nil {
34+ t.Fatal(err)
35+ }
36+ writes := 0
37+ repo.hooks.beforeBlobWrite = func(string) error { writes++; return nil }
38+ pub.Generation = 2
39+ manifest, err := codec.UnmarshalManifest(pub.Manifest)
40+ if err != nil {
41+ t.Fatal(err)
42+ }
43+ manifest.Generation = 2
44+ pub.Manifest, err = codec.MarshalManifest(manifest)
45+ if err != nil {
46+ t.Fatal(err)
47+ }
48+ if err := repo.Publish(context.Background(), pub); err != nil {
49+ t.Fatal(err)
50+ }
51+ if writes != 0 {
52+ t.Fatalf("blob writes = %d, want 0", writes)
53+ }
54+}
55+
56+func repositoryPublication(t *testing.T, name string, generation uint64, payload []byte) ports.SnapshotPublication {
57+ t.Helper()
58+ tail, err := codec.MarshalObject(codec.HistoryTail, payload)
59+ if err != nil {
60+ t.Fatal(err)
61+ }
62+ visible, err := codec.MarshalObject(codec.Visible, []byte("visible"))
63+ if err != nil {
64+ t.Fatal(err)
65+ }
66+ manifest, err := codec.MarshalManifest(codec.Manifest{Generation: generation, Name: name, Tabs: []codec.ManifestTab{{Cols: 1, Rows: 1, Panes: []codec.ManifestPane{{ID: "p", Tail: codec.ObjectRef{Kind: codec.HistoryTail, Digest: tail.Digest, Size: uint32(len(tail.Data))}, Visible: codec.ObjectRef{Kind: codec.Visible, Digest: visible.Digest, Size: uint32(len(visible.Data))}}}}}})
67+ if err != nil {
68+ t.Fatal(err)
69+ }
70+ return ports.SnapshotPublication{Name: name, Generation: generation, Manifest: manifest, Objects: []ports.SnapshotObject{tail, visible}}
71+}

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