optigami / tests /test_openenv_adapter.py
sissississi's picture
go-back (#6)
e9b7141
from openenv_runtime.environment import OpenEnvOrigamiEnvironment
from openenv_runtime.models import OrigamiAction, OrigamiObservation
def test_openenv_reset_returns_observation():
env = OpenEnvOrigamiEnvironment(mode="step", max_steps=8)
obs = env.reset(target_name="half_horizontal")
assert isinstance(obs, OrigamiObservation)
assert obs.done is False
assert obs.target_name == "half_horizontal"
assert hasattr(obs, "prompt") and obs.prompt
def test_openenv_step_single_fold_completes_simple_target():
env = OpenEnvOrigamiEnvironment(mode="step", max_steps=8)
env.reset(target_name="half_horizontal")
action = OrigamiAction(
from_point=[0.0, 0.5],
to_point=[1.0, 0.5],
assignment="V",
)
obs = env.step(action)
assert obs.reward is not None
assert obs.reward > 1.0
assert obs.done is True
def test_openenv_action_alias_from_to():
"""Client can send 'from' and 'to' (JSON-friendly) instead of from_point/to_point."""
action = OrigamiAction.model_validate({
"from": [0.0, 0.5],
"to": [1.0, 0.5],
"assignment": "V",
})
assert action.from_point == [0.0, 0.5]
assert action.to_point == [1.0, 0.5]
def test_openenv_state_contains_target_and_step():
env = OpenEnvOrigamiEnvironment(mode="step", max_steps=8)
env.reset(target_name="half_horizontal")
state = env.state()
assert "paper" in state
assert state.get("target") == "half_horizontal"
assert state.get("step") == 0