import { cleanup, render, screen, within } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { MemoryRouter } from 'react-router-dom'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ROUTER_FUTURE_FLAGS } from '../router/router-future'

const mockGetReleaseManifest = vi.fn()
const mockGetAuthHealth = vi.fn()
const mockGetSuperTokensAuthRuntimeValidation = vi.fn()
const mockIsGitHubOAuthEnabled = vi.fn(() => false)
const mockIsGoogleOAuthEnabled = vi.fn(() => false)
const mockIsOrcidOAuthEnabled = vi.fn(() => false)

vi.mock('../auth/platform-auth', () => ({
  usePlatformAuth: () => ({
    isAuthenticated: false,
  }),
}))

vi.mock('../auth/auth-api', () => ({
  getAuthHealth: (...args: unknown[]) => mockGetAuthHealth(...args),
  getReleaseManifest: (...args: unknown[]) => mockGetReleaseManifest(...args),
}))

vi.mock('../auth/supertokens-runtime', () => ({
  getSuperTokensAuthRuntimeValidation: () => mockGetSuperTokensAuthRuntimeValidation(),
  isGitHubOAuthEnabled: () => mockIsGitHubOAuthEnabled(),
  isGoogleOAuthEnabled: () => mockIsGoogleOAuthEnabled(),
  isOrcidOAuthEnabled: () => mockIsOrcidOAuthEnabled(),
}))

vi.mock('../site-config', () => ({
  brandConfig: {
    brandName: 'HyperTwist',
    legalName: 'HyperTwist',
    domain: 'hypertwist.app',
    tagline: 'Native cube and hypercube training, from first solve to 120-cell.',
    contact: {
      email: 'hello@hypertwist.app',
      emailHref: 'mailto:hello@hypertwist.app',
    },
    payment: {
      provider: 'Paddle',
    },
  },
  downloadTargets: [
    {
      platformKey: 'windows',
      platform: 'Windows',
      subtitle: 'Primary shipping lane',
      configured: true,
      details: 'Current packaged validation is strongest on the Windows Unreal lane.',
    },
    {
      platformKey: 'macos',
      platform: 'macOS',
      subtitle: 'Planned distribution surface',
      configured: false,
      details: 'List a signed desktop build here when the package lane is opened.',
    },
    {
      platformKey: 'linux',
      platform: 'Linux',
      subtitle: 'Operator-targeted later lane',
      configured: false,
      details: 'Use for future package publication after the bounded release lane is widened.',
    },
  ],
  planCatalog: [
    {
      key: 'explorer',
      name: 'Explorer',
      price: 'Free',
      ctaLabel: 'Start in the browser',
      ctaHref: '/register?next=%2Fapp',
      notes: 'Preview the browser account shell, operator dashboard, release notes, and desktop onboarding posture.',
      features: ['Browser account access'],
    },
    {
      key: 'operator',
      name: 'Operator',
      price: 'Launch pricing via Paddle',
      ctaLabel: 'Open protected downloads',
      ctaHref: '/app/downloads?platform=windows',
      notes: 'Desktop-first recognition, replay, training, and higher-dimensional runtime ownership for active training operators.',
      features: ['Desktop download access'],
    },
    {
      key: 'studio',
      name: 'Studio',
      price: 'Contact for launch readiness',
      ctaLabel: 'Open protected rollout lane',
      ctaHref: '/app/browser-access',
      notes: 'Higher-dimensional families, operator deployment support, and packaging/validation coordination for production lanes.',
      features: ['Magic120Cell and 5D operator posture'],
    },
  ],
  paddleReadyDescription:
    'HyperTwist is a desktop-first training environment with Paddle-ready checkout and launch-honest public distribution surfaces.',
  publicDocsUrl: 'https://docs.hypertwist.app',
  releaseNotesUrl: 'https://notes.hypertwist.app',
  mplSourceUrl: '',
  openSourceRepoUrl: '',
  launchReadiness: {
    operatorCheckoutConfigured: false,
    studioCheckoutConfigured: false,
    windowsDownloadConfigured: true,
    macDownloadConfigured: false,
    linuxDownloadConfigured: false,
    mplSourceConfigured: false,
    openSourceRepoConfigured: false,
  },
}))

import {
  AboutPage,
  BrowserExperiencePage,
  ChangelogPage,
  ContactPage,
  DocsPage,
  DownloadPage,
  FeaturesPage,
  GettingStartedPage,
  HelpCenterPage,
  HomeLanding,
  LaunchStatusPage,
  OpenSourceNoticesPage,
  PricingPage,
  PrivacyPage,
  ResourcesPage,
  ShippingPaymentPage,
  SupportPage,
  TermsPage,
} from '../pages/public-pages'

function renderWithProviders(element: React.ReactNode, initialEntries?: string[]) {
  const queryClient = new QueryClient({
    defaultOptions: {
      queries: {
        retry: false,
      },
    },
  })

  return render(
    <QueryClientProvider client={queryClient}>
      <MemoryRouter initialEntries={initialEntries} future={ROUTER_FUTURE_FLAGS}>
        {element}
      </MemoryRouter>
    </QueryClientProvider>,
  )
}

