Files
nmon/web/e2e/specs/setup.spec.ts
Vibe Coder f31fb3712a
Some checks failed
ci / lint (push) Successful in 4m19s
ci / openapi (push) Successful in 29s
ci / postgres (push) Successful in 4m55s
ci / test (push) Failing after 19m48s
Add settings forms, first-install wizard, webhook presets, help and poll tools
Make nmon easier to install and run without editing YAML by hand:

- Settings: point-and-click forms over config.yaml (GET/PUT
  /api/v1/settings/form); the YAML editor moves to /settings/yaml.
- First install: with no sign-in configured nmon starts in install
  mode, serves only the setup wizard (sign-in, basics, devices,
  alerting) and closes it for good once sign-in is saved. A
  self-signed certificate is generated when no TLS source is given.
  poller.interval becomes a config setting.
- Reverse proxies: opt-in --http-listen plain-HTTP listener beside
  HTTPS; sign-in stays required.
- Webhooks: Generic, Teams Adaptive Card, Slack and Discord presets,
  template preview and test send.
- Help: the operations, coverage and profile docs served at /help.
- Polling: per-device "Poll now", a dry-run test poll returning an
  SNMP trace, and time-limited in-memory SNMP debug recording, in the
  UI and as `nmon device poll`.
- Ansible: deploys into install mode when no sign-in is set, and no
  longer overwrites the config.yaml the wizard wrote.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017TuKgyKve2XLFtrrXWMi2w
2026-10-25 06:31:12 +00:00

148 lines
8.3 KiB
TypeScript

