agentleFS
VincentH-NetVincentH-Net/dotnet-agentic-engineering/.agents/skills/cli-e2e-testing/SKILL.md

cli-e2e-testing

Skill9 starsChanged 6 months agoMITView on GitHub

Use when creating, modifying, debugging, or reviewing end-to-end tests for any CLI tool that must run in a real terminal, accept keyboard input, and expose observable terminal output. Prefer Hex1b terminal automation for PTY/headless terminal flows.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

27 rules. About 0 are common, 18 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈18

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when a CLI test must exercise the real executable through a terminal-like environment instead of calling internal APIs or …

    line 19
  2. Very specific:

    Avoid Hex1b for simple non-interactive commands where ProcessStartInfo with redirected output is enough.

    line 31
  3. Distinctive:

    Create an isolated temporary workspace.

    line 35
  4. Distinctive:

    Create deterministic test fixtures and fake external tools/services as needed.

    line 36
  5. Very specific:

    Start a Hex1bTerminal with:

    line 37
  6. Very specific:

    Stop the shell/process in finally.

    line 45
  7. Distinctive:

    Keep the recording as a test artifact for visual review.

    line 46
  8. Distinctive:

    Use a unique filename that includes the test name and a GUID or timestamp.

    line 108
  9. Very specific:

    Write the recording path to test output, for example through ITestOutputHelper.

    line 109
  10. Distinctive:

    Do not commit recordings; keep them as local or CI artifacts.

    line 110
  11. Very specific:

    Keep CaptureInput disabled unless a test explicitly needs to review typed input.

    line 111
  12. Very specific:

    Use IdleTimeLimit to compress long pauses in playback.

    line 112
  13. Distinctive:

    Ensure the terminal is disposed before asserting the recording is complete.

    line 113
  14. Distinctive:

    Prefer deterministic waits over sleeps:

    line 136
  15. Distinctive:

    Use a unique command-completion sentinel when driving a shell:

    line 146
  16. Very specific:

    Wait for __DONE:0__ for success.

    line 152
  17. Distinctive:

    Wait for the prompt/list before sending input:

    line 156
  18. Distinctive:

    After keyboard input that changes the UI, wait for a visible result before continuing.

    line 174
  19. Distinctive:

    Keep e2e tests deterministic:

    line 178
  20. Distinctive:

    Avoid network calls unless the test category explicitly says it is live.

    line 182
  21. Distinctive:

    Use per-test temp directories for HOME, config, cache, and package locations when the CLI reads global state.

    line 183
  22. Distinctive:

    Prefer real local files and real process execution over mocks for the CLI itself.

    line 184
  23. Very specific:

    Use GetScreenText() for visible terminal contents.

    line 194
  24. Distinctive:

    When diagnosing a failing test:

    line 200
  25. Distinctive:

    Check the failed wait description.

    line 202
  26. Distinctive:

    Verify the wait text is literal and not accidentally matching echoed command text.

    line 205
  27. Very specific:

    Verify the CLI process inherited the intended PATH, HOME/config variables, and working directory.

    line 206

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

CLI End-to-End Testing

Use this skill when a CLI test must exercise the real executable through a terminal-like environment instead of calling internal APIs or redirecting standard input/output.

Fit

Hex1b is a good fit when tests need any of these:

  • A real PTY-backed child process such as bash, zsh, pwsh, or the CLI itself.
  • Terminal screen inspection after ANSI output, cursor movement, tables, progress bars, or interactive prompts.
  • Keyboard input such as arrows, Enter, Escape, Ctrl+C, text typing, or selection-list navigation.
  • Headless CI execution without opening a real terminal window.
  • Debuggable failures with a terminal snapshot, step history, and replayable terminal recording.

Avoid Hex1b for simple non-interactive commands where ProcessStartInfo with redirected output is enough.

Test Architecture

  1. Create an isolated temporary workspace.
  2. Create deterministic test fixtures and fake external tools/services as needed.
  3. Start a Hex1bTerminal with:
    • WithHeadless()
    • fixed dimensions large enough for the expected output
    • WithPtyProcess(...) for the shell or CLI process under test
    • WithAsciinemaRecording(...) writing to a per-test .cast file
  4. Wrap it in Hex1bTerminalAutomator.
  5. Type commands, send keys, and wait for specific output.
  6. Inspect terminal snapshots and side effects.
  7. Stop the shell/process in finally.
  8. Keep the recording as a test artifact for visual review.

Basic Pattern

using Hex1b;
using Hex1b.Automation;
using Hex1b.Input;

await using var terminal = Hex1bTerminal.CreateBuilder()
    .WithHeadless()
    .WithDimensions(160, 80)
    .WithPtyProcess(options =>
    {
        options.FileName = "/bin/bash";
        options.Arguments = ["--noprofile", "--norc", "-i"];
        options.WorkingDirectory = workspace;
        options.Environment = new Dictionary<string, string>
        {
            ["TERM"] = "xterm-256color",
            ["PATH"] = testBin + Path.PathSeparator + (Environment.GetEnvironmentVariable("PATH") ?? "")
        };
    })
    .WithAsciinemaRecording(
        recordingPath,
        new AsciinemaRecorderOptions
        {
            Title = "my-cli end-to-end test",
            Command = "my-cli",
            IdleTimeLimit = 1
        })
    .Build();

