test-fixer
FreeNo executable scriptsNot checkedAgent for diagnosing and fixing flaky terminal UI tests in the Hex1b test suite. Use when tests pass locally but fail in CI, or when tests exhibit…
by mitchdenny★ 186 GitHub starsAbout this skill
Test Fixer Skill
This skill provides guidelines for AI agents to diagnose and fix flaky tests in the Hex1b TUI library test suite. These tests use MSTest 4 (MSTest.Sdk/4.2.3, OutputType=Exe) with Microsoft.Testing.Platform and Hex1bTerminalInputSequenceBuilder to simulate user interactions with terminal applications. global.json configures dotnet test to use MTP, and test projects can also be run as executables with dotnet run --project tests/SomeProject/.
Quick Reference: Common Flaky Test Patterns
| Pattern | Symptom | Fix |
|---|---|---|
| Snapshot After Exit | Test passes locally, fails on Linux CI | Move WaitUntil before Capture, ensure Capture is before exit |
| Missing WaitUntil | Intermittent assertion failures | Add WaitUntil for expected state before Capture |
| Race with Ctrl+C | Snapshot missing expected content | Add WaitUntil between last action and Capture |
| Task.WhenAny Race | Test sometimes times out | Replace with proper WaitUntil or increase timeout |
| Test Interference | Pass isolated, fail in suite | Check for shared state, file locks, or parallel execution issues |
| Platform-Specific | Fails consistently on Windows/Linux | Add TestCategory/Ignore or fix platform-specific code |
| Task.Delay for Async Events | Flaky on slower CI runners | Replace Task.Delay with TaskCompletionSource signal |
| Helper Partial Wait | Tests using multi-line helpers fail intermittently | Wait for all/last content, not just first line |
Pattern 1: Snapshot Captured After App Exit
⚠️ This is the most common flaky test issue
Symptoms
- Test passes consistently on Windows
- Test fails on Linux CI (GitHub Actions ubuntu-latest)
- Assertion fails with content that "should" be there
- Error messages like
Assert.IsTrue failedorAn item should be selected with indicator
Root Cause
The ApplyWithCaptureAsync method returns terminal.CreateSnapshot() after all steps complete, not at the point where .Capture() is called. When the sequence includes Ctrl+C to exit the app, the terminal buffer may be cleared before the final snapshot is taken.
Platform difference: Windows terminal buffers persist longer after app exit; Linux clears them more aggressively.
Example: Broken Test
// ❌ BROKEN: Snapshot is taken AFTER Ctrl+C exits the app
var snapshot = await new Hex1bTerminalInputSequenceBuilder()
.WaitUntil(s => s.ContainsText("Counter: 3"), TimeSpan.FromSeconds(2))
.Capture("final") // This saves SVG but doesn't capture for return!
.Ctrl().Key(Hex1bKey.C) // App exits, terminal buffer may be cleared
.Build()
.ApplyWithCaptureAsync(terminal, TestContext.Current.CancellationToken);
// snapshot is from AFTER Ctrl+C, not from Capture step!
Assert.IsTrue(snapshot.ContainsText("Counter: 3")); // May fail on Linux!
How It Works
Hex1bTerminalInputSequenceBuilderbuilds a sequence ofTestStepobjectsApplyWithCaptureAsyncexecutes all steps, then callsterminal.CreateSnapshot()at the endCaptureSteponly saves SVG/HTML files—it does NOT store the snapshot for return- When
Ctrl+Ctriggers app exit, the terminal may clear its buffer before the final snapshot
Fix Strategy
Option A: Ensure WaitUntil is immediately before Capture (Recommended)
// ✅ FIXED: WaitUntil confirms state, then Capture, then exit
var snapshot = await new Hex1bTerminalInputSequenceBuilder()
.Key(Hex1bKey.A)
.Key(Hex1bKey.B)
.WaitUntil(s => s.ContainsText("Counter: 3"), TimeSpan.FromSeconds(2))
.Capture("final")
.Ctrl().Key(Hex1bKey.C)
.Build()
.ApplyWithCaptureAsync(terminal, TestContext.Current.CancellationToken);
await runTask;
// If the WaitUntil passed, we know the content was there at Capture time
// The assertion is now checking what WaitUntil already verified
Assert.IsTrue(snapshot.ContainsText("Counter: 3"));
Option B: Don't use snapshot for content assertions
// ✅ ALTERNATIVE: Use render counters or other non-snapshot assertions
var runTask = app.RunAsync(TestContext.Current.CancellationToken);
await new Hex1bTerminalInputSequenceBuilder()
.Key(Hex1bKey.A)
.Key(Hex1bKey.B)
.Capture("final")
.Ctrl().Key(Hex1bKey.C)
.Build()
.ApplyWithCaptureAsync(terminal, TestContext.Current.CancellationToken);
await runTask;
// Assert on counters/state captured during execution, not snapshot content
Assert.AreEqual(1, staticRenderCount);
Option C: Use WaitUntil as the assertion itself
// ✅ ALTERNATIVE: WaitUntil IS the assertion - if it passes
Install test-fixer in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the test-fixer skill do?
Agent for diagnosing and fixing flaky terminal UI tests in the Hex1b test suite. Use when tests pass locally but fail in CI, or when tests exhibit timing-sensitive behavior.
How do I install the test-fixer skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the test-fixer skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
by Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
by Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
by Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
by Anthropic