turn: add file-based stage turn foundation
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
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 TestRenderInputLaterTurnShowsOnlyPreviousOutput(t *testing.T) {
|
||||
previous := "## Result\n\n- changed `internal/turn`\n\n```diff\n+new line\n```\n"
|
||||
got := RenderInput("the original prompt", previous)
|
||||
want := "# Previous turn output\n\n" + previous
|
||||
if got != want {
|
||||
t.Fatalf("later turn input = %q, want %q", got, want)
|
||||
}
|
||||
if strings.Contains(got, "the original prompt") {
|
||||
t.Fatal("later turn input repeated the run prompt")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderMemory(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 := RenderMemory(entries); got != want {
|
||||
t.Fatalf("RenderMemory() = %q, want %q", got, want)
|
||||
}
|
||||
if again := RenderMemory(entries); again != want {
|
||||
t.Fatalf("RenderMemory() is not deterministic: %q", again)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderMemoryEmbedsOutputVerbatim(t *testing.T) {
|
||||
output := "## Notes\n\n```md\n# outcome success\n```\n\nlast line without newline"
|
||||
entries := []MemoryEntry{{Stage: "build", Visit: 3, Output: output, PublicFiles: []string{"public/report.md"}}}
|
||||
got := RenderMemory(entries)
|
||||
if !strings.Contains(got, output) {
|
||||
t.Fatalf("output was not embedded verbatim:\n%s", got)
|
||||
}
|
||||
if !strings.Contains(got, "- public/report.md\n") {
|
||||
t.Fatalf("public file list missing:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderMemoryEmpty(t *testing.T) {
|
||||
if got := RenderMemory(nil); got != "" {
|
||||
t.Fatalf("RenderMemory(nil) = %q, want empty", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user