from __future__ import annotations

from synaptopus.graph import categorizer_node, critic_node, generator_node, policy_node
from testsupport import (
    AcceptEvenHighPolicy,
    CounterState,
    EvenCritic,
    IncrementingGenerator,
    ThresholdCategorizer,
)


def test_graph_nodes_wrap_component_roles() -> None:
    state = CounterState(1)

    candidate = generator_node("gen", IncrementingGenerator()).run({"state": state})
    assert candidate.outputs["candidate"].value == 2

    critique = critic_node("crit", EvenCritic()).run(
        {"state": state, "candidate": candidate.outputs["candidate"].value}
    )
    assert critique.outputs["critique"].value is True

    category = categorizer_node("cat", ThresholdCategorizer()).run(
        {"state": state, "candidate": candidate.outputs["candidate"].value}
    )
    assert category.outputs["category"].value == "high"

    decision = policy_node("pol", AcceptEvenHighPolicy()).run(
        {
            "state": state,
            "candidate": candidate.outputs["candidate"].value,
            "critique": critique.outputs["critique"].value,
            "category": category.outputs["category"].value,
        }
    )
    assert decision.outputs["accepted"].value is True
    assert decision.outputs["decision"].value.label == "accept"
