summaryrefslogtreecommitdiff
path: root/tests/test_config.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_config.py')
-rw-r--r--tests/test_config.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index c24064b..9a6bf89 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -123,3 +123,75 @@ def test_can_skip_path_checks_for_schema_only_use(tmp_path: Path) -> None:
config = load_config(path, validate_paths=False)
assert config.model.root == (tmp_path / "missing").resolve()
assert config.generation.scheduler == "dpmpp_2m_karras"
+
+
+def test_server_defaults_to_stdio_when_omitted(tmp_path: Path) -> None:
+ path = tmp_path / "config.toml"
+ path.write_text(
+ f'[model]\nroot = "{tmp_path.as_posix()}"\ncheckpoint = "base.safetensors"\n',
+ encoding="utf-8",
+ )
+ config = load_config(path, validate_paths=False)
+ assert config.server.transport == "stdio"
+ assert config.server.host == "127.0.0.1"
+ assert config.server.port == 8000
+
+
+def test_server_reads_streamable_http(tmp_path: Path) -> None:
+ path = tmp_path / "config.toml"
+ path.write_text(
+ f'[model]\nroot = "{tmp_path.as_posix()}"\ncheckpoint = "base.safetensors"\n'
+ '[server]\ntransport = "streamable-http"\nhost = "0.0.0.0"\nport = 9000\n',
+ encoding="utf-8",
+ )
+ config = load_config(path, validate_paths=False)
+ assert config.server.transport == "streamable-http"
+ assert config.server.host == "0.0.0.0"
+ assert config.server.port == 9000
+
+
+@pytest.mark.parametrize(
+ "transport",
+ ["sse", "http", "ws", "unknown"],
+)
+def test_rejects_invalid_transport(tmp_path: Path, transport: str) -> None:
+ path = tmp_path / "config.toml"
+ path.write_text(
+ f'[model]\nroot = "{tmp_path.as_posix()}"\ncheckpoint = "base.safetensors"\n'
+ f'[server]\ntransport = "{transport}"\n',
+ encoding="utf-8",
+ )
+ with pytest.raises(ConfigError, match="transport"):
+ load_config(path, validate_paths=False)
+
+
+@pytest.mark.parametrize(
+ "port, message",
+ [
+ (0, "port"),
+ (65536, "port"),
+ (-1, "port"),
+ ("8000", "port"),
+ ],
+)
+def test_rejects_invalid_port(tmp_path: Path, port: str | int, message: str) -> None:
+ path = tmp_path / "config.toml"
+ port_literal = f'"{port}"' if isinstance(port, str) else str(port)
+ path.write_text(
+ f'[model]\nroot = "{tmp_path.as_posix()}"\ncheckpoint = "base.safetensors"\n'
+ f'[server]\ntransport = "streamable-http"\nport = {port_literal}\n',
+ encoding="utf-8",
+ )
+ with pytest.raises(ConfigError, match=message):
+ load_config(path, validate_paths=False)
+
+
+def test_rejects_empty_host(tmp_path: Path) -> None:
+ path = tmp_path / "config.toml"
+ path.write_text(
+ f'[model]\nroot = "{tmp_path.as_posix()}"\ncheckpoint = "base.safetensors"\n'
+ '[server]\ntransport = "streamable-http"\nhost = ""\n',
+ encoding="utf-8",
+ )
+ with pytest.raises(ConfigError, match="host"):
+ load_config(path, validate_paths=False)