fix(workflow): refuse an output named result beside an agent.run result capture at save time (#1384)
deploy / plan (push) Successful in 7s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
deploy / gate (push) Canceled after 1m25s

This commit is contained in:
sam committed 2026-11-09 09:04:17 +11:00
1 parent 031291a4bf
commit e0eb1dfdb7
2 files changed
+98

No files matched your search

+34
View File
@@ -110,9 +110,43 @@ func ParseDefinition(src string, registry StepRegistry) (YAMLDefinition, error)
return YAMLDefinition{}, fmt.Errorf("workflow %q step %d: %w", definition.ID, i+1, err)
}
}
if err := checkOutputCaptureCollisions(definition.ID, definition.Outputs, definition.Steps); err != nil {
return YAMLDefinition{}, err
}
return definition, nil
}
// checkOutputCaptureCollisions refuses a definition that declares an output
// named result beside an agent.run step capturing its structured result
// through the capture tool of the same name. appendOutputTools refuses that
// clash when the step runs, so a definition carrying it must not save.
func checkOutputCaptureCollisions(workflowID string, outputs map[string]task.OutputSpec, steps []StepRecord) error {
if _, declared := outputs[resultToolName]; !declared {
return nil
}
for _, step := range steps {
if step.Type == AgentRunStepName {
var s agentRunSettings
if err := step.Settings.Decode(&s); err == nil && s.Result != nil {
return fmt.Errorf("workflow %q: output %q collides with agent.run step %q's result capture tool %q; rename the output or remove settings.result", workflowID, resultToolName, step.StageName(), resultToolName)
}
}
for _, branch := range step.Parallel {
if err := checkOutputCaptureCollisions(workflowID, outputs, branch); err != nil {
return err
}
}
if step.Switch != nil {
for _, branch := range step.Switch.Cases {
if err := checkOutputCaptureCollisions(workflowID, outputs, branch); err != nil {
return err
}
}
}
}
return nil
}
// PackageOf returns the package a pinned definition was projected from, or
// empty for a workflow the operator wrote.
func PackageOf(src string) string {
@@ -0,0 +1,64 @@
package workflow
import "testing"
func TestParseDefinitionResultOutputCollision(t *testing.T) {
registry := StepRegistry{AgentRunStepName: newAgentRunStage}
tests := []struct {
name string
yaml string
wantErr bool
}{
{"top-level agent.run", `id: w
repository: none
outputs: {result: {type: string}}
steps:
- id: classify
type: agent.run
settings:
mission: m
result: {type: object, properties: {verdict: {type: string}}}
`, true},
{"switch case", `id: w
repository: none
inputs: {kind: {type: string}}
outputs: {result: {type: string}}
steps:
- switch:
on: inputs.kind
cases:
review:
- id: classify
type: agent.run
settings:
mission: m
result: {type: object, properties: {verdict: {type: string}}}
`, true},
{"no step result schema", `id: w
repository: none
outputs: {result: {type: string}}
steps:
- id: classify
type: agent.run
settings: {mission: m}
`, false},
{"output under another name", `id: w
repository: none
outputs: {verdict: {type: string}}
steps:
- id: classify
type: agent.run
settings:
mission: m
result: {type: object, properties: {verdict: {type: string}}}
`, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := ParseDefinition(tt.yaml, registry)
if (err != nil) != tt.wantErr {
t.Fatalf("ParseDefinition err = %v, wantErr %t", err, tt.wantErr)
}
})
}
}