File size: 24,003 Bytes
34be7eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
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


@pytest.fixture
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


@pytest.fixture
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)