4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
126 lines
5.0 KiB
Python
126 lines
5.0 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from integrations.llm_cli.runner import CLIBackedLLMClient
|
|
|
|
|
|
def _mock_probe() -> MagicMock:
|
|
return MagicMock(installed=True, bin_path="/usr/bin/mock-cli", logged_in=True, detail="ok")
|
|
|
|
|
|
@patch("integrations.llm_cli.runner.subprocess.run")
|
|
def test_cli_llm_spawn_log_redacts_prompt_in_argv(mock_run: MagicMock, caplog) -> None:
|
|
prompt = "customer secret investigation context"
|
|
mock_adapter = MagicMock()
|
|
mock_adapter.name = "copilot"
|
|
mock_adapter.detect.return_value = _mock_probe()
|
|
mock_adapter.build.return_value = MagicMock(
|
|
argv=("/usr/bin/mock-cli", "-p", prompt, "--model", "gpt-5.1"),
|
|
stdin=None,
|
|
cwd="/tmp",
|
|
env=None,
|
|
timeout_sec=30.0,
|
|
)
|
|
mock_adapter.parse.return_value = "answer"
|
|
mock_run.return_value = MagicMock(returncode=0, stdout="answer\n", stderr="")
|
|
|
|
with patch("platform.guardrails.engine.get_guardrail_engine") as gr:
|
|
gr.return_value.is_active = False
|
|
with caplog.at_level(logging.DEBUG, logger="integrations.llm_cli.runner"):
|
|
client = CLIBackedLLMClient(mock_adapter)
|
|
client.invoke(prompt)
|
|
|
|
spawn = next(record for record in caplog.records if record.msg == "cli_llm_spawn")
|
|
assert spawn.provider == "copilot"
|
|
assert spawn.argv == ["/usr/bin/mock-cli", "-p", "<redacted-prompt>", "--model", "gpt-5.1"]
|
|
assert prompt not in spawn.argv
|
|
|
|
|
|
@patch("integrations.llm_cli.runner.subprocess.run")
|
|
def test_cli_llm_spawn_log_keeps_non_prompt_argv_args(mock_run: MagicMock, caplog) -> None:
|
|
prompt = "customer secret investigation context"
|
|
mock_adapter = MagicMock()
|
|
mock_adapter.name = "claude-code"
|
|
mock_adapter.detect.return_value = _mock_probe()
|
|
mock_adapter.build.return_value = MagicMock(
|
|
argv=("/usr/bin/mock-cli", "-p", "--output-format", "text"),
|
|
stdin=prompt,
|
|
cwd="/tmp",
|
|
env=None,
|
|
timeout_sec=30.0,
|
|
)
|
|
mock_adapter.parse.return_value = "answer"
|
|
mock_run.return_value = MagicMock(returncode=0, stdout="answer\n", stderr="")
|
|
|
|
with patch("platform.guardrails.engine.get_guardrail_engine") as gr:
|
|
gr.return_value.is_active = False
|
|
with caplog.at_level(logging.DEBUG, logger="integrations.llm_cli.runner"):
|
|
client = CLIBackedLLMClient(mock_adapter)
|
|
client.invoke(prompt)
|
|
|
|
spawn = next(record for record in caplog.records if record.msg == "cli_llm_spawn")
|
|
assert spawn.provider == "claude-code"
|
|
assert spawn.argv == ["/usr/bin/mock-cli", "-p", "--output-format", "text"]
|
|
|
|
|
|
@patch("integrations.llm_cli.runner.subprocess.run")
|
|
def test_cli_llm_spawn_log_redacts_prompt_equals_form(mock_run: MagicMock, caplog) -> None:
|
|
prompt = "customer secret investigation context"
|
|
mock_adapter = MagicMock()
|
|
mock_adapter.name = "mock-cli"
|
|
mock_adapter.detect.return_value = _mock_probe()
|
|
mock_adapter.build.return_value = MagicMock(
|
|
argv=("/usr/bin/mock-cli", f"--prompt={prompt}", "--model", "gpt-5.1"),
|
|
stdin=None,
|
|
cwd="/tmp",
|
|
env=None,
|
|
timeout_sec=30.0,
|
|
)
|
|
mock_adapter.parse.return_value = "answer"
|
|
mock_run.return_value = MagicMock(returncode=0, stdout="answer\n", stderr="")
|
|
|
|
with patch("platform.guardrails.engine.get_guardrail_engine") as gr:
|
|
gr.return_value.is_active = False
|
|
with caplog.at_level(logging.DEBUG, logger="integrations.llm_cli.runner"):
|
|
client = CLIBackedLLMClient(mock_adapter)
|
|
client.invoke(prompt)
|
|
|
|
spawn = next(record for record in caplog.records if record.msg == "cli_llm_spawn")
|
|
assert spawn.provider == "mock-cli"
|
|
assert spawn.argv == ["/usr/bin/mock-cli", "--prompt=<redacted-prompt>", "--model", "gpt-5.1"]
|
|
assert all(prompt not in arg for arg in spawn.argv)
|
|
|
|
|
|
@patch("integrations.llm_cli.runner.subprocess.run")
|
|
def test_runner_uses_adapter_explain_failure_for_quota(mock_run: MagicMock) -> None:
|
|
"""Quota stderr is enriched via adapter explain_failure, not a runner-side classifier."""
|
|
import pytest
|
|
|
|
from integrations.llm_cli.failure_explain import explain_cli_failure
|
|
|
|
mock_adapter = MagicMock()
|
|
mock_adapter.name = "codex"
|
|
mock_adapter.auth_hint = "codex login"
|
|
mock_adapter.detect.return_value = _mock_probe()
|
|
mock_adapter.build.return_value = MagicMock(
|
|
argv=("/usr/bin/codex", "exec", "-"),
|
|
stdin="hello",
|
|
cwd="/tmp",
|
|
env=None,
|
|
timeout_sec=30.0,
|
|
)
|
|
mock_adapter.explain_failure.side_effect = lambda **kwargs: explain_cli_failure(
|
|
exit_label="codex exec", **kwargs
|
|
)
|
|
mock_run.return_value = MagicMock(
|
|
returncode=1, stdout="", stderr="429 Too Many Requests: quota exceeded"
|
|
)
|
|
|
|
with patch("platform.guardrails.engine.get_guardrail_engine") as gr:
|
|
gr.return_value.is_active = False
|
|
client = CLIBackedLLMClient(mock_adapter)
|
|
with pytest.raises(RuntimeError, match="quota or rate limit exceeded"):
|
|
client.invoke("hello")
|