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]>
42 lines
2.5 KiB
JavaScript
42 lines
2.5 KiB
JavaScript
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/);
|
|
}); |