diff --git a/internal/api/scoreboard_dump_test.go b/internal/api/scoreboard_dump_test.go index 04658f4..e465c5b 100644 --- a/internal/api/scoreboard_dump_test.go +++ b/internal/api/scoreboard_dump_test.go @@ -55,6 +55,9 @@ func TestScoreboardDump_Handler(t *testing.T) { if result.Rigs[0].Handle != "alice" { t.Errorf("rig handle = %q, want alice", result.Rigs[0].Handle) } + if result.Rigs[0].TrustTier != "newcomer" { + t.Errorf("rig trust_tier = %q, want newcomer (1 root stamp = weight 5)", result.Rigs[0].TrustTier) + } if len(result.Stamps) != 1 { t.Errorf("stamps count = %d, want 1", len(result.Stamps)) } diff --git a/internal/commons/scoreboard_dump.go b/internal/commons/scoreboard_dump.go index a2e79db..64feb21 100644 --- a/internal/commons/scoreboard_dump.go +++ b/internal/commons/scoreboard_dump.go @@ -11,6 +11,7 @@ type RigRow struct { DisplayName string `json:"display_name,omitempty"` DolthubOrg string `json:"dolthub_org,omitempty"` TrustLevel int `json:"trust_level"` + TrustTier string `json:"trust_tier"` RegisteredAt string `json:"registered_at,omitempty"` LastSeen string `json:"last_seen,omitempty"` RigType string `json:"rig_type,omitempty"` @@ -100,9 +101,34 @@ func QueryScoreboardDump(db DB) (*ScoreboardDump, error) { return nil, fmt.Errorf("dumping badges: %w", err) } + // Derive trust_tier for each rig from stamp weighted scores. + populateDumpTrustTiers(dump) + return dump, nil } +// populateDumpTrustTiers computes weighted scores from stamps and sets +// TrustTier on each RigRow, ensuring the dump uses the same tier labels +// as the scoreboard API. +func populateDumpTrustTiers(dump *ScoreboardDump) { + scores := make(map[string]int) + for _, s := range dump.Stamps { + weight := 0 + switch s.Severity { + case "root": + weight = 5 + case "branch": + weight = 3 + case "leaf": + weight = 1 + } + scores[s.Subject] += weight + } + for i := range dump.Rigs { + dump.Rigs[i].TrustTier = DeriveTrustTier(scores[dump.Rigs[i].Handle]) + } +} + func queryDumpRigs(db DB) ([]RigRow, error) { query := `SELECT handle, COALESCE(display_name,'') AS display_name, COALESCE(dolthub_org,'') AS dolthub_org, COALESCE(trust_level,0) AS trust_level, COALESCE(registered_at,'') AS registered_at, diff --git a/internal/commons/scoreboard_dump_test.go b/internal/commons/scoreboard_dump_test.go index 66c6691..59fa095 100644 --- a/internal/commons/scoreboard_dump_test.go +++ b/internal/commons/scoreboard_dump_test.go @@ -30,6 +30,10 @@ func TestQueryScoreboardDump_Basic(t *testing.T) { if dump.Rigs[0].DisplayName != "Alice Chen" { t.Errorf("rig display_name = %q, want Alice Chen", dump.Rigs[0].DisplayName) } + // alice has 1 root stamp (weight=5) → newcomer tier + if dump.Rigs[0].TrustTier != "newcomer" { + t.Errorf("rig trust_tier = %q, want newcomer", dump.Rigs[0].TrustTier) + } if len(dump.Stamps) != 1 { t.Fatalf("stamps count = %d, want 1", len(dump.Stamps))