fix: restore workspace nav and correct overview spot fallback

This commit is contained in:
Bu5hm4nn
2026-03-24 20:54:45 +01:00
parent 75f8e0a282
commit 2cbe4f274d
4 changed files with 74 additions and 7 deletions

View File

@@ -97,17 +97,34 @@ def test_homepage_and_options_page_render() -> None:
expect(page.locator("text=Settings").first).to_be_visible(timeout=15000)
expect(page.locator("text=Collateral entry basis").first).to_be_visible(timeout=15000)
expect(page.locator("text=Entry price ($/oz)").first).to_be_visible(timeout=15000)
page.get_by_label("Collateral entry basis").click()
page.get_by_text("Gold weight + entry price", exact=True).click()
page.get_by_label("Entry price ($/oz)").fill("4400")
page.get_by_label("Gold weight (oz)").fill("220")
budget_input = page.get_by_label("Monthly hedge budget ($)")
budget_input.fill("12345")
page.get_by_role("button", name="Save settings").click()
expect(page.locator("text=Settings saved successfully").first).to_be_visible(timeout=15000)
page.reload(wait_until="domcontentloaded", timeout=30000)
expect(page.get_by_label("Monthly hedge budget ($)")).to_have_value("12345")
expect(page.get_by_label("Entry price ($/oz)")).to_have_value("4400")
settings_text = page.locator("body").inner_text(timeout=15000)
assert "RuntimeError" not in settings_text
assert "Server error" not in settings_text
page.screenshot(path=str(ARTIFACTS / "settings.png"), full_page=True)
page.goto(workspace_url, wait_until="domcontentloaded", timeout=30000)
overview_text = page.locator("body").inner_text(timeout=15000)
assert "Hedge Analysis" in overview_text
assert "Options Chain" in overview_text
assert "Backtests" in overview_text
assert "Event Comparison" in overview_text
assert "Live quote source: configured entry price fallback" in overview_text
assert "$878.79" in overview_text
assert "$968,000.00" in overview_text
assert "$823,000.00" in overview_text
second_context = browser.new_context(viewport={"width": 1440, "height": 1000})
second_page = second_context.new_page()
second_page.goto(BASE_URL, wait_until="domcontentloaded", timeout=30000)

View File

@@ -0,0 +1,26 @@
from __future__ import annotations
from app.models.portfolio import PortfolioConfig
from app.pages.overview import _resolve_overview_spot
from app.services.alerts import build_portfolio_alert_context
def test_overview_falls_back_to_configured_entry_price_when_live_quote_units_do_not_match() -> None:
config = PortfolioConfig(entry_price=4400.0, gold_ounces=220.0, entry_basis_mode="weight", loan_amount=145000.0)
spot_price, source, updated_at = _resolve_overview_spot(
config,
{"price": 404.19, "source": "yfinance", "updated_at": "2026-03-24T00:00:00+00:00"},
)
portfolio = build_portfolio_alert_context(
config,
spot_price=spot_price,
source=source,
updated_at=updated_at,
)
assert spot_price == 4400.0
assert source == "configured_entry_price"
assert portfolio["gold_value"] == 968000.0
assert portfolio["net_equity"] == 823000.0
assert round(float(portfolio["margin_call_price"]), 2) == 878.79