Repository navigation
fix(shell): let the pytest grant cover python -m pytest - #4020
kovtcharov wants to merge 3 commits into
Conversation
|
Verdict: Approve with suggestions
One thing worth fixing before merge: the skill the agent actually reads still says to run bare Smaller: when an agent tries Real-world evidenceNo I did exercise the new logic directly on this checkout rather than reading it. Loading That confirms both halves of the claim: the granted spelling maps, and every near-miss shape stays an ordinary I could not run 🔍 Technical detailsIssues found 🟡 The coding skill still teaches only bare The PR's stated motivation is that agents type
With that unchanged, the model still reaches for bare `python -m pytest` is the same grant with the same rules. Prefer it on a checkout
that was never installed — `-m` puts the working directory on the import path, so
`from mypkg import ...` resolves without a config file or a `pip install -e .`.🟢 The env-assignment hint points away from the fix (
🟢 Common Windows/Linux launcher spellings are still refused (
Strengths
|
On macOS and Linux every piped shell command returned wrong output with status "success". The validator drops the `|` tokens and the executor then ran the segments as one argv, so `cat notes.txt | sort` ran as `cat notes.txt sort` and `grep a x.txt | wc -l` returned "x.txt" instead of a count. Windows was unaffected because it goes through cmd.exe. Validated segments are now chained as separate processes, still without a shell. The exit code is the rightmost failing stage, so `pytest | tail` cannot turn a failing suite into a verified pass; an upstream stage killed by SIGPIPE (`| head`) is not a failure. Every stage's stderr is kept, and a timeout kills the whole pipeline. test_a_pipeline_is_not_run_as_argv only pinned the shell flag, so it passed while the bug was live; it now checks that the stages are chained.
Agents reach for `python -m pytest` first, and the shell refused it with "only read-only commands are allowed" - no hint that pytest exists behind the coding skill. In a 14-task benchmark run on main that dead end was hit 5 times; the agent gave up on the tests and twice reported them as passing. `python -m pytest` is now judged as `pytest`: same grant, same flag and path policy, no extra prompt. Without the grant it gets pytest's "load that skill first" refusal. The typed spelling is what runs, because `-m` puts the working directory on the import path, so a checkout that was never installed imports without a pytest.ini workaround. Only the exact `python|python3|py -m pytest` shape maps; `-c`, a script, another module or an interpreter flag stays refused. An inline `PYTHONPATH=. pytest` was refused as an unknown command named "pythonpath=."; it now says inline environment assignments are unsupported.
120dde8 to
a14f91e
Compare
|
Everything in this PR is already on It landed as part of #4049, which squash-merged the tip of the stack this branch sits in and carried every commit below it along. GitHub does not auto-close the lower PRs in a stack when the tip is squashed, which is why this stayed open — and why it has been showing a conflict against a Closing as superseded. No work is lost; reopen if you disagree. 🔍 Technical detailsVerified rather than assumed — merged Residual: empty. The merge produces a tree identical to |
Agents type
python -m pytestfirst, and the shell refused it with "only read-only commands are allowed". The refusal never mentioned that pytest is available once the coding skill is loaded. In a 14-task benchmark run on main this dead end came up 5 times, and the agent fell back to hand-written asserts throughrun_pythoninstead of the project's test suite.python -m pytestnow counts as pytest: same grant, same flag and path rules, no extra prompt. It also imports a project that was never installed, so the agent no longer writes apytest.iniinto the repo to work around import errors.Test plan
python -m pytest tests/unit/test_skill_binary_grants.pypasses. On main, the 6 new reproducing tests fail.python -m pytest -qruns in a flat checkout with no config and no install (covered end to end bytest_python_m_pytest_imports_a_checkout_that_was_never_installed).python -c …,python -m pip …andpython -X dev -m pytestare still refused.🔍 Technical details
BinaryPolicy.python_moduledeclares which module runs a policed CLI.policy_argv()maps the exactpython|python3|py -m <module>shape to the binary, so the grant check, the confirmation skip, the path-scan exemption and the Windows argv rule all judge it aspytest. The typed argv is what runs, because-mis what puts the working directory onsys.path.PYTHONPATH=. pytestused to be refused as an unknown command namedpythonpath=.. It now says inline environment assignments are unsupported._validate_command. I merged all four on a local integration branch, and the resolution is mechanical: keep feat(shell,tui): ask instead of refusing; one name for full access #3808's classify-first order, fix(skills): load the coding skill when pytest is only in a virtualenv #3791's not-installed check and feat(skills): show the model every installed skill instead of guessing one #3765's skill-naming route, and read the policy frompolicy_argv(cmd_parts).