STUDY METHODS SOURCE EXCERPTS; not a standalone executable.
Source identifier: DEV008-upstream-compatible-verifier

--- Original lines 48-52 ---
def check(label: str, weight: int, passed: bool, detail: str = "") -> None:
    _checks.append((label, weight, passed, detail))
    status = "PASS" if passed else "FAIL"
    tail = f"  ({detail})" if detail else ""
    print(f"[{status}] ({weight}pt) {label}{tail}", file=sys.stderr)

--- Original lines 135-137 ---
def _local_utc_offset() -> timedelta:
    """UTC offset of the verifier host's local timezone (deployment tz)."""
    return datetime.now().astimezone().utcoffset() or timedelta(0)

--- Original lines 140-157 ---
def date_matches_tz(stored: str, exp_date: str) -> bool:
    """True if a stored timestamp/date corresponds to calendar date exp_date.

    Twenty stores date fields as UTC timestamps; a local date D entered in the
    UI on a UTC+N deployment is stored as (D-1)T(24-N):00:00Z. Accept only
    stored::date == exp_date or (stored + local_utc_offset)::date == exp_date.
    A pure 10-char date must match exactly.
    """
    stored = (stored or "").strip()
    if len(stored) == 10:
        return stored == exp_date
    try:
        dt = datetime.strptime(stored[:19].replace("T", " "), "%Y-%m-%d %H:%M:%S")
    except ValueError:
        return False
    if dt.strftime("%Y-%m-%d") == exp_date:
        return True
    return (dt + _local_utc_offset()).strftime("%Y-%m-%d") == exp_date

--- Original lines 166-194 ---
def check_1_twenty_company() -> None:
    """Company 'Juniper 8975064F Systems' with domain juniper-8975064f.example and 422 employees."""
    global _twenty_company_id
    try:
        ws = get_twenty_workspace_schema()
        row = twenty_sql(
            f'SELECT id, name, "domainNamePrimaryLinkUrl", employees '
            f'FROM "{ws}".company '
            f"WHERE name = 'Juniper 8975064F Systems' AND \"deletedAt\" IS NULL "
            f"LIMIT 1;"
        )
        if not row:
            check("1. Twenty company Juniper 8975064F Systems", 2, False, "not found")
            return
        parts = row.split("|")
        cid = parts[0].strip()
        name = parts[1].strip() if len(parts) > 1 else ""
        domain = parts[2].strip() if len(parts) > 2 else ""
        employees = parts[3].strip() if len(parts) > 3 else ""
        _twenty_company_id = cid
        ok = (
            name == "Juniper 8975064F Systems"
            and "juniper-8975064f.example" in domain
            and str(employees) == "422"
        )
        check("1. Twenty company Juniper 8975064F Systems", 2, ok,
              f"domain={domain}, employees={employees}")
    except Exception as e:
        check("1. Twenty company Juniper 8975064F Systems", 2, False, f"exception: {e}")

--- Original lines 197-233 ---
def check_2_twenty_person() -> None:
    """Person 'Maya Patel' with email, title, phone, linked to Juniper 8975064F Systems."""
    try:
        ws = get_twenty_workspace_schema()
        row = twenty_sql(
            f'SELECT p."nameFirstName", p."nameLastName", p."emailsPrimaryEmail", '
            f'p."jobTitle", p."phonesPrimaryPhoneNumber" '
            f'FROM "{ws}".person p '
            f'JOIN "{ws}".company c ON p."companyId" = c.id '
            f"AND c.name = 'Juniper 8975064F Systems' AND c.\"deletedAt\" IS NULL "
            f"WHERE p.\"emailsPrimaryEmail\" = 'maya.patel@juniper-8975064f.example' "
            f"AND p.\"deletedAt\" IS NULL "
            f"LIMIT 1;"
        )
        if not row:
            check("2. Twenty person Maya Patel", 2, False,
                  "not found (or not linked to company Juniper 8975064F Systems)")
            return
        parts = row.split("|")
        first = parts[0].strip()
        last = parts[1].strip() if len(parts) > 1 else ""
        email = parts[2].strip() if len(parts) > 2 else ""
        title = parts[3].strip() if len(parts) > 3 else ""
        phone = parts[4].strip() if len(parts) > 4 else ""
        digits = re.sub(r"\D", "", phone)
        phone_ok = digits.endswith("12025550155") or digits == "2025550155"
        ok = (
            first == "Maya" and last == "Patel"
            and email == "maya.patel@juniper-8975064f.example"
            and "Director of Engineering" in title
            and phone_ok
        )
        check("2. Twenty person Maya Patel", 2, ok,
              f"name={first} {last}, title={title}, phone={phone}, "
              f"phone_ok={phone_ok}, company_linked=yes")
    except Exception as e:
        check("2. Twenty person Maya Patel", 2, False, f"exception: {e}")

