Datasets:
Download scripts/generate-testdata.py from tesraghavan/agent-trace: direct link, hf CLI and curl.
- Browser
- Download file 3.13 kB
-
https://huggingface.co/datasets/tesraghavan/agent-trace/resolve/main/scripts/generate-testdata.py
- Command line
-
hf download hf://datasets/tesraghavan/agent-trace/scripts/generate-testdata.py
-
curl -L -o generate-testdata.py https://huggingface.co/datasets/tesraghavan/agent-trace/resolve/main/scripts/generate-testdata.py
3.13 kB
| #!/usr/bin/env python3 | |
| """Generate the testdata filesystem fixture for NL2Bash tasks. | |
| Deterministic (seeded) so the fixture is reproducible across machines. | |
| Run this script to regenerate testdata/ if it's missing or stale. | |
| Usage: | |
| python scripts/generate-testdata.py # generate into testdata/ | |
| python scripts/generate-testdata.py --check # verify fixture exists | |
| """ | |
| import argparse | |
| import os | |
| import random | |
| import shutil | |
| import sys | |
| from pathlib import Path | |
| SEED = 42 | |
| BASE = Path(__file__).resolve().parent.parent / "testdata" | |
| DIRS = [ | |
| "system/folder1", | |
| "system/folder1/subfolder1", | |
| "system/folder1/subfolder2", | |
| "system/folder2", | |
| "system/folder2/subfolder1", | |
| "system/folder3", | |
| "testbed/dir1", | |
| "testbed/dir2", | |
| "testbed/dir3", | |
| "testbed/dir3/subdir1", | |
| "testbed/dir3/subdir1/subsubdir1", | |
| "testbed/dir3/subdir1/subsubdir1/tmp", | |
| "workspace/project1", | |
| "workspace/project2", | |
| "workspace/logs", | |
| "workspace/data", | |
| ] | |
| EXTENSIONS = [".txt", ".log", ".py", ".sh", ".php", ".c", ".out", ".csv"] | |
| FILLER = [ | |
| "the", "quick", "brown", "fox", "jumps", "over", "lazy", "dog", | |
| "alpha", "beta", "gamma", "delta", "config", "setup", "init", | |
| ] | |
| KEYWORDS = ["Hello", "foo", "error", "warning"] | |
| KEYWORD_PROB = 0.08 # ~8% chance per line of containing a keyword | |
| def generate(): | |
| rng = random.Random(SEED) | |
| # Clean existing fixture dirs (preserve other testdata like noise.txt) | |
| for d in ["system", "testbed", "workspace"]: | |
| p = BASE / d | |
| if p.exists(): | |
| shutil.rmtree(p) | |
| for d in DIRS: | |
| (BASE / d).mkdir(parents=True, exist_ok=True) | |
| file_count = 0 | |
| for d in DIRS: | |
| n_files = rng.randint(1, 4) | |
| for i in range(n_files): | |
| ext = rng.choice(EXTENSIONS) | |
| path = BASE / d / f"file{i}{ext}" | |
| n_lines = rng.randint(3, 15) | |
| lines = [] | |
| for _ in range(n_lines): | |
| words = rng.choices(FILLER, k=rng.randint(3, 7)) | |
| if rng.random() < KEYWORD_PROB: | |
| words.insert(0, rng.choice(KEYWORDS)) | |
| lines.append(" ".join(words)) | |
| path.write_text("\n".join(lines) + "\n") | |
| file_count += 1 | |
| return file_count | |
| def check(): | |
| """Verify fixture dirs exist and have files.""" | |
| missing = [] | |
| for d in DIRS: | |
| p = BASE / d | |
| if not p.exists(): | |
| missing.append(str(p)) | |
| return missing | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Generate testdata fixture") | |
| parser.add_argument("--check", action="store_true", help="Check fixture exists without generating") | |
| args = parser.parse_args() | |
| if args.check: | |
| missing = check() | |
| if missing: | |
| print(f"Missing {len(missing)} directories:", file=sys.stderr) | |
| for m in missing[:5]: | |
| print(f" {m}", file=sys.stderr) | |
| sys.exit(1) | |
| print("Fixture OK") | |
| sys.exit(0) | |
| count = generate() | |
| print(f"Generated {count} files across {len(DIRS)} directories in {BASE}") | |
| if __name__ == "__main__": | |
| main() | |