* chore(build)!: move to .NET 10 LTS, refresh dependencies, enforce LF + SPDX headers .NET 9 reaches end of support on 2026-11-10 and this machine only has .NET 10 SDKs, so the repo no longer built locally. - global.json: SDK 10.0.401 (latestFeature) + Microsoft.Testing.Platform runner - all projects retargeted to net10.0 / net10.0-windows10.0.22621.0 - Directory.Build.props: single version source (App no longer overrides it), TreatWarningsAsErrors everywhere, lock files + locked restore in CI, NuGetAudit (all, low), EnableWindowsTargeting (Dependabot evaluated every Windows-TFM project as "not compatible" without it), XML docs on so IDE0005 runs in build - packages: Microsoft.Extensions 10.0.13, Serilog 4.4.0 (+ sinks/extensions), CommunityToolkit.Mvvm 8.4.2, Stateless 5.20.1, Vortice 3.8.3, SkiaSharp 4.153.1, Velopack 1.2.161 (DownloadUpdatesAsync lost ignoreDeltas; CheckForUpdatesAsync now honours cancellation via WaitAsync), WinAppSDK last 1.8 patch - security: drop SixLabors.ImageSharp 3.1.12 (GHSA-j3p4-wp97-rph4, GHSA-j9gm-c75j-xc9q, GHSA-jjfr-hcj7-qf5w high; GHSA-gwg2-r3hj-4w44, GHSA-wmxv-xphr-5c9g moderate) — TIFF now goes through the built-in WIC encoder (opaque, LZW) - removed unused references: M.E.Hosting/Localization/Options/DI.Abstractions where unused, Serilog sinks in Infrastructure, SkiaSharp.NativeAssets.Win32 (transitive), CsWinRT, Microsoft.Win32.Registry, H.NotifyIcon, Hosting.Abstractions - tests: xunit 2 -> xunit.v3 4.0.2 (MTP v2), FluentAssertions 6 -> AwesomeAssertions 9 (FA >= 8 is commercially licensed), NSubstitute 6, coverlet -> Microsoft.Testing.Extensions.CodeCoverage; tests pass the xunit cancellation token - .gitattributes: eol=lf everywhere (matches .editorconfig); .gitignore now ignores .idea/ and .claude/ - .editorconfig: SPDX header template (IDE0073) and IDE0161/0065/0005/0051/ 0052/0059/0060 enforced in build; headers added to every C# file, whitespace normalised; dead IID field and unused parameter/field removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci: required quality gates, hardened release pipeline, working Dependabot New required checks (one job each, no path filters so they always report): - build: locked restore, Release build with warnings as errors, tests on Microsoft.Testing.Platform with Cobertura coverage summarised in the job summary - format: `dotnet format whitespace` + style subset (SPDX header, file-scoped namespaces, using placement, unnecessary usings) - deadcode: JetBrains InspectCode gated on file-local dead/redundant-code rules (WinUI projects excluded until they are replaced) - audit: `dotnet list package --vulnerable --include-transitive` parsed by a gate script (the command itself always exits 0) - license: nuget-license allowlist for the shipped app's dependency closure - publish-smoke: publishes the app and verifies the payload (.pri/.xbf, legal docs) - pr-title (Conventional Commits), dependency-review (vulnerabilities of any severity + non-free licenses), workflow-lint (actionlint + zizmor), docs (markdownlint + offline lychee); weekly external link check and OpenSSF Scorecard are informational Release workflow: - version taken from the tag through env + SemVer regex (removes the `${{ github.event.inputs.version }}` script injection) and checked against Directory.Build.props; prerelease derived from the version - vpk pinned through the tool manifest (was unpinned while the library was 0.0.1053); full packages only, so the previous release's 100 MB package is no longer re-uploaded; release notes come from CHANGELOG (the in-app update page showed none); identical packId/title/shortcuts/mainExe - CycloneDX SBOM, SHA256SUMS of this version's assets, build-provenance attestations; release is created as a draft via gh (no third-party action with a write token); workflow_dispatch can rebuild an existing tag or dry-run Other workflows: every action pinned to a commit SHA; least-privilege permissions per job; notify-ci-failure ignores fork pull requests (they could post their commit message to Discord) and all callers pass only the secrets they need instead of `secrets: inherit`; announce-release now fires because releases are published with a user token; discussion-welcome pinned and lists security@. Removed .github/scripts/discord_notify.py (unused; the reusable workflows carry their own copy). Dependabot: EnableWindowsTargeting fixes the "not compatible" evaluation; dead avalonia group removed; ecosystems grouped (incl. Velopack + vpk), 3-day cooldown, tool manifest covered; version-update PRs paused (limit 0) until the 2.0.0 release. Repo tooling: .config/dotnet-tools.json (vpk, InspectCode, nuget-license, ReportGenerator, CycloneDX), markdownlint + lychee configs, RuntimeIdentifiers win-x64 for stable lock files, CLAUDE.md for AI assistants, markdown lint fixes, and the remaining InspectCode findings in Core/Infrastructure/ViewModels fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci: fix first-run findings of the new gates - dependency-review: drop Commons-Clause from deny-licenses (not an SPDX id) - docs: disable markdownlint MD060 (table pipe alignment) introduced in markdownlint 0.41, which the CI action ships - Dependabot cooldown 3 -> 7 days (zizmor dependabot-cooldown audit) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci: quote InspectCode arguments, force HTTPS for actionlint download - PowerShell splits a dash-prefixed native argument at its first period, so -o=inspectcode.sarif reached InspectCode as two arguments ('Specify only one solution file'); arguments are now quoted - curl in workflow-lint refuses non-HTTPS protocols and redirects (SonarCloud githubactions:S6506) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
186 lines
6.0 KiB
C#
186 lines
6.0 KiB
C#
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// Copyright (c) CaptureImage Contributors
|
|
|
|
using AwesomeAssertions;
|
|
using CaptureImage.Core.Models;
|
|
using CaptureImage.Core.Pipeline;
|
|
using Xunit;
|
|
|
|
namespace CaptureImage.Core.Tests.Pipeline;
|
|
|
|
public class FileNameStrategyTests
|
|
{
|
|
private static GameTarget MakeTarget(
|
|
string displayName = "Notepad",
|
|
string processName = "notepad") =>
|
|
new(
|
|
ProcessId: 1234,
|
|
WindowHandle: 0,
|
|
ProcessName: processName,
|
|
WindowTitle: displayName,
|
|
ExecutablePath: @"C:\Windows\System32\notepad.exe",
|
|
IconBytes: null,
|
|
SteamInfo: null);
|
|
|
|
private static DateTimeOffset FixedTime =>
|
|
new(2026, 4, 15, 19, 30, 45, TimeSpan.Zero);
|
|
|
|
[Fact]
|
|
public void Expand_AllTokens_ProducesExpectedString()
|
|
{
|
|
var target = MakeTarget(displayName: "Super Mario", processName: "mario");
|
|
var template = "{Game}_{Process}_{yyyy}-{MM}-{dd}_{HH}-{mm}-{ss}";
|
|
|
|
var result = FileNameStrategy.ExpandTokens(template, target, FixedTime);
|
|
|
|
result.Should().Be("Super Mario_mario_2026-04-15_19-30-45");
|
|
}
|
|
|
|
[Fact]
|
|
public void Expand_UnknownToken_IsLeftVerbatim()
|
|
{
|
|
var target = MakeTarget();
|
|
var result = FileNameStrategy.ExpandTokens("{Game}_{unknown}_suffix", target, FixedTime);
|
|
|
|
result.Should().Be("Notepad_{unknown}_suffix");
|
|
}
|
|
|
|
[Fact]
|
|
public void Expand_CounterToken_IsRemovedFromTemplate()
|
|
{
|
|
// {counter} is handled later by collision logic, not by ExpandTokens.
|
|
var target = MakeTarget();
|
|
var result = FileNameStrategy.ExpandTokens("{Game}{counter}", target, FixedTime);
|
|
|
|
result.Should().Be("Notepad");
|
|
}
|
|
|
|
[Fact]
|
|
public void Sanitize_IllegalCharacters_AreReplacedWithUnderscore()
|
|
{
|
|
var result = FileNameStrategy.Sanitize(@"My<Game>:""/\|?*Name");
|
|
|
|
result.Should().NotContainAny("<", ">", ":", "\"", "/", "\\", "|", "?", "*");
|
|
result.Should().Contain("My");
|
|
result.Should().Contain("Name");
|
|
}
|
|
|
|
[Fact]
|
|
public void Sanitize_WhitespaceRuns_AreCollapsed()
|
|
{
|
|
FileNameStrategy.Sanitize("A B\t\tC").Should().Be("A B C");
|
|
}
|
|
|
|
[Fact]
|
|
public void Sanitize_EmptyInput_ReturnsDefaultName()
|
|
{
|
|
FileNameStrategy.Sanitize(" ").Should().Be("capture");
|
|
FileNameStrategy.Sanitize(string.Empty).Should().Be("capture");
|
|
}
|
|
|
|
[Fact]
|
|
public void Sanitize_OnlyIllegalCharacters_ReturnsDefaultName()
|
|
{
|
|
FileNameStrategy.Sanitize(@"<<<>>>").Should().Be("capture");
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildFilePath_NoCollision_UsesSanitizedBase()
|
|
{
|
|
var strategy = new FileNameStrategy(_ => false);
|
|
var target = MakeTarget(displayName: "Notepad");
|
|
|
|
var path = strategy.BuildFilePath(
|
|
directory: @"C:\Captures",
|
|
template: "{Game}_{yyyy}-{MM}-{dd}_{HH}-{mm}-{ss}",
|
|
target: target,
|
|
captureTime: FixedTime,
|
|
format: ImageFormat.Png);
|
|
|
|
path.Should().Be(@"C:\Captures\Notepad_2026-04-15_19-30-45.png");
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildFilePath_CollisionOnce_AppendsCounter1()
|
|
{
|
|
var existing = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
@"C:\Captures\Notepad_2026-04-15_19-30-45.png",
|
|
};
|
|
var strategy = new FileNameStrategy(existing.Contains);
|
|
var target = MakeTarget();
|
|
|
|
var path = strategy.BuildFilePath(
|
|
@"C:\Captures", "{Game}_{yyyy}-{MM}-{dd}_{HH}-{mm}-{ss}",
|
|
target, FixedTime, ImageFormat.Png);
|
|
|
|
path.Should().Be(@"C:\Captures\Notepad_2026-04-15_19-30-45_1.png");
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildFilePath_ManyCollisions_IncrementsCounterUntilFree()
|
|
{
|
|
var existing = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
@"C:\Captures\Notepad_2026-04-15_19-30-45.png",
|
|
@"C:\Captures\Notepad_2026-04-15_19-30-45_1.png",
|
|
@"C:\Captures\Notepad_2026-04-15_19-30-45_2.png",
|
|
@"C:\Captures\Notepad_2026-04-15_19-30-45_3.png",
|
|
};
|
|
var strategy = new FileNameStrategy(existing.Contains);
|
|
|
|
var path = strategy.BuildFilePath(
|
|
@"C:\Captures", "{Game}_{yyyy}-{MM}-{dd}_{HH}-{mm}-{ss}",
|
|
MakeTarget(), FixedTime, ImageFormat.Png);
|
|
|
|
path.Should().Be(@"C:\Captures\Notepad_2026-04-15_19-30-45_4.png");
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(ImageFormat.Png, "png")]
|
|
[InlineData(ImageFormat.Jpeg, "jpg")]
|
|
[InlineData(ImageFormat.Webp, "webp")]
|
|
[InlineData(ImageFormat.Tiff, "tiff")]
|
|
public void BuildFilePath_RespectsFormatExtension(ImageFormat format, string expectedExt)
|
|
{
|
|
var strategy = new FileNameStrategy(_ => false);
|
|
var path = strategy.BuildFilePath(
|
|
@"C:\Captures", "{Game}",
|
|
MakeTarget(), FixedTime, format);
|
|
|
|
Path.GetExtension(path).Should().Be("." + expectedExt);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildFilePath_TargetWithIllegalCharsInTitle_StillProducesValidPath()
|
|
{
|
|
var target = MakeTarget(displayName: "Doom/Eternal: Part <2>");
|
|
var strategy = new FileNameStrategy(_ => false);
|
|
|
|
var path = strategy.BuildFilePath(
|
|
@"C:\Captures", "{Game}",
|
|
target, FixedTime, ImageFormat.Png);
|
|
|
|
var fileName = Path.GetFileName(path);
|
|
fileName.Should().NotContainAny("<", ">", ":", "\"", "/", "\\", "|", "?", "*");
|
|
}
|
|
|
|
[Fact]
|
|
public void ImageFormat_Extension_ReturnsLowercaseExtension()
|
|
{
|
|
ImageFormat.Png.Extension().Should().Be("png");
|
|
ImageFormat.Jpeg.Extension().Should().Be("jpg");
|
|
ImageFormat.Webp.Extension().Should().Be("webp");
|
|
ImageFormat.Tiff.Extension().Should().Be("tiff");
|
|
}
|
|
|
|
[Fact]
|
|
public void ImageFormat_MimeType_ReturnsStandardMime()
|
|
{
|
|
ImageFormat.Png.MimeType().Should().Be("image/png");
|
|
ImageFormat.Jpeg.MimeType().Should().Be("image/jpeg");
|
|
ImageFormat.Webp.MimeType().Should().Be("image/webp");
|
|
ImageFormat.Tiff.MimeType().Should().Be("image/tiff");
|
|
}
|
|
}
|