-
-
Notifications
You must be signed in to change notification settings - Fork 9
refactor: Update BuildCmdWrapper to use args splatting and add unit tests #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -331,18 +331,19 @@ private static void EnsureCmdWrappers(string userHome, string psPath) | |
| File.WriteAllText(yoloCmd, BuildCmdWrapper("copilot_yolo", psPath)); | ||
| } | ||
|
|
||
| private static string BuildCmdWrapper(string functionName, string psPath) | ||
| internal static string BuildCmdWrapper(string functionName, string psPath) | ||
| { | ||
| // Prefer pwsh, fall back to powershell. | ||
| // Keep wrapper simple and rely on PowerShell script for all logic. | ||
| // Pass arguments after `--` and forward via PowerShell `@args` so quoted | ||
| // values (for example --prompt "What is 1 + 1 ?") stay as a single arg. | ||
| return "@echo off\r\n" + | ||
| "setlocal\r\n" + | ||
| "set \"SCRIPT=%USERPROFILE%\\.copilot_here.ps1\"\r\n" + | ||
| "where pwsh >nul 2>nul\r\n" + | ||
| "if %ERRORLEVEL%==0 (\r\n" + | ||
| $" pwsh -NoProfile -ExecutionPolicy Bypass -Command \". '%USERPROFILE%\\.copilot_here.ps1'; {functionName} %*\"\r\n" + | ||
| $" pwsh -NoProfile -ExecutionPolicy Bypass -Command \"& {{ . '%USERPROFILE%\\.copilot_here.ps1'; {functionName} @args }}\" -- %*\r\n" + | ||
| ") else (\r\n" + | ||
| $" powershell -NoProfile -ExecutionPolicy Bypass -Command \". '%USERPROFILE%\\.copilot_here.ps1'; {functionName} %*\"\r\n" + | ||
| $" powershell -NoProfile -ExecutionPolicy Bypass -Command \"& {{ . '%USERPROFILE%\\.copilot_here.ps1'; {functionName} @args }}\" -- %*\r\n" + | ||
|
Comment on lines
+344
to
+346
|
||
| ")\r\n" + | ||
| "endlocal\r\n"; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using CopilotHere.Infrastructure; | ||
| using TUnit.Core; | ||
|
|
||
| namespace CopilotHere.Tests; | ||
|
|
||
| public class ShellIntegrationTests | ||
| { | ||
| [Test] | ||
| public async Task BuildCmdWrapper_UsesArgsSplatForForwarding() | ||
| { | ||
| // Act | ||
| var wrapper = ShellIntegration.BuildCmdWrapper("copilot_yolo", "ignored"); | ||
|
|
||
| // Assert | ||
| await Assert.That(wrapper).Contains("copilot_yolo @args"); | ||
| await Assert.That(wrapper).Contains(" -- %*"); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task BuildCmdWrapper_UsesArgsSplatForBothPwshAndWindowsPowerShell() | ||
| { | ||
| // Act | ||
| var wrapper = ShellIntegration.BuildCmdWrapper("copilot_here", "ignored"); | ||
|
|
||
| // Assert | ||
| var occurrences = wrapper.Split("copilot_here @args").Length - 1; | ||
| await Assert.That(occurrences).IsEqualTo(2); | ||
| } | ||
GordonBeeming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BuildCmdWrappertakespsPathbut never uses it (the wrapper still hardcodes%USERPROFILE%\.copilot_here.ps1). Either remove the unused parameter (and adjust call sites/tests) or usepsPathto build the script path in the generated CMD so the wrapper reflects the actual installed location.