Fix Windows-incompatible tests and hook execution - #53
Merged
Conversation
Make the test suite pass on Windows: - Run hook scripts through a POSIX shell on Windows, where shebang scripts cannot be executed directly, and treat regular hook files as executable since Windows has no exec permission bits - Use Windows-compatible commands in tests (cmd /c instead of ls, mkdir, touch, printf) and replace /etc/passwd with a temp file - Compute expected keygen paths with filepath.Join so expectations match output on any platform Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR aims to make hook execution and the Go test suite behave correctly on Windows, while preserving Unix behavior—primarily by adjusting hook executability detection/dispatch and rewriting several tests to avoid Unix-only dependencies.
Changes:
- Treat hook files as runnable on Windows (no POSIX exec bits) and run shebang hooks via
shwhen available. - Refactor multiple tests to use platform-neutral commands and filesystem setup (
cmd /c ...on Windows;os.MkdirAll/os.WriteFileinstead of shelling out). - Normalize hook test script paths (e.g.,
filepath.ToSlash) and expected path construction (filepath.Join) to reduce OS-specific assumptions.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| internal/utils/utils.go | Updates hook executability rules on Windows and routes hook execution through sh when present. |
| internal/utils/utils_test.go | Reworks tests to be platform-neutral and updates hook script generation for Windows/path handling. |
| internal/publishers/publishers_test.go | Makes CLI fallback token resolution test work on Windows by avoiding POSIX printf. |
| internal/actions/actions_test.go | Uses filepath.Join for expected keygen output paths to match OS-specific separators. |
Suppressed comments (2)
internal/utils/utils_test.go:481
- These shell snippets redirect to the log file without quoting it. If the path contains spaces, the hook will fail when run via sh (common on Windows). Quote the redirection target.
writeGlobal := "#!/bin/sh\necho G $SKM_EVENT $SKM_ALIAS >> " + logSlash + "\n"
writePerKey := "#!/bin/sh\necho K $SKM_EVENT $SKM_ALIAS >> " + logSlash + "\n"
internal/utils/utils_test.go:568
- This hook body redirects to the log file without quoting the path, which can fail when the temp/store path contains spaces. Quote the redirection target so the test is robust across platforms.
body := "#!/bin/sh\necho \"$SKM_REMOTE_HOST $SKM_REMOTE_PORT\" >> " + filepath.ToSlash(log) + "\n"
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Include expected/actual values in the ParsePath assertion failure. - Skip the symlink-resolution check on Windows when symlink creation fails. - Quote the log file path in generated hook script bodies so paths containing spaces work under sh.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The test suite previously failed on Windows, and the pluggable hook feature silently never fired there either. This change makes the whole suite pass on Windows while keeping Unix behavior intact.
Approach
sh) on Windows, where shebang scripts cannot be executed directly by the OS. On Unix, hooks execute directly as before.isExecutableFiletreats any regular file as a hook on Windows, since Windows has no POSIX executable permission bits. This is what made hooks (and several hook tests) silently no-op before.ls,touch,mkdir,printf,/etc/passwd) were rewritten to be platform-neutral:TestExecuteusescmd /c exit 0/1on Windows,true/falseon Unix.TestParsePathsymlinks a temp file instead of/etc/passwd.os.MkdirAll/os.WriteFileinstead of shelling out.filepath.ToSlash) so they work when run throughsh.TestBuildKeygenArgs_DefaultsAndShapecomputes expected paths withfilepath.Join.TestResolveTokenusescmd /c echoon Windows instead of theprintfshell builtin.Note for reviewers
shonPATH(e.g. Git Bash / MSYS / WSL). If none is present, hook scripts fall back to direct execution and report their failure via the existing error path.go build ./...,go vet ./..., andgo test ./...(all packages pass), plus anskm.exe --versionsmoke test.