Releases publish only two things per tool now: a current-stable
canonical symlink and an immutable per-version file. No more channel
mirrors (_stable/_beta/_alpha) and no more partial-version pins
(_v<X.Y>, _v<X>) — those were debt from a release model that never
matched the project's actual usage.
The `./build beta` verb stays, but narrowed: it's an internal SHA
snapshot for the BMC dev chart pipeline (chart's appVersion pins to
"<X.Y.Z>-beta-<sha>" and the chart Dockerfile fetches that SHA from
git). No public artifact on /srv/zddc/releases/. The embedded/* +
chore commit produced by `./build beta` is the actual snapshot.
`./build alpha` is removed entirely.
build/build-lib.sh:
- Drop alpha verb; narrow beta verb to embedded regen + chore commit
- promote_release: stable cut writes <tool>_v<X.Y.Z>.html + <tool>.html
symlink + <tool>.html.sig companion symlink; beta is a no-op
- promote_zddc_server: same shape — per-version binary +
per-platform canonical symlink (zddc-server_<plat>) + .sig symlink
- write_zddc_server_stub: singular; emits per-version stubs +
one canonical zddc-server.html for current stable
- Delete _promote_channel, verify_channel_links, _channel_is_active
- Seed-from-live now copies only per-version files + .sig + pubkey.pem
(the canonical symlinks get rewritten by this cut; old layout files
get cleaned by deploy's --delete-after)
- build_releases_index: dropdown simplified to "latest stable +
pinned versions"; channels-explainer section removed; tool cards +
CTA URLs point at canonical <tool>.html / zddc-server_<plat>;
composer emits "stable" sentinel for `apps:` entries
- Fix the acl:{allow:[...]} footgun in the apps_pubkey example
apps.go:
- isValidChannelOrVersion: accept only "stable" + exact X.Y.Z
(drop alpha/beta and partial pins v0.0/v0)
- normalizeChannel: same
- Resolve URL composition: stable → canonical <prefix>/<app>.html
(no _stable_ suffix), exact-version → <prefix>/<app>_v<X.Y.Z>.html
- Tests rewritten to match (beta/alpha replaced with v0.0.4 / stable;
a new TestParseSpec_RejectsLegacyChannelsAndPartialPins locks in
that the removed forms now error)
browse/build.sh: gate promote_release on $is_release like every other
tool's build.sh (longstanding inconsistency that errored under the new
promote_release case-statement).
freshen-channel: deleted (no channels to freshen).
Net: -254 lines, all green on full `go test ./...`. Dev build verified
via `./build` (no-arg) — new label format "v<next>-dev · <ts> · <sha>".
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
438 lines
13 KiB
Go
438 lines
13 KiB
Go
package apps
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"codeberg.org/VARASYS/ZDDC/zddc/internal/zddc"
|
|
)
|
|
|
|
// ── ParseSpec ────────────────────────────────────────────────────────────
|
|
|
|
func TestParseSpec_Channels(t *testing.T) {
|
|
// "stable" is the only channel alias (latest stable). beta and alpha
|
|
// channels no longer exist as public concepts.
|
|
cases := []struct {
|
|
spec, wantChan string
|
|
}{
|
|
{"stable", "stable"},
|
|
{":stable", "stable"},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.spec, func(t *testing.T) {
|
|
c, err := ParseSpec(tc.spec, "/root", "/root")
|
|
if err != nil {
|
|
t.Fatalf("ParseSpec error: %v", err)
|
|
}
|
|
if c.Channel != tc.wantChan {
|
|
t.Errorf("got Channel=%q, want %q", c.Channel, tc.wantChan)
|
|
}
|
|
if c.URLPrefix != "" || c.Path != "" || c.FullURL != "" {
|
|
t.Errorf("expected channel-only, got %+v", c)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSpec_Versions(t *testing.T) {
|
|
// Exact-version pins only. Partial pins (v0.0, v0) no longer exist
|
|
// — the upstream publishes <tool>.html (current stable) and
|
|
// <tool>_v<X.Y.Z>.html (exact-version immutable). Bare "0.0.4"
|
|
// (no v prefix) is normalized to "v0.0.4".
|
|
cases := []struct {
|
|
spec, wantChan string
|
|
}{
|
|
{"v0.0.4", "v0.0.4"},
|
|
{"0.0.4", "v0.0.4"},
|
|
{":v0.0.4", "v0.0.4"},
|
|
{":0.0.4", "v0.0.4"},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.spec, func(t *testing.T) {
|
|
c, err := ParseSpec(tc.spec, "/root", "/root")
|
|
if err != nil {
|
|
t.Fatalf("ParseSpec error: %v", err)
|
|
}
|
|
if c.Channel != tc.wantChan {
|
|
t.Errorf("got Channel=%q, want %q", c.Channel, tc.wantChan)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSpec_RejectsLegacyChannelsAndPartialPins(t *testing.T) {
|
|
// alpha/beta channels and partial-version pins are no longer valid.
|
|
rejected := []string{"alpha", "beta", ":alpha", ":beta", "v0.0", "v0", "0.0", "0", ":v0.0"}
|
|
for _, spec := range rejected {
|
|
t.Run(spec, func(t *testing.T) {
|
|
_, err := ParseSpec(spec, "/root", "/root")
|
|
if err == nil {
|
|
t.Errorf("expected error for %q, got none", spec)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSpec_URLPrefix(t *testing.T) {
|
|
cases := []struct {
|
|
spec, wantPrefix, wantChan string
|
|
}{
|
|
{"https://my-mirror.example/releases", "https://my-mirror.example/releases", ""},
|
|
{"https://my-mirror.example/releases/", "https://my-mirror.example/releases", ""}, // trailing slash stripped
|
|
{"https://my-mirror.example/releases:stable", "https://my-mirror.example/releases", "stable"},
|
|
{"https://my-mirror.example/releases:v0.0.4", "https://my-mirror.example/releases", "v0.0.4"},
|
|
// Port colon must NOT be confused with channel separator.
|
|
{"https://my-mirror.example:8080/releases", "https://my-mirror.example:8080/releases", ""},
|
|
{"https://my-mirror.example:8080/releases:stable", "https://my-mirror.example:8080/releases", "stable"},
|
|
// Colon embedded in path before final slash — treated as part of path.
|
|
{"https://host/some:thing/releases", "https://host/some:thing/releases", ""},
|
|
{"https://host/some:thing/releases:v0.0.4", "https://host/some:thing/releases", "v0.0.4"},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.spec, func(t *testing.T) {
|
|
c, err := ParseSpec(tc.spec, "/root", "/root")
|
|
if err != nil {
|
|
t.Fatalf("ParseSpec error: %v", err)
|
|
}
|
|
if c.URLPrefix != tc.wantPrefix {
|
|
t.Errorf("got URLPrefix=%q, want %q", c.URLPrefix, tc.wantPrefix)
|
|
}
|
|
if c.Channel != tc.wantChan {
|
|
t.Errorf("got Channel=%q, want %q", c.Channel, tc.wantChan)
|
|
}
|
|
if c.Path != "" || c.FullURL != "" {
|
|
t.Errorf("expected non-terminal, got %+v", c)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSpec_FullURL(t *testing.T) {
|
|
c, err := ParseSpec("https://my-fork.example/archive.html", "/root", "/root")
|
|
if err != nil {
|
|
t.Fatalf("ParseSpec error: %v", err)
|
|
}
|
|
if c.FullURL != "https://my-fork.example/archive.html" {
|
|
t.Errorf("got FullURL=%q", c.FullURL)
|
|
}
|
|
if !c.IsTerminal() {
|
|
t.Errorf("expected terminal")
|
|
}
|
|
}
|
|
|
|
func TestParseSpec_FullURLWithChannelSuffixRejected(t *testing.T) {
|
|
_, err := ParseSpec("https://my-fork.example/archive.html:stable", "/root", "/root")
|
|
if err == nil {
|
|
t.Errorf("expected error for .html URL with :suffix")
|
|
}
|
|
}
|
|
|
|
func TestParseSpec_Paths(t *testing.T) {
|
|
root := t.TempDir()
|
|
zddcDir := filepath.Join(root, "Project-X")
|
|
cases := []struct {
|
|
spec string
|
|
wantOK bool
|
|
wantPath string
|
|
}{
|
|
{"./local.html", true, filepath.Join(zddcDir, "local.html")},
|
|
{"../sibling.html", true, filepath.Join(root, "sibling.html")},
|
|
{filepath.Join(root, "abs.html"), true, filepath.Join(root, "abs.html")},
|
|
{"/etc/passwd", false, ""},
|
|
{"../../../escape.html", false, ""},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.spec, func(t *testing.T) {
|
|
c, err := ParseSpec(tc.spec, zddcDir, root)
|
|
if tc.wantOK {
|
|
if err != nil {
|
|
t.Fatalf("want success, got error: %v", err)
|
|
}
|
|
if c.Path != tc.wantPath {
|
|
t.Errorf("got Path=%q, want %q", c.Path, tc.wantPath)
|
|
}
|
|
if !c.IsTerminal() {
|
|
t.Errorf("expected terminal")
|
|
}
|
|
} else {
|
|
if err == nil {
|
|
t.Errorf("want error, got %+v", c)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSpec_Errors(t *testing.T) {
|
|
cases := []string{
|
|
"",
|
|
"weird-thing",
|
|
":",
|
|
":weird",
|
|
"v",
|
|
"v0.0.0.0",
|
|
"v0.a.0",
|
|
"https://", // missing host
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc, func(t *testing.T) {
|
|
_, err := ParseSpec(tc, "/root", "/root")
|
|
if err == nil {
|
|
t.Errorf("ParseSpec(%q) = nil, want error", tc)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// ── Resolve ──────────────────────────────────────────────────────────────
|
|
|
|
func TestResolve_NoEntries(t *testing.T) {
|
|
chain := zddc.PolicyChain{Levels: []zddc.ZddcFile{{}}}
|
|
_, has, err := Resolve(chain, "archive", t.TempDir(), t.TempDir())
|
|
if err != nil {
|
|
t.Fatalf("Resolve: %v", err)
|
|
}
|
|
if has {
|
|
t.Errorf("got override=true, want false")
|
|
}
|
|
}
|
|
|
|
func TestResolve_PerAppChannelOnly(t *testing.T) {
|
|
root := t.TempDir()
|
|
chain := zddc.PolicyChain{Levels: []zddc.ZddcFile{{
|
|
Apps: map[string]string{"archive": "stable"},
|
|
}}}
|
|
src, has, err := Resolve(chain, "archive", root, root)
|
|
if err != nil || !has {
|
|
t.Fatalf("has=%v err=%v", has, err)
|
|
}
|
|
// stable channel → canonical URL (no _stable_ suffix); the upstream
|
|
// publishes a symlink at this URL pointing at the latest version.
|
|
want := DefaultUpstreamReleases + "/archive.html"
|
|
if src.URL != want {
|
|
t.Errorf("got URL=%q, want %q", src.URL, want)
|
|
}
|
|
}
|
|
|
|
func TestResolve_PerAppVersionOnly(t *testing.T) {
|
|
root := t.TempDir()
|
|
chain := zddc.PolicyChain{Levels: []zddc.ZddcFile{{
|
|
Apps: map[string]string{"archive": "v0.0.4"},
|
|
}}}
|
|
src, _, err := Resolve(chain, "archive", root, root)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := DefaultUpstreamReleases + "/archive_v0.0.4.html"
|
|
if src.URL != want {
|
|
t.Errorf("got URL=%q, want %q", src.URL, want)
|
|
}
|
|
}
|
|
|
|
func TestResolve_DefaultProvidesURLAndChannel(t *testing.T) {
|
|
root := t.TempDir()
|
|
chain := zddc.PolicyChain{Levels: []zddc.ZddcFile{{
|
|
Apps: map[string]string{
|
|
"default": "https://mirror.example/releases:v0.0.4",
|
|
},
|
|
}}}
|
|
src, has, err := Resolve(chain, "archive", root, root)
|
|
if err != nil || !has {
|
|
t.Fatalf("has=%v err=%v", has, err)
|
|
}
|
|
if src.URL != "https://mirror.example/releases/archive_v0.0.4.html" {
|
|
t.Errorf("got URL=%q", src.URL)
|
|
}
|
|
}
|
|
|
|
func TestResolve_DefaultPlusPerAppChannelOverride(t *testing.T) {
|
|
// default=https://zddc.varasys.io/releases:stable, classifier=:v0.0.4
|
|
// → classifier pinned to v0.0.4 on the same mirror.
|
|
root := t.TempDir()
|
|
chain := zddc.PolicyChain{Levels: []zddc.ZddcFile{{
|
|
Apps: map[string]string{
|
|
"default": "https://zddc.varasys.io/releases:stable",
|
|
"classifier": ":v0.0.4",
|
|
},
|
|
}}}
|
|
src, _, err := Resolve(chain, "classifier", root, root)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if src.URL != "https://zddc.varasys.io/releases/classifier_v0.0.4.html" {
|
|
t.Errorf("got URL=%q", src.URL)
|
|
}
|
|
}
|
|
|
|
func TestResolve_DefaultPlusPerAppURLPrefixOverride(t *testing.T) {
|
|
// default=...:stable, archive=https://my.local.stuff/releases
|
|
// → custom URL + default channel (stable, canonical filename).
|
|
root := t.TempDir()
|
|
chain := zddc.PolicyChain{Levels: []zddc.ZddcFile{{
|
|
Apps: map[string]string{
|
|
"default": "https://zddc.varasys.io/releases:stable",
|
|
"archive": "https://my.local.stuff/releases",
|
|
},
|
|
}}}
|
|
src, _, err := Resolve(chain, "archive", root, root)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if src.URL != "https://my.local.stuff/releases/archive.html" {
|
|
t.Errorf("got URL=%q", src.URL)
|
|
}
|
|
}
|
|
|
|
func TestResolve_DeeperLevelOverridesParentChannel(t *testing.T) {
|
|
root := t.TempDir()
|
|
requestDir := filepath.Join(root, "Project-A")
|
|
chain := zddc.PolicyChain{Levels: []zddc.ZddcFile{
|
|
{Apps: map[string]string{"default": ":stable"}},
|
|
{Apps: map[string]string{"default": ":v0.0.4"}},
|
|
}}
|
|
src, _, err := Resolve(chain, "archive", root, requestDir)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := DefaultUpstreamReleases + "/archive_v0.0.4.html"
|
|
if src.URL != want {
|
|
t.Errorf("got URL=%q, want %q", src.URL, want)
|
|
}
|
|
}
|
|
|
|
func TestResolve_DeeperLevelOverridesParentURL(t *testing.T) {
|
|
root := t.TempDir()
|
|
requestDir := filepath.Join(root, "Project-A")
|
|
chain := zddc.PolicyChain{Levels: []zddc.ZddcFile{
|
|
{Apps: map[string]string{"default": "https://a.example/releases:stable"}},
|
|
{Apps: map[string]string{"default": "https://b.example/releases"}},
|
|
}}
|
|
src, _, err := Resolve(chain, "archive", root, requestDir)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// b.example URL prefix wins; channel inherited (stable → canonical
|
|
// filename, no _stable_ suffix).
|
|
want := "https://b.example/releases/archive.html"
|
|
if src.URL != want {
|
|
t.Errorf("got URL=%q, want %q", src.URL, want)
|
|
}
|
|
}
|
|
|
|
func TestResolve_TerminalAtLeafBeatsParentDefault(t *testing.T) {
|
|
root := t.TempDir()
|
|
requestDir := filepath.Join(root, "Project-A")
|
|
chain := zddc.PolicyChain{Levels: []zddc.ZddcFile{
|
|
{Apps: map[string]string{"default": "https://a.example/releases:stable"}},
|
|
{Apps: map[string]string{"archive": "https://my-fork.example/archive.html"}},
|
|
}}
|
|
src, _, err := Resolve(chain, "archive", root, requestDir)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if src.URL != "https://my-fork.example/archive.html" {
|
|
t.Errorf("got URL=%q (want terminal full URL)", src.URL)
|
|
}
|
|
}
|
|
|
|
func TestResolve_DeeperNonTerminalOverridesParentTerminal(t *testing.T) {
|
|
root := t.TempDir()
|
|
requestDir := filepath.Join(root, "Project-A")
|
|
chain := zddc.PolicyChain{Levels: []zddc.ZddcFile{
|
|
{Apps: map[string]string{"archive": "https://a.example/archive.html"}}, // terminal
|
|
{Apps: map[string]string{"archive": "v0.0.4"}}, // non-terminal
|
|
}}
|
|
src, _, err := Resolve(chain, "archive", root, requestDir)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := DefaultUpstreamReleases + "/archive_v0.0.4.html"
|
|
if src.URL != want {
|
|
t.Errorf("got URL=%q, want %q", src.URL, want)
|
|
}
|
|
}
|
|
|
|
func TestResolve_PathSourceTerminal(t *testing.T) {
|
|
root := t.TempDir()
|
|
projDir := filepath.Join(root, "Project-X")
|
|
chain := zddc.PolicyChain{Levels: []zddc.ZddcFile{
|
|
{},
|
|
{Apps: map[string]string{"archive": "./our-archive.html"}},
|
|
}}
|
|
src, _, err := Resolve(chain, "archive", root, projDir)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if src.URL != "" {
|
|
t.Errorf("got URL=%q, want empty", src.URL)
|
|
}
|
|
want := filepath.Join(projDir, "our-archive.html")
|
|
if src.Path != want {
|
|
t.Errorf("got Path=%q, want %q", src.Path, want)
|
|
}
|
|
}
|
|
|
|
func TestResolve_PerAppOverridesDefaultAtSameLevel(t *testing.T) {
|
|
root := t.TempDir()
|
|
chain := zddc.PolicyChain{Levels: []zddc.ZddcFile{{
|
|
Apps: map[string]string{
|
|
"default": "https://a.example/releases:stable",
|
|
"archive": "https://b.example/archive.html", // terminal — wins for archive only
|
|
},
|
|
}}}
|
|
src, _, err := Resolve(chain, "archive", root, root)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if src.URL != "https://b.example/archive.html" {
|
|
t.Errorf("got URL=%q (want b.example terminal)", src.URL)
|
|
}
|
|
|
|
// Other apps still use the default.
|
|
src2, _, err := Resolve(chain, "classifier", root, root)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if src2.URL != "https://a.example/releases/classifier.html" {
|
|
t.Errorf("got classifier URL=%q (want a.example default)", src2.URL)
|
|
}
|
|
}
|
|
|
|
func TestResolve_BadSpecBubblesError(t *testing.T) {
|
|
root := t.TempDir()
|
|
chain := zddc.PolicyChain{Levels: []zddc.ZddcFile{{
|
|
Apps: map[string]string{"archive": "this is garbage"},
|
|
}}}
|
|
_, _, err := Resolve(chain, "archive", root, root)
|
|
if err == nil {
|
|
t.Errorf("expected error")
|
|
}
|
|
}
|
|
|
|
func TestResolve_UnknownAppRejected(t *testing.T) {
|
|
root := t.TempDir()
|
|
_, _, err := Resolve(zddc.PolicyChain{}, "unknown", root, root)
|
|
if err == nil {
|
|
t.Errorf("expected error")
|
|
}
|
|
}
|
|
|
|
// ── PreviewLine ──────────────────────────────────────────────────────────
|
|
|
|
func TestPreviewLine(t *testing.T) {
|
|
root := t.TempDir()
|
|
t.Run("no entries → embedded", func(t *testing.T) {
|
|
got := PreviewLine(zddc.PolicyChain{Levels: []zddc.ZddcFile{{}}}, "archive", root, root)
|
|
if !strings.Contains(got, "embedded") {
|
|
t.Errorf("got %q", got)
|
|
}
|
|
})
|
|
t.Run("default channel → URL", func(t *testing.T) {
|
|
chain := zddc.PolicyChain{Levels: []zddc.ZddcFile{{Apps: map[string]string{"default": ":v0.0.4"}}}}
|
|
got := PreviewLine(chain, "archive", root, root)
|
|
if !strings.Contains(got, "archive_v0.0.4.html") {
|
|
t.Errorf("got %q", got)
|
|
}
|
|
})
|
|
}
|