Add replayable debug reports.
A report dumps everything needed to understand a game that went wrong:
the full state (decks card by card, shop row and tier deck order,
discards, pending choices, banked Mana/Trumpets/apples), the round's
battles, and the whole event log. Available as JSON, which replays, or
text, which reads — and the text ends with a paste-ready repro test.
Battles now record the randomness they consume alongside what they
started from, so a result can be replayed long after the round cleared
those banks: same lineups, same dice, same events, down to the log text.
Results predating the recording say so rather than quietly re-rolling.
Three ways in: the 🐛 panel's download/copy buttons, GET
/api/debug/report (DEBUG-only, since a report holds both players' hands
and the shop deck order), and `mise run report`, which reads the
database directly so a live game can be dumped without DEBUG.
This commit is contained in:
@@ -79,6 +79,45 @@ func (s *Store) LoadByCode(code string) (*game.Game, error) {
|
||||
return s.loadWhere(`code = ?`, code)
|
||||
}
|
||||
|
||||
// LoadAny fetches a game by join code or by ID, whichever the argument looks
|
||||
// like — the convenience the report command wants, since a bug report quotes
|
||||
// whichever of the two the reporter had to hand.
|
||||
func (s *Store) LoadAny(idOrCode string) (*game.Game, error) {
|
||||
if g, err := s.LoadByCode(idOrCode); err == nil {
|
||||
return g, nil
|
||||
} else if !errors.Is(err, ErrNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
return s.Load(idOrCode)
|
||||
}
|
||||
|
||||
// Recent returns the most recently updated games, newest first, for picking one
|
||||
// out by hand. Each is fully loaded, so callers can report on it directly.
|
||||
func (s *Store) Recent(limit int) ([]*game.Game, error) {
|
||||
if limit <= 0 {
|
||||
limit = 20
|
||||
}
|
||||
rows, err := s.db.Query(`SELECT state FROM games ORDER BY updated_at DESC LIMIT ?`, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var games []*game.Game
|
||||
for rows.Next() {
|
||||
var blob string
|
||||
if err := rows.Scan(&blob); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var g game.Game
|
||||
if err := json.Unmarshal([]byte(blob), &g); err != nil {
|
||||
// One corrupt row shouldn't hide the rest of the list.
|
||||
continue
|
||||
}
|
||||
games = append(games, &g)
|
||||
}
|
||||
return games, rows.Err()
|
||||
}
|
||||
|
||||
func (s *Store) loadWhere(cond string, arg any) (*game.Game, error) {
|
||||
var blob string
|
||||
err := s.db.QueryRow(`SELECT state FROM games WHERE `+cond, arg).Scan(&blob)
|
||||
|
||||
Reference in New Issue
Block a user