"""Tests for Task dataclass dict-compatibility layer."""

from pathlib import Path

from clawbench.task_utils import Task


class TestTaskDictCompat:
    """Task should behave like a dict for backward-compat code."""

    def _make_task(self) -> Task:
        return Task(name="my-task", path=Path("/tmp/my-task"), tags=["gws"])

    def test_getitem(self):
        t = self._make_task()
        assert t["task_name"] == "my-task"
        assert t["task_path"] == "/tmp/my-task"

    def test_get_with_default(self):
        t = self._make_task()
        assert t.get("task_name") == "my-task"
        assert t.get("missing", 42) == 42

    def test_contains(self):
        t = self._make_task()
        assert "task_name" in t
        assert "nonexistent" not in t

    def test_iter(self):
        t = self._make_task()
        assert set(t) == {"task_name", "task_path"}

    def test_keys(self):
        t = self._make_task()
        assert set(t.keys()) == {"task_name", "task_path"}

    def test_double_star_unpack(self):
        t = self._make_task()
        merged = {**t, "_repeat": 3}
        assert merged == {
            "task_name": "my-task",
            "task_path": "/tmp/my-task",
            "_repeat": 3,
        }
