/** * Round-trips a phrase through the translation service. * * npm run translate:test ["texte à traduire"] * * The settings page has the same button; this exists to check a deployment * from the host, before anyone signs in, and to see the cache working. */ import 'dotenv/config'; import { prisma } from '../lib/db'; import { defaultProvider, translateToEnglish } from '../lib/translation/service'; async function main(): Promise { const text = process.argv[2] ?? 'Fermeture exceptionnelle jeudi après-midi'; const provider = defaultProvider(); if (!provider) { console.error('Service non configuré : renseignez TRANSLATION_API_URL et TRANSLATION_API_KEY.'); process.exitCode = 1; return; } console.log(`Modèle : ${provider.model}`); console.log(`Français : ${text}`); const started = Date.now(); const first = await translateToEnglish(text, provider); const elapsed = Date.now() - started; if (!first.ok) { console.error(`Échec : ${first.error}`); process.exitCode = 1; return; } console.log(`Anglais : ${first.text}`); console.log(`Durée : ${elapsed} ms (cache : ${first.cached ? 'oui' : 'non'})`); // Second pass proves the cache: it must not touch the network at all. const again = Date.now(); const second = await translateToEnglish(text, provider); console.log( `2e appel : ${Date.now() - again} ms (cache : ${second.ok && second.cached ? 'oui' : 'non'})`, ); } main() .catch((error: unknown) => { console.error(error); process.exitCode = 1; }) .finally(() => { void prisma.$disconnect(); });