Summarise this report on every report (2.0.1)

The eight reports that list people get the AI summary too, sent as
anonymised totals built on the screen (aiReportData.ts): no names,
contact details, notes or comments; consent and medical only as counts.
The server refuses personal columns on those reports and logs each
summary in the access log (ai_report; sensitive for consent and medical).

Roadmap §18: 2.0.1, then crosscode.co.za, then 2.1.0 (AI helpers on the
Consent log and Access log).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-02 18:42:27 +02:00
co-authored by Claude Opus 5.5
parent 8d7269a1e2
commit 40fa8b2dba
20 changed files with 359 additions and 48 deletions
+10 -2
View File
@@ -79,10 +79,18 @@ describe('what the helpers send', () => {
expect(r.warnings.some(w => w.includes('R7 800 short'))).toBe(true);
});
test('summarise a report: only reports without people', async () => {
await expect(summariseReport('u1', { reportKey: 'payments', title: 'Payments', columns: ['User'], rows: [['Jane']] })).rejects.toMatchObject({ reason: 'AI_REPORT_HAS_PEOPLE' });
test('summarise a report: people reports only as anonymised totals', async () => {
for (const columns of [['Event', 'User', 'Amount'], ['Event', 'Email'], ['Event', 'Performed by', 'Notes'], ['Event', 'Attendee', 'Medical'], ['Parent / guardian']]) {
await expect(summariseReport('u1', { reportKey: 'payments', title: 'Payments', columns, rows: [['Jane']] })).rejects.toMatchObject({ reason: 'AI_REPORT_HAS_PEOPLE' });
}
await expect(summariseReport('u1', { reportKey: 'nope', title: 'X', columns: ['A'], rows: [[1]] })).rejects.toMatchObject({ code: 'VALIDATION_FAILED' });
expect(mockRun).not.toHaveBeenCalled();
mockRun.mockResolvedValue({ output: { headline: 'h', insights: [], watchOut: [] }, status });
await summariseReport('u1', { reportKey: 'medicalList', title: 'Medical', columns: ['Event', 'Attendees', 'With allergies', 'With medical aid'], rows: [['Camp', 40, 6, 30]] }, now);
await summariseReport('u1', { reportKey: 'feedbackSummary', title: 'Feedback', columns: ['Event', 'Question', 'Answered', 'Result'], rows: [['Camp', 'Overall', 12, '4.5 / 5']] }, now);
expect(mockRun).toHaveBeenCalledTimes(2);
mockRun.mockReset();
mockRun.mockResolvedValue({ output: { headline: 'h', insights: [], watchOut: [] }, status });
await summariseReport('u1', { reportKey: 'revenue', title: 'Revenue Summary', stats: [{ label: 'Total', value: 'R66 550' }], columns: ['Event', 'Amount'], rows: [['Camp', 'R16 650']] }, now);
expect(mockRun.mock.calls[0][2].input).toBe('Report: Revenue Summary\nTotal: R66 550\nColumns: Event | Amount\nCamp | R16 650');
});
+15 -2
View File
@@ -700,13 +700,26 @@ describe('AI helpers (2.0)', () => {
expect(mockRunHelper.mock.calls[0][0]).toBe('improve_text');
});
test('summarise a report: reports with people in them are refused by validation', async () => {
test('summarise a report: unknown reports fail validation, people columns are refused', async () => {
signedIn = { id: 's1', role: 'supervisor' };
expect((await request(app).post('/api/v2/ai/summarise-report').send({ reportKey: 'nope', title: 'X', columns: ['A'], rows: [[1]] })).status).toBe(400);
const res = await request(app).post('/api/v2/ai/summarise-report').send({ reportKey: 'payments', title: 'Payments', columns: ['User'], rows: [['Jane']] });
expect(res.status).toBe(400);
expect(res.status).toBe(403);
expect(res.body.error.reason).toBe('AI_REPORT_HAS_PEOPLE');
expect(mockRunHelper).not.toHaveBeenCalled();
});
test('summarise a report: a people report as totals, with an access-log entry (sensitive for medical)', async () => {
signedIn = { id: 's1', role: 'supervisor' };
mockRunHelper.mockResolvedValue({ output: { headline: 'h', insights: [], watchOut: [] }, status: st });
const res = await request(app).post('/api/v2/ai/summarise-report').send({ reportKey: 'medicalList', title: 'Medical & emergency list', columns: ['Event', 'Attendees', 'With allergies'], rows: [['Camp', 40, 6]] });
expect(res.status).toBe(200);
expect(mockAccessLog).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({ action: 'ai_report', records: 1, sensitive: true }));
mockAccessLog.mockClear();
await request(app).post('/api/v2/ai/summarise-report').send({ reportKey: 'revenue', title: 'Revenue', columns: ['Event', 'Amount'], rows: [['Camp', 100]] });
expect(mockAccessLog).not.toHaveBeenCalled();
});
test('draft an event: the draft with warnings worked out in code', async () => {
signedIn = { id: 's1', role: 'supervisor' };
const draft = {