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

Function testWshExec

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

Source from the content-addressed store, hash-verified

190}
191
192func testWshExec(connName string, cmd string, timeout time.Duration) error {
193 opts, err := remote.ParseOpts(connName)
194 if err != nil {
195 return fmt.Errorf("failed to parse connection string: %w", err)
196 }
197
198 log.Printf("Connecting to %s with wsh enabled...", opts.String())
199
200 conn := conncontroller.GetConn(opts)
201 ctx, cancel := context.WithTimeout(context.Background(), timeout)
202 defer cancel()
203
204 wshEnabled := true
205 err = conn.Connect(ctx, &wconfig.ConnKeywords{
206 ConnWshEnabled: &wshEnabled,
207 })
208 if err != nil {
209 return fmt.Errorf("connection failed: %w", err)
210 }
211
212 status := conn.DeriveConnStatus()
213 log.Printf("✓ Connected! (wsh enabled: %v)", status.WshEnabled)
214 if status.WshVersion != "" {
215 log.Printf(" wsh version: %s", status.WshVersion)
216 }
217 if !status.WshEnabled {
218 log.Printf(" WARNING: wsh not enabled - reason: %s", status.NoWshReason)
219 }
220
221 log.Printf("Starting wsh-enabled shell...")
222
223 swapToken := &shellutil.TokenSwapEntry{
224 Token: uuid.New().String(),
225 Env: make(map[string]string),
226 Exp: time.Now().Add(5 * time.Minute),
227 }
228 swapToken.Env["TERM_PROGRAM"] = "waveterm"
229 swapToken.Env["WAVETERM"] = "1"
230 swapToken.Env["WAVETERM_VERSION"] = wavebase.WaveVersion
231 swapToken.Env["WAVETERM_CONN"] = connName
232
233 cmdOpts := shellexec.CommandOptsType{
234 SwapToken: swapToken,
235 }
236
237 termSize := waveobj.TermSize{Rows: 24, Cols: 80}
238 shellProc, err := shellexec.StartRemoteShellProc(ctx, ctx, termSize, "", cmdOpts, conn)
239 if err != nil {
240 return fmt.Errorf("failed to start shell: %w", err)
241 }
242 defer shellProc.Close()
243
244 log.Printf("✓ Shell started! Executing: %s", cmd)
245
246 _, err = shellProc.Cmd.Write([]byte(cmd + "\n"))
247 if err != nil {
248 return fmt.Errorf("failed to write command: %w", err)
249 }

Callers 1

mainFunction · 0.85

Calls 9

ParseOptsFunction · 0.92
GetConnFunction · 0.92
StartRemoteShellProcFunction · 0.92
CloseMethod · 0.65
WriteMethod · 0.65
StringMethod · 0.45
ConnectMethod · 0.45
DeriveConnStatusMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected