package main
import (
"path/filepath"
"testing"
"craftdesign.group/quarry/internal/oltp"
)
// A site admin with no explicit repo_role rows must still read as
// "the fleet is yours": GrantsFor carries the "" marker me.feed keys
// on. This is the dashboard-was-empty regression (2026-08-21).
func TestGrantsForCarriesSiteAdminMarker(t *testing.T) {
db, err := oltp.Open(filepath.Join(t.TempDir(), "oltp.db"))
if err != nil {
t.Fatal(err)
}
defer db.Close()
if err := db.AddAccount("root", "pw12345678", true); err != nil {
t.Fatal(err)
}
if err := db.AddAccount("plain", "pw12345678", false); err != nil {
t.Fatal(err)
}
if err := db.Grant("plain", "alpha", oltp.Write); err != nil {
t.Fatal(err)
}
st := accountStore{db: db}
admin, err := st.GrantsFor("root")
if err != nil {
t.Fatal(err)
}
if admin[""] != "admin" {
t.Fatalf("site admin marker missing: %v", admin)
}
user, err := st.GrantsFor("plain")
if err != nil {
t.Fatal(err)
}
if _, has := user[""]; has {
t.Fatalf("plain account grew the marker: %v", user)
}
if user["alpha"] != "developer" {
t.Fatalf("explicit grant lost: %v", user)
}
}