Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/test_vibe_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ def test_derive_health_url_drops_status_query_parameters(self):
"http://localhost:8080/api/health",
)

def test_derive_health_url_reports_invalid_url_without_traceback(self):
with self.assertRaisesRegex(RuntimeError, "无效的 InkDash URL"):
vibe_update.derive_health_url("http://[::1")

def test_format_health_summary(self):
summary = vibe_update.format_health_summary({
"status": "ok",
Expand Down Expand Up @@ -295,6 +299,19 @@ def test_wait_for_health_times_out_with_last_error(self):
monotonic_fn=iter([0.0, 0.0]).__next__,
)

def test_wait_for_health_rejects_invalid_url_before_retry(self):
with patch("vibe_update.request_vibe") as request_mock:
with self.assertRaisesRegex(RuntimeError, "无效的 InkDash URL"):
vibe_update.wait_for_health(
"http://[::1",
request_timeout=0.1,
wait_timeout=2.0,
wait_interval=0.1,
sleep_fn=lambda _: self.fail("invalid URL should not sleep"),
)

request_mock.assert_not_called()

def test_request_vibe_reports_invalid_json_without_traceback(self):
with patch("vibe_update.request.urlopen", return_value=FakeResponse(b"<html>not json</html>")):
with self.assertRaisesRegex(RuntimeError, "不是有效 JSON"):
Expand Down
8 changes: 6 additions & 2 deletions vibe_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ def request_vibe(


def derive_health_url(url: str) -> str:
parsed = urlparse(url.rstrip("/"))
try:
parsed = urlparse(url.rstrip("/"))
except ValueError as e:
raise RuntimeError(f"无效的 InkDash URL:{e}") from e
path = parsed.path.rstrip("/")
for suffix in ("/api/vibe", "/api/status", "/api/health"):
if path.endswith(suffix):
Expand Down Expand Up @@ -405,13 +408,14 @@ def wait_for_health(
sleep_fn=time.sleep,
monotonic_fn=time.monotonic,
) -> Dict[str, Any]:
health_url = derive_health_url(url)
deadline = monotonic_fn() + max(0.0, wait_timeout)
interval = max(0.1, wait_interval)
last_error = ""

while True:
try:
return request_vibe(derive_health_url(url), None, request_timeout, token)
return request_vibe(health_url, None, request_timeout, token)
except RuntimeError as e:
last_error = str(e)

Expand Down
Loading