Skip to content

Refactor shell plugin, add tests & fix bugs#4554

Open
DavidGBrett wants to merge 9 commits into
devfrom
clean-up-shell-plugin
Open

Refactor shell plugin, add tests & fix bugs#4554
DavidGBrett wants to merge 9 commits into
devfrom
clean-up-shell-plugin

Conversation

@DavidGBrett

@DavidGBrett DavidGBrett commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Follow up PR from #4545

Finish the job of refactoring the shell plugin and in doing that make it testable and then add tests for it.
Also did some bug fixes in the process.

Bug fixes

  • RunCommand — rewrote method to use Arguments instead of
    ArgumentList so OS correctly splits args by spaces, add support for quoted executable
    paths with spaces, and improve whitespace handling in args.
  • Command history - stores the original input (e.g. echo %USERPROFILE%) instead of expanded environment variables, matching what the user actually typed.
  • CMD close-after-press - removed spurious /c after pause > nul in the pause command. pause ignores arguments, so it had no effect, but cleaning it up prevents confusion.

Summary by cubic

Refactored the shell plugin to centralize process creation and add per‑shell helpers, fixing argument parsing, elevation, and Windows Terminal quirks. Improves reliability across CMD, PowerShell, pwsh, Windows Terminal, and RunCommand; history now records exactly what you typed.

Summary of changes

  • Changed: Centralized setup in CreateProcessStartInfo (trim, env var expansion, working dir, UseShellExecute = true). Simplified admin elevation (Verb = "runas" if either flag is true). Windows Terminal escaping and argument handling are more robust. PowerShell now adds -NoExit when leaving open and omits -Command in that case; pwsh always uses -Command and adds -NoExit when leaving open. CMD close-after-press uses pause > nul (no trailing /c). RunCommand now uses Arguments for the tail, handles quoted executable paths, trims leading whitespace, and falls back to the whole command when the executable isn’t found.
  • Added: Private per-shell helpers (ConfigureCmdProcessStartInfo, ConfigurePowershellProcessStartInfo, ConfigurePwshProcessStartInfo, ConfigureRunCommandStartInfo). Unified close prompt parameter (closePrompt).
  • Removed: Duplicate UseShellExecute assignment in RunCommand. Public visibility of shell-specific config methods (now private).
  • Memory: No meaningful impact.
  • Security: No new risks; command history stores the original input (not expanded).
  • Unit tests: Switched tests to CreateProcessStartInfo to validate the full pipeline across shells and Windows Terminal. Added coverage for leave-open/close, -NoExit/-Command behavior, close prompt, quoting and quoted-paths, env var expansion, working dir, PATH lookup, admin verb, and multi-word arguments in RunCommand; updated the CMD pause assertion.

Release Note
Commands now launch more reliably across shells; multi-word arguments and quoted paths work in RunCommand, and your history shows exactly what you typed.

Written for commit 049ffe5. Summary will update on new commits.

Review in cubic

@github-actions github-actions Bot added this to the 2.2.0 milestone Jun 30, 2026

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread Plugins/Flow.Launcher.Plugin.Shell/Main.cs
@DavidGBrett DavidGBrett marked this pull request as draft June 30, 2026 14:57
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Main.cs now builds shell ProcessStartInfo through a shared helper and explicit shell options. ShellPluginTest.cs was rewritten to assert the resulting CMD, PowerShell, Pwsh, and RunCommand start info, plus shared elevation, working directory, shell execution, and expansion behavior.

Changes

Shell Plugin Refactor and Tests

