fix(mac): resolve duplicate symbols blocking darwin/linux builds + add Mac tests. Remove duplicate launchProcessGuard from guard_unix.go (kept richer health_unix.go shell-loop version using pgrep -f). Remove duplicate applyDetachedStart from exec_stub.go (kept platform_unix.go impl that clears stdio). Add silent_stub.go for !windows so silentCombinedOutput/silentOutput/silentRun compile on Mac. All 4 targets now build: darwin/arm64, darwin/amd64, linux/amd64, linux/arm64. New tests: workerProcessRunning, applyDetachedStart stdio clearing, PersistenceKeyName, HostOSVersion, LaunchAgent plist content, silent stub exec wrappers.
This commit is contained in:
48
agent/deploy/guard_unix_test.go
Normal file
48
agent/deploy/guard_unix_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
//go:build !windows
|
||||
|
||||
package deploy
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestWorkerProcessRunningNotFound checks the negative path (process absent).
|
||||
// On any CI/local box the test binary name is extremely unlikely to exist as a
|
||||
// running process by that exact name, so pgrep should return non-zero.
|
||||
func TestWorkerProcessRunningNotFound(t *testing.T) {
|
||||
// Use a name that will never be a running process.
|
||||
if workerProcessRunning("__aetherforge_nonexistent_9z__") {
|
||||
t.Error("should return false for a process that does not exist")
|
||||
}
|
||||
}
|
||||
|
||||
// TestWorkerProcessRunningCurrent verifies detection works when a process IS
|
||||
// running. We use "go" (the go toolchain itself) since it's always present
|
||||
// during a test run inside go test.
|
||||
func TestWorkerProcessRunningCurrent(t *testing.T) {
|
||||
// pgrep -x matches exact process names; "go" may or may not match
|
||||
// depending on how go test spawns subprocesses. Use the test binary itself.
|
||||
name := "go"
|
||||
out, err := exec.Command("pgrep", "-x", name).Output()
|
||||
if err != nil || len(out) == 0 {
|
||||
t.Skipf("pgrep -x go found nothing; skip live-process check (pgrep not in PATH?)")
|
||||
}
|
||||
// If pgrep found it, our function must also find it.
|
||||
if !workerProcessRunning(name) {
|
||||
t.Errorf("workerProcessRunning(%q) should be true when pgrep finds it", name)
|
||||
}
|
||||
}
|
||||
|
||||
// TestWorkerProcessRunningStripsExeSuffix ensures that Windows-style ".exe"
|
||||
// suffixes in process names are stripped before the pgrep call so the same
|
||||
// config name can be used on both platforms.
|
||||
func TestWorkerProcessRunningStripsExeSuffix(t *testing.T) {
|
||||
// Process "crypto-miner-agent.exe" → pgrep -x "crypto-miner-agent"
|
||||
// We can't guarantee it's running, but we can confirm it doesn't panic
|
||||
// and returns a bool.
|
||||
result := workerProcessRunning("__nonexistent__.exe")
|
||||
if result {
|
||||
t.Error("should not find __nonexistent__.exe as a running process")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user