--- Original lines 236-275 ---
def check_3_twenty_opportunity() -> None:
    """Opportunity with amount 130300, stage Won, close date 2026-07-01, correct links."""
    try:
        ws = get_twenty_workspace_schema()
        row = twenty_sql(
            f'SELECT o.name, o."amountAmountMicros", o.stage, o."closeDate"::text '
            f'FROM "{ws}".opportunity o '
            f'JOIN "{ws}".company c ON o."companyId" = c.id '
            f"AND c.name = 'Juniper 8975064F Systems' AND c.\"deletedAt\" IS NULL "
            f'JOIN "{ws}".person p ON o."pointOfContactId" = p.id '
            f"AND p.\"emailsPrimaryEmail\" = 'maya.patel@juniper-8975064f.example' "
            f"AND p.\"deletedAt\" IS NULL "
            f"WHERE o.name LIKE '%Juniper 8975064F Systems%Enterprise Software Modernization%' "
            f"AND o.\"deletedAt\" IS NULL "
            f"LIMIT 1;"
        )
        if not row:
            check("3. Twenty opportunity", 2, False,
                  "not found (or not linked to company + point of contact)")
            return
        parts = row.split("|")
        name = parts[0].strip()
        amount_raw = parts[1].strip() if len(parts) > 1 else "0"
        stage = parts[2].strip() if len(parts) > 2 else ""
        close_date = parts[3].strip() if len(parts) > 3 else ""

        try:
            amount = int(amount_raw) / 1_000_000
        except (ValueError, TypeError):
            amount = float(amount_raw or 0)
        amount_ok = abs(amount - 130300.0) < 1.0
        stage_ok = stage.upper() == "WON"
        date_ok = date_matches_tz(close_date, "2026-07-01")

        ok = amount_ok and stage_ok and date_ok
        check("3. Twenty opportunity", 2, ok,
              f"amount={amount}, stage={stage}, closeDate={close_date}, "
              f"date_ok={date_ok}, links=ok")
    except Exception as e:
        check("3. Twenty opportunity", 2, False, f"exception: {e}")

--- Original lines 278-295 ---
def check_4_twenty_favorite() -> None:
    """Company 'Juniper 8975064F Systems' is marked as a favorite."""
    try:
        if not _twenty_company_id:
            check("4. Twenty company is favorite", 1, False, "company ID unknown from check 1")
            return
        ws = get_twenty_workspace_schema()
        row = twenty_sql(
            f'SELECT id FROM "{ws}".favorite '
            f"WHERE \"companyId\" = '{_twenty_company_id}' "
            f"AND \"deletedAt\" IS NULL "
            f"LIMIT 1;"
        )
        ok = bool(row)
        check("4. Twenty company is favorite", 1, ok,
              "found" if ok else "no favorite record")
    except Exception as e:
        check("4. Twenty company is favorite", 1, False, f"exception: {e}")

--- Original lines 298-312 ---
def _twenty_task_on_opportunity(ws: str, title_like: str) -> str:
    """Fetch a task by title, required to be linked to the Arcturus opportunity."""
    return twenty_sql(
        f'SELECT t.title, t."dueAt"::text, '
        f"regexp_replace(t.\"bodyV2Markdown\", E'[\\n\\r]+', ' ', 'g') "
        f'FROM "{ws}".task t '
        f'JOIN "{ws}"."taskTarget" tt ON tt."taskId" = t.id '
        f"AND tt.\"deletedAt\" IS NULL "
        f'JOIN "{ws}".opportunity o ON tt."targetOpportunityId" = o.id '
        f"AND o.name LIKE '%Juniper 8975064F Systems%Enterprise Software Modernization%' "
        f"AND o.\"deletedAt\" IS NULL "
        f"WHERE t.title LIKE '{title_like}' "
        f"AND t.\"deletedAt\" IS NULL "
        f"LIMIT 1;"
    )

