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.
Move release channels to an authoritative channels.db
262e516e838cfc4b16b5d00fd98d5e4ef135aa85 · Keenan Nemetz · 19d ago · parent 24019cb3
Move release channels to an authoritative channels.db Channels are consumed from the public URL and are server-side publication state, so they no longer live on the vole branch or in the derived index. - forge/channel: authoritative SQLite store with schema, validation, and CRUD - config: data/channels.db, opened and closed with the instance - CLI: release channel set|list|clear over a new vole-channel SSH verb - server: maintain for set/clear, read for list, annotated-tag validation, audit channel.set/channel.clear, JSON list - web: channel page and tree read the store; release badges query it - remove the metadata-branch channel parser/validator, the index-derived channel table, and the hook path rules - backup, instance-data, and architecture docs include channels.db Refs: 01M7BPHANWMSW5HK2GT0PY74QZ
server/channels_test.go +48−44
| @@ -1,11 +1,10 @@ | |||
| 1 | 1 | package server_test | |
| 2 | 2 | ||
| 3 | // Channels are a mutable alias to an immutable release: the page redirects, the | ||
| 4 | // tree serves the target's files, and moving the pointer is a maintainer action | ||
| 5 | // with an audit line. | ||
| 3 | // Channels are a mutable server-side alias to an immutable release: the page | ||
| 4 | // redirects, the tree serves the target's files, and moving the pointer is a | ||
| 5 | // maintainer action with an audit line. | ||
| 6 | 6 | ||
| 7 | 7 | import ( | |
| 8 | "fmt" | ||
| 9 | 8 | "io" | |
| 10 | 9 | "net/http" | |
| 11 | 10 | "os" | |
| @@ -13,16 +12,27 @@ import ( | |||
| 13 | 12 | "strings" | |
| 14 | 13 | "testing" | |
| 15 | 14 | "time" | |
| 15 | |||
| 16 | "rodent.software/vole/forge/channel" | ||
| 16 | 17 | ) | |
| 17 | 18 | ||
| 18 | func channelDoc(t *testing.T, f *fixture, tag, by, description string) string { | ||
| 19 | // channelWork is a clone with an origin remote, which is what the CLI resolves | ||
| 20 | // before it asks the instance over SSH. | ||
| 21 | func channelWork(t *testing.T, f *fixture) string { | ||
| 19 | 22 | t.Helper() | |
| 20 | ttag, err := mustRepo(t, f).Git().Tag(tag) | ||
| 21 | if err != nil || !ttag.Annotated { | ||
| 22 | t.Fatalf("tag %s: %v (annotated=%v)", tag, err, ttag.Annotated) | ||
| 23 | work := workRepo(t, map[string]string{"readme.md": "channels\n"}) | ||
| 24 | if _, errs, err := runGit(t, work, "remote", "add", "origin", f.sshURL(f.repo)); err != nil { | ||
| 25 | t.Fatalf("remote: %v: %s", err, errs) | ||
| 26 | } | ||
| 27 | return work | ||
| 28 | } | ||
| 29 | |||
| 30 | func setChannelCLI(t *testing.T, f *fixture, key, work, name, tag, description string) { | ||
| 31 | t.Helper() | ||
| 32 | out, errOut, err := f.cliWithKey(key, work, "release", "channel", "set", name, tag, "-m", description) | ||
| 33 | if err != nil { | ||
| 34 | t.Fatalf("channel set: %v\n%s%s", err, out, errOut) | ||
| 23 | 35 | } | |
| 24 | return fmt.Sprintf("---\nrelease: %s\nrelease_object: %s\nupdated_by: %s\nupdated_at: %s\n---\n%s\n", | ||
| 25 | tag, ttag.OID, by, time.Now().UTC().Format(time.RFC3339), description) | ||
| 26 | 36 | } | |
| 27 | 37 | ||
| 28 | 38 | func TestChannelPageAndTree(t *testing.T) { | |
| @@ -30,13 +40,7 @@ func TestChannelPageAndTree(t *testing.T) { | |||
| 30 | 40 | f := releaseFixture(t) | |
| 31 | 41 | data := []byte("Package: vole\n") | |
| 32 | 42 | attachArtifact(t, f, "v1.0.0", "apt/Packages", data) | |
| 33 | |||
| 34 | meta := f.newMetaRepo(t) | ||
| 35 | if err := meta.apply(map[string]string{ | ||
| 36 | "channels/stable.md": channelDoc(t, f, "v1.0.0", "keenan", "Recommended for production."), | ||
| 37 | }, "channel: stable -> v1.0.0"); err != nil { | ||
| 38 | t.Fatal(err) | ||
| 39 | } | ||
| 43 | setChannelCLI(t, f, f.keyPath, channelWork(t, f), "stable", "v1.0.0", "Recommended for production.") | ||
| 40 | 44 | ||
| 41 | 45 | code, page := f.get("/" + f.repo + "/channels") | |
| 42 | 46 | if code != 200 { | |
| @@ -48,14 +52,11 @@ func TestChannelPageAndTree(t *testing.T) { | |||
| 48 | 52 | } | |
| 49 | 53 | } | |
| 50 | 54 | ||
| 51 | // The release page carries the channel badge, so the pointer is discoverable | ||
| 52 | // from the release it names. | ||
| 53 | 55 | if code, release := f.get("/" + f.repo + "/releases/v1.0.0"); code != 200 || | |
| 54 | 56 | !strings.Contains(release, "/channels/stable") { | |
| 55 | 57 | t.Fatalf("release page = %d, badge missing:\n%s", code, release) | |
| 56 | 58 | } | |
| 57 | 59 | ||
| 58 | // The stable page is a redirect to the canonical release page. | ||
| 59 | 60 | req, _ := http.NewRequest(http.MethodGet, f.http.URL+"/"+f.repo+"/channels/stable", nil) | |
| 60 | 61 | resp, err := noRedirect.Do(req) | |
| 61 | 62 | if err != nil { | |
| @@ -66,7 +67,6 @@ func TestChannelPageAndTree(t *testing.T) { | |||
| 66 | 67 | t.Fatalf("channel redirect = %d %q", resp.StatusCode, resp.Header.Get("Location")) | |
| 67 | 68 | } | |
| 68 | 69 | ||
| 69 | // The tree is served from the target release, under the channel name. | ||
| 70 | 70 | resp, err = http.Get(f.http.URL + "/" + f.repo + "/channels/stable/apt/Packages") | |
| 71 | 71 | if err != nil { | |
| 72 | 72 | t.Fatal(err) | |
| @@ -100,10 +100,14 @@ func TestChannelPageAndTree(t *testing.T) { | |||
| 100 | 100 | func TestChannelDanglingTarget(t *testing.T) { | |
| 101 | 101 | t.Parallel() | |
| 102 | 102 | f := releaseFixture(t) | |
| 103 | raw := fmt.Sprintf("---\nrelease: v9.9.9\nrelease_object: %s\nupdated_by: keenan\nupdated_at: %s\n---\n", | ||
| 104 | strings.Repeat("a", 40), time.Now().UTC().Format(time.RFC3339)) | ||
| 105 | meta := f.newMetaRepo(t) | ||
| 106 | if err := meta.apply(map[string]string{"channels/stable.md": raw}, "channel: stable -> v9.9.9"); err != nil { | ||
| 103 | m := mustRepo(t, f) | ||
| 104 | if err := f.srv.Channels.Set(m.ID, channel.Channel{ | ||
| 105 | Name: "stable", | ||
| 106 | Release: "v9.9.9", | ||
| 107 | ReleaseObject: strings.Repeat("a", 40), | ||
| 108 | UpdatedBy: "keenan", | ||
| 109 | UpdatedAt: time.Now().UTC(), | ||
| 110 | }); err != nil { | ||
| 107 | 111 | t.Fatal(err) | |
| 108 | 112 | } | |
| 109 | 113 | ||
| @@ -122,7 +126,7 @@ func TestChannelDanglingTarget(t *testing.T) { | |||
| 122 | 126 | func TestChannelMoveRequiresMaintain(t *testing.T) { | |
| 123 | 127 | t.Parallel() | |
| 124 | 128 | f := releaseFixture(t) | |
| 125 | raw := channelDoc(t, f, "v1.0.0", "carol", "move") | ||
| 129 | work := channelWork(t, f) | ||
| 126 | 130 | ||
| 127 | 131 | pub, priv := keypair(t, filepath.Join(f.cfg.DataDir, "id_contrib")) | |
| 128 | 132 | contrib, err := f.srv.Identity.Create("carol", pub, "test") | |
| @@ -141,14 +145,12 @@ func TestChannelMoveRequiresMaintain(t *testing.T) { | |||
| 141 | 145 | t.Fatal(err) | |
| 142 | 146 | } | |
| 143 | 147 | ||
| 144 | if out, err := pushMetaAs(t, f, priv, map[string]string{"channels/stable.md": raw}, nil, "channel: stable"); err == nil || | ||
| 145 | !strings.Contains(out, "maintain") { | ||
| 146 | t.Fatalf("contributor channel move = %v: %s, want a maintain refusal", err, out) | ||
| 148 | _, errOut, err := f.cliWithKey(priv, work, "release", "channel", "set", "stable", "v1.0.0", "-m", "move") | ||
| 149 | if err == nil || !strings.Contains(errOut, "maintain") { | ||
| 150 | t.Fatalf("contributor channel move = %v: %s, want a maintain refusal", err, errOut) | ||
| 147 | 151 | } | |
| 148 | 152 | ||
| 149 | if _, err := pushMetaAs(t, f, f.addWriter(t), map[string]string{"channels/stable.md": raw}, nil, "channel: stable"); err != nil { | ||
| 150 | t.Fatalf("maintainer channel move: %v", err) | ||
| 151 | } | ||
| 153 | setChannelCLI(t, f, f.addWriter(t), work, "stable", "v1.0.0", "moved") | ||
| 152 | 154 | audit, err := os.ReadFile(f.cfg.AuditLog()) | |
| 153 | 155 | if err != nil { | |
| 154 | 156 | t.Fatal(err) | |
| @@ -169,16 +171,24 @@ func TestChannelFileIsNotPublicOnAPrivateRepo(t *testing.T) { | |||
| 169 | 171 | t.Fatalf("push: %s", errs) | |
| 170 | 172 | } | |
| 171 | 173 | if _, errs, err := runGit(t, work, "tag", "-a", "v1.0.0", "-m", "notes\n"); err != nil { | |
| 172 | t.Fatalf("tag: %s", errs) | ||
| 174 | t.Fatalf("tag: %v: %s", err, errs) | ||
| 173 | 175 | } | |
| 174 | 176 | if _, errs, err := f.git(work, "push", f.sshURL(f.repo), "refs/tags/v1.0.0:refs/tags/v1.0.0"); err != nil { | |
| 175 | 177 | t.Fatalf("push tag: %s", errs) | |
| 176 | 178 | } | |
| 177 | 179 | attachArtifact(t, f, "v1.0.0", "apt/Packages", []byte("Package: vole\n")) | |
| 178 | meta := f.newMetaRepo(t) | ||
| 179 | if err := meta.apply(map[string]string{ | ||
| 180 | "channels/stable.md": channelDoc(t, f, "v1.0.0", "keenan", ""), | ||
| 181 | }, "channel: stable -> v1.0.0"); err != nil { | ||
| 180 | m := mustRepo(t, f) | ||
| 181 | ttag, err := m.Git().Tag("v1.0.0") | ||
| 182 | if err != nil { | ||
| 183 | t.Fatal(err) | ||
| 184 | } | ||
| 185 | if err := f.srv.Channels.Set(m.ID, channel.Channel{ | ||
| 186 | Name: "stable", | ||
| 187 | Release: "v1.0.0", | ||
| 188 | ReleaseObject: ttag.OID, | ||
| 189 | UpdatedBy: "keenan", | ||
| 190 | UpdatedAt: time.Now().UTC(), | ||
| 191 | }); err != nil { | ||
| 182 | 192 | t.Fatal(err) | |
| 183 | 193 | } | |
| 184 | 194 | if code, _ := f.get("/" + f.repo + "/channels/stable/apt/Packages"); code != 404 { | |
| @@ -197,13 +207,7 @@ func TestChannelFileIsNotPublicOnAPrivateRepo(t *testing.T) { | |||
| 197 | 207 | func TestChannelCLI(t *testing.T) { | |
| 198 | 208 | t.Parallel() | |
| 199 | 209 | f := releaseFixture(t) | |
| 200 | work := workRepo(t, map[string]string{"readme.md": "cli\n"}) | ||
| 201 | if _, errs, err := runGit(t, work, "remote", "add", "origin", f.sshURL(f.repo)); err != nil { | ||
| 202 | t.Fatalf("remote: %v: %s", err, errs) | ||
| 203 | } | ||
| 204 | if _, errs, err := f.git(work, "fetch", f.sshURL(f.repo), "refs/tags/v1.0.0:refs/tags/v1.0.0"); err != nil { | ||
| 205 | t.Fatalf("fetch tag: %v: %s", err, errs) | ||
| 206 | } | ||
| 210 | work := channelWork(t, f) | ||
| 207 | 211 | ||
| 208 | 212 | out, errOut, err := f.cli(work, "release", "channel", "set", "stable", "v1.0.0", "-m", "CLI channel") | |
| 209 | 213 | if err != nil { | |