41 lines
788 B
Go
41 lines
788 B
Go
package exec_test
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"agent-native/exec"
|
|
)
|
|
|
|
func TestStubBackendExecution(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
|
|
backend := &exec.StubBackend{}
|
|
if backend.Name() != "stub" {
|
|
t.Errorf("expected stub backend, got %s", backend.Name())
|
|
}
|
|
|
|
req := exec.Request{
|
|
WorkDir: tmpDir,
|
|
Prompt: "请编写用户初始需求收集表",
|
|
Targets: []string{"output.md"},
|
|
Timeout: 5 * time.Second,
|
|
}
|
|
|
|
res, err := backend.Execute(context.Background(), req)
|
|
if err != nil {
|
|
t.Fatalf("stub execute failed: %v", err)
|
|
}
|
|
if !res.Success {
|
|
t.Fatalf("expected success")
|
|
}
|
|
|
|
outputPath := filepath.Join(tmpDir, "output.md")
|
|
if _, err := os.Stat(outputPath); err != nil {
|
|
t.Fatalf("expected output.md to exist: %v", err)
|
|
}
|
|
}
|