The classify result required a workflow, and the capture tool rejects an empty required string on the agent's single allowed call. A task needing no code change has no workflow to name, so the classification failed instead of closing the task -- the non-code path could never complete. Require only what every classification has: whether a change is needed and the reasons. Name the workflow required-when-true in its description, guard the handoff on needs_code_change rather than relying on the finish step having ended the run first, and comment the reasons before closing so the reporter sees why nothing was built.
97 lines
3.0 KiB
Go
97 lines
3.0 KiB
Go
package workflow
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// triageRegistry is the built-in step vocabulary the shipped definitions use.
|
|
func triageRegistry() StepRegistry {
|
|
registry := StepRegistry{}
|
|
add := func(types ...StepType) {
|
|
for _, stepType := range types {
|
|
registry[stepType.Name] = stepType.Factory
|
|
}
|
|
}
|
|
add(RepoStepTypes()...)
|
|
add(ControlStepTypes()...)
|
|
add(ReviewStepTypes()...)
|
|
add(AgentRunStepType(), FinishStepType(), CommandRunStepType(), WorkflowCallStepType(), DiffRulesStepType())
|
|
return registry
|
|
}
|
|
|
|
// triageDefinition returns the shipped triage definition's steps.
|
|
func triageDefinition(t *testing.T) []StepRecord {
|
|
t.Helper()
|
|
var source string
|
|
for _, entry := range ShippedDefinitions().Definitions {
|
|
if entry.ID == "triage" {
|
|
source = entry.YAML
|
|
}
|
|
}
|
|
if source == "" {
|
|
t.Fatal("the triage definition is not shipped")
|
|
}
|
|
definition, err := ParseDefinition(source, triageRegistry())
|
|
if err != nil {
|
|
t.Fatalf("parse the triage definition: %v", err)
|
|
}
|
|
return definition.Steps
|
|
}
|
|
|
|
// triageStep returns the first step whose type or id is want, or fails.
|
|
func triageStep(t *testing.T, steps []StepRecord, want string) StepRecord {
|
|
t.Helper()
|
|
for _, step := range steps {
|
|
if step.Type == want || step.ID == want {
|
|
return step
|
|
}
|
|
}
|
|
t.Fatalf("no %q step", want)
|
|
return StepRecord{}
|
|
}
|
|
|
|
// The triage result's workflow names where a code change goes. A task that
|
|
// needs no change has nowhere to go, so requiring it makes the agent assert
|
|
// something it does not know -- and the capture tool rejects an empty required
|
|
// string on the agent's single allowed call, which fails the classification
|
|
// rather than closing the task.
|
|
func TestTriageDoesNotRequireAWorkflowForANonCodeTask(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
classify := triageStep(t, triageDefinition(t), "classify")
|
|
|
|
var settings struct {
|
|
Result map[string]any `yaml:"result"`
|
|
}
|
|
if err := classify.Settings.Decode(&settings); err != nil {
|
|
t.Fatalf("decode the classify settings: %v", err)
|
|
}
|
|
tool, err := agentResultTool(settings.Result)
|
|
if err != nil {
|
|
t.Fatalf("build the result tool: %v", err)
|
|
}
|
|
if tool == nil {
|
|
t.Fatal("classify declares no result schema")
|
|
}
|
|
if slices.Contains(tool.RequiredFields, "workflow") {
|
|
t.Errorf("required = %v, want no workflow: a task that needs no code change has none to name", tool.RequiredFields)
|
|
}
|
|
if !slices.Contains(tool.RequiredFields, "needs_code_change") {
|
|
t.Errorf("required = %v, want needs_code_change", tool.RequiredFields)
|
|
}
|
|
}
|
|
|
|
// Handoff reads steps.classify.result.workflow. On the non-code path that field
|
|
// is absent, so the step must be skipped by its condition rather than relying on
|
|
// workflow.finish having ended the run first.
|
|
func TestTriageOnlyHandsOffWhenACodeChangeIsNeeded(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
handoff := triageStep(t, triageDefinition(t), HandoffStepName)
|
|
if !strings.Contains(handoff.When, "needs_code_change") {
|
|
t.Errorf("%s when = %q, want a needs_code_change condition", HandoffStepName, handoff.When)
|
|
}
|
|
}
|