Skip to content

CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.

fix(hitl): tighten frozen-dataclass test, clarify conftest helper intent, type AskUser.details

xf gong8635b7b86ff8
diff --git a/cubepi/hitl/policy.py b/cubepi/hitl/policy.py
index 7009eec..a95eae3 100644
--- a/cubepi/hitl/policy.py
+++ b/cubepi/hitl/policy.py
@@ -1,7 +1,7 @@
from __future__ import annotations
from dataclasses import dataclass
-from typing import Union
+from typing import Any, Union
@dataclass(frozen=True)
@@ -18,7 +18,7 @@ class Deny:
class AskUser:
prompt: str | None = None
timeout_seconds: float | None = None
- details: dict | None = None
+ details: dict[str, Any] | None = None
ApprovalDecision = Union[Approve, Deny, AskUser]
diff --git a/tests/hitl/conftest.py b/tests/hitl/conftest.py
index f4ca9af..17a0824 100644
--- a/tests/hitl/conftest.py
+++ b/tests/hitl/conftest.py
@@ -1,13 +1,20 @@
-# tests/hitl/conftest.py
+"""Shared test helpers for HITL test suite.
+
+`await_pending` is intentionally a plain async helper (not a pytest fixture)
+because downstream tests call it directly with the channel as a positional
+argument, e.g. `await await_pending(ch)`. Promoting it to a fixture would
+force every test that uses it to take it as a parameter and then invoke
+it — more boilerplate for no benefit.
+"""
+
import asyncio
async def await_pending(channel, *, timeout: float = 2.0) -> None:
"""Wait until channel.pending becomes non-None, or fail the test on timeout.
- Use this in tests that race a host coroutine against an awaiting agent.
Replaces the `while ch.pending is None: await asyncio.sleep(0)` pattern,
- which silently hangs if the host task crashes.
+ which silently hangs if the host coroutine crashes.
"""
async def _wait():
diff --git a/tests/hitl/test_types.py b/tests/hitl/test_types.py
index 8af806e..967f161 100644
--- a/tests/hitl/test_types.py
+++ b/tests/hitl/test_types.py
@@ -1,3 +1,5 @@
+import dataclasses
+
import pytest
from cubepi.hitl.types import (
Option,
@@ -78,5 +80,5 @@ def test_approval_decision_dataclasses_frozen():
u = AskUser(timeout_seconds=10.0)
assert d.reason == "forbidden"
assert u.timeout_seconds == 10.0
- with pytest.raises(Exception):
+ with pytest.raises(dataclasses.FrozenInstanceError):
a.foo = "bar" # frozen dataclass