Fix the error-state regressions from the #164 verification (#171) (#173)

T8: the invalid-FEN flash is generic; the client message and FEN go to the
log. A2: an expired confirmation link says so and lands on log-in, where an
unconfirmed account resends the email. W3: the connection banner gains Reload
and Home actions. D1: a failed export logs and redirects to the data tab with
a support address instead of a bare 500. D2: an unknown export format renders
the styled 404. H1: the empty-database home CTA points at the guest trainer
instead of auth-gated /endgames. X2/X3: the importer hides inspect(reason)
behind generic copy and logs it.

Adds coverage for the T8 copy, A2 destination, D2 404 page, H1 CTA and the W3
actions; the H1 tests now restore the curated-code override so async page
tests cannot poison each other.
This commit is contained in:
2026-11-13 16:46:29 +01:00
committed by GitHub
parent 8934d191ad
commit aebb2aecfb
13 changed files with 103 additions and 27 deletions
@@ -282,6 +282,17 @@ defmodule ChesstrainerWeb.Layouts do
{gettext("Attempting to reconnect")}
<.icon name="hero-arrow-path" class="ml-1 size-3 motion-safe:animate-spin" />
</.flash>
<div
id="connection-actions"
hidden
phx-disconnected={show("#connection-actions")}
phx-connected={hide("#connection-actions")}
class="pointer-events-auto flex items-center gap-3 rounded-lg border border-base-300 bg-base-100 px-4 py-2 text-sm shadow-lg"
>
<a href="" class="font-semibold text-primary-text hover:underline">Reload</a>
<.link href={~p"/"} class="text-muted hover:underline">Home</.link>
</div>
</div>
"""
end
@@ -8,6 +8,6 @@ defmodule ChesstrainerWeb.PageHTML do
embed_templates "page_html/*"
defp play_path(nil), do: ~p"/endgames"
defp play_path(nil), do: ~p"/guest-train"
defp play_path(%{public_code: public_code}), do: ~p"/endgames/#{public_code}/play"
end
@@ -12,9 +12,15 @@
Train your intuition to find the winning moves under pressure. Puzzle sessions focused purely on technical execution.
</p>
<div class="hero-actions">
<.pill_button variant={:primary} navigate={play_path(@active_endgame)}>
Try today's puzzle <.icon_arrow />
</.pill_button>
<%= if @active_endgame do %>
<.pill_button variant={:primary} navigate={play_path(@active_endgame)}>
Try today's puzzle <.icon_arrow />
</.pill_button>
<% else %>
<.pill_button variant={:primary} navigate={play_path(nil)}>
Start training <.icon_arrow />
</.pill_button>
<% end %>
<div class="rating-note">
<span class="avatar-stack">
<i>♟</i>
@@ -15,8 +15,11 @@ defmodule ChesstrainerWeb.UserConfirmationController do
:error ->
conn
|> put_flash(:error, "User not found or token is invalid.")
|> redirect(to: ~p"/users/register")
|> put_flash(
:error,
"That confirmation link is invalid or has expired. Log in to request a new one."
)
|> redirect(to: ~p"/users/log-in")
end
end
end
@@ -1,7 +1,10 @@
defmodule ChesstrainerWeb.UserDataController do
use ChesstrainerWeb, :controller
require Logger
alias Chesstrainer.Attempts
alias Chesstrainer.Branding
@user_columns ~w(user_username user_email user_rating user_rating_deviation user_plan user_joined_at)
@attempt_columns ~w(played_at puzzle public_code color result outcome rated_at)
@@ -9,16 +12,41 @@ defmodule ChesstrainerWeb.UserDataController do
def export(conn, %{"format" => format}) when format in ["csv", "json"] do
user = conn.assigns.current_scope.user
attempts = Attempts.list_attempts_for_user(user.id)
filename = "lucid-chess-data-#{Date.utc_today()}.#{format}"
conn
|> put_resp_content_type(content_type(format))
|> put_resp_header("content-disposition", ~s(attachment; filename="#{filename}"))
|> send_resp(200, body(format, user, attempts))
try do
attempts = Attempts.list_attempts_for_user(user.id)
filename = "lucid-chess-data-#{Date.utc_today()}.#{format}"
conn
|> put_resp_content_type(content_type(format))
|> put_resp_header("content-disposition", ~s(attachment; filename="#{filename}"))
|> send_resp(200, body(format, user, attempts))
rescue
exception ->
export_failed(conn, Exception.message(exception))
catch
:exit, reason ->
export_failed(conn, inspect(reason))
end
end
def export(conn, _params), do: send_resp(conn, 404, "Unknown export format")
def export(conn, _params) do
conn
|> put_status(:not_found)
|> put_view(ChesstrainerWeb.ErrorHTML)
|> render("404.html")
end
defp export_failed(conn, reason) do
Logger.error("profile.export_failed", reason: reason)
conn
|> put_flash(
:error,
"We couldn't build your export. Try again; if it keeps failing, email #{Branding.support_email()}."
)
|> redirect(to: ~p"/users/profile/data")
end
defp body("csv", user, attempts), do: to_csv(user, attempts)
@@ -8,6 +8,8 @@ defmodule ChesstrainerWeb.EndgameLive.Import do
use ChesstrainerWeb, :live_view
require Logger
alias Chesstrainer.Endgames.BulkImport
alias Chesstrainer.Endgames.Tablebase.Local
@@ -268,7 +270,14 @@ defmodule ChesstrainerWeb.EndgameLive.Import do
end
def handle_async(:lookup, {:exit, reason}, socket) do
{:noreply, put_flash(socket, :error, "Could not look up the FENs: #{inspect(reason)}")}
Logger.error("bulk_import.lookup_failed", reason: inspect(reason))
{:noreply,
put_flash(
socket,
:error,
"The lookup failed. Try again; if it keeps happening, check the server log."
)}
end
defp tablebase_status do
@@ -284,7 +293,8 @@ defmodule ChesstrainerWeb.EndgameLive.Import do
{:error, "Local tablebase is not configured. Set TABLEBASE_PATH to enable imports."}
{:error, reason} ->
{:error, "Local tablebase failed to load: #{inspect(reason)}"}
Logger.warning("bulk_import.tablebase_unavailable", reason: inspect(reason))
{:error, "The local tablebase failed to load. Check TABLEBASE_PATH and the server log."}
end
end
@@ -197,12 +197,10 @@ defmodule ChesstrainerWeb.EndgameLive.PlayCore do
end
def fen_invalid(socket, %{"fen" => fen, "message" => message}) do
Logger.warning("board.fen_invalid", fen: fen, message: message)
{:noreply,
put_flash(
socket,
:error,
"Endgame FEN is invalid and the board cannot be loaded: #{message} (#{fen})"
)}
put_flash(socket, :error, "The board couldn't load this position. Reset to try again.")}
end
def reset(socket) do