// The first-install wizard against the mock API: redirect into install mode, every step, the skip paths, the
// install-mode gate and the redirect away from /setup once setup is complete.
import { expect, test } from './support.ts'
import type { Page } from '@playwright/test'
test.describe('setup wizard in install mode', () => {
test.use({ mock: { setup: 'install' } })
async function signIn(page: Page, password = 'correct horse battery') {
await page.getByTestId('su-pass').fill(password)
await page.getByTestId('su-confirm').fill(password)
await page.getByTestId('setup-next').click()
}
test('every route redirects to /setup, help still works, and the warning is shown', async ({ page }) => {
await page.goto('/devices')
await expect(page).toHaveURL(/\/setup$/)
await expect(page.getByTestId('setup-wizard')).toBeVisible()
await expect(page.getByTestId('setup-warning')).toContainText('anyone who can reach')
await expect(page.getByTestId('setup-progress-signin')).toHaveAttribute('data-state', 'current')
await page.goto('/settings')
await expect(page).toHaveURL(/\/setup$/)
await page.goto('/help/operations')
await expect(page.getByTestId('help-page')).toBeVisible()
await expect(page.getByTestId('setup-shell')).toBeVisible()
})
test('step 1 validates the password and the user before anything is sent', async ({ page }) => {
await page.goto('/setup')
await expect(page.getByTestId('su-user')).toHaveValue('admin')
await page.getByTestId('su-pass').fill('short')
await page.getByTestId('su-confirm').fill('other')
await page.getByTestId('setup-next').click()
await expect(page.getByTestId('su-pass-error')).toContainText('at least 12')
await expect(page.getByTestId('su-confirm-error')).toContainText('differ')
await expect(page.getByTestId('setup-step-signin')).toBeVisible()
await page.getByTestId('su-oidc').check()
await expect(page.getByTestId('su-redirect')).toHaveValue(/\/auth\/callback$/)
await page.getByTestId('setup-next').click()
await expect(page.getByTestId('su-issuer-error')).toBeVisible()
await expect(page.getByTestId('su-client-secret-error')).toBeVisible()
})
test('walks sign-in, basics, devices, alerting and finish, then goes to the break-glass sign-in', async ({ page }) => {
await page.route('**/auth/breakglass', (r) => r.fulfill({ status: 200, contentType: 'text/plain', body: 'signed in here' }))
await page.goto('/setup')
// 1 sign-in
const signinReq = page.waitForRequest((r) => r.url().endsWith('/api/v1/setup/signin'))
await signIn(page)
const sent = (await signinReq).postDataJSON() as { username: string; oidc?: unknown }
expect(sent.username).toBe('admin')
expect(sent.oidc).toBeUndefined()
// 2 basics
await expect(page.getByTestId('setup-step-basics')).toBeVisible()
await expect(page.getByTestId('setup-progress-signin')).toHaveAttribute('data-state', 'done')
await expect(page.getByTestId('su-hot')).toHaveAttribute('placeholder', '30d')
await page.getByTestId('su-poll').fill('10s')
await page.getByTestId('setup-next').click()
await expect(page.getByTestId('su-poll-error')).toBeVisible()
await page.getByTestId('su-poll').fill('2m')
const basicsReq = page.waitForRequest((r) => r.method() === 'PUT' && r.url().endsWith('/api/v1/settings/form'))
await page.getByTestId('setup-next').click()
const patch = (await basicsReq).postDataJSON() as Record<string, unknown>
expect(Object.keys(patch).sort()).toEqual(['poller_interval', 'retention', 'timezone'])
expect(patch.poller_interval).toBe('2m')
// 3 devices: a name is rejected, a dead address fails, the others are discovered live
await expect(page.getByTestId('setup-step-devices')).toBeVisible()
await page.getByTestId('snmp-community').fill('public')
await page.getByTestId('su-addresses').fill('switch1.example.net')
await page.getByTestId('su-add-devices').click()
await expect(page.getByTestId('su-addresses-error')).toContainText('switch1.example.net')
await page.getByTestId('su-addresses').fill('192.0.2.10\n2001:db8::11\n192.0.2.99')
await page.getByTestId('su-add-devices').click()
await expect(page.getByTestId('su-add-result')).toHaveCount(3)
await expect(page.locator('[data-testid=su-add-result][data-state=failed]')).toHaveCount(1)
await expect(page.locator('[data-testid=su-add-result][data-state=added]')).toHaveCount(2)
await expect(page.getByTestId('su-device-row')).toHaveCount(2)
await expect(page.locator('[data-testid=su-device-row][data-state=discovered]')).toHaveCount(2, { timeout: 15_000 })
await page.getByTestId('setup-next').click()
// 4 alerting
await expect(page.getByTestId('setup-step-alerting')).toBeVisible()
// The mock's settings are seeded with one receiver, so the new card is the second; it must not replace the first.
await expect(page.getByTestId('su-existing-receivers')).toContainText('ops-hook')
await page.getByTestId('f-rcv-name-1').fill('noc')
await page.getByTestId('f-rcv-url-1').fill('https://hooks.example.net/nmon')
await page.getByTestId('f-rcv-tpl-1-preset').selectOption('generic')
await page.getByTestId('f-rcv-tpl-1-test').click()
await expect(page.getByTestId('f-rcv-tpl-1-result')).toContainText('Delivered')
await expect(page.getByTestId('su-policies')).toBeChecked()
const policies = page.waitForRequest((r) => r.url().endsWith('/api/v1/setup/recommended-policies'))
const receivers = page.waitForRequest((r) => r.method() === 'PUT' && r.url().endsWith('/api/v1/settings/form'))
await page.getByTestId('setup-next').click()
const saved = (await receivers).postDataJSON() as { receivers: { name: string }[] }
expect(saved.receivers.map((r) => r.name)).toEqual(['ops-hook', 'noc'])
await policies
// 5 finish
await expect(page.getByTestId('setup-step-finish')).toBeVisible()
const summary = page.getByTestId('setup-summary')
await expect(summary).toContainText('break-glass admin is ready')
await expect(summary).toContainText('time zone, retention and poll interval saved')
await expect(summary).toContainText('2 added')
await expect(summary).toContainText('"noc"')
await expect(summary).toContainText('recommended alert policies turned on')
await page.getByTestId('setup-next').click()
await expect(page).toHaveURL(/\/auth\/breakglass$/)
await expect(page.locator('body')).toContainText('signed in here')
})
test('steps 2 to 4 can be skipped, Back works, and the summary says what was left', async ({ page }) => {
await page.route('**/auth/breakglass', (r) => r.fulfill({ status: 200, contentType: 'text/plain', body: 'ok' }))
await page.goto('/setup')
await expect(page.getByTestId('setup-skip')).toHaveCount(0)
await expect(page.getByTestId('setup-back')).toHaveCount(0)
await signIn(page)
await expect(page.getByTestId('setup-step-basics')).toBeVisible()
await page.getByTestId('setup-skip').click()
await expect(page.getByTestId('setup-step-devices')).toBeVisible()
await page.getByTestId('setup-back').click()
await expect(page.getByTestId('setup-step-basics')).toBeVisible()
await page.getByTestId('setup-skip').click()
await page.getByTestId('setup-skip').click()
await expect(page.getByTestId('setup-step-alerting')).toBeVisible()
await page.getByTestId('setup-skip').click()
const summary = page.getByTestId('setup-summary')
await expect(summary).toContainText('defaults kept')
await expect(summary).toContainText('none yet')
await expect(summary).toContainText('no receiver yet')
await expect(summary).toContainText('nothing alerts')
await page.getByTestId('setup-next').click()
await expect(page).toHaveURL(/\/auth\/breakglass$/)
})
test('each step has a help link into the operations guide', async ({ page }) => {
await page.goto('/setup')
await page.getByTestId('help-link-setup-signin').click()
await expect(page).toHaveURL(/\/help\/operations#setup-wizard-sign-in$/)
await expect(page.locator('#setup-wizard-sign-in')).toBeVisible()
})
})
test.describe('after setup is complete', () => {
test('/setup goes back to the app', async ({ page }) => {
await page.goto('/setup')
await expect(page).toHaveURL(/\/$/)
await expect(page.getByTestId('setup-wizard')).toHaveCount(0)
})
})