rein-aharness/tests/test_approaches.py
tegwick 20e6f381f6 feat(runtime): enforce governed mutation boundaries
Assistant: codex
Assistant-Model: gpt-5.6-sol
Assistant-Session: 01a06ba0-10aa-7ea0-b20a-4f3fac39efe9
2026-09-04 11:25:07 +02:00

142 lines
3.6 KiB
Python

"""Pure approach selection tests (REIN-A-0002-T02)."""
from __future__ import annotations
from datetime import date
from rein_aharness.approaches import (
APPROACH_AGENT_SESSION,
APPROACH_BRIEF_DAILY,
APPROACH_BRIEF_WEEKLY,
APPROACH_FI_RESEARCH_BRIEF,
APPROACH_MAIL_PIPELINE,
APPROACH_UNMATCHED,
execute_approach,
legacy_approaches_enabled,
select_approach,
)
from rein_aharness.ops_run_client import OpsRun
def _run(**kwargs) -> OpsRun:
base = dict(
id="r",
activity_definition_id="",
idempotency_key="k",
target_repo="x",
title="",
description="",
labels=[],
)
base.update(kwargs)
return OpsRun(**base)
def test_select_fi_by_label() -> None:
assert (
select_approach(
_run(labels=["automated", "research-brief", "freedom-intelligence"])
)
== APPROACH_FI_RESEARCH_BRIEF
)
def test_select_fi_by_blob() -> None:
assert (
select_approach(
_run(
labels=["automated"],
activity_definition_id="fi-daily-research-brief",
title="FI daily research brief",
)
)
== APPROACH_FI_RESEARCH_BRIEF
)
def test_select_binky_rhythm() -> None:
assert (
select_approach(_run(labels=["binky", "rhythm", "automated"]))
== APPROACH_BRIEF_DAILY
)
def test_select_binky_weekly_review_requires_binky_and_weekly_label() -> None:
assert (
select_approach(
_run(labels=["binky", "weekly-review", "automated"])
)
== APPROACH_BRIEF_WEEKLY
)
def test_select_binky_weekly_review_by_definition() -> None:
assert (
select_approach(
_run(activity_definition_id="binky-weekly-review-prep")
)
== APPROACH_BRIEF_WEEKLY
)
def test_weekly_review_label_alone_is_unmatched() -> None:
assert select_approach(_run(labels=["weekly-review"])) == APPROACH_UNMATCHED
def test_select_mail_intake() -> None:
assert (
select_approach(_run(labels=["mail-intake", "automated"]))
== APPROACH_MAIL_PIPELINE
)
def test_select_agent_session() -> None:
assert (
select_approach(_run(labels=["agent-session", "automated"]))
== APPROACH_AGENT_SESSION
)
def test_select_hint_overrides() -> None:
assert (
select_approach(
_run(labels=["automated"], approach_hint="fi-research-brief")
)
== APPROACH_FI_RESEARCH_BRIEF
)
def test_unmatched() -> None:
assert select_approach(_run(labels=["automated"], title="misc hygiene")) == (
APPROACH_UNMATCHED
)
def test_fi_before_generic_automated() -> None:
"""research-brief must not fall through to unmatched when only automated."""
assert (
select_approach(_run(labels=["research-brief"])) == APPROACH_FI_RESEARCH_BRIEF
)
def test_legacy_approaches_require_non_expired_explicit_date() -> None:
today = date(2026, 9, 4)
assert legacy_approaches_enabled("2026-09-04", today=today) is True
assert legacy_approaches_enabled("2026-09-03", today=today) is False
assert legacy_approaches_enabled("true", today=today) is False
assert legacy_approaches_enabled("", today=today) is False
def test_execute_approach_refuses_profile_absent_route_without_flag(
monkeypatch,
) -> None:
monkeypatch.delenv("AGENT_HARNESS_LEGACY_APPROACHES_UNTIL")
result = execute_approach(
_run(labels=["research-brief"], target_repo="not-resolved"),
report_to_hub=False,
)
assert result.ok is False
assert result.reopen is False
assert "compatibility routing is disabled" in result.reason