Skip to content

fix(skills): teach the coding skill the pytest spelling that actually works - #4174

Merged
kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:claude/coding-skill-pytest-spelling
Sep 25, 2026
Merged

kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:claude/coding-skill-pytest-spelling

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

On a checkout that was never pip-installed, bare pytest cannot import the project — so the agent's test run fails, and its usual way out is to write a config file into your repository to make the import work. The gate already accepts python -m pytest, which has the same grant and the same flag rules and needs no such workaround, but the skill the agent actually reads only ever showed the spelling that fails.

The refusal for PYTHONPATH=. pytest had the same gap: it correctly named the inline assignment as unsupported and then said to drop it, which walks straight back into the import error. It now names the spelling that works.

Test plan

  • pytest tests/unit -k "skill_binary or shell_guardrails or starter_skill or pytest_grant" — 591 passed, 80 skipped.
  • python -m pytest is already mapped to the pytest grant (src/gaia/skills/binaries.py), so this changes guidance only, not policy.

🤖 Generated with Claude Code

… works

The gate accepts `python -m pytest`, but the coding skill the agent reads shows
bare `pytest` only — so it keeps typing the spelling that fails to import the
project on a checkout that was never installed, and works around it by writing
a config file into the repository.

The refusal for `PYTHONPATH=. pytest` had the same gap: it named the inline
assignment and said to drop it, which walks back into the import error. It now
names `python -m pytest`.

Co-Authored-By: Claude Opus 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes — the skill half of this PR is a genuine improvement; the error-message half contradicts what the shell gate actually does today.

Teaching the coding skill to prefer python -m pytest is right, and I confirmed the gate really does treat it as the pytest grant (same flag rules, no extra confirmation prompt). But the second change edits a refusal that says inline VAR=value command is "not supported" — and it is supported: PYTHONPATH=. pytest -q runs today, another message a few hundred lines away tells the agent exactly that, and there's a test asserting it passes. That branch can't even be reached from a real run_shell_command call, because leading assignments are lifted out before the check runs. So the edit either never shows up, or shows up telling the agent to avoid the one thing that works.

Two smaller gaps in the new skill text:

  • python -m pytest does not rescue a project whose package lives under src/ — it adds the current directory to the import path, not src/. That's the very shape GAIA itself has, and the skill never mentions the PYTHONPATH=src python -m pytest spelling the gate allows. An agent hitting that case still has no documented route and lands back on writing a config file into the repo, which is the failure this PR set out to prevent.
  • On hosts where only python3 exists, the literal python -m pytest fails to launch. Worth one clause saying python3 -m pytest works identically.

Real-world evidence

No evidence-bundle.md in the tree, and this change touches agent-facing text rather than a CLI/API/UI surface, so there are no pixels to defer — the PR's own pytest run covers the surface that exists. I tried to exercise the gate directly in this lane and could not: the runner has no GAIA dependencies installed, so import gaia fails. My findings therefore rest on reading the guardrail code and its tests, not on executing it — the reachability claim above is worth a 30-second check on your machine before you act on it.

🔍 Technical details

🟡 The edited hint describes behavior the gate no longer has, on an unreachable branch (src/gaia/agents/tools/shell_tools.py:1802)

Inline assignments are supported. _parse_line → _take_segment_envs → _take_env_assignments (shell_tools.py:765, :297) strips leading NAME=value tokens off every segment and hands them to the subprocess via _segment_env, before _validate_command sees the argv (the only production call site is _shell_command_refusal, shell_tools.py:1159). By the time the _ENV_ASSIGNMENT_RE.match(cmd_parts[0]) check at :1793 runs, cmd_parts[0] can no longer be an assignment — _ENV_ASSIGNMENT_RE (prefix) and _ENV_ASSIGNMENT (fullmatch) accept the same tokens, so nothing slips past the strip. Denied names (PATH=, LD_*, …) are refused earlier by _env_refusal with a different message.

Two things follow:

  1. tests/unit/test_shell_env_assignment.py:79-82 asserts PYTHONPATH=lib pytest -q tests/ returns status == "success". The hint now steers the agent away from a command that works.
  2. It directly contradicts shell_tools.py:750: "Any other 'NAME=value' in front of a command is fine: 'PYTHONPATH=. pytest -q'" — and :761, which recommends that exact spelling.

