ae4526d87c
- turn.RenderPreviousAttempt: bounded "# Previous attempt" section (attempt number, failing stage, bounded diagnostic, partial-edits note). - In-stage retries (stage/model_run.go) append it instead of resending an identical prompt; run retries (resume and restart) add it to the first model visit's input.md, numbering attempts along the retry chain. - --input-file retry overrides render only the override keys in input.md, labelled "# Operator correction" (the step row keeps the merged input). - Essential memory (memory.md) inlines a revisiting stage's own last handoff, bounded, besides the previous stage's handoff. - Interrupted runs can be retried: resume reruns the interrupted visit, or starts the next stage after the last completed visit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
67 lines
2.9 KiB
Go
67 lines
2.9 KiB
Go
package turn
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestRenderPreviousAttemptIsBoundedAndNamesTheFailure(t *testing.T) {
|
|
text := RenderPreviousAttempt(PreviousAttempt{Attempt: 3, Stage: "land", Run: 42, Diagnostic: "checks failed: go test ./...\n~~~\n" + strings.Repeat("y", 9000)})
|
|
for _, want := range []string{"# Previous attempt", "attempt 3", "run 42", "stage land", "checks failed", "Partial edits", "[truncated]"} {
|
|
if !strings.Contains(text, want) {
|
|
t.Fatalf("missing %q:\n%s", want, text)
|
|
}
|
|
}
|
|
if len(text) > PreviousAttemptCap+500 {
|
|
t.Fatalf("section is %d bytes", len(text))
|
|
}
|
|
// A diagnostic cannot close the fence early.
|
|
if strings.Count(text, "~~~") != 2 {
|
|
t.Fatalf("diagnostic broke the fence:\n%s", text)
|
|
}
|
|
empty := RenderPreviousAttempt(PreviousAttempt{Stage: "plan"})
|
|
if !strings.Contains(empty, "No diagnostic was recorded.") || !strings.Contains(empty, "attempt 2 of stage plan") {
|
|
t.Fatalf("empty diagnostic rendering:\n%s", empty)
|
|
}
|
|
}
|
|
|
|
// TestEssentialMemoryRevisitShowsOwnPreviousHandoff proves a stage that runs
|
|
// again (a reviewer after the implementer fixed its findings) sees its own last
|
|
// handoff, bounded, besides the immediately previous stage's handoff.
|
|
func TestEssentialMemoryRevisitShowsOwnPreviousHandoff(t *testing.T) {
|
|
entries := feedbackLoopEntries()
|
|
entries = append(entries, MemoryEntry{Stage: "code", Visit: 2, Outcome: "success", Output: "# handoff\n\nFixed the lock leak and added the eviction test.\n"})
|
|
memory := RenderEssential(Essential{Task: "Add a cache.", StageKey: "review", Entries: entries, InputPath: "in.md", HistoryPath: "hist.md"})
|
|
if len(memory) > EssentialCap {
|
|
t.Fatalf("essential memory is %d bytes, over the cap", len(memory))
|
|
}
|
|
for _, want := range []string{
|
|
"## Previous stage: code · visit 2",
|
|
"Fixed the lock leak",
|
|
"## This stage's previous visit: review · visit 1 · outcome changes_requested",
|
|
"cache.go:42 leaks the lock on the error path.",
|
|
} {
|
|
if !strings.Contains(memory, want) {
|
|
t.Fatalf("memory missing %q:\n%s", want, memory)
|
|
}
|
|
}
|
|
if strings.Contains(memory, "Long preamble.") {
|
|
t.Fatalf("own handoff carried non-handoff text:\n%s", memory)
|
|
}
|
|
|
|
// Long own handoffs are bounded with a pointer to history.md.
|
|
entries[2].Output = "# handoff\n\n" + paragraph("finding", 5000)
|
|
memory = RenderEssential(Essential{Task: "Add a cache.", StageKey: "review", Entries: entries, InputPath: "in.md", HistoryPath: "hist.md"})
|
|
if len(memory) > EssentialCap || !strings.Contains(memory, "full text in history.md") {
|
|
t.Fatalf("own handoff not bounded (%d bytes):\n%s", len(memory), memory)
|
|
}
|
|
|
|
// No own section on a first visit or when the previous turn is this stage.
|
|
for _, key := range []string{"land", "code"} {
|
|
memory = RenderEssential(Essential{Task: "Add a cache.", StageKey: key, Entries: entries})
|
|
if strings.Contains(memory, "This stage's previous visit") {
|
|
t.Fatalf("%s got an own-handoff section:\n%s", key, memory)
|
|
}
|
|
}
|
|
}
|