arcade-mcp/arcade/tests/cli/test_utils.py
Nate Barbettini 75c6a2becf
arcade chat: allow overriding host, port, TLS (#31)
Adds:
- New options to `arcade chat`: `-h/--host`, `-p/--port`, and
`--tls/--notls`. This allows us to point `arcade chat` at a different
server than what's configured in `arcade.toml` which is very helpful for
debugging.
- Special case: if you do `-h localhost`, it will automatically use port
9099 and no TLS unless otherwise specified.
- Adds a non-fatal engine health check to `arcade chat` startup:

<img width="499" alt="image"
src="https://github.com/user-attachments/assets/b7fae29e-2f8d-4004-a27b-645b4cd997a8">
2024-09-10 09:25:05 -07:00

135 lines
3.5 KiB
Python

import pytest
from arcade.cli.utils import apply_config_overrides
from arcade.core.config_model import ApiConfig, Config, EngineConfig
DEFAULT_HOST = "api.arcade-ai.com"
DEFAULT_PORT = None
DEFAULT_TLS = True
@pytest.mark.parametrize(
"inputs, expected_outputs",
[
pytest.param(
{
"host_input": None,
"port_input": None,
"tls_input": None,
},
{
"host": DEFAULT_HOST,
"port": DEFAULT_PORT,
"tls": DEFAULT_TLS,
},
id="noop",
),
pytest.param(
{
"host_input": "api2.arcade-ai.com",
"port_input": None,
"tls_input": None,
},
{
"host": "api2.arcade-ai.com",
"port": DEFAULT_PORT,
"tls": DEFAULT_TLS,
},
id="set host",
),
pytest.param(
{
"host_input": None,
"port_input": 6789,
"tls_input": None,
},
{
"host": DEFAULT_HOST,
"port": 6789,
"tls": DEFAULT_TLS,
},
id="set port",
),
pytest.param(
{
"host_input": None,
"port_input": None,
"tls_input": False,
},
{
"host": DEFAULT_HOST,
"port": DEFAULT_PORT,
"tls": False,
},
id="set TLS to False",
),
pytest.param(
{
"host_input": None,
"port_input": None,
"tls_input": True,
},
{
"host": DEFAULT_HOST,
"port": DEFAULT_PORT,
"tls": True,
},
id="set TLS to True",
),
pytest.param(
{
"host_input": "localhost",
"port_input": None,
"tls_input": None,
},
{
"host": "localhost",
"port": 9099,
"tls": False,
},
id="localhost and no port or TLS specified",
),
pytest.param(
{
"host_input": "localhost",
"port_input": 1234,
"tls_input": None,
},
{
"host": "localhost",
"port": 1234,
"tls": False,
},
id="localhost and port specified",
),
pytest.param(
{
"host_input": "localhost",
"port_input": None,
"tls_input": True,
},
{
"host": "localhost",
"port": 9099,
"tls": True,
},
id="localhost and TLS specified",
),
],
)
def test_apply_config_overrides(inputs: dict, expected_outputs: dict):
# Set fake default values for testing
config = Config(
api=ApiConfig(key="fake_api_key"),
engine=EngineConfig(
host=DEFAULT_HOST,
port=DEFAULT_PORT,
tls=DEFAULT_TLS,
),
)
apply_config_overrides(config, inputs["host_input"], inputs["port_input"], inputs["tls_input"])
assert config.engine.host == expected_outputs["host"]
assert config.engine.port == expected_outputs["port"]
assert config.engine.tls == expected_outputs["tls"]