Replace starters with four graded examples seeded into new databases
The template catalog is now Example 1-4: one stage, two stages (handoff), feedback loop (runner-owned limits, retries, timeout) and human decision (type=human approve/revise/abort with notify hooks). All read-only or leave changes uncommitted; none commits, pushes or deploys. A brand-new database (schema created by this Open) gets the examples once at server start, bound to the configured default model and harness. A server_settings marker records the decision, so removed examples never come back and existing installs are marked without any pipeline being added or rewritten.
This commit is contained in:
+117
-198
@@ -1,6 +1,7 @@
|
||||
package examples_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
@@ -13,52 +14,50 @@ import (
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
)
|
||||
|
||||
func TestReadmeThreeStageExampleIsValid(t *testing.T) {
|
||||
source, err := os.ReadFile("three-stage.md")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
graph, err := pipeline.Parse(string(source))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(graph.Stages) != 4 || graph.Settings != nil {
|
||||
t.Fatal("example must be manual-only and four stages")
|
||||
}
|
||||
// The graded set, in reading order, with its stage keys.
|
||||
var wantStages = []struct {
|
||||
key string
|
||||
stages []string
|
||||
}{
|
||||
{"one-stage", []string{"review"}},
|
||||
{"two-stages", []string{"draft", "check"}},
|
||||
{"feedback-loop", []string{"implement", "review"}},
|
||||
{"human-decision", []string{"plan", "decide", "act"}},
|
||||
}
|
||||
|
||||
func TestCatalogContainsValidUnpublishedTemplates(t *testing.T) {
|
||||
func TestCatalogIsTheGradedExampleSet(t *testing.T) {
|
||||
items := examples.Catalog()
|
||||
if len(items) != 8 {
|
||||
if len(items) != len(wantStages) {
|
||||
t.Fatal("unexpected catalog size", len(items))
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
wantStages := map[string]int{"task": 2, "review": 1, "research": 2, "three-stage": 4, "debug": 4, "summarize": 2, "compare": 2, "plan": 2}
|
||||
for _, item := range items {
|
||||
if seen[item.Key] || item.Description == "" || item.Name == "" {
|
||||
t.Fatal("invalid template metadata", item.Key)
|
||||
for i, item := range items {
|
||||
// Numbered names keep the reading order in name-sorted pipeline lists.
|
||||
if item.Key != wantStages[i].key || !strings.HasPrefix(item.Name, fmt.Sprintf("Example %d: ", i+1)) || item.Description == "" || item.Scheduled {
|
||||
t.Fatal("invalid or out-of-order example metadata", item.Key, item.Name)
|
||||
}
|
||||
seen[item.Key] = true
|
||||
graph, err := pipeline.Parse(item.Source)
|
||||
graph, err := pipeline.ParseDefinition(item.Source)
|
||||
if err != nil {
|
||||
t.Fatal(item.Key, err)
|
||||
}
|
||||
if (graph.Settings != nil) != item.Scheduled {
|
||||
t.Fatal("missing schedule warning", item.Key)
|
||||
if graph.Settings != nil {
|
||||
t.Fatal("examples must be manual-only", item.Key)
|
||||
}
|
||||
if graph.Settings != nil || len(graph.Stages) > 4 {
|
||||
t.Fatal("starters must be small and manual-only", item.Key)
|
||||
var keys []string
|
||||
for _, s := range graph.Stages {
|
||||
keys = append(keys, s.Key)
|
||||
if strings.TrimSpace(s.Prompt) == "" || s.FallbackError || s.Edges["error"] != protocol.FailureEnd {
|
||||
t.Fatalf("%s/%s needs a prompt and an explicit error -> #failure edge", item.Key, s.Key)
|
||||
}
|
||||
}
|
||||
if len(graph.Stages) != wantStages[item.Key] {
|
||||
t.Fatal("unexpected/non-generic catalog entry", item.Key)
|
||||
if !slices.Equal(keys, wantStages[i].stages) {
|
||||
t.Fatalf("%s stages = %v, want %v", item.Key, keys, wantStages[i].stages)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// parsedCatalog parses every bundled starter once for the role/route assertions.
|
||||
func parsedCatalog(t *testing.T) map[string]pipeline.Graph {
|
||||
func parsedCatalog(t *testing.T) map[string]protocol.Graph {
|
||||
t.Helper()
|
||||
parsed := map[string]pipeline.Graph{}
|
||||
parsed := map[string]protocol.Graph{}
|
||||
for _, item := range examples.Catalog() {
|
||||
graph, err := pipeline.Parse(item.Source)
|
||||
if err != nil {
|
||||
@@ -69,72 +68,36 @@ func parsedCatalog(t *testing.T) map[string]pipeline.Graph {
|
||||
return parsed
|
||||
}
|
||||
|
||||
func stageTools(t *testing.T, graph pipeline.Graph, key string) ([]string, bool) {
|
||||
func stageByKey(t *testing.T, graph protocol.Graph, key string) protocol.Stage {
|
||||
t.Helper()
|
||||
for _, s := range graph.Stages {
|
||||
if s.Key != key {
|
||||
continue
|
||||
if s.Key == key {
|
||||
return s
|
||||
}
|
||||
tools, explicit, err := stage.ToolNames(pipeline.StageDefinition(s))
|
||||
if err != nil {
|
||||
t.Fatalf("stage %s: %v", key, err)
|
||||
}
|
||||
sorted := slices.Clone(tools)
|
||||
slices.Sort(sorted)
|
||||
return sorted, explicit
|
||||
}
|
||||
t.Fatalf("stage %s not found", key)
|
||||
return nil, false
|
||||
return protocol.Stage{}
|
||||
}
|
||||
|
||||
// starterTools is the expected explicit role allowlist per template and stage.
|
||||
// Every bundled starter declares a tools block; an empty list is the intentional
|
||||
// deny-all tool-free role.
|
||||
var starterTools = map[string]map[string][]string{
|
||||
"task": {
|
||||
"worker": {"read", "glob", "grep", "edit", "shell"},
|
||||
"review": {"read", "glob", "grep", "shell"},
|
||||
},
|
||||
"review": {"review": {"read", "glob", "grep", "websearch", "webfetch"}},
|
||||
"research": {
|
||||
"research": {"websearch", "webfetch"},
|
||||
"report": {"webfetch"},
|
||||
},
|
||||
"summarize": {"summarize": {"read", "glob", "grep"}, "check": {"read", "glob", "grep"}},
|
||||
"compare": {"compare": {"read", "glob", "grep"}, "check": {"read", "glob", "grep"}},
|
||||
"plan": {"plan": {"read", "glob", "grep"}, "check": {"read", "glob", "grep"}},
|
||||
"three-stage": {
|
||||
"planner": {"read", "glob", "grep", "websearch", "webfetch"},
|
||||
"implementer": {"read", "glob", "grep", "edit", "shell"},
|
||||
"reviewer": {"read", "glob", "grep", "shell", "websearch", "webfetch"},
|
||||
"committer": {"read", "glob", "grep", "shell"},
|
||||
},
|
||||
"debug": {
|
||||
"diagnose": {"read", "glob", "grep", "shell"},
|
||||
"fix": {"read", "glob", "grep", "edit", "shell"},
|
||||
"verify": {"read", "glob", "grep", "shell"},
|
||||
"committer": {"read", "glob", "grep", "shell"},
|
||||
},
|
||||
// Every model stage declares an explicit role allowlist. Only the stages that
|
||||
// make the requested change may edit; nothing has web tools.
|
||||
var exampleTools = map[string]map[string][]string{
|
||||
"one-stage": {"review": {"read", "glob", "grep"}},
|
||||
"two-stages": {"draft": {"read", "glob", "grep"}, "check": {"read", "glob", "grep"}},
|
||||
"feedback-loop": {"implement": {"read", "glob", "grep", "edit", "shell"}, "review": {"read", "glob", "grep", "shell"}},
|
||||
"human-decision": {"plan": {"read", "glob", "grep"}, "act": {"read", "glob", "grep", "edit", "shell"}},
|
||||
}
|
||||
|
||||
func TestStarterRoleToolRestrictions(t *testing.T) {
|
||||
func TestExampleRoleToolRestrictions(t *testing.T) {
|
||||
parsed := parsedCatalog(t)
|
||||
if len(parsed) != len(starterTools) {
|
||||
t.Fatal("every catalog entry must have role tool expectations")
|
||||
}
|
||||
for key, stages := range starterTools {
|
||||
graph, ok := parsed[key]
|
||||
if !ok {
|
||||
t.Fatalf("catalog entry %s missing", key)
|
||||
}
|
||||
if len(stages) != len(graph.Stages) {
|
||||
t.Fatalf("every %s stage must have role tool expectations", key)
|
||||
}
|
||||
for key, stages := range exampleTools {
|
||||
graph := parsed[key]
|
||||
for stageKey, want := range stages {
|
||||
tools, explicit := stageTools(t, graph, stageKey)
|
||||
if !explicit {
|
||||
t.Fatalf("%s/%s must declare an explicit tools block", key, stageKey)
|
||||
tools, explicit, err := stage.ToolNames(pipeline.StageDefinition(stageByKey(t, graph, stageKey)))
|
||||
if err != nil || !explicit {
|
||||
t.Fatalf("%s/%s must declare an explicit tools block: %v", key, stageKey, err)
|
||||
}
|
||||
slices.Sort(tools)
|
||||
sortedWant := slices.Clone(want)
|
||||
slices.Sort(sortedWant)
|
||||
if !slices.Equal(tools, sortedWant) {
|
||||
@@ -142,6 +105,15 @@ func TestStarterRoleToolRestrictions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
for key, graph := range parsed {
|
||||
for _, s := range graph.Stages {
|
||||
if s.Type == stage.ModelType {
|
||||
if _, ok := exampleTools[key][s.Key]; !ok {
|
||||
t.Fatalf("%s/%s needs a role tool expectation", key, s.Key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllExampleDefinitionsAreRegistered(t *testing.T) {
|
||||
@@ -162,137 +134,84 @@ func TestAllExampleDefinitionsAreRegistered(t *testing.T) {
|
||||
t.Fatalf("%s must ship in the embedded catalog: %v", file, err)
|
||||
}
|
||||
}
|
||||
if len(files)-1 != len(registered) {
|
||||
t.Fatal("every catalog entry needs a checked-in file")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStartersBindConfiguredDefaultsAndOutcomes(t *testing.T) {
|
||||
func TestExamplesBindConfiguredDefaults(t *testing.T) {
|
||||
for _, item := range examples.Catalog() {
|
||||
t.Run(item.Key, func(t *testing.T) {
|
||||
for _, backend := range []string{"opencode", "pi"} {
|
||||
raw, err := pipeline.Parse(item.Source)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, s := range raw.Stages {
|
||||
if s.Configs["provider"] != "default" || s.Configs["model"] != "default" || s.Configs["harness"] != "" {
|
||||
t.Fatalf("%s must inherit model and harness, got %v", s.Key, s.Configs)
|
||||
if s.Type != stage.ModelType {
|
||||
continue
|
||||
}
|
||||
if s.Type != stage.ModelType || len(s.Memory) != 0 || s.Output != "" || s.Configs["delivery"] != "" {
|
||||
t.Fatalf("%s must use plain model-stage Markdown without delivery or retired blocks", s.Key)
|
||||
}
|
||||
if s.Edges["success"] == "" || (s.Edges["blocked"] != protocol.FailureEnd && s.Edges["rejected"] != protocol.FailureEnd) || s.Edges["error"] != protocol.FailureEnd {
|
||||
t.Fatalf("%s must bind success, blocked/rejected and error outcomes: %v", s.Key, s.Edges)
|
||||
if s.Configs["provider"] != "default" || s.Configs["model"] != "default" || s.Configs["harness"] != "" || s.Configs["delivery"] != "" || len(s.Memory) != 0 || s.Output != "" {
|
||||
t.Fatalf("%s/%s must inherit model and harness without delivery or retired blocks: %v", item.Key, s.Key, s.Configs)
|
||||
}
|
||||
}
|
||||
bound := pipeline.WithDefaults(item.Source, "test-provider/test-model", "opencode")
|
||||
graph, err := pipeline.Parse(bound)
|
||||
graph, err := pipeline.ParseDefinition(pipeline.WithDefaults(item.Source, "test-provider/test-model", backend))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Fatal(item.Key, err)
|
||||
}
|
||||
for _, s := range graph.Stages {
|
||||
if s.Configs["provider"] != "test-provider" || s.Configs["model"] != "test-model" || s.Configs["harness"] != "opencode" {
|
||||
t.Fatalf("%s did not bind configured defaults: %v", s.Key, s.Configs)
|
||||
if s.Type != stage.ModelType {
|
||||
continue
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimpleLocalStartersSupportConfiguredPiHarness(t *testing.T) {
|
||||
for _, item := range examples.Catalog() {
|
||||
if !slices.Contains([]string{"task", "summarize", "compare", "plan"}, item.Key) {
|
||||
continue
|
||||
}
|
||||
graph, err := pipeline.Parse(pipeline.WithDefaults(item.Source, "test-provider/test-model", "pi"))
|
||||
if err != nil {
|
||||
t.Fatal(item.Key, err)
|
||||
}
|
||||
for _, s := range graph.Stages {
|
||||
if s.Configs["harness"] != "pi" {
|
||||
t.Fatalf("%s/%s ignored configured harness", item.Key, s.Key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSmallCodeChangeEndsInIndependentReadOnlyReview(t *testing.T) {
|
||||
graph := parsedCatalog(t)["task"]
|
||||
if graph.Stages[0].Edges["success"] != "review" || graph.Stages[1].Edges["success"] != protocol.SuccessEnd {
|
||||
t.Fatal("small code change must route through review")
|
||||
}
|
||||
if !strings.Contains(graph.Stages[1].Prompt, "Independently review the actual changed files") ||
|
||||
!strings.Contains(graph.Stages[0].Prompt, "Do not commit, push or deploy") {
|
||||
t.Fatal("small code change must review actual work and leave it uncommitted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResearchRequiresSourceEvidenceAndHonestToolLimitations(t *testing.T) {
|
||||
graph := parsedCatalog(t)["research"]
|
||||
if !strings.Contains(graph.Stages[0].Prompt, "If either is unavailable") ||
|
||||
!strings.Contains(graph.Stages[1].Prompt, "Fact-check") ||
|
||||
!strings.Contains(graph.Stages[1].Prompt, "Never invent citations") {
|
||||
t.Fatal("research must report missing tools and verify, not invent, citations")
|
||||
}
|
||||
}
|
||||
|
||||
func TestThreeStagePlannerBlockedRoute(t *testing.T) {
|
||||
graph := parsedCatalog(t)["three-stage"]
|
||||
for _, s := range graph.Stages {
|
||||
if s.Key == "planner" {
|
||||
if got := s.Edges["blocked"]; got != protocol.FailureEnd {
|
||||
t.Fatalf("planner blocked route = %q, want %q", got, protocol.FailureEnd)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestThreeStageUsesTurnFilesWithoutRetiredBlocks(t *testing.T) {
|
||||
graph := parsedCatalog(t)["three-stage"]
|
||||
for _, s := range graph.Stages {
|
||||
if len(s.Memory) != 0 {
|
||||
t.Fatalf("%s stage %s must not use the retired memory block: %v", "three-stage", s.Key, s.Memory)
|
||||
}
|
||||
if s.Output != "" {
|
||||
t.Fatalf("%s stage %s must not declare the retired output block", "three-stage", s.Key)
|
||||
}
|
||||
}
|
||||
var reviewer protocol.Stage
|
||||
for _, s := range graph.Stages {
|
||||
if s.Key == "reviewer" {
|
||||
reviewer = s
|
||||
}
|
||||
}
|
||||
if reviewer.Key == "" || !strings.Contains(strings.ToLower(reviewer.Prompt), "independently review") {
|
||||
t.Fatalf("three-stage reviewer must independently review the full diff: %+v", reviewer)
|
||||
}
|
||||
}
|
||||
|
||||
// Existing extended coding starters retain their explicit local-commit behavior.
|
||||
// The small task starter deliberately leaves changes uncommitted for the user.
|
||||
func TestExtendedCodingStartersEndInACommitter(t *testing.T) {
|
||||
for _, tc := range []struct{ key, producer string }{
|
||||
{"three-stage", "implementer"},
|
||||
{"debug", "fix"},
|
||||
} {
|
||||
graph := parsedCatalog(t)[tc.key]
|
||||
last := graph.Stages[len(graph.Stages)-1]
|
||||
if last.Key != "committer" {
|
||||
t.Fatalf("%s must end in a committer stage, got %q", tc.key, last.Key)
|
||||
}
|
||||
if got := last.Edges["success"]; got != protocol.SuccessEnd {
|
||||
t.Fatalf("%s committer success route = %q, want %q", tc.key, got, protocol.SuccessEnd)
|
||||
}
|
||||
if len(last.Memory) != 0 || last.Output != "" {
|
||||
t.Fatalf("%s committer must use the turn files, not retired blocks: %+v", tc.key, last)
|
||||
}
|
||||
if !strings.Contains(last.Prompt, "diff") {
|
||||
t.Fatalf("%s committer prompt must inspect the actual diff", tc.key)
|
||||
}
|
||||
// The producer hands its work on rather than ending the run itself.
|
||||
for _, s := range graph.Stages {
|
||||
if s.Key == tc.producer {
|
||||
if protocol.IsTerminal(s.Edges["success"]) {
|
||||
t.Fatalf("%s/%s must hand success to a later stage, not %q", tc.key, tc.producer, s.Edges["success"])
|
||||
if s.Configs["provider"] != "test-provider" || s.Configs["model"] != "test-model" || s.Configs["harness"] != backend {
|
||||
t.Fatalf("%s/%s did not bind configured defaults: %v", item.Key, s.Key, s.Configs)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No example commits, pushes or deploys; editing examples leave changes uncommitted.
|
||||
func TestExamplesAreSafe(t *testing.T) {
|
||||
for key, graph := range parsedCatalog(t) {
|
||||
for _, s := range graph.Stages {
|
||||
prompt := strings.ToLower(s.Prompt)
|
||||
edits := slices.Contains(exampleTools[key][s.Key], "edit")
|
||||
if edits && !strings.Contains(prompt, "uncommitted") {
|
||||
t.Fatalf("%s/%s must leave its changes uncommitted", key, s.Key)
|
||||
}
|
||||
if !edits && s.Type == stage.ModelType && !strings.Contains(prompt, "do not edit") && !strings.Contains(prompt, "change nothing") {
|
||||
t.Fatalf("%s/%s must say it changes nothing", key, s.Key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedbackLoopUsesRunnerOwnedLimitsAndRetries(t *testing.T) {
|
||||
graph := parsedCatalog(t)["feedback-loop"]
|
||||
implement, review := stageByKey(t, graph, "implement"), stageByKey(t, graph, "review")
|
||||
if implement.Edges["success"] != "review" || review.Edges["rejected"] != "implement" || review.Edges["approved"] != protocol.SuccessEnd {
|
||||
t.Fatal("feedback loop must route implement -> review, rejected -> implement", implement.Edges, review.Edges)
|
||||
}
|
||||
if review.Limits == nil || review.Limits.MaxVisits != 3 || !slices.Equal(review.Limits.On, []string{"rejected"}) {
|
||||
t.Fatalf("review must cap rejected loops with runner-owned limits: %+v", review.Limits)
|
||||
}
|
||||
if implement.Configs["retries"] != "1" || implement.Configs["timeout"] != "30m" || review.Configs["retries"] != "2" || review.Configs["timeout"] != "15m" {
|
||||
t.Fatal("feedback loop must show explicit retries and timeouts", implement.Configs, review.Configs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHumanDecisionWaitsAndNotifies(t *testing.T) {
|
||||
graph := parsedCatalog(t)["human-decision"]
|
||||
plan, decide, act := stageByKey(t, graph, "plan"), stageByKey(t, graph, "decide"), stageByKey(t, graph, "act")
|
||||
if decide.Type != stage.HumanType || decide.Edges["approve"] != "act" || decide.Edges["revise"] != "plan" || decide.Edges["abort"] != protocol.FailureEnd {
|
||||
t.Fatalf("decide must be a human approve/revise/abort stage: %+v", decide)
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
s protocol.Stage
|
||||
want []string
|
||||
}{{plan, []string{"failure"}}, {decide, []string{"waiting"}}, {act, []string{"success", "failure"}}} {
|
||||
if tc.s.Notify == nil || !slices.Equal(tc.s.Notify.On, tc.want) {
|
||||
t.Fatalf("%s notify = %+v, want on=%v", tc.s.Key, tc.s.Notify, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user