Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Unblock CI by integrating three mutually-blocked fixes into one branch (#8590)
LawyZheng7fa048e690f8
diff --git a/tests/unit/conftest.py b/tests/unit/conftest.pyindex f9599224e..bfccf78fc 100644--- a/tests/unit/conftest.py+++ b/tests/unit/conftest.py@@ -5,6 +5,7 @@ import asyncioimport contextlibimport itertoolsimport logging+import osimport shutilimport sysimport threading@@ -27,6 +28,7 @@ from playwright.async_api import Error as PlaywrightErrorfrom sqlalchemy import create_enginefrom sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine+import skyvern._cli_bootstrap as cli_bootstrapfrom skyvern.forge.agent_functions import AgentFunctionfrom skyvern.forge.prompts import prompt_enginefrom skyvern.forge.sdk.api import files@@ -198,6 +200,25 @@ def restore_interpreter_traceback_hooks() -> Iterator[None]:sys.excepthook, threading.excepthook, sys.unraisablehook = hooks[email protected](autouse=True)+def reset_cli_runtime_entry() -> Iterator[None]:+ """A CliRunner invocation marks the whole process as CLI-entered and loads a backend env file.++ Both outlive the test, and the pair trips the CLI-only guard that refuses an API key+ against the default production URL in any later test that builds a cloud client. The env+ load also records SKYVERN_ENV_INTENT unconditionally, which config reads for env precedence.+ """+ entered = cli_bootstrap._CLI_RUNTIME_PREPARED+ loaded = {name: os.environ.get(name) for name in ("SKYVERN_API_KEY", "SKYVERN_BASE_URL", "SKYVERN_ENV_INTENT")}+ yield+ cli_bootstrap._CLI_RUNTIME_PREPARED = entered+ for name, value in loaded.items():+ if value is None:+ os.environ.pop(name, None)+ else:+ os.environ[name] = value++@pytest.fixture(autouse=True)def reset_mcp_stateless_http_mode():"""Keep MCP transport mode from leaking between independently collected test files."""diff --git a/tests/unit/test_cli_commands.py b/tests/unit/test_cli_commands.pyindex b18fca860..7f26538a7 100644--- a/tests/unit/test_cli_commands.py+++ b/tests/unit/test_cli_commands.py@@ -5,6 +5,7 @@ from __future__ import annotationsimport asyncioimport importlibimport json+import osimport shleximport subprocessimport sys@@ -1180,6 +1181,42 @@ class TestCliRuntimeFlag:assert completed.returncode == 0, completed.stderr+class TestCliRuntimeResetFixture:+ def test_reset_cli_runtime_entry_restores_process_and_env_state(self, monkeypatch: pytest.MonkeyPatch) -> None:+ """The autouse conftest fixture must undo everything a CLI entry leaves in the process.++ prepare_cli_runtime flips _CLI_RUNTIME_PREPARED, and load_backend_env_files writes+ SKYVERN_ENV_INTENT unconditionally plus SKYVERN_API_KEY / SKYVERN_BASE_URL when a .env+ supplies them. config._settings_env_intent reads SKYVERN_ENV_INTENT for env precedence,+ so leaking it past teardown steers a later cloud-client test in the same shard.+ """+ from skyvern import _cli_bootstrap+ from tests.unit.conftest import reset_cli_runtime_entry++ run_reset = reset_cli_runtime_entry.__wrapped__++ monkeypatch.setattr(_cli_bootstrap, "_CLI_RUNTIME_PREPARED", False)+ monkeypatch.delenv("SKYVERN_API_KEY", raising=False)+ monkeypatch.delenv("SKYVERN_BASE_URL", raising=False)+ monkeypatch.setenv("SKYVERN_ENV_INTENT", "auto")++ teardown = run_reset()+ next(teardown)++ _cli_bootstrap._CLI_RUNTIME_PREPARED = True+ os.environ["SKYVERN_API_KEY"] = "leaked-key"+ os.environ["SKYVERN_BASE_URL"] = "https://leaked.example"+ os.environ["SKYVERN_ENV_INTENT"] = "cloud"++ with pytest.raises(StopIteration):+ next(teardown)++ assert _cli_bootstrap._CLI_RUNTIME_PREPARED is False+ assert "SKYVERN_API_KEY" not in os.environ+ assert "SKYVERN_BASE_URL" not in os.environ+ assert os.environ["SKYVERN_ENV_INTENT"] == "auto"++class TestCredentialsCommands:def test_add_credential_invalid_type_json_error_includes_action(self, capsys: pytest.CaptureFixture) -> None:from skyvern.cli import credentials as credentials_cmd