using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(90));
var runTask = terminal.RunAsync(cts.Token);
var auto = new Hex1bTerminalAutomator(terminal, defaultTimeout: TimeSpan.FromSeconds(30));

try
{
    await auto.TypeAsync("my-cli --dry-run; printf '\\n__DONE:%s__\\n' \"$?\"");
    await auto.EnterAsync();
    await auto.WaitUntilTextAsync("__DONE:0__", timeout: TimeSpan.FromSeconds(60));

    using var snapshot = auto.CreateSnapshot();
    string screen = snapshot.GetScreenText();
    Assert.Contains("Expected output", screen, StringComparison.Ordinal);
}
finally
{
    await auto.TypeAsync("exit");
    await auto.EnterAsync();
    await runTask.WaitAsync(TimeSpan.FromSeconds(5));
}

Recordings

Make Hex1b asciinema recordings a standard artifact for terminal e2e tests. This gives reviewers a visual playback of what happened without changing the CLI tool under test.

Recording guidelines:

  • Store recordings outside any disposable temp workspace, typically under the test project's TestResults/recordings directory.
  • Use a unique filename that includes the test name and a GUID or timestamp.
  • Write the recording path to test output, for example through ITestOutputHelper.
  • Do not commit recordings; keep them as local or CI artifacts.
  • Keep CaptureInput disabled unless a test explicitly needs to review typed input. It is disabled by default.
  • Use IdleTimeLimit to compress long pauses in playback.
  • Ensure the terminal is disposed before asserting the recording is complete.

Example recording path helper:

static string CreateRecordingPath(string testName)
{
    string recordingDirectory = Path.Combine(ProjectDirectory, "TestResults", "recordings");
    _ = Directory.CreateDirectory(recordingDirectory);
    return Path.Combine(recordingDirectory, $"{testName}-{Guid.NewGuid():N}.cast");
}

Visual verification:

asciinema play tests/MyCli.LiveTests/TestResults/recordings/MyTest-abc123.cast

For CI, upload TestResults/recordings/*.cast as test artifacts so failures can be replayed locally.

Waiting

Prefer deterministic waits over sleeps:

await auto.WaitUntilTextAsync("Select an option");
await auto.WaitUntilAsync(
    snapshot => snapshot.ContainsText("Ready") && !snapshot.ContainsText("Loading"),
    timeout: TimeSpan.FromSeconds(30),
    description: "CLI to finish loading");

Use a unique command-completion sentinel when driving a shell:

my-cli args; printf '\n__DONE:%s__\n' "$?"

Wait for __DONE:0__ for success. If testing failures, wait for the expected non-zero sentinel.

Keyboard Input

Wait for the prompt/list before sending input:

await auto.WaitUntilTextAsync("select which to apply:");
await auto.LeftAsync();
await auto.WaitUntilTextAsync("[ ] first-item");
await auto.EnterAsync();

Useful automator methods:

  • TypeAsync("text")
  • EnterAsync()
  • UpAsync(), DownAsync(), LeftAsync(), RightAsync()
  • SpaceAsync()
  • EscapeAsync()
  • Ctrl().KeyAsync(Hex1bKey.C)

After keyboard input that changes the UI, wait for a visible result before continuing.

External Dependencies

Keep e2e tests deterministic:

  • Stub external CLIs by putting scripts in a temporary bin directory and prepending it to PATH.
  • Log stub invocations to a temp file when assertions need to prove what was called.
  • Avoid network calls unless the test category explicitly says it is live.
  • Use per-test temp directories for HOME, config, cache, and package locations when the CLI reads global state.
  • Prefer real local files and real process execution over mocks for the CLI itself.

Assertions

Assert both terminal output and side effects:

  • Output: summary lines, prompts, selected item state, error messages, completion sentinel.
  • Side effects: files created/updated, command log contents, exit code sentinel.
  • Negative checks: no install/update command was invoked, no directive block was written, no unexpected prompt appeared.

Use GetScreenText() for visible terminal contents. If important output can scroll out of view, use larger fixed dimensions, add a sentinel near the end, or assert side effects and inspect the Hex1b recording.

Failure Diagnostics

Hex1b automation failures include step history and terminal snapshots. Make wait descriptions specific enough to identify the failed phase.

When diagnosing a failing test:

  1. Check the failed wait description.
  2. Inspect the terminal snapshot from the exception.
  3. Play the .cast recording to see the terminal flow exactly as the test saw it.
  4. Verify the wait text is literal and not accidentally matching echoed command text.
  5. Verify the CLI process inherited the intended PATH, HOME/config variables, and working directory.
  6. Confirm the test waited for the UI to rerender after each key input.

Common Pitfalls

  • Matching command text echoed by the shell instead of output produced after execution.
  • Pressing Enter immediately after a key input without waiting for the terminal UI to update.
  • Relying on arbitrary delays instead of WaitUntilTextAsync or WaitUntilAsync.
  • Letting tests use the developer machine's real CLI extensions, global config, or network credentials.
  • Using a terminal height too small for the output under test.
  • Writing recordings into a temp workspace that the test deletes before the developer can replay them.
  • Asserting a file was not created when the CLI intentionally creates scaffolding even with no selected actions; assert the meaningful content instead.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.