Download tasks/autoslash/environment/reference/clone/tests/test_autoslash_surface.py from TIGER-Lab/WebsiteBench: direct link, hf CLI and curl.
- Browser
- Download file 24 kB
-
https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/autoslash/environment/reference/clone/tests/test_autoslash_surface.py
- Command line
-
hf download hf://datasets/TIGER-Lab/WebsiteBench/tasks/autoslash/environment/reference/clone/tests/test_autoslash_surface.py
-
curl -L -o test_autoslash_surface.py https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/autoslash/environment/reference/clone/tests/test_autoslash_surface.py
24 kB
| from __future__ import annotations | |
| import importlib | |
| import os | |
| import socket | |
| import sqlite3 | |
| import subprocess | |
| import sys | |
| import time | |
| import urllib.request | |
| from pathlib import Path | |
| import pytest | |
| from fastapi.testclient import TestClient | |
| def app_module(tmp_path: Path, monkeypatch: pytest.MonkeyPatch): | |
| clone = Path(__file__).resolve().parents[1] | |
| runtime = clone.parent / "backend" / "runtime.json" | |
| database = tmp_path / "data" / "autoslash.sqlite3" | |
| monkeypatch.setenv("WEBSITEBENCH_SITE_BACKEND_RUNTIME", str(runtime)) | |
| monkeypatch.setenv("WEBSITEBENCH_SITE_BACKEND_DATABASE", str(database)) | |
| for name in ("app", "backend.business"): | |
| sys.modules.pop(name, None) | |
| module = importlib.import_module("app") | |
| yield module, database | |
| def client(app_module): | |
| module, _ = app_module | |
| with TestClient( | |
| module.app, | |
| base_url="http://testserver", | |
| headers={"Origin": "http://testserver"}, | |
| ) as value: | |
| yield value | |
| def submit_quote( | |
| client: TestClient, | |
| email: str = "reviewer@example.test", | |
| *, | |
| follow_redirects: bool = True, | |
| ): | |
| assert client.get("/").status_code == 200 | |
| response = client.post( | |
| "/quote/pickup-location", | |
| data={"AirportId-display": "Miami International Airport (MIA)"}, | |
| ) | |
| assert response.status_code == 200 | |
| assert "return your rental to the same location" in response.text | |
| response = client.post("/quote/dropoff-location", data={"same_location": "yes"}) | |
| assert "When will you pick up" in response.text | |
| response = client.post( | |
| "/quote/pickup-date", | |
| data={"pickup_date": "2026-09-18", "pickup_time": "10:00"}, | |
| ) | |
| assert "When will you drop off" in response.text | |
| response = client.post( | |
| "/quote/dropoff-date", | |
| data={"dropoff_date": "2026-09-21", "dropoff_time": "10:00"}, | |
| ) | |
| assert "What kind of vehicle would you like" in response.text | |
| response = client.post("/quote/vehicle", data={"CarClass": "ECAR"}) | |
| assert "Which of these credit cards do you have" in response.text | |
| response = client.post( | |
| "/quote/memberships", data={"AffiliationIds": ["3", "25"]} | |
| ) | |
| assert "FirstName" in response.text | |
| return client.post( | |
| "/quote/contact-info", | |
| data={ | |
| "FirstName": "Review", | |
| "LastName": "User", | |
| "Email": email, | |
| "ConfirmEmail": email, | |
| "PointOfSaleCountry": "US", | |
| }, | |
| follow_redirects=follow_redirects, | |
| ) | |
| def submit_tracking( | |
| client: TestClient, | |
| email: str = "reviewer@example.test", | |
| *, | |
| follow_redirects: bool = True, | |
| ): | |
| response = client.post( | |
| "/price-tracking/confirmation", | |
| data={"CompanyId": "Budget", "ConfirmationNumber": "SYNTH-123"}, | |
| ) | |
| assert "When is your rental" in response.text | |
| response = client.post( | |
| "/price-tracking/date", | |
| data={"pickup_date": "2026-09-18", "dropoff_date": "2026-09-21"}, | |
| ) | |
| assert "What price did you book" in response.text | |
| response = client.post( | |
| "/price-tracking/price", data={"total_price": "184.12", "currency": "USD"} | |
| ) | |
| assert "eligible discounts" in response.text | |
| response = client.post( | |
| "/price-tracking/deals", data={"deals": ["AAA"]} | |
| ) | |
| assert "price-drop alerts" in response.text | |
| return client.post( | |
| "/price-tracking/email", | |
| data={"email": email, "confirm_email": email}, | |
| follow_redirects=follow_redirects, | |
| ) | |
| def test_exact_health_and_public_routes(client: TestClient) -> None: | |
| assert client.get("/__websitebench/health").json() == {"status": "ok"} | |
| assert client.get("/healthz").json() == {"ok": True, "site_id": "autoslash"} | |
| expected = { | |
| "/": "#1 Site for Cheap Car Rentals", | |
| "/track": "Enter your rental company and confirmation number", | |
| "/reservations/lookup": "Reservation Lookup", | |
| "/reservations/forgot": "Forgot your Trip ID", | |
| "/contact-us": "Contact AutoSlash Support", | |
| "/coupons": "Coupons", | |
| "/frequently-asked-questions": "Frequently asked questions", | |
| "/our-story": "Our Story", | |
| "/how-we-do-it": "How We Do It", | |
| "/privacy-policy": "AUTOSLASH PRIVACY POLICY", | |
| "/terms-of-use": "Site Terms and Conditions", | |
| } | |
| for path, text in expected.items(): | |
| response = client.get(path) | |
| assert response.status_code == 200, path | |
| assert text in response.text, path | |
| if path == "/track": | |
| assert 'class="tracking-video-link"' in response.text | |
| assert 'aria-label="Open the AutoSlash savings video"' in response.text | |
| assert 'class="source-chat-button"' in response.text | |
| assert 'aria-label="Open AutoSlash support"' in response.text | |
| assert '<i></i>Help!</span>' in response.text | |
| assert response.text.count('class="tracking-step-copy"') == 3 | |
| not_found = client.get("/missing/deep/link") | |
| assert not_found.status_code == 404 | |
| assert "Page Not Found" in not_found.text | |
| def test_quote_journey_is_persisted_and_mail_is_local_only( | |
| client: TestClient, app_module | |
| ) -> None: | |
| _, database = app_module | |
| response = submit_quote(client) | |
| assert response.status_code == 200 | |
| assert "working on your quote" in response.text | |
| assert "No credit card is required" in response.text | |
| for expected in ( | |
| "Miami International Airport (MIA)", | |
| "Sep 18, 2026 at 10:00", | |
| "Sep 21, 2026 at 10:00", | |
| "Economy car", | |
| "American Express, Amex Platinum", | |
| "United States", | |
| ): | |
| assert expected in response.text | |
| summary = client.get("/api/session-summary").json() | |
| assert summary == { | |
| "site_id": "autoslash", | |
| "quote_requests": 1, | |
| "tracking_requests": 0, | |
| } | |
| with sqlite3.connect(database) as connection: | |
| assert connection.execute( | |
| "SELECT status FROM autoslash_quote_requests" | |
| ).fetchone() == ("received",) | |
| assert connection.execute( | |
| "SELECT status,is_simulation,purpose FROM websitebench_mail_jobs" | |
| ).fetchone() == ("LOCAL_SIMULATION", 1, "quote-request") | |
| def test_tracking_journey_is_manual_rebook_not_auto_rebook( | |
| client: TestClient, app_module | |
| ) -> None: | |
| _, database = app_module | |
| assert client.get("/track").status_code == 200 | |
| response = submit_tracking(client) | |
| assert response.status_code == 200 | |
| assert "no automatic rebooking occurs" in response.text | |
| for expected in ( | |
| "Budget", | |
| "SYNTH-123", | |
| "Sep 18, 2026", | |
| "Sep 21, 2026", | |
| "$184.12 USD", | |
| "AAA", | |
| ): | |
| assert expected in response.text | |
| assert 'name="card"' not in response.text.lower() | |
| assert 'name="cvv"' not in response.text.lower() | |
| summary = client.get("/api/session-summary").json() | |
| assert summary["tracking_requests"] == 1 | |
| with sqlite3.connect(database) as connection: | |
| payload, status = connection.execute( | |
| "SELECT payload_json,status FROM autoslash_tracking_requests" | |
| ).fetchone() | |
| assert status == "watching" | |
| assert "auto_rebook" not in payload | |
| def test_anonymous_sessions_are_owner_scoped(app_module) -> None: | |
| module, _ = app_module | |
| with ( | |
| TestClient( | |
| module.app, | |
| base_url="http://testserver", | |
| headers={"Origin": "http://testserver"}, | |
| ) as first, | |
| TestClient( | |
| module.app, | |
| base_url="http://testserver", | |
| headers={"Origin": "http://testserver"}, | |
| ) as second, | |
| ): | |
| assert submit_quote(first).status_code == 200 | |
| assert first.get("/api/session-summary").json()["quote_requests"] == 1 | |
| assert second.get("/api/session-summary").json()["quote_requests"] == 0 | |
| assert submit_tracking(second).status_code == 200 | |
| assert second.get("/api/session-summary").json()["tracking_requests"] == 1 | |
| assert first.get("/api/session-summary").json()["tracking_requests"] == 0 | |
| def test_recovery_lookup_and_contact_are_local_and_non_enumerating( | |
| client: TestClient, app_module | |
| ) -> None: | |
| _, database = app_module | |
| bad = client.post("/reservations/lookup", data={"confirmation": "", "email": ""}) | |
| assert "Reservation Lookup" in bad.text | |
| lookup = client.post( | |
| "/reservations/lookup", | |
| data={"confirmation": "SYNTH-404", "email": "lookup@example.test"}, | |
| ) | |
| assert "contains no source-site reservations" in lookup.text | |
| first = client.post( | |
| "/reservations/forgot", data={"email": "known@example.test"} | |
| ) | |
| second = client.post( | |
| "/reservations/forgot", data={"email": "unknown@example.test"} | |
| ) | |
| public_first = first.text.split("Reference:")[0] | |
| public_second = second.text.split("Reference:")[0] | |
| assert public_first == public_second | |
| contact = client.post( | |
| "/contact-us", | |
| data={ | |
| "name": "Synthetic Reviewer", | |
| "email": "support@example.test", | |
| "confirm_email": "support@example.test", | |
| "subject": "Tracking help", | |
| "description": "Synthetic local support request.", | |
| }, | |
| ) | |
| assert "Thanks for contacting us" in contact.text | |
| with sqlite3.connect(database) as connection: | |
| assert connection.execute( | |
| "SELECT COUNT(*) FROM autoslash_support_requests" | |
| ).fetchone() == (1,) | |
| statuses = connection.execute( | |
| "SELECT DISTINCT status FROM websitebench_mail_jobs" | |
| ).fetchall() | |
| assert statuses == [("LOCAL_SIMULATION",)] | |
| def test_no_fictional_shortcuts_or_raw_state(client: TestClient) -> None: | |
| assert client.post("/api/task-763").status_code in {404, 405} | |
| assert client.post("/api/payment", json={"card": "4242"}).status_code in {404, 405} | |
| assert client.get("/api/state").status_code == 404 | |
| source = Path(__file__).resolve().parents[1] / "app.py" | |
| text = source.read_text(encoding="utf-8") | |
| for forbidden in ( | |
| "auto_rebook", | |
| "_expand_catalogue", | |
| "api_payment", | |
| '"password":', | |
| "/api/session/login", | |
| "4242", | |
| ): | |
| assert forbidden not in text | |
| def test_same_origin_boundary_and_local_reference_rewrite( | |
| client: TestClient, app_module | |
| ) -> None: | |
| rejected = client.post( | |
| "/contact-us", | |
| headers={"Origin": "https://attacker.invalid"}, | |
| data={"name": "x"}, | |
| ) | |
| assert rejected.status_code == 403 | |
| module, _ = app_module | |
| with TestClient(module.app, base_url="http://testserver") as unproven: | |
| assert unproven.post("/contact-us", data={"name": "x"}).status_code == 403 | |
| assert unproven.post( | |
| "/contact-us", headers={"Origin": "null"}, data={"name": "x"} | |
| ).status_code == 403 | |
| assert unproven.post( | |
| "/contact-us", | |
| headers={"Origin": "https://testserver"}, | |
| data={"name": "x"}, | |
| ).status_code == 403 | |
| for path in ("/", "/coupons", "/frequently-asked-questions", "/our-story"): | |
| response = client.get(path) | |
| assert "https://www.autoslash.com" not in response.text | |
| assert "http://www.autoslash.com" not in response.text | |
| assert "content-security-policy" in response.headers | |
| def test_loopback_http_session_cookie_is_browser_usable(client: TestClient) -> None: | |
| response = client.get("/") | |
| cookie = response.headers["set-cookie"] | |
| assert cookie.startswith("websitebench-autoslash-session=") | |
| assert "__Host-" not in cookie | |
| assert "Secure" not in cookie | |
| assert response.headers["referrer-policy"] == "same-origin" | |
| assert "name=referrer content=no-referrer" not in response.text | |
| def test_https_keeps_the_runtime_host_cookie_contract(app_module) -> None: | |
| module, _ = app_module | |
| with TestClient(module.app, base_url="https://testserver") as secure_client: | |
| cookie = secure_client.get("/").headers["set-cookie"] | |
| assert cookie.startswith("__Host-websitebench-autoslash-session=") | |
| assert "Secure" in cookie | |
| def test_airport_entry_wins_over_inactive_non_airport_panel( | |
| client: TestClient, | |
| ) -> None: | |
| client.get("/") | |
| response = client.post( | |
| "/quote/pickup-location", | |
| data={ | |
| "AirportId-display": "Miami International Airport (MIA)", | |
| "location_type": "non-airport", | |
| "location": "", | |
| "btnContinue": "Next", | |
| }, | |
| ) | |
| assert "return your rental to the same location" in response.text | |
| def test_membership_step_has_a_real_submit_control(client: TestClient) -> None: | |
| response = client.get("/quote/memberships") | |
| assert '<button type="submit" class="go-to-step2 btn">Next</button>' in response.text | |
| assert ( | |
| '<a href=about:blank#www.autoslash.com/quote/memberships ' | |
| 'class="go-to-step2 btn"' | |
| ) not in response.text | |
| def test_contact_step_preserves_the_visible_default_country( | |
| client: TestClient, | |
| ) -> None: | |
| response = client.get("/quote/contact-info") | |
| assert '<option value="US" selected>United States</option>' in response.text | |
| def test_tracking_price_control_accepts_cents(client: TestClient) -> None: | |
| client.post( | |
| "/price-tracking/confirmation", | |
| data={"CompanyId": "Budget", "ConfirmationNumber": "SYNTH-763"}, | |
| ) | |
| response = client.post( | |
| "/price-tracking/date", | |
| data={"pickup_date": "2026-09-18", "dropoff_date": "2026-09-21"}, | |
| ) | |
| assert 'name="total_price"' in response.text | |
| assert 'step="0.01"' in response.text | |
| def test_final_confirmations_use_get_routes_and_refresh_without_duplicates( | |
| client: TestClient, | |
| ) -> None: | |
| quote = submit_quote(client, follow_redirects=False) | |
| assert quote.status_code == 303 | |
| assert quote.headers["location"] == "/quote/confirmation" | |
| assert "working on your quote" in client.get(quote.headers["location"]).text | |
| assert "working on your quote" in client.get(quote.headers["location"]).text | |
| assert client.get("/api/session-summary").json()["quote_requests"] == 1 | |
| tracking = submit_tracking(client, follow_redirects=False) | |
| assert tracking.status_code == 303 | |
| assert tracking.headers["location"] == "/price-tracking/complete" | |
| assert "watch for lower prices" in client.get(tracking.headers["location"]).text | |
| assert "watch for lower prices" in client.get(tracking.headers["location"]).text | |
| assert client.get("/api/session-summary").json()["tracking_requests"] == 1 | |
| replay = client.post( | |
| "/price-tracking/email", | |
| data={"email": "reviewer@example.test", "confirm_email": "reviewer@example.test"}, | |
| ) | |
| assert replay.status_code == 409 | |
| assert client.get("/api/session-summary").json()["tracking_requests"] == 1 | |
| def test_final_posts_require_complete_server_side_workflow_state( | |
| client: TestClient, | |
| ) -> None: | |
| quote = client.post( | |
| "/quote/contact-info", | |
| data={ | |
| "FirstName": "Direct", | |
| "LastName": "Bypass", | |
| "Email": "direct@example.test", | |
| "ConfirmEmail": "direct@example.test", | |
| }, | |
| ) | |
| assert quote.status_code == 409 | |
| assert "Complete the earlier quote steps" in quote.text | |
| tracking = client.post( | |
| "/price-tracking/email", | |
| data={"email": "direct@example.test", "confirm_email": "direct@example.test"}, | |
| ) | |
| assert tracking.status_code == 409 | |
| assert "Complete the earlier tracking steps" in tracking.text | |
| assert client.get("/api/session-summary").json() == { | |
| "site_id": "autoslash", | |
| "quote_requests": 0, | |
| "tracking_requests": 0, | |
| } | |
| def test_intermediate_posts_require_the_previous_workflow_stage( | |
| client: TestClient, | |
| ) -> None: | |
| quote = client.post( | |
| "/quote/pickup-date", | |
| data={"pickup_date": "2026-09-18", "pickup_time": "10:00"}, | |
| ) | |
| assert quote.status_code == 409 | |
| assert "Start your quote again" in quote.text | |
| tracking = client.post( | |
| "/price-tracking/price", | |
| data={"total_price": "184.12", "currency": "USD"}, | |
| ) | |
| assert tracking.status_code == 409 | |
| assert "Start price tracking again" in tracking.text | |
| # An out-of-order request must not create enough state for a later step. | |
| tracking = client.post( | |
| "/price-tracking/deals", data={"deals": ["AAA"]} | |
| ) | |
| assert tracking.status_code == 409 | |
| final = client.post( | |
| "/price-tracking/email", | |
| data={"email": "direct@example.test", "confirm_email": "direct@example.test"}, | |
| ) | |
| assert final.status_code == 409 | |
| assert client.get("/api/session-summary").json()["tracking_requests"] == 0 | |
| def test_server_rejects_tampered_options_and_invalid_date_order( | |
| client: TestClient, | |
| ) -> None: | |
| invalid_company = client.post( | |
| "/price-tracking/confirmation", | |
| data={ | |
| "CompanyId": "Invented Rental Co", | |
| "TrackingConfirmationNumber": "SYNTH-763", | |
| }, | |
| ) | |
| assert "Choose a rental company" in invalid_company.text | |
| assert client.post( | |
| "/price-tracking/date", | |
| data={"pickup_date": "2026-09-18", "dropoff_date": "2026-09-21"}, | |
| ).status_code == 409 | |
| client.post( | |
| "/quote/pickup-location", | |
| data={"AirportId-display": "Miami International Airport (MIA)"}, | |
| ) | |
| client.post("/quote/dropoff-location", data={"same_location": "yes"}) | |
| invalid_date = client.post( | |
| "/quote/pickup-date", | |
| data={"pickup_date": "not-a-date", "pickup_time": "10:00"}, | |
| ) | |
| assert "When will you pick up" in invalid_date.text | |
| client.post( | |
| "/quote/pickup-date", | |
| data={"pickup_date": "2026-09-18", "pickup_time": "10:00"}, | |
| ) | |
| reversed_dates = client.post( | |
| "/quote/dropoff-date", | |
| data={"dropoff_date": "2026-09-17", "dropoff_time": "10:00"}, | |
| ) | |
| assert "Select a drop-off date after the pickup date" in reversed_dates.text | |
| client.post( | |
| "/quote/dropoff-date", | |
| data={"dropoff_date": "2026-09-21", "dropoff_time": "10:00"}, | |
| ) | |
| client.post("/quote/vehicle", data={"CarClass": "INVENTED"}) | |
| valid_vehicle = client.post("/quote/vehicle", data={"CarClass": "ECAR"}) | |
| assert "Which of these credit cards" in valid_vehicle.text | |
| invalid_membership = client.post( | |
| "/quote/memberships", data={"AffiliationIds": ["INVENTED"]} | |
| ) | |
| assert "Which of these credit cards" in invalid_membership.text | |
| client.post("/quote/memberships", data={"AffiliationIds": ["3"]}) | |
| invalid_country = client.post( | |
| "/quote/contact-info", | |
| data={ | |
| "FirstName": "Review", | |
| "LastName": "User", | |
| "Email": "reviewer@example.test", | |
| "ConfirmEmail": "reviewer@example.test", | |
| "PointOfSaleCountry": "INVENTED", | |
| }, | |
| ) | |
| assert "Driver's license issued by" in invalid_country.text | |
| assert client.get("/api/session-summary").json()["quote_requests"] == 0 | |
| def test_owner_records_survive_app_restart(app_module) -> None: | |
| module, _ = app_module | |
| cookie_name = "websitebench-autoslash-session" | |
| with TestClient( | |
| module.app, | |
| base_url="http://testserver", | |
| headers={"Origin": "http://testserver"}, | |
| ) as first: | |
| assert submit_quote(first).status_code == 200 | |
| token = first.cookies.get(cookie_name) | |
| assert token | |
| sys.modules.pop("app", None) | |
| restarted = importlib.import_module("app") | |
| with TestClient(restarted.app, base_url="http://testserver") as second: | |
| summary = second.get( | |
| "/api/session-summary", | |
| headers={"Cookie": f"{cookie_name}={token}"}, | |
| ).json() | |
| assert summary["quote_requests"] == 1 | |
| def test_reference_extended_controls_have_real_local_state_targets( | |
| client: TestClient, | |
| ) -> None: | |
| faq = client.get("/frequently-asked-questions").text | |
| assert 'class="faq-empty-message"' in faq | |
| assert "No results. No FAQ answers match your search." in faq | |
| coupons = client.get("/coupons").text | |
| assert 'id="coupon-company-select"' in coupons | |
| assert '<option value="All">All Companies</option>' in coupons | |
| assert '<option value="Avis">Avis</option>' in coupons | |
| home = client.get("/").text | |
| assert 'class="mobile-menu-icon"' in home | |
| assert 'class="mobile-menu-nav"' in home | |
| assert 'href="/track"' in home | |
| assert 'class="mobile-logo popup-from-top sf-hidden"' not in home | |
| def test_reference_interactions_and_company_contract(client: TestClient) -> None: | |
| script = client.get("/static/site/reference-interactions.js").text | |
| assert "tab-non-airport" in script | |
| assert 'node.style.display = localMode ? "none" : ""' in script | |
| assert 'localTab.classList.toggle("active", localMode)' in script | |
| assert 'airportTab.classList.toggle("active", !localMode)' in script | |
| navigation = client.get("/static/site/navigation.css").text | |
| assert 'li:nth-child(6) > a::before' in navigation | |
| assert 'body[data-view="track"] .desktop-nav' in navigation | |
| assert 'body[data-view="contact"] .desktop-nav' in navigation | |
| assert 'body[data-view="track"] .clone-header .brand img' in navigation | |
| assert 'font: 700 14px/1.25 AutoSans' in navigation | |
| assert "modal-mobile-menu" in client.get("/").text | |
| app_script = client.get("/static/site/autoslash.js").text | |
| assert "bindFaq" in app_script | |
| assert "bindCoupons" in app_script | |
| track = client.get("/track").text | |
| assert 'name="TrackingConfirmationNumber"' in track | |
| assert 'placeholder="rental confirmation number"' in track | |
| assert '<svg viewBox="0 0 320 512"' in track | |
| assert 'aria-label="Twitter">♥' not in track | |
| home = client.get("/").text | |
| for asset in ( | |
| "/static/site/assets/pic-steps-request-mobile-1.svg", | |
| "/static/site/assets/pic-steps-request-mobile-2.svg", | |
| "/static/site/assets/pic-steps-request-mobile-3.svg", | |
| ): | |
| assert asset in home | |
| assert client.get(asset).status_code == 200 | |
| assert "Who Owns Hertz Car Rental?" in home | |
| assert "What to Know About Car Rentals in North Carolina" in home | |
| track = client.get("/track").text | |
| assert track.count("<option") == 153 | |
| assert "Other (Not Listed)" in track | |
| assert "In the News" in track | |
| assert "All About Autoslash: The #1 Tool to Save on Rental Cars!" in track | |
| assert track.count("tracking-card-read-more") == 2 | |
| def test_compile_points_to_site_runtime_contract() -> None: | |
| clone = Path(__file__).resolve().parents[1] | |
| subprocess.run([str(clone / "compile.sh")], cwd=clone, check=True) | |
| executable = (clone / "executable").read_text(encoding="utf-8") | |
| assert '$ROOT/../backend/runtime.json' in executable | |
| def test_executable_normalizes_sigterm_to_clean_exit(tmp_path: Path) -> None: | |
| clone = Path(__file__).resolve().parents[1] | |
| subprocess.run([str(clone / "compile.sh")], cwd=clone, check=True) | |
| with socket.socket() as listener: | |
| listener.bind(("127.0.0.1", 0)) | |
| port = listener.getsockname()[1] | |
| environment = os.environ | { | |
| "HOST": "127.0.0.1", | |
| "PORT": str(port), | |
| "DATA_DIR": str(tmp_path / "data"), | |
| "SEED": "672", | |
| "TZ": "Etc/UTC", | |
| "PYTHON": sys.executable, | |
| } | |
| process = subprocess.Popen( | |
| [str(clone / "executable")], cwd=clone, env=environment | |
| ) | |
| try: | |
| for _ in range(40): | |
| try: | |
| with urllib.request.urlopen( | |
| f"http://127.0.0.1:{port}/__websitebench/health", timeout=0.2 | |
| ) as response: | |
| if response.read() == b'{"status":"ok"}': | |
| break | |
| except OSError: | |
| time.sleep(0.05) | |
| else: | |
| pytest.fail("executable did not become healthy") | |
| process.terminate() | |
| assert process.wait(timeout=5) == 0 | |
| finally: | |
| if process.poll() is None: | |
| process.kill() | |
| process.wait(timeout=5) | |