Skip to content

test(shell): fix test on non posix shell#2495

Closed
hongqitai wants to merge 1 commit into
Hmbown:mainfrom
hongqitai:test/fix-test-on-non-posix
Closed

test(shell): fix test on non posix shell#2495
hongqitai wants to merge 1 commit into
Hmbown:mainfrom
hongqitai:test/fix-test-on-non-posix

Conversation

@hongqitai

@hongqitai hongqitai commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Test "codewhale_tui::tools::shell::tests::shell_execution_scrubs_parent_env_and_keeps_explicit_env" fail on non posix shell like fish.
Use "sh -c" run command to fix it.

Testing

  • [ x ] cargo fmt --all -- --check
  • [ x ] cargo clippy --workspace --all-targets --all-features
  • [ x ] cargo test --workspace --all-features

Checklist

  • [ x ] Updated docs or comments as needed
  • [ x ] Added or updated tests where relevant
  • [ x ] Verified TUI behavior manually if UI changes

Greptile Summary

This PR fixes a test failure on non-POSIX shells (e.g. fish) by wrapping the test command in sh -c '...', ensuring the POSIX ${VAR-default} parameter expansion syntax is always interpreted by a POSIX-compatible shell rather than the user's default shell.

  • The original command relied on ${VAR-default} expansion being understood by the ambient shell; wrapping in sh -c ensures a POSIX interpreter regardless of the configured shell dispatcher.
  • The quoting is correct: the sh -c argument uses single quotes, which prevent the outer shell from reinterpreting the double-quoted format string and variable expansions inside.

Confidence Score: 5/5

Safe to merge — it is a one-line test-only change with correct quoting and no impact on production code paths.

The change is confined to a single test, replaces a shell-specific invocation with a portable sh -c wrapper, preserves the original test assertion, and introduces no new logic or risk.

No files require special attention.

Important Files Changed

Filename Overview
crates/tui/src/tools/shell/tests.rs One-line change: wraps the env-scrubbing test command in sh -c '...' so POSIX parameter expansion works on non-POSIX shells like fish. Quoting is correct and the test assertion logic is unchanged.

Sequence Diagram

sequenceDiagram
    participant T as Test
    participant M as ShellManager
    participant OS as OS Shell (e.g. fish)
    participant SH as sh (POSIX)

    T->>M: execute_with_options_env("sh -c 'printf ...'")
    M->>OS: spawn with scrubbed env + explicit vars
    OS->>SH: "sh -c 'printf "%s\n%s\n" "${VAR-unset}" ...'"
    SH-->>OS: "unset\nexplicit-value\n"
    OS-->>M: stdout
    M-->>T: "ShellResult { stdout: "unset\nexplicit-value\n" }"
    T->>T: assert_eq!(result.stdout, "unset\nexplicit-value\n")
Loading

Reviews (1): Last reviewed commit: "test(shell): fix test on non posix shell" | Re-trigger Greptile

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

Copy link
Copy Markdown
Contributor

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 updates a shell execution test in crates/tui/src/tools/shell/tests.rs to wrap the printf command inside sh -c. This ensures the command runs in a shell environment, which is necessary for evaluating the environment variables correctly. There are no review comments, and I have no additional feedback to provide.

@Hmbown

Hmbown commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Thanks @hongqitai — harvested this shell test portability fix into main for v0.8.49 in d88b2c3. Closing this PR as integrated and credited in the changelog.

@Hmbown Hmbown closed this Jun 1, 2026
@hongqitai hongqitai deleted the test/fix-test-on-non-posix branch June 1, 2026 09:58
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.

2 participants