chore(claude-do): merge [A1] Detail-Pane: Approve, Submit, Reject, Park, Merge-Previ
ClaudeDo-Task: 120cb6a4-ad0d-426a-bb72-e3c508698b8f
This commit is contained in:
@@ -299,7 +299,12 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase, IDisposable
|
|||||||
[NotifyCanExecuteChangedFor(nameof(RejectReviewCommand))]
|
[NotifyCanExecuteChangedFor(nameof(RejectReviewCommand))]
|
||||||
private string _reviewFeedback = "";
|
private string _reviewFeedback = "";
|
||||||
|
|
||||||
public bool HasReviewFeedback => !string.IsNullOrWhiteSpace(ReviewFeedback);
|
public bool HasReviewFeedback => !string.IsNullOrWhiteSpace(ReviewFeedback) && !RejectOp.IsRunning;
|
||||||
|
|
||||||
|
public OperationStatus ApproveOp { get; } = new();
|
||||||
|
public OperationStatus SubmitOp { get; } = new();
|
||||||
|
public OperationStatus RejectOp { get; } = new();
|
||||||
|
public OperationStatus ParkOp { get; } = new();
|
||||||
|
|
||||||
public DetailsIslandViewModel(
|
public DetailsIslandViewModel(
|
||||||
IDbContextFactory<ClaudeDoDbContext> dbFactory,
|
IDbContextFactory<ClaudeDoDbContext> dbFactory,
|
||||||
@@ -330,6 +335,30 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase, IDisposable
|
|||||||
};
|
};
|
||||||
Prep = new PrepPanelViewModel(worker);
|
Prep = new PrepPanelViewModel(worker);
|
||||||
|
|
||||||
|
// OperationStatus.IsRunning is a nested ObservableObject property, so
|
||||||
|
// [NotifyCanExecuteChangedFor] on the command can't see it -- without this, the
|
||||||
|
// button stays clickable for the whole duration of the call.
|
||||||
|
ApproveOp.PropertyChanged += (_, e) =>
|
||||||
|
{
|
||||||
|
if (e.PropertyName == nameof(OperationStatus.IsRunning)) ApproveReviewCommand.NotifyCanExecuteChanged();
|
||||||
|
};
|
||||||
|
SubmitOp.PropertyChanged += (_, e) =>
|
||||||
|
{
|
||||||
|
if (e.PropertyName == nameof(OperationStatus.IsRunning)) SubmitForReviewCommand.NotifyCanExecuteChanged();
|
||||||
|
};
|
||||||
|
RejectOp.PropertyChanged += (_, e) =>
|
||||||
|
{
|
||||||
|
if (e.PropertyName == nameof(OperationStatus.IsRunning))
|
||||||
|
{
|
||||||
|
OnPropertyChanged(nameof(HasReviewFeedback));
|
||||||
|
RejectReviewCommand.NotifyCanExecuteChanged();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ParkOp.PropertyChanged += (_, e) =>
|
||||||
|
{
|
||||||
|
if (e.PropertyName == nameof(OperationStatus.IsRunning)) ParkReviewCommand.NotifyCanExecuteChanged();
|
||||||
|
};
|
||||||
|
|
||||||
Notes = new NotesEditorViewModel(_notesApi);
|
Notes = new NotesEditorViewModel(_notesApi);
|
||||||
Notes.ErrorReported += msg => { if (ShowErrorAsync is not null) _ = ShowErrorAsync(msg); };
|
Notes.ErrorReported += msg => { if (ShowErrorAsync is not null) _ = ShowErrorAsync(msg); };
|
||||||
Subtasks.CollectionChanged += (_, _) => NotifyStepsChanged();
|
Subtasks.CollectionChanged += (_, _) => NotifyStepsChanged();
|
||||||
@@ -1218,12 +1247,22 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase, IDisposable
|
|||||||
private async System.Threading.Tasks.Task ApproveReviewAsync()
|
private async System.Threading.Tasks.Task ApproveReviewAsync()
|
||||||
{
|
{
|
||||||
if (Task is null || !_worker.IsConnected) return;
|
if (Task is null || !_worker.IsConnected) return;
|
||||||
|
var taskId = Task.Id;
|
||||||
|
using var op = ApproveOp.Begin(Loc.T("ops.merge.merging"));
|
||||||
|
// Subscribed only for the duration of the call: the worker broadcasts to every
|
||||||
|
// client, and a VM left on this event would keep reacting to merges for other tasks.
|
||||||
|
void OnMergeProgress(string progressTaskId, string phase, int elapsedSeconds)
|
||||||
|
{
|
||||||
|
if (progressTaskId != taskId || phase != MergePhaseVerifying) return;
|
||||||
|
ApproveOp.Report(Loc.T("ops.merge.verifying", FormatElapsed(elapsedSeconds)));
|
||||||
|
}
|
||||||
|
_worker.MergeProgressEvent += OnMergeProgress;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var hasChildren = Subtasks.Count > 0 || ChildOutcomes.Count > 0;
|
var hasChildren = Subtasks.Count > 0 || ChildOutcomes.Count > 0;
|
||||||
var result = await _worker.ApproveReviewAsync(Task.Id, Merge.SelectedMergeTarget ?? "");
|
var result = await _worker.ApproveReviewAsync(taskId, Merge.SelectedMergeTarget ?? "");
|
||||||
if (!hasChildren && result?.Status == "conflict")
|
if (!hasChildren && result?.Status == "conflict")
|
||||||
await _merge.ResolveConflictAsync(Task.Id, Merge.SelectedMergeTarget ?? "");
|
await _merge.ResolveConflictAsync(taskId, Merge.SelectedMergeTarget ?? "");
|
||||||
// The merge itself already landed; the verify command failed, so the task stayed
|
// The merge itself already landed; the verify command failed, so the task stayed
|
||||||
// out of Done. Surface that instead of silently looking like nothing happened.
|
// out of Done. Surface that instead of silently looking like nothing happened.
|
||||||
else if (!hasChildren && result?.Status == "verify_failed" && ShowErrorAsync != null)
|
else if (!hasChildren && result?.Status == "verify_failed" && ShowErrorAsync != null)
|
||||||
@@ -1238,25 +1277,38 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase, IDisposable
|
|||||||
if (ShowErrorAsync != null)
|
if (ShowErrorAsync != null)
|
||||||
await ShowErrorAsync(ex.Message);
|
await ShowErrorAsync(ex.Message);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_worker.MergeProgressEvent -= OnMergeProgress;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Mirrors TaskMergeService.PhaseVerifying — a hub payload token, not a display string.
|
||||||
|
private const string MergePhaseVerifying = "verifying";
|
||||||
|
|
||||||
|
private static string FormatElapsed(int seconds) =>
|
||||||
|
TimeSpan.FromSeconds(Math.Max(0, seconds)).ToString(@"mm\:ss");
|
||||||
|
|
||||||
// Force the diff to have been opened before a merge can happen — but only when
|
// Force the diff to have been opened before a merge can happen — but only when
|
||||||
// there is actually something to inspect (a childless sandbox run with no worktree
|
// there is actually something to inspect (a childless sandbox run with no worktree
|
||||||
// has no diff, so it approves straight through).
|
// has no diff, so it approves straight through).
|
||||||
private bool CanApproveReview() =>
|
private bool CanApproveReview() =>
|
||||||
Task != null && _worker.IsConnected && IsWaitingForReview
|
Task != null && _worker.IsConnected && IsWaitingForReview
|
||||||
&& (!Merge.HasReviewableDiff || ReviewDiffViewed);
|
&& (!Merge.HasReviewableDiff || ReviewDiffViewed)
|
||||||
|
&& !ApproveOp.IsRunning;
|
||||||
|
|
||||||
// An interactive (ConPTY) session leaves its worktree changed but never flips the task
|
// An interactive (ConPTY) session leaves its worktree changed but never flips the task
|
||||||
// status. Offer "Submit for review" for an Idle/Failed task that still has a worktree, so
|
// status. Offer "Submit for review" for an Idle/Failed task that still has a worktree, so
|
||||||
// its hand-driven work can enter the normal review/merge flow (commits first, server-side).
|
// its hand-driven work can enter the normal review/merge flow (commits first, server-side).
|
||||||
public bool CanSubmitForReview =>
|
public bool CanSubmitForReview =>
|
||||||
Task != null && _worker.IsConnected && (IsIdle || IsFailed) && !string.IsNullOrEmpty(WorktreePath);
|
Task != null && _worker.IsConnected && (IsIdle || IsFailed) && !string.IsNullOrEmpty(WorktreePath)
|
||||||
|
&& !SubmitOp.IsRunning;
|
||||||
|
|
||||||
[RelayCommand(CanExecute = nameof(CanSubmitForReview))]
|
[RelayCommand(CanExecute = nameof(CanSubmitForReview))]
|
||||||
private async System.Threading.Tasks.Task SubmitForReviewAsync()
|
private async System.Threading.Tasks.Task SubmitForReviewAsync()
|
||||||
{
|
{
|
||||||
if (Task is null || !_worker.IsConnected) return;
|
if (Task is null || !_worker.IsConnected) return;
|
||||||
|
using var op = SubmitOp.Begin(Loc.T("ops.review.submitting"));
|
||||||
try { await _worker.SubmitTaskForReviewAsync(Task.Id); }
|
try { await _worker.SubmitTaskForReviewAsync(Task.Id); }
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -1270,20 +1322,24 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase, IDisposable
|
|||||||
if (Task is null || !_worker.IsConnected) return;
|
if (Task is null || !_worker.IsConnected) return;
|
||||||
var feedback = ReviewFeedback;
|
var feedback = ReviewFeedback;
|
||||||
if (string.IsNullOrWhiteSpace(feedback)) return;
|
if (string.IsNullOrWhiteSpace(feedback)) return;
|
||||||
|
using var op = RejectOp.Begin(Loc.T("ops.review.rejecting"));
|
||||||
try { await _worker.RejectReviewToQueueAsync(Task.Id, feedback); }
|
try { await _worker.RejectReviewToQueueAsync(Task.Id, feedback); }
|
||||||
catch { /* stale review action; broadcast reconciles */ return; }
|
catch { /* stale review action; broadcast reconciles */ return; }
|
||||||
ReviewFeedback = "";
|
ReviewFeedback = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Park: set the task aside (back to Idle), keeping its worktree intact.
|
// Park: set the task aside (back to Idle), keeping its worktree intact.
|
||||||
[RelayCommand]
|
[RelayCommand(CanExecute = nameof(CanParkReview))]
|
||||||
private async System.Threading.Tasks.Task ParkReviewAsync()
|
private async System.Threading.Tasks.Task ParkReviewAsync()
|
||||||
{
|
{
|
||||||
if (Task is null || !_worker.IsConnected) return;
|
if (Task is null || !_worker.IsConnected) return;
|
||||||
|
using var op = ParkOp.Begin(Loc.T("ops.review.parking"));
|
||||||
try { await _worker.RejectReviewToIdleAsync(Task.Id); }
|
try { await _worker.RejectReviewToIdleAsync(Task.Id); }
|
||||||
catch { /* stale review action; broadcast reconciles */ }
|
catch { /* stale review action; broadcast reconciles */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool CanParkReview() => Task != null && _worker.IsConnected && !ParkOp.IsRunning;
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
private async System.Threading.Tasks.Task ResetReviewAsync()
|
private async System.Threading.Tasks.Task ResetReviewAsync()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using ClaudeDo.Ui.Localization;
|
||||||
using ClaudeDo.Ui.Services;
|
using ClaudeDo.Ui.Services;
|
||||||
using ClaudeDo.Ui.ViewModels.Modals;
|
using ClaudeDo.Ui.ViewModels.Modals;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@@ -27,6 +28,10 @@ public sealed partial class MergeSectionViewModel : ViewModelBase
|
|||||||
[ObservableProperty] private ObservableCollection<string> _mergeTargetBranches = new();
|
[ObservableProperty] private ObservableCollection<string> _mergeTargetBranches = new();
|
||||||
[ObservableProperty] private string? _selectedMergeTarget;
|
[ObservableProperty] private string? _selectedMergeTarget;
|
||||||
|
|
||||||
|
// No CanExecute to gate here — RefreshMergePreviewAsync is triggered from the Bind path,
|
||||||
|
// not a [RelayCommand], so PreviewOp only drives the indicator, never locks a button.
|
||||||
|
public OperationStatus PreviewOp { get; } = new();
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
[NotifyPropertyChangedFor(nameof(ShowMergePreviewMuted))]
|
[NotifyPropertyChangedFor(nameof(ShowMergePreviewMuted))]
|
||||||
private string _mergePreviewText = "";
|
private string _mergePreviewText = "";
|
||||||
@@ -118,6 +123,7 @@ public sealed partial class MergeSectionViewModel : ViewModelBase
|
|||||||
}
|
}
|
||||||
var capturedTaskId = TaskId;
|
var capturedTaskId = TaskId;
|
||||||
var capturedTarget = SelectedMergeTarget;
|
var capturedTarget = SelectedMergeTarget;
|
||||||
|
using var op = PreviewOp.Begin(Loc.T("ops.review.previewing"));
|
||||||
var dto = await _worker.PreviewMergeAsync(capturedTaskId, capturedTarget ?? "");
|
var dto = await _worker.PreviewMergeAsync(capturedTaskId, capturedTarget ?? "");
|
||||||
if (TaskId != capturedTaskId || SelectedMergeTarget != capturedTarget) return;
|
if (TaskId != capturedTaskId || SelectedMergeTarget != capturedTarget) return;
|
||||||
var (text, clean, conflict) = MergePreviewPresenter.Describe(dto);
|
var (text, clean, conflict) = MergePreviewPresenter.Describe(dto);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:vm="using:ClaudeDo.Ui.ViewModels.Islands"
|
xmlns:vm="using:ClaudeDo.Ui.ViewModels.Islands"
|
||||||
xmlns:loc="using:ClaudeDo.Ui.Localization"
|
xmlns:loc="using:ClaudeDo.Ui.Localization"
|
||||||
|
xmlns:controls="using:ClaudeDo.Ui.Views.Controls"
|
||||||
x:DataType="vm:DetailsIslandViewModel"
|
x:DataType="vm:DetailsIslandViewModel"
|
||||||
x:Class="ClaudeDo.Ui.Views.Islands.Detail.WorkConsole">
|
x:Class="ClaudeDo.Ui.Views.Islands.Detail.WorkConsole">
|
||||||
|
|
||||||
@@ -263,10 +264,13 @@
|
|||||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||||
FontFamily="{StaticResource MonoFont}"
|
FontFamily="{StaticResource MonoFont}"
|
||||||
FontSize="{StaticResource FontSizeMono}" />
|
FontSize="{StaticResource FontSizeMono}" />
|
||||||
<Button Grid.Column="2" Classes="prompt-action accent" Content="[Resume]"
|
<StackPanel Grid.Column="2" Spacing="4" Margin="12,2,0,0">
|
||||||
VerticalAlignment="Top" Margin="12,2,0,0"
|
<Button Classes="prompt-action accent" Content="[Resume]"
|
||||||
ToolTip.Tip="{loc:Tr session.reviewContinueTip}"
|
HorizontalAlignment="Right"
|
||||||
Command="{Binding RejectReviewCommand}" />
|
ToolTip.Tip="{loc:Tr session.reviewContinueTip}"
|
||||||
|
Command="{Binding RejectReviewCommand}" />
|
||||||
|
<controls:OperationIndicator Status="{Binding RejectOp}" HorizontalAlignment="Right" />
|
||||||
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<!-- Inset lives on the content, NOT on the ScrollViewer: Avalonia 12 leaves
|
<!-- Inset lives on the content, NOT on the ScrollViewer: Avalonia 12 leaves
|
||||||
@@ -331,6 +335,7 @@
|
|||||||
<TextBlock Classes="meta" Text="{Binding Merge.MergePreviewText}" TextWrapping="Wrap"
|
<TextBlock Classes="meta" Text="{Binding Merge.MergePreviewText}" TextWrapping="Wrap"
|
||||||
Foreground="{DynamicResource TextMuteBrush}"
|
Foreground="{DynamicResource TextMuteBrush}"
|
||||||
IsVisible="{Binding Merge.ShowMergePreviewMuted}" />
|
IsVisible="{Binding Merge.ShowMergePreviewMuted}" />
|
||||||
|
<controls:OperationIndicator Status="{Binding Merge.PreviewOp}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<!-- Inspect: diff / worktree / combined diff -->
|
<!-- Inspect: diff / worktree / combined diff -->
|
||||||
@@ -367,11 +372,17 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<WrapPanel Orientation="Horizontal">
|
<WrapPanel Orientation="Horizontal">
|
||||||
<Button Classes="btn accent" Content="Approve & Merge" Margin="0,0,8,8"
|
<StackPanel Orientation="Horizontal" Spacing="{StaticResource SpaceSm}" Margin="0,0,8,8">
|
||||||
Command="{Binding ApproveReviewCommand}" />
|
<Button Classes="btn accent" Content="Approve & Merge"
|
||||||
<Button Classes="btn" Content="Park" Margin="0,0,8,8"
|
Command="{Binding ApproveReviewCommand}" />
|
||||||
ToolTip.Tip="Set aside — back to Idle, keeps the worktree"
|
<controls:OperationIndicator Status="{Binding ApproveOp}" />
|
||||||
Command="{Binding ParkReviewCommand}" />
|
</StackPanel>
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="{StaticResource SpaceSm}" Margin="0,0,8,8">
|
||||||
|
<Button Classes="btn" Content="Park"
|
||||||
|
ToolTip.Tip="Set aside — back to Idle, keeps the worktree"
|
||||||
|
Command="{Binding ParkReviewCommand}" />
|
||||||
|
<controls:OperationIndicator Status="{Binding ParkOp}" />
|
||||||
|
</StackPanel>
|
||||||
<Button Classes="btn" Content="Cancel" Margin="0,0,8,8"
|
<Button Classes="btn" Content="Cancel" Margin="0,0,8,8"
|
||||||
Command="{Binding CancelReviewCommand}" />
|
Command="{Binding CancelReviewCommand}" />
|
||||||
</WrapPanel>
|
</WrapPanel>
|
||||||
@@ -388,8 +399,11 @@
|
|||||||
<TextBlock Classes="meta" TextWrapping="Wrap"
|
<TextBlock Classes="meta" TextWrapping="Wrap"
|
||||||
Foreground="{DynamicResource TextMuteBrush}"
|
Foreground="{DynamicResource TextMuteBrush}"
|
||||||
Text="Worked on this by hand? Submit the worktree for review to merge it." />
|
Text="Worked on this by hand? Submit the worktree for review to merge it." />
|
||||||
<Button Classes="btn accent" Content="Submit for review" HorizontalAlignment="Left"
|
<StackPanel Orientation="Horizontal" Spacing="{StaticResource SpaceSm}">
|
||||||
Command="{Binding SubmitForReviewCommand}" />
|
<Button Classes="btn accent" Content="Submit for review" HorizontalAlignment="Left"
|
||||||
|
Command="{Binding SubmitForReviewCommand}" />
|
||||||
|
<controls:OperationIndicator Status="{Binding SubmitOp}" />
|
||||||
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ public class DetailsIslandReviewActionsTests : IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ApproveReview_WhenWorkerThrows_CallsShowErrorAsync()
|
public async Task ApproveReview_WhenWorkerThrows_CallsShowErrorAsync_AndResetsIsRunning()
|
||||||
{
|
{
|
||||||
var worker = new ThrowingWorkerClient();
|
var worker = new ThrowingWorkerClient();
|
||||||
var vm = BuildVm(worker);
|
var vm = BuildVm(worker);
|
||||||
@@ -160,6 +160,189 @@ public class DetailsIslandReviewActionsTests : IDisposable
|
|||||||
await vm.ApproveReviewCommand.ExecuteAsync(null);
|
await vm.ApproveReviewCommand.ExecuteAsync(null);
|
||||||
|
|
||||||
Assert.Equal(worker.ExceptionMessage, reportedError);
|
Assert.Equal(worker.ExceptionMessage, reportedError);
|
||||||
|
Assert.False(vm.ApproveOp.IsRunning);
|
||||||
|
Assert.True(vm.ApproveReviewCommand.CanExecute(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class BlockingApproveWorkerClient : StubWorkerClient
|
||||||
|
{
|
||||||
|
public override bool IsConnected => true;
|
||||||
|
public TaskCompletionSource<MergeResultDto?> Gate { get; } = new();
|
||||||
|
public override Task<MergeResultDto?> ApproveReviewAsync(string taskId, string targetBranch) => Gate.Task;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int MergeProgressSubscriberCount(StubWorkerClient worker)
|
||||||
|
{
|
||||||
|
var field = typeof(StubWorkerClient).GetField("MergeProgressEvent",
|
||||||
|
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||||
|
var del = (Delegate?)field!.GetValue(worker);
|
||||||
|
return del?.GetInvocationList().Length ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ApproveReview_SetsIsRunning_AndLocksTheButton_WhileThePendingCallIsInFlight()
|
||||||
|
{
|
||||||
|
var worker = new BlockingApproveWorkerClient();
|
||||||
|
var vm = BuildVm(worker);
|
||||||
|
vm.Bind(new TaskRowViewModel { Id = "task-approve-1", Status = TaskStatus.WaitingForReview });
|
||||||
|
vm.Monitor.ApplyState(TaskStatus.WaitingForReview);
|
||||||
|
|
||||||
|
var approve = vm.ApproveReviewCommand.ExecuteAsync(null);
|
||||||
|
|
||||||
|
Assert.True(vm.ApproveOp.IsRunning);
|
||||||
|
Assert.False(vm.ApproveReviewCommand.CanExecute(null));
|
||||||
|
|
||||||
|
worker.Gate.SetResult(new MergeResultDto("merged", new List<string>(), null));
|
||||||
|
await approve;
|
||||||
|
|
||||||
|
Assert.False(vm.ApproveOp.IsRunning);
|
||||||
|
Assert.True(vm.ApproveReviewCommand.CanExecute(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ApproveReview_SharpensLabelForItsOwnTask_ButIgnoresProgressForOtherTasks()
|
||||||
|
{
|
||||||
|
var worker = new BlockingApproveWorkerClient();
|
||||||
|
var vm = BuildVm(worker);
|
||||||
|
vm.Bind(new TaskRowViewModel { Id = "task-approve-2", Status = TaskStatus.WaitingForReview });
|
||||||
|
vm.Monitor.ApplyState(TaskStatus.WaitingForReview);
|
||||||
|
|
||||||
|
var approve = vm.ApproveReviewCommand.ExecuteAsync(null);
|
||||||
|
var merging = vm.ApproveOp.Label;
|
||||||
|
|
||||||
|
worker.RaiseMergeProgress("some-other-task", "verifying", 30);
|
||||||
|
Assert.Equal(merging, vm.ApproveOp.Label);
|
||||||
|
|
||||||
|
worker.RaiseMergeProgress("task-approve-2", "verifying", 30);
|
||||||
|
Assert.NotEqual(merging, vm.ApproveOp.Label);
|
||||||
|
|
||||||
|
worker.Gate.SetResult(new MergeResultDto("merged", new List<string>(), null));
|
||||||
|
await approve;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ApproveReview_UnsubscribesFromMergeProgress_AfterTheCallCompletes()
|
||||||
|
{
|
||||||
|
var worker = new BlockingApproveWorkerClient();
|
||||||
|
var vm = BuildVm(worker);
|
||||||
|
vm.Bind(new TaskRowViewModel { Id = "task-approve-3", Status = TaskStatus.WaitingForReview });
|
||||||
|
vm.Monitor.ApplyState(TaskStatus.WaitingForReview);
|
||||||
|
|
||||||
|
var approve = vm.ApproveReviewCommand.ExecuteAsync(null);
|
||||||
|
Assert.Equal(1, MergeProgressSubscriberCount(worker));
|
||||||
|
|
||||||
|
worker.Gate.SetResult(new MergeResultDto("merged", new List<string>(), null));
|
||||||
|
await approve;
|
||||||
|
|
||||||
|
Assert.Equal(0, MergeProgressSubscriberCount(worker));
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class BlockingSubmitWorkerClient : StubWorkerClient
|
||||||
|
{
|
||||||
|
public override bool IsConnected => true;
|
||||||
|
public TaskCompletionSource Gate { get; } = new();
|
||||||
|
public override Task SubmitTaskForReviewAsync(string taskId, CancellationToken ct = default) => Gate.Task;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SubmitForReview_SetsIsRunning_AndLocksTheButton_WhilePending()
|
||||||
|
{
|
||||||
|
var worker = new BlockingSubmitWorkerClient();
|
||||||
|
var vm = BuildVm(worker);
|
||||||
|
vm.Bind(new TaskRowViewModel { Id = "task-submit-1", Status = TaskStatus.Idle });
|
||||||
|
vm.Monitor.ApplyState(TaskStatus.Idle);
|
||||||
|
vm.WorktreePath = "/tmp/wt";
|
||||||
|
|
||||||
|
var submit = vm.SubmitForReviewCommand.ExecuteAsync(null);
|
||||||
|
|
||||||
|
Assert.True(vm.SubmitOp.IsRunning);
|
||||||
|
Assert.False(vm.SubmitForReviewCommand.CanExecute(null));
|
||||||
|
|
||||||
|
worker.Gate.SetResult();
|
||||||
|
await submit;
|
||||||
|
|
||||||
|
Assert.False(vm.SubmitOp.IsRunning);
|
||||||
|
Assert.True(vm.SubmitForReviewCommand.CanExecute(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class BlockingRejectWorkerClient : StubWorkerClient
|
||||||
|
{
|
||||||
|
public override bool IsConnected => true;
|
||||||
|
public TaskCompletionSource Gate { get; } = new();
|
||||||
|
public override Task RejectReviewToQueueAsync(string taskId, string feedback) => Gate.Task;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task RejectReview_SetsIsRunning_AndLocksTheButton_WhilePending()
|
||||||
|
{
|
||||||
|
var worker = new BlockingRejectWorkerClient();
|
||||||
|
var vm = BuildVm(worker);
|
||||||
|
vm.Bind(new TaskRowViewModel { Id = "task-reject-1", Status = TaskStatus.WaitingForReview });
|
||||||
|
vm.ReviewFeedback = "tighten the error handling";
|
||||||
|
|
||||||
|
var reject = vm.RejectReviewCommand.ExecuteAsync(null);
|
||||||
|
|
||||||
|
Assert.True(vm.RejectOp.IsRunning);
|
||||||
|
Assert.False(vm.RejectReviewCommand.CanExecute(null));
|
||||||
|
|
||||||
|
worker.Gate.SetResult();
|
||||||
|
await reject;
|
||||||
|
|
||||||
|
Assert.False(vm.RejectOp.IsRunning);
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class BlockingParkWorkerClient : StubWorkerClient
|
||||||
|
{
|
||||||
|
public override bool IsConnected => true;
|
||||||
|
public TaskCompletionSource Gate { get; } = new();
|
||||||
|
public override Task RejectReviewToIdleAsync(string taskId) => Gate.Task;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ParkReview_SetsIsRunning_AndLocksTheButton_WhilePending()
|
||||||
|
{
|
||||||
|
var worker = new BlockingParkWorkerClient();
|
||||||
|
var vm = BuildVm(worker);
|
||||||
|
vm.Bind(new TaskRowViewModel { Id = "task-park-2", Status = TaskStatus.WaitingForReview });
|
||||||
|
|
||||||
|
var park = vm.ParkReviewCommand.ExecuteAsync(null);
|
||||||
|
|
||||||
|
Assert.True(vm.ParkOp.IsRunning);
|
||||||
|
Assert.False(vm.ParkReviewCommand.CanExecute(null));
|
||||||
|
|
||||||
|
worker.Gate.SetResult();
|
||||||
|
await park;
|
||||||
|
|
||||||
|
Assert.False(vm.ParkOp.IsRunning);
|
||||||
|
Assert.True(vm.ParkReviewCommand.CanExecute(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class BlockingPreviewWorkerClient : StubWorkerClient
|
||||||
|
{
|
||||||
|
public override bool IsConnected => true;
|
||||||
|
public TaskCompletionSource<MergePreviewDto?> Gate { get; } = new();
|
||||||
|
public override Task<MergePreviewDto?> PreviewMergeAsync(string taskId, string targetBranch) => Gate.Task;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task MergePreview_ShowsBusy_WhileTheWorkerCallIsPending_AndResetsAfter()
|
||||||
|
{
|
||||||
|
var worker = new BlockingPreviewWorkerClient();
|
||||||
|
var vm = BuildVm(worker);
|
||||||
|
// SyncTaskContext directly rather than Bind(): Bind() loads the task from the DB
|
||||||
|
// asynchronously and TaskId only lands once that completes, which would race the
|
||||||
|
// synchronous assertion below.
|
||||||
|
vm.Merge.SyncTaskContext("task-preview-1", "do the thing", false);
|
||||||
|
vm.Merge.SyncWorktree("/tmp/wt", null, null, "Active", null);
|
||||||
|
|
||||||
|
var preview = vm.Merge.RefreshMergePreviewAsync();
|
||||||
|
|
||||||
|
Assert.True(vm.Merge.PreviewOp.IsRunning);
|
||||||
|
|
||||||
|
worker.Gate.SetResult(new MergePreviewDto("clean", new List<string>(), 3));
|
||||||
|
await preview;
|
||||||
|
|
||||||
|
Assert.False(vm.Merge.PreviewOp.IsRunning);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
Reference in New Issue
Block a user