fix(points): welcome check-in awards +10; add Sessions view, AI connection test, silent reload

The front-desk check-in set checked_in and printed badges but awarded nothing,
so the +10 depended on which check-in a person happened to get. Every award
path was reviewed:

- welcome_checkin awards +10 (category checkin) on a genuine first check-in and
  returns points + points_awarded; checkin_attendee and preview_welcome_checkin
  return points_awarded too.
- set_registration_checked_in(false) deleted all checkin points while keeping
  the checkins rows, and switching back on awarded nothing -- one mistaken
  toggle destroyed those points permanently. ON now recomputes from the rows
  that still exist and awards only the shortfall: reversible, still unfarmable.
- The staff/Admin/@appe.at exclusion stays (product decision) but is no longer
  silent: three-way points sheets in the scanner, "no points" with a tooltip in
  Registrations, and the Contacts points modal refuses to apply rather than
  letting adjust_points (void) no-op quietly.

Also in this change:
- admin silent refresh (5s poll + 500ms after writes) across all data views;
  Registrations patches in place so rows never slide under the cursor
- Settings "Validate AI connection" via a new sidecar POST /llm-test verdict
  endpoint (never leaks the key, distinguishes "no usage block" from "off")
- new Sessions view between Schedule and Activity: speakers, attendance,
  ratings, attendee filter, and one button that summarises every session with
  feedback (one request each, concurrency 3, UI blocked until all settle)
- provider requests disable thinking through one shared body builder sending
  both reasoning_effort:"none" and chat_template_kwargs.enable_thinking

SQL: 113 / 57 / 24 assertions (set_registration_checked_in section 3 was
rewritten, it asserted the bug). Sidecar 34 unit tests. Full e2e 202 passed,
0 failed. Migration applied locally only -- not deployed.
This commit is contained in:
Lago committed 2026-10-19 20:14:03 +02:00
1 parent 96e4e6a6ea
commit fdb6045966
35 files changed
+2778 -154

No files matched your search

