Download tests/unit/test_state.py from desiree/spi: direct link, hf CLI and curl.
- Browser
- Download file 2.28 kB
-
https://huggingface.co/desiree/spi/resolve/main/tests/unit/test_state.py
- Command line
-
hf download hf://desiree/spi/tests/unit/test_state.py
-
curl -L -o test_state.py https://huggingface.co/desiree/spi/resolve/main/tests/unit/test_state.py
2.28 kB
| import pytest | |
| from spi.schemas.project_state import Constraint, ProjectState | |
| def test_delta_bumps_version_and_logs(): | |
| s = ProjectState(prompt="a lighthouse at dusk") | |
| v0 = s.state_version | |
| s.apply_delta("Test", "set_intent", "goal set", | |
| [{"op": "set", "path": "intent.goal", "value": "lighthouse"}]) | |
| assert s.state_version == v0 + 1 | |
| assert s.mutations[-1].agent == "Test" | |
| assert s.mutations[-1].version == s.state_version | |
| def test_nested_delta_merge(): | |
| s = ProjectState() | |
| s.apply_delta("T", "a", "merge concept", | |
| [{"op": "merge", "path": "concept", "value": {"theme": "memory"}}]) | |
| s.apply_delta("T", "a", "merge more", | |
| [{"op": "merge", "path": "concept", "value": {"camera": "slow push"}}]) | |
| assert s.concept["theme"] == "memory" and s.concept["camera"] == "slow push" | |
| def test_append_delta(): | |
| s = ProjectState() | |
| s.apply_delta("T", "a", "add constraint", | |
| [{"op": "append", "path": "constraints", | |
| "value": Constraint(constraint_id="C_001", text="no dialogue")}]) | |
| assert s.constraints[0].constraint_id == "C_001" | |
| assert s.constraints[0].hard is True | |
| def test_unknown_op_raises(): | |
| s = ProjectState() | |
| try: | |
| s.apply_delta("T", "a", "bad", [{"op": "delete", "path": "concept", "value": {}}]) | |
| raise AssertionError("unknown op must raise") | |
| except ValueError as e: | |
| assert "delete" in str(e) | |
| def test_lazy_get_context(): | |
| s = ProjectState(prompt="x") | |
| s.apply_delta("T", "a", "s", [{"op": "set", "path": "intent.goal", "value": "g"}]) | |
| ctx = s.get_context(["intent.goal", "concept.missing"]) | |
| assert ctx["intent.goal"] == "g" and ctx["concept.missing"] is None | |
| def test_json_roundtrip(): | |
| s = ProjectState(prompt="roundtrip") | |
| s.apply_delta("T", "a", "s", [{"op": "set", "path": "intent.goal", "value": "g"}]) | |
| s2 = ProjectState.from_json(s.to_json()) | |
| assert s2.prompt == "roundtrip" and s2.state_version == s.state_version | |
| assert len(s2.mutations) == 1 | |
| def test_validate_assignment_coerces_dicts(): | |
| s = ProjectState() | |
| s.plan = {"project_id": "SPI-X", "scenes": [], "shots": [], "jobs": []} | |
| assert hasattr(s.plan, "shots") # dict coerced into ProductionPlan |