99 lines
3.4 KiB
C#
99 lines
3.4 KiB
C#
using CursorLang.Core.Services;
|
|
using CursorLang.Tests.Shared;
|
|
|
|
namespace CursorLang.Core.Tests.Services;
|
|
|
|
/// <summary>
|
|
/// Telling a launch by Windows apart from a launch by the user: the first one goes
|
|
/// to the tray without a window, the second one is what the window is for.
|
|
/// </summary>
|
|
public sealed class StartupLaunchTests
|
|
{
|
|
[Fact]
|
|
public void A_launch_by_the_user_carries_no_argument()
|
|
{
|
|
Assert.False(StartupLaunch.HasArgument([]));
|
|
Assert.False(StartupLaunch.IsAutomatic([]));
|
|
}
|
|
|
|
[Fact]
|
|
public void The_startup_entry_says_so_in_the_command_line()
|
|
{
|
|
Assert.True(StartupLaunch.HasArgument([StartupLaunch.Argument]));
|
|
Assert.True(StartupLaunch.IsAutomatic([StartupLaunch.Argument]));
|
|
}
|
|
|
|
// The argument does not have to come first: Windows may put its own
|
|
// alongside it one day
|
|
[Fact]
|
|
public void The_argument_is_looked_for_among_the_others()
|
|
{
|
|
Assert.True(StartupLaunch.HasArgument(["--whatever", StartupLaunch.Argument]));
|
|
}
|
|
|
|
[Fact]
|
|
public void The_case_of_the_argument_does_not_matter()
|
|
{
|
|
Assert.True(StartupLaunch.HasArgument([StartupLaunch.Argument.ToUpperInvariant()]));
|
|
}
|
|
|
|
[Fact]
|
|
public void Anything_else_is_a_launch_by_the_user()
|
|
{
|
|
Assert.False(StartupLaunch.HasArgument(["--startupp", "startup", "-startup"]));
|
|
}
|
|
|
|
/// <summary>
|
|
/// The command written into the registry carries the argument: that is the whole
|
|
/// point of the argument.
|
|
/// </summary>
|
|
[Fact]
|
|
public void The_startup_entry_is_written_with_the_argument()
|
|
{
|
|
using var agent = new StagedAgentExecutable();
|
|
|
|
string? command = RegistryStartup.GetCommand();
|
|
|
|
Assert.NotNull(command);
|
|
Assert.EndsWith(StartupLaunch.Argument, command, StringComparison.Ordinal);
|
|
|
|
// And the path itself stays quoted: it has spaces in it more often than not
|
|
Assert.StartsWith("\"", command, StringComparison.Ordinal);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Windows must start the agent, whoever asked for it.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The checkbox lives in the settings window, which is a process of its own. Were
|
|
/// the entry written from the path of whoever is running, the startup list would
|
|
/// hold the settings window — a process that shows a window and exits, instead of
|
|
/// the one that is supposed to sit in the tray.
|
|
/// </remarks>
|
|
[Fact]
|
|
public void The_startup_entry_names_the_agent_rather_than_whoever_wrote_it()
|
|
{
|
|
using var agent = new StagedAgentExecutable();
|
|
|
|
string? command = RegistryStartup.GetCommand();
|
|
|
|
Assert.NotNull(command);
|
|
Assert.Contains("CursorLang.exe", command, StringComparison.OrdinalIgnoreCase);
|
|
Assert.DoesNotContain("CursorLang.Settings.exe", command, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
// Without an agent on disk there is nothing to put in the startup list, and
|
|
// pointing Windows at a file that is not there would be worse than saying nothing
|
|
[Fact]
|
|
public void Without_an_agent_on_disk_there_is_no_entry_to_write()
|
|
{
|
|
string agent = Path.Combine(AppContext.BaseDirectory, "CursorLang.exe");
|
|
if (File.Exists(agent))
|
|
{
|
|
Assert.Skip("The agent is built into the test output folder — nothing to check here");
|
|
}
|
|
|
|
Assert.Null(RegistryStartup.GetCommand());
|
|
}
|
|
}
|