Buckets:

download
raw
2.98 kB
"""Tests for persisted agent conversation JSON schema (``hof.agent.conversation_state``)."""
from __future__ import annotations
import pytest
from hof.agent import (
MAX_CONVERSATION_STATE_BYTES,
enforce_max_conversation_state_bytes,
normalize_conversation_state_for_storage,
validate_conversation_state,
)
def test_validate_minimal_round_trip() -> None:
raw = {"version": 1, "thread": [], "mutationOutcomes": {}}
model = validate_conversation_state(raw)
stored = normalize_conversation_state_for_storage(model)
assert stored["version"] == 1
assert stored["thread"] == []
assert stored["mutationOutcomes"] == {}
def test_validate_accepts_plan_object() -> None:
raw = {
"version": 1,
"thread": [],
"mutationOutcomes": {},
"plan": {"phase": "ready", "text": "- [ ] step", "runId": "r1"},
}
model = validate_conversation_state(raw)
assert model.plan is not None
assert model.plan.phase == "ready"
assert model.plan.text.startswith("- [ ]")
assert model.plan.run_id == "r1"
def test_validate_accepts_plan_clarifying_and_todo_indices() -> None:
raw = {
"version": 1,
"thread": [],
"mutationOutcomes": {},
"plan": {
"phase": "clarifying",
"text": "",
"runId": "r1",
"clarificationBarrier": {
"runId": "run-x",
"clarificationId": "cid-y",
"questions": [
{
"id": "q1",
"prompt": "Scope?",
"options": [
{"id": "a", "label": "A"},
{"id": "b", "label": "B"},
],
},
],
},
"planTodoDoneIndices": [0, 2],
},
}
model = validate_conversation_state(raw)
assert model.plan is not None
assert model.plan.phase == "clarifying"
assert model.plan.clarification_barrier is not None
assert model.plan.clarification_barrier["clarificationId"] == "cid-y"
assert model.plan.plan_todo_done_indices == [0, 2]
def test_validate_accepts_camel_case_alias() -> None:
raw = {
"version": 1,
"thread": [{"kind": "user", "id": "1", "content": "hi"}],
"mutationOutcomes": {"p1": True},
}
model = validate_conversation_state(raw)
assert model.thread == raw["thread"]
assert model.mutation_outcomes == {"p1": True}
def test_validate_rejects_bad_version() -> None:
with pytest.raises(ValueError, match="unsupported conversation state version"):
validate_conversation_state({"version": 2, "thread": [], "mutationOutcomes": {}})
def test_enforce_max_bytes() -> None:
big = {"x": "a" * (MAX_CONVERSATION_STATE_BYTES + 10)}
with pytest.raises(ValueError, match="conversation state too large"):
enforce_max_conversation_state_bytes(big)

Xet Storage Details

Size:
2.98 kB
·
Xet hash:
411b525628dad895bd6eb88eb1d4f598e20ae87aabcd3ad5e5b6b8cde63b0833

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.