Layer / File(s) Summary
Process start helper extraction
Plugins/Flow.Launcher.Plugin.Shell/Main.cs
PrepareProcessStartInfo now computes runAsAdmin and closePrompt, delegates construction to CreateProcessStartInfo, and that helper trims and expands the command, sets Verb, WorkingDirectory, and UseShellExecute, then dispatches to shell-specific configuration.
Shell-specific start info configuration
Plugins/Flow.Launcher.Plugin.Shell/Main.cs
ConfigureCmdProcessStartInfo, ConfigurePowershellProcessStartInfo, ConfigurePwshProcessStartInfo, and ConfigureRunCommandStartInfo now receive explicit flags for close-after-press, close prompt text, and Windows Terminal, and build Arguments or ArgumentList accordingly.
Test helper setup
Flow.Launcher.Test/Plugins/ShellPluginTest.cs
ShellPluginTest.cs adds a shared ClosePrompt constant and a Create(...) helper that calls Main.CreateProcessStartInfo with the shell and start-info options used by the suite.
Shell-specific process start assertions
Flow.Launcher.Test/Plugins/ShellPluginTest.cs
The test suite now asserts CMD, PowerShell, Pwsh, and RunCommand ProcessStartInfo values, including shell switches, Windows Terminal behavior, close-prompt handling, quoted input, and command mapping.
Shared start info assertions
Flow.Launcher.Test/Plugins/ShellPluginTest.cs
Shared parameterized tests validate Verb for elevation, WorkingDirectory, UseShellExecute, and environment variable expansion differences across shell modes.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested reviewers: VictoriousRaptor

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: shell plugin refactor, added tests, and bug fixes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The description matches the refactor, bug fixes, and expanded shell plugin tests shown in the changeset.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch clean-up-shell-plugin

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
Flow.Launcher.Test/Plugins/ShellPluginTest.cs (1)

133-165: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Tighten the PowerShell branch assertions.

These tests only verify marker tokens (wt.exe, "powershell", -NoExit, missing -Command). A regression that drops the command payload or the WT-specific escaped \; terminator in Main.ConfigurePowershellProcessStartInfo(...) would still pass. Please assert the full ArgumentList for the WT and leave-open paths.

