feat(generation): enforce prompt budget with whole article eviction (#47)

This commit is contained in:
2026-11-25 11:47:23 +01:00
parent 3983e49ff8
commit c5b8d0d4da
31 changed files with 882 additions and 296 deletions

View File

@ -16,7 +16,7 @@ test('ticket #27: resumes a running job after leaving Dashboard without a second
const outcome = {
id: 'outcome-27', status: 'succeeded', language: 'fr', ranking_mode: 'title',
total_candidates: 3, laya_selected: 2, selected: 2, global_limit: 10,
content_fallbacks: 0, source_stats: [],
content_fallbacks: 0, source_stats: [], articles_removed_for_prompt_budget: 1,
}
let job = null
let posts = 0
@ -51,13 +51,23 @@ test('ticket #27: resumes a running job after leaving Dashboard without a second
if (path === '/api/summaries/generations') {
if (job?.status === 'succeeded') {
completedHistoryReads++
return respond([{ id: outcome.id, summary_id: summary.id, outcome, created_at: summary.generated_at }])
return respond([
{ id: outcome.id, summary_id: summary.id, outcome, created_at: summary.generated_at },
{ id: 'outcome-before-27', summary_id: previous.id, outcome: { ...outcome, id: 'outcome-before-27', articles_removed_for_prompt_budget: 2 }, created_at: previous.generated_at },
])
}
return respond([])
}
return route.continue()
})
const expectNoDiagnostics = async () => {
await expect(page.getByRole('region', { name: 'Bilan de la génération' })).toHaveCount(0)
await expect(page.getByText(/Prochaine synthèse|Budget souhaité|Budget effectif|Réserve de sortie|Détails de la génération|articles examinés|Contenus complets/)).toHaveCount(0)
await expect(page.getByLabel('Indices actuellement suivis')).toHaveCount(0)
await expect(page.getByText('Entreprise test', { exact: true })).toHaveCount(0)
}
await test.step('start one generation and keep the mocked job running', async () => {
await page.goto(new URL('/login', stack.frontendUrl).href)
await page.getByLabel('Adresse email').fill(stack.bootstrapAdmin.email)
@ -65,6 +75,7 @@ test('ticket #27: resumes a running job after leaving Dashboard without a second
await page.getByRole('button', { name: 'Se connecter' }).click()
await expect(page).toHaveURL(new URL('/', stack.frontendUrl).href)
await expect(page.getByText(previous.content, { exact: true })).toBeVisible()
await expectNoDiagnostics()
await page.getByRole('button', { name: 'Générer une synthèse', exact: true }).click()
await expect(page.getByRole('status').filter({ hasText: 'Synthèse en cours.' })).toBeVisible()
expect(posts).toBe(1)
@ -74,6 +85,8 @@ test('ticket #27: resumes a running job after leaving Dashboard without a second
await page.getByRole('link', { name: 'Mes préférences', exact: true }).filter({ visible: true }).click()
await expect(page).toHaveURL(new URL('/preferences', stack.frontendUrl).href)
await expect(page.getByRole('heading', { name: 'Mes préférences', exact: true })).toBeVisible()
await expect(page.getByLabel('Modèle de synthèse', { exact: true })).toHaveValue('model-27')
await expect(page.getByText(/Budget effectif|Réserve de sortie|Capacité du modèle/)).toHaveCount(0)
await expect(page.getByText('Synthèse en cours. Le traitement peut prendre plusieurs minutes.', { exact: true })).toHaveCount(0)
const readsBeforeReturn = recentReads
await page.getByRole('link', { name: 'Synthèses', exact: true }).filter({ visible: true }).click()
@ -84,6 +97,7 @@ test('ticket #27: resumes a running job after leaving Dashboard without a second
const generate = page.getByRole('button', { name: 'Génération en cours', exact: true })
await expect(generate).toBeDisabled()
await expect(page.getByText(previous.content, { exact: true })).toBeVisible()
await expectNoDiagnostics()
// Observe an actual polling request while the job remains active.
const readsBeforePoll = jobReads
await expect.poll(() => jobReads, { timeout: 10_000 }).toBeGreaterThan(readsBeforePoll)
@ -97,9 +111,15 @@ test('ticket #27: resumes a running job after leaving Dashboard without a second
await expect(page.getByText(summary.content, { exact: true })).toBeVisible()
await expect(page.getByRole('status').filter({ hasText: 'Synthèse en cours.' })).toHaveCount(0)
await expect(page.getByRole('button', { name: 'Générer une synthèse', exact: true })).toBeEnabled()
await expect(page.getByRole('region', { name: 'Bilan de la génération' })).toContainText('3 articles examinés')
await expectNoDiagnostics()
await expect(page.getByText('1 article ancien a été retiré pour respecter le plafond du prompt.', { exact: true })).toBeVisible()
await expect(page.getByRole('heading', { name: 'Historique', exact: true })).toBeVisible()
await expect(page.getByRole('button', { name: `${previous.content}…`, exact: true })).toBeVisible()
await expect(page.getByText('2 articles parmi les plus anciens ont été retirés pour respecter le plafond du prompt.', { exact: true })).toBeVisible()
await page.getByRole('button', { name: `${previous.content}…`, exact: true }).click()
await expect(page.getByText(previous.content, { exact: true })).toBeVisible()
await expect(page.getByText('2 articles parmi les plus anciens ont été retirés pour respecter le plafond du prompt.', { exact: true })).toHaveCount(2)
await expectNoDiagnostics()
expect(completedListReads).toBeGreaterThan(0)
expect(completedHistoryReads).toBeGreaterThan(0)
expect(posts).toBe(1)