Label to workflow rules and a default workflow are the intake-routes resource: ordered, case-insensitive, first rule wins, seeded with bug to tdd, feature to feasibility, default triage. A write naming an undefined workflow or an empty label is refused. The daemon reads it through the workflow definitions client when pinning a task and at intake. The kind indirection only carried this routing, so it is removed: the per-kind NATS subjects (every consumer already bound archie.task.>) are one subject, the envelope and playbook triggers lose their kind, and x-intake-routes is dropped. The dashboard gets an Issue routing page under Automation; the trigger card reads the same setting.
135 lines
4.5 KiB
Go
135 lines
4.5 KiB
Go
package workflow
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"log/slog"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/agentrun"
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
|
)
|
|
|
|
// shippedTriageYAML returns the shipped triage definition's YAML.
|
|
func shippedTriageYAML(t *testing.T) string {
|
|
t.Helper()
|
|
for _, entry := range ShippedDefinitions().Definitions {
|
|
if entry.ID == "triage" {
|
|
return entry.YAML
|
|
}
|
|
}
|
|
t.Fatal("the triage definition is not shipped")
|
|
return ""
|
|
}
|
|
|
|
// The shipped collection must stay valid with triage declaring its repository
|
|
// optional: the control plane seeds and saves workflow definitions through
|
|
// ValidateDefinitionCollection, so an invalid shipped set would fail every
|
|
// operator save and the seed for orgs without a stored document.
|
|
func TestShippedCollectionValidatesWithOptionalTriage(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if err := ValidateDefinitionCollection(ShippedDefinitions(), triageRegistry()); err != nil {
|
|
t.Fatalf("shipped collection: %v", err)
|
|
}
|
|
|
|
definition, err := ParseDefinition(shippedTriageYAML(t), triageRegistry())
|
|
if err != nil {
|
|
t.Fatalf("parse the triage definition: %v", err)
|
|
}
|
|
if got := definition.RepositoryMode(); got != task.RepositoryOptional {
|
|
t.Fatalf("triage repository mode = %q, want %q", got, task.RepositoryOptional)
|
|
}
|
|
// An optional workflow may carry only repo-free step types, since it can
|
|
// run with no worktree at all.
|
|
if err := walkSteps(definition.Steps, `workflow "triage"`, func(where string, step StepRecord) error {
|
|
if NeedsRepository(step.Type) {
|
|
return fmt.Errorf("%s step %q needs a repository", where, step.StageName())
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
t.Fatalf("triage steps: %v", err)
|
|
}
|
|
}
|
|
|
|
// fakePromptRunner answers one agent.run with a fixed captured result and
|
|
// records the workspace and mission it was given.
|
|
type fakePromptRunner struct {
|
|
res agentrun.Result
|
|
workspace string
|
|
mission string
|
|
}
|
|
|
|
func (f *fakePromptRunner) Run(_ context.Context, workspace string, req agentrun.Request, _ agentrun.Reporter) (agentrun.Result, error) {
|
|
f.workspace = workspace
|
|
f.mission = req.Mission
|
|
return f.res, nil
|
|
}
|
|
|
|
// A prompt-only Run starts a task directly: an unlabeled repository-less task
|
|
// routes to triage, compiles, and runs to completion in a scratch workspace,
|
|
// with no repository involved.
|
|
func TestRepoLessTaskRunsTriageFromAPrompt(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
available := map[string]struct{}{}
|
|
for _, entry := range ShippedDefinitions().Definitions {
|
|
available[entry.ID] = struct{}{}
|
|
}
|
|
promptTask := &task.Task{ID: 7, Attempt: 1, Source: SourceChat, Title: "what does this do?", Body: "Explain the auth flow."}
|
|
if promptTask.HasRepository() {
|
|
t.Fatal("the prompt-only task must have no repository")
|
|
}
|
|
id, err := ResolveWorkflowID(promptTask, ShippedIntakeRoutes(), available)
|
|
if err != nil {
|
|
t.Fatalf("route: %v", err)
|
|
}
|
|
if id != "triage" {
|
|
t.Fatalf("routed to %q, want triage", id)
|
|
}
|
|
|
|
wf, err := ParseAndCompile(shippedTriageYAML(t), triageRegistry())
|
|
if err != nil {
|
|
t.Fatalf("compile triage: %v", err)
|
|
}
|
|
if got := wf.Interface.RepositoryMode(); got != task.RepositoryOptional {
|
|
t.Fatalf("compiled triage repository mode = %q, want %q", got, task.RepositoryOptional)
|
|
}
|
|
|
|
runner := &fakePromptRunner{res: agentrun.Result{
|
|
Version: agentrun.ProtocolVersion, TaskID: 7, Attempt: 1, Stage: AgentRunStepName,
|
|
Status: agentrun.StatusPassed, Summary: "triaged",
|
|
Captures: map[string][]json.RawMessage{resultToolName: {json.RawMessage(`{"needs_code_change": false, "reasons": "conversational"}`)}},
|
|
}}
|
|
store := &fakeStepStore{}
|
|
scratch := t.TempDir()
|
|
tc := &TaskContext{
|
|
Task: promptTask, Store: store, Log: slog.Default(), Agent: runner,
|
|
Cfg: config.Config{Models: map[string]string{"default": "test/model"}},
|
|
Dir: scratch,
|
|
}
|
|
|
|
Run(context.Background(), wf, tc)
|
|
|
|
if tc.Outcome.Status != StatusCompleted {
|
|
t.Fatalf("outcome status = %q, want %q (detail %q)", tc.Outcome.Status, StatusCompleted, tc.Outcome.Detail)
|
|
}
|
|
if runner.workspace != scratch {
|
|
t.Errorf("agent ran in workspace %q, want the scratch workspace %q", runner.workspace, scratch)
|
|
}
|
|
if !strings.Contains(runner.mission, "Explain the auth flow.") {
|
|
t.Errorf("mission %q lacks the prompt", runner.mission)
|
|
}
|
|
var names []string
|
|
for _, s := range store.started {
|
|
names = append(names, s.Name)
|
|
}
|
|
if !slices.Contains(names, "classify") {
|
|
t.Errorf("steps started = %v, want a classify step", names)
|
|
}
|
|
}
|