feat(installer): add Git, GitIdentity, Port, and WriteAccess preflight checks
Implements IEnvironmentCheck for the four checks derivable without a Claude CLI probe: - GitCheck (Error) - resolves git via ExecutableResolver (handles .cmd shims), parses `git --version`. - GitIdentityCheck (Warning) - user.name/user.email presence; Unknown (not Failed) if git itself is missing, so it doesn't duplicate GitCheck's failure. - PortCheck (Warning) - loopback bind probe for SignalRPort/ExternalMcpPort; resolves the owning process via a new NetstatPortOwnerResolver and treats a port held by the running ClaudeDo.Worker (update/repair case) as Ok. Both ports are configurable, hence a warning. - WriteAccessCheck (Error) - create+delete a probe file in InstallDirectory and ~/.todo-app (walking up to the first existing parent), not an ACL read (ACLs lie on virtualized paths). Process calls go through a new IProcessRunner wrapping the existing static ProcessRunner, so checks are fakeable in tests instead of spawning real processes. DotnetRuntimeCheck was intentionally not added: per docs/explore-notes/installer-preflight.md, App/Worker publish self-contained (no preinstalled runtime needed), and the Installer's own .NET 8 Desktop Runtime requirement is self-proving - a framework-dependent apphost can't reach managed code at all if that runtime is missing, so a check running from inside the process can never observe a failure. Brings in two prerequisite commits this task builds on that hadn't reached this branch yet: the IEnvironmentCheck/EnvironmentCheckService scaffolding and the installer-preflight.md research note.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Principal;
|
||||
using ClaudeDo.Installer.Checks;
|
||||
using ClaudeDo.Installer.Core;
|
||||
|
||||
namespace ClaudeDo.Installer.Tests.Checks;
|
||||
|
||||
public sealed class WriteAccessCheckTests : IDisposable
|
||||
{
|
||||
private readonly List<string> _cleanupDirs = new();
|
||||
|
||||
private string TempDir()
|
||||
{
|
||||
var dir = Path.Combine(Path.GetTempPath(), $"cdwriteaccess_{Guid.NewGuid():N}");
|
||||
Directory.CreateDirectory(dir);
|
||||
_cleanupDirs.Add(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var dir in _cleanupDirs)
|
||||
{
|
||||
try { Directory.Delete(dir, recursive: true); } catch { }
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Writable_directory_reports_ok()
|
||||
{
|
||||
var dir = TempDir();
|
||||
var check = new WriteAccessCheck();
|
||||
|
||||
var result = await check.RunAsync(new InstallContext { InstallDirectory = dir }, CancellationToken.None);
|
||||
|
||||
Assert.Equal(CheckStatus.Ok, result.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NonExistent_path_under_writable_parent_reports_ok()
|
||||
{
|
||||
var parent = TempDir();
|
||||
var target = Path.Combine(parent, "does", "not", "exist");
|
||||
var check = new WriteAccessCheck();
|
||||
|
||||
var result = await check.RunAsync(new InstallContext { InstallDirectory = target }, CancellationToken.None);
|
||||
|
||||
Assert.Equal(CheckStatus.Ok, result.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Unwritable_directory_reports_failed_with_no_leftover_file()
|
||||
{
|
||||
var dir = TempDir();
|
||||
var dirInfo = new DirectoryInfo(dir);
|
||||
var identity = WindowsIdentity.GetCurrent().User!;
|
||||
var denyRule = new FileSystemAccessRule(identity, FileSystemRights.CreateFiles | FileSystemRights.WriteData, AccessControlType.Deny);
|
||||
|
||||
var acl = dirInfo.GetAccessControl();
|
||||
acl.AddAccessRule(denyRule);
|
||||
dirInfo.SetAccessControl(acl);
|
||||
|
||||
try
|
||||
{
|
||||
var check = new WriteAccessCheck();
|
||||
|
||||
var result = await check.RunAsync(new InstallContext { InstallDirectory = dir }, CancellationToken.None);
|
||||
|
||||
Assert.Equal(CheckStatus.Failed, result.Status);
|
||||
Assert.Equal(CheckSeverity.Error, result.Severity);
|
||||
Assert.Contains(dir, result.Message);
|
||||
Assert.Empty(Directory.GetFiles(dir));
|
||||
}
|
||||
finally
|
||||
{
|
||||
acl.RemoveAccessRule(denyRule);
|
||||
dirInfo.SetAccessControl(acl);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user