P7.1: move Windows-only runner tests into runner_windows_test.go
Tests touching SysProcAttr.HideWindow/CmdLine and windowsShellCommandLine are guarded by //go:build windows; runner_test.go drops the winproc import. Linux cross-compile and Windows test run both clean. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -114,7 +114,7 @@ These land together because both edit `domain/job.go` and `storage/store.go`.
|
||||
- [x] P6.3 — Re-measure startup → PERFORMANCE.md
|
||||
|
||||
### Phase 7 — Roadmap follow-ups
|
||||
- [ ] P7.1 — Linux test build fix (build-tagged Windows tests)
|
||||
- [x] P7.1 — Linux test build fix (build-tagged Windows tests)
|
||||
|
||||
### Phase 8 — Docs + version
|
||||
- [ ] P8.1 — `docs/DEVELOPMENT.md`
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"time"
|
||||
|
||||
"gitea.mixdep.ru/mix/gosentry/src/domain"
|
||||
"gitea.mixdep.ru/mix/gosentry/src/platform/winproc"
|
||||
)
|
||||
|
||||
func echoCommand(message string) string {
|
||||
@@ -322,60 +321,3 @@ func TestRunJobStartOnlyReportsStartFailure(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDirectCommandDoesNotHideWindow(t *testing.T) {
|
||||
if runtime.GOOS != "windows" {
|
||||
t.Skip("Windows window visibility only")
|
||||
}
|
||||
|
||||
invocation := jobInvocation(context.Background(), domain.Job{
|
||||
Command: `C:\Windows\System32\cmd.exe`,
|
||||
Arguments: "/C\necho visible direct process",
|
||||
})
|
||||
if invocation.hideWindow {
|
||||
t.Fatal("direct command should not request hidden startup window")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShellCommandHidesWindow(t *testing.T) {
|
||||
if runtime.GOOS != "windows" {
|
||||
t.Skip("Windows window visibility only")
|
||||
}
|
||||
|
||||
invocation := jobInvocation(context.Background(), domain.Job{Command: "echo hidden shell process"})
|
||||
if !invocation.hideWindow {
|
||||
t.Fatal("shell command should request hidden startup window")
|
||||
}
|
||||
winproc.ConfigureHiddenWindow(invocation.command)
|
||||
if invocation.command.SysProcAttr == nil || !invocation.command.SysProcAttr.HideWindow {
|
||||
t.Fatal("expected shell command to be hidden")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShellCommandUsesWindowsSafeQuoting(t *testing.T) {
|
||||
if runtime.GOOS != "windows" {
|
||||
t.Skip("Windows cmd.exe quoting only")
|
||||
}
|
||||
|
||||
command := shellCommand(context.Background(), `"C:\Program Files\FreeFileSync\FreeFileSync.exe" "D:\Local\Programs\FreeFileSync\Jobs\Auto.ffs_batch"`)
|
||||
winproc.ConfigureHiddenWindow(command)
|
||||
|
||||
want := `cmd.exe /S /C ""C:\Program Files\FreeFileSync\FreeFileSync.exe" "D:\Local\Programs\FreeFileSync\Jobs\Auto.ffs_batch""`
|
||||
if command.SysProcAttr == nil {
|
||||
t.Fatal("expected SysProcAttr")
|
||||
}
|
||||
if command.SysProcAttr.CmdLine != want {
|
||||
t.Fatalf("expected command line %q, got %q", want, command.SysProcAttr.CmdLine)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWindowsShellCommandLineQuotesUnquotedProgramPath(t *testing.T) {
|
||||
if runtime.GOOS != "windows" {
|
||||
t.Skip("Windows cmd.exe quoting only")
|
||||
}
|
||||
|
||||
got := windowsShellCommandLine(`C:\Program Files\Joplin\Joplin.exe --profile "D:\Joplin Profile"`)
|
||||
want := `cmd.exe /S /C ""C:\Program Files\Joplin\Joplin.exe" --profile "D:\Joplin Profile""`
|
||||
if got != want {
|
||||
t.Fatalf("expected command line %q, got %q", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
//go:build windows
|
||||
|
||||
package runner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"gitea.mixdep.ru/mix/gosentry/src/domain"
|
||||
"gitea.mixdep.ru/mix/gosentry/src/platform/winproc"
|
||||
)
|
||||
|
||||
func TestDirectCommandDoesNotHideWindow(t *testing.T) {
|
||||
invocation := jobInvocation(context.Background(), domain.Job{
|
||||
Command: `C:\Windows\System32\cmd.exe`,
|
||||
Arguments: "/C\necho visible direct process",
|
||||
})
|
||||
if invocation.hideWindow {
|
||||
t.Fatal("direct command should not request hidden startup window")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShellCommandHidesWindow(t *testing.T) {
|
||||
invocation := jobInvocation(context.Background(), domain.Job{Command: "echo hidden shell process"})
|
||||
if !invocation.hideWindow {
|
||||
t.Fatal("shell command should request hidden startup window")
|
||||
}
|
||||
winproc.ConfigureHiddenWindow(invocation.command)
|
||||
if invocation.command.SysProcAttr == nil || !invocation.command.SysProcAttr.HideWindow {
|
||||
t.Fatal("expected shell command to be hidden")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShellCommandUsesWindowsSafeQuoting(t *testing.T) {
|
||||
command := shellCommand(context.Background(), `"C:\Program Files\FreeFileSync\FreeFileSync.exe" "D:\Local\Programs\FreeFileSync\Jobs\Auto.ffs_batch"`)
|
||||
winproc.ConfigureHiddenWindow(command)
|
||||
|
||||
want := `cmd.exe /S /C ""C:\Program Files\FreeFileSync\FreeFileSync.exe" "D:\Local\Programs\FreeFileSync\Jobs\Auto.ffs_batch""`
|
||||
if command.SysProcAttr == nil {
|
||||
t.Fatal("expected SysProcAttr")
|
||||
}
|
||||
if command.SysProcAttr.CmdLine != want {
|
||||
t.Fatalf("expected command line %q, got %q", want, command.SysProcAttr.CmdLine)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWindowsShellCommandLineQuotesUnquotedProgramPath(t *testing.T) {
|
||||
got := windowsShellCommandLine(`C:\Program Files\Joplin\Joplin.exe --profile "D:\Joplin Profile"`)
|
||||
want := `cmd.exe /S /C ""C:\Program Files\Joplin\Joplin.exe" --profile "D:\Joplin Profile""`
|
||||
if got != want {
|
||||
t.Fatalf("expected command line %q, got %q", want, got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user