Skip to content

Conversation

@dkmnx
Copy link
Owner

@dkmnx dkmnx commented Feb 6, 2026

Summary

This PR fixes Windows compatibility issues related to file handling and script execution in the audit and update commands.

Changes

File Lock Fixes

  • Close audit loggers with defer to prevent file locks on Windows (cmd/audit.go)
  • Update audit.Logger.Close() to nil the file pointer after closing (internal/audit/audit.go)
  • Add missing defer logger.Close() calls in audit tests

Test Fixes

  • Fix wrapper script execution test to use PowerShell instead of cmd.exe on Windows (cmd/switch_test.go)
  • Update comment assertion to match PowerShell comment syntax (# instead of REM)
  • Skip permission tests on Windows where chmod behaves differently (cmd/audit_helpers_test.go)

Update Command Fixes

  • Use platform-specific temp file extensions (.ps1 on Windows, .sh on Unix) for install scripts (cmd/update.go)
  • Add better error wrapping for script execution failures
  • Add test coverage for platform-specific temp file extensions

Test Plan

  • All existing tests pass
  • New test for platform-specific temp file extensions
  • Tests run correctly on both Windows and Unix platforms

Files Changed

  • cmd/audit.go - Add defer Close() calls
  • cmd/audit_helpers_test.go - Skip permission test on Windows
  • cmd/audit_test.go - Add defer Close() calls
  • cmd/switch_test.go - Fix PowerShell execution
  • cmd/update.go - Platform-specific temp file extensions
  • cmd/update_test.go - Test temp file extensions
  • internal/audit/audit.go - Improve Close() method

dkmnx added 4 commits February 5, 2026 09:50
- Use .ps1 extension on Windows for PowerShell -File flag compatibility
- Use .sh extension on Unix-like systems
- Add error context in runInstallScript for better diagnostics
- Add TestDownloadToTempFileExtension to verify platform-appropriate extensions

Fixes silent failure of 'kairo update' on Windows where PowerShell
-File flag could not execute files without .ps1 extension.
- Use 'powershell -ExecutionPolicy Bypass -File' instead of 'cmd /c'
- PowerShell scripts (.ps1) cannot be executed by cmd.exe directly
- Fix comment check from 'REM' to '#' for PowerShell syntax

Fixes TestWrapperScriptExecution failure on Windows where
wrapper script was opening in Notepad instead of executing.
- Add defer logger.Close() to auditCmd, auditListCmd, auditExportCmd
- Set logger.f = nil after closing to prevent reuse of closed file
- Add defer logger.Close() to audit tests
- Skip permission test on Windows (chmod behaves differently)

Fixes file lock errors in audit tests on Windows where audit.log
cannot be deleted after test execution because file was left open.
- ci: update Go version to 1.25.7 in all workflows (fixes GO-2026-4337)
- pre-commit: use cmd /c for Windows-native hook execution
- task: add pre-commit and pre-commit-install tasks to Taskfile.yml
@dkmnx dkmnx merged commit 97eb3e5 into main Feb 6, 2026
16 checks passed
@dkmnx dkmnx deleted the fix/update-windows-temp-extension branch February 6, 2026 06:24
dkmnx added a commit that referenced this pull request Feb 9, 2026
…sion

fix(windows): resolve file locks and script execution issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant