Skip to content

Commit b7c59b9

Browse files
committed
task: set status betterstack page conditionally for staging and production
1 parent b702567 commit b7c59b9

3 files changed

Lines changed: 113 additions & 16 deletions

File tree

src/aignostics/gui/_frame.py

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from loguru import logger
1515

1616
from aignostics.constants import WINDOW_TITLE
17+
from aignostics.platform import API_ROOT_PRODUCTION, API_ROOT_STAGING
1718
from aignostics.utils import __version__, open_user_data_directory
1819

1920
from ._theme import theme
@@ -29,6 +30,24 @@
2930
CLASSES_FULL_SIZE = f"{CLASSES_FULL_WIDTH} {CLASSES_FULL_HEIGHT}"
3031

3132

33+
def get_status_page_url(api_root: str) -> str | None:
34+
"""Get the status page URL based on the API root environment.
35+
36+
Args:
37+
api_root: The API root URL to determine the environment
38+
39+
Returns:
40+
The status page URL for production/staging, or None for dev/test
41+
"""
42+
if api_root == API_ROOT_PRODUCTION:
43+
return "https://status.platform.aignostics.com"
44+
elif api_root == API_ROOT_STAGING:
45+
return "https://status.platform-staging.aignostics.com"
46+
else:
47+
# No status page for dev and test environments
48+
return None
49+
50+
3251
@contextmanager
3352
def frame( # noqa: C901, PLR0915
3453
navigation_title: str,
@@ -213,7 +232,9 @@ def _update_health() -> None:
213232
coroutine=_health_load_and_render(),
214233
name="_health_load_and_render",
215234
)
216-
ui.run_javascript("document.getElementById('betterstack').src = document.getElementById('betterstack').src;")
235+
# Only refresh the status iframe if it exists (production/staging)
236+
if get_status_page_url(settings().api_root):
237+
ui.run_javascript("document.getElementById('betterstack').src = document.getElementById('betterstack').src;")
217238

218239
ui.timer(interval=HEALTH_UPDATE_INTERVAL, callback=_update_health, immediate=True)
219240

@@ -342,13 +363,15 @@ def toggle_dark_mode() -> None:
342363
ui.link("Get Support", "https://platform.aignostics.com/support", new_tab=True).mark(
343364
"LINK_DOCUMENTATION"
344365
)
345-
with ui.item().props("clickable"):
346-
with ui.item_section().props("avatar"):
347-
ui.icon("check_circle", color="primary")
348-
with ui.item_section():
349-
ui.link("Check Platform Status", "https://status.aignostics.com", new_tab=True).mark(
350-
"LINK_DOCUMENTATION"
351-
)
366+
status_url = get_status_page_url(settings().api_root)
367+
if status_url:
368+
with ui.item().props("clickable"):
369+
with ui.item_section().props("avatar"):
370+
ui.icon("check_circle", color="primary")
371+
with ui.item_section():
372+
ui.link("Check Platform Status", status_url, new_tab=True).mark(
373+
"LINK_DOCUMENTATION"
374+
)
352375
with ui.item().props("clickable"):
353376
with ui.item_section().props("avatar"):
354377
ui.icon("handshake", color="primary")
@@ -368,14 +391,16 @@ def toggle_dark_mode() -> None:
368391
ui.row(align_items="center").classes("justify-start w-full"),
369392
):
370393
health_link()
371-
with ui.row().style("padding: 0"):
372-
ui.html(
373-
'<iframe id="betterstack" src="https://status.aignostics.com/badge?theme=dark" '
374-
'width="250" height="30" frameborder="0" scrolling="no" '
375-
'style="color-scheme: dark"></iframe>',
376-
sanitize=False,
377-
).style("margin-left: 0px;")
378-
ui.tooltip("Check Platform Status")
394+
status_url = get_status_page_url(settings().api_root)
395+
if status_url:
396+
with ui.row().style("padding: 0"):
397+
ui.html(
398+
f'<iframe id="betterstack" src="{status_url}/badge?theme=dark" '
399+
'width="250" height="30" frameborder="0" scrolling="no" '
400+
'style="color-scheme: dark"></iframe>',
401+
sanitize=False,
402+
).style("margin-left: 0px;")
403+
ui.tooltip("Check Platform Status")
379404
ui.space()
380405
with ui.row():
381406
flavor = " (native)" if getattr(sys, "frozen", False) else ""

tests/aignostics/gui/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Tests for GUI module."""

tests/aignostics/gui/frame_test.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""Tests for GUI frame module."""
2+
3+
import pytest
4+
5+
from aignostics.gui._frame import get_status_page_url
6+
from aignostics.platform import (
7+
API_ROOT_DEV,
8+
API_ROOT_PRODUCTION,
9+
API_ROOT_STAGING,
10+
API_ROOT_TEST,
11+
)
12+
13+
14+
@pytest.mark.unit
15+
def test_get_status_page_url_production(record_property) -> None:
16+
"""Test that production environment returns correct status page URL.
17+
18+
Args:
19+
record_property: pytest record_property fixture
20+
"""
21+
record_property("tested-item-id", "SPEC-GUI-FRAME")
22+
url = get_status_page_url(API_ROOT_PRODUCTION)
23+
assert url == "https://status.platform.aignostics.com"
24+
25+
26+
@pytest.mark.unit
27+
def test_get_status_page_url_staging(record_property) -> None:
28+
"""Test that staging environment returns correct status page URL.
29+
30+
Args:
31+
record_property: pytest record_property fixture
32+
"""
33+
record_property("tested-item-id", "SPEC-GUI-FRAME")
34+
url = get_status_page_url(API_ROOT_STAGING)
35+
assert url == "https://status.platform-staging.aignostics.com"
36+
37+
38+
@pytest.mark.unit
39+
def test_get_status_page_url_dev(record_property) -> None:
40+
"""Test that dev environment returns None (no status page).
41+
42+
Args:
43+
record_property: pytest record_property fixture
44+
"""
45+
record_property("tested-item-id", "SPEC-GUI-FRAME")
46+
url = get_status_page_url(API_ROOT_DEV)
47+
assert url is None
48+
49+
50+
@pytest.mark.unit
51+
def test_get_status_page_url_test(record_property) -> None:
52+
"""Test that test environment returns None (no status page).
53+
54+
Args:
55+
record_property: pytest record_property fixture
56+
"""
57+
record_property("tested-item-id", "SPEC-GUI-FRAME")
58+
url = get_status_page_url(API_ROOT_TEST)
59+
assert url is None
60+
61+
62+
@pytest.mark.unit
63+
def test_get_status_page_url_unknown(record_property) -> None:
64+
"""Test that unknown environment returns None (no status page).
65+
66+
Args:
67+
record_property: pytest record_property fixture
68+
"""
69+
record_property("tested-item-id", "SPEC-GUI-FRAME")
70+
url = get_status_page_url("https://custom.example.com")
71+
assert url is None

0 commit comments

Comments
 (0)