feat: add manual feedback AI summaries and secure leaderboard scoring
Co-authored-by: Stephan Charles <[email protected]> Co-authored-by: Amelia Hernandez <[email protected]> Co-authored-by: Markus Franz <[email protected]> Co-authored-by: Sabrina Hota <[email protected]> Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
1 parent
407b878e23
commit
821907b164
37 files changed
+1640
-77
No files matched your search
@@ -0,0 +1,42 @@
|
||||
const { test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { validateSettings, generateSummary } = require('../src/feedback-summary');
|
||||
const settings = { endpoint: 'https://llm.example/v1/chat/completions', model: 'test-model', api_key: 'test-secret' };
|
||||
|
||||
test('validates endpoint, model and credential input', () => {
|
||||
assert.equal(validateSettings(settings).model, 'test-model');
|
||||
for (const endpoint of ['http://localhost:11434', 'https://user:[email protected]', 'https://example.com/?key=secret', 'file:///etc/passwd']) {
|
||||
assert.throws(() => validateSettings({ ...settings, endpoint }));
|
||||
}
|
||||
assert.throws(() => validateSettings({ ...settings, model: '' }));
|
||||
assert.throws(() => validateSettings({ ...settings, api_key: 'secret\r\nHeader: value' }));
|
||||
});
|
||||
|
||||
test('does not call LLM without feedback', async () => {
|
||||
await assert.rejects(generateSummary(settings, { feedback: [] }, () => { throw new Error('Must not call'); }), /No feedback/);
|
||||
});
|
||||
|
||||
test('sends only ratings and comments and reads OpenAI-compatible output', async () => {
|
||||
const result = await generateSummary(settings, {
|
||||
scope: 'session', title: 'Session', feedback: [{ rating: 5, comment: 'Useful', contact_email: '[email protected]', id: 'private-id' }],
|
||||
}, async (url, options) => {
|
||||
assert.equal(url, settings.endpoint);
|
||||
assert.equal(options.redirect, 'error');
|
||||
assert.equal(options.headers.Authorization, 'Bearer test-secret');
|
||||
const request = JSON.parse(options.body);
|
||||
assert.equal(request.model, 'test-model');
|
||||
assert.ok(!options.body.includes('[email protected]'));
|
||||
assert.ok(!options.body.includes('private-id'));
|
||||
assert.deepEqual(JSON.parse(request.messages[1].content).responses, [{ rating: 5, comment: 'Useful' }]);
|
||||
return new Response(JSON.stringify({ choices: [{ message: { content: ' Useful session. ' } }] }));
|
||||
});
|
||||
assert.equal(result, 'Useful session.');
|
||||
});
|
||||
|
||||
test('rejects provider errors, malformed output and oversized inputs', async () => {
|
||||
const input = { scope: 'event', title: 'Event', feedback: [{ rating: 3 }] };
|
||||
await assert.rejects(generateSummary(settings, input, async () => new Response('secret error', { status: 401 })), /HTTP 401/);
|
||||
await assert.rejects(generateSummary(settings, input, async () => new Response('not JSON')), /invalid JSON/);
|
||||
await assert.rejects(generateSummary(settings, input, async () => new Response('{}')), /invalid summary/);
|
||||
await assert.rejects(generateSummary(settings, { ...input, feedback: [{ rating: 1, comment: 'x'.repeat(200001) }] }), /200 KB/);
|
||||
});
|
||||
Reference in new issue
Block a user