Files
ClaudeDo/tests/ClaudeDo.Ui.Tests/ViewModels/WorktreesSettingsTabViewModelTests.cs
T
mika kuns b5464fc533 fix(worker-client): stop swallowing mutating hub call failures
TryInvokeAsync catches every exception and returns null, which is fine
for read-only calls but hid real HubException reasons behind a generic
"offline" message for the 7 mutating call sites (RestoreDefaultAgents,
UpsertPrimeSchedule, AddDailyNote, CleanupFinishedWorktrees,
ResetAllWorktrees, ForceRemoveWorktree, BuildPlanningIntegrationBranch)
— the same bug class fixed for ApproveReview in e1807fd. Each of the 22
TryInvokeAsync call sites was audited; the 15 read-only ones are left
unchanged (empty/offline is the right display). For the 7 switched to
a direct hub invoke, every caller was checked and, where it had no
catch, one was added so the exception surfaces (StatusMessage,
ShowErrorAsync/CombinedWarning) instead of crashing.
2026-07-29 13:19:38 +02:00

54 lines
1.8 KiB
C#

using System.IO;
using ClaudeDo.Localization;
using ClaudeDo.Ui.Localization;
using ClaudeDo.Ui.Services;
using ClaudeDo.Ui.ViewModels.Modals.Settings;
namespace ClaudeDo.Ui.Tests.ViewModels;
public class WorktreesSettingsTabViewModelTests
{
public WorktreesSettingsTabViewModelTests()
{
var dir = AppContext.BaseDirectory;
while (dir is not null && !Directory.Exists(Path.Combine(dir, "src", "ClaudeDo.Localization", "locales")))
dir = Path.GetDirectoryName(dir);
Loc.Current = new Localizer(
LocaleStore.Load(Path.Combine(dir!, "src", "ClaudeDo.Localization", "locales")), "en");
}
private sealed class ThrowingWorker : StubWorkerClient
{
public string ExceptionMessage { get; init; } = "disk full";
public override Task<WorktreeCleanupDto?> CleanupFinishedWorktreesAsync(string? listId = null) =>
throw new Exception(ExceptionMessage);
public override Task<WorktreeResetDto?> ResetAllWorktreesAsync() =>
throw new Exception(ExceptionMessage);
}
[Fact]
public async Task CleanupWorktrees_WhenWorkerThrows_ShowsExceptionMessage()
{
var worker = new ThrowingWorker();
var vm = new WorktreesSettingsTabViewModel(worker);
await vm.CleanupWorktreesCommand.ExecuteAsync(null);
Assert.Contains(worker.ExceptionMessage, vm.StatusMessage);
Assert.False(vm.IsBusy);
}
[Fact]
public async Task ConfirmResetAll_WhenWorkerThrows_ShowsExceptionMessage()
{
var worker = new ThrowingWorker();
var vm = new WorktreesSettingsTabViewModel(worker);
await vm.ConfirmResetAllCommand.ExecuteAsync(null);
Assert.Contains(worker.ExceptionMessage, vm.StatusMessage);
Assert.False(vm.IsBusy);
Assert.False(vm.ShowResetConfirm);
}
}