Reject out-of-range endgame FENs at entry (#25)

Add FEN.piece_count/1 and reject positions with more than 7 pieces in the Endgame changeset, so an 8+ piece FEN fails at entry instead of saving and then blocking at play.

Accumulate all FEN issues rather than letting a later check overwrite an earlier one, and guard the seed FENs with a test (dropping the out-of-range seed that bypassed the changeset).
This commit is contained in:
2026-11-03 12:18:22 +01:00
parent dd060531d3
commit ff7adcf308
6 changed files with 128 additions and 10 deletions
+24
View File
@@ -0,0 +1,24 @@
defmodule Chesstrainer.SeedsTest do
use ExUnit.Case, async: true
alias Chesstrainer.FEN
Code.require_file("../../priv/repo/seeds/endgames.ex", __DIR__)
describe "seed endgames" do
test "are normalised and within tablebase range" do
for endgame <- Chesstrainer.Repo.Seeds.Endgames.all() do
fen = FEN.normalize(endgame.fen)
assert length(String.split(fen, " ")) == 6,
"seed FEN must have 6 fields: #{endgame.fen}"
refute String.ends_with?(fen, " 0"),
"seed FEN keeps fullmove 0 after normalisation: #{endgame.fen}"
assert FEN.piece_count(fen) <= 7,
"seed FEN has more than 7 pieces: #{endgame.fen}"
end
end
end
end