import { expect, test } from '@playwright/test'

/**
 * Live-stack verification — hits the deployed deck at OVERDECK_LIVE_URL (default :31337).
 * Run via e2e-remote so headless Playwright is allowed:
 *   OVERDECK_LIVE_URL=http://e14:31337 ~/.claude/bin/e2e-remote --key bots-live -- \
 *     pnpm exec playwright test bots-live.spec.ts --config playwright.live.config.ts
 */
const LIVE_URL = process.env.OVERDECK_LIVE_URL ?? 'http://127.0.0.1:31337'

test.describe('bots page (live stack)', () => {
  test.skip(!process.env.OVERDECK_LIVE_URL, 'requires an explicit live deployment URL')
  test.use({ baseURL: LIVE_URL })

  test('shows named fleet with observability columns, not opaque bot ids', async ({ page }) => {
    await page.goto('/bots', { waitUntil: 'domcontentloaded' })

    await expect(page.getByRole('heading', { level: 4, name: 'Fleet summary' })).toBeVisible({ timeout: 15_000 })
    await expect(page.getByRole('heading', { level: 4, name: 'Bots (Botmaster)' })).toBeVisible()

    // Registry names — never raw D1 ids as the primary label.
    await expect(page.getByText('HetziBot')).toBeVisible()
    await expect(page.getByText('ZyncBot')).toBeVisible()
    await expect(page.getByText('FewTok')).toBeVisible()
    await expect(page.getByText('4laMbKGL04')).toHaveCount(0)

    // Traffic/runtime labels from the new adapter.
    await expect(page.getByText('running · idle').first()).toBeVisible()
    await expect(page.getByText(/running · last call \d+d ago/)).toBeVisible()

    // Full-density observability columns.
    await expect(page.getByText('Last active')).toBeVisible()
    await expect(page.getByText('Total', { exact: true })).toBeVisible()
    await expect(page.getByText('Reporting')).toBeVisible()

    // HetziBot historical metrics surface even when 24h is zero.
    await expect(page.getByRole('row', { name: /HetziBot/ })).toContainText('124')
  })
})
