Strengthen template planning, reuse and independent review
This commit is contained in:
+125
-2
@@ -1,10 +1,14 @@
|
||||
package examples_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/examples"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"os"
|
||||
"testing"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
)
|
||||
|
||||
func TestReadmeThreeStageExampleIsValid(t *testing.T) {
|
||||
@@ -48,3 +52,122 @@ func TestCatalogContainsValidUnpublishedTemplates(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// parsedCatalog parses every bundled starter once for the role/route assertions.
|
||||
func parsedCatalog(t *testing.T) map[string]pipeline.Graph {
|
||||
t.Helper()
|
||||
parsed := map[string]pipeline.Graph{}
|
||||
for _, item := range examples.Catalog() {
|
||||
graph, err := pipeline.Parse(item.Source)
|
||||
if err != nil {
|
||||
t.Fatal(item.Key, err)
|
||||
}
|
||||
parsed[item.Key] = graph
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
func stageTools(t *testing.T, graph pipeline.Graph, key string) ([]string, bool) {
|
||||
t.Helper()
|
||||
for _, s := range graph.Stages {
|
||||
if s.Key != key {
|
||||
continue
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
// 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", "websearch", "webfetch"}},
|
||||
"summary": {"summarize": {}},
|
||||
"review": {"review": {"read", "glob", "grep", "websearch", "webfetch"}},
|
||||
"research": {
|
||||
"research": {"websearch", "webfetch"},
|
||||
"report": {},
|
||||
},
|
||||
"three-stage": {
|
||||
"planner": {"read", "glob", "grep", "websearch", "webfetch"},
|
||||
"implementer": {"read", "glob", "grep", "edit", "shell"},
|
||||
"reviewer": {"read", "glob", "grep", "shell", "websearch", "webfetch"},
|
||||
},
|
||||
}
|
||||
|
||||
func TestStarterRoleToolRestrictions(t *testing.T) {
|
||||
parsed := parsedCatalog(t)
|
||||
for key, stages := range starterTools {
|
||||
graph, ok := parsed[key]
|
||||
if !ok {
|
||||
t.Fatalf("catalog entry %s missing", 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)
|
||||
}
|
||||
sortedWant := slices.Clone(want)
|
||||
slices.Sort(sortedWant)
|
||||
if !slices.Equal(tools, sortedWant) {
|
||||
t.Fatalf("%s/%s tools = %v, want %v", key, stageKey, tools, sortedWant)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 TestThreeStageReviewerMemoryKeepsPlannerAcceptance(t *testing.T) {
|
||||
graph := parsedCatalog(t)["three-stage"]
|
||||
var reviewer protocol.Stage
|
||||
for _, s := range graph.Stages {
|
||||
if s.Key == "reviewer" {
|
||||
reviewer = s
|
||||
}
|
||||
}
|
||||
if reviewer.Key == "" {
|
||||
t.Fatal("three-stage reviewer stage missing")
|
||||
}
|
||||
plannerOwned := map[string]string{
|
||||
"plan": "planner.plan",
|
||||
"design": "planner.design",
|
||||
"reuse_targets": "planner.reuse_targets",
|
||||
"acceptance_checks": "planner.acceptance_checks",
|
||||
"research": "planner.research",
|
||||
}
|
||||
for alias, reference := range plannerOwned {
|
||||
if got := reviewer.Memory[alias]; got != reference {
|
||||
t.Fatalf("reviewer memory %s = %q, want %q", alias, got, reference)
|
||||
}
|
||||
}
|
||||
if got := reviewer.Memory["task"]; got != "input.prompt" {
|
||||
t.Fatalf("reviewer must receive the original task, got %q", got)
|
||||
}
|
||||
for alias, want := range map[string]string{
|
||||
"changed_files": "implementer.changed_files",
|
||||
"implementation_summary": "implementer.implementation_summary",
|
||||
"evidence": "implementer.evidence?",
|
||||
} {
|
||||
if got := reviewer.Memory[alias]; got != want {
|
||||
t.Fatalf("reviewer memory %s = %q, want %q", alias, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user