fix(triage): let a task that needs no code change be classified
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.
This commit is contained in:
1 parent
2f8d375692
commit
fc0dd41092
2 files changed
+103
-2
No files matched your search
@@ -25,11 +25,15 @@ steps:
|
||||
workflow:
|
||||
type: string
|
||||
enum: [implement, tdd, feasibility]
|
||||
description: Which workflow fits best, when needs_code_change is true.
|
||||
description: Which workflow fits best. Required when needs_code_change is true; omit it otherwise.
|
||||
reasons:
|
||||
type: string
|
||||
description: The rationale, written for the human who filed the request.
|
||||
required: [needs_code_change, workflow, reasons]
|
||||
required: [needs_code_change, reasons]
|
||||
- type: forge.comment
|
||||
when: "!steps.classify.result.needs_code_change"
|
||||
settings:
|
||||
body: "Triaged: no code change is needed for this. {{ steps.classify.result.reasons }}"
|
||||
- type: forge.close-issue
|
||||
when: "!steps.classify.result.needs_code_change"
|
||||
- type: workflow.finish
|
||||
@@ -37,6 +41,7 @@ steps:
|
||||
settings:
|
||||
detail: "triaged: no code change needed. {{ steps.classify.result.reasons }}"
|
||||
- type: workflow.handoff
|
||||
when: "steps.classify.result.needs_code_change"
|
||||
settings:
|
||||
workflow: "{{ steps.classify.result.workflow }}"
|
||||
detail: "triaged to {{ steps.classify.result.workflow }}: {{ steps.classify.result.reasons }}"
|
||||
@@ -0,0 +1,96 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user