tazel
A build system for C, C++, Objective-C, Objective-C++ and Zig, with C# project files.
Clonegit clone https://git.progmasoft.com/tazel
Add tazel doctor environment diagnostics command
- Commit
f3289b2b77568accd0ac6ba8b5dfc8014dbefb61- Author
- Leitwolf11 ·
- Parents
e4ceaf0339b8
Changes
CHANGELOG.md | 3 + docs/commands.md | 1 + src/Progmasoft.Tazel/Cli/CommandLine.cs | 2 +- src/Progmasoft.Tazel/Cli/CommandMakers.cs | 1 + src/Progmasoft.Tazel/Cli/CommandTypes.cs | 3 + src/Progmasoft.Tazel/Cli/Commands.cs | 1 + src/Progmasoft.Tazel/Cli/DoctorCommands.cs | 85 +++++++++++++++++++++++++ src/Progmasoft.Tazel/Cli/Help.cs | 7 +++ src/Progmasoft.Tazel/Cli/ShellCompletion.cs | 1 + src/Progmasoft.Tazel/Program.cs | 2 +- tests/Progmasoft.Tazel.Tests/DoctorTests.cs | 97 +++++++++++++++++++++++++++++ 11 files changed, 201 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 195ab07..d515579 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ## Unreleased +- Added `tazel doctor` for read-only environment diagnostics (.NET runtime, C/C++ compiler, Zig, git, Linux KVM/MicroVM, + and live daemon status) without requiring a workspace. + - Added `Progmasoft.Tazel.CedreCeleste`, Tazel's internal demand-driven, revision-based incremental evaluation engine with interned keys, ordered dynamic dependencies, 128-bit content-hash change pruning, async evaluation without restarts, cycle detection, error-as-value caching, and graph introspection snapshots. diff --git a/docs/commands.md b/docs/commands.md index 50169ed..285b264 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -16,6 +16,7 @@ | `tazel init [--force]` | interactively initializes a module in the current directory | | `tazel git add` | stages the module's files with system `git`, respecting `.gitignore` | | `tazel log cache\|workspace\|what-ran\|what-failed\|what-up\|snoop\|daemon\|registries` | read-only inspection of cache, module root, recent runs, daemon status, and effective registries | +| `tazel doctor` | checks local compilers, runtime, git, Linux KVM/MicroVM, and daemon status without requiring a workspace | | `tazel fetch` | downloads and checks the modules and plugins the module depends on, without building | | `tazel vendor` | copies the modules of Tazel Portal Modules and their indexes into `vendor/` | | `tazel clean [--expunge] [--dry-run]` | removes the outputs, the test logs, zig's cache and the compiled project files; `--expunge` removes all of `.tazel`; `--dry-run` lists what would be removed without deleting | diff --git a/src/Progmasoft.Tazel/Cli/CommandLine.cs b/src/Progmasoft.Tazel/Cli/CommandLine.cs index 115c993..fa29988 100644 --- a/src/Progmasoft.Tazel/Cli/CommandLine.cs +++ b/src/Progmasoft.Tazel/Cli/CommandLine.cs @@ -20,7 +20,7 @@ internal static class CommandLine { /// <summary>The commands, as <c>tazel help</c> lists them.</summary> public static IReadOnlyList<string> Commands { get; } = - ["build", "run", "test", "coverage", "query", "cquery", "aquery", "new", "init", "git", "log", "fetch", "vendor", "clean", "package", "custom", + ["build", "run", "test", "coverage", "query", "cquery", "aquery", "new", "init", "git", "log", "doctor", "fetch", "vendor", "clean", "package", "custom", "cache", "explain", "version", "help", "license", "shell-completion", "dotnet", "limited-time", "options", "custom-cmds", "envs", "tool", "ignore"]; private static readonly string[] Building = ["build", "run", "test", "coverage", "cquery", "aquery"]; diff --git a/src/Progmasoft.Tazel/Cli/CommandMakers.cs b/src/Progmasoft.Tazel/Cli/CommandMakers.cs index f256b44..31865aa 100644 --- a/src/Progmasoft.Tazel/Cli/CommandMakers.cs +++ b/src/Progmasoft.Tazel/Cli/CommandMakers.cs @@ -26,6 +26,7 @@ internal static class CommandMakers ["init"] = (scanned, output) => Bare(scanned, new InitCommand(output, scanned.Has("force"))), ["git"] = MakeGit, ["log"] = MakeLog, + ["doctor"] = (scanned, output) => Bare(scanned, new DoctorCommand(output)), ["explain"] = (scanned, output) => Explain(output, scanned.Positional, scanned.Has("short"), scanned.Has("long")), ["fetch"] = (scanned, output) => Bare(scanned, new FetchCommand(output)), ["vendor"] = (scanned, output) => Bare(scanned, new VendorCommand(output)), diff --git a/src/Progmasoft.Tazel/Cli/CommandTypes.cs b/src/Progmasoft.Tazel/Cli/CommandTypes.cs index a92dac5..7e49775 100644 --- a/src/Progmasoft.Tazel/Cli/CommandTypes.cs +++ b/src/Progmasoft.Tazel/Cli/CommandTypes.cs @@ -167,6 +167,9 @@ internal sealed record GitAddCommand(OutputOptions Output) : Command(Output); /// <summary><c>tazel log <action></c>: read-only inspection of workspace, cache, runs, daemon, and registries.</summary> internal sealed record LogCommand(OutputOptions Output, string Action) : Command(Output); +/// <summary><c>tazel doctor</c>: read-only environment diagnostics with actionable hints.</summary> +internal sealed record DoctorCommand(OutputOptions Output) : Command(Output); + /// <summary><c>tazel cache keygen</c>: a key pair for signing the results of a remote cache.</summary> internal sealed record CacheKeygenCommand(OutputOptions Output, Cache.SigningAlgorithm Algorithm) : Command(Output); diff --git a/src/Progmasoft.Tazel/Cli/Commands.cs b/src/Progmasoft.Tazel/Cli/Commands.cs index 322ee02..ebbfc4e 100644 --- a/src/Progmasoft.Tazel/Cli/Commands.cs +++ b/src/Progmasoft.Tazel/Cli/Commands.cs @@ -47,6 +47,7 @@ internal sealed partial class Commands(Reporter reporter, string workingDirector NewCommand create => Task.FromResult(new NewInitCommands(reporter, workingDirectory).New(create.Name, create.Force)), InitCommand init => Task.FromResult(new NewInitCommands(reporter, workingDirectory).Init(init.Force)), LogCommand log => Task.FromResult(new LogCommands(reporter, workingDirectory, TazelVersion).Run(log.Action)), + DoctorCommand => new DoctorCommands(reporter, TazelVersion).RunAsync(cancel), DaemonCommand daemon => DaemonAsync(daemon, cancel), CustomCommandLine custom => CustomAsync(custom, cancel), CacheCheckCommand check => CacheCheckAsync(check, cancel), diff --git a/src/Progmasoft.Tazel/Cli/DoctorCommands.cs b/src/Progmasoft.Tazel/Cli/DoctorCommands.cs new file mode 100644 index 0000000..3e77fc2 --- /dev/null +++ b/src/Progmasoft.Tazel/Cli/DoctorCommands.cs @@ -0,0 +1,85 @@ +// SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com> +// SPDX-License-Identifier: MIT + +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; +using Progmasoft.Tazel.Daemon; +using Progmasoft.Tazel.Driver; +using Progmasoft.Tazel.Output; + +namespace Progmasoft.Tazel.Cli; + +/// <summary>Implements <c>tazel doctor</c>: read-only environment diagnostics with actionable hints.</summary> +internal sealed class DoctorCommands(Reporter reporter, Version tazelVersion) +{ + /// <summary>Runs environment checks and prints a structured summary table.</summary> + public async Task<int> RunAsync(CancellationToken cancel) + { + var rows = new List<IReadOnlyList<string>> + { + CheckRuntime(), + CheckCCompiler(), + CheckTool("Zig", "zig", "optional; install zig to build Zig targets"), + CheckTool("Git", "git", "install git for 'tazel new', 'tazel init', and 'tazel git add'"), + CheckMicroVm(), + await CheckDaemonAsync(cancel).ConfigureAwait(false), + }; + + reporter.Table(["Check", "Status", "Details"], rows); + reporter.Status($"tazel {tazelVersion.ToString(3)} environment check complete"); + return 0; + } + + private static IReadOnlyList<string> CheckRuntime() => + [".NET Runtime", "ok", $".NET {Environment.Version} ({RuntimeInformation.OSDescription.Trim()})"]; + + private static IReadOnlyList<string> CheckCCompiler() + { + foreach (var name in new[] { "clang", "gcc", "cl" }) + { + var found = Host.Which(name); + if (found is not null) + { + return ["C/C++ Compiler", "ok", $"{name} ({found})"]; + } + } + + return ["C/C++ Compiler", "missing", "install clang or gcc (or declare a toolchain in toolchains/BUILD.csx)"]; + } + + private static IReadOnlyList<string> CheckTool(string label, string executable, string missingHint) + { + var found = Host.Which(executable); + return found is not null + ? [label, "ok", found] + : [label, "missing", missingHint]; + } + + private static IReadOnlyList<string> CheckMicroVm() + { + if (!OperatingSystem.IsLinux()) + { + return ["MicroVM / KVM", "info", "Linux KVM sandbox is only active on Linux hosts"]; + } + + if (!File.Exists("/dev/kvm")) + { + return ["MicroVM / KVM", "warn", "/dev/kvm not found; enable KVM for Linux MicroVM sandboxing"]; + } + + return ["MicroVM / KVM", "ok", "/dev/kvm available"]; + } + + private static async Task<IReadOnlyList<string>> CheckDaemonAsync(CancellationToken cancel) + { + var config = DaemonConfig.FromEnvironment(); + var status = await DaemonClient.TryStatusAsync(config, cancel).ConfigureAwait(false); + return status is not null + ? [".NET Daemon", "running", $"pid {status.Pid}, uptime {status.UptimeSeconds}s, socket {config.SocketPath}"] + : [".NET Daemon", "stopped", "start with 'tazel dotnet daemon start' (optional)"]; + } +} diff --git a/src/Progmasoft.Tazel/Cli/Help.cs b/src/Progmasoft.Tazel/Cli/Help.cs index 8fc93b6..802d50c 100644 --- a/src/Progmasoft.Tazel/Cli/Help.cs +++ b/src/Progmasoft.Tazel/Cli/Help.cs @@ -361,6 +361,13 @@ internal static class Help daemon whether the daemon is running, version and memory (never starts a daemon) registries effective module repository list and source file (never prints tokens) """), + ["doctor"] = new("tazel doctor: checks local tools, runtime, KVM/MicroVM, and daemon status.", """ + tazel doctor + + Checks the local environment (.NET runtime, C/C++ compiler, Zig, git, Linux KVM/MicroVM availability, and + whether the .NET daemon is running) and prints a summary table with actionable hints. Runs without a + workspace and never starts a daemon. + """), }; private const string GlobalOptions = """ diff --git a/src/Progmasoft.Tazel/Cli/ShellCompletion.cs b/src/Progmasoft.Tazel/Cli/ShellCompletion.cs index 0b5f5fd..7987079 100644 --- a/src/Progmasoft.Tazel/Cli/ShellCompletion.cs +++ b/src/Progmasoft.Tazel/Cli/ShellCompletion.cs @@ -64,6 +64,7 @@ internal static class ShellCompletion ("init", "Initialize a Tazel module in the current directory"), ("git", "Stage module files with git"), ("log", "Inspect workspace, cache, runs, daemon, and registries"), + ("doctor", "Check local tools, runtime, KVM/MicroVM, and daemon status"), ("fetch", "Download and verify dependencies"), ("vendor", "Copy dependencies into vendor/"), ("clean", "Remove build outputs"), diff --git a/src/Progmasoft.Tazel/Program.cs b/src/Progmasoft.Tazel/Program.cs index 52b6212..ecc20d4 100644 --- a/src/Progmasoft.Tazel/Program.cs +++ b/src/Progmasoft.Tazel/Program.cs @@ -137,7 +137,7 @@ internal static class Program /// </summary> private static void ApplyDotnetSettings(Command command, string directory) { - if (command is HelpCommand or ExplainCommand or VersionCommand or LicenseCommand or ShellCompletionCommand or DotnetWhatIsCommand or DaemonCommand or NewCommand or InitCommand || + if (command is HelpCommand or ExplainCommand or VersionCommand or LicenseCommand or ShellCompletionCommand or DotnetWhatIsCommand or DaemonCommand or DoctorCommand or NewCommand or InitCommand || command is LogCommand { Action: "daemon" or "registries" or "what-up" or "snoop" }) { return; diff --git a/tests/Progmasoft.Tazel.Tests/DoctorTests.cs b/tests/Progmasoft.Tazel.Tests/DoctorTests.cs new file mode 100644 index 0000000..60db80c --- /dev/null +++ b/tests/Progmasoft.Tazel.Tests/DoctorTests.cs @@ -0,0 +1,97 @@ +// SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com> +// SPDX-License-Identifier: MIT + +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using Progmasoft.Tazel.Cli; +using Progmasoft.Tazel.Daemon; +using Xunit; + +namespace Progmasoft.Tazel.Tests; + +[Collection("environment")] +public sealed class DoctorTests +{ + [Fact] + public void ParsesDoctorAndRejectsArguments() + { + Assert.IsType<DoctorCommand>(CommandLine.Parse(["doctor"])); + var error = Assert.Throws<CommandLineException>(() => CommandLine.Parse(["doctor", "extra"])); + Assert.Contains("takes no 'extra'", error.Message, StringComparison.Ordinal); + } + + [Fact] + public async Task RunsWithoutWorkspaceAndReportsEnvironmentChecks() + { + var token = TestContext.Current.CancellationToken; + var dir = Path.Combine(Path.GetTempPath(), $"tz-doc-{Guid.NewGuid():N}"[..16]); + Directory.CreateDirectory(dir); + try + { + using var envDir = new EnvironmentVariable("TAZEL_DAEMON_DIR", dir); + using var writer = new StringWriter(); + var exit = await Program.RunAsync(["--color", "never", "doctor"], dir, writer, token); + Assert.Equal(0, exit); + var text = writer.ToString(); + Assert.Contains(".NET Runtime", text, StringComparison.Ordinal); + Assert.Contains("C/C++ Compiler", text, StringComparison.Ordinal); + Assert.Contains(".NET Daemon", text, StringComparison.Ordinal); + Assert.Contains("stopped", text, StringComparison.Ordinal); + + using var jsonWriter = new StringWriter(); + var jsonExit = await Program.RunAsync(["--message-format=jsonl", "doctor"], dir, jsonWriter, token); + Assert.Equal(0, jsonExit); + Assert.Contains("\"kind\":\"table\"", jsonWriter.ToString(), StringComparison.Ordinal); + } + finally + { + if (Directory.Exists(dir)) + { + Directory.Delete(dir, recursive: true); + } + } + } + + [Fact] + public async Task ReportsRunningDaemonWhenLive() + { + var token = TestContext.Current.CancellationToken; + var dir = Path.Combine(Path.GetTempPath(), $"tz-dl-{Guid.NewGuid():N}"[..16]); + Directory.CreateDirectory(dir); + try + { + using var envDir = new EnvironmentVariable("TAZEL_DAEMON_DIR", dir); + var config = DaemonConfig.FromEnvironment(); + using var cts = CancellationTokenSource.CreateLinkedTokenSource(token); + cts.CancelAfter(TimeSpan.FromSeconds(15)); + var server = new DaemonServer(config, new Version(0, 3, 0)); + var runTask = Task.Run(() => server.RunAsync(cts.Token), cts.Token); + + for (var i = 0; i < 60 && await DaemonClient.TryStatusAsync(config, cts.Token) is null; i++) + { + await Task.Delay(25, cts.Token); + } + + using var writer = new StringWriter(); + var exit = await Program.RunAsync(["--color", "never", "doctor"], dir, writer, cts.Token); + Assert.Equal(0, exit); + Assert.Contains("running", writer.ToString(), StringComparison.Ordinal); + + await DaemonProtocol.SendAsync( + config.SocketPath, + new DaemonRequest(DaemonProtocol.ProtocolVersion, "shutdown", Graceful: true), + TimeSpan.FromSeconds(2), + cts.Token); + await runTask; + } + finally + { + if (Directory.Exists(dir)) + { + Directory.Delete(dir, recursive: true); + } + } + } +}