feat(EXEC-001): add hedge strategy builder

This commit is contained in:
Bu5hm4nn
2026-03-27 22:33:20 +01:00
parent 554a41a060
commit 4620234967
9 changed files with 429 additions and 37 deletions

View File

@@ -0,0 +1,62 @@
from __future__ import annotations
from pathlib import Path
from uuid import uuid4
from playwright.sync_api import expect, sync_playwright
BASE_URL = "http://127.0.0.1:8000"
ARTIFACTS = Path("tests/artifacts")
ARTIFACTS.mkdir(parents=True, exist_ok=True)
def test_hedge_builder_saves_template_and_reuses_it_in_backtests() -> None:
template_name = f"Crash Guard 95 {uuid4().hex[:8]}"
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page(viewport={"width": 1440, "height": 1000})
page.goto(BASE_URL, wait_until="domcontentloaded", timeout=30000)
page.get_by_role("button", name="Get started").click()
page.wait_for_url(f"{BASE_URL}/*", timeout=15000)
workspace_url = page.url
page.goto(f"{workspace_url}/hedge", wait_until="domcontentloaded", timeout=30000)
expect(page.locator("text=Hedge Analysis").first).to_be_visible(timeout=15000)
expect(page.locator("text=Strategy Builder").first).to_be_visible(timeout=15000)
expect(page.get_by_label("Strategy selector")).to_be_visible(timeout=15000)
hedge_text = page.locator("body").inner_text(timeout=15000)
assert "$6.25/oz" in hedge_text
page.get_by_label("Template name").fill(template_name)
page.get_by_label("Expiration days").fill("180")
page.get_by_label("Primary strike (% of spot)").fill("95")
page.get_by_role("button", name="Save template").click()
expect(
page.locator(f"text=Saved template {template_name}. Reusable on hedge, backtests, and event comparison.")
).to_be_visible(timeout=15000)
expect(page.get_by_label("Strategy selector")).to_have_value(template_name, timeout=15000)
hedge_text = page.locator("body").inner_text(timeout=15000)
assert "Selected template: " + template_name in hedge_text
assert "Custom 180-day protective put at 95% strike." in hedge_text
assert "$3.49/oz" in hedge_text
assert "$4.95/oz" not in hedge_text
assert "RuntimeError" not in hedge_text
assert "Server error" not in hedge_text
page.screenshot(path=str(ARTIFACTS / "hedge-builder.png"), full_page=True)
page.goto(f"{workspace_url}/backtests", wait_until="networkidle", timeout=30000)
expect(page.locator("text=Backtests").first).to_be_visible(timeout=15000)
page.get_by_label("Template").click()
expect(page.get_by_text(template_name, exact=True)).to_be_visible(timeout=15000)
page.goto(f"{workspace_url}/event-comparison", wait_until="networkidle", timeout=30000)
expect(page.locator("text=Event Comparison").first).to_be_visible(timeout=15000)
page.get_by_label("Strategy templates").click()
expect(page.get_by_text(template_name, exact=True)).to_be_visible(timeout=15000)
browser.close()