Open the mirror's registry on what is current, not an empty search box
The mirror page lists Hugging Face's trending models without anything typed, with views for what is new this month and what is most downloaded, filters for task and size, and each repository's parameter count, architecture, context length and age from one registry call. "Only what these nodes can run" is on by default and leaves out architectures the nodes' llama.cpp cannot load, and adapters, saying how many it hid. Listings are remembered for ten minutes. The stylesheet is now linked by a hash of its content. It is cached for a day, so under a fixed name a deploy's new styles reached people a day after its markup. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
5aa5675a9c
commit
02fa639657
20 files changed
+632
-52
No files matched your search
+125
-10
@@ -19,6 +19,7 @@ import (
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -29,6 +30,9 @@ const DefaultEndpoint = "https://huggingface.co"
|
||||
type Client struct {
|
||||
base string
|
||||
hc *http.Client
|
||||
|
||||
mu sync.Mutex
|
||||
cache map[string]cached
|
||||
}
|
||||
|
||||
// New builds a client against an endpoint, or the public one when empty.
|
||||
@@ -58,6 +62,36 @@ type Model struct {
|
||||
// it is not a plain bool here.
|
||||
Gated Gated `json:"gated"`
|
||||
Private bool `json:"private"`
|
||||
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
TrendingScore float64 `json:"trendingScore"`
|
||||
// GGUF is what the registry read from the repository's weights, absent
|
||||
// for one that has none.
|
||||
GGUF *GGUFInfo `json:"gguf"`
|
||||
}
|
||||
|
||||
// GGUFInfo is the registry's summary of a repository's GGUF weights.
|
||||
type GGUFInfo struct {
|
||||
// Total is the parameter count.
|
||||
Total int64 `json:"total"`
|
||||
Architecture string `json:"architecture"`
|
||||
ContextLength int64 `json:"context_length"`
|
||||
}
|
||||
|
||||
// Params is the parameter count, 0 when the registry does not know it.
|
||||
func (m Model) Params() int64 {
|
||||
if m.GGUF == nil {
|
||||
return 0
|
||||
}
|
||||
return m.GGUF.Total
|
||||
}
|
||||
|
||||
// Architecture is the GGUF architecture, empty when unknown.
|
||||
func (m Model) Architecture() string {
|
||||
if m.GGUF == nil {
|
||||
return ""
|
||||
}
|
||||
return m.GGUF.Architecture
|
||||
}
|
||||
|
||||
// Gated is Hugging Face's gating flag, which is false or a word.
|
||||
@@ -92,20 +126,101 @@ func (c *Client) Search(ctx context.Context, query string, limit int) ([]Model,
|
||||
if strings.TrimSpace(query) == "" {
|
||||
return nil, fmt.Errorf("search for something")
|
||||
}
|
||||
if limit <= 0 || limit > 50 {
|
||||
limit = 20
|
||||
// By downloads, because the thing somebody means by a short name is
|
||||
// almost always the one everybody else meant too.
|
||||
return c.Explore(ctx, Query{Search: query, Sort: SortDownloads, Limit: limit})
|
||||
}
|
||||
|
||||
// Sort orders an exploration.
|
||||
type Sort string
|
||||
|
||||
// The orders the registry offers that are worth offering.
|
||||
const (
|
||||
SortTrending Sort = "trendingScore"
|
||||
SortDownloads Sort = "downloads"
|
||||
SortLikes Sort = "likes"
|
||||
SortCreated Sort = "createdAt"
|
||||
)
|
||||
|
||||
// Query is what to list from the registry.
|
||||
type Query struct {
|
||||
Search string
|
||||
Sort Sort
|
||||
// Task is a pipeline tag: text-generation, feature-extraction. Empty is
|
||||
// any.
|
||||
Task string
|
||||
// GGUF keeps to repositories with GGUF weights, which is what llama.cpp
|
||||
// loads.
|
||||
GGUF bool
|
||||
// MaxParams bounds the parameter count; 0 is no bound. The registry
|
||||
// applies it, so a page of small models is a full page.
|
||||
MaxParams int64
|
||||
Limit int
|
||||
}
|
||||
|
||||
// exploreFields is everything a listing shows. Asking for any field with
|
||||
// expand returns only the fields asked for, so all of them are named.
|
||||
var exploreFields = []string{"downloads", "likes", "pipeline_tag", "tags", "lastModified",
|
||||
"createdAt", "gated", "private", "trendingScore", "gguf"}
|
||||
|
||||
// Explore lists repositories: the trending ones, the newest, or a search.
|
||||
//
|
||||
// Remembered for a few minutes. The mirror page opens on this, and a page
|
||||
// that waits on a registry on the far side of the internet every time it is
|
||||
// opened is slow for news that changes by the hour.
|
||||
func (c *Client) Explore(ctx context.Context, q Query) ([]Model, error) {
|
||||
if q.Limit <= 0 || q.Limit > 100 {
|
||||
q.Limit = 20
|
||||
}
|
||||
q := url.Values{
|
||||
"search": {query},
|
||||
"limit": {fmt.Sprint(limit)},
|
||||
// By downloads, because the thing somebody means by a short name is
|
||||
// almost always the one everybody else meant too.
|
||||
"sort": {"downloads"},
|
||||
if q.Sort == "" {
|
||||
q.Sort = SortTrending
|
||||
}
|
||||
v := url.Values{
|
||||
"limit": {fmt.Sprint(q.Limit)},
|
||||
"sort": {string(q.Sort)},
|
||||
"direction": {"-1"},
|
||||
"expand[]": exploreFields,
|
||||
}
|
||||
if s := strings.TrimSpace(q.Search); s != "" {
|
||||
v.Set("search", s)
|
||||
}
|
||||
if q.Task != "" {
|
||||
v.Set("pipeline_tag", q.Task)
|
||||
}
|
||||
if q.GGUF {
|
||||
v.Set("filter", "gguf")
|
||||
}
|
||||
if q.MaxParams > 0 {
|
||||
v.Set("num_parameters", fmt.Sprintf("min:0,max:%d", q.MaxParams))
|
||||
}
|
||||
path := "/api/models?" + v.Encode()
|
||||
|
||||
c.mu.Lock()
|
||||
if e, ok := c.cache[path]; ok && time.Since(e.at) < exploreTTL {
|
||||
c.mu.Unlock()
|
||||
return e.models, nil
|
||||
}
|
||||
c.mu.Unlock()
|
||||
|
||||
var out []Model
|
||||
err := c.get(ctx, "/api/models?"+q.Encode(), &out)
|
||||
return out, err
|
||||
if err := c.get(ctx, path, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.mu.Lock()
|
||||
if c.cache == nil || len(c.cache) > 200 {
|
||||
c.cache = map[string]cached{}
|
||||
}
|
||||
c.cache[path] = cached{at: time.Now(), models: out}
|
||||
c.mu.Unlock()
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// exploreTTL is how long a listing is reused.
|
||||
const exploreTTL = 10 * time.Minute
|
||||
|
||||
type cached struct {
|
||||
at time.Time
|
||||
models []Model
|
||||
}
|
||||
|
||||
// File is one file in a repository.
|
||||
|
||||
@@ -3,6 +3,8 @@ package hf
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -187,3 +189,44 @@ func TestAShardSetPublishesNoSingleChecksum(t *testing.T) {
|
||||
t.Errorf("expected no checksum for a set, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExploringAsksForWhatThePageFilters(t *testing.T) {
|
||||
var got url.Values
|
||||
calls := 0
|
||||
c := registry(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
calls++
|
||||
got = r.URL.Query()
|
||||
_, _ = w.Write([]byte(`[{"id":"a/b-GGUF","gguf":{"total":7615616512,"architecture":"qwen2","context_length":32768}}]`))
|
||||
})
|
||||
|
||||
q := Query{Sort: SortTrending, Task: "text-generation", GGUF: true, MaxParams: 9e9, Limit: 30}
|
||||
models, err := c.Explore(t.Context(), q)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for k, want := range map[string]string{
|
||||
"sort": "trendingScore", "pipeline_tag": "text-generation", "filter": "gguf",
|
||||
"num_parameters": "min:0,max:9000000000", "limit": "30",
|
||||
} {
|
||||
if got.Get(k) != want {
|
||||
t.Errorf("%s = %q, want %q", k, got.Get(k), want)
|
||||
}
|
||||
}
|
||||
// Expanding any field returns only the expanded ones, so the listing has
|
||||
// to name the counts it shows as well as the GGUF summary.
|
||||
if !slices.Contains(got["expand[]"], "gguf") || !slices.Contains(got["expand[]"], "downloads") {
|
||||
t.Errorf("expand = %v", got["expand[]"])
|
||||
}
|
||||
if len(models) != 1 || models[0].Params() != 7615616512 || models[0].Architecture() != "qwen2" {
|
||||
t.Errorf("the GGUF summary did not decode: %+v", models)
|
||||
}
|
||||
|
||||
// The page opens on this; a second look within minutes is not a second
|
||||
// trip to the registry.
|
||||
if _, err := c.Explore(t.Context(), q); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if calls != 1 {
|
||||
t.Errorf("the registry was asked %d times", calls)
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/control/catalog"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/gguf"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -36,7 +37,7 @@ type MirrorAdmin interface {
|
||||
// off, which is right for a deployment with no way out to the internet: a
|
||||
// search box that can only time out is worse than no search box.
|
||||
type Registry interface {
|
||||
Search(ctx context.Context, query string, limit int) ([]hf.Model, error)
|
||||
Explore(ctx context.Context, q hf.Query) ([]hf.Model, error)
|
||||
Repo(ctx context.Context, id string) (hf.Repo, error)
|
||||
}
|
||||
|
||||
@@ -119,7 +120,9 @@ type adminMirrorData struct {
|
||||
// The explorer.
|
||||
HasRegistry bool
|
||||
Query string
|
||||
Results []hf.Model
|
||||
Explore *explorer
|
||||
// Back is the listing an open repository was reached from.
|
||||
Back template.URL
|
||||
Repo *hf.Repo
|
||||
RepoSets []repoSet
|
||||
RegistryErr string
|
||||
@@ -442,7 +445,7 @@ func plural(n int, one, many string) string {
|
||||
return strconv.Itoa(n) + " " + many
|
||||
}
|
||||
|
||||
// explore fills in the registry half of the page: a search, or one repository.
|
||||
// explore fills in the registry half of the page: a listing, or one repository.
|
||||
//
|
||||
// A failure here is reported in its own line rather than as the page's error.
|
||||
// The registry is somebody else's server on the other side of the internet, and
|
||||
@@ -456,6 +459,7 @@ func (p *AccountPages) explore(r *http.Request, d *adminMirrorData) {
|
||||
d.Query = strings.TrimSpace(r.URL.Query().Get("q"))
|
||||
|
||||
if repo := strings.TrimSpace(r.URL.Query().Get("repo")); repo != "" {
|
||||
d.Back = exploreState(r.URL.Query()).href(d.Query, "", "")
|
||||
got, err := p.registry.Repo(r.Context(), repo)
|
||||
if err != nil {
|
||||
d.RegistryErr = err.Error()
|
||||
@@ -491,14 +495,7 @@ func (p *AccountPages) explore(r *http.Request, d *adminMirrorData) {
|
||||
return
|
||||
}
|
||||
|
||||
if d.Query != "" {
|
||||
got, err := p.registry.Search(r.Context(), d.Query, 20)
|
||||
if err != nil {
|
||||
d.RegistryErr = err.Error()
|
||||
return
|
||||
}
|
||||
d.Results = got
|
||||
}
|
||||
p.exploreList(r, d)
|
||||
}
|
||||
|
||||
// defaultModelName is the catalog name a repository suggests.
|
||||
|
||||
@@ -345,10 +345,12 @@ type fakeRegistry struct {
|
||||
repo hf.Repo
|
||||
err error
|
||||
asked string
|
||||
query hf.Query
|
||||
}
|
||||
|
||||
func (f *fakeRegistry) Search(_ context.Context, q string, _ int) ([]hf.Model, error) {
|
||||
f.asked = q
|
||||
func (f *fakeRegistry) Explore(_ context.Context, q hf.Query) ([]hf.Model, error) {
|
||||
f.asked = q.Search
|
||||
f.query = q
|
||||
return f.results, f.err
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/gguf"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/hf"
|
||||
)
|
||||
|
||||
// The explorer's views: what the registry is excited about this week, what
|
||||
// arrived this month, and what everybody settled on.
|
||||
const (
|
||||
viewTrending = "trending"
|
||||
viewNew = "new"
|
||||
viewDownloads = "downloads"
|
||||
)
|
||||
|
||||
// newWithin is how recent a repository has to be to count as new.
|
||||
const newWithin = 30 * 24 * time.Hour
|
||||
|
||||
// minParams is the smallest thing worth calling a model.
|
||||
const minParams = 50e6
|
||||
|
||||
// exploreShown is how many rows the explorer lists.
|
||||
const exploreShown = 25
|
||||
|
||||
var exploreViews = []struct{ key, label string }{
|
||||
{viewTrending, "Trending"}, {viewNew, "New this month"}, {viewDownloads, "Most downloaded"},
|
||||
}
|
||||
|
||||
var exploreTasks = []struct{ key, label, tag string }{
|
||||
{"chat", "Chat", "text-generation"}, {"embed", "Embeddings", "feature-extraction"}, {"any", "Any task", ""},
|
||||
}
|
||||
|
||||
var exploreSizes = []struct {
|
||||
key, label string
|
||||
max int64
|
||||
}{
|
||||
{"3", "≤ 3B", 3e9}, {"9", "≤ 9B", 9e9}, {"35", "≤ 35B", 35e9}, {"any", "Any size", 0},
|
||||
}
|
||||
|
||||
// explorer is the registry half of the mirror page when no repository is
|
||||
// open: a listing, its filters, and links that keep them.
|
||||
type explorer struct {
|
||||
View, Task, Size string
|
||||
// Here keeps to what the nodes' llama.cpp can load. On by default: a
|
||||
// trending list is mostly things this cluster cannot run, and finding
|
||||
// that out one repository at a time is what the explorer is for avoiding.
|
||||
Here bool
|
||||
Rows []exploreRow
|
||||
// Hidden is how many rows Here took out, so an empty page says why.
|
||||
Hidden int
|
||||
|
||||
Views, Tasks, Sizes []exploreLink
|
||||
}
|
||||
|
||||
type exploreLink struct {
|
||||
Label string
|
||||
Href template.URL
|
||||
Active bool
|
||||
}
|
||||
|
||||
type exploreRow struct {
|
||||
hf.Model
|
||||
Verdict gguf.Verdict
|
||||
Href template.URL
|
||||
New bool
|
||||
}
|
||||
|
||||
// ParamsLabel is the parameter count as people say it: 7.6B, 494M.
|
||||
func (r exploreRow) ParamsLabel() string {
|
||||
n := r.Params()
|
||||
switch {
|
||||
case n <= 0:
|
||||
return "—"
|
||||
case n >= 1e9:
|
||||
return trimZero(fmt.Sprintf("%.1f", float64(n)/1e9)) + "B"
|
||||
default:
|
||||
return fmt.Sprintf("%dM", n/1e6)
|
||||
}
|
||||
}
|
||||
|
||||
// ContextLabel is the context length in thousands of tokens.
|
||||
func (r exploreRow) ContextLabel() string {
|
||||
if r.GGUF == nil || r.GGUF.ContextLength <= 0 {
|
||||
return "—"
|
||||
}
|
||||
return fmt.Sprintf("%dk", r.GGUF.ContextLength/1024)
|
||||
}
|
||||
|
||||
// Age is how long ago the repository last changed, coarsely.
|
||||
func (r exploreRow) Age() string {
|
||||
t := r.LastModified
|
||||
if t.IsZero() {
|
||||
t = r.CreatedAt
|
||||
}
|
||||
if t.IsZero() {
|
||||
return "—"
|
||||
}
|
||||
d := time.Since(t)
|
||||
switch {
|
||||
case d < time.Hour:
|
||||
return "just now"
|
||||
case d < 48*time.Hour:
|
||||
return fmt.Sprintf("%dh", int(d.Hours()))
|
||||
case d < 14*24*time.Hour:
|
||||
return fmt.Sprintf("%dd", int(d.Hours()/24))
|
||||
case d < 60*24*time.Hour:
|
||||
return fmt.Sprintf("%dw", int(d.Hours()/24/7))
|
||||
default:
|
||||
return fmt.Sprintf("%dmo", int(d.Hours()/24/30))
|
||||
}
|
||||
}
|
||||
|
||||
func trimZero(s string) string { return strings.TrimSuffix(s, ".0") }
|
||||
|
||||
// exploreState reads the explorer's settings from the address. With none set
|
||||
// — the page opened from the menu — it is trending chat models this cluster
|
||||
// can run.
|
||||
func exploreState(q url.Values) explorer {
|
||||
e := explorer{View: q.Get("view"), Task: q.Get("task"), Size: q.Get("size")}
|
||||
// "x" marks a submitted form, so an unticked box reads as off rather than
|
||||
// as not yet chosen.
|
||||
e.Here = q.Get("x") != "1" || q.Get("here") == "1"
|
||||
if !oneOf(e.View, viewTrending, viewNew, viewDownloads) {
|
||||
e.View = viewTrending
|
||||
// A search with no view asks for what a name usually means, which is
|
||||
// the one everybody downloads.
|
||||
if strings.TrimSpace(q.Get("q")) != "" {
|
||||
e.View = viewDownloads
|
||||
}
|
||||
}
|
||||
if !oneOf(e.Task, "chat", "embed", "any") {
|
||||
e.Task = "chat"
|
||||
}
|
||||
if !oneOf(e.Size, "3", "9", "35", "any") {
|
||||
e.Size = "any"
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
func oneOf(s string, options ...string) bool {
|
||||
for _, o := range options {
|
||||
if s == o {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// href is the page with these settings and one of them changed.
|
||||
func (e explorer) href(query, key, value string) template.URL {
|
||||
v := url.Values{"view": {e.View}, "task": {e.Task}, "size": {e.Size}, "x": {"1"}}
|
||||
if e.Here {
|
||||
v.Set("here", "1")
|
||||
}
|
||||
if query != "" {
|
||||
v.Set("q", query)
|
||||
}
|
||||
if key != "" {
|
||||
v.Set(key, value)
|
||||
}
|
||||
return template.URL("/admin/mirror?" + v.Encode())
|
||||
}
|
||||
|
||||
// hfQuery is what to ask the registry for.
|
||||
func (e explorer) hfQuery(search string) hf.Query {
|
||||
q := hf.Query{Search: search, Sort: hf.SortTrending, Limit: 60,
|
||||
// What runs here is GGUF; the architecture check needs the registry's
|
||||
// reading of one.
|
||||
GGUF: e.Here}
|
||||
switch e.View {
|
||||
case viewDownloads:
|
||||
q.Sort = hf.SortDownloads
|
||||
case viewNew:
|
||||
// Trending, then kept to the recent: sorted by creation date alone,
|
||||
// the newest repositories are mostly empty uploads nobody has used.
|
||||
q.Limit = 100
|
||||
}
|
||||
for _, t := range exploreTasks {
|
||||
if t.key == e.Task {
|
||||
q.Task = t.tag
|
||||
}
|
||||
}
|
||||
for _, s := range exploreSizes {
|
||||
if s.key == e.Size {
|
||||
q.MaxParams = s.max
|
||||
}
|
||||
}
|
||||
return q
|
||||
}
|
||||
|
||||
// exploreList fills in the listing.
|
||||
func (p *AccountPages) exploreList(r *http.Request, d *adminMirrorData) {
|
||||
e := exploreState(r.URL.Query())
|
||||
for _, v := range exploreViews {
|
||||
e.Views = append(e.Views, exploreLink{v.label, e.href(d.Query, "view", v.key), v.key == e.View})
|
||||
}
|
||||
for _, t := range exploreTasks {
|
||||
e.Tasks = append(e.Tasks, exploreLink{t.label, e.href(d.Query, "task", t.key), t.key == e.Task})
|
||||
}
|
||||
for _, s := range exploreSizes {
|
||||
e.Sizes = append(e.Sizes, exploreLink{s.label, e.href(d.Query, "size", s.key), s.key == e.Size})
|
||||
}
|
||||
d.Explore = &e
|
||||
|
||||
got, err := p.registry.Explore(r.Context(), e.hfQuery(d.Query))
|
||||
if err != nil {
|
||||
d.RegistryErr = err.Error()
|
||||
return
|
||||
}
|
||||
back := e.href(d.Query, "", "")
|
||||
for _, m := range got {
|
||||
if e.View == viewNew && time.Since(m.CreatedAt) > newWithin {
|
||||
continue
|
||||
}
|
||||
row := exploreRow{Model: m, Verdict: gguf.Verdict{Servable: true},
|
||||
Href: back + template.URL("&repo="+url.QueryEscape(m.ID)),
|
||||
New: !m.CreatedAt.IsZero() && time.Since(m.CreatedAt) < newWithin}
|
||||
if a := m.Architecture(); a != "" && p.llamaVersion != "" {
|
||||
row.Verdict = gguf.LlamaCpp(p.llamaVersion, a)
|
||||
}
|
||||
// An adapter or a fragment, not a model: tens of megabytes of LoRA
|
||||
// weights listed among the models they need a model to run on.
|
||||
if e.Here && m.Params() > 0 && m.Params() < minParams {
|
||||
continue
|
||||
}
|
||||
if e.Here && row.Verdict.Checked && !row.Verdict.Servable {
|
||||
e.Hidden++
|
||||
continue
|
||||
}
|
||||
if len(e.Rows) < exploreShown {
|
||||
e.Rows = append(e.Rows, row)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"html"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/hf"
|
||||
)
|
||||
|
||||
func ggufModel(id, arch string, params int64, created time.Time) hf.Model {
|
||||
return hf.Model{ID: id, CreatedAt: created, LastModified: created,
|
||||
GGUF: &hf.GGUFInfo{Total: params, Architecture: arch, ContextLength: 32768}}
|
||||
}
|
||||
|
||||
func TestTheExplorerOpensOnTrendingModelsTheNodesCanRun(t *testing.T) {
|
||||
// Opened from the menu, with nothing typed: what is current, in the
|
||||
// shape this cluster runs, without a search to start it.
|
||||
now := time.Now()
|
||||
reg := &fakeRegistry{results: []hf.Model{
|
||||
ggufModel("Qwen/Qwen3-8B-GGUF", "qwen3", 8.2e9, now.Add(-90*24*time.Hour)),
|
||||
ggufModel("odd/Kev-GGUF", "ggmlc", 5e8, now.Add(-2*24*time.Hour)),
|
||||
}}
|
||||
body := mirrorGet(t, mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}),
|
||||
"/admin/mirror").Body.String()
|
||||
|
||||
q := reg.query
|
||||
if q.Sort != hf.SortTrending || q.Task != "text-generation" || !q.GGUF || q.Search != "" {
|
||||
t.Errorf("asked the registry for %+v", q)
|
||||
}
|
||||
if !strings.Contains(body, "Qwen/Qwen3-8B-GGUF") || !strings.Contains(body, "8.2B") {
|
||||
t.Errorf("the trending model is missing or unsized: %s", body)
|
||||
}
|
||||
// The kev case: listed, it invites a fetch the nodes cannot use.
|
||||
if strings.Contains(body, "odd/Kev-GGUF") {
|
||||
t.Error("a model llama.cpp cannot load is offered")
|
||||
}
|
||||
if !strings.Contains(body, "1 more is hidden") {
|
||||
t.Error("the page should say something was hidden, and why")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUntickingRunsHereShowsEverythingWithAVerdict(t *testing.T) {
|
||||
reg := &fakeRegistry{results: []hf.Model{
|
||||
ggufModel("odd/Kev-GGUF", "ggmlc", 5e8, time.Now()),
|
||||
}}
|
||||
// x=1 is the submitted form; "here" absent is the box unticked.
|
||||
body := mirrorGet(t, mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}),
|
||||
"/admin/mirror?x=1&view=downloads&task=any&size=9").Body.String()
|
||||
|
||||
q := reg.query
|
||||
if q.GGUF || q.Sort != hf.SortDownloads || q.Task != "" || q.MaxParams != 9e9 {
|
||||
t.Errorf("asked the registry for %+v", q)
|
||||
}
|
||||
if !strings.Contains(body, "odd/Kev-GGUF") || !strings.Contains(body, "ggmlc ✗") {
|
||||
t.Errorf("the unrunnable model should be listed and marked: %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewThisMonthLeavesOutOlderRepositories(t *testing.T) {
|
||||
now := time.Now()
|
||||
reg := &fakeRegistry{results: []hf.Model{
|
||||
ggufModel("a/Old-GGUF", "llama", 1e9, now.Add(-200*24*time.Hour)),
|
||||
ggufModel("a/Fresh-GGUF", "llama", 1e9, now.Add(-3*24*time.Hour)),
|
||||
}}
|
||||
body := mirrorGet(t, mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}),
|
||||
"/admin/mirror?view=new").Body.String()
|
||||
if strings.Contains(body, "a/Old-GGUF") || !strings.Contains(body, "a/Fresh-GGUF") {
|
||||
t.Errorf("new this month shows the wrong repositories: %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpeningARepositoryKeepsTheWayBack(t *testing.T) {
|
||||
reg := &fakeRegistry{results: []hf.Model{ggufModel("a/B-GGUF", "llama", 1e9, time.Now())}}
|
||||
mux := mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg})
|
||||
body := html.UnescapeString(mirrorGet(t, mux, "/admin/mirror?view=new&size=3").Body.String())
|
||||
if !strings.Contains(body, "size=3") || !strings.Contains(body, "repo=a%2FB-GGUF") {
|
||||
t.Fatalf("the row's link should keep the filters: %s", body)
|
||||
}
|
||||
|
||||
reg.repo = hf.Repo{ID: "a/B-GGUF", Revision: "abc123def456"}
|
||||
body = html.UnescapeString(mirrorGet(t, mux, "/admin/mirror?view=new&size=3&repo=a/B-GGUF").Body.String())
|
||||
if !strings.Contains(body, "back to the list") || !strings.Contains(body, "view=new") {
|
||||
t.Errorf("the repository page should lead back to the same listing: %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnAdapterIsNotListedAsAModel(t *testing.T) {
|
||||
reg := &fakeRegistry{results: []hf.Model{
|
||||
ggufModel("a/Some-LoRA-GGUF", "qwen2", 2e6, time.Now()),
|
||||
ggufModel("a/Tiny-GGUF", "qwen2", 135e6, time.Now()),
|
||||
}}
|
||||
body := mirrorGet(t, mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}),
|
||||
"/admin/mirror").Body.String()
|
||||
if strings.Contains(body, "Some-LoRA") || !strings.Contains(body, "a/Tiny-GGUF") {
|
||||
t.Errorf("adapters should be left out and small models kept: %s", body)
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ li { margin: .25rem 0; }
|
||||
a { color: var(--accent); }
|
||||
.wrap.narrow { max-width: 30rem; }
|
||||
label { display: block; margin: .9rem 0; font-size: .9rem; font-weight: 600; }
|
||||
input[type=text], input[type=email], input[type=password] {
|
||||
input[type=text], input[type=email], input[type=password], input[type=search] {
|
||||
display: block; width: 100%; margin-top: .3rem; font: inherit; font-weight: 400;
|
||||
padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px;
|
||||
background: var(--card); color: var(--fg);
|
||||
@@ -456,3 +456,23 @@ table.held .use .as { display: block; font-size: .72rem; color: var(--muted);
|
||||
table.held .use .opt { font-size: .75rem; line-height: 1.3; }
|
||||
table.held td.num { white-space: nowrap; }
|
||||
table.held select.mode { width: 100%; padding: .15rem .3rem; font-size: .8rem; }
|
||||
|
||||
/* Link pills: the same look as .tabs, for choices that are addresses rather
|
||||
than panels on one page — a filtered listing should survive a reload and be
|
||||
worth sending to somebody. */
|
||||
.pills { display: flex; flex-wrap: wrap; gap: .35rem; margin: .5rem 0; }
|
||||
.pills a { font-size: .85rem; font-weight: 600; color: var(--muted); padding: .35rem .85rem;
|
||||
border: 1px solid transparent; border-radius: 999px; text-decoration: none; }
|
||||
.pills a:hover { color: var(--fg); }
|
||||
.pills a.on { color: var(--fg); background: var(--card); border-color: var(--line); }
|
||||
.pills.small a { font-size: .78rem; font-weight: 500; padding: .2rem .65rem; }
|
||||
.explore-filters { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; }
|
||||
.explore-search { display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: center; margin: .5rem 0 .75rem; }
|
||||
.explore-search input[type=search] { flex: 1 1 18rem; width: auto; margin: 0; }
|
||||
.explore-search label.check { font-size: .85rem; color: var(--muted); display: inline-flex; gap: .35rem; align-items: center; margin: 0; }
|
||||
table.explore td:first-child { max-width: 28rem; overflow-wrap: anywhere; }
|
||||
table.explore td.num { white-space: nowrap; }
|
||||
table.explore .cannot { color: var(--bad); }
|
||||
.tag { display: inline-block; font-size: .7rem; font-weight: 600; color: var(--muted);
|
||||
border: 1px solid var(--line); border-radius: 999px; padding: 0 .4rem; margin-left: .3rem; vertical-align: 1px; }
|
||||
.tag.new { color: var(--accent); border-color: var(--accent); }
|
||||
@@ -1,7 +1,7 @@
|
||||
{{define "signup"}}<!doctype html>
|
||||
<html lang="en"><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Sign up · llmgw</title><link rel="stylesheet" href="/_static/base.css">
|
||||
<title>Sign up · llmgw</title><link rel="stylesheet" href="{{stylesheet}}">
|
||||
</head><body><div class="wrap narrow">
|
||||
<header><h1>Create an account</h1>
|
||||
<p class="sub">An operator approves it before it can be used.</p></header>
|
||||
@@ -30,7 +30,7 @@ Tell whoever you asked for access that you have signed up.</p>
|
||||
{{define "login"}}<!doctype html>
|
||||
<html lang="en"><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Sign in · llmgw</title><link rel="stylesheet" href="/_static/base.css">
|
||||
<title>Sign in · llmgw</title><link rel="stylesheet" href="{{stylesheet}}">
|
||||
</head><body><div class="wrap narrow">
|
||||
<header><h1>Sign in</h1></header>
|
||||
|
||||
@@ -47,7 +47,7 @@ Tell whoever you asked for access that you have signed up.</p>
|
||||
{{define "profile"}}<!doctype html>
|
||||
<html lang="en"><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Your keys · llmgw</title><link rel="stylesheet" href="/_static/base.css">
|
||||
<title>Your keys · llmgw</title><link rel="stylesheet" href="{{stylesheet}}">
|
||||
</head><body><div class="wrap">
|
||||
<header>
|
||||
<h1>Your keys</h1>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
{{/* Only while something is downloading. A reload at any other time would
|
||||
take with it whatever the operator was typing into the form below. */}}
|
||||
{{if .RefreshSec}}<meta http-equiv="refresh" content="{{.RefreshSec}}">{{end}}
|
||||
<title>Mirror · llmgw</title><link rel="stylesheet" href="/_static/base.css">
|
||||
<title>Mirror · llmgw</title><link rel="stylesheet" href="{{stylesheet}}">
|
||||
</head><body><div class="wrap">
|
||||
<header>
|
||||
<h1>Model mirror</h1>
|
||||
@@ -183,12 +183,24 @@ document.addEventListener('click', function (e) {
|
||||
{{else}}<p class="empty">The mirror is reachable and holds nothing yet.</p>{{end}}
|
||||
|
||||
{{if .HasRegistry}}
|
||||
<h2>Find a model</h2>
|
||||
<form method="get" action="/admin/mirror">
|
||||
<label>Search Hugging Face
|
||||
<input type="text" name="q" value="{{.Query}}" placeholder="qwen2.5 coder gguf"></label>
|
||||
<h2>Explore models</h2>
|
||||
{{if not .Repo}}{{with .Explore}}
|
||||
<nav class="pills" aria-label="Which models">{{range .Views}}<a href="{{.Href}}"{{if .Active}} class="on" aria-current="page"{{end}}>{{.Label}}</a>{{end}}</nav>
|
||||
<div class="explore-filters">
|
||||
<nav class="pills small" aria-label="Task">{{range .Tasks}}<a href="{{.Href}}"{{if .Active}} class="on" aria-current="true"{{end}}>{{.Label}}</a>{{end}}</nav>
|
||||
<nav class="pills small" aria-label="Size">{{range .Sizes}}<a href="{{.Href}}"{{if .Active}} class="on" aria-current="true"{{end}}>{{.Label}}</a>{{end}}</nav>
|
||||
</div>
|
||||
{{end}}
|
||||
<form method="get" action="/admin/mirror" class="explore-search">
|
||||
{{with .Explore}}<input type="hidden" name="view" value="{{.View}}">
|
||||
<input type="hidden" name="task" value="{{.Task}}">
|
||||
<input type="hidden" name="size" value="{{.Size}}">
|
||||
<input type="hidden" name="x" value="1">{{end}}
|
||||
<input type="search" name="q" value="{{.Query}}" placeholder="Search Hugging Face — qwen coder, gemma, bge…" aria-label="Search Hugging Face">
|
||||
<label class="check"><input type="checkbox" name="here" value="1" onchange="this.form.submit()"{{if .Explore}}{{if .Explore.Here}} checked{{end}}{{end}}> only what these nodes can run</label>
|
||||
<button type="submit">Search</button>
|
||||
</form>
|
||||
{{end}}
|
||||
|
||||
{{if .RegistryErr}}
|
||||
{{/* Its own line, not the page's error: the registry is somebody else's server
|
||||
@@ -197,24 +209,35 @@ document.addEventListener('click', function (e) {
|
||||
<p class="note error-row">The registry: {{.RegistryErr}}</p>
|
||||
{{end}}
|
||||
|
||||
{{if .Results}}
|
||||
<table><tr><th>Repository</th><th>Downloads</th><th>Task</th><th></th></tr>
|
||||
{{range .Results}}<tr>
|
||||
<td><code>{{.ID}}</code>{{if .Gated.Is}} <span class="opt">gated</span>{{end}}</td>
|
||||
{{if not .Repo}}{{with .Explore}}
|
||||
{{if .Rows}}
|
||||
<table class="explore">
|
||||
<tr><th>Repository</th><th class="num">Size</th><th>Architecture</th><th class="num">Context</th>
|
||||
<th class="num">Downloads</th><th class="num">Likes</th><th class="num">Updated</th></tr>
|
||||
{{range .Rows}}<tr>
|
||||
<td><a href="{{.Href}}"><code>{{.ID}}</code></a>
|
||||
{{if .New}}<span class="tag new">new</span>{{end}}{{if .Gated.Is}}<span class="tag">gated</span>{{end}}</td>
|
||||
<td class="num">{{.ParamsLabel}}</td>
|
||||
<td>{{if .Architecture}}<span{{if not .Verdict.Servable}} class="cannot"{{end}} title="{{.Verdict.Reason}}">{{.Architecture}}{{if .Verdict.Checked}}{{if .Verdict.Servable}} ✓{{else}} ✗{{end}}{{end}}</span>{{else}}—{{end}}</td>
|
||||
<td class="num">{{.ContextLabel}}</td>
|
||||
<td class="num">{{compact .Downloads}}</td>
|
||||
<td>{{or .PipelineTag "—"}}</td>
|
||||
<td><a href="/admin/mirror?q={{$.Query}}&repo={{.ID}}">files</a></td>
|
||||
<td class="num">{{compact .Likes}}</td>
|
||||
<td class="num">{{.Age}}</td>
|
||||
</tr>{{end}}
|
||||
</table>
|
||||
{{if .Hidden}}<p class="note">{{.Hidden}} more {{if eq .Hidden 1}}is{{else}}are{{end}} hidden: their architecture is one the nodes' llama.cpp cannot load.
|
||||
Untick “only what these nodes can run” to see them.</p>{{end}}
|
||||
<p class="note">A gated repository needs its terms accepted with a Hugging Face
|
||||
account, and this browses anonymously — the files will list, and fetching one
|
||||
will fail at the mirror. Download it by hand and put it in the mirror
|
||||
directory, or give the mirror a token.</p>
|
||||
{{else if .Query}}{{if not .RegistryErr}}
|
||||
<p class="empty">Nothing matched “{{.Query}}”.</p>
|
||||
{{else if not $.RegistryErr}}
|
||||
<p class="empty">{{if $.Query}}Nothing matched “{{$.Query}}”{{else}}Nothing to list{{end}}{{if .Hidden}} that these nodes can run — {{.Hidden}} {{if eq .Hidden 1}}result was{{else}}results were{{end}} hidden for an architecture llama.cpp cannot load{{end}}.</p>
|
||||
{{end}}
|
||||
{{end}}{{end}}
|
||||
|
||||
{{if .Repo}}
|
||||
<p><a href="{{.Back}}">← back to the list</a></p>
|
||||
<h3>{{.Repo.ID}} <span class="opt">at {{.Repo.ShortRevision}}</span></h3>
|
||||
{{if .RepoSets}}
|
||||
<table>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{{define "admin_quotas"}}<!doctype html>
|
||||
<html lang="en"><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Quotas · llmgw</title><link rel="stylesheet" href="/_static/base.css">
|
||||
<title>Quotas · llmgw</title><link rel="stylesheet" href="{{stylesheet}}">
|
||||
{{/* Links and forms work as plain navigation; htmx, when it loads, swaps only
|
||||
#quotas so opening a form or saving one does not jump the page. */}}
|
||||
<meta name="htmx-config" content='{"scrollIntoViewOnBoost":false,"defaultFocusScroll":false}'>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{{define "admin_usage"}}<!doctype html>
|
||||
<html lang="en"><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Usage · llmgw</title><link rel="stylesheet" href="/_static/base.css">
|
||||
<title>Usage · llmgw</title><link rel="stylesheet" href="{{stylesheet}}">
|
||||
</head><body><div class="wrap">
|
||||
<header>
|
||||
<h1>Usage over time</h1>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{{define "admin_users"}}<!doctype html>
|
||||
<html lang="en"><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>People · llmgw</title><link rel="stylesheet" href="/_static/base.css">
|
||||
<title>People · llmgw</title><link rel="stylesheet" href="{{stylesheet}}">
|
||||
{{/* Forms here post and get the whole page back, which works with no script at
|
||||
all. htmx, when it loads, swaps only #people from that page instead of
|
||||
reloading it, so an open project stays open and the page does not jump. */}}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{{define "chat"}}<!doctype html>
|
||||
<html lang="en"><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Chat · llmgw</title><link rel="stylesheet" href="/_static/base.css">
|
||||
<title>Chat · llmgw</title><link rel="stylesheet" href="{{stylesheet}}">
|
||||
<link rel="stylesheet" href="/_static/katex/katex.min.css">
|
||||
<script defer src="/_static/katex/katex.min.js"></script>
|
||||
<script defer src="/_static/katex/auto-render.min.js"></script>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<html lang="en"><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>Your llmgw key</title><link rel="stylesheet" href="/_static/base.css">
|
||||
<title>Your llmgw key</title><link rel="stylesheet" href="{{stylesheet}}">
|
||||
</head><body><div class="wrap">
|
||||
<header>
|
||||
<h1>Your API key</h1>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<html lang="en"><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta http-equiv="refresh" content="{{.RefreshSec}}">
|
||||
<title>llmgw — cluster</title><link rel="stylesheet" href="/_static/base.css">
|
||||
<title>llmgw — cluster</title><link rel="stylesheet" href="{{stylesheet}}">
|
||||
</head><body><div class="wrap">
|
||||
<header>
|
||||
<h1>Cluster</h1>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>llmgw</title>
|
||||
<meta name="description" content="One OpenAI-compatible endpoint in front of self-hosted models.">
|
||||
<link rel="stylesheet" href="/_static/base.css">
|
||||
<link rel="stylesheet" href="{{stylesheet}}">
|
||||
</head><body><div class="wrap">
|
||||
|
||||
{{if .Notice}}<p class="banner note">{{.Notice}}</p>{{end}}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<html lang="en"><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
{{if .Follow}}<meta http-equiv="refresh" content="5">{{end}}
|
||||
<title>llmgw — {{.Node}} logs</title><link rel="stylesheet" href="/_static/base.css">
|
||||
<title>llmgw — {{.Node}} logs</title><link rel="stylesheet" href="{{stylesheet}}">
|
||||
</head><body><div class="wrap">
|
||||
<header>
|
||||
<h1>{{.Node}}</h1>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{{define "org"}}<!doctype html>
|
||||
<html lang="en"><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>{{.Org.Name}} · llmgw</title><link rel="stylesheet" href="/_static/base.css">
|
||||
<title>{{.Org.Name}} · llmgw</title><link rel="stylesheet" href="{{stylesheet}}">
|
||||
</head><body><div class="wrap">
|
||||
<header>
|
||||
<h1>{{.Org.Name}}</h1>
|
||||
@@ -96,7 +96,7 @@ people do elsewhere — in another organization, or on their own — is not show
|
||||
{{define "org-none"}}<!doctype html>
|
||||
<html lang="en"><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Organizations · llmgw</title><link rel="stylesheet" href="/_static/base.css">
|
||||
<title>Organizations · llmgw</title><link rel="stylesheet" href="{{stylesheet}}">
|
||||
</head><body><div class="wrap">
|
||||
<header>
|
||||
<h1>Organizations</h1>
|
||||
|
||||
+18
-2
@@ -14,7 +14,9 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"embed"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/fs"
|
||||
@@ -35,9 +37,23 @@ var files embed.FS
|
||||
//go:embed static
|
||||
var staticFiles embed.FS
|
||||
|
||||
// stylesheetURL names the stylesheet by its content. The assets are cached for a
|
||||
// day, and under a fixed name a deploy that changed the page's look reached
|
||||
// people a day later — or reached the markup at once and the styles not at
|
||||
// all, which is worse than either.
|
||||
var stylesheetURL = func() string {
|
||||
b, err := staticFiles.ReadFile("static/base.css")
|
||||
if err != nil {
|
||||
panic("web: the stylesheet is missing from the binary: " + err.Error())
|
||||
}
|
||||
sum := sha256.Sum256(b)
|
||||
return "/_static/base.css?v=" + hex.EncodeToString(sum[:4])
|
||||
}()
|
||||
|
||||
var funcs = template.FuncMap{
|
||||
"lower": strings.ToLower,
|
||||
"sub": func(a, b int) int { return a - b },
|
||||
"stylesheet": func() string { return stylesheetURL },
|
||||
"lower": strings.ToLower,
|
||||
"sub": func(a, b int) int { return a - b },
|
||||
"join": func(v []string) string {
|
||||
if len(v) == 0 {
|
||||
return "—"
|
||||
|
||||
@@ -2,7 +2,10 @@ package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
@@ -602,3 +605,24 @@ func TestTheLandingPageDiagramDescribesItself(t *testing.T) {
|
||||
t.Error("the schematic is decoration to anyone not looking at it")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheStylesheetIsNamedByItsContent(t *testing.T) {
|
||||
// Cached for a day: under a fixed name, a deploy's new styles reached
|
||||
// people a day after its markup did.
|
||||
b, err := staticFiles.ReadFile("static/base.css")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sum := sha256.Sum256(b)
|
||||
want := "/_static/base.css?v=" + hex.EncodeToString(sum[:4])
|
||||
if stylesheetURL != want {
|
||||
t.Errorf("stylesheet at %q, want %q", stylesheetURL, want)
|
||||
}
|
||||
var out strings.Builder
|
||||
if err := template.Must(template.New("").Funcs(funcs).Parse(`<link href="{{stylesheet}}">`)).Execute(&out, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(out.String(), "v="+hex.EncodeToString(sum[:4])) {
|
||||
t.Errorf("rendered as %s", out.String())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user