Files
CommandForge/tests/CommandForge.Tests/UserCommandNormalizationTests.cs
poli0981andClaude Opus 4.8 68e62f3f22 fix: cmd user-commands hang, recipe duplicate steps, sidebar scrollbar
Post-v1.1.0 fixes reported from testing.

- User commands hanging on cmd: SystemProcessRunner now redirects and
  immediately closes stdin, so an interactive process (e.g. "cmd" with
  no /c) gets EOF and exits instead of blocking forever. Additionally,
  UserCommandFactory.NormalizeArguments prepends /c for cmd (e.g. "cmd"
  + "ping google.com" -> "cmd /c ping google.com") so the command runs
  and exits; the run confirmation shows the effective command line.
  PowerShell and other executables are unchanged.
- Recipes: AddStep no longer adds a command already in the chain, so a
  recipe never runs one command multiple times.
- Sidebar: hide the vertical scrollbar on the command-groups list.
- Tests for the cmd /c normalization (cmd/cmd.exe/path, existing /c|/k,
  powershell, empty args) + ToDefinition applying it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 16:30:27 +07:00

44 lines
1.7 KiB
C#

using CommandForge.Application.UserCommands;
using CommandForge.Domain;
namespace CommandForge.Tests;
/// <summary>
/// Tests the cmd argument normalization that fixes user commands hanging on an interactive
/// cmd.exe (e.g. "cmd" + "ping google.com" must run as "cmd /c ping google.com").
/// </summary>
public sealed class UserCommandNormalizationTests
{
[Theory]
[InlineData("cmd", "ping google.com", "/c ping google.com")]
[InlineData("cmd.exe", "dir", "/c dir")]
[InlineData("CMD", "echo hi", "/c echo hi")]
[InlineData("C:\\Windows\\System32\\cmd.exe", "whoami", "/c whoami")]
[InlineData("cmd", "", "/c")]
public void NormalizeArguments_PrependsSlashC_ForCmd(string exe, string args, string expected)
=> Assert.Equal(expected, UserCommandFactory.NormalizeArguments(exe, args));
[Theory]
[InlineData("cmd", "/c ping x")] // already has /c
[InlineData("cmd", "/k keep open")] // explicit /k
[InlineData("cmd", "/C UPPER")] // case-insensitive switch
[InlineData("powershell", "ping x")] // not cmd — leave as-is (powershell runs it)
[InlineData("ping", "google.com")] // direct executable
public void NormalizeArguments_LeavesAsIs_WhenNotPlainCmd(string exe, string args)
=> Assert.Equal(args, UserCommandFactory.NormalizeArguments(exe, args));
[Fact]
public void ToDefinition_AppliesCmdNormalization()
{
var def = UserCommandFactory.ToDefinition(new UserCommand
{
Id = "x",
Name = "n",
Executable = "cmd",
Arguments = "ping google.com",
});
Assert.Equal("/c ping google.com", def.ArgsTemplate);
}
}