- Runtime channel "candidate" is now "alpha"; configs, the --candidate flag
and SetRuntimeChannel("candidate") still map to alpha.
- ListRemote follows GitHub's Link pagination so stable runtimes are not
pushed off the first page by daily alphas.
- patches/series.txt is the single patch queue for CI and pack-runtime.ps1;
pack-runtime takes -Patches and derives allowed changed files from the
patches (fixes a false "undeclared change" with the coroutine patch).
- build-runtime.yml runs daily: resolves upstream HEAD, skips commits already
released, applies the queue via apply-patch-series.ps1 (skips patches
already upstream, stops on conflicts), gates with check-runtime-alpha.ps1,
publishes an alpha prerelease, keeps the 7 newest alphas, and files issues
on failure or merged patches. Stable promotion stays manual.
- AGENTS.md and runtime docs updated for the alpha channel.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
205 lines
7.0 KiB
Go
205 lines
7.0 KiB
Go
package runtime
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
type fakeGitHub struct {
|
|
srv *httptest.Server
|
|
archive []byte
|
|
sums string
|
|
hits map[string]int
|
|
}
|
|
|
|
func newFakeGitHub(t *testing.T) *fakeGitHub {
|
|
t.Helper()
|
|
g := &fakeGitHub{archive: bytes.Repeat([]byte("reims-runtime-"), 50_000), hits: map[string]int{}}
|
|
sum := sha256.Sum256(g.archive)
|
|
g.sums = hex.EncodeToString(sum[:]) + " reims-runtime-win-x64-abc1234.tar.zst\n"
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/repos/o/r/releases", func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Header.Get("User-Agent") != "reims-go" {
|
|
t.Errorf("User-Agent = %q", r.Header.Get("User-Agent"))
|
|
}
|
|
base := g.srv.URL
|
|
fmt.Fprintf(w, `[
|
|
{"tag_name":"runtime-abc1234","prerelease":true,"published_at":"2026-11-28T10:00:00Z","assets":[
|
|
{"name":"reims-runtime-win-x64-abc1234.tar.zst","size":%d,"browser_download_url":"%s/a/archive"},
|
|
{"name":"reims-runtime-src-abc1234.tar.zst","size":5,"browser_download_url":"%s/a/src"},
|
|
{"name":"SHA256SUMS.txt","size":90,"browser_download_url":"%s/a/sums"}]},
|
|
{"tag_name":"runtime-0000old","prerelease":false,"published_at":"2026-10-01T00:00:00Z","assets":[
|
|
{"name":"reims-runtime-win-x64-0000old.tar.zst","size":1,"browser_download_url":"%s/a/x"},
|
|
{"name":"reims-runtime-src-0000old.tar.zst","size":1,"browser_download_url":"%s/a/x"},
|
|
{"name":"SHA256SUMS.txt","size":1,"browser_download_url":"%s/a/x"}]},
|
|
{"tag_name":"runtime-nosrc00","prerelease":false,"published_at":"2026-11-01T00:00:00Z","assets":[
|
|
{"name":"reims-runtime-win-x64-nosrc00.tar.zst","size":1,"browser_download_url":"%s/a/x"},
|
|
{"name":"SHA256SUMS.txt","size":1,"browser_download_url":"%s/a/x"}]},
|
|
{"tag_name":"runtime-draft00","draft":true,"assets":[]},
|
|
{"tag_name":"v0.1.0","prerelease":false,"assets":[]}
|
|
]`, len(g.archive), base, base, base, base, base, base, base, base)
|
|
})
|
|
mux.HandleFunc("/a/archive", func(w http.ResponseWriter, r *http.Request) {
|
|
g.hits["archive"]++
|
|
if r.Header.Get("Range") != "" {
|
|
g.hits["range"]++
|
|
}
|
|
http.ServeContent(w, r, "a.tar.zst", time.Time{}, bytes.NewReader(g.archive))
|
|
})
|
|
mux.HandleFunc("/a/sums", func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, g.sums) })
|
|
g.srv = httptest.NewServer(mux)
|
|
t.Cleanup(g.srv.Close)
|
|
return g
|
|
}
|
|
|
|
func (g *fakeGitHub) source() Source {
|
|
return Source{APIBase: g.srv.URL, Repo: "o/r", Client: g.srv.Client()}
|
|
}
|
|
|
|
func TestListRemoteFiltersChannelsAndIncompleteReleases(t *testing.T) {
|
|
g := newFakeGitHub(t)
|
|
stable, err := g.source().ListRemote(context.Background(), false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(stable) != 1 || stable[0].Commit != "0000old" || stable[0].Channel != ChannelStable {
|
|
t.Fatalf("stable only = %+v", stable)
|
|
}
|
|
all, err := g.source().ListRemote(context.Background(), true)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(all) != 2 || all[0].Commit != "abc1234" || all[0].Channel != ChannelAlpha || all[0].SourceName == "" {
|
|
t.Fatalf("with alpha = %+v", all)
|
|
}
|
|
if r, err := Pick(all, "abc"); err != nil || r.Commit != "abc1234" {
|
|
t.Fatalf("pick prefix: %v %v", r, err)
|
|
}
|
|
if r, _ := Pick(all, "latest"); r.Commit != "abc1234" {
|
|
t.Fatalf("latest = %v", r)
|
|
}
|
|
if _, err := Pick(nil, ""); err == nil {
|
|
t.Fatal("empty list")
|
|
}
|
|
}
|
|
|
|
func TestDownloadResumesAndVerifies(t *testing.T) {
|
|
g := newFakeGitHub(t)
|
|
src := g.source()
|
|
list, _ := src.ListRemote(context.Background(), true)
|
|
r := list[0]
|
|
dir := t.TempDir()
|
|
|
|
// A previous run left the first 100 KB.
|
|
part := filepath.Join(dir, r.ArchiveName+".part")
|
|
os.WriteFile(part, g.archive[:100_000], 0o644)
|
|
|
|
var last int64
|
|
path, err := src.Download(context.Background(), r, dir, func(done, total int64) {
|
|
if total != int64(len(g.archive)) {
|
|
t.Errorf("total = %d", total)
|
|
}
|
|
last = done
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if g.hits["range"] != 1 {
|
|
t.Fatalf("expected a ranged request, hits=%v", g.hits)
|
|
}
|
|
if last != int64(len(g.archive)) {
|
|
t.Fatalf("last progress = %d", last)
|
|
}
|
|
got, _ := os.ReadFile(path)
|
|
if !bytes.Equal(got, g.archive) {
|
|
t.Fatal("archive content differs")
|
|
}
|
|
if _, err := os.Stat(part); !os.IsNotExist(err) {
|
|
t.Fatal(".part left behind")
|
|
}
|
|
|
|
// Already there and valid: no new request.
|
|
before := g.hits["archive"]
|
|
if _, err := src.Download(context.Background(), r, dir, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if g.hits["archive"] != before {
|
|
t.Fatal("re-downloaded a verified archive")
|
|
}
|
|
}
|
|
|
|
func TestDownloadRejectsAWrongChecksum(t *testing.T) {
|
|
g := newFakeGitHub(t)
|
|
g.sums = strings.Repeat("0", 64) + " reims-runtime-win-x64-abc1234.tar.zst\n"
|
|
list, _ := g.source().ListRemote(context.Background(), true)
|
|
dir := t.TempDir()
|
|
_, err := g.source().Download(context.Background(), list[0], dir, nil)
|
|
if err == nil || !strings.Contains(err.Error(), "SHA256 mismatch") {
|
|
t.Fatalf("err = %v", err)
|
|
}
|
|
entries, _ := os.ReadDir(dir)
|
|
if len(entries) != 0 {
|
|
t.Fatalf("bad download kept: %v", entries)
|
|
}
|
|
}
|
|
|
|
func TestListRemoteFollowsPagination(t *testing.T) {
|
|
mux := http.NewServeMux()
|
|
var srv *httptest.Server
|
|
release := func(commit string, pre bool) string {
|
|
return fmt.Sprintf(`{"tag_name":"runtime-%[1]s","prerelease":%[2]t,"published_at":"2026-11-%[3]sT00:00:00Z","assets":[
|
|
{"name":"reims-runtime-win-x64-%[1]s.tar.zst","size":1,"browser_download_url":"x"},
|
|
{"name":"reims-runtime-src-%[1]s.tar.zst","size":1,"browser_download_url":"x"},
|
|
{"name":"SHA256SUMS.txt","size":1,"browser_download_url":"x"}]}`, commit, pre, commit[:2])
|
|
}
|
|
mux.HandleFunc("/repos/o/r/releases", func(w http.ResponseWriter, r *http.Request) {
|
|
switch r.URL.Query().Get("page") {
|
|
case "":
|
|
w.Header().Set("Link", fmt.Sprintf(`<%s/repos/o/r/releases?per_page=100&page=2>; rel="next", <%s/repos/o/r/releases?per_page=100&page=2>; rel="last"`, srv.URL, srv.URL))
|
|
fmt.Fprint(w, "["+release("20alpha", true)+"]")
|
|
case "2":
|
|
// The stable runtime sits on the second page, behind newer alphas.
|
|
fmt.Fprint(w, "["+release("10stabl", false)+"]")
|
|
default:
|
|
t.Errorf("unexpected page %q", r.URL.RawQuery)
|
|
}
|
|
})
|
|
srv = httptest.NewServer(mux)
|
|
defer srv.Close()
|
|
src := Source{APIBase: srv.URL, Repo: "o/r", Client: srv.Client()}
|
|
list, err := src.ListRemote(context.Background(), false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(list) != 1 || list[0].Commit != "10stabl" {
|
|
t.Fatalf("stable across pages = %+v", list)
|
|
}
|
|
}
|
|
|
|
func TestNextLinkStaysOnAPIHost(t *testing.T) {
|
|
if got := nextLink(`<https://api.github.com/x?page=2>; rel="next", <https://api.github.com/x?page=9>; rel="last"`); got != "https://api.github.com/x?page=2" {
|
|
t.Fatalf("nextLink = %q", got)
|
|
}
|
|
if got := nextLink(`<https://api.github.com/x?page=9>; rel="last"`); got != "" {
|
|
t.Fatalf("no next: %q", got)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeChannel(t *testing.T) {
|
|
for in, want := range map[string]string{"": ChannelStable, "stable": ChannelStable, "alpha": ChannelAlpha, "candidate": ChannelAlpha, " Alpha ": ChannelAlpha, "beta": ChannelStable} {
|
|
if got := NormalizeChannel(in); got != want {
|
|
t.Errorf("NormalizeChannel(%q) = %q, want %q", in, got, want)
|
|
}
|
|
}
|
|
}
|