v0.35.1 2aca1df

ci_artifact_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package domain_test
4
5import (
6	"strings"
7	"testing"
8	"time"
9
10	"github.com/stretchr/testify/assert"
11	"github.com/stretchr/testify/require"
12
13	"bnema.dev/ermite/internal/domain"
14)
15
16func TestCIArtifactBlobKeys(t *testing.T) {
17	a := domain.CIArtifact{RunID: 7, ID: 42, Name: "not-used-in-keys"}
18	assert.Equal(t, "ci/00000000000000000007/00000000000000000042", a.BlobKey())
19	assert.Equal(t, a.BlobKey()+".blocks/abcd.0123", a.BlockKey("abcd.0123"))
20	assert.Equal(t, domain.CIArtifactStoreLegacy, a.Store)
21}
22
23func TestParseArtifactName(t *testing.T) {
24	for _, ok := range []string{"dist", "my artifact (linux) v1.2", "é", strings.Repeat("é", 256), "..", "a.b-c_d"} {
25		assert.NoError(t, domain.ParseArtifactName(ok), "%q", ok)
26	}
27	for _, bad := range []string{"", strings.Repeat("a", 257), "a/b", `a\b`, "a:b", `a"b`, "a<b", "a>b", "a|b", "a*b", "a?b", "a\nb", "a\x00b", "\xff"} {
28		assert.ErrorIs(t, domain.ParseArtifactName(bad), domain.ErrInvalid, "%q", bad)
29	}
30}
31
32func TestParseArtifactMediaTypeAndDigest(t *testing.T) {
33	mt, err := domain.ParseArtifactMediaType("")
34	require.NoError(t, err)
35	assert.Equal(t, domain.CIArtifactZip, mt)
36	mt, err = domain.ParseArtifactMediaType("text/plain; charset=utf-8")
37	require.NoError(t, err)
38	assert.Equal(t, "text/plain; charset=utf-8", mt)
39	for _, bad := range []string{strings.Repeat("a", 256), "text/plain\r\nX-Evil: 1", "tëxt/plain"} {
40		_, err := domain.ParseArtifactMediaType(bad)
41		assert.ErrorIs(t, err, domain.ErrInvalid, "%q", bad)
42	}
43
44	hex := strings.Repeat("ab", 32)
45	d, err := domain.ParseArtifactDigest("SHA256:" + strings.ToUpper(hex))
46	require.NoError(t, err)
47	assert.Equal(t, "sha256:"+hex, d)
48	d, err = domain.ParseArtifactDigest("")
49	require.NoError(t, err)
50	assert.Empty(t, d)
51	for _, bad := range []string{hex, "sha256:" + hex[:62], "sha1:" + hex, "sha256:" + strings.Repeat("zz", 32)} {
52		_, err := domain.ParseArtifactDigest(bad)
53		assert.ErrorIs(t, err, domain.ErrInvalid, bad)
54	}
55}
56
57func TestArtifactExpiry(t *testing.T) {
58	now := time.Date(2026, 10, 15, 12, 0, 0, 0, time.UTC)
59	day := 24 * time.Hour
60	assert.Equal(t, now.Add(90*day), domain.ArtifactExpiry(time.Time{}, now, 90*day), "unset: the retention")
61	assert.Equal(t, now.Add(day), domain.ArtifactExpiry(now.Add(time.Hour), now, 90*day), "at least a day")
62	assert.Equal(t, now.Add(day), domain.ArtifactExpiry(now.Add(-time.Hour), now, 90*day), "a time in the past")
63	assert.Equal(t, now.Add(90*day), domain.ArtifactExpiry(now.Add(400*day), now, 90*day), "at most the retention")
64	assert.Equal(t, now.Add(3*day), domain.ArtifactExpiry(now.Add(3*day), now, 90*day))
65	assert.Equal(t, now.Add(day), domain.ArtifactExpiry(time.Time{}, now, time.Hour), "a retention below a day counts as a day")
66}
67
68func TestArtifactOwnership(t *testing.T) {
69	tok := domain.HashTokenSecret("ermitejob_a")
70	j := domain.CIJob{ID: "5-0-0", RunID: 5, RunAttempt: 2, TokenHash: tok}
71	a := domain.CIArtifact{RunID: 5, Attempt: 2, JobID: "5-0-0", Assignment: tok, State: domain.CIArtifactPending}
72	assert.True(t, a.PendingOf(j))
73	other := j
74	other.TokenHash = domain.HashTokenSecret("ermitejob_b")
75	assert.False(t, a.PendingOf(other), "another assignment of the job")
76	assert.True(t, a.UploadedBy(other))
77	next := j
78	next.RunAttempt = 3
79	assert.False(t, a.UploadedBy(next), "another attempt")
80	a.State = domain.CIArtifactFinal
81	assert.False(t, a.PendingOf(j))
82	a.ExpiresAt = time.Now().Add(time.Hour)
83	assert.True(t, a.Visible(time.Now()))
84	assert.False(t, a.Visible(a.ExpiresAt))
85}

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