Skip to content
quarry Artifact [8f3802636d]
Login

Artifact [8f3802636d]

Artifact 8f3802636d5fcbd21f4add8f96c9aa234185af4c639a313918e9ec67319e72de:


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"] != "write" {
		t.Fatalf("explicit grant lost: %v", user)
	}
}