package script_test

import (
	"devops/agent/script"
	"devops/agent/test"
	"fmt"
	"testing"
	"time"
)

func TestScriptExcutor_ExecuteScript(t *testing.T) {
	// 直接使用单元测试的上下文, 方便取消
	req := script.NewExecuteScriptRequest("task_debug.sh", []string{})
	req.SetWorkDir("task-02")
	req.SetTimeout(30 * time.Second)
	req.SetDebugScript(true)
	req.SetLogFile("stdout.txt")
	req.SetLogCallback(func(s string) {
		fmt.Print(s)
	})

	resp, err := script.ExecuteScript(t.Context(), req)
	if err != nil {
		t.Fatalf("failed to execute script: %v", err)
	}
	t.Logf("script execution result: %+v", resp)
}

func init() {
	// 设置测试环境
	test.Setup()
}
