v0.16.2 PGN site, web client panel update
test / test (push) Canceled after 0s
test / e2e (push) Canceled after 0s

This commit is contained in:
lixen committed 2026-10-20 01:39:53 -04:00
1 parent 0461020c46
commit a012d07cd8
12 files changed
+84 -45

No files matched your search

+4 -3
View File
@@ -52,8 +52,9 @@ type PGN struct {
// BuildPGN exports a stored game. ply < 0 exports every move; otherwise the
// first ply moves, with result "*" and no termination when that stops short
// of the end of the line.
func BuildPGN(record *storage.GameRecord, moves []storage.MoveRecord, ply int) (*PGN, error) {
// of the end of the line. site is the Site tag of a game played on this
// server (PGN's "?" when empty); an imported game keeps its own.
func BuildPGN(record *storage.GameRecord, moves []storage.MoveRecord, ply int, site string) (*PGN, error) {
if ply > len(moves) {
return nil, fmt.Errorf("%w: game has %d plies", ErrPlyOutOfRange, len(moves))
}
@@ -75,7 +76,7 @@ func BuildPGN(record *storage.GameRecord, moves []storage.MoveRecord, ply int) (
}
}
start := record.StartTimeUTC.UTC()
event, site, round := "Casual game", "", ""
event, round := "Casual game", ""
if record.ImportedBy != "" {
event, site, round = record.Event, record.Site, record.Round
if event == "" {
+25 -5
View File
@@ -129,7 +129,7 @@ func TestBuildPGN(t *testing.T) {
rec := record(chess.StartFEN, "white_wins", "resignation")
rec.BlackType, rec.BlackLevel, rec.WhiteType, rec.WhiteName = 2, 4, 1, "alice"
pgn, err := BuildPGN(rec, moves, -1)
pgn, err := BuildPGN(rec, moves, -1, "")
if err != nil {
t.Fatal(err)
}
@@ -143,25 +143,45 @@ func TestBuildPGN(t *testing.T) {
t.Errorf("filename %q", pgn.Filename)
}
partial, err := BuildPGN(rec, moves, 1)
partial, err := BuildPGN(rec, moves, 1, "")
if err != nil {
t.Fatal(err)
}
if !strings.HasSuffix(partial.Text, "\n\n1. e4 *\n") || partial.Filename != "chess-20260928-68007fd1-ply1.pgn" {
t.Errorf("partial %q:\n%s", partial.Filename, partial.Text)
}
if _, err := BuildPGN(rec, moves, 3); err == nil {
if _, err := BuildPGN(rec, moves, 3, ""); err == nil {
t.Error("ply beyond the line accepted")
}
}
// A game played here names the server's site; an imported game keeps its own.
func TestBuildPGNSite(t *testing.T) {
moves := stored(t, chess.StartFEN, "e2e4")
rec := record(chess.StartFEN, "", "")
for _, tc := range []struct{ importedBy, recordSite, site, want string }{
{"", "", "lixen.com", "lixen.com"},
{"", "", "", "?"},
{"alice", "Linares ESP", "lixen.com", "Linares ESP"},
} {
rec.ImportedBy, rec.Site = tc.importedBy, tc.recordSite
pgn, err := BuildPGN(rec, moves, -1, tc.site)
if err != nil {
t.Fatal(err)
}
if want := "[Site \"" + tc.want + "\"]\n"; !strings.Contains(pgn.Text, want) {
t.Errorf("site %q, imported by %q: PGN lacks %q:\n%s", tc.site, tc.importedBy, want, pgn.Text)
}
}
}
// A resignation taken back by an undo is noted before the live result.
func TestBuildPGNNotesContinuedConcession(t *testing.T) {
moves := stored(t, chess.StartFEN, "e2e4", "e7e5", "d2d4")
rec := record(chess.StartFEN, "", "")
rec.ConcessionResult, rec.ConcessionTermination, rec.ConcessionPly = "black_wins", "resignation", 2
pgn, err := BuildPGN(rec, moves, -1)
pgn, err := BuildPGN(rec, moves, -1, "")
if err != nil {
t.Fatal(err)
}
@@ -171,7 +191,7 @@ func TestBuildPGNNotesContinuedConcession(t *testing.T) {
// The concession that is still the result needs no note.
rec.Result, rec.Termination, rec.ConcessionPly = "black_wins", "resignation", 3
if pgn, _ = BuildPGN(rec, moves, -1); strings.Contains(pgn.Text, "continued") {
if pgn, _ = BuildPGN(rec, moves, -1, ""); strings.Contains(pgn.Text, "continued") {
t.Errorf("standing resignation noted as continued:\n%s", pgn.Text)
}
}