Merge branch 'worktree-agent-add3194df2bcbd3c5'

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 14:21:07 +00:00
48 changed files with 2684 additions and 131 deletions
+89
View File
@@ -0,0 +1,89 @@
package pipeline
import (
"strings"
"testing"
"git.a-wan.net/alan/pipelines/internal/stage"
)
func checkStageSource(key, commands, configs, edges string) string {
return "# stage " + key + "\n\n```configs\ntype=check\n" + configs + "\n```\n\n```commands\n" + commands + "\n```\n\n```edges\n" + edges + "\n```\n"
}
// A check stage sits between implement and review: a red tree goes back to
// the implementer with the failing output, never to the reviewer.
func TestParseCheckStageBeforeReview(t *testing.T) {
source := lintSource(
modelStage("implement", "Make the change.", "read\nedit\nshell", "success -> verify\nerror -> #failure", "```checks\nnone: the verify stage runs the suite\n```"),
checkStageSource("verify", "go vet ./...\ngo test ./...", "command_timeout=15m", "pass -> review\nfail -> implement"),
modelStage("review", "Review the diff.", "read\nglob\ngrep", "success -> #success\nerror -> #failure", ""),
)
g, err := ParseDefinition(source)
if err != nil {
t.Fatal(err)
}
verify := g.Stages[1]
if verify.Type != stage.CheckType || verify.Blocks["commands"] != "go vet ./...\ngo test ./..." || verify.Configs["command_timeout"] != "15m" {
t.Fatalf("parsed %+v", verify)
}
if verify.Edges["error"] != "#failure" || !verify.FallbackError {
t.Fatal("check stage error edge", verify.Edges)
}
def := StageDefinition(verify)
if _, err := stage.CheckStageSpec(def); err != nil {
t.Fatal("stored definition no longer validates:", err)
}
errs, _ := Lint(g)
var rules []string
for _, finding := range errs {
rules = append(rules, finding.String())
}
// fail -> implement loops back: the existing loop rule asks for a limit.
if len(errs) != 1 || errs[0].Rule != "limits" {
t.Fatalf("lint %v", rules)
}
limited := strings.Replace(source, "```configs\ntype=check", "```limits\n{\"max_visits\":3}\n```\n\n```configs\ntype=check", 1)
if g, err = ParseDefinition(limited); err != nil {
t.Fatal(err)
}
if errs, _ := Lint(g); len(errs) != 0 {
t.Fatal(errs)
}
}
func TestCheckStageRejectsModelBlocksAndSilentGuards(t *testing.T) {
if _, err := ParseDefinition(checkStageSource("verify", "go test ./...", "model=x", "pass -> #success\nfail -> #failure")); err == nil {
t.Fatal("model config accepted on a check stage")
}
if _, err := ParseDefinition(checkStageSource("verify", "", "", "pass -> #success\nfail -> #failure")); err == nil {
t.Fatal("empty commands accepted")
}
g, err := ParseDefinition(checkStageSource("verify", "ruff check . || true", "", "pass -> #success\nfail -> #failure"))
if err != nil {
t.Fatal(err)
}
errs, _ := Lint(g)
if len(errs) != 1 || errs[0].Rule != "commands" {
t.Fatal(errs)
}
}
// A delivery check stage is the landing gate: its commands are the checks the
// server runs on the committed candidate before fast-forwarding main.
func TestCheckStageAsLandingGateSatisfiesDeliveryLint(t *testing.T) {
source := lintSource(
modelStage("implement", "Make the change; the delivery gate lands it.", "read\nedit\nshell", "success -> land\nerror -> #failure", "```checks\nnone: the land gate runs the suite\n```"),
checkStageSource("land", "go test ./...", "delivery=true", "pass -> #success\nfail -> #failure"),
)
g, err := ParseDefinition(source)
if err != nil {
t.Fatal(err)
}
if errs, _ := Lint(g); len(errs) != 0 {
t.Fatal(errs)
}
if enabled, err := stage.DeliveryEnabled(StageDefinition(g.Stages[1])); err != nil || !enabled {
t.Fatal(enabled, err)
}
}
+7
View File
@@ -90,6 +90,13 @@ func Lint(g Graph) (errs, warnings []LintFinding) {
}
}
}
if stage.EffectiveType(s.Type) == stage.CheckType {
for _, line := range strings.Split(s.Blocks["commands"], "\n") {
if guard := silentGuard(line); guard != "" {
add(&errs, s, "commands", "command %q can pass without running anything (%s); a missing tool must fail the check, so remove the guard", strings.TrimSpace(line), guard)
}
}
}
if stage.EffectiveType(s.Type) == stage.HumanType {
continue // a person bounds a human stage's loop
}