Example assertions
 [Test]
 public void Powershell_WT_UsesWindowsTerminal()
 {
     var info = Create(
         shell: Shell.Powershell,
         useWindowsTerminal: true);

     Assert.That(info.FileName, Is.EqualTo("wt.exe"));
-    Assert.That(info.ArgumentList, Does.Contain("powershell"));
+    Assert.That(info.ArgumentList, Is.EqualTo(["powershell", "-Command", "test\\;"]));
 }
 ...
 [Test]
 public void Powershell_LeaveShellOpen_OmitsCommandSwitch()
 {
     var info = Create(
         shell: Shell.Powershell,
         leaveShellOpen: true);

-    Assert.That(info.ArgumentList, Does.Not.Contain("-Command"));
+    Assert.That(info.ArgumentList, Is.EqualTo(["-NoExit", "test"]));
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Flow.Launcher.Test/Plugins/ShellPluginTest.cs` around lines 133 - 165, The
PowerShell tests in ShellPluginTest are too loose and can miss regressions in
Main.ConfigurePowershellProcessStartInfo(...). Tighten the assertions in
Powershell_WT_UsesWindowsTerminal and
Powershell_LeaveShellOpen_OmitsCommandSwitch to verify the full ArgumentList,
not just marker tokens, including the command payload and the WT-specific
escaped terminator sequence. Use the existing Create helper and Shell.Powershell
path to assert the exact argument shape for both the Windows Terminal and
leave-shell-open cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Flow.Launcher.Test/Plugins/ShellPluginTest.cs`:
- Around line 69-77: The Cmd_CloseShellAfterPress_AppendsPause test only checks
a substring of the synthesized Arguments, so malformed trailing tokens could
still slip through. Update this assertion in
Cmd_CloseShellAfterPress_AppendsPause to verify the full command string produced
by Create/ConfigureCmdProcessStartInfo for Shell.Cmd when closeShellAfterPress
is true, including the exact pause sequence and any surrounding tokens.

In `@Plugins/Flow.Launcher.Plugin.Shell/Main.cs`:
- Around line 382-390: The Shell command parsing in Main should preserve the raw
tail of the command instead of adding it as a single argv item. Update the logic
in the command-splitting block around ExistInPath so the extracted arguments are
assigned through info.Arguments rather than info.ArgumentList.Add(arguments),
and keep the executable name in info.FileName. Add a test covering a known
executable invoked with multiple arguments to verify the tail is passed through
unchanged.

---

Nitpick comments:
In `@Flow.Launcher.Test/Plugins/ShellPluginTest.cs`:
- Around line 133-165: The PowerShell tests in ShellPluginTest are too loose and
can miss regressions in Main.ConfigurePowershellProcessStartInfo(...). Tighten
the assertions in Powershell_WT_UsesWindowsTerminal and
Powershell_LeaveShellOpen_OmitsCommandSwitch to verify the full ArgumentList,
not just marker tokens, including the command payload and the WT-specific
escaped terminator sequence. Use the existing Create helper and Shell.Powershell
path to assert the exact argument shape for both the Windows Terminal and
leave-shell-open cases.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 24730a6a-8fc7-4f77-ad81-2b86239f72b4

📥 Commits

Reviewing files that changed from the base of the PR and between fe36686 and f1a863a.

📒 Files selected for processing (2)
  • Flow.Launcher.Test/Plugins/ShellPluginTest.cs
  • Plugins/Flow.Launcher.Plugin.Shell/Main.cs

Comment thread Flow.Launcher.Test/Plugins/ShellPluginTest.cs
Comment thread Plugins/Flow.Launcher.Plugin.Shell/Main.cs Outdated
@DavidGBrett DavidGBrett added bug Something isn't working Code Refactor labels Jun 30, 2026
@DavidGBrett DavidGBrett force-pushed the clean-up-shell-plugin branch from f1a863a to 3271072 Compare June 30, 2026 15:34
@DavidGBrett DavidGBrett marked this pull request as ready for review June 30, 2026 17:55

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread Flow.Launcher.Test/Plugins/ShellPluginTest.cs Outdated
@DavidGBrett DavidGBrett marked this pull request as draft June 30, 2026 18:01
@DavidGBrett DavidGBrett marked this pull request as ready for review June 30, 2026 18:10
@DavidGBrett DavidGBrett changed the title Refactor shell plugin & add tests Refactor shell plugin, add tests & fix small bugs Jun 30, 2026

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread Plugins/Flow.Launcher.Plugin.Shell/Main.cs Outdated
@DavidGBrett DavidGBrett marked this pull request as draft June 30, 2026 18:24
@DavidGBrett DavidGBrett force-pushed the clean-up-shell-plugin branch from e8c679d to 4344cdc Compare July 1, 2026 16:34
This is a clearer name which is more important now that its also a param
Logically equivalent as per De Morgan's Laws

This also makes the intent clearer - we use "runas" if either runAsAdministrator or _settings.RunAsAdministrator is true
…pecific methods so full pipeline is tested

The shell specific methods such as ConfigureCmdProcessStartInfo are now private to prevent them from being tested instead of CreateProcessStartInfo
Existing two tests are preserved but renamed and rewritten slightly
…plugin

The trailing /c after pause > nul had no purpose as pause ignores
arguments. Adjusted the test to match.
…path handling

- Uses Arguments instead of ArgumentList so that OS parser can correctly split the args by spaces.
- Quoted executable paths with spaces are now parsed correctly.
- Arguments are now always trimmed to catch extra whitespace
@DavidGBrett DavidGBrett force-pushed the clean-up-shell-plugin branch from 4344cdc to 049ffe5 Compare July 1, 2026 16:36
@DavidGBrett DavidGBrett marked this pull request as ready for review July 1, 2026 16:41
@DavidGBrett DavidGBrett changed the title Refactor shell plugin, add tests & fix small bugs Refactor shell plugin, add tests & fix bugs Jul 1, 2026

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 2 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Code Refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant