File size: 4,685 Bytes
b199558
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
119
120
121
122
123
124
125
126
127
128
129
130
131
"""Structural validation for TerminalBench-DockerLess.jsonl.

Checks that every row carries the classic Terminal-Bench task.yaml fields and the
Harbor task.toml rendering, that the embedded task directory is complete, that
the verifier and instruction do not leak each other, and that every task is
non-trivial (something must fail before any agent acts).

Run with:  python tools/validate.py
"""

import json
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
DATASET = ROOT / "TerminalBench-DockerLess.jsonl"

TB_FIELDS = [
    "task_id",
    "instruction",
    "author_name",
    "author_email",
    "difficulty",
    "category",
    "tags",
    "parser_name",
    "max_agent_timeout_sec",
    "max_test_timeout_sec",
    "expert_time_estimate_min",
    "junior_time_estimate_min",
    "task_yaml",
    "task_toml",
    "dockerfile",
    "solution",
    "tests",
    "dockerless",
]

REQUIRED_FILES = ["instruction.md", "environment/Dockerfile", "solution/solve.sh", "tests/test.sh"]

MAX_INSTRUCTION_CHARS = 4000
MIN_AGENT_TIMEOUT = 60
MIN_TEST_TIMEOUT = 30

failures = []


def check(condition, message):
    if not condition:
        failures.append(message)


def main():
    rows = [json.loads(line) for line in open(DATASET, encoding="utf-8") if line.strip()]
    check(len(rows) == 4, "expected 4 rows, found %d" % len(rows))

    seen = set()
    for row in rows:
        tid = row.get("task_id", "<missing>")
        for field in TB_FIELDS:
            check(field in row, "%s: missing field %s" % (tid, field))
        check(tid not in seen, "%s: duplicate task_id" % tid)
        seen.add(tid)

        instruction = row["instruction"]
        check(len(instruction.strip()) > 200, "%s: instruction too short" % tid)
        check(len(instruction) <= MAX_INSTRUCTION_CHARS, "%s: instruction too long" % tid)
        check("::" not in instruction, "%s: instruction leaks a test node id" % tid)
        check("test_outputs" not in instruction, "%s: instruction names the verifier file" % tid)

        check(row["parser_name"] == "pytest", "%s: parser_name must be pytest" % tid)
        check(row["difficulty"] in ("easy", "medium", "hard"), "%s: bad difficulty" % tid)
        check(row["max_agent_timeout_sec"] >= MIN_AGENT_TIMEOUT, "%s: agent timeout too small" % tid)
        check(row["max_test_timeout_sec"] >= MIN_TEST_TIMEOUT, "%s: test timeout too small" % tid)

        yaml = row["task_yaml"]
        for needle in ("instruction: |", "parser_name: pytest", "difficulty: ", "max_agent_timeout_sec:"):
            check(needle in yaml, "%s: task_yaml missing %r" % (tid, needle))
        toml = row["task_toml"]
        for needle in ('schema_version = "1.4"', "[verifier]", "[agent]", "[environment]"):
            check(needle in toml, "%s: task_toml missing %r" % (tid, needle))

        tests = row["tests"]
        check("test.sh" in tests, "%s: tests/test.sh missing" % tid)
        check("test_outputs.py" in tests, "%s: tests/test_outputs.py missing" % tid)
        check(row["solution"].strip() != "", "%s: empty solution" % tid)
        check("FROM " in row["dockerfile"], "%s: dockerfile does not look like a Dockerfile" % tid)

        dockerless = row["dockerless"]
        files = dockerless["files"]
        for rel in files:
            check(not rel.startswith("/"), "%s: absolute path in snapshot: %s" % (tid, rel))
            check(".." not in Path(rel).parts, "%s: escaping path in snapshot: %s" % (tid, rel))
        check("Dockerfile" not in files, "%s: snapshot contains the Dockerfile" % tid)
        check("setup.sh" not in files, "%s: snapshot contains setup.sh" % tid)

        check(
            bool(dockerless["baseline_failures"]),
            "%s: nothing fails before the agent acts" % tid,
        )
        check(
            bool(dockerless.get("setup", "").strip()) or bool(files),
            "%s: task has neither setup script nor files" % tid,
        )

        print(
            "%-24s %-6s files=%-2d tests=%-2d baseline_fail=%-2d instr=%d chars"
            % (
                tid,
                row["difficulty"],
                len(files),
                len(tests) - 1,
                len(dockerless["baseline_failures"]),
                len(instruction),
            )
        )

    total_chars = DATASET.stat().st_size
    print("\n%d tasks, %.1f KiB (~%d tokens)" % (len(rows), total_chars / 1024.0, total_chars // 4))
    if failures:
        print("\nFAILED %d checks:" % len(failures))
        for message in failures:
            print("  - %s" % message)
        return 1
    print("all checks passed")
    return 0


if __name__ == "__main__":
    sys.exit(main())