"""PostHog-loop playbook, step 8: the holdout experiment.

The experiment takes its salt from the protocol (declared in step 4), so who
is held out was fixed before anything was scored. Held-out users are never
delivered under the experiment's purpose; they are the comparison group.
"""

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))  # playbooks/playbook_api.py
from playbook_api import Api, State

api, state = Api(), State("posthog-loop")

experiment = api.post(
    "/slots/growth/experiments",
    {"holdout_fraction": 0.2, "purpose": "general", "protocol_id": state["protocol_id"]},
    key="posthog-loop-experiment",
)
print(f"experiment: {experiment['status']}, holdout_fraction: {experiment['holdout_fraction']}")
state.update(
    experiment_id=experiment["experiment_id"],
    holdout_fraction=experiment["holdout_fraction"],
)