Cleanest fix is deleting the dead branch (:1793-1807) so the generic not-in-allowlist refusal handles whatever residual case exists. If you'd rather keep it as defense-in-depth for direct _validate_command callers, at least stop it from misdescribing policy:

                    "hint": (
                        "Put the assignment in front of the command: "
                        "'PYTHONPATH=. pytest -q'. Loader and hook variables "
                        "(PATH, LD_*, GIT_*, PYTEST_*, ...) are the only ones "
                        "refused."
                    ),

🟢 python -m doesn't fix a src/-layout checkout (hub/skills/coding/SKILL.md:67-77)

python -m prepends the current directory, so for a project whose package is under src/ (GAIA's own layout) the import still fails. The gate permits PYTHONPATH=src python -m pytest — tests/unit/test_memory_error_refusals.py:362 uses that shape — but the skill never names it.

Two edits, both outside the example fence:

  • :67-69 — say "the current directory" rather than "the project's own directory", and add that python3 -m works the same way on hosts without a python alias.
  • after :77 — one sentence for the src/ case: "If the package lives under src/, the current directory is not enough — name the import root: PYTHONPATH=src python -m pytest -q tests/. A leading NAME=value is allowed for anything but loader and hook variables."

Verified while reviewing

  • policy_argv (src/gaia/skills/binaries.py:730) rewrites <python|python3|py> -m pytest … to the pytest policy argv, and both the refusal path (_validate_command, returns None at shell_tools.py:1537) and the prompt-skip path (skill_grant_covers_call, :1258) apply it — so python -m pytest is allowed and pre-authorized, exactly as the PR description claims. An interpreter flag before -m (python -X utf8 -m pytest) is deliberately not covered; the skill's examples don't use one.
  • Grant coverage for the -m spelling is already tested: tests/unit/test_skill_binary_grants.py:1437-1478, tests/unit/test_shell_compound_commands.py:404-413.

Strengths

  • The skill change fixes a measured failure mode with the right lever — agent-facing guidance, not a policy loosening — and keeps bare pytest legitimate instead of forbidding it.
  • The rationale is stated where the agent reads it ("works on a checkout that was never installed"), so the agent can generalize rather than pattern-match the example.

Kalin Ovtcharov and others added 2 commits September 24, 2026 14:03
Review follow-up. The refusal hint I edited described inline `VAR=value`
commands as unsupported and steered the agent away from `PYTHONPATH=. pytest`
— but main now lifts leading assignments before that check, so the branch is
unreachable and the advice contradicted what works. The edit is reverted.

The skill text gains the two cases it missed: `python -m` adds the current
directory, not `src/`, so a src-layout project needs
`PYTHONPATH=src python -m pytest`; and `python3 -m pytest` where only `python3`
exists. All three spellings are allowed under the coding skill's pytest grant.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 25, 2026
Merged via the queue into amd:main with commit 806a66a Sep 25, 2026
20 checks passed
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Sep 25, 2026
The coding skill grants `pytest` and tells the model to run the tests,
but it didn't list the one tool that can run a shell command. Once
loading a skill brings in the tools it declares, the model got every
coding tool except the one that runs tests. The skill now declares that
tool. A new starter-pack check fails any skill whose shell grant has no
tool to use it. Coding was the only skill that broke the rule;
`github-triage` already declared the tool.

Overlaps amd#3390 and amd#4174, which both edit the same `pytest` paragraph
and neither adds the tool. Whichever merges second needs a one-line
rebase.

## Test plan
- [x] `python -m pytest tests/unit/test_starter_skills.py -q -k
shell_grant`: the new check fails for `coding` before the fix and passes
for all 16 skills after it
- [x] `python -m pytest tests/unit/test_starter_skills.py
tests/unit/test_skill_binary_grants.py
hub/agents/gaia/python/tests/test_gaia_agent.py -q`: 489 passed. The one
failure, `test_manifest_tools_count_matches_real_registry` (81 vs 80),
counts the agent's tool registry, which this change doesn't touch
- [x] `black --check` / `isort --check-only` on the changed test file
- [ ] `gaia eval agent`: the loaded coding skill now gives the model an
extra tool

Fixes amd#4222

Co-authored-by: Kalin Ovtcharov <[email protected]>
Co-authored-by: Kalin Ovtcharov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants