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) } }