// A deep link to the old history route redirects to the audit page keeping // section, actor, since and the hash, and the feed loads with filter chips. const assert = require('node:assert/strict'); const { trackAudit } = require('./helpers/audit-helpers.cjs'); module.exports = async ({ page, go, shot, fail }) => { const { lastRequest } = trackAudit(page); await go('/settings/audit'); const status = await page.evaluate(async () => (await fetch('/api/auth/status')).json()); const actor = status?.user?.id; assert.ok(actor, 'signed-in identity has no id'); const deepLink = `/settings/history?section=container-runtime-policies&actor=${encodeURIComponent(actor)}&since=30d#deep`; await go(deepLink); assert.match(page.url(), /\/settings\/audit\?/, 'history did not redirect to the audit route'); assert.match(page.url(), /section=container-runtime-policies/, 'redirect dropped section'); assert.match(page.url(), new RegExp(`actor=${encodeURIComponent(actor)}`), 'redirect dropped actor'); assert.match(page.url(), /since=30d/, 'redirect dropped since'); assert.match(page.url(), /#deep$/, 'redirect dropped the hash'); const redirected = lastRequest(); assert.ok(redirected, 'the redirect issued no /api/audit request'); assert.equal(redirected.searchParams.get('kind'), 'container-runtime-policies'); assert.equal(redirected.searchParams.get('actor'), actor); // The feed must be readable before anything below can mean anything. A 500 // here is the whole page: say what the server answered instead of timing out. const probe = await page.evaluate(async () => { const response = await fetch('/api/audit?limit=1'); return { status: response.status, body: await response.text() }; }); if (probe.status !== 200) { await shot('unavailable'); fail(`GET /api/audit returned ${probe.status}: ${probe.body.slice(0, 200)}`); return; } const kindChip = page.locator('ul[aria-label="Active filters"] li', { hasText: 'Kind:' }); await kindChip.first().waitFor({ timeout: 8000 }); assert.match(await kindChip.first().innerText(), /Container runtime policies/, 'kind chip missing its catalog title'); assert.match( await page.locator('ul[aria-label="Active filters"] li', { hasText: 'Actor:' }).first().innerText(), new RegExp(actor), 'actor chip missing', ); await shot('redirect'); await go('/settings/audit'); await page.locator('[data-row-key]').first().waitFor(); await shot('desktop'); };