File size: 3,411 Bytes
ac9f14b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Sanity-check the generated shellops_pro dataset.
For every row:
  * re-run `gt_bash` against a fresh copy of init_dir
  * confirm stdout matches `expected_text` exactly (for string/hybrid)
  * confirm resulting file tree byte-matches post_files (for files/hybrid)
  * verify file count, file-type diversity, and total char volume
"""

import shutil
import subprocess
import tempfile
from collections import Counter
from pathlib import Path
import pandas as pd

ROOT = Path(__file__).resolve().parents[3]
DATA_DIR = Path(__file__).resolve().parent

def write_tree(dst: Path, files: list) -> None:
    dst.mkdir(parents=True, exist_ok=True)
    for entry in files:
        p = dst / entry["path"]
        p.parent.mkdir(parents=True, exist_ok=True)
        p.write_text(entry["content"])

def read_tree(src: Path) -> dict:
    result = {}
    for p in sorted(src.rglob("*")):
        if p.is_file():
            result[p.relative_to(src).as_posix()] = p.read_text()
    return result

def verify_row(row: dict) -> None:
    with tempfile.TemporaryDirectory() as tmp:
        work = Path(tmp) / "work"
        write_tree(work, list(row["pre_files"]))
        r = subprocess.run(
            ["bash", "-c", row["gt_bash"]],
            cwd=work,
            capture_output=True,
            text=True,
        )
        assert r.returncode == 0, (
            f"{row['id']} gt_bash failed: rc={r.returncode} stderr={r.stderr!r}"
        )
        got_stdout = r.stdout.rstrip("\n")
        if row["task_type"] in ("string", "hybrid"):
            assert got_stdout == row["expected_text"], (
                f"{row['id']} stdout mismatch:\nexpected={row['expected_text']!r}\n"
                f"got={got_stdout!r}"
            )
        if row["task_type"] in ("files", "hybrid"):
            actual_tree = read_tree(work)
            expected_tree = {e["path"]: e["content"] for e in row["post_files"]}
            only_actual = set(actual_tree) - set(expected_tree)
            only_expected = set(expected_tree) - set(actual_tree)
            diff_keys = [
                k
                for k in actual_tree
                if k in expected_tree and actual_tree[k] != expected_tree[k]
            ]
            assert actual_tree == expected_tree, (
                f"{row['id']} file tree mismatch:\n"
                f"only_in_actual={only_actual}\n"
                f"only_in_expected={only_expected}\n"
                f"content_diffs={diff_keys}"
            )

def main() -> None:
    df = pd.read_parquet(DATA_DIR / "test.parquet")
    assert 1 <= len(df) <= 150, f"unexpected row count: {len(df)}"
    print(f"{'id':<24} {'type':<7} {'nfiles':>6} {'nbytes':>9} {'exts':<40}")
    for _, row in df.iterrows():
        pre = list(row["pre_files"])
        n_files = len(pre)
        n_bytes = sum(len(e["content"]) for e in pre)
        ext_counts = Counter(Path(e["path"]).suffix or "<noext>" for e in pre)
        exts = ",".join(sorted(ext_counts))
        assert n_files >= 30, f"{row['id']}: n_files={n_files}"
        verify_row(row.to_dict())
        print(
            f"{row['id']:<24} {row['task_type']:<7} {n_files:>6} {n_bytes:>9} {exts:<40}"
        )
    total_bytes = sum(
        sum(len(e["content"]) for e in r["pre_files"]) for _, r in df.iterrows()
    )
    print(f"\nall {len(df)} tasks verified. total pre_files bytes: {total_bytes:,}")

if __name__ == "__main__":
    main()