File size: 3,777 Bytes
27d7338
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"""Easy task definition.

Provides a simple Python data-processing utility with exactly 3 real bugs and
no red herrings, plus ground truth metadata with exact line numbers.
"""

from __future__ import annotations

from dataclasses import dataclass
from typing import List

from env.models import GroundTruthBug


@dataclass(frozen=True)
class TaskSpec:
    """Container for a task specification used by the environment."""

    task_id: str
    max_steps: int
    pr_title: str
    pr_description: str
    full_file: str
    code_diff: str
    ground_truth: List[GroundTruthBug]


def get_task() -> TaskSpec:
    """Return the easy task specification (buggy code + ground truth)."""

    full_file = "\n".join(
        [
            "from __future__ import annotations",
            "",
            "from dataclasses import dataclass",
            "from typing import Iterable, List, Optional",
            "",
            "",
            "@dataclass",
            "class Item:",
            "    value: int",
            "",
            "",
            "def summarize_adjacent_deltas(items: List[Optional[Item]]) -> List[int]:",
            '    """Compute deltas between adjacent item values.',
            "",
            "    Returns a list of differences: items[i+1].value - items[i].value.",
            "    \"\"\"",
            "    deltas: List[int] = []",
            "    for i in range(len(items)):",
            "        left = items[i]",
            "        right = items[i + 1]",
            "        if left.value < 0:",
            "            continue",
            "        delta = right.value - left.value",
            "        include = False",
            "        if include = delta > 0:",
            "            deltas.append(delta)",
            "    return deltas",
            "",
        ]
    )

    code_diff = "\n".join(
        [
            "--- a/utils.py",
            "+++ b/utils.py",
            "@@",
            "+def summarize_adjacent_deltas(items: List[Optional[Item]]) -> List[int]:",
            "+    deltas: List[int] = []",
            "+    for i in range(len(items)):",
            "+        left = items[i]",
            "+        right = items[i + 1]",
            "+        if left.value < 0:",
            "+            continue",
            "+        delta = right.value - left.value",
            "+        include = False",
            "+        if include = delta > 0:",
            "+            deltas.append(delta)",
            "+    return deltas",
        ]
    )

    ground_truth = [
        GroundTruthBug(
            line_number=18,
            severity="major",
            category="bug",
            description="Off-by-one: loop iterates full len(items) while accessing items[i+1], causing IndexError on last iteration.",
        ),
        GroundTruthBug(
            line_number=21,
            severity="major",
            category="bug",
            description="Missing null check: left can be None; accessing left.value crashes when None is present in the list.",
        ),
        GroundTruthBug(
            line_number=25,
            severity="minor",
            category="bug",
            description="Uses assignment '=' inside a conditional instead of '==', causing a syntax/logic error and making the condition invalid.",
        ),
    ]

    return TaskSpec(
        task_id="easy",
        max_steps=8,
        pr_title="Add utility to compute adjacent deltas",
        pr_description=(
            "This PR adds a small helper used by reporting code to compute per-step deltas "
            "from a list of Items. The function should be robust to missing entries."
        ),
        full_file=full_file,
        code_diff=code_diff,
        ground_truth=ground_truth,
    )