返回 DeepSeek-Reasonix
shell_ozone_test.go
根目录 / desktop / shell_ozone_test.go
1 //go:build !windows
2
3 package main
4
5 import (
6 "os"
7 "path/filepath"
8 "strings"
9 "testing"
10 "time"
11 )
12
13 func TestBootstrapShellChoosesOzonePlatformFromSession(t *testing.T) {
14 x11 := "--ozone-platform=x11"
15 cases := []struct {
16 name string
17 env []string
18 args []string
19 want []string
20 }{
21 {"wayland with xwayland defaults to x11", []string{"XDG_SESSION_TYPE=wayland", "WAYLAND_DISPLAY=wayland-0", "DISPLAY=:0"}, []string{"--flag"}, []string{x11, "--flag"}},
22 {"wayland display alone counts as wayland", []string{"WAYLAND_DISPLAY=wayland-0", "DISPLAY=:0"}, nil, []string{x11}},
23 {"pure wayland stays native", []string{"XDG_SESSION_TYPE=wayland", "WAYLAND_DISPLAY=wayland-0"}, []string{"--flag"}, []string{"--flag"}},
24 {"override wayland stays native", []string{"XDG_SESSION_TYPE=wayland", "DISPLAY=:0", "REASONIX_OZONE_PLATFORM=wayland"}, nil, nil},
25 {"override x11 forces x11", []string{"XDG_SESSION_TYPE=x11", "DISPLAY=:0", "REASONIX_OZONE_PLATFORM=x11"}, nil, []string{x11}},
26 {"override auto keeps the default", []string{"XDG_SESSION_TYPE=wayland", "DISPLAY=:0", "REASONIX_OZONE_PLATFORM=auto"}, nil, []string{x11}},
27 {"explicit flag wins", []string{"XDG_SESSION_TYPE=wayland", "DISPLAY=:0"}, []string{"--ozone-platform=wayland"}, []string{"--ozone-platform=wayland"}},
28 {"explicit hint wins", []string{"XDG_SESSION_TYPE=wayland", "DISPLAY=:0"}, []string{"--ozone-platform-hint=wayland"}, []string{"--ozone-platform-hint=wayland"}},
29 {"x11 session unchanged", []string{"XDG_SESSION_TYPE=x11", "DISPLAY=:0"}, []string{"--flag"}, []string{"--flag"}},
30 }
31 for _, tc := range cases {
32 t.Run(tc.name, func(t *testing.T) {
33 exe, shell := writeShellBootstrapFixture(t, "linux")
34 out := filepath.Join(t.TempDir(), "shell.out")
35 script := "#!/bin/sh\nprintf '%s\\n' \"$@\" > \"$REASONIX_TEST_SHELL_OUT.tmp\" && mv \"$REASONIX_TEST_SHELL_OUT.tmp\" \"$REASONIX_TEST_SHELL_OUT\"\n"
36 if err := os.MkdirAll(filepath.Dir(shell), 0o755); err != nil {
37 t.Fatal(err)
38 }
39 if err := os.WriteFile(shell, []byte(script), 0o755); err != nil {
40 t.Fatal(err)
41 }
42 env := append([]string{"PATH=" + os.Getenv("PATH"), "REASONIX_TEST_SHELL_OUT=" + out}, tc.env...)
43 if handled, code := bootstrapShell(exe, "linux", tc.args, env); !handled || code != 0 {
44 t.Fatalf("bootstrap handled=%v code=%d", handled, code)
45 }
46 deadline := time.Now().Add(10 * time.Second)
47 for {
48 raw, err := os.ReadFile(out)
49 if err == nil {
50 got := strings.Fields(string(raw))
51 if strings.Join(got, " ") != strings.Join(tc.want, " ") {
52 t.Fatalf("shell argv = %q, want %q", got, tc.want)
53 }
54 return
55 }
56 if time.Now().After(deadline) {
57 t.Fatalf("shell never ran: %v", err)
58 }
59 time.Sleep(20 * time.Millisecond)
60 }
61 })
62 }
63 }
64
64 lines GO