Files
pipelines/internal/turn/integration_test.go
T
alan b1482b554b turn: keep the body written before a trailing outcome
ParseOutput returned only the text after the outcome value, so a stage that wrote
its result first and "# outcome" last handed the next stage "(no output)" — the
probe's Compose and Critique turns were both lost this way. The body is now the
whole document with just the outcome heading and value line removed, in order,
byte for byte. Tests cover a trailing and a mid-document outcome.
2026-10-19 23:31:06 +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 != "# Notes\n\nChecked the diff.\n\n\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)
}
}