Add a fake-only end-to-end stack, Firefox journey, and bounded process cleanup for normal, failed, and interrupted runs. Refs #12 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
134 lines
7.1 KiB
JavaScript
134 lines
7.1 KiB
JavaScript
import { execFileSync } from 'node:child_process'
|
|
import { randomUUID } from 'node:crypto'
|
|
import { test, expect } from '@playwright/test'
|
|
import { readStackManifest } from './stack-manifest.mjs'
|
|
|
|
function articleAndJobSnapshot(stack) {
|
|
const env = {
|
|
...process.env,
|
|
PGHOST: stack.databaseURL.hostname,
|
|
PGPORT: stack.databaseURL.port || '5432',
|
|
PGUSER: decodeURIComponent(stack.databaseURL.username),
|
|
PGPASSWORD: decodeURIComponent(stack.databaseURL.password),
|
|
PGDATABASE: decodeURIComponent(stack.databaseURL.pathname.slice(1)),
|
|
PGSSLMODE: stack.databaseURL.searchParams.get('sslmode') || 'disable',
|
|
}
|
|
const sql = `SELECT
|
|
(SELECT count(*)::text || ':' || coalesce(md5(string_agg(md5(row_to_json(a)::text), ',' ORDER BY row_to_json(a)::text)), md5('')) FROM public.articles a)
|
|
|| '|' ||
|
|
(SELECT count(*)::text || ':' || coalesce(md5(string_agg(md5(row_to_json(s)::text), ',' ORDER BY row_to_json(s)::text)), md5('')) FROM public.article_symbols s)
|
|
|| '|' ||
|
|
(SELECT count(*)::text || ':' || coalesce(md5(string_agg(md5(row_to_json(j)::text), ',' ORDER BY row_to_json(j)::text)), md5('')) FROM public.scrape_jobs j);`
|
|
return execFileSync(stack.psqlPath, ['--no-psqlrc', '--tuples-only', '--no-align', '--set', 'ON_ERROR_STOP=1', '--command', sql], {
|
|
env,
|
|
encoding: 'utf8',
|
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
timeout: 10_000,
|
|
}).trim()
|
|
}
|
|
|
|
async function login(page, baseURL, email, password) {
|
|
await page.goto(new URL('/login', baseURL).href)
|
|
await page.getByLabel('Adresse email').fill(email)
|
|
await page.getByLabel('Mot de passe').fill(password)
|
|
await page.getByRole('button', { name: 'Se connecter' }).click()
|
|
await expect(page).toHaveURL(new URL('/', baseURL).href)
|
|
}
|
|
|
|
test('admin creates a user who follows a fake index and generates a private summary without article/job writes', async ({ page, request }) => {
|
|
const stack = readStackManifest()
|
|
await page.context().route('**/*', async route => {
|
|
const host = new URL(route.request().url()).hostname
|
|
if (host !== '127.0.0.1' && host !== '[::1]') return route.abort('blockedbyclient')
|
|
return route.continue()
|
|
})
|
|
const baseURL = stack.frontendUrl
|
|
const fixture = stack.fixtures
|
|
const email = `e2e-${randomUUID()}@example.test`
|
|
const password = `E2e-${randomUUID()}!`
|
|
const before = articleAndJobSnapshot(stack)
|
|
|
|
await test.step('admin bootstrap login and account creation', async () => {
|
|
await login(page, baseURL, stack.bootstrapAdmin.email, stack.bootstrapAdmin.password)
|
|
await page.goto(new URL('/admin/users', baseURL).href)
|
|
await page.getByRole('button', { name: 'Créer un compte' }).click()
|
|
const form = page.getByRole('form', { name: 'Créer un compte' })
|
|
await form.getByLabel('Email').fill(email)
|
|
await form.getByLabel('Mot de passe initial').fill(password)
|
|
await form.getByRole('button', { name: 'Créer', exact: true }).click()
|
|
await expect(form.getByRole('status')).toHaveText('Compte créé avec succès.')
|
|
await page.getByRole('button', { name: 'Déconnexion' }).click()
|
|
})
|
|
|
|
await test.step('new user login and explicit fake OpenFIGI selection', async () => {
|
|
await login(page, baseURL, email, password)
|
|
await page.goto(new URL('/assets', baseURL).href)
|
|
const query = page.getByRole('textbox', { name: 'Nom ou symbole' })
|
|
await query.fill(fixture.indexQuery)
|
|
await page.getByRole('button', { name: 'Rechercher' }).click()
|
|
const results = page.getByRole('region', { name: 'Résultats de recherche' })
|
|
await expect(results.getByText(fixture.indexName)).toBeVisible()
|
|
await expect(results.getByText(fixture.indexSymbol)).toBeVisible()
|
|
await results.getByRole('button', { name: 'Suivre cet indice' }).click()
|
|
await expect(page.getByRole('region', { name: 'Indices suivis' })).toContainText(fixture.indexSymbol)
|
|
})
|
|
|
|
await test.step('user saves language and ranking preferences', async () => {
|
|
await page.goto(new URL('/preferences', baseURL).href)
|
|
await page.getByLabel('Langue des synthèses').selectOption('en')
|
|
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.')
|
|
})
|
|
|
|
await test.step('fake scraper and Laya produce an aggregate summary', async () => {
|
|
await page.goto(new URL('/', baseURL).href)
|
|
await page.getByRole('button', { name: 'Générer une synthèse' }).click()
|
|
await expect(page.getByText(fixture.summarySentinel, { exact: false })).toBeVisible({ timeout: 90_000 })
|
|
await expect(page.getByText('Langue de cette synthèse : English', { exact: true })).toBeVisible()
|
|
for (const forbidden of [fixture.articleTitle, fixture.articleURL, fixture.articleContent, fixture.candidateID]) {
|
|
await expect(page.getByText(forbidden, { exact: false })).toHaveCount(0)
|
|
}
|
|
})
|
|
|
|
await test.step('legacy article/job routes stay closed and database rows remain unchanged', async () => {
|
|
const api = stack.apiUrl
|
|
expect((await request.get(new URL('/api/articles', api).href)).status()).toBe(404)
|
|
expect((await request.get(new URL('/api/articles/e2e-forbidden', api).href)).status()).toBe(404)
|
|
expect((await request.get(new URL('/api/admin/scrape-jobs', api).href)).status()).toBe(404)
|
|
expect((await request.post(new URL('/api/admin/scrape-jobs/trigger', api).href)).status()).toBe(404)
|
|
expect(articleAndJobSnapshot(stack)).toBe(before)
|
|
})
|
|
|
|
await test.step('fake-provider audit confirms every dependency stayed local', async () => {
|
|
const response = await request.get(new URL(stack.fakeAuditPath, stack.fakeControlUrl).href)
|
|
expect(response.ok()).toBeTruthy()
|
|
const events = await response.json()
|
|
expect(events.openfigiSearches).toBeGreaterThan(0)
|
|
expect(events.scraperCalls).toBeGreaterThan(0)
|
|
expect(events.layaRankingCalls).toBeGreaterThan(0)
|
|
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, {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
})
|
|
expect(history.status()).toBe(200)
|
|
const generations = await history.json()
|
|
expect(generations.data.length).toBe(1)
|
|
const outcome = generations.data[0].outcome
|
|
expect(outcome.status).toBe('succeeded')
|
|
expect(outcome.total_candidates).toBe(1)
|
|
expect(outcome.source_stats).toHaveLength(1)
|
|
const serialized = JSON.stringify(outcome)
|
|
const candidateIDs = events.events.filter(event => event.kind === 'layaRankingCalls').map(event => event.candidate_id)
|
|
expect(candidateIDs.length).toBeGreaterThan(0)
|
|
for (const forbidden of [fixture.articleTitle, fixture.articleURL, fixture.articleContent, ...candidateIDs]) {
|
|
expect(serialized).not.toContain(forbidden)
|
|
await expect(page.getByText(forbidden, { exact: false })).toHaveCount(0)
|
|
}
|
|
for (const field of ['title', 'url', 'content', 'prompt', 'candidate_id']) {
|
|
expect(serialized).not.toContain(`"${field}":`)
|
|
}
|
|
})
|
|
})
|