+189
View File
@@ -0,0 +1,189 @@
import { test, expect, type Page } from '@playwright/test';
import { APP_URL, EVENT_ID, ID } from '../src/helpers/config';
import { login } from '../src/helpers/auth';
import { db, psql, psqlScalar, sqlQuote } from '../src/helpers/db';
import { AppPage } from '../src/pages/AppPage';
import { ScanPage } from '../src/pages/ScanPage';
/**
* Points awarded by the two check-in paths, measured against the real database.
*
* The bug this guards: the front-desk (welcome) check-in awarded NOTHING while a
* session scan awarded +10, so "check me in" paid out differently depending on
* which check-in a person happened to get. On top of that, the scanner sheet
* claimed "+10 pts · now 0" for staff accounts, which never earn anything.
*
* Every assertion is the DB row, not just the UI text — the sheet and the score
* have to agree.
*/
const EMAIL = '[email protected]';
const TOKEN = 'CVV-POINTS-FLOW-01';
const STAFF_EMAIL = '[email protected]';
const STAFF_TOKEN = 'CVV-POINTS-STAFF-01';
function someSessionId(): string {
return psqlScalar(`select s.id from public.sessions s
join public.slots sl on sl.id = s.slot_id
where s.event_id = ${sqlQuote(EVENT_ID)} and sl.type <> 'service_session'
order by sl.id, s.id limit 1`);
}
function provision(email: string, token: string, type: 'attendee' | 'staff'): void {
psql(`insert into public.contacts (email, full_name, is_admin)
values (${sqlQuote(email)}, ${sqlQuote(type === 'staff' ? 'Staff Points Test' : 'Points Flow Attendee')}, false)
on conflict (email) do update set full_name = excluded.full_name, is_admin = false`);
psql(`insert into public.registrations (event_id, contact_email, type, checked_in, points, qr_token)
values (${sqlQuote(EVENT_ID)}, ${sqlQuote(email)}, ${sqlQuote(type)}, false, 0, ${sqlQuote(token)})
on conflict (event_id, contact_email)
do update set checked_in = false, points = 0, qr_token = excluded.qr_token, type = excluded.type`);
psql(`delete from public.checkins where contact_email = ${sqlQuote(email)}`);
psql(`delete from public.points_log where contact_email = ${sqlQuote(email)}`);
psql(`delete from pgmq.q_badge_print where message->'sample'->>'email' = ${sqlQuote(email)}`);
}
function cleanup(email: string): void {
psql(`delete from public.checkins where contact_email = ${sqlQuote(email)}`);
psql(`delete from public.points_log where contact_email = ${sqlQuote(email)}`);
psql(`delete from pgmq.q_badge_print where message->'sample'->>'email' = ${sqlQuote(email)}`);
psql(`delete from public.registrations where contact_email = ${sqlQuote(email)}`);
psql(`delete from public.contacts where email = ${sqlQuote(email)}`);
}
const pointsOf = (email: string): number => db.registration(email)?.points ?? -1;
/**
* Toggle the admin check-in switch through the real RPC. psql has no JWT and
* `is_admin()` reads `auth.jwt()`, so the claims are supplied exactly as
* PostgREST would supply them. Each psql() call is its own session, so `set
* local role` cannot leak, and the write is committed (this test asserts on
* persisted points, not on a rollback).
*/
const ADMIN_CLAIMS =
'{"sub":"00000000-0000-0000-0000-000000000000","email":"[email protected]","role":"authenticated","exp":1893456000}';
function toggleCheckedIn(email: string, checkedIn: boolean, field: 'points_removed' | 'points_added'): number {
const out = psql(`begin;
set local role authenticated;
set local request.jwt.claims = ${sqlQuote(ADMIN_CLAIMS)};
select ${field} from public.set_registration_checked_in(
(select id from public.registrations
where contact_email = ${sqlQuote(email)} and event_id = ${sqlQuote(EVENT_ID)}),
${checkedIn});
commit;`);
// psql echoes BEGIN/COMMIT around the row, so take the numeric line.
const value = out.split('\n').map((l) => l.trim()).filter((l) => /^-?\d+$/.test(l)).pop();
if (value === undefined) throw new Error(`set_registration_checked_in returned no number: ${out}`);
return Number(value);
}
test.describe('Check-in points (+10 per path)', () => {
test.beforeEach(() => {
provision(EMAIL, TOKEN, 'attendee');
provision(STAFF_EMAIL, STAFF_TOKEN, 'staff');
});
test.afterAll(() => {
cleanup(EMAIL);
cleanup(STAFF_EMAIL);
});
async function openScanner(page: Page) {
const app = new AppPage(page, APP_URL);
const scan = new ScanPage(page);
await login(page, APP_URL, ID.staff);
await app.waitForAdmitted();
await app.gotoTab('scan');
await scan.setStaffMode();
return scan;
}
test('CONV-PTS-001 the welcome (front desk) check-in awards +10 and says so', async ({ page }) => {
const scan = await openScanner(page);
expect(pointsOf(EMAIL), 'starts at zero').toBe(0);
await scan.setWelcomeMode();
// The confirmation sheet promises the points before the write happens.
await scan.scanCode(TOKEN);
await expect(scan.welcomeConfirm()).toContainText(/awards \+10 points/i);
await scan.confirmWelcome();
await expect(scan.welcomeResult()).toBeVisible();
await expect(scan.welcomePoints()).toHaveText('+10 pts · now 10');
expect(pointsOf(EMAIL)).toBe(10);
expect(db.isWelcomeCheckedIn(EMAIL)).toBe(true);
// Audited, so the score can be explained later.
expect(psqlScalar(`select category || '=' || delta from public.points_log
where contact_email = ${sqlQuote(EMAIL)} order by created_at desc limit 1`)).toBe('checkin=10');
});
test('CONV-PTS-002 a second welcome adds nothing, and a session scan then totals 20', async ({ page }) => {
const scan = await openScanner(page);
const session = someSessionId();
expect(session, 'the active event needs at least one checkable session').toBeTruthy();
await scan.setWelcomeMode();
await scan.scanWelcome(TOKEN);
expect(pointsOf(EMAIL)).toBe(10);
await scan.dismissResult();
// Same person welcomed twice: the sheet must say "no extra points", not "+10".
await scan.scanWelcome(TOKEN);
await expect(scan.welcomePoints()).toContainText(/no extra points/i);
expect(pointsOf(EMAIL)).toBe(10);
await scan.dismissResult();
// Now a session scan — the second, independent +10.
await scan.setSessionMode();
await scan.selectSession(session);
await scan.scanCode(TOKEN);
await expect(scan.sessionResult()).toBeVisible();
await expect(scan.sessionPoints()).toHaveText('+10 pts · now 20');
expect(pointsOf(EMAIL)).toBe(20);
});
test('CONV-PTS-003 a staff pass checks in fine but earns nothing, visibly', async ({ page }) => {
const scan = await openScanner(page);
await scan.setWelcomeMode();
await scan.scanCode(STAFF_TOKEN);
await expect(scan.welcomeConfirm()).toContainText(/does not earn points/i);
await scan.confirmWelcome();
await expect(scan.welcomePoints()).toContainText(/staff earn no points/i);
await expect(scan.welcomePoints()).not.toContainText('+10');
// Checked in, zero points — the exclusion is deliberate, and now it says so.
expect(db.isWelcomeCheckedIn(STAFF_EMAIL)).toBe(true);
expect(pointsOf(STAFF_EMAIL)).toBe(0);
expect(psqlScalar(`select count(*) from public.points_log where contact_email = ${sqlQuote(STAFF_EMAIL)}`)).toBe('0');
});
test('CONV-PTS-004 re-checking via the admin toggle restores the points the check-in rows justify', async ({ page }) => {
const scan = await openScanner(page);
const session = someSessionId();
expect(session).toBeTruthy();
await scan.setWelcomeMode();
await scan.scanWelcome(TOKEN);
// Wait for the sheet before dismissing: `dismissResult` only clicks when the
// button is already there, and dismissing too early leaves the backdrop up.
await expect(scan.welcomeResult()).toBeVisible();
await scan.dismissResult();
await scan.setSessionMode();
await scan.selectSession(session);
await scan.scanCode(TOKEN);
await expect(scan.sessionResult()).toBeVisible();
expect(pointsOf(EMAIL)).toBe(20);
// Admin switches the pass off, then back on — through the real RPC, which is
// the only admin path and the one that lost points permanently before.
expect(toggleCheckedIn(EMAIL, false, 'points_removed')).toBe(20);
expect(pointsOf(EMAIL)).toBe(0);
expect(toggleCheckedIn(EMAIL, true, 'points_added')).toBe(20);
expect(pointsOf(EMAIL)).toBe(20);
// A third click must not farm points: the target is derived from the
// check-in rows that exist, never from the number of toggles.
expect(toggleCheckedIn(EMAIL, true, 'points_added')).toBe(0);
expect(pointsOf(EMAIL)).toBe(20);
});
});
+40 -3
View File
@@ -41,7 +41,7 @@ const event = {
/** Mutable per-test fixtures so a handler can observe its own writes. */
type Harness = { regs: Reg[]; registrationFetches: number; setCheckedInDelayMs: number };
async function openAdmin(page: Page, view: 'Registrations' | 'Settings', h: Harness) {
async function openAdmin(page: Page, view: 'Registrations' | 'Settings' | 'Contacts', h: Harness) {
const payload = Buffer.from(JSON.stringify({ sub: user.id, exp: Math.floor(Date.now() / 1000) + 3600 })).toString('base64url');
const session = { user, access_token: `eyJhbGciOiJIUzI1NiJ9.${payload}.test`, refresh_token: 'r', expires_in: 3600, token_type: 'bearer' };
await page.route('**/auth/v1/**', (r) => r.fulfill({ json: new URL(r.request().url()).pathname.endsWith('/user') ? user : session }));
@@ -98,11 +98,48 @@ test.describe('Registrations check-in toggle', () => {
await rowToggle(page, 'Ann A').click();
await expect(page.getByText(/Ann A: checked in/)).toBeVisible();
// The whole point: no list reload, therefore no re-sort and no jumping row.
// The whole point: no reload on the write path, therefore no re-sort and no
// jumping row. The checkbox still shows the new state.
expect(h.registrationFetches, 'the toggle must not refetch registrations').toBe(fetchesAfterLoad);
expect(await order(page)).toEqual(before);
// The row still shows the new state.
await expect(rows(page).filter({ hasText: 'Ann A' }).locator('input[type=checkbox]')).toBeChecked();
// The silent pull does arrive (500 ms after the write), and this is the other
// half of the promise: it patches in place instead of reordering or blanking.
await expect.poll(() => h.registrationFetches, { timeout: 5_000 }).toBeGreaterThan(fetchesAfterLoad);
await expect(rows(page)).toHaveCount(4);
expect(await order(page)).toEqual(before);
await expect(rows(page).filter({ hasText: 'Ann A' }).locator('input[type=checkbox]')).toBeChecked();
});
test('a staff row says why it has no points instead of showing 0', async ({ page }) => {
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 0 };
h.regs[3].points = 0; // Dee D, type staff — never earns anything
await openAdmin(page, 'Registrations', h);
const staffRow = rows(page).filter({ hasText: 'Dee D' }).first();
await expect(staffRow.getByTestId('points-exempt-r4')).toBeVisible();
await expect(staffRow.getByTestId('points-exempt-r4')).toContainText('no points');
// Attendees keep the plain number.
await expect(rows(page).filter({ hasText: 'Ann A' }).first().locator('.pts')).toHaveText('40');
await expect(rows(page).filter({ hasText: 'Ann A' }).first().getByTestId('points-exempt-r1')).toHaveCount(0);
});
test('restoring check-in on a row that lost its points reports the award', async ({ page }) => {
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 0 };
// The toggle had been switched off before, so points sit at 0 while the
// server still counts real check-in rows: restoring must top up, not zero.
h.regs[1].checked_in = false;
h.regs[1].points = 0;
await openAdmin(page, 'Registrations', h);
// Registered after openAdmin's handler so it wins (Playwright matches the
// most recently added route first).
await page.route('**/rpc/set_registration_checked_in*', (route) =>
route.fulfill({ json: [{ registration_id: 'r2', checked_in: true, points_removed: 0, points_added: 20 }] }));
await rowToggle(page, 'Bob B').click();
await expect(page.getByText(/\+20 check-in pts restored/)).toBeVisible();
await expect(rows(page).filter({ hasText: 'Bob B' }).locator('.pts')).toHaveText('20');
});
test('only the toggled row is busy; the rest of the table stays usable', async ({ page }) => {
+253
View File
@@ -0,0 +1,253 @@
import { test, expect, type Page, type Route } from '@playwright/test';
const adminUrl = process.env.CONVIVO_ADMIN_URL || 'http://localhost:3001';
const eventId = 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa';
const user = { id: '99999999-9999-4999-8999-999999999999', email: '[email protected]', aud: 'authenticated', role: 'authenticated', app_metadata: {}, user_metadata: {} };
/**
* The Sessions view: per-session speakers and attendance, an attendee filter
* that answers "which sessions did this person go to?", and one button that
* summarises every session with feedback — blocking the page until all the
* requests have settled, then storing each result.
*/
type Summary = {
scope: string; target_id: string; event_id: string; session_id: string | null; summary: string;
response_count: number; source_fingerprint: string; model: string; generated_at: string;
};
type Harness = {
/** session ids that have at least one feedback row */
feedbackSessions: string[];
/** session ids that already have a stored summary */
stored: string[];
/** per-request artificial latency, so the overlay can be observed mid-run */
summaryDelayMs: number;
failFor: string[];
/** filled in by the route as requests arrive */
summaryRequests: string[];
};
const mkSessions = () => [
{ id: 's1', event_id: eventId, slot_id: 1, title: 'Opening Keynote', description: 'Why we are here.', room: 'Hall A', capacity: 200, level: 'all', area: 'keynote', average_feedback: null, ai_generated_feedback: null, material_path: null, created_at: 'x' },
{ id: 's2', event_id: eventId, slot_id: 1, title: 'Power Apps Deep Dive', description: null, room: 'Room 2', capacity: 40, level: '200', area: 'power apps', average_feedback: null, ai_generated_feedback: null, material_path: null, created_at: 'x' },
{ id: 's3', event_id: eventId, slot_id: 2, title: 'Copilot Workshop', description: null, room: 'Room 3', capacity: null, level: null, area: null, average_feedback: null, ai_generated_feedback: null, material_path: null, created_at: 'x' },
];
const slots = [
{ id: 1, event_id: eventId, type: 'session', name: 'Morning', slot_date: '2026-11-01', start_time: '09:00:00', end_time: '10:00:00' },
{ id: 2, event_id: eventId, type: 'session', name: 'Afternoon', slot_date: '2026-11-01', start_time: '13:00:00', end_time: '14:00:00' },
];
const contacts = [
{ email: '[email protected]', full_name: 'Admin User', is_admin: true },
{ email: '[email protected]', full_name: 'Ann Example', is_admin: false },
{ email: '[email protected]', full_name: 'Bob Other', is_admin: false },
{ email: '[email protected]', full_name: 'Ann Speaker', is_admin: false },
];
/** session_speakers is returned for the embedded-filter shape the view uses. */
const speakers = [
{ session_id: 's1', contact_email: '[email protected]' },
{ session_id: 's2', contact_email: '[email protected]' },
];
const checkins = [
{ id: 'c1', event_id: eventId, session_id: 's1', contact_email: '[email protected]', staff_email: '[email protected]', created_at: '2026-11-01T09:01:00Z' },
{ id: 'c2', event_id: eventId, session_id: 's1', contact_email: '[email protected]', staff_email: '[email protected]', created_at: '2026-11-01T09:02:00Z' },
{ id: 'c3', event_id: eventId, session_id: 's2', contact_email: '[email protected]', staff_email: '[email protected]', created_at: '2026-11-01T09:31:00Z' },
];
async function openAdmin(page: Page, h: Harness, opts: { configured?: boolean } = {}) {
const payload = Buffer.from(JSON.stringify({ sub: user.id, exp: Math.floor(Date.now() / 1000) + 3600 })).toString('base64url');
const session = { user, access_token: `eyJhbGciOiJIUzI1NiJ9.${payload}.test`, refresh_token: 'r', expires_in: 3600, token_type: 'bearer' };
const event = { id: eventId, name: 'Session Conference', is_active: true, start_date: '2026-11-01', end_date: '2026-11-01', badge_copies: 1 };
const settings = { endpoint: opts.configured === false ? '' : 'https://llm.example/v1/chat/completions', model: opts.configured === false ? '' : 'test-model', has_api_key: true, updated_at: null };
const summaries: Summary[] = h.stored.map((id) => ({
scope: 'session', target_id: id, event_id: eventId, session_id: id, summary: `Stored summary for ${id}`,
response_count: 1, source_fingerprint: 'old', model: 'old-model', generated_at: '2026-11-01T18:00:00Z',
}));
await page.route('**/auth/v1/**', (r) => r.fulfill({ json: new URL(r.request().url()).pathname.endsWith('/user') ? user : session }));
await page.route('**/rest/v1/**', async (route: Route) => {
const u = new URL(route.request().url());
const t = u.pathname.split('/').pop();
if (t === 'contacts') return route.fulfill({ json: u.searchParams.has('email') ? contacts[0] : contacts });
if (t === 'events') return route.fulfill({ json: u.searchParams.has('is_active') ? event : [event] });
if (t === 'sessions') return route.fulfill({ json: mkSessions() });
if (t === 'slots') return route.fulfill({ json: slots });
if (t === 'session_speakers') return route.fulfill({ json: speakers.map((s) => ({ ...s, sessions: { event_id: eventId } })) });
if (t === 'checkins') return route.fulfill({ json: checkins });
if (t === 'feedback') {
const rows = h.feedbackSessions.flatMap((id) => [
{ id: `f-${id}-1`, event_id: eventId, session_id: id, contact_email: '[email protected]', rating: 5, comment: 'Great.', created_at: '2026-11-01T17:00:00Z' },
{ id: `f-${id}-2`, event_id: eventId, session_id: id, contact_email: '[email protected]', rating: 4, comment: 'Good.', created_at: '2026-11-01T17:05:00Z' },
]);
return route.fulfill({ json: rows });
}
if (t === 'event_feedback' || t === 'points_log' || t === 'registrations' || t === 'leaderboard') return route.fulfill({ json: [] });
if (t === 'feedback_summaries') return route.fulfill({ json: summaries });
return route.fulfill({ json: [] });
});
await page.route('**/sidecar/llm-settings', (route) => route.fulfill({ json: settings }));
await page.route('**/sidecar/feedback-summary', async (route: Route) => {
expect(route.request().headers().authorization).toBe(`Bearer ${session.access_token}`);
const body = route.request().postDataJSON() as { scope: string; session_id?: string };
const id = body.session_id ?? '';
h.summaryRequests.push(id);
if (h.summaryDelayMs) await new Promise((r) => setTimeout(r, h.summaryDelayMs));
if (h.failFor.includes(id)) return route.fulfill({ status: 502, json: { error: 'LLM endpoint returned HTTP 503' } });
const summary: Summary = {
scope: 'session', target_id: id, event_id: eventId, session_id: id,
summary: `Generated summary for ${id}`, response_count: 2, source_fingerprint: 'new', model: 'test-model',
generated_at: '2026-11-01T18:30:00Z',
};
const i = summaries.findIndex((s) => s.target_id === id);
if (i >= 0) summaries.splice(i, 1);
summaries.push(summary);
return route.fulfill({ json: summary });
});
await page.goto(`${adminUrl}/auth/callback#access_token=${session.access_token}&refresh_token=r&type=magiclink`);
await expect(page.locator('.nav')).toBeVisible();
await page.locator('.nav').getByRole('button', { name: /Sessions/ }).click();
return { summaries };
}
const sessionRows = (page: Page) => page.locator('table.data tbody tr:not(.row-detail)');
test.describe('Sessions view', () => {
test.beforeEach(async ({ page }) => {
await page.setViewportSize({ width: 1440, height: 900 });
});
test('sits between Schedule and Activity and lists sessions with speakers and check-ins', async ({ page }, testInfo) => {
const h: Harness = { feedbackSessions: ['s1', 's2'], stored: [], summaryDelayMs: 0, failFor: [], summaryRequests: [] };
await openAdmin(page, h);
// The nav renders an emoji icon inside .ico, so the accessible name is
// "🎤 Sessions"; compare the label text with the icon stripped.
const clean = await page.locator('.nav').locator('.nav-item').evaluateAll((els) =>
els.map((el) => {
const ico = el.querySelector('.ico')?.textContent ?? '';
return (el.textContent ?? '').replace(ico, '').trim();
}),
);
expect(clean.indexOf('Sessions')).toBeGreaterThan(-1);
expect(clean.indexOf('Sessions')).toBe(clean.indexOf('Schedule') + 1);
expect(clean.indexOf('Activity')).toBe(clean.indexOf('Sessions') + 1);
await expect(sessionRows(page)).toHaveCount(3);
// Speakers come from session_speakers via the embedded event filter. The chip
// also holds the avatar initials, so match the chip rather than raw text.
const keynote = sessionRows(page).filter({ hasText: 'Opening Keynote' }).first();
const deepDive = sessionRows(page).filter({ hasText: 'Power Apps Deep Dive' }).first();
await expect(keynote.locator('.speaker-chip')).toHaveText(/Ann Speaker/);
await expect(deepDive.locator('.speaker-chip')).toHaveText(/Bob Other/);
await expect(sessionRows(page).filter({ hasText: 'Copilot Workshop' }).first().locator('.speaker-chip')).toHaveCount(0);
// Check-in counts per session.
await expect(page.getByTestId('generate-all-summaries')).toBeEnabled();
await expect(keynote.locator('.att-count')).toHaveText('2');
await expect(keynote.locator('.pill.amber')).toContainText('4.5★ · 2');
// s3 has no feedback at all.
const workshop = sessionRows(page).filter({ hasText: 'Copilot Workshop' }).first();
await expect(workshop).toContainText('no feedback');
await expect(workshop.locator('.att-count')).toHaveCount(0);
// Expanding a row shows the roster of who scanned in.
await keynote.click();
const detail = page.locator('tr.row-detail');
await expect(detail).toContainText('Checked in (2)');
await expect(detail.getByTestId('detail-checkin-c1')).toBeVisible();
await expect(detail.getByTestId('detail-checkin-c2')).toBeVisible();
await expect(detail.getByText('Ann Example', { exact: true })).toBeVisible();
await page.screenshot({ path: testInfo.outputPath('sessions-desktop.png'), fullPage: true });
});
test('the attendee filter narrows to the sessions that person checked into', async ({ page }) => {
const h: Harness = { feedbackSessions: ['s1', 's2'], stored: [], summaryDelayMs: 0, failFor: [], summaryRequests: [] };
await openAdmin(page, h);
await page.getByTestId('attendee-filter').selectOption('[email protected]');
await expect(sessionRows(page)).toHaveCount(2);
await expect(page.locator('.cell-session', { hasText: 'Opening Keynote' })).toBeVisible();
await expect(page.locator('.cell-session', { hasText: 'Power Apps Deep Dive' })).toBeVisible();
await expect(page.locator('.cell-session', { hasText: 'Copilot Workshop' })).toHaveCount(0);
await expect(page.getByTestId('attendee-summary')).toContainText('Ann Example attended 2 sessions');
// The expanded roster highlights exactly that person.
await sessionRows(page).filter({ hasText: 'Opening Keynote' }).first().click();
await expect(page.locator('tr.row-detail mark')).toHaveText('Ann Example');
await page.getByTestId('attendee-filter').selectOption('[email protected]');
await expect(sessionRows(page)).toHaveCount(1);
await expect(page.locator('.cell-session', { hasText: 'Opening Keynote' })).toBeVisible();
});
test('one click summarises every session with feedback, blocking the page until all finish', async ({ page }, testInfo) => {
const h: Harness = { feedbackSessions: ['s1', 's2'], stored: [], summaryDelayMs: 600, failFor: [], summaryRequests: [] };
const { summaries } = await openAdmin(page, h);
expect(summaries).toHaveLength(0);
await page.getByTestId('generate-all-summaries').click();
// UI is blocked while the run is in flight.
await expect(page.getByTestId('summary-overlay')).toBeVisible();
await expect(page.getByTestId('generate-all-summaries')).toBeDisabled();
await expect(page.getByTestId('summary-progress')).toContainText('of 2');
// Nothing else is reachable behind the overlay.
await expect(page.getByTestId('attendee-filter')).toBeDisabled();
await expect(page.getByTestId('summary-overlay')).toHaveCount(0, { timeout: 15_000 });
// Exactly one request per session that has feedback — none for s3.
expect([...h.summaryRequests].sort()).toEqual(['s1', 's2']);
await expect(page.getByTestId('summary-run-result')).toContainText('2 session summaries stored');
await expect(page.getByTestId('summary-done-s1')).toBeVisible();
await expect(page.getByTestId('summary-done-s2')).toBeVisible();
// Stored summaries are readable in the expanded row.
await sessionRows(page).filter({ hasText: 'Opening Keynote' }).first().click();
await expect(page.locator('tr.row-detail')).toContainText('Generated summary for s1');
await page.screenshot({ path: testInfo.outputPath('sessions-after-summary.png'), fullPage: true });
});
test('a failing session summary is reported and the others still land', async ({ page }) => {
const h: Harness = { feedbackSessions: ['s1', 's2'], stored: [], summaryDelayMs: 0, failFor: ['s2'], summaryRequests: [] };
await openAdmin(page, h);
await page.getByTestId('generate-all-summaries').click();
await expect(page.getByTestId('summary-run-result')).toContainText('1 session summary stored', { timeout: 15_000 });
await expect(page.getByTestId('summary-run-result')).toContainText('1 failed: Power Apps Deep Dive');
await expect(page.getByTestId('summary-done-s1')).toBeVisible();
await expect(page.getByTestId('summary-stale-s2')).toHaveCount(0);
});
test('a stale stored summary is flagged and can be regenerated', async ({ page }) => {
const h: Harness = { feedbackSessions: ['s1', 's2'], stored: ['s2'], summaryDelayMs: 0, failFor: [], summaryRequests: [] };
await openAdmin(page, h);
// s2's stored summary was built from 1 response; there are 2 now.
await expect(page.getByTestId('summary-stale-s2')).toBeVisible();
await expect(page.getByTestId('summary-done-s2')).toHaveCount(0);
await expect(page.getByTestId('generate-all-summaries')).toBeEnabled();
});
test('the button is disabled when no session has any feedback', async ({ page }) => {
const h: Harness = { feedbackSessions: [], stored: [], summaryDelayMs: 0, failFor: [], summaryRequests: [] };
await openAdmin(page, h);
await expect(page.getByTestId('generate-all-summaries')).toBeDisabled();
await expect(page.locator('table.data tbody')).toContainText('no feedback');
});
test('without a configured LLM the button is disabled and says why', async ({ page }) => {
const h: Harness = { feedbackSessions: ['s1'], stored: [], summaryDelayMs: 0, failFor: [], summaryRequests: [] };
await openAdmin(page, h, { configured: false });
await expect(page.getByTestId('sessions-llm-unconfigured')).toBeVisible();
await expect(page.getByTestId('generate-all-summaries')).toBeDisabled();
});
test('the table fits a mobile viewport without horizontal overflow', async ({ page }, testInfo) => {
await page.setViewportSize({ width: 390, height: 844 });
const h: Harness = { feedbackSessions: ['s1'], stored: [], summaryDelayMs: 0, failFor: [], summaryRequests: [] };
await openAdmin(page, h);
await expect(page.getByTestId('sessions-toolbar')).toBeVisible();
await expect(page.getByTestId('generate-all-summaries')).toBeVisible();
await page.screenshot({ path: testInfo.outputPath('sessions-mobile.png'), fullPage: true });
});
});