package server import ( "strings" "testing" "git.a-wan.net/alan/pipelines/internal/protocol" ) // A failed stage whose error edge leads to another stage (a landing gate that // sends the run back to implement) must tell that stage what failed. func TestRecordFailureCarriesTheDiagnosticToTheNextStage(t *testing.T) { state := &runState{prompt: "Do the task", visits: map[string]int{"land": 1}} state.recordFailure(protocol.RunStep{ Stage: "land", Outcome: "error", Status: "failed", Diagnostic: "delivery check \"tool/test\" failed: exit status 1: FAILED test/a_test.dart: reads the row", }) if len(state.turns) != 1 || state.turns[0].Stage != "land" || state.turns[0].Outcome != "error" || state.turns[0].Visit != 1 { t.Fatalf("turns = %+v", state.turns) } input := state.turnInput() for _, want := range []string{"Do the task", "The land stage failed", "FAILED test/a_test.dart: reads the row"} { if !strings.Contains(input, want) { t.Errorf("next input lacks %q:\n%s", want, input) } } } func TestRecordFailureBoundsTheDiagnostic(t *testing.T) { state := &runState{visits: map[string]int{}} state.recordFailure(protocol.RunStep{Stage: "land", Outcome: "error", Diagnostic: "first failure\n" + strings.Repeat("x", 3*maxFailureDetail)}) output := state.turns[0].Output if len(output) > maxFailureDetail+400 { t.Fatalf("output is %d bytes", len(output)) } if !strings.Contains(output, "first failure") || !strings.Contains(output, "[truncated]") { t.Fatalf("output = %.200s", output) } }