Files
pipelines/internal/turn/render_test.go
T
alan 538143554c Split stage memory into capped essential memory.md and full history.md
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.
2026-11-04 13:00:48 +00:00

85 lines
2.7 KiB
Go

package turn
import (
"strings"
"testing"
)
func TestRenderInputFirstTurnIsTheRunPrompt(t *testing.T) {
prompt := "# Task\n\nImplement the thing.\n"
if got := RenderInput(prompt, ""); got != prompt {
t.Fatalf("first turn input = %q, want prompt verbatim", got)
}
if got := RenderInput(prompt, " \r\n\t"); got != prompt {
t.Fatalf("blank previous output should behave as the first turn, got %q", got)
}
}
func TestRenderInputLaterTurnKeepsTheTaskAndThePreviousOutput(t *testing.T) {
previous := "## Result\n\n- changed `internal/turn`\n\n```diff\n+new line\n```\n"
got := RenderInput("# Goal\n\nThe original prompt.\n", previous)
want := "# Run task\n\n### Goal\n\nThe original prompt.\n\n# Previous turn output\n\n" + previous
if got != want {
t.Fatalf("later turn input = %q, want %q", got, want)
}
// Without a recorded prompt the previous output stands alone.
if got := RenderInput("", previous); got != "# Previous turn output\n\n"+previous {
t.Fatalf("promptless later input = %q", got)
}
}
func TestRenderHistory(t *testing.T) {
entries := []MemoryEntry{
{
Stage: "planner",
Visit: 1,
Output: "# Plan\n\nDo the work.",
PublicFiles: []string{"public/b.md", "public/a.md", "public/a.md"},
},
{
Stage: "reviewer",
Visit: 2,
Output: "No public files.\n",
},
}
want := "## planner · visit 1\n\n" +
"### Plan\n\nDo the work.\n\n" +
"Files added to public/:\n- public/a.md\n- public/b.md\n\n" +
"## reviewer · visit 2\n\n" +
"No public files.\n\n" +
"Files added to public/:\n- _(none)_\n"
if got := RenderHistory(entries); got != want {
t.Fatalf("RenderHistory() = %q, want %q", got, want)
}
if again := RenderHistory(entries); again != want {
t.Fatalf("RenderHistory() is not deterministic: %q", again)
}
}
func TestRenderHistoryDemotesBodyHeadingsButNotFences(t *testing.T) {
output := "## Notes\n\n```md\n# outcome success\n```\n\n#### Deep\n\nlast line without newline"
entries := []MemoryEntry{{Stage: "build", Visit: 3, Output: output, PublicFiles: []string{"public/report.md"}}}
got := RenderHistory(entries)
if !strings.Contains(got, "#### Notes") {
t.Fatalf("body heading was not demoted:\n%s", got)
}
if !strings.Contains(got, "###### Deep") {
t.Fatalf("a deep heading was not capped at H6:\n%s", got)
}
if !strings.Contains(got, "```md\n# outcome success\n```") {
t.Fatalf("a fenced heading was changed:\n%s", got)
}
if !strings.Contains(got, "- public/report.md\n") {
t.Fatalf("public file list missing:\n%s", got)
}
if strings.Contains(got, "\n## Notes\n") {
t.Fatalf("a body heading still looks like a turn section:\n%s", got)
}
}
func TestRenderHistoryEmpty(t *testing.T) {
if got := RenderHistory(nil); got != "" {
t.Fatalf("RenderHistory(nil) = %q, want empty", got)
}
}