Files
poli0981andClaude Opus 4.8 44cdfe838b Phase 4: Velopack auto-update
Add the update path per the roadmap: IUpdateService -> VelopackUpdateService
(GithubSource against the project repo; per-user install, no UAC), a minimal
"Check for updates" dialog (check -> prompt -> progress -> apply & restart),
mapped error dialogs (404/403/429/5xx/offline; 419 is not special-cased), an
"auto-check on startup" setting, and scripts/pack.ps1 for vpk packaging.

- Application stays Velopack-free: UpdateError, UpdateCheckResult, pure
  UpdateErrorMapper, widened IUpdateService, CheckForUpdateUseCase.
- Infrastructure: VelopackUpdateService (lazy manager, degrades to NotInstalled
  in dev) + VelopackBootstrap so the WPF layer never references Velopack.
- WPF: UpdateViewModel/UpdateDialog, IUpdateDialogService, Tools menu item,
  VelopackApp.Build().Run() at startup + non-blocking auto-check, gated on the
  Phase 3 "command running" guard before applying.
- Tests: error mapping (429 handled, 419 -> Unknown), use-case pass-through,
  DI resolution.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-17 22:34:32 +07:00

56 lines
2.2 KiB
C#

using System.Net;
using CommandForge.Application.Ports;
using CommandForge.Application.Updates;
namespace CommandForge.Tests;
/// <summary>
/// Verifies the HTTP-status → <see cref="UpdateError"/> mapping (must-have test per Testing.md).
/// The key invariant: 429 is handled, and 419 (the Laravel CSRF myth) is NOT special-cased.
/// </summary>
public sealed class UpdateErrorMappingTests
{
[Theory]
[InlineData(HttpStatusCode.NotFound, UpdateError.NotFound)] // 404
[InlineData(HttpStatusCode.Forbidden, UpdateError.RateLimited)] // 403 (primary rate limit)
[InlineData(HttpStatusCode.TooManyRequests, UpdateError.RateLimited)] // 429 (secondary rate limit)
[InlineData(HttpStatusCode.InternalServerError, UpdateError.ServerError)] // 500
[InlineData(HttpStatusCode.ServiceUnavailable, UpdateError.ServerError)] // 503
[InlineData(HttpStatusCode.BadGateway, UpdateError.ServerError)] // 502
public void Map_HttpStatus_MapsToExpectedError(HttpStatusCode status, UpdateError expected)
{
var result = UpdateErrorMapper.Map(status, new HttpRequestException("boom", null, status));
Assert.Equal(expected, result);
}
[Fact]
public void Map_OfflineHttpRequestException_WithNoStatus_MapsToOffline()
{
var result = UpdateErrorMapper.Map(null, new HttpRequestException("no network"));
Assert.Equal(UpdateError.Offline, result);
}
[Fact]
public void Map_TaskCanceled_WithNoStatus_MapsToOffline()
{
var result = UpdateErrorMapper.Map(null, new TaskCanceledException());
Assert.Equal(UpdateError.Offline, result);
}
[Fact]
public void Map_419_IsNotSpecialCased_MapsToUnknown()
{
// 419 is a Laravel CSRF code, not a GitHub status — it must fall through to Unknown.
var status = (HttpStatusCode)419;
var result = UpdateErrorMapper.Map(status, new HttpRequestException("csrf myth", null, status));
Assert.Equal(UpdateError.Unknown, result);
}
[Fact]
public void Map_UnexpectedExceptionWithNoStatus_MapsToUnknown()
{
var result = UpdateErrorMapper.Map(null, new InvalidOperationException());
Assert.Equal(UpdateError.Unknown, result);
}
}