feat: promote accepted proposals from API

This commit is contained in:
Josh Creek
2026-09-01 10:29:41 +01:00
parent e0ba6c6ead
commit 03ff8e485e
16 changed files with 270 additions and 49 deletions
+30
View File
@@ -2,6 +2,7 @@ package domain
import (
"fmt"
"sort"
"time"
)
@@ -68,5 +69,34 @@ func PrepareProposal(id string, playlist Playlist, formation MatchFormation, ran
if err != nil {
return PreparedProposal{}, err
}
if formation.Selection.Region == "" || len(formation.Selection.Players) == 0 || formation.Selection.Players[0].ProtocolVersion < 1 {
return PreparedProposal{}, fmt.Errorf("formed match metadata is incomplete")
}
proposal.Region = formation.Selection.Region
proposal.Protocol = formation.Selection.Players[0].ProtocolVersion
for _, player := range formation.Selection.Players {
if player.ProtocolVersion != proposal.Protocol {
return PreparedProposal{}, fmt.Errorf("formed match has mixed protocols")
}
}
assignProposalSlots(&proposal, formation.Teams)
return PreparedProposal{Proposal: proposal, CasualLineup: lineup}, nil
}
func assignProposalSlots(proposal *Proposal, teams Teams) {
assign := func(team int, players []Candidate) {
ordered := append([]Candidate(nil), players...)
sort.Slice(ordered, func(i, j int) bool { return ordered[i].PlayerID < ordered[j].PlayerID })
for index, player := range ordered {
for participant := range proposal.Participants {
if proposal.Participants[participant].PlayerID == player.PlayerID {
proposal.Participants[participant].Team = team
proposal.Participants[participant].Slot = team*3 + index
break
}
}
}
}
assign(0, teams.Team0)
assign(1, teams.Team1)
}
+4 -1
View File
@@ -10,7 +10,7 @@ func testFormation(t *testing.T, count int) MatchFormation {
now := time.Unix(1000, 0)
players := make([]Candidate, count)
for i := range players {
players[i] = Candidate{TicketID: string(rune('a' + i)), PlayerID: string(rune('p' + i)), Rating: 1500, EnqueuedAt: now, PredictedRTT: map[string]float64{"EU": 40}}
players[i] = Candidate{TicketID: string(rune('a' + i)), PlayerID: string(rune('p' + i)), ProtocolVersion: 1, Rating: 1500, EnqueuedAt: now, PredictedRTT: map[string]float64{"EU": 40}}
}
selection, err := SelectCandidates(players[0], players[1:], count, now)
if err != nil {
@@ -31,6 +31,9 @@ func TestPrepareProposalBuildsCasualLineupBeforeCreatingProposal(t *testing.T) {
if prepared.Proposal.Playlist != Casual || len(prepared.Proposal.Participants) != 2 || len(prepared.CasualLineup) != 6 {
t.Fatalf("prepared casual proposal = %+v", prepared)
}
if prepared.Proposal.Region != "EU" || prepared.Proposal.Protocol != 1 || prepared.Proposal.Participants[0].Slot == prepared.Proposal.Participants[1].Slot || prepared.Proposal.Participants[0].Team == prepared.Proposal.Participants[1].Team {
t.Fatalf("prepared proposal did not retain deterministic topology: %+v", prepared.Proposal)
}
humans := 0
teams := map[int]bool{}
for _, slot := range prepared.CasualLineup {
+4
View File
@@ -34,11 +34,15 @@ const (
type ProposalParticipant struct {
PlayerID string
Response Response
Team int
Slot int
}
type Proposal struct {
ProposalID string
Playlist Playlist
Region string
Protocol int
Participants []ProposalParticipant
State State
Revision uint64