--- Original lines 315-344 ---
def check_5_twenty_task_milestone2() -> None:
    """Task 'Milestone 2 collection — Juniper 8975064F Systems' with due 2026-07-05 and body keywords."""
    try:
        ws = get_twenty_workspace_schema()
        row = _twenty_task_on_opportunity(ws, "%Milestone 2 collection%Juniper 8975064F Systems%")
        if not row:
            check("5. Twenty task Milestone 2 collection", 2, False,
                  "not found (or not linked to the Arcturus opportunity)")
            return
        parts = row.split("|", 2)
        title = parts[0].strip()
        due_at = parts[1].strip() if len(parts) > 1 else ""
        body = parts[2] if len(parts) > 2 else ""

        date_ok = date_matches_tz(due_at, "2026-07-05")
        kw = {
            "70900": "70900" in body,
            "8975064F100VIP": "8975064F100VIP" in body,
            "maya": "maya" in body.lower(),
            "2026-07-05": "2026-07-05" in body,
            "2026-08-08": "2026-08-08" in body,
            "Juniper 8975064F Phase 2": "Juniper 8975064F Phase 2" in body or "Development & Go-Live" in body,
        }
        body_ok = all(kw.values())
        missing = ",".join(k for k, v in kw.items() if not v) or "none"
        ok = date_ok and body_ok
        check("5. Twenty task Milestone 2 collection", 2, ok,
              f"dueAt={'ok' if date_ok else due_at}, body_missing={missing}")
    except Exception as e:
        check("5. Twenty task Milestone 2 collection", 2, False, f"exception: {e}")

--- Original lines 347-376 ---
def check_6_twenty_task_celebration() -> None:
    """Task 'Send celebration invite — Juniper 8975064F Systems' with due 2026-07-26 and body keywords."""
    try:
        ws = get_twenty_workspace_schema()
        row = _twenty_task_on_opportunity(ws, "%Send celebration invite%Juniper 8975064F Systems%")
        if not row:
            check("6. Twenty task Send celebration invite", 2, False,
                  "not found (or not linked to the Arcturus opportunity)")
            return
        parts = row.split("|", 2)
        title = parts[0].strip()
        due_at = parts[1].strip() if len(parts) > 1 else ""
        body = parts[2] if len(parts) > 2 else ""

        date_ok = date_matches_tz(due_at, "2026-07-26")
        bl = body.lower()
        kw = {
            "8975064F100VIP": "8975064F100VIP" in body,
            "maya": "maya" in bl,
            "100%": "100%" in body or "100 %" in body,
            "event_name": "Juniper 8975064F Systems Milestone Celebration" in body,
            "max 3": "max 3" in bl or "max usages 3" in bl,
        }
        body_ok = all(kw.values())
        missing = ",".join(k for k, v in kw.items() if not v) or "none"
        ok = date_ok and body_ok
        check("6. Twenty task Send celebration invite", 2, ok,
              f"dueAt={'ok' if date_ok else due_at}, body_missing={missing}")
    except Exception as e:
        check("6. Twenty task Send celebration invite", 2, False, f"exception: {e}")

--- Original lines 381-401 ---
def check_7_bc_customer() -> None:
    """Customer 'Juniper 8975064F Systems' with email maya.patel@juniper-8975064f.example."""
    try:
        row = bigcapital_sql(
            "SELECT DISPLAY_NAME, IFNULL(EMAIL, '') "
            "FROM CONTACTS "
            "WHERE DISPLAY_NAME = 'Juniper 8975064F Systems' "
            "AND CONTACT_SERVICE = 'customer' "
            "LIMIT 1;"
        )
        if not row:
            check("7. BigCapital customer Juniper 8975064F Systems", 1, False, "not found")
            return
        parts = row.split("\t")
        name = parts[0].strip()
        email = parts[1].strip() if len(parts) > 1 else ""
        ok = name == "Juniper 8975064F Systems" and "maya.patel@juniper-8975064f.example" in email
        check("7. BigCapital customer Juniper 8975064F Systems", 1, ok,
              f"name={name}, email={email}")
    except Exception as e:
        check("7. BigCapital customer Juniper 8975064F Systems", 1, False, f"exception: {e}")

