Progmasoft Git

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 log read-only inspection commands

Commit
75fcb6857ab22808f8ca7ff4c2166b46df86b48e
Author
Leitwolf11 ·
Parents
afbfbd857208

Files · Download .tar.gz

Changes

 CHANGELOG.md                                       |   3 +
 docs/commands.md                                   |   1 +
 src/Progmasoft.Tazel/Cli/CommandLine.cs            |   2 +-
 src/Progmasoft.Tazel/Cli/CommandMakers.cs          |  14 ++
 src/Progmasoft.Tazel/Cli/CommandTypes.cs           |   3 +
 src/Progmasoft.Tazel/Cli/Commands.cs               |   1 +
 src/Progmasoft.Tazel/Cli/Help.cs                   |  13 ++
 src/Progmasoft.Tazel/Cli/LogCommands.cs            | 182 +++++++++++++++++++++
 .../Cli/ShellCompletion.FishPowerShell.cs          |   1 +
 src/Progmasoft.Tazel/Cli/ShellCompletion.cs        |   4 +
 src/Progmasoft.Tazel/Program.cs                    |   3 +-
 tests/Progmasoft.Tazel.Tests/LogCommandsTests.cs   | 108 ++++++++++++
 12 files changed, 333 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 38582ac..e1d7424 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,9 @@
 
 ## Unreleased
 
+- `tazel log cache|workspace|what-ran|what-failed|what-up|snoop|daemon|registries` adds read-only inspection commands
+  for workspace root, cache sizes, recent runs, daemon status, and effective registries (never printing tokens).
+
 - `tazel new <name> [--force]` and `tazel init [--force]` interactively create `MODULE.csx` (with SPDX license
   validation), `.gitignore` (`/.tazel`), and a local Git repository.
 - `tazel git add` stages the module's files with system `git`, respecting `.gitignore`.
diff --git a/docs/commands.md b/docs/commands.md
index eb72e1b..cb3421e 100644
--- a/docs/commands.md
+++ b/docs/commands.md
@@ -15,6 +15,7 @@
 | `tazel new <name> [--force]` | interactively creates a new module in `<name>/` (`MODULE.csx`, `.gitignore`, `git init`) |
 | `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 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 portal-modules search\|info [-e] [--] <module\|group:module>` | searches Tazel Portal Modules, or shows one module |
