feat(generation): score articles with selected relevance model (#48)
This commit is contained in:
@ -113,6 +113,12 @@ describe('Dashboard — génération de synthèses éphémères', () => {
|
||||
createReport.mockResolvedValue({ id: 'report-1' })
|
||||
})
|
||||
|
||||
it.each(['ranking_model_unavailable', 'ranking_model_incompatible'])('guide vers les préférences pour %s', async (failure_code) => {
|
||||
generationStatus.mockResolvedValueOnce({ id: 'failed', status: 'failed', failure_code })
|
||||
renderDashboard()
|
||||
expect(await screen.findByRole('alert')).toHaveTextContent(/modèle.*classement/)
|
||||
expect(screen.getByRole('link', { name: 'Mes préférences' })).toHaveAttribute('href', '/preferences')
|
||||
})
|
||||
it('retire les diagnostics et les badges des résultats récents et historiques', async () => {
|
||||
listSummaries.mockResolvedValue([generatedSummary, previousSummary])
|
||||
listGenerations.mockResolvedValue([{ summary_id: generatedSummary.id, outcome: outcome('succeeded') }, { summary_id: previousSummary.id, outcome: outcome('partial') }])
|
||||
|
||||
@ -8,8 +8,8 @@ afterEach(() => {
|
||||
|
||||
it('charge et sauvegarde les préférences du compte via GET et PUT /api/me/preferences', async () => {
|
||||
localStorage.setItem('token', 'user-token')
|
||||
const initial = { language: 'fr', ranking_mode: 'title', summary_prompt_token_budget: 250000 }
|
||||
const updated = { language: 'en' as const, ranking_mode: 'title_content' as const, summary_prompt_token_budget: 80000 }
|
||||
const initial = { language: 'fr', ranking_mode: 'title', summary_prompt_token_budget: 250000, ranking_model_id: null }
|
||||
const updated = { language: 'en' as const, ranking_mode: 'title_content' as const, summary_prompt_token_budget: 80000, ranking_model_id: 'ranking-model' }
|
||||
const fetchMock = vi.fn()
|
||||
.mockResolvedValueOnce(new Response(JSON.stringify({ data: initial }), { status: 200 }))
|
||||
.mockResolvedValueOnce(new Response(JSON.stringify({ data: updated }), { status: 200 }))
|
||||
@ -22,3 +22,13 @@ it('charge et sauvegarde les préférences du compte via GET et PUT /api/me/pref
|
||||
method: 'PUT', headers, body: JSON.stringify(updated),
|
||||
})
|
||||
})
|
||||
|
||||
it('charge le catalogue ranking via son rôle sans changer le catalogue synthèse', async () => {
|
||||
const fetchMock = vi.fn().mockImplementation(async () => new Response(JSON.stringify({ data: [] }), { status: 200 }))
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
const ranking = (preferencesApi as unknown as { listRankingModels: () => Promise<unknown> }).listRankingModels
|
||||
expect(ranking).toBeTypeOf('function')
|
||||
await ranking()
|
||||
await preferencesApi.listSummaryModels()
|
||||
expect(fetchMock.mock.calls.map(call => call[0])).toEqual(['/api/me/summary-models?role=ranking', '/api/me/summary-models'])
|
||||
})
|
||||
|
||||
@ -1,20 +1,23 @@
|
||||
import { cleanup, render, screen, waitFor } from '@testing-library/react'
|
||||
import { cleanup, render, screen, waitFor, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { ComponentType } from 'react'
|
||||
import { ApiError } from '../src/api/client'
|
||||
import { Preferences } from '../src/pages/Preferences'
|
||||
import { MemoryRouter } from 'react-router-dom'
|
||||
import { Sidebar } from '../src/components/layout/Sidebar'
|
||||
import { MobileNav } from '../src/components/layout/MobileNav'
|
||||
import { router } from '../src/lib/router'
|
||||
|
||||
const { getPreferences, updatePreferences } = vi.hoisted(() => ({
|
||||
const { getPreferences, updatePreferences, listModels, listRankingModels } = vi.hoisted(() => ({
|
||||
listModels: vi.fn(),
|
||||
listRankingModels: vi.fn(),
|
||||
getPreferences: vi.fn(),
|
||||
updatePreferences: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/api/preferences', () => ({
|
||||
preferencesApi: { get: getPreferences, update: updatePreferences, listSummaryModels: vi.fn().mockResolvedValue([{ id: 'model-a', provider: 'OpenAI', model: 'summary' }]) },
|
||||
preferencesApi: { get: getPreferences, update: updatePreferences, listSummaryModels: listModels, listRankingModels },
|
||||
}))
|
||||
|
||||
function containsPreferencesRoute(routes: typeof router.routes): boolean {
|
||||
@ -29,10 +32,54 @@ vi.mock('@/lib/theme', () => ({ useTheme: () => ({ theme: 'light', setTheme: vi.
|
||||
describe('Mes préférences', () => {
|
||||
afterEach(cleanup)
|
||||
beforeEach(() => {
|
||||
listRankingModels.mockResolvedValue([{ id: 'model-a', provider: 'OpenAI', model: 'summary' }])
|
||||
listModels.mockResolvedValue([{ id: 'model-a', provider: 'OpenAI', model: 'summary' }])
|
||||
getPreferences.mockResolvedValue({ language: 'fr', ranking_mode: 'title' })
|
||||
updatePreferences.mockResolvedValue({ language: 'en', ranking_mode: 'title_content' })
|
||||
})
|
||||
|
||||
it('réserve le catalogue compatible au classement et garde le catalogue complet pour la synthèse', async () => {
|
||||
listModels.mockResolvedValueOnce([{ id: 'summary-only', provider: 'Other', model: 'summary-only' }])
|
||||
render(<Preferences />)
|
||||
const summary = await screen.findByLabelText('Modèle de synthèse')
|
||||
const ranking = screen.getByLabelText('Modèle de classement de pertinence')
|
||||
expect(within(summary).getByRole('option', { name: 'Other · summary-only' })).toBeInTheDocument()
|
||||
expect(within(ranking).queryByRole('option', { name: 'Other · summary-only' })).not.toBeInTheDocument()
|
||||
expect(within(ranking).getByRole('option', { name: 'OpenAI · summary' })).toBeInTheDocument()
|
||||
})
|
||||
it('explique un refus de compatibilité et conserve le choix', async () => {
|
||||
updatePreferences.mockRejectedValueOnce(new ApiError('ranking_model_incompatible', 400))
|
||||
render(<Preferences />)
|
||||
const ranking = await screen.findByLabelText('Modèle de classement de pertinence')
|
||||
const user = userEvent.setup()
|
||||
await user.selectOptions(ranking, 'model-a')
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer' }))
|
||||
expect(await screen.findByRole('alert')).toHaveTextContent('incompatible avec le classement')
|
||||
expect(ranking).toHaveValue('model-a')
|
||||
})
|
||||
it('sépare le classement sans choix automatique et sauvegarde indépendamment', async () => {
|
||||
getPreferences.mockResolvedValueOnce({ language: 'fr', ranking_mode: 'title', summary_model_id: 'model-a', ranking_model_id: null })
|
||||
render(<Preferences />)
|
||||
const ranking = await screen.findByLabelText('Modèle de classement de pertinence')
|
||||
expect(ranking).toHaveValue('')
|
||||
expect(ranking).toHaveAccessibleDescription(/titre.*tous les articles.*sans filtrage.*pertinence décroissante.*date/i)
|
||||
const user = userEvent.setup()
|
||||
await user.selectOptions(ranking, 'model-a')
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer' }))
|
||||
expect(updatePreferences).toHaveBeenLastCalledWith(expect.objectContaining({ summary_model_id: 'model-a', ranking_model_id: 'model-a' }))
|
||||
})
|
||||
it('signale une sélection de classement indisponible sans la remplacer', async () => {
|
||||
getPreferences.mockResolvedValueOnce({ language: 'fr', ranking_mode: 'title', ranking_model_id: 'removed' })
|
||||
render(<Preferences />)
|
||||
expect(await screen.findByLabelText('Modèle de classement de pertinence')).toHaveValue('removed')
|
||||
expect(screen.getByRole('alert')).toHaveTextContent('Le modèle de classement sélectionné n’est plus disponible.')
|
||||
})
|
||||
it('explique le catalogue vide et garde le classement sans sélection', async () => {
|
||||
listRankingModels.mockResolvedValueOnce([])
|
||||
render(<Preferences />)
|
||||
expect(await screen.findByLabelText('Modèle de classement de pertinence')).toHaveValue('')
|
||||
expect(screen.getByText('Aucun modèle de classement disponible. Contactez votre administrateur.')).toBeInTheDocument()
|
||||
})
|
||||
it('est accessible par une route dédiée', () => {
|
||||
expect(containsPreferencesRoute(router.routes)).toBe(true)
|
||||
})
|
||||
|
||||
@ -7,7 +7,7 @@ import { GenerationDetails } from '../src/components/GenerationDetails'
|
||||
import type { GenerationOutcome } from '../src/api/summaries'
|
||||
|
||||
const { get, update, listSummaryModels } = vi.hoisted(() => ({ get: vi.fn(), update: vi.fn(), listSummaryModels: vi.fn() }))
|
||||
vi.mock('@/api/preferences', () => ({ preferencesApi: { get, update, listSummaryModels } }))
|
||||
vi.mock('@/api/preferences', () => ({ preferencesApi: { listRankingModels: vi.fn().mockResolvedValue([]), get, update, listSummaryModels } }))
|
||||
vi.mock('@/components/Appearance', () => ({ Appearance: () => null }))
|
||||
const profile = { context_window_tokens: 128000, input_limit_tokens: 128000, output_reserve_tokens: 4096, framing_tokens: 1024, token_count_method: 'utf8_bytes_upper_bound_v1' }
|
||||
const preferences = { language: 'fr', ranking_mode: 'title_content', summary_model_id: 'a', summary_prompt_token_budget: 250000 }
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { cleanup, render, screen } from '@testing-library/react'
|
||||
import { cleanup, render, screen, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { Preferences } from '../src/pages/Preferences'
|
||||
@ -11,7 +11,7 @@ const { getPreferences, updatePreferences, listSummaryModels, listSummaries, lis
|
||||
listReports: vi.fn(), listMessages: vi.fn(), deleteReport: vi.fn(), createMessage: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/api/preferences', () => ({ preferencesApi: { get: getPreferences, update: updatePreferences, listSummaryModels } }))
|
||||
vi.mock('@/api/preferences', () => ({ preferencesApi: { listRankingModels: vi.fn().mockResolvedValue([]), get: getPreferences, update: updatePreferences, listSummaryModels } }))
|
||||
vi.mock('@/api/summaries', () => ({ summariesApi: { list: listSummaries, generations: listGenerations, recentJob: status, getJob: status, generate: vi.fn() } }))
|
||||
vi.mock('@/api/assets', () => ({ assetsApi: { list: listAssets } }))
|
||||
vi.mock('@/api/reports', () => ({ reportsApi: { list: listReports, listMessages, delete: deleteReport, createMessage } }))
|
||||
@ -45,8 +45,8 @@ describe('choix personnel du modèle de synthèse — ticket #14', () => {
|
||||
render(<Preferences />)
|
||||
const selector = await screen.findByLabelText(/modèle de synthèse/i)
|
||||
expect(selector).toHaveValue('model-a')
|
||||
expect(screen.getByRole('option', { name: 'OpenAI · gpt-summary' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('option', { name: 'Ollama · qwen-summary' })).toBeInTheDocument()
|
||||
expect(within(selector).getByRole('option', { name: 'OpenAI · gpt-summary' })).toBeInTheDocument()
|
||||
expect(within(selector).getByRole('option', { name: 'Ollama · qwen-summary' })).toBeInTheDocument()
|
||||
await user.selectOptions(selector, 'model-b')
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer' }))
|
||||
expect(updatePreferences).toHaveBeenCalledWith({ language: 'fr', ranking_mode: 'title_content', summary_model_id: 'model-b', summary_prompt_token_budget: 250000 })
|
||||
|
||||
Reference in New Issue
Block a user