using System; using System.Threading.Tasks; using ClaudeDo.Data.Models; using ClaudeDo.Ui.ViewModels; namespace ClaudeDo.Ui.Tests; // Covers the "restart worker" footer feedback fix: RestartWorkerStatus used to be set but was // never bound in any view, so a died-on-launch worker (e.g. a port conflict, see #292) restarted // silently. RestartWorkerOperation is a test seam standing in for the real kill-and-relaunch + // short-timeout survival check, so these tests only assert the success/failure routing to the // shared footer strip (WorkerLogText/WorkerLogLevel), not real process spawning. public class IslandsShellViewModelRestartWorkerTests { [Fact] public async Task ProcessSurvives_FlashesFooterSuccess() { var vm = new IslandsShellViewModel { RestartWorkerOperation = () => Task.CompletedTask }; await vm.RestartWorkerCommand.ExecuteAsync(null); Assert.Equal(WorkerLogLevel.Success, vm.WorkerLogLevel); Assert.Contains("restarted", vm.WorkerLogText); Assert.True(vm.IsWorkerLogVisible); } [Fact] public async Task ProcessDiesWithinTimeout_FlashesFooterError() { var vm = new IslandsShellViewModel { RestartWorkerOperation = () => throw new InvalidOperationException("worker process exited immediately (code 1)") }; await vm.RestartWorkerCommand.ExecuteAsync(null); Assert.Equal(WorkerLogLevel.Error, vm.WorkerLogLevel); Assert.Contains("worker process exited immediately", vm.WorkerLogText); Assert.True(vm.IsWorkerLogVisible); } }