This repository has been archived on 2026-08-04. You can view files and clone it, but cannot push or open issues or pull requests.
orchestrator/agent-team/tests/test_transport_base.py

92 lines
2.6 KiB
Python

"""Unit tests for agent_team.transport.base (§3.3.1)."""
from __future__ import annotations
from typing import Any
import pytest
from agent_team.transport.base import (
GITHUB_MARKER_TEMPLATE,
NormalizedAnswer,
QuestionSet,
Transport,
)
def test_transport_is_abstract() -> None:
with pytest.raises(TypeError):
Transport() # type: ignore[abstract]
def test_question_set_fields() -> None:
qs = QuestionSet(
thread_id="t1",
question_id="q1",
turn=2,
questions=["a?", "b?"],
context={"repo": "x"},
)
assert qs.thread_id == "t1"
assert qs.question_id == "q1"
assert qs.turn == 2
assert qs.questions == ["a?", "b?"]
assert qs.context == {"repo": "x"}
def test_question_set_context_defaults_empty() -> None:
qs = QuestionSet(thread_id="t", question_id="q", turn=0, questions=[])
assert qs.context == {}
def test_normalized_answer_fields() -> None:
ans = NormalizedAnswer(question_id="q1", answer={"choice": 1}, via="slack")
assert ans.question_id == "q1"
assert ans.answer == {"choice": 1}
assert ans.via == "slack"
def test_concrete_subclass_implements_contract() -> None:
class FakeTransport(Transport):
def __init__(self) -> None:
self.posted: dict[str, Any] = {}
def post_question(
self, *, thread_id, question_id, turn, question_set, deadline
) -> str:
ref = f"slack-ts-{question_id}"
self.posted = {
"thread_id": thread_id,
"question_id": question_id,
"turn": turn,
"deadline": deadline,
"ref": ref,
}
return ref
def parse_answer(self, raw) -> tuple[str, Any, str]:
na = NormalizedAnswer(
question_id=raw["callback_id"], answer=raw["value"], via="slack"
)
return na.question_id, na.answer, na.via
t = FakeTransport()
qs = QuestionSet(thread_id="t1", question_id="q1", turn=0, questions=["?"])
ref = t.post_question(
thread_id="t1",
question_id="q1",
turn=0,
question_set=qs,
deadline="2026-06-18T00:00:00Z",
)
assert ref == "slack-ts-q1"
assert t.posted["question_id"] == "q1"
parsed = t.parse_answer({"callback_id": "q1", "value": "yes"})
assert parsed == ("q1", "yes", "slack")
def test_github_marker_embeds_question_id() -> None:
marker = GITHUB_MARKER_TEMPLATE.format(question_id="abc123")
assert marker == "<!-- shq:abc123 -->"
assert "abc123" in marker