feat(generation): score articles with selected relevance model (#48)
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
|
||||
The supervisor requires Linux `/proc`, child-subreaper support and Python 3 (standard library only). Run `make test-e2e` from the project root after `make deps` and `make test-postgres`. The latter prepares the pinned embedded-postgres CLI v2.0.1/PostgreSQL 16.15.1 cache. Install Playwright's pinned Firefox beforehand if it is not already cached (`cd frontend && npx playwright install firefox`). These preparation steps may require network access; the E2E runner itself uses offline caches and never installs dependencies.
|
||||
|
||||
The runner builds the dedicated `backend/cmd/e2e` executable, starts a disposable `tradarr_e2e` database, applies the real migrations, and refuses a nonempty database. It ignores inherited application/test database URLs, chooses loopback ports, and bootstraps a reserved disposable admin. Exactly one fixture source is enabled. The catalogue contains one explicit fake summary model. The new user selects it in the real preferences UI; new accounts have no default selection. The injected Laya ranker and summary provider are separate test doubles, with no concrete retrieval adapter instantiated and no legacy role fallback. Production uses the same `internal/server` constructor with its existing real composition and scheduler enabled.
|
||||
The runner builds the dedicated `backend/cmd/e2e` executable, starts a disposable `tradarr_e2e` database, applies the real migrations, and refuses a nonempty database. It ignores inherited application/test database URLs, chooses loopback ports, and bootstraps a reserved disposable admin. Exactly one fixture source is enabled. The catalogue contains the fake-summary synthesis model and a separate ollama/llama3 ranking model with native JSON schema capability. The new user selects both independently in the real preferences UI; new accounts have no default selection. The journey verifies both saved model IDs and the model actually called by the scoring fake. The injected Laya ranker and summary provider are separate test doubles, with no concrete retrieval adapter instantiated and no legacy role fallback. Production uses the same `internal/server` constructor with its existing real composition and scheduler enabled.
|
||||
|
||||
OpenFIGI, an Ollama-compatible fake Laya and a fake scraper share a loopback HTTP service with `/audit` counters and structured call events. The ranking fake extracts the real candidate UUID from the request prompt and returns it in `ranked_article_ids`; the browser assertion checks that actual UUID in audit events against the saved outcome. No hard-coded fixture ID selects a candidate.
|
||||
|
||||
|
||||
@ -36,9 +36,11 @@ function restoreAISeed(stack) {
|
||||
}
|
||||
const providerID = '00000000-0000-0000-0000-000000001202'
|
||||
const modelID = stack.fixtures.summaryModelID
|
||||
const rankingModelID = stack.fixtures.rankingModelID
|
||||
const rankingModelName = stack.fixtures.rankingModelName.replaceAll("'", "''")
|
||||
const fakeURL = stack.layaFakeUrl.replaceAll("'", "''")
|
||||
const sql = `BEGIN;
|
||||
DELETE FROM ai_provider_models WHERE id <> '${modelID}';
|
||||
DELETE FROM ai_provider_models WHERE id NOT IN ('${modelID}', '${rankingModelID}');
|
||||
DELETE FROM ai_providers WHERE id <> '${providerID}';
|
||||
INSERT INTO ai_providers(id,name,model,endpoint,is_active)
|
||||
VALUES('${providerID}','ollama','fake-laya','${fakeURL}',true)
|
||||
@ -46,6 +48,9 @@ function restoreAISeed(stack) {
|
||||
INSERT INTO ai_provider_models(id,provider_id,model,enabled)
|
||||
VALUES('${modelID}','${providerID}','fake-summary',true)
|
||||
ON CONFLICT(id) DO UPDATE SET provider_id=EXCLUDED.provider_id,model=EXCLUDED.model,enabled=true;
|
||||
INSERT INTO ai_provider_models(id,provider_id,model,enabled)
|
||||
VALUES('${rankingModelID}','${providerID}','${rankingModelName}',true)
|
||||
ON CONFLICT(id) DO UPDATE SET provider_id=EXCLUDED.provider_id,model=EXCLUDED.model,enabled=true;
|
||||
COMMIT;`
|
||||
execFileSync(stack.psqlPath, ['--no-psqlrc', '--set', 'ON_ERROR_STOP=1', '--command', sql], {
|
||||
env,
|
||||
@ -92,7 +97,27 @@ test('bug #18: admin AI page consumes current empty and configured API payloads'
|
||||
id: stack.fixtures.summaryModelID,
|
||||
provider_id: '00000000-0000-0000-0000-000000001202',
|
||||
provider: 'ollama', model: 'fake-summary', enabled: true,
|
||||
}), expect.objectContaining({
|
||||
id: stack.fixtures.rankingModelID,
|
||||
provider_id: '00000000-0000-0000-0000-000000001202',
|
||||
provider: 'ollama', model: stack.fixtures.rankingModelName, enabled: true,
|
||||
ranking_capability: stack.fixtures.rankingCapability,
|
||||
})])
|
||||
const summaryCatalog = await responseData(request, api('/me/summary-models?role=summary'), token)
|
||||
const defaultCatalog = await responseData(request, api('/me/summary-models'), token)
|
||||
expect(summaryCatalog.json.data).toEqual(defaultCatalog.json.data)
|
||||
expect(summaryCatalog.json.data).toEqual([
|
||||
expect.objectContaining({ id: stack.fixtures.summaryModelID, provider: 'ollama', model: 'fake-summary', ranking_capability: expect.objectContaining({ selectable: false }) }),
|
||||
expect.objectContaining({ id: stack.fixtures.rankingModelID, provider: 'ollama', model: stack.fixtures.rankingModelName }),
|
||||
])
|
||||
const rankingCatalog = await responseData(request, api('/me/summary-models?role=ranking'), token)
|
||||
expect(rankingCatalog.json.data).toEqual([expect.objectContaining({
|
||||
id: stack.fixtures.rankingModelID, provider: 'ollama', model: stack.fixtures.rankingModelName,
|
||||
ranking_capability: stack.fixtures.rankingCapability,
|
||||
})])
|
||||
expect(rankingCatalog.json.data.map(model => model.id)).not.toContain(stack.fixtures.summaryModelID)
|
||||
const invalidRole = await responseData(request, api('/me/summary-models?role=unknown'), token, 400)
|
||||
expect(invalidRole.json.error).toBe('invalid model role')
|
||||
expect(configuredOllama.json).toHaveProperty('error')
|
||||
|
||||
let emptyCounts
|
||||
@ -101,8 +126,11 @@ test('bug #18: admin AI page consumes current empty and configured API payloads'
|
||||
let reconfiguredModelData
|
||||
let providerID
|
||||
try {
|
||||
// Both seeded rows are unselected by the bootstrap admin and may be
|
||||
// Both seeded models are unselected by the bootstrap admin and may be
|
||||
// removed safely inside this disposable database.
|
||||
expect((await request.delete(api(`/admin/ai-models/${stack.fixtures.rankingModelID}`), {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})).status()).toBe(204)
|
||||
expect((await request.delete(api(`/admin/ai-models/${stack.fixtures.summaryModelID}`), {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})).status()).toBe(204)
|
||||
|
||||
@ -68,12 +68,16 @@ export function readStackManifest() {
|
||||
if (!manifest.bootstrapAdmin?.email || !manifest.bootstrapAdmin?.password) {
|
||||
throw new Error('E2E fake stack manifest must provide disposable bootstrap admin credentials.')
|
||||
}
|
||||
for (const field of ['companyQuery', 'companyID', 'companyName', 'companySymbol', 'companyFIGI', 'summaryModelID', 'summarySentinel', 'articleTitle', 'articleURL', 'articleContent', 'candidateID']) {
|
||||
for (const field of ['companyQuery', 'companyID', 'companyName', 'companySymbol', 'companyFIGI', 'summaryModelID', 'rankingModelID', 'rankingModelName', 'summarySentinel', 'articleTitle', 'articleURL', 'articleContent', 'candidateID']) {
|
||||
if (typeof manifest.fixtures?.[field] !== 'string' || !manifest.fixtures[field]) {
|
||||
throw new Error(`E2E fake stack manifest is missing fixtures.${field}.`)
|
||||
}
|
||||
}
|
||||
|
||||
if (manifest.fixtures.rankingCapability?.selectable !== true || manifest.fixtures.rankingCapability?.mode !== 'json_schema') {
|
||||
throw new Error('E2E fake stack manifest must provide a compatible structured ranking capability.')
|
||||
}
|
||||
|
||||
const databaseURL = new URL(manifest.databaseUrl)
|
||||
const databaseName = decodeURIComponent(databaseURL.pathname.replace(/^\//, ''))
|
||||
if (!/(^|[-_])(e2e|test)([-_]|$)/i.test(databaseName)) {
|
||||
|
||||
@ -105,9 +105,23 @@ test('admin creates a user who follows a fake company and generates a private su
|
||||
await page.goto(new URL('/preferences', baseURL).href)
|
||||
await page.getByLabel('Langue des synthèses').selectOption('en')
|
||||
await page.getByLabel('Modèle de synthèse', { exact: true }).selectOption(fixture.summaryModelID)
|
||||
const ranking = page.getByLabel('Modèle de classement de pertinence', { exact: true })
|
||||
await expect(ranking).toHaveValue('')
|
||||
await expect(ranking.getByRole('option', { name: `ollama · ${fixture.rankingModelName}`, exact: true })).toHaveAttribute('value', fixture.rankingModelID)
|
||||
await expect(ranking.locator(`option[value="${fixture.summaryModelID}"]`)).toHaveCount(0)
|
||||
expect(fixture.rankingCapability).toMatchObject({ selectable: true, mode: 'json_schema' })
|
||||
await ranking.selectOption(fixture.rankingModelID)
|
||||
await page.getByLabel('Informations utilisées par Laya pour classer les articles').selectOption('title_content')
|
||||
await page.getByRole('button', { name: 'Enregistrer' }).click()
|
||||
await expect(page.getByRole('status')).toHaveText('Préférences enregistrées.')
|
||||
const token = await page.evaluate(() => localStorage.getItem('token'))
|
||||
const response = await request.get(new URL('/api/me/preferences', stack.apiUrl).href, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
expect(response.status()).toBe(200)
|
||||
const { data: savedPreferences } = await response.json()
|
||||
expect(savedPreferences.summary_model_id).toBe(fixture.summaryModelID)
|
||||
expect(savedPreferences.ranking_model_id).toBe(fixture.rankingModelID)
|
||||
})
|
||||
|
||||
await test.step('fake scraper and Laya produce an aggregate summary', async () => {
|
||||
@ -145,6 +159,10 @@ test('admin creates a user who follows a fake company and generates a private su
|
||||
expect(events.companyResolutions).toBeGreaterThan(0)
|
||||
expect(events.scraperCalls).toBeGreaterThan(0)
|
||||
expect(events.layaRankingCalls).toBeGreaterThan(0)
|
||||
expect(events.relevanceScoringCalls).toBeGreaterThan(0)
|
||||
const scoringCalls = events.events.filter(event => event.kind === 'relevanceScoringCalls')
|
||||
expect(scoringCalls.length).toBeGreaterThan(0)
|
||||
expect(scoringCalls.every(event => event.model === fixture.rankingModelName)).toBeTruthy()
|
||||
expect(events.layaSummaryCalls).toBeGreaterThan(0)
|
||||
const token = await page.evaluate(() => localStorage.getItem('token'))
|
||||
const history = await request.get(new URL('/api/summaries/generations', stack.apiUrl).href, {
|
||||
|
||||
Reference in New Issue
Block a user