Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion case-study/runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ this runner deliberately doesn't fake those.

```bash
cp case-study/runner/arms.example.json case-study/runner/arms.json
# edit arms.json: set task_repo to your task_ist_preprocessing clone, set models
# REQUIRED: edit arms.json -> set "task_repo" to your task_ist_preprocessing
# clone (and set the models). A real run errors clearly if it's left unset.

# validate the plan without running anything:
python case-study/runner/run.py --config case-study/runner/arms.json --dry-run
Expand All @@ -35,6 +36,11 @@ python case-study/runner/run.py --config case-study/runner/arms.json

Output: `case-study/runs/results.json` and `results.md`.

> **Run it from anywhere.** Paths in the config (`copilot_repo`, `workdir`,
> `prompt_file`) resolve against the repo root, not your current directory — so
> `python runner/run.py ...` from inside `case-study/` works too. Only the
> `--config` path itself is taken relative to your shell's working directory.

## Smoke-test offline first (no tokens, no setup)

Before spending real tokens, validate the whole prepare → run → grade → table
Expand Down
1 change: 1 addition & 0 deletions case-study/runner/arms.example.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"_comment": "Copy to arms.json and edit. REQUIRED: set 'task_repo' to a local clone of openproblems-bio/task_ist_preprocessing (or use --mock-harness to smoke-test offline). Relative paths resolve against the repo root, so the runner works from any directory.",
"copilot_repo": ".",
"task_repo": "/path/to/task_ist_preprocessing",
"component_name": "log_normalization",
Expand Down
48 changes: 41 additions & 7 deletions case-study/runner/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

HERE = Path(__file__).resolve().parent
CASE_STUDY = HERE.parent
REPO_ROOT = CASE_STUDY.parent
GRADE_PY = CASE_STUDY / "grade.py"
STRIP_SH = CASE_STUDY / "scripts" / "strip_skill.sh"
COPILOT_ASSETS = ("AGENTS.md", "skills", "context")
Expand All @@ -44,13 +45,25 @@
}


def _resolve(base: Path, value: str) -> Path:
"""Resolve ``value`` as an absolute path, anchoring relatives at ``base``."""
p = Path(value).expanduser()
return p if p.is_absolute() else base / p


def _load_config(path: Path) -> dict:
cfg = json.loads(path.read_text(encoding="utf-8"))
cfg.setdefault("workdir", "case-study/runs")
cfg.setdefault("component_name", "log_normalization")
cfg.setdefault("timeout_seconds", 1800)
cfg.setdefault("prompt_file", "case-study/task/prompt.txt")
cfg.setdefault("run_viash", False)
# Resolve paths against the repo root (derived from this script's location),
# NOT the current working directory, so the runner works from any directory.
copilot_repo = _resolve(REPO_ROOT, cfg.get("copilot_repo", ".")).resolve()
cfg["copilot_repo"] = str(copilot_repo)
cfg["workdir"] = str(_resolve(REPO_ROOT, cfg.get("workdir", "case-study/runs")))
cfg["prompt_file"] = str(
_resolve(copilot_repo, cfg.get("prompt_file", "case-study/task/prompt.txt"))
)
return cfg


Expand Down Expand Up @@ -185,7 +198,7 @@ def grade_component(
def run_arm(
cfg: dict, arm: dict, copilot_repo: Path, dry_run: bool, mock: str | None = None
) -> dict:
prompt = (copilot_repo / cfg["prompt_file"]).read_text(encoding="utf-8").strip()
prompt = Path(cfg["prompt_file"]).read_text(encoding="utf-8").strip()
result = {
"arm": arm["name"],
"harness": arm["harness"],
Expand Down Expand Up @@ -278,19 +291,40 @@ def main(argv: list[str] | None = None) -> int:
args = parser.parse_args(argv)

cfg = _load_config(args.config)
copilot_repo = Path(cfg.get("copilot_repo", ".")).resolve()
copilot_repo = Path(cfg["copilot_repo"])

task_repo_val = str(cfg.get("task_repo", "")).strip()
task_repo = Path(task_repo_val).expanduser() if task_repo_val else None

# In mock mode, synthesize a stand-in task repo if the configured one is absent
# so the full prepare->run->grade pipeline runs with no external dependencies.
if args.mock_harness and not args.dry_run:
task_repo = Path(cfg["task_repo"]).expanduser()
if not task_repo.exists():
synth = Path(cfg["workdir"]).resolve() / "_mock_task_repo"
if task_repo is None or not task_repo.exists():
synth = Path(cfg["workdir"]) / "_mock_task_repo"
if synth.exists():
shutil.rmtree(synth)
_synthesize_task_repo(synth)
cfg["task_repo"] = str(synth)
print(f"(mock) synthesized stand-in task repo at {synth}")
# Real run: fail early and clearly if task_repo is the unedited placeholder.
elif not args.dry_run:
if (
not task_repo_val
or task_repo_val.startswith("/path/to/")
or task_repo is None
or not task_repo.exists()
):
print(
"❌ 'task_repo' is not set to a real checkout "
f"(current value: {task_repo_val or '(missing)'}).\n"
" Edit your arms config and point it at a local clone of\n"
" openproblems-bio/task_ist_preprocessing, for example:\n"
' "task_repo": "/home/you/task_ist_preprocessing"\n'
" Or smoke-test the pipeline offline first with no clone:\n"
" --mock-harness skill-aware",
file=sys.stderr,
)
return 2

arms = cfg["arms"]
if args.only:
Expand Down
27 changes: 27 additions & 0 deletions tests/test_case_study_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,30 @@ def test_mock_end_to_end(tmp_path):
by_arm = {r["arm"]: r["graded"]["score"] for r in results}
assert by_arm["skill"] == 11
assert by_arm["noskill"] == 0


def test_config_paths_are_cwd_independent(tmp_path, monkeypatch):
"""Paths resolve against the repo root, not the current working directory."""
monkeypatch.chdir(tmp_path) # run from an unrelated directory
cfg = run_mod._load_config(EXAMPLE_CONFIG)
prompt = Path(cfg["prompt_file"])
assert prompt.is_absolute() and prompt.is_file()
assert prompt == REPO_ROOT / "case-study" / "task" / "prompt.txt"
assert Path(cfg["copilot_repo"]) == REPO_ROOT
assert Path(cfg["workdir"]).is_absolute()


def test_real_run_rejects_placeholder_task_repo(tmp_path, capsys):
"""A real run with the unedited placeholder fails clearly (exit 2)."""
config = {
"copilot_repo": str(REPO_ROOT),
"task_repo": "/path/to/task_ist_preprocessing",
"workdir": str(tmp_path / "runs"),
"arms": [{"name": "x", "harness": "gemini", "model": "m", "skill": False}],
"harnesses": {"gemini": {"command": ["gemini", "-p", "{prompt}"]}},
}
cfg_path = tmp_path / "arms.json"
cfg_path.write_text(json.dumps(config), encoding="utf-8")
rc = run_mod.main(["--config", str(cfg_path)])
assert rc == 2
assert "task_repo" in capsys.readouterr().err
Loading