feat(workflow): make kind-to-workflow routing YAML-overridable
First slice of docs/prds/eda-playbook-engine.md: which registered workflow an intake Kind (bug/feature/bootstrap) prefers is now data, loaded from an optional WorkflowRoutingFile, instead of a Go literal. labelKinds and the NATS-subject-per-kind set are unchanged -- expanding the label vocabulary itself is a separate, larger decision (subject allocation) deferred per the design doc's open questions. An unrecognised kind in the file is a reported load failure (schema defines what's accepted, per the design doc's collision-handling rule), not a silently-dropped binding. No file configured falls back to today's hardcoded defaults unchanged.
This commit is contained in:
1 parent
4acfa28966
commit
97a5c0d2ca
5 files changed
+177
-25
No files matched your search
@@ -639,6 +639,12 @@ func (b *boot) setupGateways(ctx context.Context, cfgPath, overlayPath string) b
|
||||
// built-ins fill gaps.
|
||||
func (b *boot) loadWorkflows(ctx context.Context) error {
|
||||
cfg, log := b.cfg, b.log
|
||||
kindWorkflows, err := workflow.LoadKindWorkflowsYAML(cfg.WorkflowRoutingFile)
|
||||
if err != nil {
|
||||
log.Error("workflow routing file load failed", "path", cfg.WorkflowRoutingFile, "err", err)
|
||||
return err
|
||||
}
|
||||
workflow.SetKindWorkflows(kindWorkflows)
|
||||
skillsBase := cfg.SkillsDir
|
||||
if skillsBase == "" {
|
||||
skillsBase = cfg.WorkDir
|
||||
|
||||
@@ -433,6 +433,12 @@ type Config struct {
|
||||
// (plugin-defined workflows override built-ins). When empty,
|
||||
// only built-in workflows are available.
|
||||
SkillsDir string `toml:"skills_dir" yaml:"skills_dir"`
|
||||
// WorkflowRoutingFile is an optional path to a YAML file rebinding
|
||||
// which registered workflow an intake Kind (bug/feature/bootstrap)
|
||||
// prefers -- see docs/prds/eda-playbook-engine.md. When empty, the
|
||||
// built-in bindings (bug->tdd, feature->feasibility,
|
||||
// bootstrap->bootstrap) are used unchanged.
|
||||
WorkflowRoutingFile string `toml:"workflow_routing_file" yaml:"workflow_routing_file"`
|
||||
// MaxRetries caps how many times a parked task is retried before
|
||||
// being permanently parked (status "dead"). Defaults to 3.
|
||||
MaxRetries int `toml:"max_retries" yaml:"max_retries"`
|
||||
|
||||
@@ -1,27 +1,92 @@
|
||||
package workflow
|
||||
|
||||
import "github.com/samcharles93/archie-core/internal/domain/workintake"
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
// kindWorkflows names the registry entry each intake kind prefers. Bootstrap
|
||||
// exercises the full pipeline deterministically (no LLM spend) -- invites,
|
||||
// clone, push, PR, labels.
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/workintake"
|
||||
)
|
||||
|
||||
// KindWorkflows maps an intake kind to the registered workflow name it
|
||||
// prefers. The zero value is not itself a valid override -- pass the result
|
||||
// of LoadKindWorkflowsYAML to SetKindWorkflows, or nil to restore defaults.
|
||||
type KindWorkflows map[workintake.Kind]string
|
||||
|
||||
// defaultKindWorkflows names the registry entry each intake kind prefers
|
||||
// when no override has been loaded. Bootstrap exercises the full pipeline
|
||||
// deterministically (no LLM spend) -- invites, clone, push, PR, labels.
|
||||
//
|
||||
// The label vocabulary itself belongs to workintake, which is what reads
|
||||
// forge issues. This package owns only the choice of workflow for a kind:
|
||||
// keeping both here meant the transport and the registry each had their own
|
||||
// copy of the label table.
|
||||
var kindWorkflows = map[workintake.Kind]string{
|
||||
var defaultKindWorkflows = KindWorkflows{
|
||||
workintake.KindBug: "tdd",
|
||||
workintake.KindFeature: "feasibility",
|
||||
workintake.KindBootstrap: "bootstrap",
|
||||
}
|
||||
|
||||
// activeKindWorkflows is what workflowForLabels actually reads. Set once at
|
||||
// daemon startup by SetKindWorkflows; nil means "use defaultKindWorkflows".
|
||||
// This is package state deliberately, matching the once-at-startup,
|
||||
// never-concurrent-with-Route lifecycle SkillsDir/PluginDir already have --
|
||||
// Route() is never called before the daemon finishes loading configuration.
|
||||
var activeKindWorkflows KindWorkflows
|
||||
|
||||
// SetKindWorkflows overrides the kind-to-workflow-name bindings Route()
|
||||
// consults, e.g. from a file loaded by LoadKindWorkflowsYAML. Passing nil
|
||||
// restores the built-in defaults -- the first slice of
|
||||
// docs/prds/eda-playbook-engine.md: which workflow a Kind prefers is data,
|
||||
// not a Go literal, without touching labelKinds or the closed NATS-subject
|
||||
// set that Kind itself still governs.
|
||||
func SetKindWorkflows(kw KindWorkflows) {
|
||||
activeKindWorkflows = kw
|
||||
}
|
||||
|
||||
// LoadKindWorkflowsYAML reads a kind-to-workflow-name binding file. An empty
|
||||
// path returns (nil, nil) -- "no file configured" means "use defaults",
|
||||
// matching SkillsDir's own empty-means-built-ins-only convention rather than
|
||||
// requiring callers to stat first.
|
||||
//
|
||||
// A kind the workintake package does not recognise is a definition failure,
|
||||
// per the design doc's rule: the schema (here, the closed Kind vocabulary)
|
||||
// defines what's accepted, and anything else is the caller's fault --
|
||||
// reported as an error, not silently dropped or guessed at.
|
||||
func LoadKindWorkflowsYAML(path string) (KindWorkflows, error) {
|
||||
if path == "" {
|
||||
return nil, nil
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read kind-workflows file %s: %w", path, err)
|
||||
}
|
||||
raw := map[string]string{}
|
||||
if err := yaml.Unmarshal(data, &raw); err != nil {
|
||||
return nil, fmt.Errorf("parse kind-workflows file %s: %w", path, err)
|
||||
}
|
||||
kw := make(KindWorkflows, len(raw))
|
||||
for k, name := range raw {
|
||||
kind := workintake.Kind(k)
|
||||
if err := kind.Validate(); err != nil {
|
||||
return nil, fmt.Errorf("kind-workflows file %s: %w", path, err)
|
||||
}
|
||||
kw[kind] = name
|
||||
}
|
||||
return kw, nil
|
||||
}
|
||||
|
||||
// workflowForLabels returns the registered workflow name for a task's
|
||||
// labels, trying each recognised kind in label order so a "bug,feature" task
|
||||
// still reaches feasibility when no tdd workflow is registered.
|
||||
func workflowForLabels(reg Registry, labels string) (Workflow, bool) {
|
||||
kw := activeKindWorkflows
|
||||
if kw == nil {
|
||||
kw = defaultKindWorkflows
|
||||
}
|
||||
for _, kind := range workintake.KindsForLabels(workintake.SplitLabels(labels)) {
|
||||
name, ok := kindWorkflows[kind]
|
||||
name, ok := kw[kind]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package workflow
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/workintake"
|
||||
"github.com/samcharles93/archie-core/internal/store"
|
||||
)
|
||||
|
||||
@@ -47,3 +50,74 @@ func TestRouteLabelMatchStillWinsOverTriage(t *testing.T) {
|
||||
t.Fatalf("Route() = %q, want %q", wf.Name, "tdd")
|
||||
}
|
||||
}
|
||||
|
||||
// TestLoadKindWorkflowsYAMLOverridesDefaultBinding is the first slice of
|
||||
// docs/prds/eda-playbook-engine.md: which workflow a Kind prefers becomes
|
||||
// data, not a Go literal. A YAML file rebinding "bug" to "feasibility"
|
||||
// must be honoured by Route() once loaded.
|
||||
func TestLoadKindWorkflowsYAMLOverridesDefaultBinding(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "workflow-routing.yaml")
|
||||
writeFile(t, path, "bug: feasibility\n")
|
||||
|
||||
kw, err := LoadKindWorkflowsYAML(path)
|
||||
if err != nil {
|
||||
t.Fatalf("LoadKindWorkflowsYAML() error = %v", err)
|
||||
}
|
||||
SetKindWorkflows(kw)
|
||||
t.Cleanup(func() { SetKindWorkflows(nil) })
|
||||
|
||||
task := &store.Task{Labels: "bug"}
|
||||
wf := Route(task, Registry{"tdd": TDD(), "feasibility": Feasibility()})
|
||||
if wf.Name != "feasibility" {
|
||||
t.Fatalf("Route() = %q, want %q (YAML override not applied)", wf.Name, "feasibility")
|
||||
}
|
||||
}
|
||||
|
||||
// TestSetKindWorkflowsNilRestoresDefaults pins the fallback: no file, or
|
||||
// an explicit nil override, must reproduce today's hardcoded bindings
|
||||
// unchanged -- required for backward compatibility per the design doc.
|
||||
func TestSetKindWorkflowsNilRestoresDefaults(t *testing.T) {
|
||||
SetKindWorkflows(KindWorkflows{workintake.KindBug: "feasibility"})
|
||||
SetKindWorkflows(nil)
|
||||
|
||||
task := &store.Task{Labels: "bug"}
|
||||
wf := Route(task, Registry{"tdd": TDD(), "feasibility": Feasibility()})
|
||||
if wf.Name != "tdd" {
|
||||
t.Fatalf("Route() = %q, want %q (default binding not restored)", wf.Name, "tdd")
|
||||
}
|
||||
}
|
||||
|
||||
// TestLoadKindWorkflowsYAMLRejectsUnknownKind ensures a typo'd or invalid
|
||||
// kind in the YAML is a reported load failure, not a silently-ignored
|
||||
// binding -- the "schema defines the accepted message; anything else is
|
||||
// the caller's fault, dropped and logged" rule from the design doc.
|
||||
func TestLoadKindWorkflowsYAMLRejectsUnknownKind(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "workflow-routing.yaml")
|
||||
writeFile(t, path, "not-a-real-kind: tdd\n")
|
||||
|
||||
if _, err := LoadKindWorkflowsYAML(path); err == nil {
|
||||
t.Fatal("LoadKindWorkflowsYAML() error = nil, want error for unknown kind")
|
||||
}
|
||||
}
|
||||
|
||||
// TestLoadKindWorkflowsYAMLMissingFileReturnsNilNoError treats an unset
|
||||
// routing file as "use defaults", matching SkillsDir's own "empty means
|
||||
// built-ins only" convention rather than requiring callers to stat first.
|
||||
func TestLoadKindWorkflowsYAMLMissingFileReturnsNilNoError(t *testing.T) {
|
||||
kw, err := LoadKindWorkflowsYAML("")
|
||||
if err != nil {
|
||||
t.Fatalf("LoadKindWorkflowsYAML(\"\") error = %v, want nil", err)
|
||||
}
|
||||
if kw != nil {
|
||||
t.Fatalf("LoadKindWorkflowsYAML(\"\") = %#v, want nil", kw)
|
||||
}
|
||||
}
|
||||
|
||||
func writeFile(t *testing.T, path, content string) {
|
||||
t.Helper()
|
||||
if err := os.WriteFile(path, []byte(content), 0o600); err != nil {
|
||||
t.Fatalf("write %s: %v", path, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user