Files
ClaudeDo/tests/ClaudeDo.Installer.Tests/Checks/ClaudeVersionCheckTests.cs
T
mika kuns d743a9d0e9 feat(installer): add Claude CLI preflight checks (found, version, login, auto-mode)
Four IEnvironmentCheck implementations in src/ClaudeDo.Installer/Checks/:
- ClaudeCliCheck (Error) — resolves ctx.ClaudeBin via ExecutableResolver, runs
  --version; failure message lists searched PATH entries + fallback dirs, flags
  shim resolution (.cmd/.ps1) in Detail.
- ClaudeVersionCheck (Error) — tolerant version parsing (ignores surrounding
  text), numeric System.Version comparison against a named floor constant
  (2.1.220, see docs/explore-notes/installer-preflight.md §3). Unparseable or
  missing CLI -> Unknown, never Failed.
- ClaudeAuthCheck (Error) — `claude auth status --json`, never sends a prompt.
- PermissionModeAutoCheck (Warning) — per the note's §2 conclusion, real
  auto-mode eligibility (org/model/plan) has no cheap static signal, so this
  only confirms `claude --help` still lists "auto" as a --permission-mode
  choice. Kept as its own check rather than folded into ClaudeVersionCheck,
  since the note explicitly separates "flag recognized" from "mode eligible"
  and only the former is checkable at all.

All four share a new ClaudeCliLookup that resolves the CLI and runs
--version exactly once per install run (memoized, semaphore-guarded), so
none of the three version-dependent checks repeats that call.

Foundation prerequisites this task depends on (docs/explore-notes/
installer-preflight.md, ExecutableResolver, the IEnvironmentCheck/CheckResult/
EnvironmentCheckService abstraction, ProcessCommand, IProcessRunner) existed
only on an unmerged sibling branch, not on main. Rather than merging that
whole unreviewed branch, the specific prerequisite files were copied in
as-is (git history shows their origin). GitCheck/GitIdentityCheck/PortCheck/
WriteAccessCheck from that branch were intentionally NOT brought in — out of
scope for this task.

Deviations/decisions worth flagging:
- Added ExecutableResolver.FallbackDirectories() (public) so ClaudeCliCheck
  can name the checked fallback locations in its failure message; the prior
  branch kept that list private.
- Paths.cs now qualifies System.Environment explicitly. Adding the
  ClaudeDo.Data.Environment namespace makes bare `Environment.X` inside any
  ClaudeDo.Data.* namespace resolve to the sibling namespace instead of
  System.Environment (C# prefers nested/enclosing namespace members over
  usings) — this broke the build until qualified.

Not done (explicitly out of scope): no DI wiring into the wizard UI, no
XAML — matches how the prerequisite Git/Port/WriteAccess checks were also
left unwired.
2026-08-05 19:43:34 +02:00

70 lines
2.4 KiB
C#

using ClaudeDo.Installer.Checks;
using ClaudeDo.Installer.Core;
namespace ClaudeDo.Installer.Tests.Checks;
public sealed class ClaudeVersionCheckTests : IDisposable
{
private readonly string _dir;
public ClaudeVersionCheckTests()
{
_dir = Path.Combine(Path.GetTempPath(), $"cdclaudeversion_{Guid.NewGuid():N}");
Directory.CreateDirectory(_dir);
File.WriteAllText(Path.Combine(_dir, "claude.exe"), "");
}
public void Dispose()
{
try { Directory.Delete(_dir, recursive: true); } catch { }
}
private ClaudeCliLookup MakeLookup(FakeProcessRunner runner) =>
new(runner, pathOverride: _dir, pathExtOverride: ".exe");
[Theory]
[InlineData("2.1.220 (Claude Code)", CheckStatus.Ok)] // exactly at the floor
[InlineData("2.1.219 (Claude Code)", CheckStatus.Failed)] // one patch below the floor
[InlineData("2.1.191", CheckStatus.Failed)]
[InlineData("v2.1.191", CheckStatus.Failed)]
[InlineData("2.10.0", CheckStatus.Ok)] // minor 10 > minor 1, not a lexical trap
[InlineData("garbage output, no version here", CheckStatus.Unknown)]
public async Task Version_parsing_and_gate(string versionOutput, CheckStatus expected)
{
var runner = new FakeProcessRunner((0, versionOutput));
var check = new ClaudeVersionCheck(MakeLookup(runner));
var result = await check.RunAsync(new InstallContext(), CancellationToken.None);
Assert.Equal(expected, result.Status);
}
[Fact]
public void Minor_version_compares_numerically_not_lexically()
{
Assert.True(new Version(2, 10, 0) > new Version(2, 9, 0));
}
[Fact]
public async Task Cli_not_found_reports_unknown_not_failed()
{
var emptyDir = Path.Combine(Path.GetTempPath(), $"cdclaudeversion_empty_{Guid.NewGuid():N}");
Directory.CreateDirectory(emptyDir);
try
{
var runner = new FakeProcessRunner();
var check = new ClaudeVersionCheck(new ClaudeCliLookup(runner, pathOverride: emptyDir, pathExtOverride: ".exe"));
var ctx = new InstallContext { ClaudeBin = "claudedo_totally_missing_cmd_9f3a1" };
var result = await check.RunAsync(ctx, CancellationToken.None);
Assert.Empty(runner.Calls);
Assert.Equal(CheckStatus.Unknown, result.Status);
}
finally
{
Directory.Delete(emptyDir, recursive: true);
}
}
}