package pipeline import ( "git.a-wan.net/alan/pipelines/internal/protocol" "os" "testing" ) func TestNestedForkShowcaseIsForwardOnly(t *testing.T) { source, err := os.ReadFile("testdata/nested-forks.md") if err != nil { t.Fatal(err) } graph, err := Parse(string(source)) if err != nil { t.Fatal(err) } if len(graph.Stages) != 7 { t.Fatalf("expected seven stages, got %d", len(graph.Stages)) } indices := map[string]int{} for i, s := range graph.Stages { indices[s.Key] = i } forks := 0 for i, s := range graph.Stages { branches := 0 for _, target := range s.Edges { if protocol.IsTerminal(target) { continue } branches++ if indices[target] <= i { t.Fatalf("backward/cyclic edge %s -> %s", s.Key, target) } } if branches == 2 { forks++ } else if branches > 2 { t.Fatal("expected binary forks only") } } if forks != 2 || graph.Stages[1].Edges["detailed"] != "detail_router" || graph.Stages[3].Edges["walkthrough"] != "walkthrough" || graph.Stages[3].Edges["reference"] != "reference" { t.Fatal("expected one fork nested under the detailed branch") } for _, key := range []string{"brief_answer", "walkthrough", "reference"} { if graph.Stages[indices[key]].Edges["success"] != "delivery" { t.Fatal("content paths must converge on delivery") } } }