MCPcopy
hub / github.com/keploy/keploy / startInDockerWithPTY

Method startInDockerWithPTY

pkg/platform/http/agent.go:1403–1442  ·  view source on GitHub ↗

startInDockerWithPTY starts the docker agent with PTY support for interactive input (e.g., sudo password)

(ctx context.Context, logger *zap.Logger, cmd *exec.Cmd)

Source from the content-addressed store, hash-verified

1401
1402// startInDockerWithPTY starts the docker agent with PTY support for interactive input (e.g., sudo password)
1403func (a *AgentClient) startInDockerWithPTY(ctx context.Context, logger *zap.Logger, cmd *exec.Cmd) error {
1404 // Configure command for PTY execution (OS-specific)
1405 agentUtils.ConfigureCommandForPTY(cmd)
1406
1407 logger.Debug("Starting docker agent with PTY for interactive input")
1408
1409 // Start with PTY
1410 ptyHandle, err := agentUtils.StartCommandWithPTY(cmd, logger)
1411 if err != nil {
1412 utils.LogError(logger, err, "failed to start keploy agent in docker with PTY")
1413 return err
1414 }
1415
1416 a.mu.Lock()
1417 a.agentCmd = cmd
1418 a.agentPTY = ptyHandle
1419 a.mu.Unlock()
1420
1421 pid := cmd.Process.Pid
1422 logger.Debug("keploy agent in docker started with PTY", zap.Int("pid", pid))
1423
1424 // Wait for the command to finish
1425 err = ptyHandle.Wait()
1426
1427 a.mu.Lock()
1428 a.agentCmd = nil
1429 a.agentPTY = nil
1430 a.mu.Unlock()
1431
1432 if err != nil {
1433 if ctx.Err() == context.Canceled {
1434 logger.Info("Keploy agent in docker stopped gracefully.")
1435 return nil
1436 }
1437 utils.LogError(logger, err, "failed to run keploy agent in docker with PTY")
1438 return err
1439 }
1440
1441 return nil
1442}
1443
1444// GetErrorChannel returns nil for HTTP transport — use GetMockErrors() instead.
1445func (a *AgentClient) GetErrorChannel() <-chan error {

Callers 1

startInDockerMethod · 0.95

Calls 3

LogErrorFunction · 0.92
DebugMethod · 0.65
WaitMethod · 0.45

Tested by

no test coverage detected