Bundles the prior autonomous-session output that was sitting unstaged: - Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances) - country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk after the per-subpath dynamic-import approach silently failed in webpack) - Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index, redirects (ocr to ai, reports to dashboard, invitations to users), docs/admin-ia-proposal.md - Per-template email tester (registry + endpoint + UI on Email admin page) - Cancel-document mode picker (delete-from-Documenso vs keep-for-audit) - Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers - Customize-widgets per-region sortables at xl+ (charts/rails/feed); single flat sortable below xl when the layout stacks; per-viewport saved orders - Audit doc updates capturing each shipped item - Lint fixes: react-compiler immutability in DonutChart (reduce instead of let-reassign), set-state-in-effect disables in CountryFlag and UploadForSigning preview-bytes effect, unused 'confirm' destructures in interest contract + reservation tabs, unescaped apostrophe in test-template card copy
73 lines
2.5 KiB
TypeScript
73 lines
2.5 KiB
TypeScript
import 'dotenv/config';
|
|
import { test, expect } from '@playwright/test';
|
|
import { io, type Socket } from 'socket.io-client';
|
|
|
|
import { login, apiHeaders, getPortId } from '../smoke/helpers';
|
|
|
|
/**
|
|
* Real-API socket round-trip for the Phase B alert engine.
|
|
*
|
|
* - Joins the port's socket room
|
|
* - Posts directly to the alert engine via an admin endpoint that runs
|
|
* `runAlertEngineForPorts([portId])`
|
|
* - Verifies an `alert:created` event lands within a few seconds
|
|
*
|
|
* Skips when SOCKET_URL isn't configured (local dev defaults to the
|
|
* NEXT_PUBLIC_SOCKET_URL the page uses, but the CI server may differ).
|
|
*/
|
|
|
|
const SOCKET_URL =
|
|
process.env.NEXT_PUBLIC_SOCKET_URL ?? process.env.SOCKET_URL ?? 'http://localhost:3000';
|
|
|
|
test.describe('Alert engine - socket fanout', () => {
|
|
test.skip(
|
|
!process.env.RUN_ALERT_ENGINE_REALAPI,
|
|
'RUN_ALERT_ENGINE_REALAPI not set (opt-in; emits real events)',
|
|
);
|
|
|
|
test('engine sweep emits alert:created over the socket', async ({ page }) => {
|
|
await login(page, 'super_admin');
|
|
const portId = await getPortId(page);
|
|
const headers = await apiHeaders(page);
|
|
|
|
// Listen on the socket. We resolve when an alert:created event lands
|
|
// for our port id, or reject after a timeout.
|
|
const cookieHeader = await page.evaluate(() => document.cookie);
|
|
const socket: Socket = io(SOCKET_URL, {
|
|
transports: ['websocket'],
|
|
extraHeaders: { Cookie: cookieHeader },
|
|
});
|
|
socket.emit('join:port', { portId });
|
|
|
|
const eventPromise = new Promise<{ portId: string; ruleId: string }>((resolve, reject) => {
|
|
const timer = setTimeout(
|
|
() => reject(new Error('Timed out waiting for alert:created')),
|
|
15_000,
|
|
);
|
|
socket.on('alert:created', (payload: { portId: string; ruleId: string }) => {
|
|
if (payload.portId === portId) {
|
|
clearTimeout(timer);
|
|
resolve(payload);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Trigger a sweep against the running server.
|
|
const triggerRes = await page.request.post(`/api/v1/admin/alerts/run-engine`, {
|
|
headers,
|
|
});
|
|
expect([200, 404]).toContain(triggerRes.status());
|
|
if (triggerRes.status() === 404) {
|
|
// The trigger route is opt-in scaffolding; skip if not present in this build.
|
|
socket.disconnect();
|
|
test.skip(true, 'admin/alerts/run-engine not implemented in this build');
|
|
return;
|
|
}
|
|
|
|
const payload = await eventPromise;
|
|
expect(payload.portId).toBe(portId);
|
|
|
|
socket.disconnect();
|
|
});
|
|
});
|