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
34 changes: 34 additions & 0 deletions tests/test_loopguard_conda_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""A test run started in a conda environment is a verification.

`conda run -n <env>` (and `mamba run`, `micromamba run`) runs a command in a named or prefixed
environment, as `uv run` and `poetry run` do in theirs. The micro-skills observer already learns
and injects that form (`conda run -n <env> pytest`), so a run the agent types as told must count
as the turn's verification too."""
import pytest

from tokeneconomizer import loopguard as guard
from tokeneconomizer.loopguard import turn


@pytest.mark.parametrize("cmd", ["conda run -n ml pytest -q",
"conda run -n ml python -m pytest tests",
"conda run --no-capture-output -n ml python -m pytest",
"conda run --name ml --live-stream pytest",
"conda run -p ./env pytest", "conda run --prefix=/opt/env pytest",
"conda run --cwd src -n ml python -m unittest",
"mamba run -n ml pytest", "micromamba run -n ml pytest",
"micromamba run -r /opt/mamba -n ml pytest",
"conda run pytest"])
def test_a_runner_in_a_conda_environment_counts_as_a_verification(cmd):
assert turn.status_of_tests(cmd) == "own"
g = guard.TurnGuard(turn_key="t")
g.fold("Edit", {"file_path": "/r/a.py", "old_string": "x", "new_string": "y"}, "ok")
g.fold("Bash", {"command": cmd}, "FAILED (failures=1)", 1)
assert g.verifications == 1 and not g.resolved_proxy()


@pytest.mark.parametrize("cmd", ["conda run -n ml python train.py", "conda install -n ml pytest",
"conda run -n ml pytest --collect-only",
"micromamba create -n ml pytest"])
def test_conda_leaves_what_it_runs_to_decide(cmd):
assert turn.status_of_tests(cmd) is None
4 changes: 4 additions & 0 deletions tokeneconomizer/loopguard/turn.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
# env's options; `-u`, `-C` and their long forms take a value
r"env(?:\s+(?:(?:-[uC]|--unset|--chdir)(?:=|\s*)[^\s-]\S*|-[-\w]*))*|"
r"timeout(?:\s+(?:-\S+|[A-Z]+|\d\S*))+|"
# `conda run -n ml`, `mamba run -p ./env`, `micromamba run -r /opt -n ml`:
# the environment's name or path, and the other options that take a value
r"(?:conda|mamba|micromamba)\s+run(?:\s+(?:(?:-[npr]|--name|--prefix|"
r"--root-prefix|--cwd)(?:=|\s*)[^\s-]\S*|-[-\w]*))*|"
r"(?:(?:uv|poetry|pipenv|pdm|hatch|rye)\s+run|npx|bunx|"
r"(?:npm|pnpm|yarn)\s+(?:exec|dlx)|bundle\s+exec|xvfb-run)"
r"(?:\s+-\S+)*|"
Expand Down
Loading