Files
pipelines/internal/turn/layout_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

72 lines
2.2 KiB
Go

package turn
import (
"os"
"path/filepath"
"testing"
)
func TestLayoutIsDeterministic(t *testing.T) {
runDir := filepath.Join(t.TempDir(), "run")
want := Paths{
RunDir: runDir,
Sequence: 2,
StageKey: "implementer",
TurnDir: filepath.Join(runDir, "stages", "02-implementer"),
InputPath: filepath.Join(runDir, "stages", "02-implementer", "input.md"),
MemoryPath: filepath.Join(runDir, "stages", "02-implementer", "memory.md"),
HistoryPath: filepath.Join(runDir, "stages", "02-implementer", "history.md"),
OutputPath: filepath.Join(runDir, "stages", "02-implementer", "output.md"),
PrivateDir: filepath.Join(runDir, "stages", "02-implementer", "private"),
PublicDir: filepath.Join(runDir, "public"),
}
got := Layout(runDir, 2, "implementer")
if got != want {
t.Fatalf("Layout() = %#v, want %#v", got, want)
}
if again := Layout(runDir, 2, "implementer"); again != got {
t.Fatalf("Layout() is not deterministic: %#v then %#v", got, again)
}
}
func TestLayoutSupportsLongSequences(t *testing.T) {
got := Layout("/runs/one", 123, "review")
want := filepath.Join("/runs/one", "stages", "123-review")
if got.TurnDir != want {
t.Fatalf("TurnDir = %q, want %q", got.TurnDir, want)
}
}
func TestPathsEnsureIsIdempotentAndPreservesFiles(t *testing.T) {
paths := Layout(t.TempDir(), 1, "build")
if err := paths.Ensure(); err != nil {
t.Fatalf("Ensure() error: %v", err)
}
for _, dir := range []string{paths.TurnDir, paths.PrivateDir, paths.PublicDir} {
info, err := os.Stat(dir)
if err != nil {
t.Fatalf("stat %s: %v", dir, err)
}
if !info.IsDir() {
t.Fatalf("%s is not a directory", dir)
}
}
kept := filepath.Join(paths.PrivateDir, "keep.txt")
if err := os.WriteFile(kept, []byte("preserve me"), 0o600); err != nil {
t.Fatal(err)
}
if err := paths.Ensure(); err != nil {
t.Fatalf("second Ensure() error: %v", err)
}
body, err := os.ReadFile(kept)
if err != nil {
t.Fatalf("read preserved file: %v", err)
}
if string(body) != "preserve me" {
t.Fatalf("preserved file = %q", body)
}
if _, err := os.Stat(paths.InputPath); !os.IsNotExist(err) {
t.Fatalf("Ensure() should not create the input file, stat error = %v", err)
}
}