xworkmate-bridge/internal/desktop/input_test.go
Haitao Pan 07d69b50f7 Merge branch 'codex/fix-openclaw-probe-terminal' into release/v1.1.4
# Conflicts:
#	internal/acp/openclaw_async_tasks.go
2026-06-03 16:59:53 +08:00

47 lines
1.0 KiB
Go

package desktop
import (
"strings"
"testing"
)
func TestDesktopCommandEnvPreservesProcessEnvironmentAndOverridesDisplay(t *testing.T) {
t.Setenv("PATH", "/usr/local/bin:/usr/bin")
t.Setenv("HOME", "/home/ubuntu")
t.Setenv("DISPLAY", ":old")
env := desktopCommandEnv(":0.0")
if !envContains(env, "PATH=/usr/local/bin:/usr/bin") {
t.Fatalf("expected PATH to be preserved, got %#v", env)
}
if !envContains(env, "HOME=/home/ubuntu") {
t.Fatalf("expected HOME to be preserved, got %#v", env)
}
if !envContains(env, "DISPLAY=:0.0") {
t.Fatalf("expected DISPLAY override, got %#v", env)
}
if countEnvPrefix(env, "DISPLAY=") != 1 {
t.Fatalf("expected exactly one DISPLAY entry, got %#v", env)
}
}
func envContains(env []string, expected string) bool {
for _, item := range env {
if item == expected {
return true
}
}
return false
}
func countEnvPrefix(env []string, prefix string) int {
count := 0
for _, item := range env {
if strings.HasPrefix(item, prefix) {
count++
}
}
return count
}