--- Original lines 404-439 ---
def check_8_bc_items() -> None:
    """Items 'Juniper 8975064F Phase 1' (59400) and 'Juniper 8975064F Phase 2' (70900) exist as service type."""
    try:
        rows = bigcapital_sql(
            "SELECT NAME, TYPE, SELL_PRICE "
            "FROM ITEMS "
            "WHERE NAME LIKE 'Juniper 8975064F Phase 1%' OR NAME LIKE 'Juniper 8975064F Phase 2%' "
            "ORDER BY NAME;"
        )
        if not rows:
            check("8. BigCapital items Juniper 8975064F Phase 1 & 2", 2, False, "no items found")
            return
        p1_ok = False
        p2_ok = False
        for line in rows.split("\n"):
            line = line.strip()
            if not line:
                continue
            parts = line.split("\t")
            if len(parts) < 3:
                continue
            name = parts[0].strip()
            type_ok = parts[1].strip().lower() == "service"
            price_raw = parts[2].strip()
            # mysql -N -B renders SQL NULL as the literal string "NULL"
            price = float(price_raw) if price_raw not in ("", "NULL") else 0.0
            if "Requirements" in name and "Solution Design" in name:
                p1_ok = type_ok and abs(price - 59400.0) < 1.0
            elif "Development" in name and "Go-Live" in name:
                p2_ok = type_ok and abs(price - 70900.0) < 1.0

        ok = p1_ok and p2_ok
        check("8. BigCapital items Juniper 8975064F Phase 1 & 2", 2, ok,
              f"Phase1={'ok' if p1_ok else 'FAIL'}, Phase2={'ok' if p2_ok else 'FAIL'}")
    except Exception as e:
        check("8. BigCapital items Juniper 8975064F Phase 1 & 2", 2, False, f"exception: {e}")

--- Original lines 442-463 ---
def check_9_bc_account() -> None:
    """Account 'Deferred Revenue — Juniper 8975064F Enterprise Engagements' as Other Current Liability."""
    try:
        row = bigcapital_sql(
            "SELECT NAME, ACCOUNT_TYPE "
            "FROM ACCOUNTS "
            "WHERE NAME LIKE '%Deferred Revenue%Juniper 8975064F Enterprise Engagements%' "
            "LIMIT 1;"
        )
        if not row:
            check("9. BigCapital deferred revenue account", 1, False, "not found")
            return
        parts = row.split("\t")
        name = parts[0].strip()
        acct_type = parts[1].strip() if len(parts) > 1 else ""
        # BigCapital stores account types with hyphens (e.g. 'other-current-liability')
        normalised = acct_type.lower().replace(" ", "-").replace("_", "-")
        ok = "Deferred Revenue" in name and "other-current-liability" in normalised
        check("9. BigCapital deferred revenue account", 1, ok,
              f"name={name}, type={acct_type}")
    except Exception as e:
        check("9. BigCapital deferred revenue account", 1, False, f"exception: {e}")

--- Original lines 466-498 ---
def _bc_milestone_invoice(label: str, weight: int, inv_date: str,
                          item_like: str, rate: int, due_date: str) -> None:
    """Invoice identified by date + customer + line item; gate DUE_DATE + DELIVERED_AT."""
    try:
        row = bigcapital_sql(
            "SELECT si.ID, si.DUE_DATE, si.DELIVERED_AT "
            "FROM SALES_INVOICES si "
            "JOIN CONTACTS c ON si.CUSTOMER_ID = c.ID "
            "AND c.DISPLAY_NAME = 'Juniper 8975064F Systems' "
            "JOIN ITEMS_ENTRIES ie ON ie.REFERENCE_TYPE = 'SaleInvoice' "
            "AND ie.REFERENCE_ID = si.ID "
            "JOIN ITEMS i ON ie.ITEM_ID = i.ID "
            f"WHERE si.INVOICE_DATE = '{inv_date}' "
            f"AND i.NAME LIKE '{item_like}' "
            f"AND ie.QUANTITY = 1 AND ABS(ie.RATE - {rate}) < 1 "
            "LIMIT 1;"
        )
        if not row:
            check(label, weight, False,
                  f"no invoice dated {inv_date} with line item {item_like} qty 1 @ {rate}")
            return
        parts = row.split("\t")
        due = parts[1].strip() if len(parts) > 1 else ""
        delivered = parts[2].strip() if len(parts) > 2 else ""

        due_ok = due_date in due
        delivered_ok = delivered not in ("", "NULL", "None", "null", "0000-00-00")

        ok = due_ok and delivered_ok
        check(label, weight, ok,
              f"line_item=ok, due={due}, delivered={'yes' if delivered_ok else 'no'}")
    except Exception as e:
        check(label, weight, False, f"exception: {e}")

