Files
poli0981andClaude Opus 5.5 f7bbe53f96 feat(ui)!: Fluent redesign with WPF-UI 4.3
The app now follows Windows 11: Mica window with its own title bar, a
navigation pane, in-window dialogs, snackbars and the system accent color.
MaterialDesignThemes is gone.

- Shell: resizable FluentWindow (min 960x600) that remembers its size,
  position and maximized state. The title bar has a command search box
  (Ctrl+K), an admin-session indicator with "End admin session", and a More
  menu. The pane has Home, Favorites, History, Recipes, My commands and the
  catalog with its twelve categories and counts; the selection stays in sync
  with the view-model through NavigationKey.
- MainViewModel keeps the shell only; the catalog's browsing, filters,
  detail and run logic moved to CatalogViewModel. The catalog gets risk and
  admin-only filter chips, the estimated duration and an expanded command
  line in the detail panel, and a splitter between detail and console.
- One shared console for catalog, recipes and user commands: virtualized,
  batched, capped at 10,000 lines with a "N earlier lines" note, Copy all,
  Save to file, "Waiting for administrator permission…" status and Restart
  now (asks first, never while a command runs).
- Confirmation, update and bug-report dialogs are Fluent content dialogs;
  Cancel stays the default and Run appears for a Dangerous command only
  once its name or id is typed. The Legal Gate, terms viewer, crash dialog
  and command palette are Fluent windows; the Legal Gate lets you pick the
  language first.
- Theme: light, dark or system through ApplicationThemeManager, accent from
  Windows, High Contrast always wins. Font size scales every text and
  control live. Pages set the theme text color themselves (the navigation
  frame doesn't pass it down), and list text dims instead of recoloring so
  it stays readable on a selected row; search matches are bold and
  underlined.
- A finished run notifies with a snackbar (and flashes the taskbar button)
  when the console isn't visible; the taskbar shows progress while running.
- Catalog icons map to Fluent System Icons (IconMap), checked by a test.
- The presentation namespace is now CommandForge.Desktop: a namespace named
  CommandForge.Wpf hid WPF-UI's root namespace in XAML-generated code. The
  project, assembly and exe keep the name CommandForge.Wpf.
- IElevationService raises SessionChanged when the elevated helper starts or
  stops.
- Strings: about 45 new keys in all five languages; twelve unused keys
  removed. A test now scans the UI sources so every key the XAML or code
  uses must exist in every language.

BREAKING CHANGE: new look and layout; settings, history, recipes and user
commands carry over unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 22:26:42 +07:00

152 lines
5.3 KiB
C#

using System.Threading.Channels;
using CommandForge.Application.Ports;
using CommandForge.Application.UseCases;
using CommandForge.Domain;
namespace CommandForge.Tests;
/// <summary>Tests routing by <c>RequiresAdmin</c>, and that a run always ends (fault, cancel) with the output channel completed.</summary>
public sealed class RunCommandUseCaseTests
{
[Fact]
public async Task AdminCommand_RoutesToElevation()
{
var executor = new Recording();
var elevation = new RecordingElevation();
var useCase = new RunCommandUseCase(executor, elevation);
await useCase.RunAsync(Command(requiresAdmin: true), Channel.CreateUnbounded<OutputLine>().Writer, TestContext.Current.CancellationToken);
Assert.True(elevation.Called);
Assert.False(executor.Called);
}
[Fact]
public async Task NonAdminCommand_RoutesToExecutor()
{
var executor = new Recording();
var elevation = new RecordingElevation();
var useCase = new RunCommandUseCase(executor, elevation);
await useCase.RunAsync(Command(requiresAdmin: false), Channel.CreateUnbounded<OutputLine>().Writer, TestContext.Current.CancellationToken);
Assert.True(executor.Called);
Assert.False(elevation.Called);
}
[Fact(Timeout = 30_000)]
public async Task ExecutorFault_StillCompletesTheOutputChannel()
{
// The UI reads output until the channel completes; a crash must not leave it waiting forever.
var useCase = new RunCommandUseCase(new Throwing(), new RecordingElevation());
var channel = Channel.CreateUnbounded<OutputLine>();
await Assert.ThrowsAsync<InvalidOperationException>(
() => useCase.RunAsync(Command(requiresAdmin: false), channel.Writer, TestContext.Current.CancellationToken));
await channel.Reader.Completion.WaitAsync(TestContext.Current.CancellationToken);
}
[Fact(Timeout = 30_000)]
public async Task CancelWhileWaitingForElevation_ReturnsCancelled()
{
// e.g. the user cancels while the UAC prompt is still open.
var useCase = new RunCommandUseCase(new Recording(), new HangingElevation());
var channel = Channel.CreateUnbounded<OutputLine>();
using var cancel = CancellationTokenSource.CreateLinkedTokenSource(TestContext.Current.CancellationToken);
var run = useCase.RunAsync(Command(requiresAdmin: true), channel.Writer, cancel.Token);
await cancel.CancelAsync();
var result = await run;
Assert.True(result.Cancelled);
Assert.False(result.Success);
await channel.Reader.Completion.WaitAsync(TestContext.Current.CancellationToken);
}
private static CommandDefinition Command(bool requiresAdmin) => new()
{
Id = "x",
CategoryId = "c",
TitleKey = "t",
DescriptionKey = "d",
Executable = "x",
RequiresAdmin = requiresAdmin,
};
private static ExecutionResult Ok() => new() { ExitCode = 0, Success = true, Duration = TimeSpan.Zero };
private sealed class Recording : ICommandExecutor
{
public bool Called { get; private set; }
public Task<ExecutionResult> ExecuteAsync(CommandDefinition command, ChannelWriter<OutputLine> output, CancellationToken cancellationToken = default)
{
Called = true;
output.TryComplete();
return Task.FromResult(Ok());
}
}
private sealed class RecordingElevation : IElevationService
{
public bool Called { get; private set; }
public bool IsSessionActive => false;
public event EventHandler? SessionChanged
{
add
{
// A fake session never starts or ends.
}
remove
{
// A fake session never starts or ends.
}
}
public Task EndSessionAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;
public Task<ExecutionResult> RunElevatedAsync(CommandDefinition command, ChannelWriter<OutputLine> output, CancellationToken cancellationToken = default)
{
Called = true;
output.TryComplete();
return Task.FromResult(Ok());
}
}
private sealed class Throwing : ICommandExecutor
{
public Task<ExecutionResult> ExecuteAsync(CommandDefinition command, ChannelWriter<OutputLine> output, CancellationToken cancellationToken = default)
=> throw new InvalidOperationException("executor failed");
}
private sealed class HangingElevation : IElevationService
{
public bool IsSessionActive => false;
public event EventHandler? SessionChanged
{
add
{
// A fake session never starts or ends.
}
remove
{
// A fake session never starts or ends.
}
}
public Task EndSessionAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;
public async Task<ExecutionResult> RunElevatedAsync(CommandDefinition command, ChannelWriter<OutputLine> output, CancellationToken cancellationToken = default)
{
await Task.Delay(Timeout.Infinite, cancellationToken);
return Ok();
}
}
}