vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Add named release channels and a generic channel file route
24019cb30892b9fc0118697e8b89cd61e9fab576 · Keenan Nemetz · 19d ago · parent 4f8a3da8
Add named release channels and a generic channel file route A channel is a mutable pointer, channels/<name>.md, to one immutable annotated release. The target tag object is recorded so a rewritten tag is detected rather than silently followed. - metadata: channel parse/render/validate, closed-layout and size checks, set/clear writers - CLI: vole release channel set|list|clear; a dangling target is reported - server: maintain/admin path gate and audit for channel.set/clear - index: release_channels table, incremental refresh, per-tag badge query - web: /channels list, /channels/<name> redirect, and /channels/<name>/<path...> serving the target release's tree with OID ETags, Range, revalidation, and octet-stream responses - tests: metadata round trips, index moves, hook role/audit, page/tree/dangling/ private, and the CLI end to end No apt, yum, or other package-manager code is involved: a package layout is a directory in the release tree. Refs: 01M7BPHANWMSW5HK2GT0PY74QZ
metadata/channels_test.go +127
| @@ -0,0 +1,127 @@ | |||
| 1 | package metadata | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "strings" | ||
| 5 | "testing" | ||
| 6 | "time" | ||
| 7 | |||
| 8 | "rodent.software/vole/core/git" | ||
| 9 | ) | ||
| 10 | |||
| 11 | func putChannelFile(t *testing.T, g *git.Repo, path, raw string) { | ||
| 12 | t.Helper() | ||
| 13 | if _, err := git.CommitFiles(g, Ref, func(files map[string][]byte) error { | ||
| 14 | files[path] = []byte(raw) | ||
| 15 | return nil | ||
| 16 | }, "channel hand edit", "keenan"); err != nil { | ||
| 17 | t.Fatal(err) | ||
| 18 | } | ||
| 19 | } | ||
| 20 | |||
| 21 | func channelFile(tag, object, by, at, body string) string { | ||
| 22 | return "---\nrelease: " + tag + "\nrelease_object: " + object + | ||
| 23 | "\nupdated_by: " + by + "\nupdated_at: " + at + "\n---\n" + body | ||
| 24 | } | ||
| 25 | |||
| 26 | func TestValidChannelName(t *testing.T) { | ||
| 27 | t.Parallel() | ||
| 28 | for _, ok := range []string{"stable", "latest", "beta", "lts-2026", "a"} { | ||
| 29 | if err := ValidChannelName(ok); err != nil { | ||
| 30 | t.Errorf("ValidChannelName(%q) = %v", ok, err) | ||
| 31 | } | ||
| 32 | } | ||
| 33 | for _, bad := range []string{"", "Stable", "-stable", "stable/", "stable.md", "a b", strings.Repeat("a", 33), ".", ".."} { | ||
| 34 | if err := ValidChannelName(bad); err == nil { | ||
| 35 | t.Errorf("ValidChannelName(%q) = nil", bad) | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | func TestChannelRoundTrip(t *testing.T) { | ||
| 41 | t.Parallel() | ||
| 42 | g := writeRepo(t) | ||
| 43 | obj := strings.Repeat("a", 40) | ||
| 44 | at := time.Date(2026, 11, 14, 12, 0, 0, 0, time.UTC) | ||
| 45 | ch := &Channel{ | ||
| 46 | Name: "stable", | ||
| 47 | Release: "v1.0.0", | ||
| 48 | ReleaseObject: obj, | ||
| 49 | UpdatedBy: "keenan", | ||
| 50 | UpdatedAt: at, | ||
| 51 | Description: "Recommended for production.", | ||
| 52 | } | ||
| 53 | if err := WriteChannel(g, Ref, ch, "channel: stable", "keenan"); err != nil { | ||
| 54 | t.Fatal(err) | ||
| 55 | } | ||
| 56 | list, err := LoadChannelsAt(g, Ref) | ||
| 57 | if err != nil { | ||
| 58 | t.Fatal(err) | ||
| 59 | } | ||
| 60 | if len(list) != 1 { | ||
| 61 | t.Fatalf("channels = %+v, want one", list) | ||
| 62 | } | ||
| 63 | got := list[0] | ||
| 64 | if got.Name != ch.Name || got.Release != ch.Release || got.ReleaseObject != obj || | ||
| 65 | got.UpdatedBy != ch.UpdatedBy || !got.UpdatedAt.Equal(at) || got.Description != ch.Description { | ||
| 66 | t.Fatalf("round trip = %+v, want %+v", got, ch) | ||
| 67 | } | ||
| 68 | if problems := ChannelProblems(g, Ref); len(problems) != 0 { | ||
| 69 | t.Fatalf("ChannelProblems = %v", problems) | ||
| 70 | } | ||
| 71 | if problems := ValidateIssues(g, Ref); len(problems) != 0 { | ||
| 72 | t.Fatalf("ValidateIssues = %v", problems) | ||
| 73 | } | ||
| 74 | |||
| 75 | if err := DeleteChannel(g, Ref, "stable", "channel: clear stable", "keenan"); err != nil { | ||
| 76 | t.Fatal(err) | ||
| 77 | } | ||
| 78 | list, err = LoadChannelsAt(g, Ref) | ||
| 79 | if err != nil || len(list) != 0 { | ||
| 80 | t.Fatalf("after clear = %+v, %v", list, err) | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | func TestChannelProblems(t *testing.T) { | ||
| 85 | t.Parallel() | ||
| 86 | g := writeRepo(t) | ||
| 87 | obj := strings.Repeat("b", 40) | ||
| 88 | at := "2026-11-14T12:00:00Z" | ||
| 89 | putChannelFile(t, g, "channels/stable.md", channelFile("v1.0.0", obj, "keenan", at, "Stable.\n")) | ||
| 90 | if problems := ChannelProblems(g, Ref); len(problems) != 0 { | ||
| 91 | t.Fatalf("a valid channel was refused: %v", problems) | ||
| 92 | } | ||
| 93 | |||
| 94 | putChannelFile(t, g, "channels/Upper.md", channelFile("v1.0.0", obj, "keenan", at, "")) | ||
| 95 | putChannelFile(t, g, "channels/nested/stable.md", channelFile("v1.0.0", obj, "keenan", at, "")) | ||
| 96 | putChannelFile(t, g, "channels/bad.md", "---\nrelease: v1.0.0\n---\n") | ||
| 97 | problems := ChannelProblems(g, Ref) | ||
| 98 | if len(problems) != 3 { | ||
| 99 | t.Fatalf("ChannelProblems = %v, want three problems", problems) | ||
| 100 | } | ||
| 101 | for _, p := range problems { | ||
| 102 | if !strings.Contains(p, "channels/") { | ||
| 103 | t.Errorf("problem does not name its file: %q", p) | ||
| 104 | } | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | func TestChannelNameFromPath(t *testing.T) { | ||
| 109 | t.Parallel() | ||
| 110 | for path, want := range map[string]string{ | ||
| 111 | "channels/stable.md": "stable", | ||
| 112 | "channels/lts-2026.md": "lts-2026", | ||
| 113 | } { | ||
| 114 | got, ok := ChannelNameFromPath(path) | ||
| 115 | if !ok || got != want { | ||
| 116 | t.Errorf("ChannelNameFromPath(%q) = %q, %v", path, got, ok) | ||
| 117 | } | ||
| 118 | } | ||
| 119 | for _, path := range []string{ | ||
| 120 | "channels/Stable.md", "channels/stable.txt", "channels/nested/stable.md", | ||
| 121 | "channels/.md", "releases/v1/file", | ||
| 122 | } { | ||
| 123 | if name, ok := ChannelNameFromPath(path); ok { | ||
| 124 | t.Errorf("ChannelNameFromPath(%q) = %q, true", path, name) | ||
| 125 | } | ||
| 126 | } | ||
| 127 | } | ||