diff --git a/README.md b/README.md index 29085d370bc40da2fac076b37ead6ffdbfd62764..18a0801bf7884605b8017cc89542d2b8cd736a8a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # sr-ht-ecore Extended core for the custom services of a self-hosted SourceHut instance -(compare, spec, dolt, cover, bench, ...). Everything these services share that +(diff, spec, dolt, cover, bench, ...). Everything these services share that is *ours* — not upstream's — lives here, so the sr-ht-core fork can stay a clean mirror of upstream core-go, and so the services stop carrying drifting copies of the same code. @@ -111,7 +111,7 @@ ## Usage: chrome ```go -svc := chrome.NewService(conf, "compare.sr.ht") +svc := chrome.NewService(conf, "diff.sr.ht") svc.StyleHref = cssHref // after discovering the hashed stylesheet svc.Assets = map[string]string{"bundle.js": bundleHref} // any further artefacts @@ -180,7 +180,7 @@ cssHref, err := assets.Resolve(webFS, "static/main.min.*.css", assets.DefaultPrefix) // err is a malformed glob, not a missing stylesheet: absent resolves to "". -svc := chrome.NewService(conf, "compare.sr.ht") +svc := chrome.NewService(conf, "diff.sr.ht") svc.StyleHref = cssHref set, err := pages.Load(webFS, pages.Options{Funcs: myHelpers}) @@ -210,8 +210,8 @@ ```go func TestMain(m *testing.M) { ecoretest.InitCrypto(); os.Exit(m.Run()) } -conf := ecoretest.Config("compare.sr.ht") -noHub := ecoretest.Config("compare.sr.ht", ecoretest.Delete("hub.sr.ht")) +conf := ecoretest.Config("diff.sr.ht") +noHub := ecoretest.Config("diff.sr.ht", ecoretest.Delete("hub.sr.ht")) ``` ## Policy: chrome diff --git a/chrome/chrome.go b/chrome/chrome.go index 49f09983efd3d3362273b42789f9a26d77f8244b..c9198c6b9298c7d1a6ecaf5f51789a9ce016c587 100644 --- a/chrome/chrome.go +++ b/chrome/chrome.go @@ -1,5 +1,5 @@ // Package chrome is the shared page chrome for the custom services of a -// self-hosted SourceHut instance (compare, spec, dolt, cover, bench, ...). +// self-hosted SourceHut instance (diff, spec, dolt, cover, bench, ...). // // Every one of those services renders the same top strip: the brand (circle // icon + site name + red service label), the service switcher derived from the @@ -10,7 +10,7 @@ // const active checks, divergent hub handling). This package is the one copy. // // Usage: // -// svc := chrome.NewService(conf, "compare.sr.ht") +// svc := chrome.NewService(conf, "diff.sr.ht") // svc.StyleHref = cssHref // after discovering the hashed stylesheet // page := svc.Page(r, "My title", username) // @@ -208,7 +208,7 @@ // Service is the static half of the chrome, built once at startup. The // exported fields may be adjusted between NewService and the first Page call // (they are read, never written, by Page). type Service struct { - // Section is the literal config section, e.g. "compare.sr.ht". + // Section is the literal config section, e.g. "diff.sr.ht". Section string // StyleHref is the href of the built stylesheet (the hashed // main.min..css); the zero value renders a bare page rather than diff --git a/chrome/chrome_test.go b/chrome/chrome_test.go index a0eb033053176bd4c4e46e3a34a9ce7074c26d94..d58842ba3ef0069d2a82a9720c249ce7776aa89f 100644 --- a/chrome/chrome_test.go +++ b/chrome/chrome_test.go @@ -20,22 +20,22 @@ "sr.ht": { "site-name": "srht.example", "environment": "production", }, - "meta.sr.ht": {"origin": "https://meta.example"}, - "git.sr.ht": {"origin": "https://git.example"}, - "todo.sr.ht": {"origin": "https://todo.example"}, - "builds.sr.ht": {"origin": "https://builds.example"}, - "hub.sr.ht": {"origin": "https://hub.example"}, - "paste.sr.ht": {"origin": "https://paste.example"}, - "pages.sr.ht": {"origin": "https://pages.example"}, - "compare.sr.ht": {"origin": "https://compare.example"}, - "dolt.sr.ht": {"origin": "https://dolt.example"}, - "ghost.sr.ht": {}, // no origin -> must not appear - "webhooks": {"private-key": "x"}, + "meta.sr.ht": {"origin": "https://meta.example"}, + "git.sr.ht": {"origin": "https://git.example"}, + "todo.sr.ht": {"origin": "https://todo.example"}, + "builds.sr.ht": {"origin": "https://builds.example"}, + "hub.sr.ht": {"origin": "https://hub.example"}, + "paste.sr.ht": {"origin": "https://paste.example"}, + "pages.sr.ht": {"origin": "https://pages.example"}, + "diff.sr.ht": {"origin": "https://diff.example"}, + "dolt.sr.ht": {"origin": "https://dolt.example"}, + "ghost.sr.ht": {}, // no origin -> must not appear + "webhooks": {"private-key": "x"}, } } func TestBuildNavOrderExclusionsActive(t *testing.T) { - nav := BuildNav(testConf(), "compare.sr.ht") + nav := BuildNav(testConf(), "diff.sr.ht") var names []string for _, it := range nav { @@ -43,24 +43,24 @@ names = append(names, it.Name) } // Canonical services first in canonical order, customs alphabetical after; // hub/paste/pages and the origin-less section excluded. - assert.Equal(t, []string{"git", "todo", "builds", "meta", "compare", "dolt"}, names) + assert.Equal(t, []string{"git", "todo", "builds", "meta", "diff", "dolt"}, names) for _, it := range nav { - assert.Equal(t, it.Name == "compare", it.Active, "active flag for %s", it.Name) + assert.Equal(t, it.Name == "diff", it.Active, "active flag for %s", it.Name) } } func TestPageURLsAndIdentity(t *testing.T) { - svc := NewService(testConf(), "compare.sr.ht") + svc := NewService(testConf(), "diff.sr.ht") r := httptest.NewRequest("GET", "/~alice/demo?a=1", nil) p := svc.Page(r, "t", "alice") assert.Equal(t, "srht.example", p.SiteName) - assert.Equal(t, "compare", p.SiteLabel) + assert.Equal(t, "diff", p.SiteLabel) assert.Equal(t, "https://meta.example/login?return_to="+ - "https%3A%2F%2Fcompare.example%2F~alice%2Fdemo%3Fa%3D1", p.LoginURL) + "https%3A%2F%2Fdiff.example%2F~alice%2Fdemo%3Fa%3D1", p.LoginURL) assert.Equal(t, "https://meta.example/logout?return_to="+ - "https%3A%2F%2Fcompare.example", p.LogoutURL) + "https%3A%2F%2Fdiff.example", p.LogoutURL) // Hub is configured, so the profile link prefers hub's ~username page. assert.Equal(t, "https://hub.example/~alice", p.ProfileURL) assert.Equal(t, "container", p.ContainerClass) @@ -70,19 +70,19 @@ func TestPageProfileFallsBackToMeta(t *testing.T) { conf := testConf() delete(conf, "hub.sr.ht") - svc := NewService(conf, "compare.sr.ht") + svc := NewService(conf, "diff.sr.ht") r := httptest.NewRequest("GET", "/", nil) assert.Equal(t, "https://meta.example/profile", svc.Page(r, "t", "alice").ProfileURL) // Anonymous viewers get the meta profile link regardless of hub. assert.Equal(t, "https://meta.example/profile", - NewService(testConf(), "compare.sr.ht").Page(r, "t", "").ProfileURL) + NewService(testConf(), "diff.sr.ht").Page(r, "t", "").ProfileURL) } func TestPageEnvBanner(t *testing.T) { conf := testConf() conf["sr.ht"]["environment"] = "staging" - svc := NewService(conf, "compare.sr.ht") + svc := NewService(conf, "diff.sr.ht") p := svc.Page(httptest.NewRequest("GET", "/", nil), "t", "") assert.True(t, p.ShowBanner) @@ -102,7 +102,7 @@ return b.String() } func TestNavTemplateLoggedIn(t *testing.T) { - svc := NewService(testConf(), "compare.sr.ht") + svc := NewService(testConf(), "diff.sr.ht") svc.ExtraNav = []NavItem{{Name: "tokens", Origin: "/tokens"}} p := svc.Page(httptest.NewRequest("GET", "/", nil), "t", "alice") @@ -110,7 +110,7 @@ out := render(t, p) assert.Contains(t, out, "icon icon-circle") // The brand is two links: the site name to hub, the red label to us. assert.Contains(t, out, `srht.example`) - assert.Contains(t, out, `compare`) + assert.Contains(t, out, `diff`) assert.Contains(t, out, `href="https://git.example"`) assert.Contains(t, out, `href="/tokens"`, "extra nav entries must render") assert.Contains(t, out, "Logged in as") @@ -118,7 +118,7 @@ assert.NotContains(t, out, "ENVIRONMENT") } func TestNavTemplateAnonymous(t *testing.T) { - svc := NewService(testConf(), "compare.sr.ht") + svc := NewService(testConf(), "diff.sr.ht") p := svc.Page(httptest.NewRequest("GET", "/", nil), "t", "") out := render(t, p) @@ -134,11 +134,11 @@ // brand becomes two links to the same place rather than a dead one. func TestNavBrandWithoutHub(t *testing.T) { conf := testConf() delete(conf, "hub.sr.ht") - svc := NewService(conf, "compare.sr.ht") + svc := NewService(conf, "diff.sr.ht") out := render(t, svc.Page(httptest.NewRequest("GET", "/", nil), "t", "alice")) assert.Contains(t, out, `srht.example`) - assert.Contains(t, out, `compare`) + assert.Contains(t, out, `diff`) } // TestNavTemplateEmbeddedPage guards the documented consumption pattern: a @@ -245,12 +245,12 @@ // TestLoginURLForMatchesTheNav guards the whole reason the accessor exists: a // handler redirecting to login must land the viewer exactly where the nav's // "Log in" would have. func TestLoginURLForMatchesTheNav(t *testing.T) { - svc := NewService(testConf(), "compare.sr.ht") + svc := NewService(testConf(), "diff.sr.ht") r := httptest.NewRequest("GET", "/~alice/demo?a=1", nil) assert.Equal(t, svc.Page(r, "t", "").LoginURL, svc.LoginURLFor(r)) assert.Equal(t, "https://meta.example/login?return_to="+ - "https%3A%2F%2Fcompare.example%2F~alice%2Fdemo%3Fa%3D1", svc.LoginURLFor(r)) + "https%3A%2F%2Fdiff.example%2F~alice%2Fdemo%3Fa%3D1", svc.LoginURLFor(r)) } // TestHeadLinksAreGuardedAndTheFaviconSurvivesEscaping covers the two ways the @@ -267,7 +267,7 @@ require.NoError(t, tpl.Execute(&b, p)) return b.String() } - svc := NewService(testConf(), "compare.sr.ht") + svc := NewService(testConf(), "diff.sr.ht") svc.StyleHref = "/static/main.min.0badc0de.css" out := renderHead(t, svc.Page(httptest.NewRequest("GET", "/", nil), "t", "")) @@ -281,7 +281,7 @@ assert.NotContains(t, out, "ZgotmplZ", "a filtered href would render as this") // A binary built without a stylesheet, and a service that switched the // icon off, render neither link rather than an empty one. - bare := NewService(testConf(), "compare.sr.ht") + bare := NewService(testConf(), "diff.sr.ht") bare.FaviconHref = "" out = renderHead(t, bare.Page(httptest.NewRequest("GET", "/", nil), "t", "")) assert.NotContains(t, out, "