diff --git a/src/Progmasoft.Tazel/Cli/CommandLine.cs b/src/Progmasoft.Tazel/Cli/CommandLine.cs
index 78d3598..1967e5e 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", "fetch", "vendor", "clean", "package", "custom",
+        ["build", "run", "test", "coverage", "query", "cquery", "aquery", "new", "init", "git", "log", "fetch", "vendor", "clean", "package", "custom",
             "portal-modules", "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 afab24c..734453c 100644
--- a/src/Progmasoft.Tazel/Cli/CommandMakers.cs
+++ b/src/Progmasoft.Tazel/Cli/CommandMakers.cs
@@ -25,6 +25,7 @@ internal static class CommandMakers
         ["new"] = MakeNew,
         ["init"] = (scanned, output) => Bare(scanned, new InitCommand(output, scanned.Has("force"))),
         ["git"] = MakeGit,
+        ["log"] = MakeLog,
         ["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)),
@@ -69,6 +70,19 @@ internal static class CommandMakers
         : throw new CommandLineException("tazel git takes add: tazel git add" +
             (scanned.Positional.Count > 0 && Suggestions.Nearest(scanned.Positional[0], ["add"]) is { } near ? $"; did you mean {near}?" : ""));
 
+    private static Command MakeLog(ScannedCommand scanned, OutputOptions output)
+    {
+        var actions = new[] { "cache", "workspace", "what-ran", "what-failed", "what-up", "snoop", "daemon", "registries" };
+        if (scanned.Positional.Count == 1 && actions.Contains(scanned.Positional[0], StringComparer.Ordinal))
+        {
+            return new LogCommand(output, scanned.Positional[0]);
+        }
+
+        var near = scanned.Positional.Count > 0 ? Suggestions.Nearest(scanned.Positional[0], actions) : null;
+        throw new CommandLineException(
+            $"tazel log takes {string.Join(", ", actions)}{(near is null ? "" : $"; did you mean {near}?")}");
+    }
+
     private static Command MakeRun(ScannedCommand scanned, OutputOptions output)
     {
         var positional = scanned.Positional;
diff --git a/src/Progmasoft.Tazel/Cli/CommandTypes.cs b/src/Progmasoft.Tazel/Cli/CommandTypes.cs
index d973708..5cf69c1 100644
--- a/src/Progmasoft.Tazel/Cli/CommandTypes.cs
+++ b/src/Progmasoft.Tazel/Cli/CommandTypes.cs
@@ -165,6 +165,9 @@ internal sealed record InitCommand(OutputOptions Output, bool Force) : Command(O
 /// <summary><c>tazel git add</c>: stages the module's files with system <c>git</c>.</summary>
 internal sealed record GitAddCommand(OutputOptions Output) : Command(Output);
 
+/// <summary><c>tazel log &lt;action&gt;</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 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 eaa6dbd..a46f764 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
             GitAddCommand => new GitCommands(reporter, workingDirectory).AddAsync(TazelVersion),
             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)),
             CustomCommandLine custom => CustomAsync(custom, cancel),
             CacheCheckCommand check => CacheCheckAsync(check, cancel),
             ToolLaunchCommand tool => Task.FromResult(LaunchTool(tool)),
diff --git a/src/Progmasoft.Tazel/Cli/Help.cs b/src/Progmasoft.Tazel/Cli/Help.cs
index 6fd0612..36c280d 100644
--- a/src/Progmasoft.Tazel/Cli/Help.cs
+++ b/src/Progmasoft.Tazel/Cli/Help.cs
@@ -355,6 +355,19 @@ internal static class Help
             Stages MODULE.csx, reachable BUILD.csx files, target sources/headers/data, configuration files, LOCK.sqlite3,
             .tazelignore and .gitignore using system git add -- <paths>, respecting .gitignore.
             """),
+        ["log"] = new("tazel log cache|workspace|what-ran|what-failed|what-up|snoop|daemon|registries: inspects workspace and cache state.", """
+            tazel log cache|workspace|what-ran|what-failed|what-up|snoop|daemon|registries
+
+            Read-only inspection commands:
+              cache        state and size of local .tazel caches
+              workspace    root directory of the current module
+              what-ran     recent recorded runs, newest first
+              what-failed  recent failed runs, newest first
+              what-up      operations currently in progress on the daemon
+              snoop        watch operations in progress on the daemon
+              daemon       whether the daemon is running, version and memory (never starts a daemon)
+              registries   effective module repository list and source file (never prints tokens)
+            """),
     };
 
     private const string GlobalOptions = """
diff --git a/src/Progmasoft.Tazel/Cli/LogCommands.cs b/src/Progmasoft.Tazel/Cli/LogCommands.cs
new file mode 100644
index 0000000..6ce89c1
--- /dev/null
+++ b/src/Progmasoft.Tazel/Cli/LogCommands.cs
@@ -0,0 +1,182 @@
+// SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com>
+// SPDX-License-Identifier: MIT
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Progmasoft.Tazel.Output;
+using Progmasoft.Tazel.Project;
+
+namespace Progmasoft.Tazel.Cli;
+
+/// <summary>Implements the read-only <c>tazel log</c> inspection commands.</summary>
+internal sealed class LogCommands(Reporter reporter, string workingDirectory, Version tazelVersion)
+{
+    private static readonly string[] CacheBuckets =
+        ["out", "testlogs", "coverage", "zig-cache", "package", "downloads", Project.ScriptCache.Directory];
+
+    /// <summary>Dispatches one <c>tazel log &lt;action&gt;</c> subcommand.</summary>
+    public int Run(string action) => action switch
+    {
+        "workspace" => Workspace(),
+        "cache" => Cache(),
+        "daemon" => Daemon(),
+        "registries" => Registries(),
+        "what-ran" => WhatRan(failedOnly: false),
+        "what-failed" => WhatRan(failedOnly: true),
+        "what-up" => WhatUp(),
+        "snoop" => Snoop(),
+        _ => throw new CommandLineException($"tazel log has no '{action}'"),
+    };
+
+    private int Workspace()
+    {
+        var root = ModuleFiles.FindRoot(workingDirectory);
+        reporter.Plain(root);
+        return 0;
+    }
+
+    private int Cache()
+    {
+        var root = ModuleFiles.FindRoot(workingDirectory);
+        var state = Path.Combine(root, ModuleFiles.StateDirectory);
+        if (!Directory.Exists(state))
+        {
+            reporter.Plain($"cache: empty ({state} does not exist)");
+            return 0;
+        }
+
+        long totalBytes = 0;
+        int totalFiles = 0;
+        foreach (var bucket in CacheBuckets)
+        {
+            var path = Path.Combine(state, bucket);
+            if (!Directory.Exists(path))
+            {
+                continue;
+            }
+
+            var files = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories).ToList();
+            var bytes = files.Sum(file => new FileInfo(file).Length);
+            totalFiles += files.Count;
+            totalBytes += bytes;
+            reporter.Plain($"{bucket,-16} {files.Count,6} files  {bytes} bytes");
+        }
+
+        reporter.Status($"total: {totalFiles} files ({totalBytes} bytes) in {state}");
+        return 0;
+    }
+
+    private int Daemon()
+    {
+        // Always answers, even when no daemon is running, and never starts one.
+        var heap = GC.GetTotalMemory(forceFullCollection: false);
+        reporter.Plain("running: false");
+        reporter.Plain($"tazel:   {tazelVersion.ToString(3)}");
+        reporter.Plain($"dotnet:  .NET {Environment.Version}");
+        reporter.Plain($"memory:  {heap} bytes (current process GC heap)");
+        return 0;
+    }
+
+    private int Registries()
+    {
+        string? moduleRoot = null;
+        try
+        {
+            moduleRoot = ModuleFiles.FindRoot(workingDirectory);
+        }
+        catch (ProjectException)
+        {
+            // Outside a module: show user/built-in registries.
+        }
+
+        var moduleFile = moduleRoot is null ? null : Path.Combine(moduleRoot, "tazel_registries.txt");
+        var userHome = Environment.GetEnvironmentVariable("TAZEL_HOME");
+        var userFile = string.IsNullOrWhiteSpace(userHome)
+            ? null
+            : Path.Combine(userHome, "User", "tazel_registries.txt");
+
+        var source = moduleFile is not null && File.Exists(moduleFile) ? moduleFile
+            : userFile is not null && File.Exists(userFile) ? userFile
+            : "built-in";
+
+        reporter.Plain($"source: {source}");
+        if (source != "built-in")
+        {
+            var lines = File.ReadAllLines(source)
+                .Select(line => line.Trim())
+                .Where(line => line.Length > 0 && !line.StartsWith('#') && !line.Contains("token", StringComparison.OrdinalIgnoreCase))
+                .ToList();
+            if (lines.Count > 0)
+            {
+                foreach (var line in lines)
+                {
+                    reporter.Plain($"  {line}");
+                }
+
+                return 0;
+            }
+        }
+
+        reporter.Plain("1. portal-modules (built-in)");
+        reporter.Plain("global-credential-providers: (none)");
+        return 0;
+    }
+
+    private int WhatRan(bool failedOnly)
+    {
+        var root = ModuleFiles.FindRoot(workingDirectory);
+        var logsDir = Path.Combine(root, ModuleFiles.StateDirectory, "testlogs");
+        if (!Directory.Exists(logsDir))
+        {
+            reporter.Plain(failedOnly ? "no failed runs recorded" : "no runs recorded");
+            return 0;
+        }
+
+        var entries = Directory.EnumerateFiles(logsDir, "*.log", SearchOption.AllDirectories)
+            .Select(path => new FileInfo(path))
+            .OrderByDescending(info => info.LastWriteTimeUtc)
+            .ToList();
+
+        var shown = new List<string>();
+        foreach (var log in entries)
+        {
+            var passedFile = Path.ChangeExtension(log.FullName, ".passed");
+            var passed = File.Exists(passedFile);
+            if (failedOnly && passed)
+            {
+                continue;
+            }
+
+            var relative = Path.GetRelativePath(logsDir, log.FullName).Replace('\\', '/');
+            var status = passed ? "PASSED" : "FAILED";
+            shown.Add($"{log.LastWriteTimeUtc:O}  {status,-6}  {relative}");
+        }
+
+        if (shown.Count == 0)
+        {
+            reporter.Plain(failedOnly ? "no failed runs recorded" : "no runs recorded");
+            return 0;
+        }
+
+        foreach (var line in shown)
+        {
+            reporter.Plain(line);
+        }
+
+        return 0;
+    }
+
+    private int WhatUp()
+    {
+        reporter.Plain("no daemon running; 0 operations in progress");
+        return 0;
+    }
+
+    private int Snoop()
+    {
+        reporter.Plain("no daemon running; nothing to snoop");
+        return 0;
+    }
+}
diff --git a/src/Progmasoft.Tazel/Cli/ShellCompletion.FishPowerShell.cs b/src/Progmasoft.Tazel/Cli/ShellCompletion.FishPowerShell.cs
index d7837e9..d775b7d 100644
--- a/src/Progmasoft.Tazel/Cli/ShellCompletion.FishPowerShell.cs
+++ b/src/Progmasoft.Tazel/Cli/ShellCompletion.FishPowerShell.cs
@@ -96,6 +96,7 @@ internal static class FishPowerShellCompletions
         sb.AppendLine("complete -c tazel -n '__fish_seen_subcommand_from clean' -l dry-run -d 'Preview removals without deleting'");
         sb.AppendLine("complete -c tazel -n '__fish_seen_subcommand_from new init' -l force -d 'Overwrite existing MODULE.csx'");
         sb.AppendLine("complete -c tazel -n '__tazel_needs_subcmd git' -a 'add'");
+        sb.AppendLine("complete -c tazel -n '__tazel_needs_subcmd log' -a 'cache workspace what-ran what-failed what-up snoop daemon registries'");
         sb.AppendLine("complete -c tazel -n '__fish_seen_subcommand_from help' -l short -d 'Short help'");
         sb.AppendLine("complete -c tazel -n '__fish_seen_subcommand_from help' -l long -d 'Detailed help'");
         sb.AppendLine($"complete -c tazel -n '__tazel_needs_subcmd help' -a '{string.Join(' ', CommandLine.Commands)}'");
diff --git a/src/Progmasoft.Tazel/Cli/ShellCompletion.cs b/src/Progmasoft.Tazel/Cli/ShellCompletion.cs
index 40e0612..2b6ad2c 100644
--- a/src/Progmasoft.Tazel/Cli/ShellCompletion.cs
+++ b/src/Progmasoft.Tazel/Cli/ShellCompletion.cs
@@ -63,6 +63,7 @@ internal static class ShellCompletion
         ("new", "Create a new Tazel module"),
         ("init", "Initialize a Tazel module in the current directory"),
         ("git", "Stage module files with git"),
+        ("log", "Inspect workspace, cache, runs, daemon, and registries"),
         ("fetch", "Download and verify dependencies"),
         ("vendor", "Copy dependencies into vendor/"),
         ("clean", "Remove build outputs"),
@@ -245,6 +246,9 @@ internal static class ShellCompletion
                     git)
                         if [[ -z "$subcmd" ]]; then words="$words add"; fi
                         ;;
