Fixing unit tests on windows (#813)
* Add Windows stub for orphan cleanup * Fix account switch tests on Windows * Make query session events test portable * Disable beads daemon in query session events test * Add Windows bd stubs for sling tests * Make expandOutputPath test OS-agnostic * Make role_agents test Windows-friendly * Make config path tests OS-agnostic * Make HealthCheckStateFile test OS-agnostic * Skip orphan process check on Windows * Normalize sparse checkout detail paths * Make dog path tests OS-agnostic * Fix bare repo refspec config on Windows * Add Windows process detection for locks * Add Windows CI workflow * Make mail path tests OS-agnostic * Skip plugin file mode test on Windows * Skip tmux-dependent polecat tests on Windows * Normalize polecat paths and AGENTS.md content * Make beads init failure test Windows-friendly * Skip rig agent bead init test on Windows * Make XDG path tests OS-agnostic * Make exec tests portable on Windows * Adjust atomic write tests for Windows * Make wisp tests Windows-friendly * Make workspace find tests OS-agnostic * Fix Windows rig add integration test * Make sling var logging Windows-friendly * Fix sling attached molecule update ordering --------- Co-authored-by: Johann Dirry <johann.dirry@microsea.at>
This commit is contained in:
@@ -16,7 +16,6 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -193,23 +192,6 @@ func (l *Lock) write(sessionID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// processExists checks if a process with the given PID exists and is alive.
|
||||
func processExists(pid int) bool {
|
||||
if pid <= 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
// On Unix, sending signal 0 checks if process exists without affecting it
|
||||
process, err := os.FindProcess(pid)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// Try to send signal 0 - this will fail if process doesn't exist
|
||||
err = process.Signal(syscall.Signal(0))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// FindAllLocks scans a directory tree for agent.lock files.
|
||||
// Returns a map of worker directory -> LockInfo.
|
||||
func FindAllLocks(root string) (map[string]*LockInfo, error) {
|
||||
|
||||
25
internal/lock/process_unix.go
Normal file
25
internal/lock/process_unix.go
Normal file
@@ -0,0 +1,25 @@
|
||||
//go:build !windows
|
||||
|
||||
package lock
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// processExists checks if a process with the given PID exists and is alive.
|
||||
func processExists(pid int) bool {
|
||||
if pid <= 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
// On Unix, sending signal 0 checks if process exists without affecting it.
|
||||
process, err := os.FindProcess(pid)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// Try to send signal 0 - this will fail if process doesn't exist.
|
||||
err = process.Signal(syscall.Signal(0))
|
||||
return err == nil
|
||||
}
|
||||
22
internal/lock/process_windows.go
Normal file
22
internal/lock/process_windows.go
Normal file
@@ -0,0 +1,22 @@
|
||||
//go:build windows
|
||||
|
||||
package lock
|
||||
|
||||
import "golang.org/x/sys/windows"
|
||||
|
||||
// processExists checks if a process with the given PID exists and is alive.
|
||||
func processExists(pid int) bool {
|
||||
if pid <= 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
handle, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
|
||||
if err != nil {
|
||||
if err == windows.ERROR_ACCESS_DENIED {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
_ = windows.CloseHandle(handle)
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user