From 45c9b819838d46461cfd7431c805f86d667ae7bd Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 3 Jun 2026 02:37:12 +0200 Subject: [PATCH] fix(import): collapse duplicate fee-type warnings into a bounded list --- lib/mv/membership/import/import_runner.ex | 2 +- .../membership/import/import_runner_test.exs | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/lib/mv/membership/import/import_runner.ex b/lib/mv/membership/import/import_runner.ex index b56cae6..28893a3 100644 --- a/lib/mv/membership/import/import_runner.ex +++ b/lib/mv/membership/import/import_runner.ex @@ -80,7 +80,7 @@ defmodule Mv.Membership.Import.ImportRunner do all_errors = progress.errors ++ chunk_result.errors new_errors = Enum.take(all_errors, max_errors) errors_truncated? = length(all_errors) > max_errors - new_warnings = progress.warnings ++ Map.get(chunk_result, :warnings, []) + new_warnings = Enum.uniq(progress.warnings ++ Map.get(chunk_result, :warnings, [])) chunks_processed = current_chunk_idx + 1 new_status = if chunks_processed >= progress.total_chunks, do: :done, else: :running diff --git a/test/mv/membership/import/import_runner_test.exs b/test/mv/membership/import/import_runner_test.exs index 22d21bd..b5fe3c2 100644 --- a/test/mv/membership/import/import_runner_test.exs +++ b/test/mv/membership/import/import_runner_test.exs @@ -21,6 +21,65 @@ defmodule Mv.Membership.Import.ImportRunnerTest do end end + describe "merge_progress/4 warning accumulation" do + test "deduplicates identical warnings across chunks instead of growing unbounded" do + progress = %{ + inserted: 0, + failed: 0, + errors: [], + warnings: ["Fee type 'Ghost' not found; using the default fee type."], + status: :running, + current_chunk: 0, + total_chunks: 3 + } + + chunk_result = %{ + inserted: 2, + failed: 0, + errors: [], + errors_truncated?: false, + warnings: [ + "Fee type 'Ghost' not found; using the default fee type.", + "Fee type 'Ghost' not found; using the default fee type." + ] + } + + result = ImportRunner.merge_progress(progress, chunk_result, 0) + + assert result.warnings == ["Fee type 'Ghost' not found; using the default fee type."] + end + + test "preserves distinct warnings while collapsing duplicates" do + progress = %{ + inserted: 0, + failed: 0, + errors: [], + warnings: ["Fee type 'A' not found; using the default fee type."], + status: :running, + current_chunk: 0, + total_chunks: 2 + } + + chunk_result = %{ + inserted: 1, + failed: 0, + errors: [], + errors_truncated?: false, + warnings: [ + "Fee type 'A' not found; using the default fee type.", + "Fee type 'B' not found; using the default fee type." + ] + } + + result = ImportRunner.merge_progress(progress, chunk_result, 0) + + assert result.warnings == [ + "Fee type 'A' not found; using the default fee type.", + "Fee type 'B' not found; using the default fee type." + ] + end + end + describe "read_file_entry/2" do test "returns {:ok, content} for a readable file" do path =