--- Original lines 501-504 ---
def check_10_bc_invoice1() -> None:
    """Milestone 1 invoice: 2026-03-15, Juniper 8975064F Phase 1 line item qty 1 @ 59400, due 2026-04-14, delivered."""
    _bc_milestone_invoice("10. BigCapital Milestone 1 invoice", 2,
                          "2026-03-15", "Juniper 8975064F Phase 1%", 59400, "2026-04-14")

--- Original lines 507-510 ---
def check_11_bc_invoice2() -> None:
    """Milestone 2 invoice: 2026-06-05, Juniper 8975064F Phase 2 line item qty 1 @ 70900, due 2026-07-05, delivered."""
    _bc_milestone_invoice("11. BigCapital Milestone 2 invoice", 2,
                          "2026-06-05", "Juniper 8975064F Phase 2%", 70900, "2026-07-05")

--- Original lines 513-546 ---
def check_12_bc_payment() -> None:
    """Payment of 59400 dated 2026-04-20, applied to the Milestone 1 invoice, into Petty Cash."""
    try:
        row = bigcapital_sql(
            "SELECT pr.PAYMENT_DATE, pr.AMOUNT, a.NAME "
            "FROM PAYMENT_RECEIVES pr "
            "JOIN PAYMENT_RECEIVES_ENTRIES pre ON pre.PAYMENT_RECEIVE_ID = pr.ID "
            "JOIN SALES_INVOICES si ON pre.INVOICE_ID = si.ID "
            "AND si.INVOICE_DATE = '2026-03-15' "
            "JOIN CONTACTS c ON pr.CUSTOMER_ID = c.ID "
            "AND c.DISPLAY_NAME = 'Juniper 8975064F Systems' "
            "JOIN ACCOUNTS a ON pr.DEPOSIT_ACCOUNT_ID = a.ID "
            "WHERE pr.PAYMENT_DATE = '2026-04-20' "
            "AND ABS(pr.AMOUNT - 59400) < 1 "
            "AND ABS(pre.PAYMENT_AMOUNT - 59400) < 1 "
            "AND a.NAME LIKE '%Petty Cash%' "
            "LIMIT 1;"
        )
        if not row:
            check("12. BigCapital payment received", 2, False,
                  "no 59400 payment dated 2026-04-20 into Petty Cash applied to the 2026-03-15 invoice")
            return
        parts = row.split("\t")
        pay_date = parts[0].strip()
        amount = float(parts[1].strip() or 0) if len(parts) > 1 else 0.0
        account = parts[2].strip() if len(parts) > 2 else ""

        account_ok = "Petty Cash" in account

        ok = account_ok
        check("12. BigCapital payment received", 2, ok,
              f"date={pay_date}, amount={amount}, applied_to=Milestone1, account={account}")
    except Exception as e:
        check("12. BigCapital payment received", 2, False, f"exception: {e}")