describe('public marketing pages', () => {
  beforeEach(() => {
    cleanup()
    mockGetAuthHealth.mockReset()
    mockGetReleaseManifest.mockReset()
    mockGetSuperTokensAuthRuntimeValidation.mockReset()
    mockIsGitHubOAuthEnabled.mockReset()
    mockIsGoogleOAuthEnabled.mockReset()
    mockIsOrcidOAuthEnabled.mockReset()
    mockGetSuperTokensAuthRuntimeValidation.mockReturnValue({
      ready: true,
      missing: [],
      warnings: [],
    })
    mockIsGitHubOAuthEnabled.mockReturnValue(true)
    mockIsGoogleOAuthEnabled.mockReturnValue(false)
    mockIsOrcidOAuthEnabled.mockReturnValue(true)
  })

  it('routes public download access through the protected dashboard with the requested platform preserved', async () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: false,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: false,
        productPlanMapConfigured: false,
        webhookSecretConfigured: false,
      },
      runtime: {
        mode: 'mixed',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-22T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: 'https://hypertwist.app/open-source/source.zip',
        open_source_repo_url: 'https://github.com/hypertwist/hypertwist',
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [
          {
            platform_key: 'windows',
            platform: 'Windows',
            subtitle: 'Primary shipping lane',
            details: 'Current packaged validation is strongest on the Windows Unreal lane.',
            configured: true,
            channel: 'candidate',
            version: '1.0.0',
            build_id: 'win64-1000',
            published_at: '2026-06-22T00:00:00.000Z',
            file_name: 'HyperTwist-Windows.zip',
            file_size_bytes: 1048576,
            checksum_sha256: 'abc123',
            download_url: null,
            download_available: false,
            validation_summary: {
              lane: 'Windows Unreal packaged validation',
              result: 'passed',
              generated_at: '2026-06-22T01:43:08.7625247Z',
              configuration: 'Development',
              skip_build: true,
              smoke_map_count: 2,
              smoke_maps: [
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_Magic120CellTraining',
                  label: 'Magic120Cell dedicated-family training map',
                  result: 'passed',
                },
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_MagicCube5DTraining',
                  label: 'MagicCube5D dedicated-family training map',
                  result: 'passed',
                },
              ],
            },
          },
        ],
      },
    })

    renderWithProviders(<DownloadPage />)

    expect(screen.getByRole('link', { name: /sign in for windows access/i }).getAttribute('href')).toBe('/app/downloads?platform=windows')
    expect(screen.getAllByText('Account-gated early access').length).toBeGreaterThan(0)
    expect(screen.getByText(/Operator checkout: available through account\/support follow-up/i)).toBeTruthy()
    expect(screen.getByText('Current packaged desktop proof')).toBeTruthy()
    expect(screen.getByText('How the release lane works')).toBeTruthy()
    expect(screen.getByText('What the installed runtime already owns')).toBeTruthy()
    expect(screen.getByText('Higher-dimensional family guide')).toBeTruthy()
    expect(screen.getByText('Current input and runtime control truth')).toBeTruthy()
    expect(screen.getByText('Why HyperTwist gives you both a website and a desktop app')).toBeTruthy()
    expect(screen.getByText('Why the website feels fast and focused')).toBeTruthy()
    expect(screen.getByRole('heading', { name: 'Browser account access methods' })).toBeTruthy()
    expect(screen.getByText('Auth methods ready')).toBeTruthy()
    expect(screen.getByText('Email and password')).toBeTruthy()
    expect(screen.getByText('GitHub sign-in')).toBeTruthy()
    expect(screen.getByText('ORCID sign-in')).toBeTruthy()
    expect(screen.queryByText('Google sign-in')).toBeNull()
    expect(screen.getByText('Choose the right HyperTwist surface')).toBeTruthy()
    const downloadDecisionGuideHeading = screen.getByRole('heading', { name: 'Choose the next best step' })
    const downloadDecisionGuideSection = downloadDecisionGuideHeading.closest('section')
    expect(downloadDecisionGuideSection).toBeTruthy()
    expect(within(downloadDecisionGuideSection as HTMLElement).getByText('Need the desktop download?')).toBeTruthy()
    expect(within(downloadDecisionGuideSection as HTMLElement).getByText('Need legal details, release notes, or source links?')).toBeTruthy()
    expect(screen.getByText('First launch and desktop setup')).toBeTruthy()
    expect(screen.getByText('First-session verification checklist')).toBeTruthy()
    expect(screen.getByText('Verify the higher-dimensional lane you plan to use')).toBeTruthy()
    expect(screen.getAllByText('Offline desktop guide').length).toBeGreaterThan(0)
    expect(screen.getByRole('link', { name: 'Download offline desktop guide' }).getAttribute('href')).toBe('/manual/hypertwist-operator-manual.md')
    expect(screen.getByText('First desktop session after install')).toBeTruthy()
    expect(screen.getByText('2. Pair the installed runtime without password reuse')).toBeTruthy()
    expect(screen.getByText('Digital delivery workflow')).toBeTruthy()
    expect(screen.getByText('Private download handoff')).toBeTruthy()
    expect(screen.getByText('Distribution doctrine')).toBeTruthy()
    expect(screen.getByText('Public pages are distribution surfaces')).toBeTruthy()
    expect(screen.getByText('Release references and source availability')).toBeTruthy()
    expect(screen.getByRole('link', { name: 'https://docs.hypertwist.app' })).toBeTruthy()
    expect(screen.getByRole('link', { name: 'https://notes.hypertwist.app' })).toBeTruthy()
    expect(screen.getByText('Pair desktop access to the browser account')).toBeTruthy()
    expect(screen.getByText('Higher-dimensional runtime ownership')).toBeTruthy()
    expect(screen.getByText('Magic120Cell packaged runtime')).toBeTruthy()
    expect(screen.getByText('Current input and runtime control truth')).toBeTruthy()
    expect(screen.getByText('Native diagnostics check')).toBeTruthy()
    expect(await screen.findByText('Version: 1.0.0')).toBeTruthy()
    expect(screen.getByText('SHA-256: abc123')).toBeTruthy()
    expect(screen.getAllByText('Packaged validation passed').length).toBeGreaterThan(0)
    expect(screen.getAllByText(/Magic120Cell dedicated-family training map: passed/i).length).toBeGreaterThan(0)
    expect(screen.getByText('Generates desktop-link tokens for safe website-to-desktop pairing.')).toBeTruthy()
    expect(screen.getByText('Owns the device integrations the public website does not claim.')).toBeTruthy()
    expect(document.title).toBe('Download HyperTwist desktop | HyperTwist')
    expect(document.head.querySelector('meta[property="og:url"]')?.getAttribute('content')).toBe('https://hypertwist.app/download')
  })

  it('keeps public download recovery guidance explicit when live release authority is unavailable', async () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: false,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: false,
        productPlanMapConfigured: false,
        webhookSecretConfigured: false,
      },
      runtime: {
        mode: 'mixed',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockRejectedValue(new Error('release manifest unavailable'))

    renderWithProviders(<DownloadPage />)

    expect(await screen.findByText(/Release service recovery/i)).toBeTruthy()
    expect(screen.getByText(/direct package delivery stays intentionally withheld until that authority returns/i)).toBeTruthy()
    expect(screen.getByText('What stays intentionally withheld')).toBeTruthy()
    expect(screen.getAllByRole('link', { name: 'Open protected download center' }).some((link) => link.getAttribute('href') === '/app/downloads?platform=windows')).toBe(true)
    expect(screen.getByRole('link', { name: 'Open support' }).getAttribute('href')).toBe('/support?topic=operator-access')
  })

  it('surfaces homepage account-gated access status from live auth and release readiness', async () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: false,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: false,
        productPlanMapConfigured: false,
        webhookSecretConfigured: false,
      },
      runtime: {
        mode: 'mixed',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-22T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: 'https://hypertwist.app/open-source/source.zip',
        open_source_repo_url: 'https://github.com/hypertwist/hypertwist',
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [
          {
            platform_key: 'windows',
            platform: 'Windows',
            subtitle: 'Primary shipping lane',
            details: 'Current packaged validation is strongest on the Windows Unreal lane.',
            configured: true,
            channel: 'candidate',
            version: '1.0.0',
            build_id: 'win64-1000',
            published_at: '2026-06-22T00:00:00.000Z',
            file_name: 'HyperTwist-Windows.zip',
            file_size_bytes: 1048576,
            checksum_sha256: 'abc123',
            download_url: null,
            download_available: false,
            validation_summary: {
              lane: 'Windows Unreal packaged validation',
              result: 'passed',
              generated_at: '2026-06-22T01:43:08.7625247Z',
              configuration: 'Development',
              skip_build: true,
              smoke_map_count: 2,
              smoke_maps: [
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_Magic120CellTraining',
                  label: 'Magic120Cell dedicated-family training map',
                  result: 'passed',
                },
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_MagicCube5DTraining',
                  label: 'MagicCube5D dedicated-family training map',
                  result: 'passed',
                },
              ],
            },
          },
        ],
      },
    })

    renderWithProviders(<HomeLanding />, ['/'])

    expect(screen.getByText('Current access snapshot')).toBeTruthy()
    expect(await screen.findByText('Public website and release access')).toBeTruthy()
    expect(screen.getAllByText('Account-gated early access').length).toBeGreaterThan(0)
    expect(screen.getByText('Why HyperTwist gives you both a website and a desktop app')).toBeTruthy()
    expect(screen.getByText('Common browser-versus-desktop questions')).toBeTruthy()
    expect(screen.getByText('What is the website actually for?')).toBeTruthy()
    expect(screen.getByText('The desktop app stays primary because that is where practice starts to feel rich, responsive, and worth returning to every day.')).toBeTruthy()
    expect(screen.getByText('Why the website exists')).toBeTruthy()
    expect(screen.getByText('Controls and device support today')).toBeTruthy()
    expect(screen.getAllByText('Account-gated early access').length).toBeGreaterThan(0)
    expect(screen.getByText('Subscription access: managed on the website/dashboard and handed to the downloadable through desktop-link pairing.')).toBeTruthy()
    expect(screen.getByRole('heading', { name: 'Browser account access methods' })).toBeTruthy()
    expect(screen.getByText('Auth methods ready')).toBeTruthy()
    expect(screen.getByText('Email and password')).toBeTruthy()
    expect(screen.getByText('GitHub sign-in')).toBeTruthy()
    expect(screen.getByText('ORCID sign-in')).toBeTruthy()
    expect(screen.queryByText('Google sign-in')).toBeNull()
    expect(screen.getByText('Current packaged desktop proof')).toBeTruthy()
    expect(screen.getByText('Packaged validation passed')).toBeTruthy()
    const homeDecisionGuideHeading = screen.getByRole('heading', { name: 'Choose the next best step' })
    const homeDecisionGuideSection = homeDecisionGuideHeading.closest('section')
    expect(homeDecisionGuideSection).toBeTruthy()
    expect(within(homeDecisionGuideSection as HTMLElement).getByText('Need the desktop download?')).toBeTruthy()
    expect(within(homeDecisionGuideSection as HTMLElement).getByText('Need pricing, billing, or subscription help?')).toBeTruthy()
    expect(screen.getByText('Release references and source availability')).toBeTruthy()
    expect(screen.getByRole('link', { name: 'https://docs.hypertwist.app' })).toBeTruthy()
    expect(screen.getByText('How a real first session flows')).toBeTruthy()
    expect(screen.getByText('What the first serious session should look like')).toBeTruthy()
    expect(screen.getByText('1. Resolve access and choose the right build')).toBeTruthy()
    expect(screen.getByText('Which public page should you open next?')).toBeTruthy()
    expect(screen.getAllByText('Offline desktop guide').length).toBeGreaterThan(0)
    expect(screen.getByRole('link', { name: 'Download offline desktop guide' }).getAttribute('href')).toBe('/manual/hypertwist-operator-manual.md')
    expect(screen.getByText('Launch status')).toBeTruthy()
    expect(screen.getByText('Choose the right HyperTwist surface')).toBeTruthy()
    expect(screen.getByText('Open your account dashboard')).toBeTruthy()
    expect(screen.getAllByText('Where each part of HyperTwist lives').length).toBeGreaterThan(0)
    expect(screen.getAllByText('Native Unreal desktop runtime').length).toBeGreaterThan(0)
  })

  it('surfaces about-page workflow and current XR truth without pretending the web replaces the simulator', () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: false,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: true,
        productPlanMapConfigured: true,
        webhookSecretConfigured: true,
      },
      runtime: {
        mode: 'public',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-22T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: 'https://hypertwist.app/open-source/source.zip',
        open_source_repo_url: 'https://github.com/hypertwist/hypertwist',
        commerce: {
          operator_checkout_url: 'https://buy.paddle.com/operator-live',
          studio_checkout_url: 'https://buy.paddle.com/studio-live',
          plan_price_operator: '$19 / month',
          plan_price_studio: '$99 / month',
        },
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [
          {
            platform_key: 'windows',
            platform: 'Windows',
            subtitle: 'Primary shipping lane',
            details: 'Current packaged validation is strongest on the Windows Unreal lane.',
            configured: true,
            channel: 'candidate',
            version: '1.0.0',
            build_id: 'win64-1000',
            published_at: '2026-06-22T00:00:00.000Z',
            file_name: 'HyperTwist-Windows.zip',
            file_size_bytes: 1048576,
            checksum_sha256: 'abc123',
            download_url: null,
            download_available: false,
            validation_summary: {
              lane: 'Windows Unreal packaged validation',
              result: 'passed',
              generated_at: '2026-06-22T01:43:08.7625247Z',
              configuration: 'Development',
              skip_build: true,
              smoke_map_count: 2,
              smoke_maps: [
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_Magic120CellTraining',
                  label: 'Magic120Cell dedicated-family training map',
                  result: 'passed',
                },
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_MagicCube5DTraining',
                  label: 'MagicCube5D dedicated-family training map',
                  result: 'passed',
                },
              ],
            },
          },
        ],
      },
    })

    renderWithProviders(<AboutPage />, ['/about'])

    expect(screen.getByText('How a real HyperTwist session unfolds')).toBeTruthy()
    expect(screen.getByText('Why HyperTwist gives you both a website and a desktop app')).toBeTruthy()
    expect(screen.getAllByText('Common browser-versus-desktop questions').length).toBeGreaterThan(0)
    expect(screen.getByText('Can I use HyperTwist entirely in my browser?')).toBeTruthy()
    expect(screen.getByText(/current shipping product is desktop-first and Unreal-backed/i)).toBeTruthy()
    expect(screen.getByText('Why the desktop app exists')).toBeTruthy()
    expect(screen.getByText('Choose the right HyperTwist surface')).toBeTruthy()
    expect(screen.getByText('Stay on the website')).toBeTruthy()
    const aboutDecisionGuideHeading = screen.getByRole('heading', { name: 'Choose the next best step' })
    const aboutDecisionGuideSection = aboutDecisionGuideHeading.closest('section')
    expect(aboutDecisionGuideSection).toBeTruthy()
    expect(within(aboutDecisionGuideSection as HTMLElement).getByText('Need account access, pairing, or dashboard help?')).toBeTruthy()
    expect(within(aboutDecisionGuideSection as HTMLElement).getByText('Need pricing, billing, or subscription help?')).toBeTruthy()
    expect(screen.getByText('Current desktop control and headset truth')).toBeTruthy()
    expect(screen.getByText('Selectable control and settings roster')).toBeTruthy()
    expect(screen.getByText('Shipped classic control profile')).toBeTruthy()
    expect(screen.getByText('Generates desktop-link tokens for safe website-to-desktop pairing.')).toBeTruthy()
    expect(screen.getByText('Future browser-only simulator')).toBeTruthy()
    expect(screen.getByText('Release and deployment maturity')).toBeTruthy()
    expect(screen.getByText('Current public access state')).toBeTruthy()
    expect(screen.getByText('About-page launch and release access')).toBeTruthy()
    expect(screen.getByText('Current packaged desktop proof')).toBeTruthy()
    expect(screen.getByText('Packaged validation passed')).toBeTruthy()
    expect(screen.getByText('Release references and source availability')).toBeTruthy()
    expect(screen.getByRole('link', { name: 'https://notes.hypertwist.app' })).toBeTruthy()
  })

  it('renders the public feature atlas with capability tiers and route-aware metadata', async () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: false,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: true,
        productPlanMapConfigured: true,
        webhookSecretConfigured: true,
      },
      runtime: {
        mode: 'public',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-22T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: 'https://hypertwist.app/open-source/source.zip',
        open_source_repo_url: 'https://github.com/hypertwist/hypertwist',
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [
          {
            platform_key: 'windows',
            platform: 'Windows',
            subtitle: 'Primary shipping lane',
            details: 'Current packaged validation is strongest on the Windows Unreal lane.',
            configured: true,
            channel: 'candidate',
            version: '1.0.0',
            build_id: 'win64-1000',
            published_at: '2026-06-22T00:00:00.000Z',
            file_name: 'HyperTwist-Windows.zip',
            file_size_bytes: 1048576,
            checksum_sha256: 'abc123',
            download_url: null,
            download_available: false,
            validation_summary: {
              lane: 'Windows Unreal packaged validation',
              result: 'passed',
              generated_at: '2026-06-22T01:43:08.7625247Z',
              configuration: 'Development',
              skip_build: true,
              smoke_map_count: 2,
              smoke_maps: [
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_Magic120CellTraining',
                  label: 'Magic120Cell dedicated-family training map',
                  result: 'passed',
                },
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_MagicCube5DTraining',
                  label: 'MagicCube5D dedicated-family training map',
                  result: 'passed',
                },
              ],
            },
          },
        ],
      },
    })

    renderWithProviders(<FeaturesPage />, ['/features'])

    expect(screen.getByText('A deep training toolkit, not just a timer.')).toBeTruthy()
    expect(screen.getByText('How to read this feature map')).toBeTruthy()
    expect(screen.getByText('Available today')).toBeTruthy()
    expect(screen.getByText('Choose the right HyperTwist surface')).toBeTruthy()
    expect(screen.getByText('Why HyperTwist gives you both a website and a desktop app')).toBeTruthy()
    expect(screen.getByText('Controls and device support today')).toBeTruthy()
    expect(screen.getAllByText('Where everything happens').length).toBeGreaterThan(0)
    expect(screen.getAllByText('Embedded simulator web tools').length).toBeGreaterThan(0)
    expect(screen.getAllByText('What you can use today').length).toBeGreaterThan(0)
    expect(screen.getByText('Current selectable control roster')).toBeTruthy()
    expect(screen.getAllByText('Selectable immersive and family-specific settings').length).toBeGreaterThan(0)
    expect(screen.getAllByText('XR reopen requirements').length).toBeGreaterThan(0)
    expect(screen.getByText('The remaining reopen requirement is Windows packaged controller validation with controller truth on the shipping lane rather than only editor-time or config-only confidence.')).toBeTruthy()
    expect(screen.getByText('Controls guide')).toBeTruthy()
    expect(screen.getByText('Native diagnostics check')).toBeTruthy()
    expect(screen.getByText('Common capability questions')).toBeTruthy()
    expect(screen.getByText('What is the website actually for?')).toBeTruthy()
    expect(screen.getByText('Is VR support already complete?')).toBeTruthy()
    expect(screen.getByText('Current availability')).toBeTruthy()
    expect(screen.getByText('Public feature and access status')).toBeTruthy()
    const featuresDecisionGuideHeading = screen.getByRole('heading', { name: 'Choose the next best step' })
    const featuresDecisionGuideSection = featuresDecisionGuideHeading.closest('section')
    expect(featuresDecisionGuideSection).toBeTruthy()
    expect(within(featuresDecisionGuideSection as HTMLElement).getByText('Need the desktop download?')).toBeTruthy()
    expect(within(featuresDecisionGuideSection as HTMLElement).getByText('Need pricing, billing, or subscription help?')).toBeTruthy()
    expect(screen.getByText('Current packaged desktop proof')).toBeTruthy()
    expect(screen.getByText('Packaged validation passed')).toBeTruthy()
    expect(screen.getByText('Release references and source availability')).toBeTruthy()
    expect(screen.getByRole('link', { name: 'https://docs.hypertwist.app' })).toBeTruthy()
    expect(document.title).toBe('HyperTwist features | HyperTwist')
    expect(document.head.querySelector('meta[property="og:url"]')?.getAttribute('content')).toBe('https://hypertwist.app/features')
  })

  it('uses exact protected fallback routes for plans that do not yet have live checkouts', () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: false,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: false,
        productPlanMapConfigured: false,
        webhookSecretConfigured: false,
      },
      runtime: {
        mode: 'mixed',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-22T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: 'https://hypertwist.app/open-source/source.zip',
        open_source_repo_url: 'https://github.com/hypertwist/hypertwist',
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [],
      },
    })
    renderWithProviders(<PricingPage />)

    expect(screen.getByRole('link', { name: /open protected downloads/i }).getAttribute('href')).toBe('/app/downloads?platform=windows')
    expect(screen.getByRole('link', { name: /open protected rollout lane/i }).getAttribute('href')).toBe('/app/browser-access')
  })

  it('prefers runtime checkout URLs and live plan prices on the pricing page when the manifest provides them', async () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: false,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: false,
        productPlanMapConfigured: false,
        webhookSecretConfigured: false,
      },
      runtime: {
        mode: 'mixed',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-22T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: 'https://hypertwist.app/open-source/source.zip',
        open_source_repo_url: 'https://github.com/hypertwist/hypertwist',
        commerce: {
          operator_checkout_url: 'https://buy.paddle.com/operator-live',
          studio_checkout_url: 'https://buy.paddle.com/studio-live',
          plan_price_operator: '$19 / month',
          plan_price_studio: '$99 / month',
        },
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [
          {
            platform_key: 'windows',
            platform: 'Windows',
            subtitle: 'Primary shipping lane',
            details: 'Current packaged validation is strongest on the Windows Unreal lane.',
            configured: true,
            channel: 'candidate',
            version: '1.0.0',
            build_id: 'win64-1000',
            published_at: '2026-06-22T00:00:00.000Z',
            file_name: 'HyperTwist-Windows.zip',
            file_size_bytes: 1048576,
            checksum_sha256: 'abc123',
            download_url: null,
            download_available: false,
            validation_summary: {
              lane: 'Windows Unreal packaged validation',
              result: 'passed',
              generated_at: '2026-06-22T01:43:08.7625247Z',
              configuration: 'Development',
              skip_build: true,
              smoke_map_count: 2,
              smoke_maps: [
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_Magic120CellTraining',
                  label: 'Magic120Cell dedicated-family training map',
                  result: 'passed',
                },
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_MagicCube5DTraining',
                  label: 'MagicCube5D dedicated-family training map',
                  result: 'passed',
                },
              ],
            },
          },
        ],
      },
    })

    renderWithProviders(<PricingPage />, ['/pricing'])

    expect(await screen.findByText('$19 / month')).toBeTruthy()
    expect(screen.getByText('$99 / month')).toBeTruthy()
    expect(screen.getByText('Current packaged desktop proof')).toBeTruthy()
    expect(screen.getAllByText('What happens after access is granted').length).toBeGreaterThan(0)
    expect(screen.getByText('What the software actually does after access is granted')).toBeTruthy()
    expect(screen.getByText('Higher-dimensional families behind the plans')).toBeTruthy()
    expect(screen.getAllByText('Current input and runtime control truth').length).toBeGreaterThan(0)
    expect(screen.getByText('The current host decision remains desktop-first for broader native OpenXR/controller rollout until Windows packaged controller validation with controller truth is complete.')).toBeTruthy()
    expect(screen.getByText('Choose the right HyperTwist surface')).toBeTruthy()
    const pricingDecisionGuideHeading = screen.getByRole('heading', { name: 'Choose the next best step' })
    const pricingDecisionGuideSection = pricingDecisionGuideHeading.closest('section')
    expect(pricingDecisionGuideSection).toBeTruthy()
    expect(within(pricingDecisionGuideSection as HTMLElement).getByText('Need pricing, billing, or subscription help?')).toBeTruthy()
    expect(within(pricingDecisionGuideSection as HTMLElement).getByText('Need account access, pairing, or dashboard help?')).toBeTruthy()
    expect(screen.getByText('Why HyperTwist gives you both a website and a desktop app')).toBeTruthy()
    expect(screen.getByText('The desktop app stays primary because that is where practice starts to feel rich, responsive, and worth returning to every day.')).toBeTruthy()
    expect(screen.getByText('Controls and device support today')).toBeTruthy()
    expect(screen.getByRole('heading', { name: 'Browser account access methods' })).toBeTruthy()
    expect(screen.getByText('Auth methods ready')).toBeTruthy()
    expect(screen.getByText('Email and password')).toBeTruthy()
    expect(screen.getByText('GitHub sign-in')).toBeTruthy()
    expect(screen.getByText('ORCID sign-in')).toBeTruthy()
    expect(screen.queryByText('Google sign-in')).toBeNull()
    expect(screen.getByText('Shows account, auth, billing, and release status.')).toBeTruthy()
    expect(screen.getByText('Owns recognition, replay, coaching, and packaged training behavior.')).toBeTruthy()
    expect(screen.getByText('Commercial distribution doctrine')).toBeTruthy()
    expect(screen.getByText('Public pages are distribution surfaces')).toBeTruthy()
    expect(screen.getByText('Higher-dimensional runtime ownership')).toBeTruthy()
    expect(screen.getByText('MagicTile embedded-browser runtime')).toBeTruthy()
    expect(screen.getByText('XR groundwork exists, but the full VR lane is not finished')).toBeTruthy()
    expect(screen.getByText('Native diagnostics check')).toBeTruthy()
    expect(screen.getByText('Release references and source availability')).toBeTruthy()
    expect(screen.getByRole('link', { name: 'https://docs.hypertwist.app' })).toBeTruthy()
    expect(screen.getByRole('link', { name: 'https://notes.hypertwist.app' })).toBeTruthy()
    expect(screen.getByText('Terms of access in practice')).toBeTruthy()
    expect(screen.getByText('Access model')).toBeTruthy()
    const checkoutLinks = screen.getAllByRole('link', { name: /open paddle checkout/i })
    expect(checkoutLinks).toHaveLength(2)
    expect(checkoutLinks[0].getAttribute('href')).toBe('https://buy.paddle.com/operator-live')
    expect(checkoutLinks[1].getAttribute('href')).toBe('https://buy.paddle.com/studio-live')
  })

  it('surfaces the preselected support lane when marketing routes send the operator here intentionally', () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: false,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: false,
        productPlanMapConfigured: false,
        webhookSecretConfigured: false,
      },
      runtime: {
        mode: 'mixed',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-22T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: 'https://hypertwist.app/open-source/source.zip',
        open_source_repo_url: 'https://github.com/hypertwist/hypertwist',
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [],
      },
    })
    renderWithProviders(<SupportPage />, ['/support?topic=launch-readiness'])

    expect(screen.getAllByText('Selected help topic').length).toBeGreaterThan(0)
    expect(screen.getAllByText('Launch readiness').length).toBeGreaterThan(0)
    expect(screen.getAllByText(/current website, pricing, download, and legal status before a wider public launch/i).length).toBeGreaterThan(0)
    expect(screen.getByText('Selected topic next steps')).toBeTruthy()
    const selectedLaneHeading = screen.getByRole('heading', { name: 'Selected topic next steps' })
    const selectedLaneSection = selectedLaneHeading.closest('section')
    expect(selectedLaneSection).toBeTruthy()
    expect(within(selectedLaneSection as HTMLElement).getByText('Confirm public launch status, checkout readiness, and support contact first.')).toBeTruthy()
    expect(within(selectedLaneSection as HTMLElement).getByRole('link', { name: 'Sign in for desktop downloads' }).getAttribute('href')).toBe('/login?next=%2Fapp%2Fdownloads%3Fplatform%3Dwindows')
    expect(within(selectedLaneSection as HTMLElement).getByRole('link', { name: 'Sign in for notices' }).getAttribute('href')).toBe('/login?next=%2Fapp%2Fnotices')
    expect(within(selectedLaneSection as HTMLElement).getByRole('link', { name: 'Open pricing' }).getAttribute('href')).toBe('/pricing')
    expect(screen.getByText('What is the website actually for?')).toBeTruthy()
    expect(screen.getByText('Is VR support already complete?')).toBeTruthy()
    expect(screen.getByText('Do higher-dimensional selector choices persist between sessions?')).toBeTruthy()
    expect(screen.getByText('Choose the right HyperTwist surface')).toBeTruthy()
    expect(screen.getByText('Why HyperTwist gives you both a website and a desktop app')).toBeTruthy()
    expect(screen.getByText('Why the website feels fast and focused')).toBeTruthy()
    expect(screen.getByText('Browser and desktop responsibilities')).toBeTruthy()
    expect(screen.getByRole('heading', { name: 'Current browser sign-in methods' })).toBeTruthy()
    expect(screen.getByText('Auth methods ready')).toBeTruthy()
    expect(screen.getByText('Email and password')).toBeTruthy()
    expect(screen.getByText('GitHub sign-in')).toBeTruthy()
    expect(screen.getByText('ORCID sign-in')).toBeTruthy()
    expect(screen.queryByText('Google sign-in')).toBeNull()
    expect(screen.getByText('Shows account, auth, billing, and release status.')).toBeTruthy()
    expect(screen.getByText('Support lanes')).toBeTruthy()
    expect(screen.getByText('Issue reporting checklist')).toBeTruthy()
    expect(screen.getByText('Account, pairing, or entitlement issue report')).toBeTruthy()
    expect(screen.getByText('Support topic quick routes')).toBeTruthy()
    expect(screen.getAllByText('Manual and route focus').length).toBeGreaterThan(0)
    expect(screen.getByText('Recovery and degraded-state guidance')).toBeTruthy()
    expect(screen.getByText('Desktop-first continuity during recovery')).toBeTruthy()
    expect(screen.getByText('Current release and package state')).toBeTruthy()
    expect(screen.getByText('Current support-facing launch access')).toBeTruthy()
    expect(screen.getByText('Current packaged desktop proof')).toBeTruthy()
    expect(screen.getByText('Packaged validation passed')).toBeTruthy()
    const decisionGuideHeading = screen.getByRole('heading', { name: 'Choose the next best step' })
    const decisionGuideSection = decisionGuideHeading.closest('section')
    expect(decisionGuideSection).toBeTruthy()
    expect(within(decisionGuideSection as HTMLElement).getByText('Need the desktop download?')).toBeTruthy()
    expect(within(decisionGuideSection as HTMLElement).getByText('Need pricing, billing, or subscription help?')).toBeTruthy()
    expect(within(decisionGuideSection as HTMLElement).getByText('Need account access, pairing, or dashboard help?')).toBeTruthy()
    expect(within(decisionGuideSection as HTMLElement).getByText('Need legal details, release notes, or source links?')).toBeTruthy()
    expect(within(decisionGuideSection as HTMLElement).getByRole('link', { name: 'Sign in for browser access' }).getAttribute('href')).toBe('/login?next=%2Fapp%2Fbrowser-access')
    expect(within(decisionGuideSection as HTMLElement).getByRole('link', { name: 'Review public notices' }).getAttribute('href')).toBe('/open-source-notices')
    expect(screen.getByText('Release references and source availability')).toBeTruthy()
    expect(screen.getByRole('link', { name: 'https://docs.hypertwist.app' })).toBeTruthy()
    expect(screen.getByText('Digital delivery workflow')).toBeTruthy()
    expect(screen.getByText('After-install rhythm')).toBeTruthy()
    expect(screen.getByText('Privacy and compliance boundary')).toBeTruthy()
    expect(screen.getByText('Browser identity and billing boundary')).toBeTruthy()
    expect(screen.getByText('Escalation map')).toBeTruthy()
    expect(screen.getByText('Runtime and training issues')).toBeTruthy()
  })

  it('renders the new browser, help, and contact guidance routes with the expected public-manual boundary language', () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: false,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: false,
        productPlanMapConfigured: false,
        webhookSecretConfigured: false,
      },
      runtime: {
        mode: 'mixed',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-22T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: 'https://hypertwist.app/open-source/source.zip',
        open_source_repo_url: 'https://github.com/hypertwist/hypertwist',
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [],
      },
    })

    const browserView = renderWithProviders(<BrowserExperiencePage />, ['/browser'])
    expect(within(browserView.container).getByText('What the website is genuinely great at')).toBeTruthy()
    expect(within(browserView.container).getByText('Why the desktop app goes much further')).toBeTruthy()
    expect(within(browserView.container).getByText('How the browser and downloadable work together')).toBeTruthy()
    expect(within(browserView.container).getByText('The website gets you in. The desktop app becomes the training room.')).toBeTruthy()

    const helpView = renderWithProviders(<HelpCenterPage />, ['/help'])
    expect(within(helpView.container).getByText('What this help center covers')).toBeTruthy()
    expect(within(helpView.container).getByText('Pick the right help path')).toBeTruthy()
    expect(within(helpView.container).getByText('Current controls and device state')).toBeTruthy()
    expect(within(helpView.container).getByText('Need escalation instead of guidance?')).toBeTruthy()

    const contactView = renderWithProviders(<ContactPage />, ['/contact'])
    expect(within(contactView.container).getByText('Contact paths')).toBeTruthy()
    expect(within(contactView.container).getByText('Primary contact route')).toBeTruthy()
    expect(within(contactView.container).getByText('What to include in your message')).toBeTruthy()
    expect(within(contactView.container).getByText('How HyperTwist classifies escalations')).toBeTruthy()
  })

  it('surfaces current packaged desktop proof on the public resources page', () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: false,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: false,
        productPlanMapConfigured: false,
        webhookSecretConfigured: false,
      },
      runtime: {
        mode: 'mixed',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-22T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: 'https://hypertwist.app/open-source/source.zip',
        open_source_repo_url: 'https://github.com/hypertwist/hypertwist',
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [
          {
            platform_key: 'windows',
            platform: 'Windows',
            subtitle: 'Primary shipping lane',
            details: 'Current packaged validation is strongest on the Windows Unreal lane.',
            configured: true,
            channel: 'candidate',
            version: '1.0.0',
            build_id: 'win64-1000',
            published_at: '2026-06-22T00:00:00.000Z',
            file_name: 'HyperTwist-Windows.zip',
            file_size_bytes: 1048576,
            checksum_sha256: 'abc123',
            download_url: null,
            download_available: false,
            validation_summary: {
              lane: 'Windows Unreal packaged validation',
              result: 'passed',
              generated_at: '2026-06-22T01:43:08.7625247Z',
              configuration: 'Development',
              skip_build: true,
              smoke_map_count: 2,
              smoke_maps: [
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_Magic120CellTraining',
                  label: 'Magic120Cell dedicated-family training map',
                  result: 'passed',
                },
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_MagicCube5DTraining',
                  label: 'MagicCube5D dedicated-family training map',
                  result: 'passed',
                },
              ],
            },
          },
        ],
      },
    })
    renderWithProviders(<ResourcesPage />, ['/resources'])

    const packagedProofHeading = screen.getByRole('heading', { name: 'Current packaged desktop proof' })
    const packagedProofSection = packagedProofHeading.closest('section')

    expect(packagedProofSection).toBeTruthy()
    expect(within(packagedProofSection as HTMLElement).getByText('Packaged validation passed')).toBeTruthy()
    expect(within(packagedProofSection as HTMLElement).getByText(/The Windows lane has current first-party package proof/i)).toBeTruthy()
    expect(within(packagedProofSection as HTMLElement).getByText(/MagicCube5D dedicated-family training map: passed/i)).toBeTruthy()
    expect(
      within(packagedProofSection as HTMLElement).getByText(
        /Package helper build mode: (reused the existing packaged-game target receipt|ran a full package build)/i
      )
    ).toBeTruthy()
    expect(screen.getAllByText('Support topic quick routes').length).toBeGreaterThan(0)
    expect(screen.getByText('Choose the right HyperTwist surface')).toBeTruthy()
    expect(screen.getByText('Why HyperTwist gives you both a website and a desktop app')).toBeTruthy()
    expect(screen.getByText('Why the website feels fast and focused')).toBeTruthy()
    expect(screen.getByText('Recovery and escalation')).toBeTruthy()
    expect(screen.getByText('Training and team playbooks')).toBeTruthy()
    expect(screen.getByText('Simulator use today')).toBeTruthy()
    expect(screen.getByText('Higher-dimensional runtime guide')).toBeTruthy()
    expect(screen.getByText('Current control and device state')).toBeTruthy()
    expect(screen.getAllByText('Selectable control and settings roster').length).toBeGreaterThan(0)
    expect(screen.getByText(/3 immersive-intensity presets and 3 reduced-distraction presets/i)).toBeTruthy()
    expect(screen.getByText('Release snapshot')).toBeTruthy()
    expect(screen.getAllByText('XR groundwork exists, but the full VR lane is not finished').length).toBeGreaterThan(0)
    expect(screen.getByText('Higher-dimensional runtime ownership')).toBeTruthy()
    expect(screen.getByText('Public manual route atlas')).toBeTruthy()
    expect(screen.getByText('Shipping & payment')).toBeTruthy()
    expect(screen.getAllByText('Offline desktop guide').length).toBeGreaterThan(0)
    expect(screen.getByRole('link', { name: 'Download offline desktop guide' }).getAttribute('href')).toBe('/manual/hypertwist-operator-manual.md')
    expect(screen.getByText('Choose the next best step')).toBeTruthy()
    expect(screen.getByText('Need account access, pairing, or dashboard help?')).toBeTruthy()
    expect(screen.getByText('Open your account dashboard')).toBeTruthy()
    expect(screen.getByRole('link', { name: 'Sign in for dashboard' }).getAttribute('href')).toBe('/login?next=%2Fapp')
    expect(screen.getByText('Release references and source availability')).toBeTruthy()
    expect(screen.getByRole('link', { name: 'https://docs.hypertwist.app' })).toBeTruthy()
  })

  it('shows the current browser account method lineup on the public docs page', async () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: true,
          google: false,
          orcid: true,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: false,
        productPlanMapConfigured: false,
        webhookSecretConfigured: false,
      },
      runtime: {
        mode: 'mixed',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-22T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: 'https://hypertwist.app/open-source/source.zip',
        open_source_repo_url: 'https://github.com/hypertwist/hypertwist',
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [],
      },
    })

    renderWithProviders(<DocsPage />)

    expect(screen.getByRole('heading', { name: 'Browser account access methods' })).toBeTruthy()
    expect(screen.getByText('Auth methods ready')).toBeTruthy()
    expect(screen.getByText('Email and password')).toBeTruthy()
    expect(screen.getByText('GitHub sign-in')).toBeTruthy()
    expect(screen.getByText('ORCID sign-in')).toBeTruthy()
    expect(screen.queryByText('Google sign-in')).toBeNull()
  })

  it('renders the public operator manual on the docs page', async () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: false,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: false,
        productPlanMapConfigured: false,
        webhookSecretConfigured: false,
      },
      runtime: {
        mode: 'mixed',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-22T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: 'https://hypertwist.app/open-source/source.zip',
        open_source_repo_url: 'https://github.com/hypertwist/hypertwist',
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [],
      },
    })

    renderWithProviders(<DocsPage />, ['/docs'])

    expect(screen.getByText('Current shipped capability')).toBeTruthy()
    expect(screen.getByText('Native training and coaching core')).toBeTruthy()
    expect(screen.getByText('How HyperTwist is actually used')).toBeTruthy()
    expect(screen.getByText('First real desktop session')).toBeTruthy()
    expect(screen.getByText('Operational verification checklist')).toBeTruthy()
    expect(screen.getByText('Recovery and degraded-state manual')).toBeTruthy()
    expect(screen.getByText('Issue reporting checklist')).toBeTruthy()
    expect(screen.getAllByText('Offline desktop guide').length).toBeGreaterThan(0)
    expect(screen.getByRole('link', { name: 'Download offline desktop guide' }).getAttribute('href')).toBe('/manual/hypertwist-operator-manual.md')
    expect(screen.getByText('Support topic quick routes')).toBeTruthy()
    expect(screen.getAllByText('Where each part of HyperTwist lives').length).toBeGreaterThan(0)
    expect(screen.getByText('Why HyperTwist gives you both a website and a desktop app')).toBeTruthy()
    expect(screen.getByText('Why the website feels fast and focused')).toBeTruthy()
    expect(screen.getByText('When to use browser versus desktop')).toBeTruthy()
    expect(screen.getByText('Choose the right HyperTwist surface')).toBeTruthy()
    expect(screen.getAllByText('Signed-in dashboard').length).toBeGreaterThan(0)
    expect(screen.getAllByText('1. Start on the website').length).toBeGreaterThan(0)
    expect(screen.getAllByText('Optional full-browser simulator branch').length).toBeGreaterThan(0)
    expect(screen.getByText('Simulator manual')).toBeTruthy()
    expect(screen.getByText('Higher-dimensional family guide')).toBeTruthy()
    expect(screen.getByText('Deployment readiness manual')).toBeTruthy()
    expect(screen.getByText('Input and device state')).toBeTruthy()
    expect(screen.getAllByText('Selectable control and settings roster').length).toBeGreaterThan(0)
    expect(screen.getAllByText('Keyboard and mouse ship today').length).toBeGreaterThan(0)
    expect(screen.getAllByText(/classic-wca-keyboard\/v1/i).length).toBeGreaterThan(0)
    expect(screen.getByText('4. Open the higher-dimensional families and read the control boundary honestly')).toBeTruthy()
    expect(screen.getByText(/I\/K = R\/R', J\/F = U\/U', H\/G = F\/F'/i)).toBeTruthy()
    expect(screen.getByText(/bounded OpenXR plugin stack, first-party runtime-owner substrate, and first-party controller settings\/rebinding ownership/i)).toBeTruthy()
    expect(screen.getByText(/R scramble, H hint, Enter submit, F mode, V hold-to-talk, C cycle voice/i)).toBeTruthy()
    expect(screen.getAllByText(/latest persisted generated-mode selector state is available for recall/i).length).toBeGreaterThan(0)
    expect(screen.getByText('Feature-registry-backed wording only')).toBeTruthy()
    expect(screen.getByText('Documentation and route atlas')).toBeTruthy()
    expect(screen.getByText('Open-source notices')).toBeTruthy()
    expect(screen.getByText('Browser auth degraded or mixed')).toBeTruthy()
    expect(screen.getByText('Release authority temporarily unavailable')).toBeTruthy()
    expect(screen.getByText('Current packaged desktop proof')).toBeTruthy()
    expect(screen.getByText('Choose the next best step')).toBeTruthy()
    expect(screen.getByText('Need the desktop download?')).toBeTruthy()
    expect(screen.getByText('Need legal details, release notes, or source links?')).toBeTruthy()
    expect(screen.getByRole('link', { name: 'Review public notices' }).getAttribute('href')).toBe('/open-source-notices')
    expect(screen.getByText('Common questions')).toBeTruthy()
    expect(screen.getByText('What is the website actually for?')).toBeTruthy()
    expect(screen.getByText('It does not pretend to be the full simulator, the advanced puzzle room, or the device-heavy practice surface.')).toBeTruthy()
    expect(screen.getByText('Packaged validation passed')).toBeTruthy()
    expect(screen.getByText('Release references and source availability')).toBeTruthy()
    expect(screen.getByRole('link', { name: 'https://docs.hypertwist.app' })).toBeTruthy()
    expect(await screen.findByRole('link', { name: /open public docs portal/i })).toBeTruthy()
  })

  it('renders the dedicated getting-started page as a canonical onboarding route', async () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: false,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: false,
        productPlanMapConfigured: false,
        webhookSecretConfigured: false,
      },
      runtime: {
        mode: 'mixed',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-22T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: 'https://hypertwist.app/open-source/source.zip',
        open_source_repo_url: 'https://github.com/hypertwist/hypertwist',
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [
          {
            platform_key: 'windows',
            platform: 'Windows',
            subtitle: 'Primary shipping lane',
            details: 'Current packaged validation is strongest on the Windows Unreal lane.',
            configured: true,
            channel: 'candidate',
            version: '1.0.0',
            build_id: 'win64-1000',
            published_at: '2026-06-22T00:00:00.000Z',
            file_name: 'HyperTwist-Windows.zip',
            file_size_bytes: 1048576,
            checksum_sha256: 'abc123',
            download_url: null,
            download_available: false,
            validation_summary: {
              lane: 'Windows Unreal packaged validation',
              result: 'passed',
              generated_at: '2026-06-22T01:43:08.7625247Z',
              configuration: 'Development',
              skip_build: true,
              smoke_map_count: 2,
              smoke_maps: [
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_Magic120CellTraining',
                  label: 'Magic120Cell dedicated-family training map',
                  result: 'passed',
                },
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_MagicCube5DTraining',
                  label: 'MagicCube5D dedicated-family training map',
                  result: 'passed',
                },
              ],
            },
          },
        ],
      },
    })

    renderWithProviders(<GettingStartedPage />, ['/getting-started'])

    expect(screen.getByText('The first serious HyperTwist session')).toBeTruthy()
    expect(screen.getByText('Operator path')).toBeTruthy()
    expect(screen.getAllByText('Offline desktop guide').length).toBeGreaterThan(0)
    expect(screen.getByRole('link', { name: 'Download offline desktop guide' }).getAttribute('href')).toBe('/manual/hypertwist-operator-manual.md')
    expect(screen.getByText('Browser account access methods')).toBeTruthy()
    expect(screen.getByText('First launch and desktop setup')).toBeTruthy()
    expect(screen.getByText('First-session verification checklist')).toBeTruthy()
    expect(screen.getByText('Simulator use today')).toBeTruthy()
    expect(screen.getByText('Higher-dimensional family guide')).toBeTruthy()
    expect(screen.getByText('Current control and device truth')).toBeTruthy()
    expect(screen.getAllByText('Selectable control and settings roster').length).toBeGreaterThan(0)
    expect(screen.getByText('Runtime control guide')).toBeTruthy()
    expect(screen.getByText('Native diagnostics check')).toBeTruthy()
    expect(screen.getByText('Choose the right HyperTwist surface')).toBeTruthy()
    expect(screen.getByText('Current packaged desktop proof')).toBeTruthy()
    expect(screen.getByText('Need help on the way in?')).toBeTruthy()
    expect(
      screen
        .getAllByRole('link', { name: 'Open download center' })
        .some((link) => link.getAttribute('href') === '/download'),
    ).toBe(true)
    expect(screen.getAllByText(/classic-wca-keyboard\/v1/i).length).toBeGreaterThan(0)
    expect(document.title).toBe('Getting started with HyperTwist | HyperTwist')
    expect(document.head.querySelector('meta[property="og:url"]')?.getAttribute('content')).toBe('https://hypertwist.app/getting-started')
  })

  it('renders the dedicated launch-status page as the canonical public release-readiness route', async () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: true,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: false,
        productPlanMapConfigured: false,
        webhookSecretConfigured: false,
      },
      runtime: {
        mode: 'mixed',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-22T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: 'https://hypertwist.app/open-source/source.zip',
        open_source_repo_url: 'https://github.com/hypertwist/hypertwist',
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [
          {
            platform_key: 'windows',
            platform: 'Windows',
            subtitle: 'Primary shipping lane',
            details: 'Current packaged validation is strongest on the Windows Unreal lane.',
            configured: true,
            channel: 'candidate',
            version: '1.0.0',
            build_id: 'win64-1000',
            published_at: '2026-06-22T00:00:00.000Z',
            file_name: 'HyperTwist-Windows.zip',
            file_size_bytes: 1048576,
            checksum_sha256: 'abc123',
            download_url: null,
            download_available: false,
            validation_summary: {
              lane: 'Windows Unreal packaged validation',
              result: 'passed',
              generated_at: '2026-06-22T01:43:08.7625247Z',
              configuration: 'Development',
              skip_build: true,
              smoke_map_count: 2,
              smoke_maps: [
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_Magic120CellTraining',
                  label: 'Magic120Cell dedicated-family training map',
                  result: 'passed',
                },
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_MagicCube5DTraining',
                  label: 'MagicCube5D dedicated-family training map',
                  result: 'passed',
                },
              ],
            },
          },
        ],
      },
    })

    renderWithProviders(<LaunchStatusPage />, ['/launch-status'])

    expect(screen.getByText('Current account and release access')).toBeTruthy()
    expect(screen.getByText('What must be true before wider public launch')).toBeTruthy()
    expect(screen.getByText('Launch hardening tracks')).toBeTruthy()
    expect(screen.getByText('Access support and escalation lanes')).toBeTruthy()
    expect(screen.getByText('Choose the next access move')).toBeTruthy()
    expect(screen.getByText('Release, notice, and support bundle')).toBeTruthy()
    expect(screen.getByText('Why access status lives on the website')).toBeTruthy()
    expect(screen.getAllByText('Launch readiness').length).toBeGreaterThan(0)
    expect(
      screen.getAllByRole('link', { name: 'Open launch status' }).some((link) => link.getAttribute('href') === '/launch-status'),
    ).toBe(true)
    expect(document.title).toBe('HyperTwist access status | HyperTwist')
    expect(document.head.querySelector('meta[property="og:url"]')?.getAttribute('content')).toBe('https://hypertwist.app/launch-status')
  })

  it('renders the release-notes page with the latest native selector-recall packet and rollout checklist', async () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: false,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: false,
        productPlanMapConfigured: false,
        webhookSecretConfigured: false,
      },
      runtime: {
        mode: 'mixed',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-24T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: 'https://hypertwist.app/open-source/source.zip',
        open_source_repo_url: 'https://github.com/hypertwist/hypertwist',
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [
          {
            platform_key: 'windows',
            platform: 'Windows',
            subtitle: 'Primary shipping lane',
            details: 'Current packaged validation is strongest on the Windows Unreal lane.',
            configured: true,
            channel: 'candidate',
            version: '1.0.0',
            build_id: 'win64-1000',
            published_at: '2026-06-22T00:00:00.000Z',
            file_name: 'HyperTwist-Windows.zip',
            file_size_bytes: 1048576,
            checksum_sha256: 'abc123',
            download_url: null,
            download_available: false,
            validation_summary: {
              lane: 'Windows Unreal packaged validation',
              result: 'passed',
              generated_at: '2026-06-22T01:43:08.7625247Z',
              configuration: 'Development',
              skip_build: true,
              smoke_map_count: 2,
              smoke_maps: [
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_Magic120CellTraining',
                  label: 'Magic120Cell dedicated-family training map',
                  result: 'passed',
                },
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_MagicCube5DTraining',
                  label: 'MagicCube5D dedicated-family training map',
                  result: 'passed',
                },
              ],
            },
          },
        ],
      },
    })

    renderWithProviders(<ChangelogPage />, ['/changelog'])

    expect(screen.getByText('Recent release packets')).toBeTruthy()
    expect(screen.getByText('Detailed chronological feed')).toBeTruthy()
    expect(screen.getAllByText('June 24, 2026').length).toBeGreaterThan(0)
    expect(screen.getByText('Signed-in operator shell now mirrors the native control roster')).toBeTruthy()
    expect(screen.getByText('Native selector-recall diagnostics hardened and revalidated')).toBeTruthy()
    expect(screen.getByText('Choose the right HyperTwist surface')).toBeTruthy()
    const changelogDecisionGuideHeading = screen.getByRole('heading', { name: 'Choose the next best step' })
    const changelogDecisionGuideSection = changelogDecisionGuideHeading.closest('section')
    expect(changelogDecisionGuideSection).toBeTruthy()
    expect(within(changelogDecisionGuideSection as HTMLElement).getByText('Need legal details, release notes, or source links?')).toBeTruthy()
    expect(within(changelogDecisionGuideSection as HTMLElement).getByRole('link', { name: 'Review public notices' }).getAttribute('href')).toBe('/open-source-notices')
    expect(screen.getByText('Release rollout checklist')).toBeTruthy()
    expect(screen.getByText('Read the actual lane that changed')).toBeTruthy()
    expect(screen.getByText(/Pair the release note with the current packaged-validation summary/i)).toBeTruthy()
    expect(screen.getByText('Current packaged desktop proof')).toBeTruthy()
    expect(screen.getByText('Packaged validation passed')).toBeTruthy()
    expect(screen.getByText('Release references and source availability')).toBeTruthy()
    expect(screen.getByRole('link', { name: 'https://notes.hypertwist.app' })).toBeTruthy()
    expect(await screen.findByRole('link', { name: /open release feed/i })).toBeTruthy()
    expect(document.title).toBe('HyperTwist release notes | HyperTwist')
    expect(document.head.querySelector('meta[property=\"og:url\"]')?.getAttribute('content')).toBe('https://hypertwist.app/changelog')
  })

  it('uses the authoritative auth-health launch summary on the public launch-status route when the server provides it', async () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: false,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 2,
        pricePlanMapConfigured: true,
        productPlanMapConfigured: true,
        webhookSecretConfigured: true,
      },
      runtime: {
        mode: 'public',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
      launch: {
        posture: 'preview',
        ready: false,
        readiness: {
          windowsDownloadConfigured: true,
          operatorCheckoutConfigured: true,
          studioCheckoutConfigured: true,
          mplSourceConfigured: true,
          openSourceRepoConfigured: true,
          billingProductPlanMapConfigured: true,
          billingPricePlanMapConfigured: true,
          billingWebhookSecretConfigured: true,
          publicAuthRuntimeReady: true,
        },
        checklist: [
          {
            id: 'windows-download',
            label: 'Windows release authority',
            configured: true,
            requiredForPublicLaunch: true,
          },
        ],
        missingLabels: ['preview-tier launch gate'],
        targets: {
          operatorCheckoutTarget: 'https://buy.paddle.com/operator-authoritative',
          studioCheckoutTarget: 'https://buy.paddle.com/studio-authoritative',
        },
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-29T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: null,
        open_source_repo_url: null,
        commerce: {
          operator_checkout_url: null,
          studio_checkout_url: null,
          plan_price_operator: '$29 / month',
          plan_price_studio: '$99 / month',
        },
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [
          {
            platform_key: 'windows',
            platform: 'Windows',
            subtitle: 'Primary shipping lane',
            details: 'Current packaged validation is strongest on the Windows Unreal lane.',
            configured: true,
            channel: 'preview',
            version: '1.0.0',
            build_id: 'win64-1000',
            published_at: '2026-06-29T00:00:00.000Z',
            file_name: 'HyperTwist-Windows.zip',
            file_size_bytes: 1048576,
            checksum_sha256: 'abc123',
            download_url: null,
            download_available: false,
            validation_summary: {
              lane: 'Windows Unreal packaged validation',
              result: 'passed',
              generated_at: '2026-06-29T01:43:08.7625247Z',
              configuration: 'Development',
              skip_build: true,
              smoke_map_count: 2,
              smoke_maps: [
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_Magic120CellTraining',
                  label: 'Magic120Cell dedicated-family training map',
                  result: 'passed',
                },
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_MagicCube5DTraining',
                  label: 'MagicCube5D dedicated-family training map',
                  result: 'passed',
                },
              ],
            },
          },
        ],
      },
    })

    renderWithProviders(<LaunchStatusPage />, ['/launch-status'])

    expect(await screen.findByText('Account-gated early access')).toBeTruthy()
    expect(await screen.findByText(/Operator checkout: available from the configured Paddle route/i)).toBeTruthy()
    expect(screen.getByText(/Studio checkout: available from the configured Paddle route/i)).toBeTruthy()
  })

  it('renders the expanded legal and digital-delivery guidance across public support surfaces', async () => {
    mockGetAuthHealth.mockResolvedValue({
      ok: true,
      service: 'hypertwist-auth-server',
      supertokens: {
        configured: true,
        reachable: true,
        ready: true,
        apiVersion: '5.4',
        error: null,
        oauth: {
          github: false,
          google: false,
        },
      },
      fallback: {
        enabled: true,
        active: false,
        reason: null,
      },
      billing: {
        statePath: '/var/lib/hypertwist/auth/hypertwist-billing-state.json',
        processedEventCount: 0,
        pricePlanMapConfigured: false,
        productPlanMapConfigured: false,
        webhookSecretConfigured: false,
      },
      runtime: {
        mode: 'mixed',
        public_origin_ready: true,
        cookie_secure: true,
        api_domain: 'https://hypertwist.app',
        website_domain: 'https://hypertwist.app',
        warnings: [],
        errors: [],
      },
    })
    mockGetReleaseManifest.mockResolvedValue({
      ok: true,
      manifest: {
        generated_at: '2026-06-22T12:00:00.000Z',
        support_email: 'hello@hypertwist.app',
        public_docs_url: 'https://docs.hypertwist.app',
        release_notes_url: 'https://notes.hypertwist.app',
        corresponding_source_url: 'https://hypertwist.app/open-source/source.zip',
        open_source_repo_url: 'https://github.com/hypertwist/hypertwist',
        viewer: {
          authenticated: false,
          canDownload: false,
          plan: null,
          role: null,
          accessStatus: null,
        },
        platforms: [
          {
            platform_key: 'windows',
            platform: 'Windows',
            subtitle: 'Primary shipping lane',
            details: 'Current packaged validation is strongest on the Windows Unreal lane.',
            configured: true,
            channel: 'candidate',
            version: '1.0.0',
            build_id: 'win64-1000',
            published_at: '2026-06-22T00:00:00.000Z',
            file_name: 'HyperTwist-Windows.zip',
            file_size_bytes: 1048576,
            checksum_sha256: 'abc123',
            download_url: null,
            download_available: false,
            validation_summary: {
              lane: 'Windows Unreal packaged validation',
              result: 'passed',
              generated_at: '2026-06-22T01:43:08.7625247Z',
              configuration: 'Development',
              skip_build: true,
              smoke_map_count: 2,
              smoke_maps: [
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_Magic120CellTraining',
                  label: 'Magic120Cell dedicated-family training map',
                  result: 'passed',
                },
                {
                  map_url: '/Game/HyperTwistTraining/Maps/L_HyperTwist_MagicCube5DTraining',
                  label: 'MagicCube5D dedicated-family training map',
                  result: 'passed',
                },
              ],
            },
          },
        ],
      },
    })

    const noticesView = renderWithProviders(<OpenSourceNoticesPage />, ['/open-source-notices'])
    expect(within(noticesView.container).getByText('Distribution doctrine')).toBeTruthy()
    expect(within(noticesView.container).getByText('Public pages are distribution surfaces')).toBeTruthy()
    expect(within(noticesView.container).getByText('Release and source references')).toBeTruthy()
    expect((await within(noticesView.container).findAllByRole('link', { name: 'https://hypertwist.app/open-source/source.zip' })).length).toBeGreaterThan(0)
    expect((await within(noticesView.container).findAllByRole('link', { name: 'https://github.com/hypertwist/hypertwist' })).length).toBeGreaterThan(0)
    expect(within(noticesView.container).getByText('Choose the right HyperTwist surface')).toBeTruthy()
    expect(within(noticesView.container).getByText('Choose the next best step')).toBeTruthy()
    expect(within(noticesView.container).getByText('Need legal details, release notes, or source links?')).toBeTruthy()
    expect(within(noticesView.container).getByText('Where each part of HyperTwist lives')).toBeTruthy()
    expect(within(noticesView.container).getAllByText('Offline desktop guide').length).toBeGreaterThan(0)
    expect(within(noticesView.container).getByText('Current packaged desktop proof')).toBeTruthy()
    expect(within(noticesView.container).getByText('Packaged validation passed')).toBeTruthy()

    const privacyView = renderWithProviders(<PrivacyPage />, ['/privacy'])
    expect(within(privacyView.container).getByText('Practical privacy boundary')).toBeTruthy()
    expect(within(privacyView.container).getByText('Browser identity and billing boundary')).toBeTruthy()
    expect(within(privacyView.container).getByText('Choose the right HyperTwist surface')).toBeTruthy()
    expect(within(privacyView.container).getByText('Choose the next best step')).toBeTruthy()
    expect(within(privacyView.container).getByText('Need account access, pairing, or dashboard help?')).toBeTruthy()
    expect(within(privacyView.container).getByText('Browser and desktop responsibilities')).toBeTruthy()
    expect(within(privacyView.container).getByText('Where each part of HyperTwist lives')).toBeTruthy()
    expect(within(privacyView.container).getByText('Support-safe escalation boundary')).toBeTruthy()
    expect(within(privacyView.container).getByText('Current packaged desktop proof')).toBeTruthy()
    expect(within(privacyView.container).getByText('Packaged validation passed')).toBeTruthy()
    expect(within(privacyView.container).getByText('Release references and source availability')).toBeTruthy()
    expect(within(privacyView.container).getByRole('link', { name: 'https://docs.hypertwist.app' })).toBeTruthy()

    const termsView = renderWithProviders(<TermsPage />, ['/terms'])
    expect(within(termsView.container).getByText('Terms in practice')).toBeTruthy()
    expect(within(termsView.container).getByText('Access model')).toBeTruthy()
    expect(within(termsView.container).getByText('Choose the right HyperTwist surface')).toBeTruthy()
    expect(within(termsView.container).getByText('Choose the next best step')).toBeTruthy()
    expect(within(termsView.container).getByText('Need the desktop download?')).toBeTruthy()
    expect(within(termsView.container).getByText('Browser and desktop responsibilities')).toBeTruthy()
    expect(within(termsView.container).getByText('Where each part of HyperTwist lives')).toBeTruthy()
    expect(within(termsView.container).getByText('Release and redistribution checklist')).toBeTruthy()
    expect(within(termsView.container).getByText('Current packaged desktop proof')).toBeTruthy()
    expect(within(termsView.container).getByText('Packaged validation passed')).toBeTruthy()
    expect(within(termsView.container).getByText('Release references and source availability')).toBeTruthy()
    expect(within(termsView.container).getByRole('link', { name: 'https://notes.hypertwist.app' })).toBeTruthy()

    const shippingPaymentView = renderWithProviders(<ShippingPaymentPage />, ['/shipping-payment'])
    expect(within(shippingPaymentView.container).getByText('Digital delivery workflow')).toBeTruthy()
    expect(within(shippingPaymentView.container).getByText('Private download handoff')).toBeTruthy()
    expect(within(shippingPaymentView.container).getByText('What happens after access is granted')).toBeTruthy()
    expect(within(shippingPaymentView.container).getByText('Choose the right HyperTwist surface')).toBeTruthy()
    expect(within(shippingPaymentView.container).getByText('Choose the next best step')).toBeTruthy()
    expect(within(shippingPaymentView.container).getByText('Need pricing, billing, or subscription help?')).toBeTruthy()
    expect(within(shippingPaymentView.container).getByText('Release references and source availability')).toBeTruthy()
    expect(within(shippingPaymentView.container).getByRole('link', { name: 'https://notes.hypertwist.app' })).toBeTruthy()
    expect(within(shippingPaymentView.container).getByText('Where each part of HyperTwist lives')).toBeTruthy()
    expect(within(shippingPaymentView.container).getAllByText('Offline desktop guide').length).toBeGreaterThan(0)
    expect(within(shippingPaymentView.container).getByText('Terms of access in practice')).toBeTruthy()
    expect(within(shippingPaymentView.container).getByText('Distribution doctrine')).toBeTruthy()
    expect(within(shippingPaymentView.container).getByText('Release and redistribution checklist')).toBeTruthy()
    expect(within(shippingPaymentView.container).getByText('Current packaged desktop proof')).toBeTruthy()
    expect(within(shippingPaymentView.container).getByText('Packaged validation passed')).toBeTruthy()
  })
})
