"""Run every assertion in a task against a completed trial's worktree."""

from __future__ import annotations

from pathlib import Path

from ablate.assertions.types import AssertionResult, evaluate
from ablate.task import Task


def run_assertions(task: Task, worktree: Path) -> tuple[list[AssertionResult], bool]:
    """Returns (results, passed). `passed` is the conjunction of all
    `required` assertions — non-required ones are reported but excluded
    from the roll-up (docs/04-task-suite.md)."""
    base_commit = task.base_commit or "HEAD"
    results = [evaluate(a, worktree, base_commit) for a in task.assertions]
    passed = all(r.passed for r in results if r.required)
    return results, passed