--- Original lines 549-577 ---
def check_13_bc_journal() -> None:
    """Published journal dated 2026-04-20: debit Deferred Revenue 59400, credit
    Uncategorized Income 59400 — all conditions scoped to the same journal."""
    try:
        row = bigcapital_sql(
            "SELECT mj.ID "
            "FROM MANUAL_JOURNALS mj "
            "WHERE mj.DATE = '2026-04-20' "
            "AND mj.DESCRIPTION LIKE '%Revenue recognition%Milestone 1%Juniper 8975064F Systems%' "
            "AND mj.PUBLISHED_AT IS NOT NULL "
            "AND EXISTS(SELECT 1 FROM MANUAL_JOURNALS_ENTRIES e "
            "JOIN ACCOUNTS a ON e.ACCOUNT_ID = a.ID "
            "WHERE e.MANUAL_JOURNAL_ID = mj.ID "
            "AND a.NAME LIKE '%Deferred Revenue%Juniper 8975064F Enterprise Engagements%' "
            "AND ABS(e.DEBIT - 59400) < 1) "
            "AND EXISTS(SELECT 1 FROM MANUAL_JOURNALS_ENTRIES e "
            "JOIN ACCOUNTS a ON e.ACCOUNT_ID = a.ID "
            "WHERE e.MANUAL_JOURNAL_ID = mj.ID "
            "AND a.NAME LIKE '%Uncategorized Income%' "
            "AND ABS(e.CREDIT - 59400) < 1) "
            "LIMIT 1;"
        )
        ok = bool(row)
        check("13. BigCapital journal entry", 3, ok,
              f"journal_id={row}" if ok else
              "no single published journal dated 2026-04-20 with matching memo, "
              "debit and credit lines")
    except Exception as e:
        check("13. BigCapital journal entry", 3, False, f"exception: {e}")

--- Original lines 580-594 ---
def check_14_bc_balance() -> None:
    """Customer outstanding balance for Juniper 8975064F Systems = 70900."""
    try:
        row = bigcapital_sql(
            "SELECT IFNULL(SUM(si.BALANCE), 0) "
            "FROM SALES_INVOICES si "
            "JOIN CONTACTS c ON si.CUSTOMER_ID = c.ID "
            "WHERE c.DISPLAY_NAME = 'Juniper 8975064F Systems';"
        )
        balance = float(row.strip() or 0) if row else 0.0
        ok = abs(balance - 70900.0) < 1.0
        check("14. BigCapital customer balance 70900", 3, ok,
              f"balance={balance}, expected=70900")
    except Exception as e:
        check("14. BigCapital customer balance 70900", 3, False, f"exception: {e}")

--- Original lines 599-634 ---
def check_15_pretix_event() -> None:
    """Event 'Juniper 8975064F Systems Milestone Celebration' live, slug, dates, currency."""
    try:
        row = pretix_sql(
            "SELECT e.slug, e.name::text, "
            "(e.date_from AT TIME ZONE COALESCE("
            "(SELECT s.value FROM pretixbase_event_settingsstore s "
            "WHERE s.object_id = e.id AND s.key = 'timezone' LIMIT 1), "
            "'UTC'))::date::text, "
            "e.currency, e.live "
            "FROM pretixbase_event e "
            "JOIN pretixbase_organizer o ON e.organizer_id = o.id "
            "WHERE o.slug = 'culinary-arts' "
            "AND e.slug = 'juniper-8975064f-milestone-celebration' "
            "LIMIT 1;"
        )
        if not row:
            check("15. Pretix event", 2, False, "not found")
            return
        parts = row.split("|")
        slug = parts[0].strip()
        name = parts[1].strip() if len(parts) > 1 else ""
        date_from = parts[2].strip() if len(parts) > 2 else ""
        currency = parts[3].strip() if len(parts) > 3 else ""
        live = parts[4].strip() if len(parts) > 4 else ""

        name_ok = "Juniper 8975064F Systems Milestone Celebration" in name
        date_ok = date_from == "2026-08-08"
        currency_ok = currency == "USD"
        live_ok = live in ("t", "true", "True", "1")

        ok = name_ok and date_ok and currency_ok and live_ok
        check("15. Pretix event", 2, ok,
              f"name_ok={name_ok}, date={date_from}, currency={currency}, live={live}")
    except Exception as e:
        check("15. Pretix event", 2, False, f"exception: {e}")

