Files
pipelines/internal/turn/integration_test.go
T
alan e37b864c40 stage turns: replace JSON results with file-based markdown turns
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 .
2026-10-19 22:27:44 +01:00

51 lines
1.7 KiB
Go

package turn
import (
"errors"
"os"
"testing"
)
// TestLayoutRenderAndParseRoundTrip exercises the three public pieces as one
// turn: prepare the layout, render the first input and accumulated memory,
// then parse the output the model returns.
func TestLayoutRenderAndParseRoundTrip(t *testing.T) {
root := t.TempDir()
paths := Layout(root, 2, "review")
if err := paths.Ensure(); err != nil {
t.Fatal(err)
}
input := RenderInput("the original run prompt", "first visit result\n")
if err := os.WriteFile(paths.InputPath, []byte(input), 0o600); err != nil {
t.Fatal(err)
}
memory := RenderMemory([]MemoryEntry{{
Stage: "implementer",
Visit: 1,
Output: "first visit result",
PublicFiles: []string{"public/screenshot.png"},
}})
if err := os.WriteFile(paths.MemoryPath, []byte(memory), 0o600); err != nil {
t.Fatal(err)
}
output := "# Notes\n\nChecked the diff.\n\n# outcome\napproved\n\n# Findings\n\nnone\n"
if err := os.WriteFile(paths.OutputPath, []byte(output), 0o600); err != nil {
t.Fatal(err)
}
if got, err := os.ReadFile(paths.InputPath); err != nil || string(got) != input {
t.Fatalf("input.md = %q, %v", got, err)
}
if got, err := os.ReadFile(paths.MemoryPath); err != nil || string(got) != memory {
t.Fatalf("memory.md = %q, %v", got, err)
}
outcome, body, err := ParseOutput(output, []string{"success", "approved", "error"})
if err != nil || outcome != "approved" || body != "\n# Findings\n\nnone\n" {
t.Fatalf("ParseOutput() = %q, %q, %v", outcome, body, err)
}
missing, _, err := ParseOutput("# Notes\n\nno heading\n", []string{"success"})
if missing != "" || !errors.Is(err, ErrMissingOutcome) {
t.Fatalf("missing outcome = %q, %v", missing, err)
}
}