detached 83e495f

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 TestParseArtifactName(t *testing.T) {
17	for _, ok := range []string{"dist", "my artifact (linux) v1.2", "é", strings.Repeat("é", 256), "..", "a.b-c_d"} {
18		assert.NoError(t, domain.ParseArtifactName(ok), "%q", ok)
19	}
20	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"} {
21		assert.ErrorIs(t, domain.ParseArtifactName(bad), domain.ErrInvalid, "%q", bad)
22	}
23}
24
25func TestParseArtifactMediaTypeAndDigest(t *testing.T) {
26	mt, err := domain.ParseArtifactMediaType("")
27	require.NoError(t, err)
28	assert.Equal(t, domain.CIArtifactZip, mt)
29	mt, err = domain.ParseArtifactMediaType("text/plain; charset=utf-8")
30	require.NoError(t, err)
31	assert.Equal(t, "text/plain; charset=utf-8", mt)
32	for _, bad := range []string{strings.Repeat("a", 256), "text/plain\r\nX-Evil: 1", "tëxt/plain"} {
33		_, err := domain.ParseArtifactMediaType(bad)
34		assert.ErrorIs(t, err, domain.ErrInvalid, "%q", bad)
35	}
36
37	hex := strings.Repeat("ab", 32)
38	d, err := domain.ParseArtifactDigest("SHA256:" + strings.ToUpper(hex))
39	require.NoError(t, err)
40	assert.Equal(t, "sha256:"+hex, d)
41	d, err = domain.ParseArtifactDigest("")
42	require.NoError(t, err)
43	assert.Empty(t, d)
44	for _, bad := range []string{hex, "sha256:" + hex[:62], "sha1:" + hex, "sha256:" + strings.Repeat("zz", 32)} {
45		_, err := domain.ParseArtifactDigest(bad)
46		assert.ErrorIs(t, err, domain.ErrInvalid, bad)
47	}
48}
49
50func TestArtifactExpiry(t *testing.T) {
51	now := time.Date(2026, 10, 15, 12, 0, 0, 0, time.UTC)
52	day := 24 * time.Hour
53	assert.Equal(t, now.Add(90*day), domain.ArtifactExpiry(time.Time{}, now, 90*day), "unset: the retention")
54	assert.Equal(t, now.Add(day), domain.ArtifactExpiry(now.Add(time.Hour), now, 90*day), "at least a day")
55	assert.Equal(t, now.Add(day), domain.ArtifactExpiry(now.Add(-time.Hour), now, 90*day), "a time in the past")
56	assert.Equal(t, now.Add(90*day), domain.ArtifactExpiry(now.Add(400*day), now, 90*day), "at most the retention")
57	assert.Equal(t, now.Add(3*day), domain.ArtifactExpiry(now.Add(3*day), now, 90*day))
58	assert.Equal(t, now.Add(day), domain.ArtifactExpiry(time.Time{}, now, time.Hour), "a retention below a day counts as a day")
59}
60
61func TestArtifactOwnership(t *testing.T) {
62	tok := domain.HashTokenSecret("ermitejob_a")
63	j := domain.CIJob{ID: "5-0-0", RunID: 5, RunAttempt: 2, TokenHash: tok}
64	a := domain.CIArtifact{RunID: 5, Attempt: 2, JobID: "5-0-0", Assignment: tok, State: domain.CIArtifactPending}
65	assert.True(t, a.PendingOf(j))
66	other := j
67	other.TokenHash = domain.HashTokenSecret("ermitejob_b")
68	assert.False(t, a.PendingOf(other), "another assignment of the job")
69	assert.True(t, a.UploadedBy(other))
70	next := j
71	next.RunAttempt = 3
72	assert.False(t, a.UploadedBy(next), "another attempt")
73	a.State = domain.CIArtifactFinal
74	assert.False(t, a.PendingOf(j))
75	a.ExpiresAt = time.Now().Add(time.Hour)
76	assert.True(t, a.Visible(time.Now()))
77	assert.False(t, a.Visible(a.ExpiresAt))
78}

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