Skip to content

test(test_tool): redirect stderr to stdout and strip ansi codes#8738

Merged
jdx merged 5 commits intojdx:mainfrom
risu729:test-tool-strip-ansi
Mar 24, 2026
Merged

test(test_tool): redirect stderr to stdout and strip ansi codes#8738
jdx merged 5 commits intojdx:mainfrom
risu729:test-tool-strip-ansi

Conversation

@risu729
Copy link
Copy Markdown
Contributor

@risu729 risu729 commented Mar 24, 2026

Fixes ni test.

This PR modifies mise test-tool to redirect stderr to stdout, and then strips ANSI codes from stdout before matching the expected output. It also cleans up unnecessary 2>&1 redirects and ansi-stripping workarounds in registry/** tools tests.

Copilot AI review requested due to automatic review settings March 24, 2026 11:53
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the mise test-tool's behavior by ensuring all command output, including errors, is captured and processed uniformly. It also streamlines the testing configurations across various tools in the registry by eliminating previously necessary output redirection and formatting workarounds, leading to cleaner and more robust test definitions.

Highlights

  • mise test-tool improvements: The mise test-tool now redirects stderr to stdout for comprehensive output capture and automatically strips ANSI escape codes before comparing test results, enhancing test reliability.
  • Registry test simplification: Redundant 2>&1 redirects and manual ANSI stripping commands have been removed from numerous registry/*.toml test configurations, simplifying test definitions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@risu729 risu729 force-pushed the test-tool-strip-ansi branch from ec1bc70 to 2fc4708 Compare March 24, 2026 11:55
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 24, 2026

Greptile Summary

This PR fixes the ni test (and hardens all other registry tool tests) by centralising two behaviours inside mise test-tool: stderr is now redirected to stdout at the Rust level (stderr_to_stdout()), and ANSI escape codes are stripped from the captured output before comparing against the expected string. As a result, all per-tool workarounds — the 2>&1 shell redirects in 27 registry .toml files, the manual sed ANSI stripping in btop.toml, and the hardcoded ANSI sequences in ni.toml's expected string — are cleanly removed.

Key changes:

  • src/cli/test_tool.rs: adds stderr_to_stdout() to the command builder and uses console::strip_ansi_codes before matching; error messages now show the cleaned output (addressing a prior review comment).
  • 27 registry files: mechanical removal of 2>&1 and/or ANSI workarounds.
  • registry/ni.toml: hardcoded escape sequences removed from the expected value.
  • registry/imagemagick.toml: test was commented out (not merely updated) — unlike every other file in the PR; the reason is not documented.

Confidence Score: 4/5

  • PR is safe to merge; the imagemagick skip and raw ANSI print are minor follow-up items.
  • The core logic change is correct and minimal — two lines in test_tool.rs. All registry cleanups are mechanical. The previously raised concern about raw ANSI in the error message has been fixed. Two small non-blocking P2s remain: (1) miseprintln! still emits raw ANSI to non-TTY outputs, and (2) the imagemagick test was silently commented out without explanation.
  • registry/imagemagick.toml — test was commented out entirely rather than updated; reason is undocumented.

Important Files Changed

Filename Overview
src/cli/test_tool.rs Core change: adds stderr_to_stdout() to capture stderr alongside stdout, and strips ANSI codes before matching expected output. Error message now uses clean_stdout. Logic is correct.
registry/ni.toml Root cause of the failing test: hardcoded ANSI escape sequences removed from expected string since stripping now happens in test_tool.rs.
registry/imagemagick.toml Test was commented out entirely rather than just removing 2>&1 — unlike every other registry file changed in this PR, which is worth explaining.
registry/btop.toml Removed manual sed-based ANSI stripping workaround in favour of the new centralised stripping in test_tool.rs — clean improvement.
registry/aws-vault.toml Commented-out test updated to remove 2>&1 — comment state (disabled) unchanged, only the stale redirect is cleaned up.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[mise test-tool &lt;tool&gt;] --> B[Install tool]
    B --> C[Build command]
    C --> D["Run: sh -c &lt;cmd&gt;\nstderr_to_stdout + stdout_capture"]
    D --> E{Exit code?}
    E -- "0" --> F[Capture combined stdout+stderr]
    E -- "127 (not found)" --> G[Log bin dirs & output]
    E -- "other" --> H[Return error]
    G --> H
    F --> I["miseprintln! raw stdout (ANSI preserved for TTY)"]
    I --> J["strip_ansi_codes(stdout) → clean_stdout"]
    J --> K{clean_stdout contains expected?}
    K -- "yes" --> L[OK ✅]
    K -- "no" --> M["Error: expected X, got clean_stdout"]
Loading

Reviews (4): Last reviewed commit: "registry: disable imagemagick version te..." | Re-trigger Greptile

Comment thread src/cli/test_tool.rs
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates mise test-tool output handling so tool tests match against combined output without ANSI formatting, and simplifies registry tool test commands accordingly.

Changes:

  • Redirect stderr to stdout when running tool test commands, and capture the combined output.
  • Strip ANSI escape codes from captured output before checking for the expected substring.
  • Remove redundant 2>&1 redirects and ANSI-stripping pipelines from multiple registry/*.toml tool tests.

Reviewed changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/cli/test_tool.rs Merge stderr into captured output and strip ANSI codes before matching expected output.
registry/zprint.toml Remove 2>&1 from version test command.
registry/trzsz-ssh.toml Remove 2>&1 from version test command.
registry/superhtml.toml Remove 2>&1 from version test command.
registry/sbt.toml Remove 2>&1 from version test command.
registry/sampler.toml Remove 2>&1 from version test command.
registry/oc.toml Remove 2>&1 from version test command.
registry/oauth2c.toml Remove 2>&1 from version test command.
registry/minio.toml Remove 2>&1 from version test command.
registry/luajit.toml Remove 2>&1 from version test command.
registry/kubent.toml Remove 2>&1 from version test command.
registry/kscript.toml Remove 2>&1 from version test command.
registry/krab.toml Remove 2>&1 from version test command.
registry/jsonnet-bundler.toml Remove 2>&1 from version test command.
registry/jfrog-cli.toml Remove 2>&1 from version test command.
registry/imagemagick.toml Remove 2>&1 from version test command.
registry/httpie-go.toml Remove 2>&1 from version test command.
registry/gomigrate.toml Remove 2>&1 from version test command.
registry/ffmpeg.toml Remove 2>&1 from version test command.
registry/dagu.toml Remove 2>&1 from version test command.
registry/cidr-merger.toml Remove 2>&1 from version test command.
registry/carapace.toml Remove 2>&1 from version test command.
registry/btop.toml Drop sed ANSI-stripping workaround; rely on centralized ANSI stripping.
registry/bombardier.toml Remove 2>&1 from version test command.
registry/bazel-watcher.toml Remove 2>&1 from version test command.
registry/aws-vault.toml Update commented-out test command to remove 2>&1.
registry/amass.toml Remove 2>&1 from version test command.
registry/agebox.toml Remove 2>&1 from version test command.
registry/aapt2.toml Remove 2>&1 from version test command.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/cli/test_tool.rs
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the mise test-tool command to automatically redirect stderr to stdout and strip ANSI codes from the output before comparison. This is a great improvement that simplifies test definitions in numerous registry/*.toml files by removing manual redirections and ANSI code stripping workarounds. The changes in src/cli/test_tool.rs are well-implemented. The suggestion to improve the clarity of the error message when a test fails remains valid.

Comment thread src/cli/test_tool.rs Outdated
@risu729 risu729 force-pushed the test-tool-strip-ansi branch from 02bc136 to cef094b Compare March 24, 2026 11:59
@jdx jdx merged commit bf9d700 into jdx:main Mar 24, 2026
34 checks passed
@risu729 risu729 deleted the test-tool-strip-ansi branch March 24, 2026 19:00
jdx pushed a commit that referenced this pull request Mar 24, 2026
### 🚀 Features

- **(github)** add github_tokens.toml, git credential fill, and `mise
github token` command by @jdx in
[#8742](#8742)
- **(registry)** add tart by @mnm364 in
[#8727](#8727)

### 🐛 Bug Fixes

- **(python)** respect precompiled flavor when excluding freethreaded
builds by @risu729 in [#8745](#8745)
- **(shim)** revert shims directory check that caused hangs on macOS by
@jdx in
[e1b8ca4](e1b8ca4)

### 📚 Documentation

- **(python)** swap docs for python.precompiled_arch and
python.precompiled_os by @risu729 in
[#8744](#8744)

### 🧪 Testing

- **(test_tool)** redirect stderr to stdout and strip ansi codes by
@risu729 in [#8738](#8738)

### New Contributors

- @rtharston made their first contribution in
[#8731](#8731)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants