Files
pipelines/internal/pipeline/lint_loops_test.go
T
alan 34b8b94223 Engine: run findings ledger, findings gate, loop continuation, larger memory, loop lint, retry partial work, resume_session
- Runner-owned findings ledger per run: stages report a # findings section
  (new items and F<n> status changes); stable IDs, persisted (run_loop_state),
  in RunDetail.findings, findings.md, memory.md, inspect.
- type=findings gate stage routes open/clear on the ledger mechanically.
- retry --extra-visits N [--stage KEY] continues an exhausted loop; limits
  on_exhausted=decide parks the run on accept/continue/abort.
- Essential memory cap 20 KB, task never truncated, handoff and open findings
  ahead of the outcome ledger.
- Lint rejects limits.on outcomes on forward edges; warns on ineffective
  limits and resume_session.
- A resumed retry carries the failed visit's output.md and private/ under
  previous-attempt/.
- resume_session=true resumes a Claude stage's previous session on loop visits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 14:22:28 +00:00

110 lines
5.1 KiB
Go

package pipeline
import (
"strings"
"testing"
)
func TestLintRejectsForwardLimitOutcomes(t *testing.T) {
// Research runs 100/101: "on" listed the forward success edge, so a good
// result on the last allowed visit failed the run.
source := lintSource(
modelStage("research", "Research.", "read", "success -> write\nretry -> research\nerror -> #failure", "```limits\n{\"max_visits\":3,\"on\":[\"success\",\"retry\"]}\n```"),
modelStage("write", "Write.", "read", "success -> #success\nerror -> #failure", ""),
)
errs, _ := lintRules(t, source)
if len(errs["limits"]) != 1 || !strings.Contains(errs["limits"][0], `limits.on lists "success", but success -> write is a forward edge`) {
t.Fatalf("limits errors = %v", errs["limits"])
}
}
func TestLintWarnsAboutIneffectiveLoopSettings(t *testing.T) {
checks := "```checks\nnone: focused tests only\n```"
source := lintSource(
modelStage("implement", "Implement.", "read\nedit", "success -> review\nerror -> #failure", checks+"\n\n```limits\n{\"max_visits\":2}\n```"),
modelStage("review", "Review.", "read", "approved -> land\nrejected -> implement\nerror -> #failure", "```limits\n{\"max_visits\":3,\"on\":[\"rejected\"],\"on_exhausted\":\"decide\",\"accept_to\":\"land\"}\n```"),
modelStage("land", "Land.", "read", "success -> #success\nerror -> #failure", "```limits\n{\"max_visits\":2}\n```"),
)
errs, warns := lintRules(t, source)
if len(errs["limits"]) != 0 {
t.Fatalf("unexpected errors %v", errs)
}
joined := strings.Join(warns["limits"], "\n")
for _, want := range []string{"implement has max_visits 2, lower than this stage's 3", "stage land: limits: limits has no effect"} {
if !strings.Contains(joined, want) {
t.Fatalf("warnings missing %q:\n%s", want, joined)
}
}
if strings.Contains(joined, "stage review: limits: limits has no effect") || strings.Contains(joined, "stage implement: limits: limits has no effect") {
t.Fatalf("review and implement are on a loop:\n%s", joined)
}
}
func TestLintWarnsAboutResumeSession(t *testing.T) {
stageWith := func(key, tools, edges, configs, extra string) string {
return "# stage " + key + "\n\n```prompt\nWork.\n```\n\n```configs\nprovider=opencode-go\nmodel=deepseek-v4.1-flash\n" + configs + "\n```\n\n```tools\n" + tools + "\n```\n\n```edges\n" + edges + "\n```\n\n" + extra + "\n"
}
source := lintSource(
stageWith("implement", "read\nedit", "success -> review\nerror -> #failure", "resume_session=true", "```checks\nnone: focused\n```"),
stageWith("review", "read", "approved -> #success\nrejected -> implement\nerror -> #failure", "resume_session=true", "```limits\n{\"max_visits\":3,\"on\":[\"rejected\"]}\n```"),
)
_, warns := lintRules(t, source)
joined := strings.Join(warns["resume_session"], "\n")
for _, want := range []string{"stage implement: resume_session: resume_session is supported only by harness=claude", "stage review: resume_session: resume_session on a read-only stage"} {
if !strings.Contains(joined, want) {
t.Fatalf("warnings missing %q:\n%s", want, joined)
}
}
if strings.Contains(joined, "has no effect") {
t.Fatalf("both stages loop:\n%s", joined)
}
}
func TestParseValidatesExhaustionSettings(t *testing.T) {
base := func(limits string) string {
return lintSource(
modelStage("implement", "Implement.", "read", "success -> review\nerror -> #failure", ""),
modelStage("review", "Review.", "read", "approved -> #success\nrejected -> implement\nerror -> #failure", "```limits\n"+limits+"\n```"),
)
}
for limits, want := range map[string]string{
`{"max_visits":3,"on_exhausted":"ask"}`: "on_exhausted must be fail or decide",
`{"max_visits":3,"accept_to":"implement"}`: "accept_to needs",
`{"max_visits":3,"on_exhausted":"decide","accept_to":"nowhere"}`: "accept_to \"nowhere\" is not a stage",
} {
if _, err := Parse(base(limits)); err == nil || !strings.Contains(err.Error(), want) {
t.Fatalf("%s: err = %v, want %q", limits, err, want)
}
}
if _, err := Parse(base(`{"max_visits":3,"on":["rejected"],"on_exhausted":"decide","accept_to":"#success"}`)); err != nil {
t.Fatal(err)
}
}
func TestParseFindingsGateStage(t *testing.T) {
gate := func(configs, edges string) string {
return lintSource(
modelStage("review", "Review.", "read", "success -> triage\nerror -> #failure", ""),
"# stage triage\n\n```configs\ntype=findings\n"+configs+"\n```\n\n```edges\n"+edges+"\n```\n",
modelStage("fix", "Fix.", "read", "success -> review\nerror -> #failure", ""),
)
}
g, err := Parse(gate("severity=minor\norigin=any", "open -> fix\nclear -> #success"))
if err != nil {
t.Fatal(err)
}
if g.Stages[1].Type != "findings" {
t.Fatalf("type = %q", g.Stages[1].Type)
}
for _, tc := range []struct{ configs, edges, want string }{
{"severity=huge", "open -> fix\nclear -> #success", "severity must be"},
{"origin=old", "open -> fix\nclear -> #success", "origin must be"},
{"", "open -> fix", "requires an edge for outcome clear"},
{"", "open -> fix\nclear -> #success\nmaybe -> fix", "outcomes are open and clear"},
} {
if _, err := Parse(gate(tc.configs, tc.edges)); err == nil || !strings.Contains(err.Error(), tc.want) {
t.Fatalf("%+v: err = %v", tc, err)
}
}
}