Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
"""Regression test: malformed AGENT_PORT must not crash server startup.
|
|
|
|
Both server variants parsed AGENT_PORT with bare int() (one inside
|
|
build_parser's default, one in main), so AGENT_PORT=abc crashed with an
|
|
unhandled ValueError at startup. They now fall back to 8000 with a warning.
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
|
|
|
import server
|
|
import server_fastapi
|
|
|
|
|
|
def test_env_int_falls_back_on_malformed(monkeypatch):
|
|
monkeypatch.setenv("AGENT_PORT", "abc")
|
|
assert server._env_int("AGENT_PORT", 8000) == 8000
|
|
assert server_fastapi._env_int("AGENT_PORT", 8000) == 8000
|
|
|
|
|
|
def test_env_int_parses_valid_value(monkeypatch):
|
|
monkeypatch.setenv("AGENT_PORT", "9000")
|
|
assert server._env_int("AGENT_PORT", 8000) == 9000
|
|
assert server_fastapi._env_int("AGENT_PORT", 8000) == 9000
|
|
|
|
|
|
def test_env_int_default_when_unset(monkeypatch):
|
|
monkeypatch.delenv("AGENT_PORT", raising=False)
|
|
assert server._env_int("AGENT_PORT", 8000) == 8000
|
|
|
|
|
|
def test_build_parser_survives_malformed_env(monkeypatch):
|
|
monkeypatch.setenv("AGENT_PORT", "not-a-port")
|
|
args = server.build_parser().parse_args([])
|
|
assert args.port == 8000
|