返回 DeepSeek-Reasonix
terminal_process_windows_test.go
根目录 / desktop / terminal_process_windows_test.go
1 //go:build windows
2
3 package main
4
5 import (
6 "bytes"
7 "fmt"
8 "os"
9 "os/exec"
10 "testing"
11 "time"
12 )
13
14 func TestWindowsTerminalProcessConPTYSmoke(t *testing.T) {
15 available, reason := terminalPlatformAvailable()
16 if !available {
17 t.Skip(reason)
18 }
19 commandPath, err := exec.LookPath("cmd.exe")
20 if err != nil {
21 t.Fatal(err)
22 }
23 proc, err := startTerminalProcess(terminalStartSpec{
24 command: commandForShellPath(commandPath, "Command Prompt"),
25 dir: t.TempDir(),
26 env: os.Environ(),
27 cols: defaultTerminalColumns,
28 rows: defaultTerminalRows,
29 })
30 if err != nil {
31 t.Fatal(err)
32 }
33 defer proc.Close()
34
35 if err := proc.Resize(100, 30); err != nil {
36 t.Fatalf("resize ConPTY: %v", err)
37 }
38
39 const marker = "reasonix-conpty-smoke"
40 readResult := make(chan error, 1)
41 go func() {
42 var output bytes.Buffer
43 buf := make([]byte, 4096)
44 for {
45 n, readErr := proc.Read(buf)
46 if n > 0 {
47 output.Write(buf[:n])
48 if bytes.Contains(output.Bytes(), []byte(marker)) {
49 readResult <- nil
50 return
51 }
52 }
53 if readErr != nil {
54 readResult <- fmt.Errorf("read ConPTY output: %w", readErr)
55 return
56 }
57 }
58 }()
59
60 if _, err := proc.Write([]byte("echo " + marker + "\r\n")); err != nil {
61 t.Fatalf("write ConPTY command: %v", err)
62 }
63 select {
64 case err := <-readResult:
65 if err != nil {
66 t.Fatal(err)
67 }
68 case <-time.After(10 * time.Second):
69 t.Fatal("timed out waiting for ConPTY output")
70 }
71
72 if _, err := proc.Write([]byte("exit\r\n")); err != nil {
73 t.Fatalf("write ConPTY exit: %v", err)
74 }
75 waitResult := make(chan error, 1)
76 go func() {
77 _, waitErr := proc.Wait()
78 waitResult <- waitErr
79 }()
80 select {
81 case err := <-waitResult:
82 if err != nil {
83 t.Fatalf("wait for ConPTY exit: %v", err)
84 }
85 case <-time.After(10 * time.Second):
86 t.Fatal("timed out waiting for ConPTY process exit")
87 }
88 }
89
89 lines GO