c412469773
Implements the suggestions from the last review pass:
- Add AmiReel.Tests (MSTest), covering the pure logic in Models/ and
Services/: SupportedVideoFormats, AppSettings normalization,
UserFacingErrors.Summarize, the new FfmpegProgressParser/
FfmpegOutputFilter, RenderPipeline.Validate, BuildProgressMessage, and
MoveSourceVideos. 59 tests, all passing. UI code-behind and anything that
spawns an actual FFmpeg process are left to manual/integration testing.
Exclude AmiReel.Tests\**\*.cs from AmiReel.csproj's default item glob —
it's a subfolder of the app project now, so without the exclude the app
itself was compiling the MSTest-only test files.
- Extract the FFmpeg version/library-banner boilerplate list that
ProcessRunner (live log filter) and UserFacingErrors (error summarizer)
had each duplicated into a shared FfmpegOutputFilter.IsBoilerplateLine;
each caller keeps its own remaining context-specific checks on top.
Also extract ProcessRunner's line-parsing regexes into a standalone
FfmpegProgressParser so it's directly unit-testable without spawning a
process.
- Convert AppSettings and RenderSettings from positional record
constructors to named `required` init properties. Both records had
runs of same-typed consecutive parameters (three string timing fields
in AppSettings; three doubles then five ints in RenderSettings) that a
positional constructor would let get silently transposed at a call site
without the compiler catching it. Update the two call sites
(MainPage.xaml.cs) to object-initializer syntax.
- Add Properties/AssemblyInfo.cs with InternalsVisibleTo("AmiReel.Tests")
and make Validate/BuildProgressMessage/IsNoise internal so tests can
reach them directly instead of only through process-spawning entry
points.
- README: document `dotnet test`, and note that Package.appxmanifest's
Identity is a local-dev placeholder that needs a real publisher/cert
before MSIX distribution.
Verified: dotnet build (solution + test project) is 0 warnings/errors,
dotnet test is 59/59 passing, and the app still launches unchanged.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
namespace AmiReel.Services;
|
|
|
|
public static class UserFacingErrors
|
|
{
|
|
public static string Summarize(Exception exception)
|
|
{
|
|
string message = exception.Message.Trim();
|
|
if (string.IsNullOrWhiteSpace(message))
|
|
return "An unexpected error occurred.";
|
|
|
|
string[] lines = message
|
|
.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
|
|
|
if (lines.Length == 0)
|
|
return "An unexpected error occurred.";
|
|
|
|
if (!lines[0].StartsWith("Process exited with code", StringComparison.OrdinalIgnoreCase))
|
|
return message;
|
|
|
|
List<string> important = [];
|
|
foreach (string line in lines.Skip(1))
|
|
{
|
|
if (IsNoise(line))
|
|
continue;
|
|
|
|
important.Add(line);
|
|
}
|
|
|
|
if (important.Count == 0)
|
|
return lines[0];
|
|
|
|
List<string> summary = [lines[0]];
|
|
foreach (string line in important.TakeLast(3))
|
|
{
|
|
if (!summary.Contains(line, StringComparer.Ordinal))
|
|
summary.Add(line);
|
|
}
|
|
|
|
return string.Join(Environment.NewLine, summary);
|
|
}
|
|
|
|
internal static bool IsNoise(string line)
|
|
{
|
|
return FfmpegOutputFilter.IsBoilerplateLine(line)
|
|
|| line.StartsWith("major_brand", StringComparison.OrdinalIgnoreCase)
|
|
|| line.StartsWith("minor_version", StringComparison.OrdinalIgnoreCase)
|
|
|| line.StartsWith("compatible_brands", StringComparison.OrdinalIgnoreCase)
|
|
|| line.StartsWith("encoder", StringComparison.OrdinalIgnoreCase)
|
|
|| line.StartsWith("[in#", StringComparison.OrdinalIgnoreCase)
|
|
|| line.StartsWith("[out#", StringComparison.OrdinalIgnoreCase)
|
|
|| line.StartsWith("Last message repeated", StringComparison.OrdinalIgnoreCase)
|
|
|| line.StartsWith("frame=", StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
}
|