e37b864c40
Each model visit now gets <run>/stages/<seq>-<stage>/ with input.md, memory.md, output.md, private/ and a shared run-level public/. The model reads the two input files, follows the stage's instructions verbatim and returns complete markdown; only the # outcome section is parsed. - add internal/turn layout, render and output parsing - write input.md/memory.md before a visit and output.md from the final message; inventory all turn files as stage artifacts - accumulate completed turns and system-written public file additions in memory, including across retries and resume - remove the JSON envelope, strict field validation, line format and the repair ladder for model stages - republish pipeline authoring prompts and docs in the new style Checks: go build ./..., go vet ./..., go test -count=1 ./..., gofmt -l .
78 lines
3.0 KiB
Go
78 lines
3.0 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
"git.a-wan.net/alan/pipelines/internal/stage"
|
|
)
|
|
|
|
// TestRuntimeLimitAndReviewLoop exercises the runner-owned visit limit on a
|
|
// worker -> review loop. Model stages now read turn files rather than selected
|
|
// memory fields, so the fake stage hands its result forward through the previous
|
|
// output map and the loop is bounded by limits alone.
|
|
func TestRuntimeLimitAndReviewLoop(t *testing.T) {
|
|
for _, approveLast := range []bool{false, true} {
|
|
t.Run(map[bool]string{false: "exhaustion", true: "last review approves"}[approveLast], func(t *testing.T) {
|
|
ctx := context.Background()
|
|
store, err := pipeline.Open(filepath.Join(t.TempDir(), "run.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer store.Close()
|
|
source := pipeline.Template([]string{"planner", "worker", "review"}, true)
|
|
source = strings.Replace(source, "# stage review", "# stage review\n\n```limits\n{\"max_visits\":3,\"on\":[\"rejected\"]}\n```", 1)
|
|
source = strings.Replace(source, "success -> #success", "success -> #success\nrejected -> worker", 1)
|
|
if _, err := store.Submit(ctx, "bounded", source); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
items, _ := store.List(ctx)
|
|
runner, err := newRunner(ctx, store)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
calls := map[string]int{}
|
|
runner.execute = func(_ context.Context, def stage.Definition, _ stage.Values) (stage.Result, error) {
|
|
calls[def.Key]++
|
|
if _, ok := def.Blocks["limits"]; ok {
|
|
t.Fatal("policy exposed to model")
|
|
}
|
|
switch def.Key {
|
|
case "planner":
|
|
return stage.Result{Outcome: "success", Output: stage.Values{"plan": "do task", "checks": "inspect actual files"}}, nil
|
|
case "worker":
|
|
return stage.Result{Outcome: "success", Output: stage.Values{"ui_revision": 0, "previous_verdict": "rejected"}}, nil
|
|
default:
|
|
if approveLast && calls["review"] == 3 {
|
|
return stage.Result{Outcome: "success", Output: stage.Values{"summary": "approved"}}, nil
|
|
}
|
|
return stage.Result{Outcome: "rejected", Output: stage.Values{"findings": "fix layout", "ui_revision": 0}}, nil
|
|
}
|
|
}
|
|
run := startRun(t, runner, items[0].ID, "test")
|
|
retained, err := store.GetRun(ctx, run.ID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if calls["review"] != 3 || calls["worker"] != 3 || len(retained.Steps) != 7 {
|
|
t.Fatal("model evaded runtime limit", calls, len(retained.Steps))
|
|
}
|
|
last := retained.Steps[6]
|
|
if last.Control == nil || last.Control.Visit != 3 {
|
|
t.Fatalf("missing retained control evidence: %+v", last)
|
|
}
|
|
if approveLast {
|
|
if retained.Status != "succeeded" || last.Control.LimitReached {
|
|
t.Fatal("last visit could not approve", retained)
|
|
}
|
|
} else if retained.Status != "failed" || !last.Control.LimitReached || last.Outcome != "rejected" || last.Target != protocol.FailureEnd {
|
|
t.Fatal("limit did not override route", last)
|
|
}
|
|
})
|
|
}
|
|
}
|