538143554c
Every stage used to be told to read memory.md, the full output of every earlier turn (19 KB average, 92 KB max), and paid for it on each model call. memory.md is now essential memory, hard-capped at 4 KB and inlined in the prompt: the task, the previous stage's # handoff section (or its truncated output head), a one-line-per-stage outcome ledger and the server-captured changed files. history.md keeps the old full memory on disk; read-capable stages are pointed at it and input.md for on-demand detail, and it is never inlined. The prompt asks each stage for a short # handoff section.
51 lines
1.7 KiB
Go
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 := RenderHistory([]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)
|
|
}
|
|
}
|