feat(sources): replace WatcherGuru with CNBC Business

Add the CNBC Business RSS source, switch supported-source wiring and reporting, and migrate existing WatcherGuru rows to disabled historical status without rewriting references.

Refs #23

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 17:17:15 +01:00
parent 1ff78a7b31
commit 64a7124889
18 changed files with 511 additions and 26 deletions

View File

@ -1,7 +1,11 @@
import type { GenerationOutcome } from '@/api/summaries'
function sourceLabel(type: string) {
return type === 'cnbc_business' ? 'CNBC Business' : type
}
export function GenerationDetails({ outcome }: { outcome: GenerationOutcome }) {
const unavailable = outcome.source_stats.filter(source => source.status === 'failed').map(source => source.source_type)
const unavailable = outcome.source_stats.filter(source => source.status === 'failed').map(source => sourceLabel(source.source_type))
return (
<section className="space-y-3" aria-label="Bilan de la génération">
{outcome.status === 'partial' && (
@ -23,7 +27,7 @@ export function GenerationDetails({ outcome }: { outcome: GenerationOutcome }) {
<thead><tr><th scope="col">Source</th><th scope="col">État</th><th scope="col">Examinés</th><th scope="col">Sélectionnés par Laya</th><th scope="col">Retenus</th><th scope="col">Plafond</th></tr></thead>
<tbody>{outcome.source_stats.map(source => (
<tr key={source.source_id}>
<th scope="row">{source.source_type}</th>
<th scope="row">{sourceLabel(source.source_type)}</th>
<td>{source.status === 'failed' ? 'Indisponible' : 'Disponible'}</td>
<td>{source.candidates}</td><td>{source.laya_selected}</td><td>{source.selected}</td><td>{source.article_limit}</td>
</tr>

View File

@ -5,7 +5,7 @@ import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Button } from '@/components/ui/button'
const SOURCE_KEYS = new Set(['yahoo_finance', 'bloomberg', 'watcher_guru'])
const SOURCE_KEYS = new Set(['yahoo_finance', 'bloomberg', 'cnbc_business'])
function isSupported(source: Source) {
return source.supported === true && source.source_key !== null && SOURCE_KEYS.has(source.source_key)
@ -105,7 +105,7 @@ export function Sources() {
return (
<div className="space-y-6">
<h1 className="text-2xl font-bold">Sources et plafonds</h1>
<p className="text-sm text-muted-foreground">Seules Yahoo Finance, Bloomberg et Watcher Guru peuvent participer aux synthèses manuelles et planifiées. Seules les sources activées sont utilisées, dans la limite de leurs plafonds. Modifier ces réglages ne lance aucune récupération d’articles ni génération immédiate.</p>
<p className="text-sm text-muted-foreground">Seules Yahoo Finance, Bloomberg et CNBC Business peuvent participer aux synthèses manuelles et planifiées. Seules les sources activées sont utilisées, dans la limite de leurs plafonds. Modifier ces réglages ne lance aucune récupération d’articles ni génération immédiate.</p>
{loading ? <p role="status">Chargement des sources et plafonds…</p> : loadError ? (
<div className="space-y-3"><p role="alert">{loadError}</p><Button onClick={() => void load()}>Réessayer</Button></div>
) : <>
@ -124,7 +124,7 @@ export function Sources() {
</Card>
{sources.length === 0 && <p>Aucune source disponible.</p>}
<div className="grid min-w-0 gap-4 lg:grid-cols-3">
{supported.map(source => <SourceLimit key={source.id} source={source.source_key === 'yahoo_finance' ? { ...source, name: 'Yahoo Finance' } : source} />)}
{supported.map(source => <SourceLimit key={source.id} source={source.source_key === 'yahoo_finance' ? { ...source, name: 'Yahoo Finance' } : source.source_key === 'cnbc_business' ? { ...source, name: 'CNBC Business' } : source} />)}
</div>
{historical.length > 0 && <section aria-labelledby="historical-sources-title" className="space-y-3">
<h2 id="historical-sources-title" className="text-lg font-semibold">Anciennes sources exclues</h2>

View File

@ -149,22 +149,25 @@ describe('plafonds d’articles administrateur', () => {
expect(updateSource).not.toHaveBeenCalled()
})
it('ne rend activables que Yahoo, Bloomberg et Watcher Guru; garde StockTwits et Reuters en historique sans commandes', async () => {
it('ne rend activables que Yahoo, Bloomberg et CNBC Business; garde Watcher Guru, StockTwits et Reuters en historique sans commandes', async () => {
listSources.mockResolvedValue([
{ id: 'y', name: 'Yahoo Finance', type: 'stocktwits', source_key: 'yahoo_finance', supported: true, operational: true, enabled: true, article_limit: 83 },
{ id: 'b', name: 'Bloomberg', type: 'bloomberg', source_key: 'bloomberg', supported: true, operational: true, enabled: false, article_limit: 77 },
{ id: 'w', name: 'Watcher.Guru', type: 'watcherguru', source_key: 'watcher_guru', supported: true, operational: true, enabled: true, article_limit: 64 },
{ id: 'c', name: 'CNBC Business', type: 'cnbc_business', source_key: 'cnbc_business', supported: true, operational: true, enabled: true, article_limit: 20 },
{ id: 'w', name: 'Watcher.Guru', type: 'watcherguru', source_key: 'watcher_guru', supported: false, operational: false, enabled: false, article_limit: 64 },
{ id: 's', name: 'StockTwits', type: 'stocktwits', source_key: null, supported: false, operational: false, enabled: false, article_limit: 31 },
{ id: 'r', name: 'Reuters', type: 'reuters', source_key: null, supported: false, operational: false, enabled: false, article_limit: 42 },
])
render(<Sources />)
expect(await screen.findByRole('heading', { name: 'Anciennes sources exclues' })).toBeInTheDocument()
for (const name of ['Yahoo Finance', 'Bloomberg', 'Watcher.Guru']) {
for (const name of ['Yahoo Finance', 'Bloomberg', 'CNBC Business']) {
expect(screen.getByRole('button', { name: new RegExp(`^(?:Activer|Désactiver) ${name}$`) })).toBeInTheDocument()
expect(screen.getByLabelText(`Plafond ${name}`)).toBeInTheDocument()
}
const historical = screen.getByRole('region', { name: 'Anciennes sources exclues' })
expect(within(historical).getByText('StockTwits')).toBeInTheDocument()
expect(within(historical).getByText('Watcher.Guru')).toBeInTheDocument()
expect(within(historical).getByText('Exclue des synthèses · Plafond historique : 64')).toBeInTheDocument()
expect(within(historical).getByText('Reuters')).toBeInTheDocument()
expect(within(historical).queryByRole('button')).not.toBeInTheDocument()
expect(within(historical).queryByRole('spinbutton')).not.toBeInTheDocument()
@ -173,7 +176,8 @@ describe('plafonds d’articles administrateur', () => {
expect(within(yahooCard as HTMLElement).queryByText(/stocktwits/i)).not.toBeInTheDocument()
expect(screen.getByLabelText('Plafond Yahoo Finance')).toHaveValue(83)
expect(screen.getByLabelText('Plafond Bloomberg')).toHaveValue(77)
expect(screen.getByLabelText('Plafond Watcher.Guru')).toHaveValue(64)
expect(screen.getByLabelText('Plafond CNBC Business')).toHaveValue(20)
expect(screen.queryByLabelText('Plafond Watcher.Guru')).not.toBeInTheDocument()
})
it('garde les anciennes sources repliées et en lecture seule même si enabled est historique', async () => {
@ -220,4 +224,27 @@ describe('plafonds d’articles administrateur', () => {
expect(await screen.findByLabelText('Plafond Yahoo Finance')).toHaveValue(240)
})
it('sauvegarde le plafond CNBC et refuse toute commande Watcher Guru même avec un ancien DTO activable', async () => {
listSources.mockResolvedValue([
{ id: 'cnbc-new', name: 'CNBC Business', type: 'cnbc_business', source_key: 'cnbc_business', supported: true, operational: true, enabled: true, article_limit: 37 },
{ id: 'watcher-old', name: 'Watcher.Guru', type: 'watcherguru', source_key: 'watcher_guru', supported: true, operational: true, enabled: true, article_limit: 64 },
])
const user = userEvent.setup()
render(<Sources />)
const cap = await screen.findByLabelText('Plafond CNBC Business')
expect(cap).toHaveValue(37)
expect(screen.queryByRole('button', { name: /^(Activer|Désactiver) Watcher/ })).not.toBeInTheDocument()
const historical = screen.getByRole('region', { name: 'Anciennes sources exclues' })
expect(within(historical).getByText('Watcher.Guru')).toBeInTheDocument()
expect(within(historical).queryByRole('spinbutton')).not.toBeInTheDocument()
expect(within(historical).queryByRole('button')).not.toBeInTheDocument()
await user.clear(cap)
await user.type(cap, '42')
await user.click(screen.getByRole('button', { name: 'Enregistrer le plafond CNBC Business' }))
await waitFor(() => expect(updateSource).toHaveBeenCalledWith('cnbc-new', true, 42))
expect(updateSource).toHaveBeenCalledTimes(1)
expect(await screen.findByRole('status')).toHaveTextContent('Plafond CNBC Business enregistré pour les prochaines synthèses.')
expect(screen.getByText(/Seules Yahoo Finance, Bloomberg et CNBC Business/)).toBeInTheDocument()
})
})

View File

@ -0,0 +1,33 @@
import { cleanup, render, screen, within } from '@testing-library/react'
import { afterEach, expect, it } from 'vitest'
import { GenerationDetails } from '../src/components/GenerationDetails'
import type { GenerationOutcome } from '../src/api/summaries'
afterEach(cleanup)
function outcome(sourceType: string): GenerationOutcome {
return {
id: 'generation-23', status: 'partial', language: 'fr', ranking_mode: 'title',
total_candidates: 0, content_fallbacks: 0, laya_selected: 0, selected: 0, global_limit: 50,
source_stats: [{ source_id: 'source-23', source_type: sourceType, status: 'failed', candidates: 0, laya_selected: 0, selected: 0, article_limit: 20, content_fallbacks: 0, failure_code: 'source_unavailable' }],
}
}
it('nomme CNBC Business dans le diagnostic agrégé sans exposer de détails de récupération', () => {
const result = outcome('cnbc_business')
render(<GenerationDetails outcome={result} />)
expect(screen.getByText('Cette synthèse a été générée sans CNBC Business, indisponible lors du traitement.')).toBeInTheDocument()
const row = screen.getByText('CNBC Business').closest('tr')!
expect(within(row).getByText('Indisponible')).toBeInTheDocument()
expect(screen.queryByText('source_unavailable')).not.toBeInTheDocument()
expect(screen.queryByRole('link')).not.toBeInTheDocument()
})
it.each(['watcherguru', 'Watcher.Guru', 'Watcher Guru'])('garde le bilan historique %s sans réécrire son identité', sourceType => {
const result = outcome(sourceType)
const before = JSON.stringify(result)
render(<GenerationDetails outcome={result} />)
expect(screen.getByText(sourceType, { exact: true })).toBeInTheDocument()
expect(screen.queryByText(/CNBC Business/)).not.toBeInTheDocument()
expect(JSON.stringify(result)).toBe(before)
})