--- Original lines 637-658 ---
def check_16_pretix_product() -> None:
    """Product 'Juniper 8975064F Celebration Gala Ticket' at price 175."""
    try:
        row = pretix_sql(
            "SELECT i.name::text, i.default_price "
            "FROM pretixbase_item i "
            "JOIN pretixbase_event e ON i.event_id = e.id "
            "WHERE e.slug = 'juniper-8975064f-milestone-celebration' "
            "AND i.name::text LIKE '%Juniper 8975064F Celebration Gala Ticket%' "
            "LIMIT 1;"
        )
        if not row:
            check("16. Pretix product Juniper 8975064F Celebration Gala Ticket", 1, False, "not found")
            return
        parts = row.split("|")
        name = parts[0].strip()
        price = float(parts[1].strip() or 0) if len(parts) > 1 else 0.0
        ok = "Juniper 8975064F Celebration Gala Ticket" in name and abs(price - 175.0) < 0.01
        check("16. Pretix product Juniper 8975064F Celebration Gala Ticket", 1, ok,
              f"price={price}")
    except Exception as e:
        check("16. Pretix product Juniper 8975064F Celebration Gala Ticket", 1, False, f"exception: {e}")

--- Original lines 661-680 ---
def check_17_pretix_quota() -> None:
    """Quota 'Juniper 8975064F Gala Ticket Quota' with size 40, linked to 'Juniper 8975064F Celebration Gala Ticket'."""
    try:
        row = pretix_sql(
            "SELECT count(*) "
            "FROM pretixbase_quota q "
            "JOIN pretixbase_event e ON q.event_id = e.id "
            "AND e.slug = 'juniper-8975064f-milestone-celebration' "
            "JOIN pretixbase_quota_items qi ON qi.quota_id = q.id "
            "JOIN pretixbase_item i ON i.id = qi.item_id "
            "WHERE q.name LIKE '%Juniper 8975064F Gala Ticket Quota%' "
            "AND q.size = 40 "
            "AND i.name::text LIKE '%Juniper 8975064F Celebration Gala Ticket%';"
        )
        count = int(row.strip() or 0) if row else 0
        ok = count >= 1
        check("17. Pretix quota Juniper 8975064F Gala Ticket Quota", 1, ok,
              f"quota(size=40)->item links={count}")
    except Exception as e:
        check("17. Pretix quota Juniper 8975064F Gala Ticket Quota", 1, False, f"exception: {e}")

--- Original lines 683-722 ---
def check_18_pretix_voucher() -> None:
    """Voucher 8975064F100VIP: 100% discount, max 3, linked to 'Celebration Gala
    Ticket', valid until 2026-08-08 (event-timezone calendar date)."""
    try:
        row = pretix_sql(
            "SELECT v.code, v.price_mode, v.value, v.max_usages, "
            "(v.valid_until AT TIME ZONE COALESCE("
            "(SELECT s.value FROM pretixbase_event_settingsstore s "
            "WHERE s.object_id = e.id AND s.key = 'timezone' LIMIT 1), "
            "'UTC'))::date::text "
            "FROM pretixbase_voucher v "
            "JOIN pretixbase_event e ON v.event_id = e.id "
            "AND e.slug = 'juniper-8975064f-milestone-celebration' "
            "JOIN pretixbase_item i ON v.item_id = i.id "
            "AND i.name::text LIKE '%Juniper 8975064F Celebration Gala Ticket%' "
            "WHERE v.code = '8975064F100VIP' "
            "LIMIT 1;"
        )
        if not row:
            check("18. Pretix voucher 8975064F100VIP", 2, False,
                  "not found (or not linked to product Juniper 8975064F Celebration Gala Ticket)")
            return
        parts = row.split("|")
        code = parts[0].strip()
        price_mode = parts[1].strip() if len(parts) > 1 else ""
        value = float(parts[2].strip() or 0) if len(parts) > 2 else 0.0
        max_usages = int(parts[3].strip() or 0) if len(parts) > 3 else 0
        valid_until = parts[4].strip() if len(parts) > 4 else ""

        code_ok = code == "8975064F100VIP"
        discount_ok = price_mode == "percent" and abs(value - 100.0) < 0.01
        max_ok = max_usages == 3
        valid_ok = valid_until == "2026-08-08"

        ok = code_ok and discount_ok and max_ok and valid_ok
        check("18. Pretix voucher 8975064F100VIP", 2, ok,
              f"mode={price_mode}, value={value}, max={max_usages}, "
              f"item_linked=yes, valid_until={valid_until}")
    except Exception as e:
        check("18. Pretix voucher 8975064F100VIP", 2, False, f"exception: {e}")

