package taskplan // ValidatePlaybook retains publication safeguards even for a saved investigation. // Investigation execution is projected separately, ending at its person checkpoint. func ValidatePlaybook(kind Kind, steps []Step) error { if kind == Recommendation { return ErrInvalid } p := Plan{Kind: kind, ProjectID: 1, Steps: steps} if kind == Investigation { p.Kind = Feature research := 0 for _, s := range steps { switch s.Action { case "scope", "investigate", "recommend": research++ case "review", "checks", "person": default: return ErrInvalid } } if research == 0 { return ErrInvalid } } if err := Validate(p); err != nil { return err } n := len(steps) if n < 3 { return ErrInvalid } end := n - 1 if end > 0 && steps[end-1].Action == "publish" { end-- } if end < 2 || steps[end-2].Action != "review" || steps[end-1].Action != "checks" { return ErrInvalid } if kind == Investigation && Validate(Plan{Kind: kind, ProjectID: 1, Steps: PlaybookSteps(kind, steps)}) != nil { return ErrInvalid } return nil } func PlaybookSteps(kind Kind, steps []Step) []Step { out := []Step{} for _, s := range steps { if kind == Investigation && (s.Action == "review" || s.Action == "checks") { continue } s.DependsOn = append([]string(nil), s.DependsOn...) out = append(out, s) } return Normalize(Plan{Kind: kind, Steps: out}).Steps }