yao/agent/sandbox/v2/testutils/testutils.go
Max 3f390c223c feat(sandbox/v2): enhance V2 sandbox integration and testing
- Implemented V2 sandbox initialization in the assistant loading process, allowing for standalone sandbox.yao configuration.
- Added support for V2 sandbox execution paths in the Assistant's Stream method, differentiating between V1 and V2 sandboxes.
- Introduced comprehensive tests for V2 sandbox configurations, ensuring correct loading and execution behavior.
- Updated the context and types to accommodate V2 sandbox features, including system information and workspace management.

Made-with: Cursor
2026-03-10 01:13:17 +08:00

47 lines
1,019 B
Go

package testutils
import (
"context"
"os"
"path/filepath"
"testing"
agenttestutils "github.com/yaoapp/yao/agent/testutils"
"github.com/yaoapp/yao/config"
sandboxv2 "github.com/yaoapp/yao/sandbox/v2"
"github.com/yaoapp/yao/tai"
"github.com/yaoapp/yao/tai/registry"
)
// Prepare initializes the full environment required for sandbox V2 E2E tests:
// - agent layer (assistants, LLM, caller)
// - tai registry + local node
// - sandbox V2 manager
func Prepare(t *testing.T) {
t.Helper()
agenttestutils.Prepare(t)
if registry.Global() == nil {
registry.Init(nil)
}
dataDir := filepath.Join(config.Conf.DataRoot, "workspaces")
os.MkdirAll(dataDir, 0755)
tai.RegisterLocal(tai.WithDataDir(dataDir))
sandboxv2.Init()
if err := sandboxv2.M().Start(context.Background()); err != nil {
t.Fatalf("sandbox v2 manager start: %v", err)
}
t.Cleanup(func() {
sandboxv2.M().Close()
})
}
// Clean tears down the test environment.
func Clean(t *testing.T) {
t.Helper()
agenttestutils.Clean(t)
}