From 1240f8e49c7f0f910cee996bd868644063fce41f Mon Sep 17 00:00:00 2001 From: Wes McKinney Date: Sat, 31 Jan 2026 17:42:09 -0600 Subject: [PATCH 1/2] Fix hook test portability and robustness - Add -Encoding UTF8 to Set-Content in pwdCmd for Windows PS 5.1 - Use exact path comparison on Unix, case-insensitive only on Windows - Add t.Cleanup safety net for logger restoration in log tests - Fix stale shellEscape doc comment (now single quotes on all platforms) Co-Authored-By: Claude Opus 4.5 --- internal/daemon/hooks.go | 4 ++-- internal/daemon/hooks_test.go | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/daemon/hooks.go b/internal/daemon/hooks.go index e3004f4..fce5aea 100644 --- a/internal/daemon/hooks.go +++ b/internal/daemon/hooks.go @@ -170,8 +170,8 @@ func interpolate(cmd string, event Event) string { } // shellEscape quotes a value for safe interpolation into a shell command. -// On Unix, wraps in single quotes with embedded single quotes escaped. -// On Windows, wraps in double quotes with embedded double quotes escaped. +// Wraps in single quotes on all platforms, with embedded single quotes escaped. +// On Windows (PowerShell), '' escapes a literal '. On Unix, uses '"'"'. func shellEscape(s string) string { if runtime.GOOS == "windows" { // PowerShell single-quoted strings: only escape is '' for literal '. diff --git a/internal/daemon/hooks_test.go b/internal/daemon/hooks_test.go index fd0d374..28f39e3 100644 --- a/internal/daemon/hooks_test.go +++ b/internal/daemon/hooks_test.go @@ -40,7 +40,7 @@ func touchCmd(path string) string { // pwdCmd returns a platform-appropriate shell command to write the cwd to a file. func pwdCmd(path string) string { if runtime.GOOS == "windows" { - return "(Get-Location).Path | Set-Content -NoNewline '" + filepath.ToSlash(path) + "'" + return "(Get-Location).Path | Set-Content -NoNewline -Encoding UTF8 '" + filepath.ToSlash(path) + "'" } return "pwd > " + path } @@ -407,7 +407,11 @@ func TestHookRunnerWorkingDirectory(t *testing.T) { want = w } } - if !strings.EqualFold(got, want) { + equal := got == want + if runtime.GOOS == "windows" { + equal = strings.EqualFold(got, want) + } + if !equal { t.Errorf("hook ran in %q, want %q", got, want) } return @@ -674,6 +678,7 @@ func TestHandleEventLogsWhenHooksFired(t *testing.T) { var buf bytes.Buffer prevOut := log.Writer() log.SetOutput(&buf) + t.Cleanup(func() { log.SetOutput(prevOut) }) cfg := &config.Config{ Hooks: []config.HookConfig{ @@ -710,6 +715,7 @@ func TestHandleEventNoLogWhenNoHooksMatch(t *testing.T) { var buf bytes.Buffer prevOut := log.Writer() log.SetOutput(&buf) + t.Cleanup(func() { log.SetOutput(prevOut) }) cfg := &config.Config{ Hooks: []config.HookConfig{ From 1cbeb84b5943bce318c96215e7fc02d549cac764 Mon Sep 17 00:00:00 2001 From: Wes McKinney Date: Sat, 31 Jan 2026 17:47:14 -0600 Subject: [PATCH 2/2] Fix UTF-8 BOM in pwdCmd on Windows PowerShell 5.1 Set-Content -Encoding UTF8 writes a BOM on PS 5.1. Use [IO.File]::WriteAllText which writes UTF-8 without BOM. Co-Authored-By: Claude Opus 4.5 --- internal/daemon/hooks_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/daemon/hooks_test.go b/internal/daemon/hooks_test.go index 28f39e3..5a67208 100644 --- a/internal/daemon/hooks_test.go +++ b/internal/daemon/hooks_test.go @@ -40,7 +40,7 @@ func touchCmd(path string) string { // pwdCmd returns a platform-appropriate shell command to write the cwd to a file. func pwdCmd(path string) string { if runtime.GOOS == "windows" { - return "(Get-Location).Path | Set-Content -NoNewline -Encoding UTF8 '" + filepath.ToSlash(path) + "'" + return "[IO.File]::WriteAllText('" + filepath.ToSlash(path) + "', (Get-Location).Path)" } return "pwd > " + path }