Merge pull request #1818 from samcharles93/fix/triage-non-code-path

fix(triage): let a task that needs no code change be classified
This commit is contained in:
sam authored and GitHub committed 2026-10-22 13:52:18 +11:00
commit 8234d56c65
2 files changed
+103 -2

No files matched your search

+7 -2
View File
@@ -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)
}
}