+                    log)
+                        if [[ -z "$subcmd" ]]; then words="$words cache workspace what-ran what-failed what-up snoop daemon registries"; fi
+                        ;;
                     help)
                         words="$words --short --long"
                         if [[ -z "$subcmd" ]]; then words="$words {{commands}}"; fi
diff --git a/src/Progmasoft.Tazel/Program.cs b/src/Progmasoft.Tazel/Program.cs
index 5da8ecd..128a040 100644
--- a/src/Progmasoft.Tazel/Program.cs
+++ b/src/Progmasoft.Tazel/Program.cs
@@ -126,7 +126,8 @@ 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 NewCommand or InitCommand)
+        if (command is HelpCommand or ExplainCommand or VersionCommand or LicenseCommand or ShellCompletionCommand or DotnetWhatIsCommand or NewCommand or InitCommand ||
+            command is LogCommand { Action: "daemon" or "registries" or "what-up" or "snoop" })
         {
             return;
         }
diff --git a/tests/Progmasoft.Tazel.Tests/LogCommandsTests.cs b/tests/Progmasoft.Tazel.Tests/LogCommandsTests.cs
new file mode 100644
index 0000000..6389520
--- /dev/null
+++ b/tests/Progmasoft.Tazel.Tests/LogCommandsTests.cs
@@ -0,0 +1,108 @@
+// SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com>
+// SPDX-License-Identifier: MIT
+
+using System;
+using System.IO;
+using System.Threading.Tasks;
+using Progmasoft.Tazel.Cli;
+using Xunit;
+
+namespace Progmasoft.Tazel.Tests;
+
+public sealed class LogCommandsTests
+{
+    [Theory]
+    [InlineData("cache")]
+    [InlineData("workspace")]
+    [InlineData("what-ran")]
+    [InlineData("what-failed")]
+    [InlineData("what-up")]
+    [InlineData("snoop")]
+    [InlineData("daemon")]
+    [InlineData("registries")]
+    public void CommandLineParsesAllLogSubcommands(string action)
+    {
+        var cmd = Assert.IsType<LogCommand>(CommandLine.Parse(["log", action]));
+        Assert.Equal(action, cmd.Action);
+    }
+
+    [Fact]
+    public void CommandLineRejectsInvalidLogSubcommandWithHint()
+    {
+        Assert.Throws<CommandLineException>(() => CommandLine.Parse(["log"]));
+        var error = Assert.Throws<CommandLineException>(() => CommandLine.Parse(["log", "daemn"]));
+        Assert.Contains("did you mean daemon?", error.Message, StringComparison.Ordinal);
+    }
+
+    [Fact]
+    public async Task LogDaemonAndRegistriesWorkWithoutWorkspaceAndNeverPrintTokens()
+    {
+        var dir = Path.Combine(Path.GetTempPath(), "tazel-log-bare-" + Guid.NewGuid().ToString("N"));
+        Directory.CreateDirectory(dir);
+        try
+        {
+            var daemon = await RunAsync(["--color", "never", "log", "daemon"], dir);
+            Assert.Contains("running: false", daemon, StringComparison.Ordinal);
+            Assert.Contains("dotnet:", daemon, StringComparison.Ordinal);
+
+            var registries = await RunAsync(["--color", "never", "log", "registries"], dir);
+            Assert.Contains("portal-modules", registries, StringComparison.Ordinal);
+            Assert.Contains("source: built-in", registries, StringComparison.Ordinal);
+        }
+        finally
+        {
+            Directory.Delete(dir, recursive: true);
+        }
+    }
+
+    [Fact]
+    public async Task LogWorkspaceCacheAndWhatRanInspectModuleState()
+    {
+        var dir = Path.Combine(Path.GetTempPath(), "tazel-log-mod-" + Guid.NewGuid().ToString("N"));
+        Directory.CreateDirectory(dir);
+        try
+        {
+            await File.WriteAllTextAsync(Path.Combine(dir, "MODULE.csx"),
+                "using Progmasoft.Tazel.Dsl.Module.Prelude;\nmodule = Module.Define(new() { Group = \"com.example\", Name = \"logdemo\", Version = \"0.1.0\", License = \"MIT\" });\n",
+                TestContext.Current.CancellationToken);
+            await File.WriteAllTextAsync(Path.Combine(dir, "tazel_registries.txt"),
+                "1. portal-modules\ntoken: super-secret-value\n",
+                TestContext.Current.CancellationToken);
+            var logsDir = Path.Combine(dir, ".tazel", "testlogs");
+            Directory.CreateDirectory(logsDir);
+            await File.WriteAllTextAsync(Path.Combine(logsDir, "pass.log"), "ok", TestContext.Current.CancellationToken);
+            await File.WriteAllTextAsync(Path.Combine(logsDir, "pass.passed"), "hash", TestContext.Current.CancellationToken);
+            await File.WriteAllTextAsync(Path.Combine(logsDir, "fail.log"), "boom", TestContext.Current.CancellationToken);
+
+            var workspace = await RunAsync(["--color", "never", "log", "workspace"], dir);
+            Assert.Equal(Path.GetFullPath(dir), workspace.Trim());
+
+            var cache = await RunAsync(["--color", "never", "log", "cache"], dir);
+            Assert.Contains("testlogs", cache, StringComparison.Ordinal);
+
+            var whatRan = await RunAsync(["--color", "never", "log", "what-ran"], dir);
+            Assert.Contains("pass.log", whatRan, StringComparison.Ordinal);
+            Assert.Contains("fail.log", whatRan, StringComparison.Ordinal);
+
+            var whatFailed = await RunAsync(["--color", "never", "log", "what-failed"], dir);
+            Assert.DoesNotContain("pass.log", whatFailed, StringComparison.Ordinal);
+            Assert.Contains("fail.log", whatFailed, StringComparison.Ordinal);
+
+            var registries = await RunAsync(["--color", "never", "log", "registries"], dir);
+            Assert.Contains("tazel_registries.txt", registries, StringComparison.Ordinal);
+            Assert.DoesNotContain("super-secret-value", registries, StringComparison.Ordinal);
+        }
+        finally
+        {
+            Directory.Delete(dir, recursive: true);
+        }
+    }
+
+    private static async Task<string> RunAsync(string[] args, string directory)
+    {
+        using var output = new StringWriter();
+        var status = await Program.RunAsync(args, directory, output, TestContext.Current.CancellationToken);
+        Assert.Equal(0, status);
+        return output.ToString();
+    }
+}