MCPcopy
hub / github.com/wavetermdev/waveterm / testInteractiveShell

Function testInteractiveShell

cmd/test-conn/testutil.go:268–326  ·  view source on GitHub ↗
(connName string, timeout time.Duration)

Source from the content-addressed store, hash-verified

266}
267
268func testInteractiveShell(connName string, timeout time.Duration) error {
269 opts, err := remote.ParseOpts(connName)
270 if err != nil {
271 return fmt.Errorf("failed to parse connection string: %w", err)
272 }
273
274 log.Printf("Connecting to %s...", opts.String())
275
276 conn := conncontroller.GetConn(opts)
277 ctx, cancel := context.WithTimeout(context.Background(), timeout)
278 defer cancel()
279
280 err = conn.Connect(ctx, &wconfig.ConnKeywords{})
281 if err != nil {
282 return fmt.Errorf("connection failed: %w", err)
283 }
284
285 log.Printf("✓ Connected! Starting interactive shell...")
286 log.Printf("Note: This is a simple test - output may be mixed with prompts")
287 log.Printf("Type commands and press Enter. Type 'exit' to quit.\n")
288
289 termSize := waveobj.TermSize{Rows: 24, Cols: 80}
290 shellProc, err := shellexec.StartRemoteShellProcNoWsh(ctx, termSize, "", shellexec.CommandOptsType{}, conn)
291 if err != nil {
292 return fmt.Errorf("failed to start shell: %w", err)
293 }
294 defer shellProc.Close()
295
296 go func() {
297 buf := make([]byte, 8192)
298 for {
299 n, err := shellProc.Cmd.Read(buf)
300 if err != nil {
301 return
302 }
303 if n > 0 {
304 fmt.Print(string(buf[:n]))
305 }
306 }
307 }()
308
309 go func() {
310 buf := make([]byte, 1)
311 for {
312 n, err := os.Stdin.Read(buf)
313 if err != nil {
314 return
315 }
316 if n > 0 {
317 shellProc.Cmd.Write(buf[:n])
318 }
319 }
320 }()
321
322 shellProc.Wait()
323 log.Printf("\nShell exited")
324
325 return nil

Callers 1

mainFunction · 0.85

Calls 9

ParseOptsFunction · 0.92
GetConnFunction · 0.92
CloseMethod · 0.65
WriteMethod · 0.65
WaitMethod · 0.65
StringMethod · 0.45
ConnectMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected