| 47 | ) |
| 48 | |
| 49 | def validate(self, config: dict[str, Any]) -> list[str]: |
| 50 | errors = super().validate(config) |
| 51 | if "condition" not in config: |
| 52 | errors.append( |
| 53 | f"While step {config.get('id', '?')!r} is missing " |
| 54 | f"'condition' field." |
| 55 | ) |
| 56 | max_iter = config.get("max_iterations") |
| 57 | if max_iter is not None: |
| 58 | # bool is a subclass of int, so isinstance(True, int) is True and |
| 59 | # True < 1 is False; reject bools explicitly so `max_iterations: true` |
| 60 | # is a type error rather than a silent single iteration. |
| 61 | if isinstance(max_iter, bool) or not isinstance(max_iter, int) or max_iter < 1: |
| 62 | errors.append( |
| 63 | f"While step {config.get('id', '?')!r}: " |
| 64 | f"'max_iterations' must be an integer >= 1." |
| 65 | ) |
| 66 | nested = config.get("steps", []) |
| 67 | if not isinstance(nested, list): |
| 68 | errors.append( |
| 69 | f"While step {config.get('id', '?')!r}: 'steps' must be a list." |
| 70 | ) |
| 71 | return errors |