File size: 1,798 Bytes
a80eade
 
 
 
 
 
 
7045b45
 
 
a80eade
7045b45
 
 
 
 
 
a80eade
 
 
 
 
 
 
7045b45
 
 
a80eade
 
7045b45
a80eade
7045b45
 
 
 
 
a80eade
7045b45
a80eade
 
 
 
7045b45
a80eade
7045b45
 
a80eade
 
7045b45
 
a80eade
 
7045b45
a80eade
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Unit tests for environment models."""

from environment.models import Action, Observation, Reward


def test_observation_serialization_round_trip() -> None:
    observation = Observation(
        task_id="null_filling",
        task_name="Missing Value Repair",
        task_description="Repair missing values in the contacts table.",
        step=0,
        max_steps=5,
        available_actions=["fill_missing"],
        context="Inspect the dataset preview.",
        dataset_preview="row_id | name | age\n0 | Alice |",
        issues_remaining=3,
        attempts_remaining=5,
        feedback="",
        feedback_history=[],
    )

    dumped = observation.model_dump(mode="json")
    restored = Observation.model_validate(dumped)

    assert restored.task_id == "null_filling"
    assert restored.attempts_remaining == 5
    assert restored.dataset_preview.startswith("row_id")


def test_action_validation_normalizes_action_type() -> None:
    action = Action(
        action_type="  FIX_VALUE  ",
        row_index=2,
        column="email",
        new_value="user@example.com",
        reason="Replace the missing email.",
    )
    assert action.action_type == "fix_value"


def test_action_from_llm_output_parses_json_block() -> None:
    action = Action.from_llm_output(
        '```json\n{"action_type":"fill_missing","row_index":2,"column":"email","new_value":"user@example.com","reason":"row 2 email is missing"}\n```'
    )
    assert action.action_type == "fill_missing"
    assert action.row_index == 2


def test_reward_clamps_value_and_fields() -> None:
    reward = Reward(value=1.4, issues_fixed_this_step=2, issues_remaining=0, solved=True, attempts_used=1)

    assert reward.value == 1.0
    assert reward.issues_fixed_this_step == 2
    assert reward.solved is True