Add generic checked starter workflows and isolated lifecycle coverage
This commit is contained in:
+107
-10
@@ -2,6 +2,7 @@ package examples_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -28,11 +29,11 @@ func TestReadmeThreeStageExampleIsValid(t *testing.T) {
|
||||
|
||||
func TestCatalogContainsValidUnpublishedTemplates(t *testing.T) {
|
||||
items := examples.Catalog()
|
||||
if len(items) != 5 {
|
||||
if len(items) != 8 {
|
||||
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}
|
||||
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)
|
||||
@@ -91,14 +92,17 @@ func stageTools(t *testing.T, graph pipeline.Graph, key string) ([]string, bool)
|
||||
// deny-all tool-free role.
|
||||
var starterTools = map[string]map[string][]string{
|
||||
"task": {
|
||||
"worker": {"read", "glob", "grep", "edit", "shell", "websearch", "webfetch"},
|
||||
"committer": {"read", "glob", "grep", "shell"},
|
||||
"worker": {"read", "glob", "grep", "edit", "shell"},
|
||||
"review": {"read", "glob", "grep"},
|
||||
},
|
||||
"review": {"review": {"read", "glob", "grep", "websearch", "webfetch"}},
|
||||
"research": {
|
||||
"research": {"websearch", "webfetch"},
|
||||
"report": {},
|
||||
"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"},
|
||||
@@ -115,11 +119,17 @@ var starterTools = map[string]map[string][]string{
|
||||
|
||||
func TestStarterRoleToolRestrictions(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 stageKey, want := range stages {
|
||||
tools, explicit := stageTools(t, graph, stageKey)
|
||||
if !explicit {
|
||||
@@ -134,6 +144,95 @@ func TestStarterRoleToolRestrictions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllExampleDefinitionsAreRegistered(t *testing.T) {
|
||||
files, err := filepath.Glob("*.md")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
registered := map[string]string{}
|
||||
for _, item := range examples.Catalog() {
|
||||
registered[item.Key+".md"] = item.Source
|
||||
}
|
||||
for _, file := range files {
|
||||
if file == "README.md" {
|
||||
continue
|
||||
}
|
||||
data, err := os.ReadFile(file)
|
||||
if err != nil || registered[file] != string(data) {
|
||||
t.Fatalf("%s must ship in the embedded catalog: %v", file, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStartersBindConfiguredDefaultsAndOutcomes(t *testing.T) {
|
||||
for _, item := range examples.Catalog() {
|
||||
t.Run(item.Key, func(t *testing.T) {
|
||||
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 || 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)
|
||||
}
|
||||
}
|
||||
bound := pipeline.WithDefaults(item.Source, "test-provider/test-model", "opencode")
|
||||
graph, err := pipeline.Parse(bound)
|
||||
if err != nil {
|
||||
t.Fatal(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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -166,12 +265,10 @@ func TestThreeStageUsesTurnFilesWithoutRetiredBlocks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestWorkProducingStartersEndInACommitter pins the guideline that a workflow
|
||||
// which changes the repository commits locally through its final committer stage,
|
||||
// staging the server-captured change set rather than only a model's declaration.
|
||||
func TestWorkProducingStartersEndInACommitter(t *testing.T) {
|
||||
// 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 }{
|
||||
{"task", "worker"},
|
||||
{"three-stage", "implementer"},
|
||||
{"debug", "fix"},
|
||||
} {
|
||||
|
||||
Reference in New Issue
Block a user