Run tasks directly with language-independent project tools
This commit is contained in:
@@ -40,7 +40,7 @@ func TestCLIHeadlessRunInspectionCancellationAndRPC(t *testing.T) {
|
||||
err := app.Run(ctx, append([]string{"--url", url}, args...))
|
||||
return out.String(), err
|
||||
}
|
||||
output, err := run("run", "workflow", "exact task", "--yes", "--json", "--request-key", "same-key")
|
||||
output, err := run("run", "workflow", "exact task", "--json", "--request-key", "same-key")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -74,12 +74,27 @@ func (r *runner) start(request protocol.Message) (*protocol.RunDetail, error) {
|
||||
return nil, fmt.Errorf("too many write paths")
|
||||
}
|
||||
for _, path := range request.WritePaths {
|
||||
if filepath.IsAbs(path) || filepath.Clean(path) != path || strings.HasPrefix(path, "..") || strings.ContainsAny(path, "*?\\") || !strings.HasSuffix(path, ".go") {
|
||||
return nil, fmt.Errorf("write paths must be exact project-local Go files")
|
||||
if filepath.IsAbs(path) || filepath.Clean(path) != path || path == ".." || strings.HasPrefix(path, ".."+string(os.PathSeparator)) || strings.ContainsAny(path, "*?\\") {
|
||||
return nil, fmt.Errorf("optional write paths must be exact run-directory-relative paths")
|
||||
}
|
||||
resolved, err := filepath.EvalSymlinks(filepath.Join(workspace, path))
|
||||
if err != nil || !strings.HasPrefix(resolved, workspace+string(os.PathSeparator)) {
|
||||
return nil, fmt.Errorf("write path must be an existing file within workspace")
|
||||
parent := filepath.Join(workspace, path)
|
||||
for {
|
||||
_, err := os.Lstat(parent)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
if !os.IsNotExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
next := filepath.Dir(parent)
|
||||
if next == parent {
|
||||
return nil, fmt.Errorf("write path is unavailable")
|
||||
}
|
||||
parent = next
|
||||
}
|
||||
resolved, err := filepath.EvalSymlinks(parent)
|
||||
if err != nil || (resolved != workspace && !strings.HasPrefix(resolved, workspace+string(os.PathSeparator))) {
|
||||
return nil, fmt.Errorf("write path must stay within the run directory")
|
||||
}
|
||||
}
|
||||
if request.Input == nil {
|
||||
@@ -99,13 +114,16 @@ func (r *runner) start(request protocol.Message) (*protocol.RunDetail, error) {
|
||||
if stage.EffectiveType(s.Type) != stage.ModelType {
|
||||
continue
|
||||
}
|
||||
tools, _, err := stage.ToolNames(pipeline.StageDefinition(s))
|
||||
tools, explicit, err := stage.ToolNames(pipeline.StageDefinition(s))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !explicit {
|
||||
request.AllowTools = true
|
||||
}
|
||||
for _, tool := range tools {
|
||||
if (tool == "edit" || tool == "shell") && !request.AllowTools {
|
||||
return nil, fmt.Errorf("stage %s: %s requires explicit manual tool approval", s.Key, tool)
|
||||
if tool == "edit" || tool == "shell" {
|
||||
request.AllowTools = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,7 +235,7 @@ func (r *runner) run(ctx context.Context, id int64, d *protocol.PipelineDetail,
|
||||
finish("failed", "error", toolErr.Error())
|
||||
return
|
||||
}
|
||||
useAgent := stage.EffectiveType(def.Type) == stage.ModelType && (len(tools) > 0 || (request.AllowTools && !explicitTools))
|
||||
useAgent := stage.EffectiveType(def.Type) == stage.ModelType && (len(tools) > 0 || !explicitTools)
|
||||
client := &stage.AgentClient{OpenCodeClient: stage.OpenCodeClient{Directory: workspace}, WritePaths: request.WritePaths, Tools: tools}
|
||||
client.OnSession = func(session string, active bool) error {
|
||||
c, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
|
||||
@@ -65,7 +65,7 @@ func TestWebStagesCanRunWithoutMutationApproval(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMutatingToolsRequireManualApproval(t *testing.T) {
|
||||
func TestDeclaredMutationToolsRunWithoutManualApproval(t *testing.T) {
|
||||
for _, tool := range []string{"edit", "shell"} {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
store, err := pipeline.Open(filepath.Join(t.TempDir(), "tools.db"))
|
||||
@@ -79,15 +79,11 @@ func TestMutatingToolsRequireManualApproval(t *testing.T) {
|
||||
items, _ := store.List(ctx)
|
||||
r, _ := newRunner(ctx, store)
|
||||
request := protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "unsafe", Input: map[string]any{"prompt": "task"}}
|
||||
if _, err := r.start(request); err == nil || !strings.Contains(err.Error(), "manual tool approval") {
|
||||
t.Fatal("mutation without approval", tool, err)
|
||||
}
|
||||
r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) {
|
||||
return stage.Result{Outcome: "success", Output: stage.Values{}}, nil
|
||||
}
|
||||
request.AllowTools = true
|
||||
if _, err := r.start(request); err != nil {
|
||||
t.Fatal("approved run rejected", err)
|
||||
t.Fatal("declared tools should run without a second approval", err)
|
||||
}
|
||||
r.wg.Wait()
|
||||
cancel()
|
||||
|
||||
Reference in New Issue
Block a user